[sql 1/9] Introduce ephemeral spaces

Nikita Pettik korablev at tarantool.org
Tue Jan 23 23:19:12 MSK 2018


From: Vladimir Davydov <vdavydov.dev at gmail.com>

Ephemeral spaces are invisible via public API and they are not
persistent. They are needed solely to do some transient calculations.

To create an ephemeral space, use space_new_ephemeral() function,
which takes a space definition and a list of index definitions as
arguments. A space created with this function may be accessed and
modified via internal API (space_execute_replace(), index_get(),
etc).

Currently, only the memtx engine supports ephemeral spaces.

Closes #2776

Signed-off-by: Nikita Pettik <korablev at tarantool.org>
---
 src/box/memtx_space.c    |  7 +++++++
 src/box/space.c          | 11 +++++++++++
 src/box/space.h          | 17 +++++++++++++++++
 src/box/sysview_engine.c |  8 ++++++++
 src/box/vinyl.c          |  8 ++++++++
 5 files changed, 51 insertions(+)

diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c
index 599a68e13..766798522 100644
--- a/src/box/memtx_space.c
+++ b/src/box/memtx_space.c
@@ -748,6 +748,12 @@ memtx_init_system_space(struct space *space)
 	memtx_space_do_add_primary_key(space, MEMTX_OK);
 }
 
+static void
+memtx_init_ephemeral_space(struct space *space)
+{
+	memtx_space_do_add_primary_key(space, MEMTX_OK);
+}
+
 static int
 memtx_space_build_secondary_key(struct space *old_space,
 				struct space *new_space,
@@ -895,6 +901,7 @@ static const struct space_vtab memtx_space_vtab = {
 	/* .execute_update = */ memtx_space_execute_update,
 	/* .execute_upsert = */ memtx_space_execute_upsert,
 	/* .init_system_space = */ memtx_init_system_space,
+	/* .init_ephemeral_space = */ memtx_init_ephemeral_space,
 	/* .check_index_def = */ memtx_space_check_index_def,
 	/* .create_index = */ memtx_space_create_index,
 	/* .add_primary_key = */ memtx_space_add_primary_key,
diff --git a/src/box/space.c b/src/box/space.c
index 703270361..37718392e 100644
--- a/src/box/space.c
+++ b/src/box/space.c
@@ -163,6 +163,17 @@ space_new(struct space_def *def, struct rlist *key_list)
 	return engine_create_space(engine, def, key_list);
 }
 
+struct space *
+space_new_ephemeral(struct space_def *def, struct rlist *key_list)
+{
+	struct space *space = space_new(def, key_list);
+	if (space == NULL)
+		return NULL;
+	space->def->opts.temporary = true;
+	space->vtab->init_ephemeral_space(space);
+	return space;
+}
+
 void
 space_delete(struct space *space)
 {
diff --git a/src/box/space.h b/src/box/space.h
index 12a3255b2..b3d2cde98 100644
--- a/src/box/space.h
+++ b/src/box/space.h
@@ -67,6 +67,10 @@ struct space_vtab {
 	int (*execute_upsert)(struct space *, struct txn *, struct request *);
 
 	void (*init_system_space)(struct space *);
+	/**
+	 * Initialize an ephemeral space instance.
+	 */
+	void (*init_ephemeral_space)(struct space *);
 	/**
 	 * Check an index definition for violation of
 	 * various limits.
@@ -423,6 +427,19 @@ struct field_def;
 struct space *
 space_new(struct space_def *space_def, struct rlist *key_list);
 
+/**
+ * Create an ephemeral space.
+ * @param space_def Space definition.
+ * @param key_list List of index_defs.
+ * @retval Space object.
+ *
+ * Ephemeral spaces are invisible via public API and they
+ * are not persistent. They are needed solely to do some
+ * transient calculations.
+ */
+struct space *
+space_new_ephemeral(struct space_def *space_def, struct rlist *key_list);
+
 /** Destroy and free a space. */
 void
 space_delete(struct space *space);
diff --git a/src/box/sysview_engine.c b/src/box/sysview_engine.c
index 6f7c2c87e..556a7e148 100644
--- a/src/box/sysview_engine.c
+++ b/src/box/sysview_engine.c
@@ -106,6 +106,13 @@ sysview_init_system_space(struct space *space)
 	unreachable();
 }
 
+static void
+sysview_init_ephemeral_space(struct space *space)
+{
+	(void)space;
+	unreachable();
+}
+
 static int
 sysview_space_check_index_def(struct space *space, struct index_def *index_def)
 {
@@ -194,6 +201,7 @@ static const struct space_vtab sysview_space_vtab = {
 	/* .execute_update = */ sysview_space_execute_update,
 	/* .execute_upsert = */ sysview_space_execute_upsert,
 	/* .init_system_space = */ sysview_init_system_space,
+	/* .init_ephemeral_space = */ sysview_init_ephemeral_space,
 	/* .check_index_def = */ sysview_space_check_index_def,
 	/* .create_index = */ sysview_space_create_index,
 	/* .add_primary_key = */ sysview_space_add_primary_key,
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index feded3436..4c670f3cd 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -844,6 +844,13 @@ vinyl_init_system_space(struct space *space)
 	unreachable();
 }
 
+static void
+vinyl_init_ephemeral_space(struct space *space)
+{
+	(void)space;
+	unreachable();
+}
+
 static int
 vinyl_space_prepare_truncate(struct space *old_space, struct space *new_space)
 {
@@ -4007,6 +4014,7 @@ static const struct space_vtab vinyl_space_vtab = {
 	/* .execute_update = */ vinyl_space_execute_update,
 	/* .execute_upsert = */ vinyl_space_execute_upsert,
 	/* .init_system_space = */ vinyl_init_system_space,
+	/* .init_ephemeral_space = */ vinyl_init_ephemeral_space,
 	/* .check_index_def = */ vinyl_space_check_index_def,
 	/* .create_index = */ vinyl_space_create_index,
 	/* .add_primary_key = */ vinyl_space_add_primary_key,
-- 
2.15.1




More information about the Tarantool-patches mailing list