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/4] index: add abort_create virtual method
Date: Tue, 27 Mar 2018 18:03:00 +0300	[thread overview]
Message-ID: <a33f4bd82d2ff4505ddc0fd57754dfc88f47c536.1522162296.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1522162296.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1522162296.git.vdavydov.dev@gmail.com>

The new method is called if index creation failed, either due to WAL
write error or build error. It will be used by Vinyl to purge prepared
LSM tree from vylog.
---
 src/box/alter.cc        | 18 ++++++++++++++++++
 src/box/index.cc        |  5 +++++
 src/box/index.h         | 12 ++++++++++++
 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 +
 9 files changed, 41 insertions(+)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 854ca6d9..6e5d6e52 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -1178,6 +1178,7 @@ public:
 	virtual void alter_def(struct alter_space *alter);
 	virtual void alter(struct alter_space *alter);
 	virtual void commit(struct alter_space *alter, int64_t lsn);
+	virtual void rollback(struct alter_space *alter);
 	virtual ~CreateIndex();
 };
 
@@ -1232,6 +1233,14 @@ CreateIndex::commit(struct alter_space *alter, int64_t signature)
 	index_commit_create(new_index, signature);
 }
 
+void
+CreateIndex::rollback(struct alter_space *alter)
+{
+	struct index *new_index = index_find_xc(alter->new_space,
+						new_index_def->iid);
+	index_abort_create(new_index);
+}
+
 CreateIndex::~CreateIndex()
 {
 	if (new_index_def)
@@ -1264,6 +1273,7 @@ public:
 	virtual void alter_def(struct alter_space *alter);
 	virtual void alter(struct alter_space *alter);
 	virtual void commit(struct alter_space *alter, int64_t signature);
+	virtual void rollback(struct alter_space *alter);
 	virtual ~RebuildIndex();
 };
 
@@ -1298,6 +1308,14 @@ RebuildIndex::commit(struct alter_space *alter, int64_t signature)
 	index_commit_create(new_index, signature);
 }
 
+void
+RebuildIndex::rollback(struct alter_space *alter)
+{
+	struct index *new_index = space_index(alter->new_space,
+					      new_index_def->iid);
+	index_abort_create(new_index);
+}
+
 RebuildIndex::~RebuildIndex()
 {
 	if (new_index_def)
diff --git a/src/box/index.cc b/src/box/index.cc
index 21c768ce..d02cbbc5 100644
--- a/src/box/index.cc
+++ b/src/box/index.cc
@@ -541,6 +541,11 @@ generic_index_commit_create(struct index *, int64_t)
 }
 
 void
+generic_index_abort_create(struct index *)
+{
+}
+
+void
 generic_index_commit_drop(struct index *)
 {
 }
diff --git a/src/box/index.h b/src/box/index.h
index 81d32a8b..b8b0feb2 100644
--- a/src/box/index.h
+++ b/src/box/index.h
@@ -351,6 +351,11 @@ struct index_vtab {
 	 */
 	void (*commit_create)(struct index *index, int64_t signature);
 	/**
+	 * Called if index creation failed, either due to
+	 * WAL write error or build error.
+	 */
+	void (*abort_create)(struct index *index);
+	/**
 	 * Called after WAL write to commit index drop.
 	 * Must not fail.
 	 */
@@ -469,6 +474,12 @@ index_commit_create(struct index *index, int64_t signature)
 }
 
 static inline void
