From: Serge Petrenko <sergepetrenko@tarantool.org> To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v2 1/6] box: add a single execution guard to clear_synchro_queue Date: Wed, 23 Dec 2020 14:59:19 +0300 [thread overview] Message-ID: <97a87e9662eec96f645d59eb44a57c22b1ecf791.1608724239.git.sergepetrenko@tarantool.org> (raw) In-Reply-To: <cover.1608724238.git.sergepetrenko@tarantool.org> 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 | 18 +++++++++++++++--- src/box/box.h | 2 +- src/box/lua/ctl.c | 4 ++-- src/box/raft.c | 9 +++++++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 306db7c37..2d403fc9a 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -1002,15 +1002,24 @@ 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; if (try_wait) { /* Wait until pending confirmations/rollbacks reach us. */ @@ -1051,6 +1060,9 @@ box_clear_synchro_queue(bool try_wait) txn_limbo_force_empty(&txn_limbo, confirm_lsn); assert(txn_limbo_is_empty(&txn_limbo)); } + + in_clear_synchro_queue = false; + 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 bb4841994..b44474b12 100644 --- a/src/box/lua/ctl.c +++ b/src/box/lua/ctl.c @@ -83,8 +83,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; } diff --git a/src/box/raft.c b/src/box/raft.c index 8f32a9662..1942df952 100644 --- a/src/box/raft.c +++ b/src/box/raft.c @@ -89,9 +89,14 @@ box_raft_update_synchro_queue(struct raft *raft) * If the node became a leader, it means it will ignore all records from * all the other nodes, and won't get late CONFIRM messages anyway. Can * clear the queue without waiting for confirmations. + * It's alright that the user may have called clear_synchro_queue + * manually. In this case the call below will exit immediately and we'll + * simply log a warning. */ - if (raft->state == RAFT_STATE_LEADER) - box_clear_synchro_queue(false); + if (raft->state == RAFT_STATE_LEADER) { + if (box_clear_synchro_queue(false) != 0) + diag_log(); + } } static int -- 2.24.3 (Apple Git-128)
next prev parent reply other threads:[~2020-12-23 11:59 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-12-23 11:59 [Tarantool-patches] [PATCH v2 0/6] make clear_synchro_queue commit everything Serge Petrenko 2020-12-23 11:59 ` Serge Petrenko [this message] 2020-12-23 11:59 ` [Tarantool-patches] [PATCH v2 2/6] relay: introduce on_status_update trigger Serge Petrenko 2020-12-23 17:25 ` Vladislav Shpilevoy 2020-12-24 16:11 ` Serge Petrenko 2020-12-23 11:59 ` [Tarantool-patches] [PATCH v2 3/6] txn_limbo: introduce txn_limbo_last_synchro_entry method Serge Petrenko 2020-12-23 17:25 ` Vladislav Shpilevoy 2020-12-24 16:13 ` Serge Petrenko 2020-12-23 11:59 ` [Tarantool-patches] [PATCH v2 4/6] box: rework clear_synchro_queue to commit everything Serge Petrenko 2020-12-23 17:28 ` Vladislav Shpilevoy 2020-12-24 16:12 ` Serge Petrenko 2020-12-24 17:35 ` Vladislav Shpilevoy 2020-12-24 21:02 ` Serge Petrenko 2020-12-23 11:59 ` [Tarantool-patches] [PATCH v2 5/6] test: fix replication/election_qsync_stress test Serge Petrenko 2020-12-23 11:59 ` [Tarantool-patches] [PATCH v2 6/6] txn_limbo: ignore CONFIRM/ROLLBACK for a foreign master Serge Petrenko 2020-12-23 17:28 ` Vladislav Shpilevoy 2020-12-24 16:13 ` Serge Petrenko 2020-12-25 10:04 ` [Tarantool-patches] [PATCH v2 0/6] make clear_synchro_queue commit everything Kirill Yukhin
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=97a87e9662eec96f645d59eb44a57c22b1ecf791.1608724239.git.sergepetrenko@tarantool.org \ --to=sergepetrenko@tarantool.org \ --cc=gorcunov@gmail.com \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 1/6] box: add a single execution guard to clear_synchro_queue' \ /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