From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 41CAC6B944; Sat, 24 Apr 2021 02:16:59 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 41CAC6B944 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1619219819; bh=i/Lcz+a+sLO164d3ZfiRmLIDj9TINGL0gzOlV5A9UN4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=G4Qn+6oLXJ7wrKrMiSUzdfu/0Gwh9vkcxltLTgrUkguG6BZthVfdXQxmY8v/07Ilq Ew0DJBd+JJDnEITz1g9YiZ5a2njF/RWD2n3PtOtVB85UnF1qKyFy5VB1dNnPE+Bk5F UYTnCZjhVWml/ljyD9X3Y72ZZSb5uwY20AgRT5IA= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5FFBC74B70 for ; Sat, 24 Apr 2021 02:15:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5FFBC74B70 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1la51h-0006fA-IE; Sat, 24 Apr 2021 02:15:58 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Date: Sat, 24 Apr 2021 01:15:54 +0200 Message-Id: <526181aae66a7feb718fc1983f7b4b61ad47f5d9.1619219639.git.v.shpilevoy@tarantool.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9203E2ABA940B75487ADF04F292A7BD7756ABB318AC2F9BF9182A05F538085040B96B5A938FF1AC7D82444CB522002A92FA1CDC3C0FFAA619B7531D95CDE8E7A3 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7519D5B419DD3416AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637329F9579A0E72DCC8638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B212162E9E6B68A8A64E0F110D37962C8CEABCB1FA743BAAB4D2E47CDBA5A96583C09775C1D3CA48CF7EF884183F8E4D67117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE7820CF4CC0E318EFB9FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA71A620F70A64A45A98AA50765F79006372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F83C798A30B85E16BCE5475246E174218B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CB6E146CBBBB42ED64EE5B95633DC1CDB70769D6DE040BB889C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F6110710A6CC527F00E2336EE0EFAE45008E59082D9D360A608A92B4DD0DCEF189D25CD62DD7C6091D7E09C32AA3244C7F0B3A27B3D5CB352B30DC3FCE88E68EF522A1CF68F4BE05FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojfZPPuXuuvpR5vnjnjZJdeQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822BB2D5F1A6BF0F09C99F5603A063573423841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 2/2] fiber: use wakeup safely on self everywhere X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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)