]> git.ozlabs.org Git - ccan/commitdiff
tdb2: don't cancel transaction when tdb_transaction_prepare_commit fails
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 6 Apr 2011 23:00:39 +0000 (08:30 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 6 Apr 2011 23:00:39 +0000 (08:30 +0930)
And don't double-log.  Both of these cause problems if we want to do
tdb_transaction_prepare_commit non-blocking (and have it fail so we can
try again).

ccan/tdb2/lock.c
ccan/tdb2/tdb2.h
ccan/tdb2/transaction.c

index 5b04c0d243d9b29f2a5104af3f7836a5a47e8f40..8bd9c4f0f4bca5c9a5079a74120919a1ae73c3d5 100644 (file)
@@ -555,23 +555,14 @@ again:
        /* Lock hashes, gradually. */
        ecode = tdb_lock_gradual(tdb, ltype, flags, TDB_HASH_LOCK_START,
                                 TDB_HASH_LOCK_RANGE);
-       if (ecode != TDB_SUCCESS) {
-               if (!(flags & TDB_LOCK_PROBE)) {
-                       tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
-                                  "tdb_allrecord_lock hashes failed");
-               }
+       if (ecode != TDB_SUCCESS)
                return ecode;
-       }
 
        /* Lock free tables: there to end of file. */
        ecode = tdb_brlock(tdb, ltype,
                           TDB_HASH_LOCK_START + TDB_HASH_LOCK_RANGE,
                           0, flags);
        if (ecode != TDB_SUCCESS) {
-               if (!(flags & TDB_LOCK_PROBE)) {
-                       tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
-                                "tdb_allrecord_lock freetables failed");
-               }
                tdb_brunlock(tdb, ltype, TDB_HASH_LOCK_START,
                             TDB_HASH_LOCK_RANGE);
                return ecode;
index 24137b88722dc3acd30432ad6b4425030c96b1c5..d78ef974b340cece0ac3306c7052edd21928deb5 100644 (file)
@@ -288,6 +288,9 @@ enum TDB_ERROR tdb_transaction_commit(struct tdb_context *tdb);
  * tdb_transaction_commit): if this succeeds then a transaction will only
  * fail if the write() or fsync() calls fail.
  *
+ * If this fails you must still call tdb_transaction_cancel() to cancel
+ * the transaction.
+ *
  * See Also:
  *     tdb_transaction_commit()
  */
index 29192beece4e3e48f0a6a337c677af2e14c0de63..d15db10691eb7d17c489a54d4211ccaa5cb16535 100644 (file)
@@ -921,10 +921,6 @@ static enum TDB_ERROR _tdb_transaction_prepare_commit(struct tdb_context *tdb)
        /* upgrade the main transaction lock region to a write lock */
        ecode = tdb_allrecord_upgrade(tdb);
        if (ecode != TDB_SUCCESS) {
-               tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
-                        "tdb_transaction_prepare_commit:"
-                        " failed to upgrade hash locks");
-               _tdb_transaction_cancel(tdb);
                return ecode;
        }
 
@@ -932,10 +928,6 @@ static enum TDB_ERROR _tdb_transaction_prepare_commit(struct tdb_context *tdb)
           during the commit */
        ecode = tdb_lock_open(tdb, TDB_LOCK_WAIT|TDB_LOCK_NOCHECK);
        if (ecode != TDB_SUCCESS) {
-               tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
-                          "tdb_transaction_prepare_commit:"
-                          " failed to get open lock");
-               _tdb_transaction_cancel(tdb);
                return ecode;
        }
 
@@ -946,10 +938,6 @@ static enum TDB_ERROR _tdb_transaction_prepare_commit(struct tdb_context *tdb)
                                                   &tdb->transaction
                                                   ->magic_offset);
                if (ecode != TDB_SUCCESS) {
-                       tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
-                                "tdb_transaction_prepare_commit:"
-                                " failed to setup recovery data");
-                       _tdb_transaction_cancel(tdb);
                        return ecode;
                }
        }
@@ -965,10 +953,6 @@ static enum TDB_ERROR _tdb_transaction_prepare_commit(struct tdb_context *tdb)
                tdb->file->map_size = tdb->transaction->old_map_size;
                ecode = methods->expand_file(tdb, add);
                if (ecode != TDB_SUCCESS) {
-                       tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
-                                "tdb_transaction_prepare_commit:"
-                                " expansion failed");
-                       _tdb_transaction_cancel(tdb);
                        return ecode;
                }
        }
@@ -1016,8 +1000,10 @@ enum TDB_ERROR tdb_transaction_commit(struct tdb_context *tdb)
 
        if (!tdb->transaction->prepared) {
                ecode = _tdb_transaction_prepare_commit(tdb);
-               if (ecode != TDB_SUCCESS)
+               if (ecode != TDB_SUCCESS) {
+                       _tdb_transaction_cancel(tdb);
                        return tdb->last_error = ecode;
+               }
        }
 
        methods = tdb->transaction->io_methods;
@@ -1040,10 +1026,6 @@ enum TDB_ERROR tdb_transaction_commit(struct tdb_context *tdb)
                ecode = methods->twrite(tdb, offset,
                                        tdb->transaction->blocks[i], length);
                if (ecode != TDB_SUCCESS) {
-                       tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
-                                  "tdb_transaction_commit:"
-                                  " write failed during commit");
-
                        /* we've overwritten part of the data and
                           possibly expanded the file, so we need to
                           run the crash recovery code */