From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Subject: [Tarantool-patches] [PATCH 2/2] fiber: use wakeup safely on self everywhere Date: Sat, 24 Apr 2021 01:15:54 +0200 [thread overview] Message-ID: <526181aae66a7feb718fc1983f7b4b61ad47f5d9.1619219639.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1619219639.git.v.shpilevoy@tarantool.org> The previous commit made fiber_wakeup() safe to use on the current fiber. Leverage the new behaviour everywhere in the source code to remove all checks f != fiber() before fiber_wakeup(f) calls. Follow-up #5292 --- src/box/applier.cc | 4 +--- src/box/journal.c | 6 ++++++ src/box/journal.h | 7 +++++++ src/box/raft.c | 14 +++----------- src/box/txn.c | 6 ++---- src/box/txn_limbo.c | 14 +------------- src/lib/swim/swim.c | 1 - 7 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/box/applier.cc b/src/box/applier.cc index dc05c91d3..33181fdbf 100644 --- a/src/box/applier.cc +++ b/src/box/applier.cc @@ -792,9 +792,7 @@ apply_synchro_row_cb(struct journal_entry *entry) txn_limbo_process(&txn_limbo, synchro_entry->req); trigger_run(&replicaset.applier.on_wal_write, NULL); } - /* The fiber is the same on final join. */ - if (synchro_entry->owner != fiber()) - fiber_wakeup(synchro_entry->owner); + fiber_wakeup(synchro_entry->owner); } /** Process a synchro request. */ diff --git a/src/box/journal.c b/src/box/journal.c index 886a15139..df491610a 100644 --- a/src/box/journal.c +++ b/src/box/journal.c @@ -63,6 +63,12 @@ journal_entry_new(size_t n_rows, struct region *region, return entry; } +void +journal_entry_fiber_wakeup_cb(struct journal_entry *entry) +{ + fiber_wakeup(entry->complete_data); +} + void journal_queue_wakeup(void) { diff --git a/src/box/journal.h b/src/box/journal.h index 8f3d56a61..4ab7e8afb 100644 --- a/src/box/journal.h +++ b/src/box/journal.h @@ -112,6 +112,13 @@ journal_entry_new(size_t n_rows, struct region *region, journal_write_async_f write_async_cb, void *complete_data); +/** + * Treat complete_data like a fiber pointer and wake it up when journal write is + * done. + */ +void +journal_entry_fiber_wakeup_cb(struct journal_entry *entry); + struct journal_queue { /** Maximal size of entries enqueued in journal (in bytes). */ int64_t max_size; diff --git a/src/box/raft.c b/src/box/raft.c index 47c869712..6b52c9876 100644 --- a/src/box/raft.c +++ b/src/box/raft.c @@ -155,8 +155,7 @@ box_raft_schedule_async(struct raft *raft) * adapted to this. Also don't wakeup the current fiber - it leads to * undefined behaviour. */ - if ((box_raft_worker->flags & FIBER_IS_CANCELLABLE) != 0 && - fiber() != box_raft_worker) + if ((box_raft_worker->flags & FIBER_IS_CANCELLABLE) != 0) fiber_wakeup(box_raft_worker); box_raft_has_work = true; } @@ -279,13 +278,6 @@ box_raft_broadcast(struct raft *raft, const struct raft_msg *msg) relay_push_raft(replica->relay, &req); } -/** Wakeup Raft state writer fiber waiting for WAL write end. */ -static void -box_raft_write_cb(struct journal_entry *entry) -{ - fiber_wakeup(entry->complete_data); -} - static void box_raft_write(struct raft *raft, const struct raft_msg *msg) { @@ -307,8 +299,8 @@ box_raft_write(struct raft *raft, const struct raft_msg *msg) if (xrow_encode_raft(&row, region, &req) != 0) goto fail; - journal_entry_create(entry, 1, xrow_approx_len(&row), box_raft_write_cb, - fiber()); + journal_entry_create(entry, 1, xrow_approx_len(&row), + journal_entry_fiber_wakeup_cb, fiber()); /* * A non-cancelable fiber is considered non-wake-able, generally. Raft diff --git a/src/box/txn.c b/src/box/txn.c index 03b39e0de..07ab131a2 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -504,9 +504,7 @@ txn_free_or_wakeup(struct txn *txn) txn_free(txn); else { txn_set_flags(txn, TXN_IS_DONE); - if (txn->fiber != fiber()) - /* Wake a waiting fiber up. */ - fiber_wakeup(txn->fiber); + fiber_wakeup(txn->fiber); } } @@ -578,7 +576,7 @@ txn_on_journal_write(struct journal_entry *entry) txn_run_wal_write_triggers(txn); if (!txn_has_flag(txn, TXN_WAIT_SYNC)) txn_complete_success(txn); - else if (txn->fiber != NULL && txn->fiber != fiber()) + else if (txn->fiber != NULL) fiber_wakeup(txn->fiber); finish: fiber_set_txn(fiber(), NULL); diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c index c22bd6665..5b23d1bb1 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -306,18 +306,6 @@ complete: return 0; } -/** - * A callback for synchronous write: txn_limbo_write_synchro fiber - * waiting to proceed once a record is written to WAL. - */ -static void -txn_limbo_write_cb(struct journal_entry *entry) -{ - assert(entry->complete_data != NULL); - if (fiber() != entry->complete_data) - fiber_wakeup(entry->complete_data); -} - static void txn_limbo_write_synchro(struct txn_limbo *limbo, uint16_t type, int64_t lsn, uint64_t term) @@ -346,7 +334,7 @@ txn_limbo_write_synchro(struct txn_limbo *limbo, uint16_t type, int64_t lsn, xrow_encode_synchro(&row, body, &req); journal_entry_create(entry, 1, xrow_approx_len(&row), - txn_limbo_write_cb, fiber()); + journal_entry_fiber_wakeup_cb, fiber()); if (journal_write(entry) != 0 || entry->res < 0) { diag_set(ClientError, ER_WAL_IO); diff --git a/src/lib/swim/swim.c b/src/lib/swim/swim.c index 1ecc90414..3955c3130 100644 --- a/src/lib/swim/swim.c +++ b/src/lib/swim/swim.c @@ -2219,7 +2219,6 @@ swim_kill_event_handler(struct swim *swim) * reused. */ swim->event_handler = NULL; - fiber_wakeup(f); fiber_cancel(f); fiber_join(f); } -- 2.24.3 (Apple Git-128)
next prev parent reply other threads:[~2021-04-23 23:16 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-04-23 23:15 [Tarantool-patches] [PATCH 0/2] fiber_wakeup() nop on self Vladislav Shpilevoy via Tarantool-patches 2021-04-23 23:15 ` [Tarantool-patches] [PATCH 1/2] fiber: make wakeup in Lua and C " Vladislav Shpilevoy via Tarantool-patches 2021-04-25 9:21 ` Serge Petrenko via Tarantool-patches 2021-04-25 15:53 ` Vladislav Shpilevoy via Tarantool-patches 2021-04-26 9:21 ` Serge Petrenko via Tarantool-patches 2021-04-23 23:15 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-04-25 9:23 ` [Tarantool-patches] [PATCH 2/2] fiber: use wakeup safely on self everywhere Serge Petrenko via Tarantool-patches 2021-04-26 21:56 ` [Tarantool-patches] [PATCH 0/2] fiber_wakeup() nop on self Cyrill Gorcunov via Tarantool-patches 2021-04-27 12:03 ` Kirill Yukhin via Tarantool-patches
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=526181aae66a7feb718fc1983f7b4b61ad47f5d9.1619219639.git.v.shpilevoy@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=gorcunov@gmail.com \ --cc=sergepetrenko@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 2/2] fiber: use wakeup safely on self everywhere' \ /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