client: Make g_lock_lock() wait till lock is obtained
authorAmitay Isaacs <amitay@gmail.com>
Thu, 7 Nov 2013 04:54:20 +0000 (15:54 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Thu, 7 Nov 2013 05:08:17 +0000 (16:08 +1100)
This makes the behaviour of g_lock_lock() similar to that implemented in
Samba.  Now ctdb_transaction_start() will return NULL only when there are
failures and not when another transaction is active.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
client/ctdb_client.c

index 6ccc4c906aac238bfac02be3cb31bb1bb7d3ed3a..fddbd02b628514a57b744644a1216ca5778ee03c 100644 (file)
@@ -3856,10 +3856,20 @@ static bool g_lock_lock(TALLOC_CTX *mem_ctx,
        struct ctdb_record_handle *h;
        struct g_lock_recs *locks;
        struct server_id id;
+       struct timeval t_start;
        int i;
 
        key.dptr = (uint8_t *)discard_const(keyname);
        key.dsize = strlen(keyname) + 1;
+
+       t_start = timeval_current();
+
+again:
+       /* Keep trying for an hour. */
+       if (timeval_elapsed(&t_start) > 3600) {
+               return false;
+       }
+
        h = ctdb_fetch_lock(ctdb_db, mem_ctx, key, &data);
        if (h == NULL) {
                return false;
@@ -3899,7 +3909,7 @@ static bool g_lock_lock(TALLOC_CTX *mem_ctx,
                                   id.task_id, id.vnn,
                                   (unsigned long long)id.unique_id));
                talloc_free(h);
-               return false;
+               goto again;
        }
 
        locks->lock = talloc_realloc(locks, locks->lock, struct g_lock_rec,