[Tarantool-patches] [PATCH 6/8] txn_limbo: fix instance id assignment

Serge Petrenko sergepetrenko at tarantool.org
Tue Jun 9 15:20:18 MSK 2020


When a txn_limbo is running on a replica, it holds changes from a remote
master. Reflect it by assigning libmo instance id accordingly.

Follow-up #4844
Part-of #4847
---
 src/box/txn.c       | 8 +++++++-
 src/box/txn_limbo.c | 8 +++++---
 src/box/txn_limbo.h | 2 +-
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/box/txn.c b/src/box/txn.c
index f30e20944..a65100b31 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -673,12 +673,18 @@ txn_commit(struct txn *txn)
 
 	bool is_sync = txn_has_flag(txn, TXN_WAIT_ACK);
 	if (is_sync) {
+		/*
+		 * Remote rows, if any, come before local rows, so
+		 * check for originating instance id here.
+		 */
+		uint32_t origin_id = req->rows[0]->replica_id;
+
 		/*
 		 * Append now. Before even WAL write is done.
 		 * After WAL write nothing should fail, even OOM
 		 * wouldn't be acceptable.
 		 */
-		limbo_entry = txn_limbo_append(&txn_limbo, txn);
+		limbo_entry = txn_limbo_append(&txn_limbo, origin_id, txn);
 		if (limbo_entry == NULL) {
 			txn_rollback(txn);
 			txn_free(txn);
diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c
index 47c1bd249..efb97a591 100644
--- a/src/box/txn_limbo.c
+++ b/src/box/txn_limbo.c
@@ -43,13 +43,15 @@ txn_limbo_create(struct txn_limbo *limbo)
 }
 
 struct txn_limbo_entry *
-txn_limbo_append(struct txn_limbo *limbo, struct txn *txn)
+txn_limbo_append(struct txn_limbo *limbo, uint32_t id, struct txn *txn)
 {
 	assert(txn_has_flag(txn, TXN_WAIT_ACK));
-	if (limbo->instance_id != instance_id) {
+	if (id == 0)
+		id = instance_id;
+	if (limbo->instance_id != id) {
 		if (limbo->instance_id == REPLICA_ID_NIL ||
 		    rlist_empty(&limbo->queue)) {
-			limbo->instance_id = instance_id;
+			limbo->instance_id = id;
 		} else {
 			diag_set(ClientError, ER_UNCOMMITTED_FOREIGN_SYNC_TXNS,
 				 limbo->instance_id);
diff --git a/src/box/txn_limbo.h b/src/box/txn_limbo.h
index 112fa8902..1ad1c567a 100644
--- a/src/box/txn_limbo.h
+++ b/src/box/txn_limbo.h
@@ -131,7 +131,7 @@ extern struct txn_limbo txn_limbo;
  * The limbo entry is allocated on the transaction's region.
  */
 struct txn_limbo_entry *
-txn_limbo_append(struct txn_limbo *limbo, struct txn *txn);
+txn_limbo_append(struct txn_limbo *limbo, uint32_t id, struct txn *txn);
 
 /** Remove the entry from the limbo, mark as rolled back. */
 void
-- 
2.24.3 (Apple Git-128)



More information about the Tarantool-patches mailing list