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 013C4469711 for ; Tue, 9 Jun 2020 15:20:44 +0300 (MSK) From: Serge Petrenko Date: Tue, 9 Jun 2020 15:20:14 +0300 Message-Id: <7ddc4d3a6b45dba38e7bc184d3125c42936fc512.1591701695.git.sergepetrenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/8] replication: introduce replication_sync_quorum cfg List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, sergos@tarantool.org, gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org From: Vladislav Shpilevoy Synchronous transactions are supposed to be replicated on a specified number of replicas before committed on master. The number of replicas can be specified using replication_sync_quorum option. It is 1 by default, so sync transactions work like asynchronous when not configured anyhow. 1 means successful WAL write on master is enough for commit. Part of #4844 --- src/box/box.cc | 27 +++++++++++++++++++++++++++ src/box/box.h | 1 + src/box/lua/cfg.cc | 9 +++++++++ src/box/lua/load_cfg.lua | 5 +++++ src/box/replication.cc | 1 + src/box/replication.h | 6 ++++++ test/app-tap/init_script.result | 1 + test/box/admin.result | 2 ++ test/box/cfg.result | 4 ++++ 9 files changed, 56 insertions(+) diff --git a/src/box/box.cc b/src/box/box.cc index 96557651b..9b67aeb1f 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -476,6 +476,19 @@ box_check_replication_sync_lag(void) return lag; } +static int +box_check_replication_sync_quorum(void) +{ + int quorum = cfg_geti("replication_sync_quorum"); + if (quorum <= 0 || quorum > VCLOCK_MAX) { + diag_set(ClientError, ER_CFG, "replication_sync_quorum", + "the value must be greater than and less than " + "maximal number of replicas"); + return -1; + } + return quorum; +} + static double box_check_replication_sync_timeout(void) { @@ -658,6 +671,8 @@ box_check_config() box_check_replication_connect_timeout(); box_check_replication_connect_quorum(); box_check_replication_sync_lag(); + if (box_check_replication_sync_quorum() < 0) + diag_raise(); box_check_replication_sync_timeout(); box_check_readahead(cfg_geti("readahead")); box_check_checkpoint_count(cfg_geti("checkpoint_count")); @@ -777,6 +792,16 @@ box_set_replication_sync_lag(void) replication_sync_lag = box_check_replication_sync_lag(); } +int +box_set_replication_sync_quorum(void) +{ + int value = box_check_replication_sync_quorum(); + if (value < 0) + return -1; + replication_sync_quorum = value; + return 0; +} + void box_set_replication_sync_timeout(void) { @@ -2417,6 +2442,8 @@ box_cfg_xc(void) box_set_replication_connect_timeout(); box_set_replication_connect_quorum(); box_set_replication_sync_lag(); + if (box_set_replication_sync_quorum() != 0) + diag_raise(); box_set_replication_sync_timeout(); box_set_replication_skip_conflict(); box_set_replication_anon(); diff --git a/src/box/box.h b/src/box/box.h index 557542a83..e81ff9ea4 100644 --- a/src/box/box.h +++ b/src/box/box.h @@ -243,6 +243,7 @@ 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_sync_quorum(void); void box_set_replication_sync_timeout(void); void box_set_replication_skip_conflict(void); void box_set_replication_anon(void); diff --git a/src/box/lua/cfg.cc b/src/box/lua/cfg.cc index a5b15e527..67dc89242 100644 --- a/src/box/lua/cfg.cc +++ b/src/box/lua/cfg.cc @@ -313,6 +313,14 @@ lbox_cfg_set_replication_sync_lag(struct lua_State *L) return 0; } +static int +lbox_cfg_set_replication_sync_quorum(struct lua_State *L) +{ + if (box_set_replication_sync_quorum() != 0) + luaT_error(L); + return 0; +} + static int lbox_cfg_set_replication_sync_timeout(struct lua_State *L) { @@ -370,6 +378,7 @@ box_lua_cfg_init(struct lua_State *L) {"cfg_set_replication_connect_quorum", lbox_cfg_set_replication_connect_quorum}, {"cfg_set_replication_connect_timeout", lbox_cfg_set_replication_connect_timeout}, {"cfg_set_replication_sync_lag", lbox_cfg_set_replication_sync_lag}, + {"cfg_set_replication_sync_quorum", lbox_cfg_set_replication_sync_quorum}, {"cfg_set_replication_sync_timeout", lbox_cfg_set_replication_sync_timeout}, {"cfg_set_replication_skip_conflict", lbox_cfg_set_replication_skip_conflict}, {"cfg_set_replication_anon", lbox_cfg_set_replication_anon}, diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua index 7dc40a47f..182c1dfdd 100644 --- a/src/box/lua/load_cfg.lua +++ b/src/box/lua/load_cfg.lua @@ -88,6 +88,7 @@ local default_cfg = { worker_pool_threads = 4, replication_timeout = 1, replication_sync_lag = 10, + replication_sync_quorum = 1, replication_sync_timeout = 300, replication_connect_timeout = 30, replication_connect_quorum = nil, -- connect all @@ -163,6 +164,7 @@ local template_cfg = { worker_pool_threads = 'number', replication_timeout = 'number', replication_sync_lag = 'number', + replication_sync_quorum = 'number', replication_sync_timeout = 'number', replication_connect_timeout = 'number', replication_connect_quorum = 'number', @@ -274,6 +276,7 @@ local dynamic_cfg = { replication_connect_timeout = private.cfg_set_replication_connect_timeout, replication_connect_quorum = private.cfg_set_replication_connect_quorum, replication_sync_lag = private.cfg_set_replication_sync_lag, + replication_sync_quorum = private.cfg_set_replication_sync_quorum, replication_sync_timeout = private.cfg_set_replication_sync_timeout, replication_skip_conflict = private.cfg_set_replication_skip_conflict, replication_anon = private.cfg_set_replication_anon, @@ -307,6 +310,7 @@ local dynamic_cfg_order = { -- rule - apply before replication itself. replication_timeout = 150, replication_sync_lag = 150, + replication_sync_quorum = 150, replication_sync_timeout = 150, replication_connect_timeout = 150, replication_connect_quorum = 150, @@ -342,6 +346,7 @@ local dynamic_cfg_skip_at_load = { replication_connect_timeout = true, replication_connect_quorum = true, replication_sync_lag = true, + replication_sync_quorum = true, replication_sync_timeout = true, replication_skip_conflict = true, replication_anon = true, diff --git a/src/box/replication.cc b/src/box/replication.cc index 273a7cb66..f2c18fa21 100644 --- a/src/box/replication.cc +++ b/src/box/replication.cc @@ -51,6 +51,7 @@ double replication_timeout = 1.0; /* seconds */ double replication_connect_timeout = 30.0; /* seconds */ int replication_connect_quorum = REPLICATION_CONNECT_QUORUM_ALL; double replication_sync_lag = 10.0; /* seconds */ +int replication_sync_quorum = 1; double replication_sync_timeout = 300.0; /* seconds */ bool replication_skip_conflict = false; bool replication_anon = false; diff --git a/src/box/replication.h b/src/box/replication.h index 93a25c8a7..3624019fb 100644 --- a/src/box/replication.h +++ b/src/box/replication.h @@ -125,6 +125,12 @@ extern int replication_connect_quorum; */ extern double replication_sync_lag; +/** + * Minimal number of replicas to confirm a synchronous transaction + * is applied on to be able to finish its commit. + */ +extern int replication_sync_quorum; + /** * Max time to wait for appliers to synchronize before entering * the orphan mode. diff --git a/test/app-tap/init_script.result b/test/app-tap/init_script.result index 7c4454285..7d2a610fa 100644 --- a/test/app-tap/init_script.result +++ b/test/app-tap/init_script.result @@ -29,6 +29,7 @@ replication_anon:false replication_connect_timeout:30 replication_skip_conflict:false replication_sync_lag:10 +replication_sync_quorum:1 replication_sync_timeout:300 replication_timeout:1 slab_alloc_factor:1.05 diff --git a/test/box/admin.result b/test/box/admin.result index d94da8c5d..c4f849f2d 100644 --- a/test/box/admin.result +++ b/test/box/admin.result @@ -79,6 +79,8 @@ cfg_filter(box.cfg) - false - - replication_sync_lag - 10 + - - replication_sync_quorum + - 1 - - replication_sync_timeout - 300 - - replication_timeout diff --git a/test/box/cfg.result b/test/box/cfg.result index b41d54599..c511458a8 100644 --- a/test/box/cfg.result +++ b/test/box/cfg.result @@ -67,6 +67,8 @@ cfg_filter(box.cfg) | - false | - - replication_sync_lag | - 10 + | - - replication_sync_quorum + | - 1 | - - replication_sync_timeout | - 300 | - - replication_timeout @@ -170,6 +172,8 @@ cfg_filter(box.cfg) | - false | - - replication_sync_lag | - 10 + | - - replication_sync_quorum + | - 1 | - - replication_sync_timeout | - 300 | - - replication_timeout -- 2.24.3 (Apple Git-128)