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 v2 2/2] alter: zap space_vtab::commit_alter
Date: Fri,  6 Apr 2018 16:15:32 +0300	[thread overview]
Message-ID: <f3a1f79fbf39dbb3d79029456d63910c29fe4fc4.1523019950.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1523019950.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1523019950.git.vdavydov.dev@gmail.com>

space_vtab::commit_alter is implemented only by memtx, which uses it
to set bsize for a new space. However, it isn't necessary to use
commit_alter for this - instead we can set bsize in prepare_alter and
reset it in drop_primary_key, along with memtx_space::replace. Let's
do it and zap space_vtab::commit_alter altogether, because the callback
is confusing: judging by its name it should be called after WAL write,
but it is called before.
---
 src/box/alter.cc         | 21 ++-------------------
 src/box/memtx_space.c    | 21 +++++++++------------
 src/box/space.h          | 15 ---------------
 src/box/sysview_engine.c |  8 --------
 src/box/vinyl.c          |  8 --------
 5 files changed, 11 insertions(+), 62 deletions(-)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 174d53fa..15805b9b 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -864,8 +864,6 @@ alter_space_do(struct txn *txn, struct alter_space *alter)
 	 * The new space is ready. Time to update the space
 	 * cache with it.
 	 */
-	space_commit_alter(alter->old_space, alter->new_space);
-
 	struct space *old_space = space_cache_replace(alter->new_space);
 	(void) old_space;
 	assert(old_space == alter->old_space);
@@ -1026,23 +1024,8 @@ DropIndex::alter_def(struct alter_space * /* alter */)
 void
 DropIndex::alter(struct alter_space *alter)
 {
-	/*
-	 * If it's not the primary key, nothing to do --
-	 * the dropped index didn't exist in the new space
-	 * definition, so does not exist in the created space.
-	 */
-	if (space_index(alter->new_space, 0) != NULL)
-		return;
-	/*
-	 * OK to drop the primary key. Inform the engine about it,
-	 * since it may have to reset handler->replace function,
-	 * so that:
-	 * - DML returns proper errors rather than crashes the
-	 *   program
-	 * - when a new primary key is finally added, the space
-	 *   can be put back online properly.
-	 */
-	space_drop_primary_key(alter->new_space);
+	if (old_index_def->iid == 0)
+		space_drop_primary_key(alter->new_space);
 }
 
 void
diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c
index ebb54f05..b3e08e49 100644
--- a/src/box/memtx_space.c
+++ b/src/box/memtx_space.c
@@ -735,7 +735,15 @@ static void
 memtx_space_drop_primary_key(struct space *space)
 {
 	struct memtx_space *memtx_space = (struct memtx_space *)space;
+	/*
+	 * Reset 'replace' callback so that:
+	 * - DML returns proper errors rather than crashes the
+	 *   program.
+	 * - When a new primary key is finally added, the space
+	 *   can be put back online properly.
+	 */
 	memtx_space->replace = memtx_space_replace_no_keys;
+	memtx_space->bsize = 0;
 }
 
 static void
@@ -820,23 +828,13 @@ memtx_space_prepare_alter(struct space *old_space, struct space *new_space)
 	struct memtx_space *old_memtx_space = (struct memtx_space *)old_space;
 	struct memtx_space *new_memtx_space = (struct memtx_space *)new_space;
 	new_memtx_space->replace = old_memtx_space->replace;
+	new_memtx_space->bsize = old_memtx_space->bsize;
 	bool is_empty = old_space->index_count == 0 ||
 			index_size(old_space->index[0]) == 0;
 	return space_def_check_compatibility(old_space->def,
 					     new_space->def, is_empty);
 }
 
