From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 B18ED445320 for ; Thu, 30 Jul 2020 02:41:21 +0300 (MSK) From: Vladislav Shpilevoy Date: Thu, 30 Jul 2020 01:41:20 +0200 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/1] txn_limbo: reduce fiber_set_cancellable() calls List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com The calls were added before and after each cond_wait() so as the fiber couldn't be woken up externally. For example, from Lua. But it is not necessary to flip the flag on each wait() call. It is enough to make it 2 times: forbid cancellation in the beginning of txn_limbo_wait_complete(), and return the old value back in the end. --- Branch: http://github.com/tarantool/tarantool/tree/gerold103/qsync-fiber_set_cancellable-refactor src/box/txn_limbo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c index b6725ae21..7f43e1c0c 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -185,6 +185,8 @@ int txn_limbo_wait_complete(struct txn_limbo *limbo, struct txn_limbo_entry *entry) { assert(entry->lsn > 0 || !txn_has_flag(entry->txn, TXN_WAIT_ACK)); + bool cancellable = fiber_set_cancellable(false); + if (txn_limbo_entry_is_complete(entry)) goto complete; @@ -193,10 +195,8 @@ txn_limbo_wait_complete(struct txn_limbo *limbo, struct txn_limbo_entry *entry) double start_time = fiber_clock(); while (true) { double deadline = start_time + replication_synchro_timeout; - bool cancellable = fiber_set_cancellable(false); double timeout = deadline - fiber_clock(); int rc = fiber_cond_wait_timeout(&limbo->wait_cond, timeout); - fiber_set_cancellable(cancellable); if (txn_limbo_entry_is_complete(entry)) goto complete; if (rc != 0) @@ -215,11 +215,9 @@ do_rollback: * rollback. Wait when it will finish and wake us * up. */ - bool cancellable = fiber_set_cancellable(false); do { fiber_yield(); } while (!txn_limbo_entry_is_complete(entry)); - fiber_set_cancellable(cancellable); goto complete; } @@ -236,6 +234,7 @@ do_rollback: break; fiber_wakeup(e->txn->fiber); } + fiber_set_cancellable(cancellable); diag_set(ClientError, ER_SYNC_QUORUM_TIMEOUT); return -1; @@ -247,6 +246,7 @@ complete: */ assert(rlist_empty(&entry->in_queue)); assert(txn_has_flag(entry->txn, TXN_IS_DONE)); + fiber_set_cancellable(cancellable); /* * The first tx to be rolled back already performed all * the necessary cleanups for us. -- 2.21.1 (Apple Git-122.3)