From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH v2 6/7] vinyl: zap vy_mem::min_lsn and rename max_lsn to dump_lsn Date: Tue, 21 Aug 2018 14:15:39 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: We never use vy_mem::min_lsn so let's zap it. As for max_lsn, we only need it to update vy_lsm::dump_lsn (max LSN stored on disk). Let's rename it appropriately. There's another reason to do that. Once we start storing deferred DELETE statements in memory (see #2129), it won't be the max statement LSN stored in vy_mem anymore, because we will account WAL LSN of deferred DELETE statements there too. Renaming it to dump_lsn will help avoid confusion. Needed for #2129 --- src/box/vy_mem.c | 8 +++----- src/box/vy_mem.h | 10 +++++++--- src/box/vy_scheduler.c | 2 +- test/unit/vy_mem.c | 11 ++++------- test/unit/vy_mem.result | 22 ++++++++++------------ 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/box/vy_mem.c b/src/box/vy_mem.c index 0c46b93c..f9be8505 100644 --- a/src/box/vy_mem.c +++ b/src/box/vy_mem.c @@ -108,8 +108,7 @@ vy_mem_new(struct vy_mem_env *env, int64_t generation, return NULL; } index->env = env; - index->min_lsn = INT64_MAX; - index->max_lsn = -1; + index->dump_lsn = -1; index->cmp_def = cmp_def; index->generation = generation; index->space_cache_version = space_cache_version; @@ -249,11 +248,10 @@ vy_mem_commit_stmt(struct vy_mem *mem, const struct tuple *stmt) /* * Normally statement LSN grows monotonically, * but not in case of building an index on an - * existing non-empty space. Hence use of MIN/MAX + * existing non-empty space. Hence use of MAX * here. */ - mem->min_lsn = MIN(mem->min_lsn, lsn); - mem->max_lsn = MAX(mem->max_lsn, lsn); + mem->dump_lsn = MAX(mem->dump_lsn, lsn); /* * If we don't bump mem version after assigning LSN to * a mem statement, a read iterator which uses diff --git a/src/box/vy_mem.h b/src/box/vy_mem.h index 52caa316..957f549f 100644 --- a/src/box/vy_mem.h +++ b/src/box/vy_mem.h @@ -166,9 +166,13 @@ struct vy_mem { size_t tree_extent_size; /** Number of statements. */ struct vy_stmt_counter count; - /** The min and max values of stmt->lsn in this tree. */ - int64_t min_lsn; - int64_t max_lsn; + /** + * Max LSN covered by this in-memory tree. + * + * Once the tree is dumped to disk it will be used to update + * vy_lsm::dump_lsn, see vy_task_dump_new(). + */ + int64_t dump_lsn; /** * Key definition for this index, extended with primary * key parts. diff --git a/src/box/vy_scheduler.c b/src/box/vy_scheduler.c index 4e8b476b..7d8961c4 100644 --- a/src/box/vy_scheduler.c +++ b/src/box/vy_scheduler.c @@ -982,7 +982,7 @@ vy_task_dump_new(struct vy_scheduler *scheduler, struct vy_lsm *lsm, vy_lsm_delete_mem(lsm, mem); continue; } - dump_lsn = MAX(dump_lsn, mem->max_lsn); + dump_lsn = MAX(dump_lsn, mem->dump_lsn); } if (dump_lsn < 0) { diff --git a/test/unit/vy_mem.c b/test/unit/vy_mem.c index 6666f94c..967aabe8 100644 --- a/test/unit/vy_mem.c +++ b/test/unit/vy_mem.c @@ -18,21 +18,18 @@ test_basic(void) assert(key_def != NULL); struct vy_mem *mem = create_test_mem(key_def); - is(mem->min_lsn, INT64_MAX, "mem->min_lsn on empty mem"); - is(mem->max_lsn, -1, "mem->max_lsn on empty mem"); + is(mem->dump_lsn, -1, "mem->dump_lsn on empty mem"); const struct vy_stmt_template stmts[] = { STMT_TEMPLATE(100, REPLACE, 1), STMT_TEMPLATE(101, REPLACE, 1), STMT_TEMPLATE(102, REPLACE, 1), STMT_TEMPLATE(103, REPLACE, 1), STMT_TEMPLATE(104, REPLACE, 1) }; - /* Check min/max lsn */ + /* Check dump lsn */ const struct tuple *stmt = vy_mem_insert_template(mem, &stmts[0]); - is(mem->min_lsn, INT64_MAX, "mem->min_lsn after prepare"); - is(mem->max_lsn, -1, "mem->max_lsn after prepare"); + is(mem->dump_lsn, -1, "mem->dump_lsn after prepare"); vy_mem_commit_stmt(mem, stmt); - is(mem->min_lsn, 100, "mem->min_lsn after commit"); - is(mem->max_lsn, 100, "mem->max_lsn after commit"); + is(mem->dump_lsn, 100, "mem->dump_lsn after commit"); /* Check vy_mem_older_lsn */ const struct tuple *older = stmt; diff --git a/test/unit/vy_mem.result b/test/unit/vy_mem.result index 6212173d..5c9c7af5 100644 --- a/test/unit/vy_mem.result +++ b/test/unit/vy_mem.result @@ -1,17 +1,15 @@ +# Looks like you planned 12 tests but ran 9. *** test_basic *** 1..12 -ok 1 - mem->min_lsn on empty mem -ok 2 - mem->max_lsn on empty mem -ok 3 - mem->min_lsn after prepare -ok 4 - mem->max_lsn after prepare -ok 5 - mem->min_lsn after commit -ok 6 - mem->max_lsn after commit -ok 7 - vy_mem_older_lsn 1 -ok 8 - vy_mem_older_lsn 2 -ok 9 - vy_mem_rollback 1 -ok 10 - vy_mem_rollback 2 -ok 11 - vy_mem->version -ok 12 - vy_mem->version +ok 1 - mem->dump_lsn on empty mem +ok 2 - mem->dump_lsn after prepare +ok 3 - mem->dump_lsn after commit +ok 4 - vy_mem_older_lsn 1 +ok 5 - vy_mem_older_lsn 2 +ok 6 - vy_mem_rollback 1 +ok 7 - vy_mem_rollback 2 +ok 8 - vy_mem->version +ok 9 - vy_mem->version *** test_basic: done *** *** test_iterator_restore_after_insertion *** 1..1 -- 2.11.0