+index_abort_create(struct index *index)
+{
+	index->vtab->abort_create(index);
+}
+
+static inline void
 index_commit_drop(struct index *index)
 {
 	index->vtab->commit_drop(index);
@@ -587,6 +598,7 @@ index_end_build(struct index *index)
  * Virtual method stubs.
  */
 void generic_index_commit_create(struct index *, int64_t);
+void generic_index_abort_create(struct index *);
 void generic_index_commit_drop(struct index *);
 void generic_index_update_def(struct index *);
 ssize_t generic_index_size(struct index *);
diff --git a/src/box/memtx_bitset.c b/src/box/memtx_bitset.c
index d76ee56d..c2685a65 100644
--- a/src/box/memtx_bitset.c
+++ b/src/box/memtx_bitset.c
@@ -457,6 +457,7 @@ memtx_bitset_index_count(struct index *base, enum iterator_type type,
 static const struct index_vtab memtx_bitset_index_vtab = {
 	/* .destroy = */ memtx_bitset_index_destroy,
 	/* .commit_create = */ generic_index_commit_create,
+	/* .abort_create = */ generic_index_abort_create,
 	/* .commit_drop = */ generic_index_commit_drop,
 	/* .update_def = */ generic_index_update_def,
 	/* .size = */ memtx_bitset_index_size,
diff --git a/src/box/memtx_hash.c b/src/box/memtx_hash.c
index 3cb6cbcd..4dab23cd 100644
--- a/src/box/memtx_hash.c
+++ b/src/box/memtx_hash.c
@@ -381,6 +381,7 @@ memtx_hash_index_create_snapshot_iterator(struct index *base)
 static const struct index_vtab memtx_hash_index_vtab = {
 	/* .destroy = */ memtx_hash_index_destroy,
 	/* .commit_create = */ generic_index_commit_create,
+	/* .abort_create = */ generic_index_abort_create,
 	/* .commit_drop = */ generic_index_commit_drop,
 	/* .update_def = */ memtx_hash_index_update_def,
 	/* .size = */ memtx_hash_index_size,
diff --git a/src/box/memtx_rtree.c b/src/box/memtx_rtree.c
index 35fcd2d0..dea68897 100644
--- a/src/box/memtx_rtree.c
+++ b/src/box/memtx_rtree.c
@@ -295,6 +295,7 @@ memtx_rtree_index_begin_build(struct index *base)
 static const struct index_vtab memtx_rtree_index_vtab = {
 	/* .destroy = */ memtx_rtree_index_destroy,
 	/* .commit_create = */ generic_index_commit_create,
+	/* .abort_create = */ generic_index_abort_create,
 	/* .commit_drop = */ generic_index_commit_drop,
 	/* .update_def = */ generic_index_update_def,
 	/* .size = */ memtx_rtree_index_size,
diff --git a/src/box/memtx_tree.c b/src/box/memtx_tree.c
index c976bd9c..06b74e11 100644
--- a/src/box/memtx_tree.c
+++ b/src/box/memtx_tree.c
@@ -582,6 +582,7 @@ memtx_tree_index_create_snapshot_iterator(struct index *base)
 static const struct index_vtab memtx_tree_index_vtab = {
 	/* .destroy = */ memtx_tree_index_destroy,
 	/* .commit_create = */ generic_index_commit_create,
+	/* .abort_create = */ generic_index_abort_create,
 	/* .commit_drop = */ generic_index_commit_drop,
 	/* .update_def = */ memtx_tree_index_update_def,
 	/* .size = */ memtx_tree_index_size,
diff --git a/src/box/sysview_index.c b/src/box/sysview_index.c
index ce2f2cb2..be17fd32 100644
--- a/src/box/sysview_index.c
+++ b/src/box/sysview_index.c
@@ -161,6 +161,7 @@ sysview_index_get(struct index *base, const char *key,
 static const struct index_vtab sysview_index_vtab = {
 	/* .destroy = */ sysview_index_destroy,
 	/* .commit_create = */ generic_index_commit_create,
+	/* .abort_create = */ generic_index_abort_create,
 	/* .commit_drop = */ generic_index_commit_drop,
 	/* .update_def = */ generic_index_update_def,
 	/* .size = */ generic_index_size,
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index f782ee64..fa67a99a 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -3952,6 +3952,7 @@ static const struct space_vtab vinyl_space_vtab = {
 static const struct index_vtab vinyl_index_vtab = {
 	/* .destroy = */ vinyl_index_destroy,
 	/* .commit_create = */ vinyl_index_commit_create,
+	/* .abort_create = */ generic_index_abort_create,
 	/* .commit_drop = */ vinyl_index_commit_drop,
 	/* .update_def = */ generic_index_update_def,
 	/* .size = */ vinyl_index_size,
-- 
2.11.0

  reply	other threads:[~2018-03-27 15:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-27 15:02 [PATCH 0/4] Introduce VY_LOG_PREPARE_LSM vylog record Vladimir Davydov
2018-03-27 15:03 ` Vladimir Davydov [this message]
2018-03-27 15:03 ` [PATCH 2/4] vinyl: use rlist for iterating over objects recovered from vylog Vladimir Davydov
2018-03-27 15:03 ` [PATCH 3/4] vinyl: fix discrepancy between vy_log.tx_size and actual tx len Vladimir Davydov
2018-03-27 15:03 ` [PATCH 4/4] vinyl: log new index before WAL write on DDL 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=a33f4bd82d2ff4505ddc0fd57754dfc88f47c536.1522162296.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 1/4] index: add abort_create virtual 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