From: Vladimir Davydov <vdavydov.dev@gmail.com> To: kostja@tarantool.org Cc: tarantool-patches@freelists.org Subject: [PATCH 05/12] vinyl: do not reallocate tuple formats on alter Date: Sun, 1 Apr 2018 12:05:32 +0300 [thread overview] Message-ID: <475ebc439ee72ccd55b1158c354a01b2452a6bd5.1522572161.git.vdavydov.dev@gmail.com> (raw) In-Reply-To: <cover.1522572160.git.vdavydov.dev@gmail.com> In-Reply-To: <cover.1522572160.git.vdavydov.dev@gmail.com> We create new formats for all indexes of the new space in vinyl_space_commit_alter() while we don't actually need to do this, because the new formats have already been created by vy_lsm_new() - all we need to do is reuse them somehow. This patch does the trick: it implements the swap_index() space virtual method for vinyl so that it swaps tuple formats between the old and new spaces. --- src/box/vinyl.c | 58 ++++++++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/src/box/vinyl.c b/src/box/vinyl.c index fc37283a..f3cef52f 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -1024,30 +1024,9 @@ vinyl_space_commit_alter(struct space *old_space, struct space *new_space) struct tuple_format *new_format = new_space->format; struct vy_lsm *pk = vy_lsm(new_space->index[0]); - struct index_def *new_index_def = space_index_def(new_space, 0); - assert(pk->pk == NULL); - /* Update the format with column mask. */ - struct tuple_format *format = - vy_tuple_format_new_with_colmask(new_format); - if (format == NULL) - goto fail; - - /* Set possibly changed opts. */ - pk->opts = new_index_def->opts; pk->check_is_unique = true; - - /* Set new formats. */ - tuple_format_unref(pk->disk_format); - tuple_format_unref(pk->mem_format); - tuple_format_unref(pk->mem_format_with_colmask); - pk->disk_format = new_format; - tuple_format_ref(new_format); - pk->mem_format_with_colmask = format; - tuple_format_ref(format); - pk->mem_format = new_format; - tuple_format_ref(new_format); vy_lsm_validate_formats(pk); key_def_update_optionality(pk->key_def, new_format->min_field_count); key_def_update_optionality(pk->cmp_def, new_format->min_field_count); @@ -1057,15 +1036,7 @@ vinyl_space_commit_alter(struct space *old_space, struct space *new_space) vy_lsm_unref(lsm->pk); vy_lsm_ref(pk); lsm->pk = pk; - new_index_def = space_index_def(new_space, i); - lsm->opts = new_index_def->opts; lsm->check_is_unique = lsm->opts.is_unique; - tuple_format_unref(lsm->mem_format_with_colmask); - tuple_format_unref(lsm->mem_format); - lsm->mem_format_with_colmask = pk->mem_format_with_colmask; - lsm->mem_format = pk->mem_format; - tuple_format_ref(lsm->mem_format_with_colmask); - tuple_format_ref(lsm->mem_format); key_def_update_optionality(lsm->key_def, new_format->min_field_count); key_def_update_optionality(lsm->cmp_def, @@ -1093,12 +1064,27 @@ vinyl_space_commit_alter(struct space *old_space, struct space *new_space) } } } - return; -fail: - /* FIXME: space_vtab::commit_alter() must not fail. */ - diag_log(); - unreachable(); - panic("failed to alter 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) +{ + struct vy_lsm *old_lsm = vy_lsm(old_space->index_map[old_index_id]); + struct vy_lsm *new_lsm = vy_lsm(new_space->index_map[new_index_id]); + + /* + * Swap the two indexes between the two spaces, + * but leave tuple formats. + */ + generic_space_swap_index(old_space, new_space, + old_index_id, new_index_id); + + SWAP(old_lsm->mem_format, new_lsm->mem_format); + SWAP(old_lsm->mem_format_with_colmask, + new_lsm->mem_format_with_colmask); + SWAP(old_lsm->disk_format, new_lsm->disk_format); + SWAP(old_lsm->opts, new_lsm->opts); } static int @@ -3938,7 +3924,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, + /* .swap_index = */ vinyl_space_swap_index, /* .prepare_alter = */ vinyl_space_prepare_alter, /* .commit_alter = */ vinyl_space_commit_alter, }; -- 2.11.0
next prev parent reply other threads:[~2018-04-01 9:05 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-04-01 9:05 [PATCH 00/12] vinyl: allow to extend key def of non-empty index Vladimir Davydov 2018-04-01 9:05 ` [PATCH 01/12] index: add commit_modify virtual method Vladimir Davydov 2018-04-01 9:05 ` [PATCH 02/12] alter: require rebuild of all secondary vinyl indexes if pk changes Vladimir Davydov 2018-04-01 9:05 ` [PATCH 03/12] alter: do not rebuild secondary indexes on compatible " Vladimir Davydov 2018-04-05 12:30 ` Konstantin Osipov 2018-04-01 9:05 ` [PATCH 04/12] space: make space_swap_index method virtual Vladimir Davydov 2018-04-01 9:05 ` Vladimir Davydov [this message] 2018-04-01 11:12 ` [tarantool-patches] [PATCH 05/12] vinyl: do not reallocate tuple formats on alter v.shpilevoy 2018-04-01 11:24 ` Vladimir Davydov 2018-04-01 9:05 ` [PATCH 06/12] vinyl: zap vy_lsm_validate_formats Vladimir Davydov 2018-04-01 9:05 ` [PATCH 07/12] vinyl: zap vy_mem_update_formats Vladimir Davydov 2018-04-01 9:05 ` [PATCH 08/12] vinyl: remove pointless is_nullable initialization for disk_format Vladimir Davydov 2018-04-01 9:05 ` [PATCH 09/12] vinyl: use source tuple format when copying field map Vladimir Davydov 2018-04-01 9:05 ` [PATCH 10/12] vinyl: rename vy_log_record::commit_lsn to create_lsn Vladimir Davydov 2018-04-01 9:05 ` [PATCH 11/12] vinyl: do not write VY_LOG_DUMP_LSM record to snapshot Vladimir Davydov 2018-04-01 9:05 ` [PATCH 12/12] vinyl: allow to modify key definition if it does not require rebuild Vladimir Davydov 2018-04-02 8:46 ` Vladimir Davydov 2018-04-05 14:32 ` Konstantin Osipov 2018-04-05 14:45 ` Konstantin Osipov 2018-04-05 14:48 ` Konstantin Osipov
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=475ebc439ee72ccd55b1158c354a01b2452a6bd5.1522572161.git.vdavydov.dev@gmail.com \ --to=vdavydov.dev@gmail.com \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH 05/12] vinyl: do not reallocate tuple formats on 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