[patches] [patch 1/1] Add ephemeral space destroy function

Nikita Pettik korablev at tarantool.org
Fri Jan 26 13:06:51 MSK 2018


It turns out that it is not enough to simply call space_delete() on
ephemeral space in order to delete space. Tuples should also be
unreferred in case of memtx engine; other engines don't support
ephemeral tables yet, but additional actions seem to be needed. In this
regard, destroy method for ephemeral spaces has been added to space
vtab. For memtx engine it just calls memtx_space_prune() which iterates
through primary index and unrefs all tuples.
Function, which deletes ephemeral space, now calls destroy method from
vtab and then ordinary space_delete().
---
 src/box/memtx_space.c    | 7 +++++++
 src/box/space.c          | 7 +++++++
 src/box/space.h          | 5 +++++
 src/box/sysview_engine.c | 8 ++++++++
 src/box/vinyl.c          | 8 ++++++++
 5 files changed, 35 insertions(+)

diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c
index 912dd2ea0..aedbc4eb4 100644
--- a/src/box/memtx_space.c
+++ b/src/box/memtx_space.c
@@ -942,6 +942,12 @@ fail:
 	panic("failed to prune space");
 }
 
+static void
+memtx_space_ephemeral_destroy(struct space *space)
+{
+	memtx_space_prune(space);
+}
+
 static void
 memtx_space_commit_truncate(struct space *old_space,
 			    struct space *new_space)
@@ -987,6 +993,7 @@ static const struct space_vtab memtx_space_vtab = {
 	/* .execute_upsert = */ memtx_space_execute_upsert,
 	/* .ephemeral_replace = */ memtx_space_ephemeral_replace,
 	/* .ephemeral_delete = */ memtx_space_ephemeral_delete,
+	/* .ephemeral_destroy = */ memtx_space_ephemeral_destroy,
 	/* .init_system_space = */ memtx_init_system_space,
 	/* .init_ephemeral_space = */ memtx_init_ephemeral_space,
 	/* .check_index_def = */ memtx_space_check_index_def,
diff --git a/src/box/space.c b/src/box/space.c
index 8d0df31ce..f7ec78c75 100644
--- a/src/box/space.c
+++ b/src/box/space.c
@@ -203,6 +203,13 @@ space_delete(struct space *space)
 	space->vtab->destroy(space);
 }
 
+void
+space_delete_ephemeral(struct space *space)
+{
+	space->vtab->ephemeral_destroy(space);
+	space_delete(space);
+}
+
 /** Do nothing if the space is already recovered. */
 void
 space_noop(struct space *space)
diff --git a/src/box/space.h b/src/box/space.h
index 0e5ef2058..501a0e662 100644
--- a/src/box/space.h
+++ b/src/box/space.h
@@ -70,6 +70,8 @@ struct space_vtab {
 
 	int (*ephemeral_delete)(struct space *, const char *);
 
+	void (*ephemeral_destroy)(struct space *);
+
 	void (*init_system_space)(struct space *);
 	/**
 	 * Initialize an ephemeral space instance.
@@ -462,6 +464,9 @@ space_new_ephemeral(struct space_def *space_def, struct rlist *key_list);
 void
 space_delete(struct space *space);
 
+void
+space_delete_ephemeral(struct space *space);
+
 /**
  * Dump space definition (key definitions, key count)
  * for ALTER.
diff --git a/src/box/sysview_engine.c b/src/box/sysview_engine.c
index 0a5fce0fd..520b15847 100644
--- a/src/box/sysview_engine.c
+++ b/src/box/sysview_engine.c
@@ -119,6 +119,13 @@ sysview_space_ephemeral_delete(struct space *space, const char *key)
 	return -1;
 }
 
+static void
+sysview_space_ephemeral_destroy(struct space *space)
+{
+	(void)space;
+	unreachable();
+}
+
 static void
 sysview_init_system_space(struct space *space)
 {
@@ -222,6 +229,7 @@ static const struct space_vtab sysview_space_vtab = {
 	/* .execute_upsert = */ sysview_space_execute_upsert,
 	/* .ephemeral_replace = */ sysview_space_ephemeral_replace,
 	/* .ephemeral_delete = */ sysview_space_ephemeral_delete,
+	/* .ephemeral_destroy = */ sysview_space_ephemeral_destroy,
 	/* .init_system_space = */ sysview_init_system_space,
 	/* .init_ephemeral_space = */ sysview_init_ephemeral_space,
 	/* .check_index_def = */ sysview_space_check_index_def,
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 0a3629f69..5bde3f866 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -2305,6 +2305,13 @@ vinyl_space_ephemeral_delete(struct space *space, const char *key)
 	return -1;
 }
 
+static void
+vinyl_space_ephemeral_destroy(struct space *space)
+{
+	(void)space;
+	unreachable();
+}
+
 static inline void
 txn_stmt_unref_tuples(struct txn_stmt *stmt)
 {
@@ -4004,6 +4011,7 @@ static const struct space_vtab vinyl_space_vtab = {
 	/* .execute_upsert = */ vinyl_space_execute_upsert,
 	/* .ephemeral_replace = */ vinyl_space_ephemeral_replace,
 	/* .ephemeral_delete = */ vinyl_space_ephemeral_delete,
+	/* .ephemeral_destroy = */ vinyl_space_ephemeral_destroy,
 	/* .init_system_space = */ vinyl_init_system_space,
 	/* .init_ephemeral_space = */ vinyl_init_ephemeral_space,
 	/* .check_index_def = */ vinyl_space_check_index_def,
-- 
2.15.1




More information about the Tarantool-patches mailing list