From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 1/4] index: add abort_create virtual method Date: Tue, 27 Mar 2018 18:03:00 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: 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