Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH 1/2] index: add compact method
Date: Fri, 18 May 2018 19:21:33 +0300	[thread overview]
Message-ID: <16298b51f2c40bdec21290accfb8401c062df78f.1526658945.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1526658945.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1526658945.git.vdavydov.dev@gmail.com>

This patch adds index.compact() Lua method. The new method is backed by
index_vtab::compact. Currently, it's a no-op for all kinds of indexes.
It will be used by Vinyl engine in order to trigger major compaction.

Part of #3139
---
 src/box/index.cc        | 19 ++++++++++++++++++-
 src/box/index.h         | 23 +++++++++++++++++++++++
 src/box/lua/index.c     | 15 +++++++++++++++
 src/box/lua/schema.lua  |  4 ++++
 src/box/memtx_bitset.c  |  1 +
 src/box/memtx_hash.c    |  1 +
 src/box/memtx_rtree.c   |  1 +
 src/box/memtx_tree.c    |  1 +
 src/box/sysview_index.c |  1 +
 src/box/vinyl.c         |  1 +
 10 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/src/box/index.cc b/src/box/index.cc
index 6cd04833..978935b3 100644
--- a/src/box/index.cc
+++ b/src/box/index.cc
@@ -410,7 +410,7 @@ box_iterator_free(box_iterator_t *it)
 
 /* }}} */
 
-/* {{{ Introspection */
+/* {{{ Other index functions */
 
 int
 box_index_info(uint32_t space_id, uint32_t index_id,
@@ -424,6 +424,17 @@ box_index_info(uint32_t space_id, uint32_t index_id,
 	return 0;
 }
 
+int
+box_index_compact(uint32_t space_id, uint32_t index_id)
+{
+	struct space *space;
+	struct index *index;
+	if (check_index(space_id, index_id, &space, &index) != 0)
+		return -1;
+	index_compact(index);
+	return 0;
+}
+
 /* }}} */
 
 /* {{{ Internal API */
@@ -666,6 +677,12 @@ generic_index_info(struct index *index, struct info_handler *handler)
 }
 
 void
