tdb2: don't cancel transactions on lock failures in tdb1 backend.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 05:56:16 +0000 (15:26 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 05:56:16 +0000 (15:26 +0930)
In TDB2, the user can override locking functions, so they may
deliberarely fail (eg. be non-blocking) expecting to retry.

For this reason, the TDB2 API requires the caller to cancel the
transaction if tdb_transaction_prepare_commit() fails.

ccan/tdb2/tdb1_transaction.c

index 9c526fb41e5d194fa10dcf2d910022881a3fc3ae..f0623025f95268f12a89febf9246475946e3fd8a 100644 (file)
@@ -963,7 +963,6 @@ static int _tdb1_transaction_prepare_commit(struct tdb1_context *tdb)
                                   "tdb1_transaction_prepare_commit:"
                                   " failed to upgrade hash locks");
                }
-               _tdb1_transaction_cancel(tdb);
                return -1;
        }
 
@@ -975,7 +974,6 @@ static int _tdb1_transaction_prepare_commit(struct tdb1_context *tdb)
                                   "tdb1_transaction_prepare_commit:"
                                   " failed to get open lock");
                }
-               _tdb1_transaction_cancel(tdb);
                return -1;
        }
 
@@ -985,7 +983,6 @@ static int _tdb1_transaction_prepare_commit(struct tdb1_context *tdb)
                        tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
                                   "tdb1_transaction_prepare_commit:"
                                   " failed to setup recovery data");
-                       _tdb1_transaction_cancel(tdb);
                        return -1;
                }
        }
@@ -1000,7 +997,6 @@ static int _tdb1_transaction_prepare_commit(struct tdb1_context *tdb)
                        tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
                                   "tdb1_transaction_prepare_commit:"
                                   " expansion failed");
-                       _tdb1_transaction_cancel(tdb);
                        return -1;
                }
                tdb->file->map_size = tdb->transaction->old_map_size;
@@ -1080,8 +1076,10 @@ int tdb1_transaction_commit(struct tdb1_context *tdb)
 
        if (!tdb->transaction->prepared) {
                int ret = _tdb1_transaction_prepare_commit(tdb);
-               if (ret)
+               if (ret) {
+                       _tdb1_transaction_cancel(tdb);
                        return ret;
+               }
        }
 
        methods = tdb->transaction->io_methods;