From 1b0aa56269dec01b45951d504b12247058d4940e Mon Sep 17 00:00:00 2001 From: Vladimir Davydov <vdavydov.dev@gmail.com> Date: Wed, 12 Jul 2017 16:52:19 +0300 Subject: [PATCH] vinyl: do not try to make index directory on truncate vy_prepare_truncate_space() doesn't need to make directories for truncated indexes - they must already exist as the indexes were created. It just needs to create initial range for each of them. Factor out vy_index_init_range_tree() out of vy_index_create() and use it instead where appropriate. --- src/box/vinyl.c | 2 +- src/box/vy_index.c | 29 ++++++++++++++++------------- src/box/vy_index.h | 11 +++++++++-- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/box/vinyl.c b/src/box/vinyl.c index f1c3f126ca..477d2d9254 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -2635,7 +2635,7 @@ vy_prepare_truncate_space(struct vy_env *env, struct space *old_space, continue; } - if (vy_index_create(new_index) != 0) + if (vy_index_init_range_tree(new_index) != 0) return -1; new_index->truncate_count = new_space->truncate_count; diff --git a/src/box/vy_index.c b/src/box/vy_index.c index 22950e6aa6..403f546010 100644 --- a/src/box/vy_index.c +++ b/src/box/vy_index.c @@ -304,9 +304,20 @@ vy_index_swap(struct vy_index *old_index, struct vy_index *new_index) rlist_swap(&old_index->runs, &new_index->runs); } -/** - * Create an index directory for a new index. - */ +int +vy_index_init_range_tree(struct vy_index *index) +{ + struct vy_range *range = vy_range_new(vy_log_next_id(), NULL, NULL, + index->key_def); + if (range == NULL) + return -1; + + assert(index->range_count == 0); + vy_index_add_range(index, range); + vy_index_acct_range(index, range); + return 0; +} + int vy_index_create(struct vy_index *index) { @@ -341,15 +352,7 @@ vy_index_create(struct vy_index *index) } /* Allocate initial range. */ - struct vy_range *range = vy_range_new(vy_log_next_id(), NULL, NULL, - index->key_def); - if (unlikely(range == NULL)) - return -1; - - assert(index->range_count == 0); - vy_index_add_range(index, range); - vy_index_acct_range(index, range); - return 0; + return vy_index_init_range_tree(index); } /** vy_index_recovery_cb() argument. */ @@ -525,7 +528,7 @@ vy_index_recover(struct vy_index *index, struct vy_recovery *recovery, (long long)index->opts.lsn)); return -1; } - return vy_index_create(index); + return vy_index_init_range_tree(index); } /* diff --git a/src/box/vy_index.h b/src/box/vy_index.h index 187b73a77a..6c0a7089a8 100644 --- a/src/box/vy_index.h +++ b/src/box/vy_index.h @@ -320,9 +320,16 @@ vy_index_unref(struct vy_index *index) void vy_index_swap(struct vy_index *old_index, struct vy_index *new_index); +/** Initialize the range tree of a new index. */ +int +vy_index_init_range_tree(struct vy_index *index); + /** - * Make the data directory and initialize the range tree - * for a new index. + * Create a new vinyl index. + * + * This function is called when an index is created after recovery + * is complete or during remote recovery. It initializes the range + * tree and makes the index directory. */ int vy_index_create(struct vy_index *index); -- GitLab