client: fix a race in the local race condition fix in transaction_start
authorMichael Adam <obnox@samba.org>
Thu, 29 Oct 2009 21:20:38 +0000 (22:20 +0100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 30 Oct 2009 11:01:16 +0000 (22:01 +1100)
The gap that remained is between checking whether a transaction commit
is in progress and taking the lock. Now we first take the lock and then
check whether a transaction commit is in progress. If so, we release the
lock, wait for one second and retry.

Michael

client/ctdb_client.c

index b03e0f85fd9bdec404b3f811cdd63ea849ebdfcf..ae01638665399c4caf3087cfb37ec6bf1d967204 100644 (file)
@@ -3213,6 +3213,15 @@ static int ctdb_transaction_fetch_start(struct ctdb_transaction_handle *h)
        }
 
 again:
+       tmp_ctx = talloc_new(h);
+
+       rh = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, NULL);
+       if (rh == NULL) {
+               DEBUG(DEBUG_ERR,(__location__ " Failed to fetch_lock database\n"));
+               talloc_free(tmp_ctx);
+               return -1;
+       }
+
        status = ctdb_ctrl_transaction_active(ctdb_db->ctdb,
                                              CTDB_CURRENT_NODE,
                                              ctdb_db->db_id);
@@ -3220,18 +3229,11 @@ again:
                DEBUG(DEBUG_NOTICE, (__location__ " transaction is active "
                                     "on db_id[0x%08x]. waiting for 1 second\n",
                                     ctdb_db->db_id));
+               talloc_free(tmp_ctx);
                sleep(1);
                goto again;
        }
 
-       tmp_ctx = talloc_new(h);
-
-       rh = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, NULL);
-       if (rh == NULL) {
-               DEBUG(DEBUG_ERR,(__location__ " Failed to fetch_lock database\n"));             
-               talloc_free(tmp_ctx);
-               return -1;
-       }
        /*
         * store the pid in the database:
         * it is not enough that the node is dmaster...