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 04/12] space: make space_swap_index method virtual
Date: Sun,  1 Apr 2018 12:05:31 +0300	[thread overview]
Message-ID: <dd8fcb96ace777a9851221eb1b29fd688e92c53c.1522572161.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1522572160.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1522572160.git.vdavydov.dev@gmail.com>

This function is called by MoveIndex and ModifyIndex ALTER operations,
i.e. when the index definition is not changed at all or is extended.
Making this method virtual will allow to avoid reallocation of vinyl
formats in vinyl_space_commit_alter().
---
 src/box/memtx_space.c    |  1 +
 src/box/space.c          |  9 ++++-----
 src/box/space.h          | 33 ++++++++++++++++++++++++---------
 src/box/sysview_engine.c |  1 +
 src/box/vinyl.c          |  1 +
 5 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c
index c7e58946..e0fa3e2c 100644
--- a/src/box/memtx_space.c
+++ b/src/box/memtx_space.c
@@ -895,6 +895,7 @@ static const struct space_vtab memtx_space_vtab = {
 	/* .drop_primary_key = */ memtx_space_drop_primary_key,
 	/* .check_format  = */ memtx_space_check_format,
 	/* .build_secondary_key = */ memtx_space_build_secondary_key,
+	/* .swap_index = */ generic_space_swap_index,
 	/* .prepare_alter = */ memtx_space_prepare_alter,
 	/* .commit_alter = */ memtx_space_commit_alter,
 };
diff --git a/src/box/space.c b/src/box/space.c
index cc6cbeda..02a97926 100644
--- a/src/box/space.c
+++ b/src/box/space.c
@@ -227,12 +227,11 @@ space_index_key_def(struct space *space, uint32_t id)
 }
 
 void
-space_swap_index(struct space *lhs, struct space *rhs,
-		 uint32_t lhs_id, uint32_t rhs_id)
+generic_space_swap_index(struct space *old_space, struct space *new_space,
+			 uint32_t old_index_id, uint32_t new_index_id)
 {
-	struct index *tmp = lhs->index_map[lhs_id];
-	lhs->index_map[lhs_id] = rhs->index_map[rhs_id];
-	rhs->index_map[rhs_id] = tmp;
+	SWAP(old_space->index_map[old_index_id],
+	     new_space->index_map[new_index_id]);
 }
 
 void
diff --git a/src/box/space.h b/src/box/space.h
index 65f1531d..cf1be1e9 100644
--- a/src/box/space.h
+++ b/src/box/space.h
@@ -104,6 +104,13 @@ struct space_vtab {
 				   struct space *new_space,
 				   struct index *new_index);
 	/**
+	 * Exchange two index objects in two spaces. Used
+	 * to update a space with a newly built index, while
+	 * making sure the old index doesn't leak.
+	 */
+	void (*swap_index)(struct space *old_space, struct space *new_space,
+			   uint32_t old_index_id, uint32_t new_index_id);
+	/**
 	 * Notify the engine about the changed space,
 	 * before it's done, to prepare 'new_space' object.
 	 */
@@ -284,6 +291,14 @@ int
 space_execute_dml(struct space *space, struct txn *txn,
 		  struct request *request, struct tuple **result);
 
+/**
+ * Generic implementation of space_vtab::swap_index
+ * that simply swaps the two indexes in index maps.
+ */
+void
+generic_space_swap_index(struct space *old_space, struct space *new_space,
+			 uint32_t old_index_id, uint32_t new_index_id);
+
 static inline void
 init_system_space(struct space *space)
 {
@@ -330,6 +345,15 @@ space_build_secondary_key(struct space *old_space,
 						    new_space, new_index);
 }
 
