From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp50.i.mail.ru (smtp50.i.mail.ru [94.100.177.110]) (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 9E574469710 for ; Wed, 25 Nov 2020 15:04:08 +0300 (MSK) References: <20201124152405.1174898-1-gorcunov@gmail.com> <20201124152405.1174898-3-gorcunov@gmail.com> From: Serge Petrenko Message-ID: <248e1a42-c948-89ca-7894-251583c33246@tarantool.org> Date: Wed, 25 Nov 2020 15:04:07 +0300 MIME-Version: 1.0 In-Reply-To: <20201124152405.1174898-3-gorcunov@gmail.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [Tarantool-patches] [PATCH v2 2/3] cfg: support symbolic evaluation of replication_synchro_quorum List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cyrill Gorcunov , tml Cc: Vladislav Shpilevoy 24.11.2020 18:24, Cyrill Gorcunov пишет: > diff --git a/src/box/box.cc b/src/box/box.cc > index 1f7dec362..e4cb013c3 100644 > --- a/src/box/box.cc > +++ b/src/box/box.cc > @@ -562,10 +562,81 @@ box_check_replication_sync_lag(void) > return lag; > } > > +/** > + * Evaluate replication syncro quorum number from a formula. > + */ > +static int > +eval_replication_synchro_quorum(int nr_replicas) > +{ > + const char fmt[] = > + "local f, err = loadstring(\"return (%s)\")\n" > + "if not f then return 'failed to load \"%s\"' end\n" > + "setfenv(f, { n = %d })\n" > + "local ok, res = pcall(f)\n" > + "if not ok then return res end\n" > + "return math.floor(res)\n"; > + char buf[512]; > + int value = -1; > + > + const char *expr = cfg_gets("replication_synchro_quorum"); > + size_t ret = snprintf(buf, sizeof(buf), fmt, expr, > + expr, nr_replicas); > + if (ret >= sizeof(buf)) { > + diag_set(ClientError, ER_CFG, > + "replication_synchro_quorum", > + "the expression is too big"); > + return -1; > + } Just noticed. Looks like this diag_set and the one below are ignored: ``` tarantool> a=string.rep('n', 1000) --- ... tarantool> box.cfg{replication_synchro_quorum=a} --- - error: 'Incorrect value for option ''replication_synchro_quorum'': the value must     be greater than zero and less than maximal number of replicas' ... ``` > + > + luaL_loadstring(tarantool_L, buf); > + lua_call(tarantool_L, 0, 1); > + > + if (lua_isnumber(tarantool_L, -1)) { > + value = (int)lua_tonumber(tarantool_L, -1); > + } else { > + diag_set(ClientError, ER_CFG, > + "replication_synchro_quorum", > + lua_tostring(tarantool_L, -1)); > + return -1; > + } Same for this diag_set: ``` tarantool> box.cfg{replication_synchro_quorum="garbage"} --- - error: 'Incorrect value for option ''replication_synchro_quorum'': the value must     be greater than zero and less than maximal number of replicas' ... ``` -- Serge Petrenko