[Tarantool-patches] [PATCH 2/3] txn_limbo: move lsn assignment to journal completion callback

Serge Petrenko sergepetrenko at tarantool.org
Thu May 20 12:02:35 MSK 2021


Previously local lsn assignment for txn_limbo entries was done right in
txn_commit() body after the WAL write.

In order to make the entries lsn available to on_wal_write triggers, which are
called from the journal completion callback, assign it right in the
callback before the triggers are called.

Note, ACKing the entry is not moved to journal completion callback, since
it may trigger writing CONFIRM, which cannot be done from the sched fiber
(which executes the journal callback).

Prerequisite #6032
---
 src/box/txn.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/box/txn.c b/src/box/txn.c
index 1fa3e4367..dea824d78 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -545,6 +545,16 @@ txn_on_journal_write(struct journal_entry *entry)
 		txn_complete_fail(txn);
 		goto finish;
 	}
+
+	if (txn_has_flag(txn, TXN_WAIT_ACK) && txn->limbo_entry->lsn == -1) {
+		int64_t lsn = entry->rows[entry->n_rows - 1]->lsn;
+		/*
+		 * Must be a local entry since its lsn wasn't known prior to
+		 * the WAL write.
+		 */
+		txn_limbo_assign_local_lsn(&txn_limbo, txn->limbo_entry, lsn);
+	}
+
 	double stop_tm = ev_monotonic_now(loop());
 	double delta = stop_tm - txn->start_tm;
 	if (delta > too_long_threshold) {
@@ -906,13 +916,6 @@ txn_commit(struct txn *txn)
 	if (is_sync) {
 		if (txn_has_flag(txn, TXN_WAIT_ACK)) {
 			int64_t lsn = req->rows[req->n_rows - 1]->lsn;
-			/*
-			 * Use local LSN assignment. Because
-			 * blocking commit is used by local
-			 * transactions only.
-			 */
-			txn_limbo_assign_local_lsn(&txn_limbo, txn->limbo_entry,
-						   lsn);
 			/* Local WAL write is a first 'ACK'. */
 			txn_limbo_ack(&txn_limbo, txn_limbo.owner_id, lsn);
 		}
-- 
2.30.1 (Apple Git-130)



More information about the Tarantool-patches mailing list