+generic_index_compact(struct index *index)
+{
+	(void)index;
+}
+
+void
 generic_index_reset_stat(struct index *index)
 {
 	(void)index;
diff --git a/src/box/index.h b/src/box/index.h
index 0aa96ade..c7384b61 100644
--- a/src/box/index.h
+++ b/src/box/index.h
@@ -224,6 +224,17 @@ int
 box_index_info(uint32_t space_id, uint32_t index_id,
 	       struct info_handler *info);
 
+/**
+ * Trigger index compaction (index:compact())
+ *
+ * \param space_id space identifier
+ * \param index_id index identifier
+ * \retval -1 on error (check box_error_last())
+ * \retval >=0 on success
+ */
+int
+box_index_compact(uint32_t space_id, uint32_t index_id);
+
 struct iterator {
 	/**
 	 * Iterate to the next tuple.
@@ -412,6 +423,11 @@ struct index_vtab {
 	struct snapshot_iterator *(*create_snapshot_iterator)(struct index *);
 	/** Introspection (index:info()) */
 	void (*info)(struct index *, struct info_handler *);
+	/**
+	 * Trigger asynchronous index compaction. What exactly
+	 * is implied under 'compaction' depends on the engine.
+	 */
+	void (*compact)(struct index *);
 	/** Reset all incremental statistic counters. */
 	void (*reset_stat)(struct index *);
 	/**
@@ -604,6 +620,12 @@ index_info(struct index *index, struct info_handler *handler)
 }
 
 static inline void
+index_compact(struct index *index)
+{
+	index->vtab->compact(index);
+}
+
+static inline void
 index_reset_stat(struct index *index)
 {
 	index->vtab->reset_stat(index);
@@ -653,6 +675,7 @@ int generic_index_replace(struct index *, struct tuple *, struct tuple *,
 			  enum dup_replace_mode, struct tuple **);
 struct snapshot_iterator *generic_index_create_snapshot_iterator(struct index *);
 void generic_index_info(struct index *, struct info_handler *);
+void generic_index_compact(struct index *);
 void generic_index_reset_stat(struct index *);
 void generic_index_begin_build(struct index *);
 int generic_index_reserve(struct index *, uint32_t);
diff --git a/src/box/lua/index.c b/src/box/lua/index.c
index 6dfa6485..5b212f0b 100644
--- a/src/box/lua/index.c
+++ b/src/box/lua/index.c
@@ -314,6 +314,20 @@ lbox_index_info(lua_State *L)
 	return 1;
 }
 
+static int
+lbox_index_compact(lua_State *L)
+{
+	if (lua_gettop(L) != 2 || !lua_isnumber(L, 1) || !lua_isnumber(L, 2))
+		return luaL_error(L, "usage index.compact(space_id, index_id)");
+
+	uint32_t space_id = lua_tonumber(L, 1);
+	uint32_t index_id = lua_tonumber(L, 2);
+
+	if (box_index_compact(space_id, index_id) != 0)
+		return luaT_error(L);
+	return 0;
+}
+
 /* }}} */
 
 void
@@ -350,6 +364,7 @@ box_lua_index_init(struct lua_State *L)
 		{"iterator_next", lbox_iterator_next},
 		{"truncate", lbox_truncate},
 		{"info", lbox_index_info},
+		{"compact", lbox_index_compact},
 		{NULL, NULL}
 	};
 
diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
index 1a616d56..552d4651 100644
--- a/src/box/lua/schema.lua
+++ b/src/box/lua/schema.lua
@@ -1288,6 +1288,10 @@ base_index_mt.info = function(index)
     return internal.info(index.space_id, index.id);
 end
 
+base_index_mt.compact = function(index)
+    return internal.compact(index.space_id, index.id)
+end
+
 base_index_mt.drop = function(index)
     check_index_arg(index, 'drop')
     return box.schema.index.drop(index.space_id, index.id)
diff --git a/src/box/memtx_bitset.c b/src/box/memtx_bitset.c
index 7b87560b..e0088337 100644
--- a/src/box/memtx_bitset.c
+++ b/src/box/memtx_bitset.c
@@ -476,6 +476,7 @@ static const struct index_vtab memtx_bitset_index_vtab = {
 	/* .create_snapshot_iterator = */
 		generic_index_create_snapshot_iterator,
 	/* .info = */ generic_index_info,
+	/* .compact = */ generic_index_compact,
 	/* .reset_stat = */ generic_index_reset_stat,
 	/* .begin_build = */ generic_index_begin_build,
 	/* .reserve = */ generic_index_reserve,
diff --git a/src/box/memtx_hash.c b/src/box/memtx_hash.c
index 24138f42..2748e850 100644
--- a/src/box/memtx_hash.c
+++ b/src/box/memtx_hash.c
@@ -400,6 +400,7 @@ static const struct index_vtab memtx_hash_index_vtab = {
 	/* .create_snapshot_iterator = */
 		memtx_hash_index_create_snapshot_iterator,
 	/* .info = */ generic_index_info,
+	/* .compact = */ generic_index_compact,
 	/* .reset_stat = */ generic_index_reset_stat,
 	/* .begin_build = */ generic_index_begin_build,
 	/* .reserve = */ generic_index_reserve,
diff --git a/src/box/memtx_rtree.c b/src/box/memtx_rtree.c
index 653343a7..83de921c 100644
--- a/src/box/memtx_rtree.c
+++ b/src/box/memtx_rtree.c
@@ -320,6 +320,7 @@ static const struct index_vtab memtx_rtree_index_vtab = {
 	/* .create_snapshot_iterator = */
 		generic_index_create_snapshot_iterator,
 	/* .info = */ generic_index_info,
+	/* .compact = */ generic_index_compact,
 	/* .reset_stat = */ generic_index_reset_stat,
 	/* .begin_build = */ generic_index_begin_build,
 	/* .reserve = */ generic_index_reserve,
diff --git a/src/box/memtx_tree.c b/src/box/memtx_tree.c
index 073006b4..6b77ef3f 100644
--- a/src/box/memtx_tree.c
+++ b/src/box/memtx_tree.c
@@ -609,6 +609,7 @@ static const struct index_vtab memtx_tree_index_vtab = {
 	/* .create_snapshot_iterator = */
 		memtx_tree_index_create_snapshot_iterator,
 	/* .info = */ generic_index_info,
+	/* .compact = */ generic_index_compact,
 	/* .reset_stat = */ generic_index_reset_stat,
 	/* .begin_build = */ memtx_tree_index_begin_build,
 	/* .reserve = */ memtx_tree_index_reserve,
diff --git a/src/box/sysview_index.c b/src/box/sysview_index.c
index 8bfc39b0..43b30d48 100644
--- a/src/box/sysview_index.c
+++ b/src/box/sysview_index.c
@@ -190,6 +190,7 @@ static const struct index_vtab sysview_index_vtab = {
 	/* .create_snapshot_iterator = */
 		generic_index_create_snapshot_iterator,
 	/* .info = */ generic_index_info,
+	/* .compact = */ generic_index_compact,
 	/* .reset_stat = */ generic_index_reset_stat,
 	/* .begin_build = */ generic_index_begin_build,
 	/* .reserve = */ generic_index_reserve,
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 6c8f0df8..896f8559 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -4060,6 +4060,7 @@ static const struct index_vtab vinyl_index_vtab = {
 	/* .create_snapshot_iterator = */
 		generic_index_create_snapshot_iterator,
 	/* .info = */ vinyl_index_info,
+	/* .compact = */ generic_index_compact,
 	/* .reset_stat = */ vinyl_index_reset_stat,
 	/* .begin_build = */ generic_index_begin_build,
 	/* .reserve = */ generic_index_reserve,
-- 
2.11.0

  reply	other threads:[~2018-05-18 16:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-18 16:21 [PATCH 0/2] vinyl: add knob for forcing major compaction Vladimir Davydov
2018-05-18 16:21 ` Vladimir Davydov [this message]
2018-05-20 21:32   ` [PATCH 1/2] index: add compact method Konstantin Osipov
2018-05-18 16:21 ` [PATCH 2/2] vinyl: implement index " Vladimir Davydov
2018-05-20 21:33   ` Konstantin Osipov

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=16298b51f2c40bdec21290accfb8401c062df78f.1526658945.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 1/2] index: add compact method' \
    /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