s3:dbwrap_ctdb: increase the rsn of the __transaction_lock__ when storing
[amitay/samba.git] / source3 / lib / dbwrap_ctdb.c
index fef984c8c31c49d08d2741f3b1b1bc4825f97f38..9e57aadb258372b8f3f97848593b3bc76c8cb2bf 100644 (file)
@@ -381,6 +381,8 @@ again:
        pid = getpid();
        data.dptr = (unsigned char *)&pid;
        data.dsize = sizeof(pid_t);
+       crec->header.rsn++;
+       crec->header.dmaster = get_my_vnn();
        status = db_ctdb_ltdb_store(ctx, key, &(crec->header), data);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, (__location__ " Failed to store pid in transaction "
@@ -399,13 +401,30 @@ again:
        }
 
        status = db_ctdb_ltdb_fetch(ctx, key, &header, tmp_ctx, &data);
-       if (!NT_STATUS_IS_OK(status) || header.dmaster != get_my_vnn()) {
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, (__location__ " failed to refetch transaction lock "
+                         "record inside transaction: %s - retrying\n",
+                         nt_errstr(status)));
+               tdb_transaction_cancel(ctx->wtdb->tdb);
+               talloc_free(tmp_ctx);
+               goto again;
+       }
+
+       if (header.dmaster != get_my_vnn()) {
+               DEBUG(3, (__location__ " refetch transaction lock record : "
+                         "we are not dmaster any more "
+                         "(dmaster[%u] != my_vnn[%u]) - retrying\n",
+                         header.dmaster, get_my_vnn()));
                tdb_transaction_cancel(ctx->wtdb->tdb);
                talloc_free(tmp_ctx);
                goto again;
        }
 
        if ((data.dsize != sizeof(pid_t)) || (*(pid_t *)(data.dptr) != pid)) {
+               DEBUG(3, (__location__ " refetch transaction lock record: "
+                         "another local process has started a transaction "
+                         "(stored pid [%u] != my pid [%u]) - retrying\n",
+                         *(pid_t *)(data.dptr), pid));
                tdb_transaction_cancel(ctx->wtdb->tdb);
                talloc_free(tmp_ctx);
                goto again;