From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 1/4] vinyl: fix EQ check in run iterator Date: Tue, 15 May 2018 17:08:37 +0300 Message-Id: <6028746ee469d1ba463c1e9740e27a3516ffc7f7.1526392563.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: vy_run_iterator_seek() is supposed to check that the resulting statement matches the search key in case of ITER_EQ, but if the search key lies at the beginning of the slice, it doesn't. As a result, vy_point_lookup() may fail to find an existing tuple as demonstrated below. Suppose we are looking for key {10} in the primary index which consists of an empty mem and two runs: run 1: DELETE{15} run 2: INSERT{10} vy_run_iterator_next() returns DELETE{15} for run 1 because of the missing EQ check and vy_point_lookup() stops at run 1 (since the terminal statement is found) and mistakenly returns NULL. The issue manifests itself as crash in vinyl_iterator_secondary_next(), when we fail to find the tuple in the primary index corresponding to a statement found in a secondary index. Part of #3393 --- src/box/vy_run.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/box/vy_run.c b/src/box/vy_run.c index 587cb002..8c922895 100644 --- a/src/box/vy_run.c +++ b/src/box/vy_run.c @@ -1316,6 +1316,7 @@ vy_run_iterator_seek(struct vy_run_iterator *itr, { const struct key_def *cmp_def = itr->cmp_def; struct vy_slice *slice = itr->slice; + const struct tuple *check_eq_key = NULL; int cmp; if (slice->begin != NULL && @@ -1340,6 +1341,8 @@ vy_run_iterator_seek(struct vy_run_iterator *itr, return 0; } if (cmp < 0 || (cmp == 0 && iterator_type != ITER_GT)) { + if (iterator_type == ITER_EQ) + check_eq_key = key; iterator_type = ITER_GE; key = slice->begin; } @@ -1365,7 +1368,15 @@ vy_run_iterator_seek(struct vy_run_iterator *itr, } } - return vy_run_iterator_do_seek(itr, iterator_type, key, ret); + if (vy_run_iterator_do_seek(itr, iterator_type, key, ret) != 0) + return -1; + + if (check_eq_key != NULL && *ret != NULL && + vy_stmt_compare(check_eq_key, *ret, cmp_def) != 0) { + vy_run_iterator_stop(itr); + *ret = NULL; + } + return 0; } /* }}} vy_run_iterator vy_run_iterator support functions */ -- 2.11.0