From 1f0023ad154250b9ad0ad0fd0bd14378c7174607 Mon Sep 17 00:00:00 2001 From: Vladimir Davydov <vdavydov.dev@gmail.com> Date: Tue, 15 May 2018 15:36:10 +0300 Subject: [PATCH] vinyl: fix lost key on dump completion vy_task_dump_complete() creates a slice per each range overlapping with the newly written run. It uses vy_range_tree_psearch(min_key) to find the first overlapping range and nsearch(max_key) to find the range immediately following the last overlapping range. This is incorrect as nsearch rb tree method returns the element matching the search key if it is present in the tree. That is, if the max key written to a run turns out to be equal the beginning of a range, the slice won't be created for it and it will be silently and persistently lost. 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_scheduler.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/box/vy_scheduler.c b/src/box/vy_scheduler.c index 4954afe75d..e1853e5d46 100644 --- a/src/box/vy_scheduler.c +++ b/src/box/vy_scheduler.c @@ -751,7 +751,12 @@ vy_task_dump_complete(struct vy_scheduler *scheduler, struct vy_task *task) goto fail; } begin_range = vy_range_tree_psearch(index->tree, min_key); - end_range = vy_range_tree_nsearch(index->tree, max_key); + end_range = vy_range_tree_psearch(index->tree, max_key); + /* + * If min_key == max_key, the slice has to span over at + * least one range. + */ + end_range = vy_range_tree_next(index->tree, end_range); tuple_unref(min_key); tuple_unref(max_key); -- GitLab