diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c index c7e58946533ba35eaf5eda5597255859bb17b402..e0fa3e2c556dc9a2bfcc0474daae3273691b1fdb 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 cc6cbedaafd94af0f321f276b61cc3b163767bf7..02a97926ebfbe8abfb297350b5088898d0c61be3 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 65f1531d214130880e30085e8ab76dd769f10922..cf1be1e9a4004904af72d17cd907172e8f957510 100644 --- a/src/box/space.h +++ b/src/box/space.h @@ -103,6 +103,13 @@ struct space_vtab { int (*build_secondary_key)(struct space *old_space, 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 f6122645f1046214f9000817ee16a06ab4d35d9c..fd4ebe5b8b5e4219625dad0c651951abebac5c44 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 2e50bf48ec62b42abca7a5b2e7bd4016cd91f59a..efe8a253290f84c59507029597683e99077908fe 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -3948,6 +3948,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, };