From: Serge Petrenko <sergepetrenko@tarantool.org> To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>, tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH v2 10/16] raft: make worker non-cancellable during WAL write Date: Fri, 20 Nov 2020 11:33:26 +0300 [thread overview] Message-ID: <1de0fec2-86e3-358c-59a8-24e83fcd1fef@tarantool.org> (raw) In-Reply-To: <268bcf29eb045de623c18c58942c07b2491658f0.1605829282.git.v.shpilevoy@tarantool.org> 20.11.2020 02:45, Vladislav Shpilevoy пишет: > This is a general practice throughout the code. If a fiber is not > cancellable, it always means a system fiber which can't be woken > up or canceled until its work done. It is used in gc (about > xlogs), recovery, vinyl, WAL, at least. > > Before raft used flag raft.is_write_in_progress. But it won't > work soon, because the worker fiber will move to box/raft.c, > where it would be incorrect to rely on deeply internal parts of > struct raft, such as is_write_in_progress. > > Hence, this patch makes raft use a more traditional way of > spurious wakeup avoidance. > > Part of #5303 Hi! Thanks for the patch! > --- > src/box/raft.c | 9 ++++++++- > src/box/raftlib.c | 10 ++++++---- > 2 files changed, 14 insertions(+), 5 deletions(-) > > diff --git a/src/box/raft.c b/src/box/raft.c > index 2c9ed11b6..8a034687b 100644 > --- a/src/box/raft.c > +++ b/src/box/raft.c > @@ -213,7 +213,14 @@ box_raft_write(struct raft *raft, const struct raft_msg *msg) > journal_entry_create(entry, 1, xrow_approx_len(&row), box_raft_write_cb, > fiber()); > > - if (journal_write(entry) != 0 || entry->res < 0) { > + /* > + * A non-cancelable fiber is considered non-wake-able, generally. Raft > + * follows this pattern of 'protection'. > + */ > + bool cancellable = fiber_set_cancellable(false); > + bool ok = (journal_write(entry) == 0 && entry->res >= 0); > + fiber_set_cancellable(cancellable); > + if (!ok) { > diag_set(ClientError, ER_WAL_IO); > diag_log(); > goto fail; > diff --git a/src/box/raftlib.c b/src/box/raftlib.c > index d28e51871..a1fca34cd 100644 > --- a/src/box/raftlib.c > +++ b/src/box/raftlib.c > @@ -986,11 +986,13 @@ raft_worker_wakeup(struct raft *raft) > fiber_set_joinable(raft->worker, true); > } > /* > - * Don't wake the fiber if it writes something. Otherwise it would be a > - * spurious wakeup breaking the WAL write not adapted to this. Also > - * don't wakeup the current fiber - it leads to undefined behaviour. > + * Don't wake the fiber if it writes something (not cancellable). > + * Otherwise it would be a spurious wakeup breaking the WAL write not > + * adapted to this. Also don't wakeup the current fiber - it leads to > + * undefined behaviour. > */ > - if (!raft->is_write_in_progress && fiber() != raft->worker) > + if ((raft->worker->flags & FIBER_IS_CANCELLABLE) != 0 && > + fiber() != raft->worker) > fiber_wakeup(raft->worker); > } > LGTM. -- Serge Petrenko
next prev parent reply other threads:[~2020-11-20 8:33 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-19 23:45 [Tarantool-patches] [PATCH v2 00/16] Raft module, part 2 - relocation to src/lib/raft Vladislav Shpilevoy 2020-11-19 23:45 ` [Tarantool-patches] [PATCH v2 01/16] raft: move sources to raftlib.h/.c Vladislav Shpilevoy 2020-11-19 23:45 ` [Tarantool-patches] [PATCH v2 10/16] raft: make worker non-cancellable during WAL write Vladislav Shpilevoy 2020-11-20 8:33 ` Serge Petrenko [this message] 2020-11-19 23:45 ` [Tarantool-patches] [PATCH v2 11/16] raft: move worker fiber from Raft library to box Vladislav Shpilevoy 2020-11-20 9:06 ` Serge Petrenko 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 12/16] raft: move synchro queue clear to the worker fiber Vladislav Shpilevoy 2020-11-20 9:07 ` Serge Petrenko 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 13/16] raft: invoke update triggers within state machine Vladislav Shpilevoy 2020-11-20 9:10 ` Serge Petrenko 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 14/16] raft: move RO summary update to box-Raft Vladislav Shpilevoy 2020-11-20 9:13 ` Serge Petrenko 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 15/16] raft: introduce RaftError Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 16/16] raft: move algorithm code to src/lib/raft Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 02/16] raft: move box_raft_* to src/box/raft.h and .c Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 03/16] raft: stop using replication_disconnect_timeout() Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 04/16] raft: stop using replication_synchro_quorum Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 05/16] raft: stop using instance_id Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 06/16] raft: make raft_request.vclock constant Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 07/16] raft: stop using replicaset.vclock Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 08/16] raft: introduce vtab for disk and network Vladislav Shpilevoy 2020-11-19 23:46 ` [Tarantool-patches] [PATCH v2 09/16] raft: introduce raft_msg, drop xrow dependency Vladislav Shpilevoy 2020-11-20 9:14 ` [Tarantool-patches] [PATCH v2 00/16] Raft module, part 2 - relocation to src/lib/raft Serge Petrenko 2020-11-20 19:42 ` Vladislav Shpilevoy 2020-11-23 5:30 ` Alexander V. Tikhonov 2020-11-23 23:26 ` Vladislav Shpilevoy
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=1de0fec2-86e3-358c-59a8-24e83fcd1fef@tarantool.org \ --to=sergepetrenko@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 10/16] raft: make worker non-cancellable during WAL write' \ /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