-static void
-memtx_space_commit_alter(struct space *old_space, struct space *new_space)
-{
-	struct memtx_space *old_memtx_space = (struct memtx_space *)old_space;
-	struct memtx_space *new_memtx_space = (struct memtx_space *)new_space;
-	bool is_empty = new_space->index_count == 0 ||
-			index_size(new_space->index[0]) == 0;
-	if (!is_empty)
-		new_memtx_space->bsize = old_memtx_space->bsize;
-}
-
 /* }}} DDL */
 
 static const struct space_vtab memtx_space_vtab = {
@@ -856,7 +854,6 @@ static const struct space_vtab memtx_space_vtab = {
 	/* .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,
 };
 
 struct space *
diff --git a/src/box/space.h b/src/box/space.h
index cf1be1e9..758d575e 100644
--- a/src/box/space.h
+++ b/src/box/space.h
@@ -116,14 +116,6 @@ struct space_vtab {
 	 */
 	int (*prepare_alter)(struct space *old_space,
 			     struct space *new_space);
-	/**
-	 * Notify the engine engine after altering a space and
-	 * replacing old_space with new_space in the space cache,
-	 * to, e.g., update all references to struct space
-	 * and replace old_space with new_space.
-	 */
-	void (*commit_alter)(struct space *old_space,
-			     struct space *new_space);
 };
 
 struct space {
@@ -361,13 +353,6 @@ space_prepare_alter(struct space *old_space, struct space *new_space)
 	return new_space->vtab->prepare_alter(old_space, new_space);
 }
 
-static inline void
-space_commit_alter(struct space *old_space, struct space *new_space)
-{
-	assert(old_space->vtab == new_space->vtab);
-	new_space->vtab->commit_alter(old_space, new_space);
-}
-
 static inline bool
 space_is_memtx(struct space *space) { return space->engine->id == 0; }
 
diff --git a/src/box/sysview_engine.c b/src/box/sysview_engine.c
index fd4ebe5b..d28430aa 100644
--- a/src/box/sysview_engine.c
+++ b/src/box/sysview_engine.c
@@ -154,13 +154,6 @@ sysview_space_prepare_alter(struct space *old_space, struct space *new_space)
 	return 0;
 }
 
-static void
-sysview_space_commit_alter(struct space *old_space, struct space *new_space)
-{
-	(void)old_space;
-	(void)new_space;
-}
-
 static int
 sysview_space_check_format(struct space *new_space, struct space *old_space)
 {
@@ -187,7 +180,6 @@ static const struct space_vtab sysview_space_vtab = {
 	/* .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,
 };
 
 static void
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 83df2b81..e809f6a8 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -1053,13 +1053,6 @@ vinyl_space_check_format(struct space *new_space, struct space *old_space)
 }
 
 static void
-vinyl_space_commit_alter(struct space *old_space, struct space *new_space)
-{
-	(void)old_space;
-	(void)new_space;
-}
-
-static void
 vinyl_space_swap_index(struct space *old_space, struct space *new_space,
 		       uint32_t old_index_id, uint32_t new_index_id)
 {
@@ -3941,7 +3934,6 @@ static const struct space_vtab vinyl_space_vtab = {
 	/* .build_secondary_key = */ vinyl_space_build_secondary_key,
 	/* .swap_index = */ vinyl_space_swap_index,
 	/* .prepare_alter = */ vinyl_space_prepare_alter,
-	/* .commit_alter = */ vinyl_space_commit_alter,
 };
 
 static const struct index_vtab vinyl_index_vtab = {
-- 
2.11.0

  parent reply	other threads:[~2018-04-06 13:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-06 13:15 [PATCH v2 0/2] alter: fix WAL error handling Vladimir Davydov
2018-04-06 13:15 ` [PATCH v2 1/2] memtx: do not use space_vtab::commit_alter for freeing tuples Vladimir Davydov
2018-04-06 14:08   ` Konstantin Osipov
2018-04-06 14:19     ` Vladimir Davydov
2018-04-06 15:29       ` Vladimir Davydov
2018-04-06 13:15 ` Vladimir Davydov [this message]
2018-04-06 14:10   ` [PATCH v2 2/2] alter: zap space_vtab::commit_alter Konstantin Osipov
2018-04-06 14:23     ` Vladimir Davydov
2018-04-06 14:28       ` Konstantin Osipov
2018-04-06 15:25         ` Vladimir Davydov

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=f3a1f79fbf39dbb3d79029456d63910c29fe4fc4.1523019950.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH v2 2/2] alter: zap space_vtab::commit_alter' \
    /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