Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH 1/1] txn_limbo: reduce fiber_set_cancellable() calls
@ 2020-07-29 23:41 Vladislav Shpilevoy
  2020-07-30  8:47 ` Cyrill Gorcunov
  2020-07-30 19:57 ` Vladislav Shpilevoy
  0 siblings, 2 replies; 3+ messages in thread
From: Vladislav Shpilevoy @ 2020-07-29 23:41 UTC (permalink / raw)
  To: tarantool-patches, gorcunov

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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Tarantool-patches] [PATCH 1/1] txn_limbo: reduce fiber_set_cancellable() calls
  2020-07-29 23:41 [Tarantool-patches] [PATCH 1/1] txn_limbo: reduce fiber_set_cancellable() calls Vladislav Shpilevoy
@ 2020-07-30  8:47 ` Cyrill Gorcunov
  2020-07-30 19:57 ` Vladislav Shpilevoy
  1 sibling, 0 replies; 3+ messages in thread
From: Cyrill Gorcunov @ 2020-07-30  8:47 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On Thu, Jul 30, 2020 at 01:41:20AM +0200, Vladislav Shpilevoy wrote:
> 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.
> ---
Ack

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Tarantool-patches] [PATCH 1/1] txn_limbo: reduce fiber_set_cancellable() calls
  2020-07-29 23:41 [Tarantool-patches] [PATCH 1/1] txn_limbo: reduce fiber_set_cancellable() calls Vladislav Shpilevoy
  2020-07-30  8:47 ` Cyrill Gorcunov
@ 2020-07-30 19:57 ` Vladislav Shpilevoy
  1 sibling, 0 replies; 3+ messages in thread
From: Vladislav Shpilevoy @ 2020-07-30 19:57 UTC (permalink / raw)
  To: tarantool-patches, gorcunov

Pushed to master and 2.5.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-30 19:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 23:41 [Tarantool-patches] [PATCH 1/1] txn_limbo: reduce fiber_set_cancellable() calls Vladislav Shpilevoy
2020-07-30  8:47 ` Cyrill Gorcunov
2020-07-30 19:57 ` Vladislav Shpilevoy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox