diff --git a/src/box/vinyl.c b/src/box/vinyl.c index f1c3f126cab8ecd8c8df8e1592b13fd88cad67d8..477d2d92542ad3632280587057db17adfb3010e0 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 22950e6aa6015d4a5845147b8bb9201d650b5d7e..403f546010a62d6de9e1e88a0d2d987218901b36 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 187b73a77ad32c5c6b06f2dee07e5b4b36af2959..6c0a7089a8e5bd817b1c886f5baf34ca51590286 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);