+static inline void
+space_swap_index(struct space *old_space, struct space *new_space,
+		 uint32_t old_index_id, uint32_t new_index_id)
+{
+	assert(old_space->vtab == new_space->vtab);
+	return new_space->vtab->swap_index(old_space, new_space,
+					   old_index_id, new_index_id);
+}
+
 static inline int
 space_prepare_alter(struct space *old_space, struct space *new_space)
 {
@@ -374,15 +398,6 @@ space_delete(struct space *space);
 void
 space_dump_def(const struct space *space, struct rlist *key_list);
 
-/**
- * Exchange two index objects in two spaces. Used
- * to update a space with a newly built index, while
- * making sure the old index doesn't leak.
- */
-void
-space_swap_index(struct space *lhs, struct space *rhs,
-		 uint32_t lhs_id, uint32_t rhs_id);
-
 /** Rebuild index map in a space after a series of swap index. */
 void
 space_fill_index_map(struct space *space);
diff --git a/src/box/sysview_engine.c b/src/box/sysview_engine.c
index f6122645..fd4ebe5b 100644
--- a/src/box/sysview_engine.c
+++ b/src/box/sysview_engine.c
@@ -185,6 +185,7 @@ static const struct space_vtab sysview_space_vtab = {
 	/* .drop_primary_key = */ sysview_space_drop_primary_key,
 	/* .check_format = */ sysview_space_check_format,
 	/* .build_secondary_key = */ sysview_space_build_secondary_key,
+	/* .swap_index = */ generic_space_swap_index,
 	/* .prepare_alter = */ sysview_space_prepare_alter,
 	/* .commit_alter = */ sysview_space_commit_alter,
 };
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 1afc6664..fc37283a 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -3938,6 +3938,7 @@ static const struct space_vtab vinyl_space_vtab = {
 	/* .drop_primary_key = */ vinyl_space_drop_primary_key,
 	/* .check_format = */ vinyl_space_check_format,
 	/* .build_secondary_key = */ vinyl_space_build_secondary_key,
+	/* .swap_index = */ generic_space_swap_index,
 	/* .prepare_alter = */ vinyl_space_prepare_alter,
 	/* .commit_alter = */ vinyl_space_commit_alter,
 };
-- 
2.11.0

  parent reply	other threads:[~2018-04-01  9:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-01  9:05 [PATCH 00/12] vinyl: allow to extend key def of non-empty index Vladimir Davydov
2018-04-01  9:05 ` [PATCH 01/12] index: add commit_modify virtual method Vladimir Davydov
2018-04-01  9:05 ` [PATCH 02/12] alter: require rebuild of all secondary vinyl indexes if pk changes Vladimir Davydov
2018-04-01  9:05 ` [PATCH 03/12] alter: do not rebuild secondary indexes on compatible " Vladimir Davydov
2018-04-05 12:30   ` Konstantin Osipov
2018-04-01  9:05 ` Vladimir Davydov [this message]
2018-04-01  9:05 ` [PATCH 05/12] vinyl: do not reallocate tuple formats on alter Vladimir Davydov
2018-04-01 11:12   ` [tarantool-patches] " v.shpilevoy
2018-04-01 11:24     ` Vladimir Davydov
2018-04-01  9:05 ` [PATCH 06/12] vinyl: zap vy_lsm_validate_formats Vladimir Davydov
2018-04-01  9:05 ` [PATCH 07/12] vinyl: zap vy_mem_update_formats Vladimir Davydov
2018-04-01  9:05 ` [PATCH 08/12] vinyl: remove pointless is_nullable initialization for disk_format Vladimir Davydov
2018-04-01  9:05 ` [PATCH 09/12] vinyl: use source tuple format when copying field map Vladimir Davydov
2018-04-01  9:05 ` [PATCH 10/12] vinyl: rename vy_log_record::commit_lsn to create_lsn Vladimir Davydov
2018-04-01  9:05 ` [PATCH 11/12] vinyl: do not write VY_LOG_DUMP_LSM record to snapshot Vladimir Davydov
2018-04-01  9:05 ` [PATCH 12/12] vinyl: allow to modify key definition if it does not require rebuild Vladimir Davydov
2018-04-02  8:46   ` Vladimir Davydov
2018-04-05 14:32     ` Konstantin Osipov
2018-04-05 14:45     ` Konstantin Osipov
2018-04-05 14:48       ` 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=dd8fcb96ace777a9851221eb1b29fd688e92c53c.1522572161.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 04/12] space: make space_swap_index method virtual' \
    /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