Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: Mons Anderson <v.perepelitsa@corp.mail.ru>,
	tml <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH v4 3/3] test: add replication/gh-5446-qsync-eval-quorum.test.lua
Date: Mon, 21 Dec 2020 19:05:55 +0300	[thread overview]
Message-ID: <20201221160555.GA81750@grain> (raw)
In-Reply-To: <0df4021b-b2b5-0157-e532-0845b0842e92@tarantool.org>

On Sun, Dec 20, 2020 at 06:01:02PM +0100, Vladislav Shpilevoy wrote:
> Thanks for the fixes!
> 
> > Took both notes from some existing example. Would the following be better?
> 
> Yes, thanks, it does not raise any questions now. Although
> you could keep 's' variable to access the space methods shorter.

Vlad, here is an interdiff for v4. I addressed all your comments I hope.
If you prefer I'll resend the whole series anew.
---
issue https://github.com/tarantool/tarantool/issues/5446
branch gorcunov/gh-5446-eval-quorum-5

Cyrill Gorcunov (4):
  cfg: add cfg_isnumber helper
  cfg: rework box_check_replication_synchro_quorum
  cfg: support symbolic evaluation of replication_synchro_quorum
  test: add replication/gh-5446-qsync-eval-quorum.test.lua

base-commit: 28f3b2f1e845aff49048d92f9062a4dfa365bf57
--
git diff gorcunov/gh-5446-eval-quorum-4
(I removed interdiff for test code)
--
diff --git a/src/box/box.cc b/src/box/box.cc
index ff5c27743..d3ec1faf3 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -585,7 +585,6 @@ box_eval_replication_synchro_quorum(int nr_replicas)
 		"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
@@ -610,6 +609,7 @@ box_eval_replication_synchro_quorum(int nr_replicas)
 		return -1;
 	}
 
+	int quorum = -1;
 	if (lua_isnumber(tarantool_L, -1))
 		quorum = (int)lua_tonumber(tarantool_L, -1);
 	lua_pop(tarantool_L, 1);
@@ -618,9 +618,6 @@ box_eval_replication_synchro_quorum(int nr_replicas)
 	 * At least we should have 1 node to sync, the weird
 	 * formulas such as N-2 do not guarantee quorums thus
 	 * return an error.
-	 *
-	 * Since diag_set doesn't allow to show the valid range
-	 * lets print a warning too.
 	 */
 	if (quorum <= 0 || quorum >= VCLOCK_MAX) {
 		const char *msg =
@@ -640,8 +637,6 @@ box_eval_replication_synchro_quorum(int nr_replicas)
 static int
 box_check_replication_synchro_quorum(void)
 {
-	int quorum = 0;
-
 	if (!cfg_isnumber("replication_synchro_quorum")) {
 		/*
 		 * The formula uses symbolic name 'N' as
@@ -656,27 +651,20 @@ box_check_replication_synchro_quorum(void)
 		 * sure that the cycle won't take too much time.
 		 */
 		for (int i = 1; i < VCLOCK_MAX; i++) {
-			quorum = box_eval_replication_synchro_quorum(i);
-			if (quorum < 0)
+			if (box_eval_replication_synchro_quorum(i) < 0)
 				return -1;
 		}
-		/*
-		 * Just to make clear the number we return here doesn't
-		 * have any special meaning, only errors are matter.
-		 * The real value is dynamic and will be updated on demand.
-		 */
 		return 0;
-	} else {
-		quorum = cfg_geti("replication_synchro_quorum");
 	}
 
+	int quorum = cfg_geti("replication_synchro_quorum");
 	if (quorum <= 0 || quorum >= VCLOCK_MAX) {
 		diag_set(ClientError, ER_CFG, "replication_synchro_quorum",
 			 "the value must be greater than zero and less than "
 			 "maximal number of replicas");
 		return -1;
 	}
-	return quorum;
+	return 0;
 }
 
 static double
@@ -877,7 +865,7 @@ box_check_config(void)
 	box_check_replication_connect_timeout();
 	box_check_replication_connect_quorum();
 	box_check_replication_sync_lag();
-	if (box_check_replication_synchro_quorum() < 0)
+	if (box_check_replication_synchro_quorum() != 0)
 		diag_raise();
 	if (box_check_replication_synchro_timeout() < 0)
 		diag_raise();
@@ -1022,10 +1010,6 @@ box_set_replication_sync_lag(void)
 	replication_sync_lag = box_check_replication_sync_lag();
 }
 
-/**
- * Renew replication_synchro_quorum value if defined
- * as a formula and we need to recalculate it.
- */
 void
 box_update_replication_synchro_quorum(void)
 {
@@ -1057,8 +1041,7 @@ box_update_replication_synchro_quorum(void)
 int
 box_set_replication_synchro_quorum(void)
 {
-	int value = box_check_replication_synchro_quorum();
-	if (value < 0)
+	if (box_check_replication_synchro_quorum() != 0)
 		return -1;
 	box_update_replication_synchro_quorum();
 	return 0;
diff --git a/src/box/box.h b/src/box/box.h
index c3e1a1276..8a7cda194 100644
--- a/src/box/box.h
+++ b/src/box/box.h
@@ -251,8 +251,8 @@ void box_set_replication_timeout(void);
 void box_set_replication_connect_timeout(void);
 void box_set_replication_connect_quorum(void);
 void box_set_replication_sync_lag(void);
-int box_set_replication_synchro_quorum(void);
 void box_update_replication_synchro_quorum(void);
+int box_set_replication_synchro_quorum(void);
 int box_set_replication_synchro_timeout(void);
 void box_set_replication_sync_timeout(void);
 void box_set_replication_skip_conflict(void);
-- 
2.26.2

      parent reply	other threads:[~2020-12-21 16:05 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
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 [this message]

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=20201221160555.GA81750@grain \
    --to=gorcunov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.perepelitsa@corp.mail.ru \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v4 3/3] test: add replication/gh-5446-qsync-eval-quorum.test.lua' \
    /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