Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@dev.tarantool.org, alexander.turenko@tarantool.org
Subject: [Tarantool-patches] [PATCH 3/4] box: yield after initial box_cfg() is finished
Date: Sun, 12 Apr 2020 22:13:29 +0200	[thread overview]
Message-ID: <ebfee57bf1006737c7e8b11839d12b5e8905da16.1586722379.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1586722379.git.v.shpilevoy@tarantool.org>

box.cfg() works in two stages, when called first time - boot the
instance using box_cfg() C++ function, and then configure it.
During booting all non-dynamic parameters are read. Dynamic are
configured mostly afterwards.

Normally there should be a yield between box_cfg() C++ call and
dynamic parameters configuration. It is used by box.ctl.wait_ro()
and box.ctl.wait_rw() Lua calls to catch the instance in read-only
state always before read-write state.

In theory a user should be able to call box.ctl.wait_ro() and
box.ctl.wait_rw() in one fiber, box.cfg() in another, and these
waits would be unblocked one after another.

It works fine now, but only because of, surprisingly, the feedback
daemon. The daemon creates a yield after C++ box_cfg() is
finished, but dynamic parameters are still being applied in
load_cfg.lua. That gives time to catch box.ctl.wait_ro() event.

The thing is that dynamic parameters configuration includes the
daemon's options too. When 'feedback_enable' option is installed
to true, the daemon is started using fiber.create(). That creates
a yield, and gives time to box.ctl.wait_ro() fibers to handle the
event.

When the daemon is disabled or removed, like it is going to happen
in #3308, this trick does not work, and box.ctl.wait_ro() started
before box.cfg() is never triggered.

It could be tested on app-tap/cfg.test.lua with

    box.cfg{}

changed to

    box.cfg{feedback_enabled = false}

Then the test would hang. A test is not patched here, because the
feedback is going to be optionally removed in a next commit, and
the test would become flaky depending on build options.

Needed for #3308
---
 src/box/box.cc | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/box/box.cc b/src/box/box.cc
index 0c15ba5e9..891289bf6 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -2450,8 +2450,21 @@ box_cfg_xc(void)
 	if (!is_bootstrap_leader)
 		replicaset_sync();
 
-	/* If anyone is waiting for ro mode to go away */
+	/* box.cfg.read_only is not read yet. */
+	assert(box_is_ro());
+	/* If anyone is waiting for ro mode. */
 	fiber_cond_broadcast(&ro_cond);
+	/*
+	 * Yield to let ro condition waiters to handle the event.
+	 * Without yield it may happen there won't be a context
+	 * switch until the ro state is changed again, and as a
+	 * result, some ro waiters may sleep forever. For example,
+	 * when Tarantool is just started, it is expected it will
+	 * enter ro=true state, and then ro=false. Without the
+	 * yield the ro=true event may be lost. This affects
+	 * box.ctl.wait_ro() call.
+	 */
+	fiber_sleep(0);
 }
 
 void
-- 
2.21.1 (Apple Git-122.3)

  parent reply	other threads:[~2020-04-12 20:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-12 20:13 [Tarantool-patches] [PATCH 0/4] CMake option to remove feedback daemon Vladislav Shpilevoy
2020-04-12 20:13 ` [Tarantool-patches] [PATCH 1/4] box: improve built-in module load panic message Vladislav Shpilevoy
2020-04-12 20:13 ` [Tarantool-patches] [PATCH 2/4] feedback: move feedback code to the single file Vladislav Shpilevoy
2020-04-12 20:13 ` Vladislav Shpilevoy [this message]
2020-04-12 20:13 ` [Tarantool-patches] [PATCH 4/4] feedback: add cmake option to disable the daemon Vladislav Shpilevoy
2020-04-15 17:28   ` Serge Petrenko
2020-04-15 20:04     ` Vladislav Shpilevoy
2020-04-12 20:19 ` [Tarantool-patches] [PATCH 0/4] CMake option to remove feedback daemon Vladislav Shpilevoy
2020-04-17  7:04 ` Kirill Yukhin

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=ebfee57bf1006737c7e8b11839d12b5e8905da16.1586722379.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 3/4] box: yield after initial box_cfg() is finished' \
    /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