[Tarantool-patches] [PATCH 1/3] box: introduce 'virtual' engine
Mergen Imeev
imeevma at tarantool.org
Thu Dec 26 20:59:11 MSK 2019
Thank you very much for your review fixes! I haven't found
any issues with them. Result after squash below:
On Sat, Dec 21, 2019 at 06:59:17PM +0100, Vladislav Shpilevoy wrote:
> Hi! Thanks for the patch!
>
> I've pushed my review fixes on top of this commit. See it below
> and on the branch. If you agree, then squash. Otherwise lets
> discuss.
>
> ==================================================================
>
> commit b3d8950d07a620ecbb19318495d33a59af5733b5
> Author: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
> Date: Sat Dec 21 18:02:43 2019 +0100
>
> Review fixes 1/3
>
> diff --git a/src/box/virtual_engine.c b/src/box/virtual_engine.c
> index 45993b91f..9a59a3f6a 100644
> --- a/src/box/virtual_engine.c
> +++ b/src/box/virtual_engine.c
> @@ -30,7 +30,6 @@
> */
> #include "virtual_engine.h"
> #include "schema.h"
> -#include "tuple.h"
>
> static void
> virtual_engine_shutdown(struct engine *engine)
> diff --git a/src/box/virtual_engine.h b/src/box/virtual_engine.h
> index 80ada450d..9cb5f520f 100644
> --- a/src/box/virtual_engine.h
> +++ b/src/box/virtual_engine.h
> @@ -29,8 +29,6 @@
> * 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) */
>From 6df53f4b5acb3282627e5088c953094dbce261e6 Mon Sep 17 00:00:00 2001
From: Mergen Imeev <imeevma at gmail.com>
Date: Sat, 30 Nov 2019 12:59:45 +0300
Subject: [PATCH] box: introduce 'virtual' engine
This patch introduces a new engine called "virtual" that will be
used to create a new system space.
Part of #4511
diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt
index fc9d1a3..d79d52c 100644
--- a/src/box/CMakeLists.txt
+++ b/src/box/CMakeLists.txt
@@ -79,6 +79,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..9a59a3f
--- /dev/null
+++ b/src/box/virtual_engine.c
@@ -0,0 +1,95 @@
+/*
+ * 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"
+
+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..9cb5f52
--- /dev/null
+++ b/src/box/virtual_engine.h
@@ -0,0 +1,53 @@
+#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.
+ */
+#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'})
More information about the Tarantool-patches
mailing list