[tarantool-patches] [PATCH] replication: Caching replication_skip_conflict in C

Konstantin Belyavskiy k.belyavskiy at tarantool.org
Thu May 3 15:55:01 MSK 2018


Improvement for #3270 (replication_skip_conflict).
Create a global variable for caching Lua variable to not check the
configuration option, that could be a bottleneck in case of massive
conflicts.

For #3270
---
Ticket: https://github.com/tarantool/tarantool/issues/3270
Branch: https://github.com/tarantool/tarantool/compare/gh-3270-caching-variable-in-c

 src/box/applier.cc       |  2 +-
 src/box/box.cc           |  7 +++++++
 src/box/box.h            |  1 +
 src/box/lua/cfg.cc       | 10 ++++++++++
 src/box/lua/load_cfg.lua |  2 +-
 src/box/replication.cc   |  1 +
 src/box/replication.h    |  6 ++++++
 7 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/box/applier.cc b/src/box/applier.cc
index a48b4ce2a..621d80cdb 100644
--- a/src/box/applier.cc
+++ b/src/box/applier.cc
@@ -515,7 +515,7 @@ applier_subscribe(struct applier *applier)
 				 */
 				if (e->type == &type_ClientError &&
 				    box_error_code(e) == ER_TUPLE_FOUND &&
-				    cfg_geti("replication_skip_conflict"))
+				    replication_skip_conflict)
 					diag_clear(diag_get());
 				else
 					diag_raise();
diff --git a/src/box/box.cc b/src/box/box.cc
index d2dfc5b5f..8fa00aba0 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -651,6 +651,12 @@ box_set_replication_connect_quorum(void)
 		replicaset_check_quorum();
 }
 
+void
+box_set_replication_skip_conflict(void)
+{
+	replication_skip_conflict = cfg_geti("replication_skip_conflict");
+}
+
 void
 box_bind(void)
 {
@@ -1740,6 +1746,7 @@ box_cfg_xc(void)
 	box_set_replication_timeout();
 	box_set_replication_connect_timeout();
 	box_set_replication_connect_quorum();
+	box_set_replication_skip_conflict();
 	replication_sync_lag = box_check_replication_sync_lag();
 	xstream_create(&join_stream, apply_initial_join_row);
 	xstream_create(&subscribe_stream, apply_row);
diff --git a/src/box/box.h b/src/box/box.h
index c9b5aad01..6de10e413 100644
--- a/src/box/box.h
+++ b/src/box/box.h
@@ -181,6 +181,7 @@ void box_set_vinyl_cache(void);
 void box_set_vinyl_timeout(void);
 void box_set_replication_timeout(void);
 void box_set_replication_connect_quorum(void);
+void box_set_replication_skip_conflict(void);
 
 extern "C" {
 #endif /* defined(__cplusplus) */
diff --git a/src/box/lua/cfg.cc b/src/box/lua/cfg.cc
index 5e88ca348..b098bacaa 100644
--- a/src/box/lua/cfg.cc
+++ b/src/box/lua/cfg.cc
@@ -251,6 +251,14 @@ lbox_cfg_set_replication_connect_quorum(struct lua_State *L)
 	return 0;
 }
 
+static int
+lbox_cfg_set_replication_skip_conflict(struct lua_State *L)
+{
+	(void) L;
+	box_set_replication_skip_conflict();
+	return 0;
+}
+
 void
 box_lua_cfg_init(struct lua_State *L)
 {
@@ -275,6 +283,8 @@ box_lua_cfg_init(struct lua_State *L)
 		{"cfg_set_replication_timeout", lbox_cfg_set_replication_timeout},
 		{"cfg_set_replication_connect_quorum",
 			lbox_cfg_set_replication_connect_quorum},
+		{"cfg_set_replication_skip_conflict",
+			lbox_cfg_set_replication_skip_conflict},
 		{NULL, NULL}
 	};
 
diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua
index 3a5a6d46a..dc2967822 100644
--- a/src/box/lua/load_cfg.lua
+++ b/src/box/lua/load_cfg.lua
@@ -194,7 +194,7 @@ local dynamic_cfg = {
     force_recovery          = function() end,
     replication_timeout     = private.cfg_set_replication_timeout,
     replication_connect_quorum = private.cfg_set_replication_connect_quorum,
-    replication_skip_conflict = function() end,
+    replication_skip_conflict = private.cfg_set_replication_skip_conflict,
 }
 
 local dynamic_cfg_skip_at_load = {
diff --git a/src/box/replication.cc b/src/box/replication.cc
index 0b770c913..185c05305 100644
--- a/src/box/replication.cc
+++ b/src/box/replication.cc
@@ -50,6 +50,7 @@ double replication_timeout = 1.0; /* seconds */
 double replication_connect_timeout = 4.0; /* seconds */
 int replication_connect_quorum = REPLICATION_CONNECT_QUORUM_ALL;
 double replication_sync_lag = 10.0; /* seconds */
+bool replication_skip_conflict = false;
 
 struct replicaset replicaset;
 
diff --git a/src/box/replication.h b/src/box/replication.h
index 8a9d57543..7b85c2fc4 100644
--- a/src/box/replication.h
+++ b/src/box/replication.h
@@ -124,6 +124,12 @@ extern int replication_connect_quorum;
  */
 extern double replication_sync_lag;
 
+/**
+ * Allows automatic skip of conflicting rows in replication (e.g. applying
+ * the row throws ER_TUPLE_FOUND) based on box.cfg configuration option.
+ */
+extern bool replication_skip_conflict;
+
 /**
  * Wait for the given period of time before trying to reconnect
  * to a master.
-- 
2.14.3 (Apple Git-98)





More information about the Tarantool-patches mailing list