[tarantool-patches] [PATCH 05/12] vinyl: do not reallocate tuple formats on alter

v.shpilevoy at tarantool.org v.shpilevoy at tarantool.org
Sun Apr 1 14:12:26 MSK 2018



> 1 апр. 2018 г., в 12:05, Vladimir Davydov <vdavydov.dev at 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
> +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);

How do you swap the formats, if they are variable length structures? 1) Their fields[] arrays are not swapped here,
2) even if you will try to swap - they can have different length.

> +	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
> 
> 




More information about the Tarantool-patches mailing list