[Tarantool-patches] [PATCH v4 05/12] txm: introduce memtx tx manager
Aleksandr Lyapunov
alyapunov at tarantool.org
Tue Sep 8 13:22:05 MSK 2020
Define memtx TX manager. It will store data for MVCC and conflict
manager. Define also 'memtx_use_mvcc_engine' in config that
enables that MVCC engine.
Part of #4897
---
src/box/CMakeLists.txt | 1 +
src/box/lua/load_cfg.lua | 2 ++
src/box/memtx_tx.c | 52 +++++++++++++++++++++++++++++++++++
src/box/memtx_tx.h | 61 +++++++++++++++++++++++++++++++++++++++++
src/main.cc | 5 ++++
test/app-tap/init_script.result | 1 +
test/box/admin.result | 2 ++
test/box/cfg.result | 4 +++
8 files changed, 128 insertions(+)
create mode 100644 src/box/memtx_tx.c
create mode 100644 src/box/memtx_tx.h
diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt
index b8b2689..2ed7270 100644
--- a/src/box/CMakeLists.txt
+++ b/src/box/CMakeLists.txt
@@ -128,6 +128,7 @@ add_library(box STATIC
memtx_tree.c
memtx_rtree.c
memtx_bitset.c
+ memtx_tx.c
engine.c
memtx_engine.c
memtx_space.c
diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua
index 53f5728..92347a9 100644
--- a/src/box/lua/load_cfg.lua
+++ b/src/box/lua/load_cfg.lua
@@ -82,6 +82,7 @@ local default_cfg = {
coredump = false,
read_only = false,
hot_standby = false,
+ memtx_use_mvcc_engine = false,
checkpoint_interval = 3600,
checkpoint_wal_threshold = 1e18,
checkpoint_count = 2,
@@ -162,6 +163,7 @@ local template_cfg = {
checkpoint_count = 'number',
read_only = 'boolean',
hot_standby = 'boolean',
+ memtx_use_mvcc_engine = 'boolean',
worker_pool_threads = 'number',
replication_timeout = 'number',
replication_sync_lag = 'number',
diff --git a/src/box/memtx_tx.c b/src/box/memtx_tx.c
new file mode 100644
index 0000000..479aa48
--- /dev/null
+++ b/src/box/memtx_tx.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010-2020, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include "memtx_tx.h"
+
+struct tx_manager
+{
+};
+
+/** That's a definition, see declaration for description. */
+bool memtx_tx_manager_use_mvcc_engine = false;
+
+/** The one and only instance of tx_manager. */
+static struct tx_manager txm;
+
+void
+memtx_tx_manager_init()
+{
+ (void)txm;
+}
+
+void
+memtx_tx_manager_free()
+{
+}
diff --git a/src/box/memtx_tx.h b/src/box/memtx_tx.h
new file mode 100644
index 0000000..fb2cb4d
--- /dev/null
+++ b/src/box/memtx_tx.h
@@ -0,0 +1,61 @@
+#pragma once
+/*
+ * Copyright 2010-2020, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdbool.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* defined(__cplusplus) */
+
+/**
+ * Global flag that enables mvcc engine.
+ * If set, memtx starts to apply statements through txm history mechanism
+ * and tx manager itself transaction reads in order to detect conflicts.
+ */
+extern bool memtx_tx_manager_use_mvcc_engine;
+
+/**
+ * Initialize memtx transaction manager.
+ */
+void
+memtx_tx_manager_init();
+
+/**
+ * Free resources of memtx transaction manager.
+ */
+void
+memtx_tx_manager_free();
+
+
+#if defined(__cplusplus)
+} /* extern "C" */
+#endif /* defined(__cplusplus) */
diff --git a/src/main.cc b/src/main.cc
index 65b1606..2f48f47 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -75,6 +75,7 @@
#include <libutil.h>
#include "box/lua/init.h" /* box_lua_init() */
#include "box/session.h"
+#include "box/memtx_tx.h"
#include "systemd.h"
#include "crypto/crypto.h"
#include "core/popen.h"
@@ -569,6 +570,8 @@ load_cfg(void)
log_format,
background);
+ memtx_tx_manager_use_mvcc_engine = cfg_getb("memtx_use_mvcc_engine");
+
if (background)
daemonize();
@@ -667,6 +670,7 @@ tarantool_free(void)
random_free();
#endif
crypto_free();
+ memtx_tx_manager_free();
coll_free();
systemd_free();
say_logger_free();
@@ -830,6 +834,7 @@ main(int argc, char **argv)
signal_init();
cbus_init();
coll_init();
+ memtx_tx_manager_init();
crypto_init();
systemd_init();
tarantool_lua_init(tarantool_bin, main_argc, main_argv);
diff --git a/test/app-tap/init_script.result b/test/app-tap/init_script.result
index 857f0c9..c8974d7 100644
--- a/test/app-tap/init_script.result
+++ b/test/app-tap/init_script.result
@@ -21,6 +21,7 @@ memtx_dir:.
memtx_max_tuple_size:1048576
memtx_memory:107374182
memtx_min_tuple_size:16
+memtx_use_mvcc_engine:false
net_msg_max:768
pid_file:box.pid
read_only:false
diff --git a/test/box/admin.result b/test/box/admin.result
index ab3e80a..d1540a7 100644
--- a/test/box/admin.result
+++ b/test/box/admin.result
@@ -63,6 +63,8 @@ cfg_filter(box.cfg)
- 107374182
- - memtx_min_tuple_size
- <hidden>
+ - - memtx_use_mvcc_engine
+ - false
- - net_msg_max
- 768
- - pid_file
diff --git a/test/box/cfg.result b/test/box/cfg.result
index bdd210b..fcfc64b 100644
--- a/test/box/cfg.result
+++ b/test/box/cfg.result
@@ -51,6 +51,8 @@ cfg_filter(box.cfg)
| - 107374182
| - - memtx_min_tuple_size
| - <hidden>
+ | - - memtx_use_mvcc_engine
+ | - false
| - - net_msg_max
| - 768
| - - pid_file
@@ -158,6 +160,8 @@ cfg_filter(box.cfg)
| - 107374182
| - - memtx_min_tuple_size
| - <hidden>
+ | - - memtx_use_mvcc_engine
+ | - false
| - - net_msg_max
| - 768
| - - pid_file
--
2.7.4
More information about the Tarantool-patches
mailing list