Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH 1/1] [tosquash] txn: refactor txn_commit_async
@ 2020-06-23 22:16 Vladislav Shpilevoy
  0 siblings, 0 replies; only message in thread
From: Vladislav Shpilevoy @ 2020-06-23 22:16 UTC (permalink / raw)
  To: tarantool-patches, sergepetrenko

* txn_free() is not needed in txn_commit_async() when it fails.
  It is done in txn_rollback() if necessary;

* if on_rollback trigger allocation failed, the transaction
  wasn't rolled back.
---
Branch: http://github.com/tarantool/tarantool/tree/gh-4842-sync-replication
Issue: https://github.com/tarantool/tarantool/issues/4842

 src/box/txn.c | 51 ++++++++++++++++++++++-----------------------------
 1 file changed, 22 insertions(+), 29 deletions(-)

diff --git a/src/box/txn.c b/src/box/txn.c
index 2e2b225c0..400705d36 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -659,56 +659,49 @@ txn_commit_async(struct txn *txn)
 	bool is_sync = txn_has_flag(txn, TXN_WAIT_ACK);
 	struct txn_limbo_entry *limbo_entry;
 	if (is_sync) {
+		/*
+		 * We'll need this trigger for sync transactions later,
+		 * but allocation failure is inappropriate after the entry
+		 * is sent to journal, so allocate early.
+		 */
+		size_t size;
+		struct trigger *trig =
+			region_alloc_object(&txn->region, typeof(*trig), &size);
+		if (trig == NULL) {
+			txn_rollback(txn);
+			diag_set(OutOfMemory, size, "region_alloc_object",
+				 "trig");
+			return -1;
+		}
+
 		/* See txn_commit(). */
 		uint32_t origin_id = req->rows[0]->replica_id;
 		int64_t lsn = req->rows[txn->n_applier_rows - 1]->lsn;
 		limbo_entry = txn_limbo_append(&txn_limbo, origin_id, txn);
 		if (limbo_entry == NULL) {
 			txn_rollback(txn);
-			txn_free(txn);
 			return -1;
 		}
 		assert(lsn > 0);
 		txn_limbo_assign_lsn(&txn_limbo, limbo_entry, lsn);
-	}
 
-	/*
-	 * We'll need this trigger for sync transactions later,
-	 * but allocation failure is inappropriate after the entry
-	 * is sent to journal, so allocate early.
-	 */
-	struct trigger *trig;
-	if (is_sync) {
-		size_t size;
-		trig = region_alloc_object(&txn->region, typeof(*trig), &size);
-		if (trig == NULL) {
-			diag_set(OutOfMemory, size, "region_alloc_object",
-				 "trig");
-			return -1;
-		}
+		/*
+		 * Set a trigger to abort waiting for confirm on
+		 * WAL write failure.
+		 */
+		trigger_create(trig, txn_limbo_on_rollback,
+			       limbo_entry, NULL);
+		txn_on_rollback(txn, trig);
 	}
 
 	fiber_set_txn(fiber(), NULL);
 	if (journal_write_async(req) != 0) {
 		fiber_set_txn(fiber(), txn);
 		txn_rollback(txn);
-		if (is_sync)
-			txn_limbo_abort(&txn_limbo, limbo_entry);
-
 		diag_set(ClientError, ER_WAL_IO);
 		diag_log();
 		return -1;
 	}
-
-	if (is_sync) {
-		/*
-		 * Set a trigger to abort waiting for confirm on
-		 * WAL write failure.
-		 */
-		trigger_create(trig, txn_limbo_on_rollback,
-			       limbo_entry, NULL);
-		txn_on_rollback(txn, trig);
-	}
 	return 0;
 }
 
-- 
2.21.1 (Apple Git-122.3)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-23 22:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 22:16 [Tarantool-patches] [PATCH 1/1] [tosquash] txn: refactor txn_commit_async Vladislav Shpilevoy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox