Tarantool development patches archive
 help / color / mirror / Atom feed
From: imeevma@tarantool.org
To: korablev@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v2 5/9] box: introduce 'service' engine
Date: Mon, 30 Dec 2019 19:43:12 +0300	[thread overview]
Message-ID: <e787edcdae3470b15232e13c89bb588924e304d4.1577724051.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1577724051.git.imeevma@gmail.com>

This patch introduces a new engine called "service" that will be
used to create a new system space. The main idea of this engine is
that it will not have a predefined space_vtab. With this engine,
we can create unusual spaces with their own vtab and behavior.

Due to the nature of this engine, it can only be used to create
system spaces.

Part of #4511
---
 src/box/CMakeLists.txt                             |  1 +
 src/box/box.cc                                     |  4 +
 src/box/service_engine.c                           | 95 ++++++++++++++++++++++
 src/box/service_engine.h                           | 53 ++++++++++++
 ...h-4511-access-settings-from-any-frontend.result | 10 +++
 ...4511-access-settings-from-any-frontend.test.lua |  4 +
 6 files changed, 167 insertions(+)
 create mode 100644 src/box/service_engine.c
 create mode 100644 src/box/service_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 c0afa63..cc67a63 100644
--- a/src/box/CMakeLists.txt
+++ b/src/box/CMakeLists.txt
@@ -81,6 +81,7 @@ add_library(box STATIC
     memtx_space.c
     sysview.c
     blackhole.c
+    service_engine.c
     vinyl.c
     vy_stmt.c
     vy_mem.c
diff --git a/src/box/box.cc b/src/box/box.cc
index 5a8e4d3..d2b463d 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 "service_engine.h"
 #include "vinyl.h"
 #include "space.h"
 #include "index.h"
@@ -1922,6 +1923,9 @@ engine_init()
 	struct sysview_engine *sysview = sysview_engine_new_xc();
 	engine_register((struct engine *)sysview);
 
+	struct engine *service_engine = service_engine_new_xc();
+	engine_register(service_engine);
+
 	struct engine *blackhole = blackhole_engine_new_xc();
 	engine_register(blackhole);
 
diff --git a/src/box/service_engine.c b/src/box/service_engine.c
new file mode 100644
index 0000000..67f8422
--- /dev/null
+++ b/src/box/service_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 "service_engine.h"
+#include "schema.h"
+
+static void
+service_engine_shutdown(struct engine *engine)
+{
+	free(engine);
+}
+
+static struct space *
+service_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 'service' engine.");
+	return NULL;
+}
+
+static const struct engine_vtab service_engine_vtab = {
+	/* .shutdown = */ service_engine_shutdown,
+	/* .create_space = */ service_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 *
+service_engine_new(void)
+{
+	struct engine *service_engine = calloc(1, sizeof(*service_engine));
+	if (service_engine == NULL) {
+		diag_set(OutOfMemory, sizeof(*service_engine), "calloc",
+			 "service_engine");
+		return NULL;
+	}
+
+	service_engine->vtab = &service_engine_vtab;
+	service_engine->name = "service";
+	service_engine->flags = ENGINE_BYPASS_TX;
+	return service_engine;
+}
diff --git a/src/box/service_engine.h b/src/box/service_engine.h
new file mode 100644
index 0000000..48e2518
--- /dev/null
+++ b/src/box/service_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 *
+service_engine_new(void);
+
+#if defined(__cplusplus)
+} /* extern "C" */
+
+#include "diag.h"
+
+static inline struct engine *
+service_engine_new_xc(void)
+{
+	struct engine *service_engine = service_engine_new();
+	if (service_engine == NULL)
+		diag_raise();
+	return service_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..de8bcb7
--- /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 = 'service'})
+ | ---
+ | - error: Tarantool does not support spaces with 'service' 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..e2d212d
--- /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 = 'service'})
-- 
2.7.4

  parent reply	other threads:[~2019-12-30 16:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-30 16:43 [Tarantool-patches] [PATCH v2 0/9] sql: Remove control pragmas imeevma
2019-12-30 16:43 ` [Tarantool-patches] [PATCH v2 1/9] sql: remove PRAGMA "count_changes" imeevma
2019-12-30 16:43 ` [Tarantool-patches] [PATCH v2 2/9] sql: remove PRAGMA "short_column_names" imeevma
2019-12-30 23:12   ` Nikita Pettik
2019-12-31  4:15     ` Mergen Imeev
2019-12-30 16:43 ` [Tarantool-patches] [PATCH v2 3/9] sql: remove PRAGMA "sql_compound_select_limit" imeevma
2019-12-30 23:11   ` Nikita Pettik
2019-12-31  4:14     ` Mergen Imeev
2019-12-30 16:43 ` [Tarantool-patches] [PATCH v2 4/9] sql: remove PRAGMA "vdbe_addoptrace" imeevma
2019-12-30 16:43 ` imeevma [this message]
2019-12-30 16:43 ` [Tarantool-patches] [PATCH v2 6/9] box: introduce _session_settings system space imeevma
2019-12-30 16:43 ` [Tarantool-patches] [PATCH v2 7/9] box: add SQL settings to _session_settings imeevma
2019-12-30 16:43 ` [Tarantool-patches] [PATCH v2 8/9] sql: remove control pragmas imeevma
2019-12-30 16:43 ` [Tarantool-patches] [PATCH v2 9/9] sql: refactor PRAGMA-related code imeevma
2019-12-30 23:31 ` [Tarantool-patches] [PATCH v2 0/9] sql: Remove control pragmas Nikita Pettik
2019-12-31  4:16   ` Mergen Imeev
2019-12-31  8:01 ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e787edcdae3470b15232e13c89bb588924e304d4.1577724051.git.imeevma@gmail.com \
    --to=imeevma@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 5/9] box: introduce '\''service'\'' engine' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox