[Tarantool-patches] [PATCH 1/4] box: add a single execution guard to clear_synchro_queue

Serge Petrenko sergepetrenko at tarantool.org
Thu Dec 10 23:55:11 MSK 2020


Clear_synchro_queue isn't meant to be called multiple times on a single
instance.

Multiple simultaneous invocations of clear_synhcro_queue() shouldn't
hurt now, since clear_synchro_queue simply exits on an empty limbo, but
may be harmful in future, when clear_synchro_queue is reworked.

Prohibit such misuse by introducing an execution guard and raising an
error once duplicate invocation is detected.

Prerequisite #5435
---
 src/box/box.cc    | 17 ++++++++++++++---
 src/box/box.h     |  2 +-
 src/box/lua/ctl.c |  4 ++--
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/box/box.cc b/src/box/box.cc
index a8bc3471d..8e0c9a160 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1001,15 +1001,25 @@ box_set_replication_anon(void)
 
 }
 
-void
+int
 box_clear_synchro_queue(bool try_wait)
 {
+	/* A guard to block multiple simultaneous function invocations. */
+	static bool in_clear_synchro_queue = false;
+	if (in_clear_synchro_queue) {
+		diag_set(ClientError, ER_UNSUPPORTED, "clear_synchro_queue",
+			 "simultaneous invocations");
+		return -1;
+	}
 	if (!is_box_configured || txn_limbo_is_empty(&txn_limbo))
-		return;
+		return 0;
 	uint32_t former_leader_id = txn_limbo.owner_id;
 	assert(former_leader_id != REPLICA_ID_NIL);
 	if (former_leader_id == instance_id)
-		return;
+		return 0;
+
+	in_clear_synchro_queue = true;
+	auto guard = make_scoped_guard([&] { in_clear_synchro_queue = false; });
 
 	if (try_wait) {
 		/* Wait until pending confirmations/rollbacks reach us. */
@@ -1050,6 +1060,7 @@ box_clear_synchro_queue(bool try_wait)
 		txn_limbo_force_empty(&txn_limbo, confirm_lsn);
 		assert(txn_limbo_is_empty(&txn_limbo));
 	}
+	return 0;
 }
 
 void
diff --git a/src/box/box.h b/src/box/box.h
index b47a220b7..95336688b 100644
--- a/src/box/box.h
+++ b/src/box/box.h
@@ -266,7 +266,7 @@ extern "C" {
 
 typedef struct tuple box_tuple_t;
 
-void
+int
 box_clear_synchro_queue(bool try_wait);
 
 /* box_select is private and used only by FFI */
diff --git a/src/box/lua/ctl.c b/src/box/lua/ctl.c
index bf26465e6..a3447f3e7 100644
--- a/src/box/lua/ctl.c
+++ b/src/box/lua/ctl.c
@@ -81,8 +81,8 @@ lbox_ctl_on_schema_init(struct lua_State *L)
 static int
 lbox_ctl_clear_synchro_queue(struct lua_State *L)
 {
-	(void) L;
-	box_clear_synchro_queue(true);
+	if (box_clear_synchro_queue(true) != 0)
+		return luaT_error(L);
 	return 0;
 }
 
-- 
2.24.3 (Apple Git-128)



More information about the Tarantool-patches mailing list