From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 04/12] space: make space_swap_index method virtual Date: Sun, 1 Apr 2018 12:05:31 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: 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