Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org
Subject: [Tarantool-patches] [PATCH 1/1] [tosquash] txn: refactor txn_commit_async
Date: Wed, 24 Jun 2020 00:16:18 +0200	[thread overview]
Message-ID: <6e27b7a8eb9cf5f294e360484a50caf764136a39.1592950555.git.v.shpilevoy@tarantool.org> (raw)

* 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)

                 reply	other threads:[~2020-06-23 22:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6e27b7a8eb9cf5f294e360484a50caf764136a39.1592950555.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/1] [tosquash] txn: refactor txn_commit_async' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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