From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>,
tml <tarantool-patches@dev.tarantool.org>
Cc: Mons Anderson <v.perepelitsa@corp.mail.ru>
Subject: Re: [Tarantool-patches] [PATCH v4 2/3] cfg: support symbolic evaluation of replication_synchro_quorum
Date: Mon, 21 Dec 2020 18:48:04 +0100 [thread overview]
Message-ID: <619b78fe-d559-7eb6-5e28-e239ed7f6e46@tarantool.org> (raw)
In-Reply-To: <20201214113935.1040421-3-gorcunov@gmail.com>
Hi! Thanks for the patch!
All looks good now except 2 small comments below.
> diff --git a/src/box/box.cc b/src/box/box.cc
> index a8bc3471d..b820af5d0 100644
> --- a/src/box/box.cc
> +++ b/src/box/box.cc
> @@ -554,10 +554,119 @@ box_check_replication_sync_lag(void)
> return lag;
> }
>
> +/**
> + * Evaluate replication syncro quorum number from a formula.
> + */
> +static int
> +box_eval_replication_synchro_quorum(int nr_replicas)
> +{
> + const char fmt[] =
> + "local expr = [[%s]]\n"
> + "local f, err = loadstring('return ('..expr..')')\n"
> + "if not f then "
> + "error(string.format('Failed to load \%\%s:"
> + "\%\%s', expr, err)) "
> + "end\n"
> + "setfenv(f, {N = %d, math = {"
> + "ceil = math.ceil,"
> + "floor = math.floor,"
> + "abs = math.abs,"
> + "random = math.random,"
> + "min = math.min,"
> + "max = math.abs,"
> + "sqrt = math.sqrt,"
> + "fmod = math.fmod,"
> + "}})\n"
> + "local res = f()\n"
> + "if type(res) ~= 'number' then\n"
> + "error('Expression should return a number')\n"
> + "end\n"
> + "return math.floor(res)\n";
> + const char *expr = cfg_gets("replication_synchro_quorum");
> + int quorum = -1;
> +
> + /*
> + * cfg_gets uses static buffer as well so we need a local
> + * one, 1K should be enough to carry arbitrary but sane
> + * formula.
> + */
> + char buf[1024];
> + int len = snprintf(buf, sizeof(buf), fmt, expr,
> + nr_replicas);
> + if (len >= (int)sizeof(buf)) {
> + diag_set(ClientError, ER_CFG,
> + "replication_synchro_quorum",
> + "the formula is too big");
> + return -1;
> + }
> +
> + luaL_loadstring(tarantool_L, buf);
> + if (lua_pcall(tarantool_L, 0, 1, 0) != 0) {
> + diag_set(ClientError, ER_CFG,
> + "replication_synchro_quorum",
> + lua_tostring(tarantool_L, -1));
> + return -1;
> + }
> +
> + if (lua_isnumber(tarantool_L, -1))
> + quorum = (int)lua_tonumber(tarantool_L, -1);
1. There is a small issue:
tarantool> box.cfg{replication_synchro_quorum='4294967297'}
2020-12-21 18:33:16.015 [47366] main/103/interactive I> set 'replication_synchro_quorum' configuration option to "4294967297"
---
...
UINT32_MAX + 1 turns to 0. +2 turns to 1. So it
is accepted because you silently truncate to `int`.
> @@ -913,7 +1013,25 @@ box_set_replication_sync_lag(void)
> void
> box_update_replication_synchro_quorum(void)
> {
> - int quorum = cfg_geti("replication_synchro_quorum");
> + int quorum = -1;
> +
> + if (!cfg_isnumber("replication_synchro_quorum")) {
> + /*
> + * The formula has been verified already. For bootstrap
> + * stage pass 1 as a number of replicas to sync because
> + * we're at early stage and registering a new replica.
> + *
> + * This should cover the valid case where formula is plain
> + * "N", ie all replicas are to be synchro mode.
> + */
> + int value = MAX(1, replicaset.registered_count);
> + quorum = box_eval_replication_synchro_quorum(value);
> + if (quorum <= 0 || quorum >= VCLOCK_MAX)
> + panic("failed to eval replication_synchro_quorum");
2. This check better be below. Because the numeric value also was
validated, right?
> + say_info("update replication_synchro_quorum = %d", quorum);
> + } else {
> + quorum = cfg_geti("replication_synchro_quorum");
> + }
next prev parent reply other threads:[~2020-12-21 17:48 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-14 11:39 [Tarantool-patches] [PATCH v4 0/3] qsync: evaluate replication_synchro_quorum dynamically Cyrill Gorcunov
2020-12-14 11:39 ` [Tarantool-patches] [PATCH v4 1/3] cfg: add cfg_isnumber helper Cyrill Gorcunov
2020-12-14 11:39 ` [Tarantool-patches] [PATCH v4 2/3] cfg: support symbolic evaluation of replication_synchro_quorum Cyrill Gorcunov
2020-12-16 13:21 ` Serge Petrenko
2020-12-16 13:35 ` Cyrill Gorcunov
2020-12-17 23:17 ` Vladislav Shpilevoy
2020-12-18 7:25 ` Cyrill Gorcunov
2020-12-20 17:01 ` Vladislav Shpilevoy
2020-12-20 18:28 ` Cyrill Gorcunov
2020-12-21 17:48 ` Vladislav Shpilevoy [this message]
2020-12-21 17:49 ` Vladislav Shpilevoy
2020-12-21 20:02 ` Cyrill Gorcunov
2020-12-21 20:12 ` Cyrill Gorcunov
2020-12-14 11:39 ` [Tarantool-patches] [PATCH v4 3/3] test: add replication/gh-5446-qsync-eval-quorum.test.lua Cyrill Gorcunov
2020-12-16 13:25 ` Serge Petrenko
2020-12-17 23:18 ` Vladislav Shpilevoy
2020-12-18 8:14 ` Cyrill Gorcunov
2020-12-20 17:01 ` Vladislav Shpilevoy
2020-12-20 18:27 ` Cyrill Gorcunov
2020-12-21 16:05 ` Cyrill Gorcunov
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=619b78fe-d559-7eb6-5e28-e239ed7f6e46@tarantool.org \
--to=v.shpilevoy@tarantool.org \
--cc=gorcunov@gmail.com \
--cc=tarantool-patches@dev.tarantool.org \
--cc=v.perepelitsa@corp.mail.ru \
--subject='Re: [Tarantool-patches] [PATCH v4 2/3] cfg: support symbolic evaluation of replication_synchro_quorum' \
/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