From 59489019ad15a5ad6b0f295e742fc9832745a842 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Thu, 7 Nov 2013 15:54:20 +1100 Subject: [PATCH] client: Make g_lock_lock() wait till lock is obtained 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 --- client/ctdb_client.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/ctdb_client.c b/client/ctdb_client.c index 6ccc4c90..fddbd02b 100644 --- a/client/ctdb_client.c +++ b/client/ctdb_client.c @@ -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, -- 2.34.1