[Tarantool-patches] [PATCH 1/3] box: introduce 'virtual' engine
imeevma at tarantool.org
imeevma at tarantool.org
Thu Dec 19 11:32:57 MSK 2019
This patch introduces a new engine called "virtual" that will be
used to create a new system space.
Part of #4511
---
src/box/CMakeLists.txt | 1 +
src/box/box.cc | 4 +
src/box/virtual_engine.c | 96 ++++++++++++++++++++++
src/box/virtual_engine.h | 55 +++++++++++++
...h-4511-access-settings-from-any-frontend.result | 10 +++
...4511-access-settings-from-any-frontend.test.lua | 4 +
6 files changed, 170 insertions(+)
create mode 100644 src/box/virtual_engine.c
create mode 100644 src/box/virtual_engine.h
create mode 100644 test/box/gh-4511-access-settings-from-any-frontend.result
create mode 100644 test/box/gh-4511-access-settings-from-any-frontend.test.lua
diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt
index 5cd5cba8..c011bfc 100644
--- a/src/box/CMakeLists.txt
+++ b/src/box/CMakeLists.txt
@@ -78,6 +78,7 @@ add_library(box STATIC
memtx_space.c
sysview.c
blackhole.c
+ virtual_engine.c
vinyl.c
vy_stmt.c
vy_mem.c
diff --git a/src/box/box.cc b/src/box/box.cc
index b119c92..a19151c 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -53,6 +53,7 @@
#include "memtx_engine.h"
#include "sysview.h"
#include "blackhole.h"
+#include "virtual_engine.h"
#include "vinyl.h"
#include "space.h"
#include "index.h"
@@ -1693,6 +1694,9 @@ engine_init()
struct sysview_engine *sysview = sysview_engine_new_xc();
engine_register((struct engine *)sysview);
+ struct engine *virtual_engine = virtual_engine_new_xc();
+ engine_register(virtual_engine);
+
struct engine *blackhole = blackhole_engine_new_xc();
engine_register(blackhole);
diff --git a/src/box/virtual_engine.c b/src/box/virtual_engine.c
new file mode 100644
index 0000000..45993b9
--- /dev/null
+++ b/src/box/virtual_engine.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2010-2019, 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 "virtual_engine.h"
+#include "schema.h"
+#include "tuple.h"
+
+static void
+virtual_engine_shutdown(struct engine *engine)
+{
+ free(engine);
+}
+
+static struct space *
+virtual_engine_create_space(struct engine *engine, struct space_def *def,
+ struct rlist *key_list)
+{
+ (void)engine;
+ (void)def;
+ (void)key_list;
+ /* There are currently no spaces with this engine. */
+ diag_set(ClientError, ER_UNSUPPORTED, "Tarantool",
+ "spaces with this engine.");
+ return NULL;
+}
+
+static const struct engine_vtab virtual_engine_vtab = {
+ /* .shutdown = */ virtual_engine_shutdown,
+ /* .create_space = */ virtual_engine_create_space,
+ /* .prepare_join = */ generic_engine_prepare_join,
+ /* .join = */ generic_engine_join,
+ /* .complete_join = */ generic_engine_complete_join,
+ /* .begin = */ generic_engine_begin,
+ /* .begin_statement = */ generic_engine_begin_statement,
+ /* .prepare = */ generic_engine_prepare,
+ /* .commit = */ generic_engine_commit,
+ /* .rollback_statement = */ generic_engine_rollback_statement,
+ /* .rollback = */ generic_engine_rollback,
+ /* .switch_to_ro = */ generic_engine_switch_to_ro,
+ /* .bootstrap = */ generic_engine_bootstrap,
+ /* .begin_initial_recovery = */ generic_engine_begin_initial_recovery,
+ /* .begin_final_recovery = */ generic_engine_begin_final_recovery,
+ /* .end_recovery = */ generic_engine_end_recovery,
+ /* .begin_checkpoint = */ generic_engine_begin_checkpoint,
+ /* .wait_checkpoint = */ generic_engine_wait_checkpoint,
+ /* .commit_checkpoint = */ generic_engine_commit_checkpoint,
+ /* .abort_checkpoint = */ generic_engine_abort_checkpoint,
+ /* .collect_garbage = */ generic_engine_collect_garbage,
+ /* .backup = */ generic_engine_backup,
+ /* .memory_stat = */ generic_engine_memory_stat,
+ /* .reset_stat = */ generic_engine_reset_stat,
+ /* .check_space_def = */ generic_engine_check_space_def,
+};
+
+struct engine *
+virtual_engine_new(void)
+{
+ struct engine *virtual_engine = calloc(1, sizeof(*virtual_engine));
+ if (virtual_engine == NULL) {
+ diag_set(OutOfMemory, sizeof(*virtual_engine), "calloc",
+ "virtual_engine");
+ return NULL;
+ }
+
+ virtual_engine->vtab = &virtual_engine_vtab;
+ virtual_engine->name = "virtual";
+ virtual_engine->flags = ENGINE_BYPASS_TX;
+ return virtual_engine;
+}
diff --git a/src/box/virtual_engine.h b/src/box/virtual_engine.h
new file mode 100644
index 0000000..80ada45
--- /dev/null
+++ b/src/box/virtual_engine.h
@@ -0,0 +1,55 @@
+#pragma once
+/*
+ * Copyright 2010-2019, 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 <stddef.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* defined(__cplusplus) */
+
+struct engine *
+virtual_engine_new(void);
+
+#if defined(__cplusplus)
+} /* extern "C" */
+
+#include "diag.h"
+
+static inline struct engine *
+virtual_engine_new_xc(void)
+{
+ struct engine *virtual_engine = virtual_engine_new();
+ if (virtual_engine == NULL)
+ diag_raise();
+ return virtual_engine;
+}
+
+#endif /* defined(__plusplus) */
diff --git a/test/box/gh-4511-access-settings-from-any-frontend.result b/test/box/gh-4511-access-settings-from-any-frontend.result
new file mode 100644
index 0000000..9874616
--- /dev/null
+++ b/test/box/gh-4511-access-settings-from-any-frontend.result
@@ -0,0 +1,10 @@
+-- test-run result file version 2
+test_run = require('test_run').new()
+ | ---
+ | ...
+
+-- User cannot create spaces with this engine.
+s = box.schema.space.create('test', {engine = 'virtual'})
+ | ---
+ | - error: Tarantool does not support spaces with this engine.
+ | ...
diff --git a/test/box/gh-4511-access-settings-from-any-frontend.test.lua b/test/box/gh-4511-access-settings-from-any-frontend.test.lua
new file mode 100644
index 0000000..611caef
--- /dev/null
+++ b/test/box/gh-4511-access-settings-from-any-frontend.test.lua
@@ -0,0 +1,4 @@
+test_run = require('test_run').new()
+
+-- User cannot create spaces with this engine.
+s = box.schema.space.create('test', {engine = 'virtual'})
--
2.7.4
More information about the Tarantool-patches
mailing list