From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id CF9E245C305 for ; Mon, 7 Dec 2020 23:17:16 +0300 (MSK) Received: by mail-lj1-f195.google.com with SMTP id a1so15111573ljq.3 for ; Mon, 07 Dec 2020 12:17:16 -0800 (PST) Date: Mon, 7 Dec 2020 23:17:13 +0300 From: Cyrill Gorcunov Message-ID: <20201207201713.GE2303@grain> References: <20201203140446.66312-1-gorcunov@gmail.com> <20201203140446.66312-3-gorcunov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Tarantool-patches] [PATCH v3 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: Vladislav Shpilevoy Cc: Mons Anderson , tml Here is a diff I force pushed --- diff --git a/src/box/box.cc b/src/box/box.cc index b9d078de4..2dfb5bc1c 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -578,17 +578,9 @@ eval_replication_synchro_quorum(int nr_replicas) "fmod = math.fmod," "}})\n" "return math.floor(f())\n"; - char buf[1024]; int value = -1; - const char *expr = cfg_gets("replication_synchro_quorum"); - size_t ret = snprintf(buf, sizeof(buf), fmt, expr, nr_replicas); - if (ret >= sizeof(buf)) { - diag_set(ClientError, ER_CFG, - "replication_synchro_quorum", - "the expression is too big"); - return -1; - } + const char *buf = tt_sprintf(fmt, expr, nr_replicas); luaL_loadstring(tarantool_L, buf); if (lua_pcall(tarantool_L, 0, 1, 0) != 0) { @@ -608,17 +600,11 @@ eval_replication_synchro_quorum(int nr_replicas) * value (say it was n-2) do not treat it as an * error but just yield a minimum valid magnitude. */ - if (value < 0) { - const int value_min = 1; - say_warn_ratelimited("replication_synchro_quorum evaluated " - "to the negative value %d, set to %d", - value, value_min); - value = value_min; - } else if (value >= VCLOCK_MAX) { + if (value >= VCLOCK_MAX) { const int value_max = VCLOCK_MAX - 1; - say_warn_ratelimited("replication_synchro_quorum evaluated " - "to value %d, set to %d", - value, value_max); + say_warn("replication_synchro_quorum evaluated " + "to value %d, set to %d", + value, value_max); value = value_max; } We use tt_sprintf and drop value < 0 test (because we return MAX(1, value) @@ -1001,30 +987,6 @@ box_set_replication_sync_lag(void) replication_sync_lag = box_check_replication_sync_lag(); } -/** - * Assign new replication_synchro_quorum value - * and notify dependent subsystems. - */ -static void -set_replication_synchro_quorum(int quorum) -{ - assert(quorum > 0 && quorum < VCLOCK_MAX); - - replication_synchro_quorum = quorum; - txn_limbo_on_parameters_change(&txn_limbo); - box_raft_update_election_quorum(); -} - -int -box_set_replication_synchro_quorum(void) -{ - int value = box_check_replication_synchro_quorum(); - if (value < 0) - return -1; - set_replication_synchro_quorum(value); - return 0; -} - /** * Renew replication_synchro_quorum value if defined * as a formula and we need to recalculate it. @@ -1053,7 +1015,20 @@ box_update_replication_synchro_quorum(void) if (quorum < 0 || quorum >= VCLOCK_MAX) panic("failed to eval replication_synchro_quorum"); say_info("update replication_synchro_quorum = %d", quorum); - set_replication_synchro_quorum(quorum); + + replication_synchro_quorum = quorum; + txn_limbo_on_parameters_change(&txn_limbo); + box_raft_update_election_quorum(); +} + +int +box_set_replication_synchro_quorum(void) +{ + int value = box_check_replication_synchro_quorum(); + if (value < 0) + return -1; + box_update_replication_synchro_quorum(); + return 0; } Use box_update_replication_synchro_quorum from inside of box_set_replication_synchro_quorum. I'm working on test now but it is yet incomplete.