Skip to content

memtx: fix reverse iterators gap tracking#7410

Merged
alyapunov merged 2 commits intotarantool:masterfrom
CuriousGeorgiy:gh-7409-gap-tracking-rev-iters
Aug 4, 2022
Merged

memtx: fix reverse iterators gap tracking#7410
alyapunov merged 2 commits intotarantool:masterfrom
CuriousGeorgiy:gh-7409-gap-tracking-rev-iters

Conversation

@CuriousGeorgiy
Copy link
Member

In case of reverse iterators, due to index limitations, we need to clarify
the successor tuple early: this implies that the successor's story is not
always at the top of the history chain, whilst we need to add the gap item
to the story currently present in index — fix this by explicitly retrieving
the top story in the successor's history chain.

CLoses #7409

NO_DOC=bugfix

@drewdzzz
Copy link
Contributor

diff --git a/src/box/memtx_tree.cc b/src/box/memtx_tree.cc
index 1ec614f6c..b2ca40322 100644
--- a/src/box/memtx_tree.cc
+++ b/src/box/memtx_tree.cc
@@ -397,8 +397,13 @@ tree_iterator_prev_raw_base(struct iterator *iterator, struct tuple **ret)
 	struct memtx_tree_data<USE_HINT> *check =
 		memtx_tree_iterator_get_elem(&index->tree, &it->tree_iterator);
 	if (check == NULL || !memtx_tree_data_is_equal(check, &it->current)) {
+		bool exact = false;
 		it->tree_iterator = memtx_tree_lower_bound_elem(&index->tree,
-								it->current, NULL);
+								it->current, &exact);
+		struct memtx_tree_data<USE_HINT> *tmp = memtx_tree_iterator_get_elem
+			(&index->tree, &it->tree_iterator);
+		tree_iterator_set_current(it, tmp);
+		assert(exact);
 	}
 	memtx_tree_iterator_prev(&index->tree, &it->tree_iterator);
 	struct tuple *successor = it->current.tuple;
@@ -491,8 +496,13 @@ tree_iterator_prev_equal_raw_base(struct iterator *iterator, struct tuple **ret)
 	struct memtx_tree_data<USE_HINT> *check =
 		memtx_tree_iterator_get_elem(&index->tree, &it->tree_iterator);
 	if (check == NULL || !memtx_tree_data_is_equal(check, &it->current)) {
+		bool exact = false;
 		it->tree_iterator = memtx_tree_lower_bound_elem(&index->tree,
-								it->current, NULL);
+								it->current, &exact);
+		struct memtx_tree_data<USE_HINT> *tmp = memtx_tree_iterator_get_elem
+			(&index->tree, &it->tree_iterator);
+		tree_iterator_set_current(it, tmp);
+		assert(exact);
 	}
 	memtx_tree_iterator_prev(&index->tree, &it->tree_iterator);
 	struct tuple *successor = it->current.tuple;
diff --git a/src/box/memtx_tx.c b/src/box/memtx_tx.c
index 2b858944b..0564dda96 100644
--- a/src/box/memtx_tx.c
+++ b/src/box/memtx_tx.c
@@ -2847,6 +2847,7 @@ memtx_tx_track_gap_slow(struct txn *txn, struct space *space, struct index *inde
 			}
 		}
 		assert(index->dense_id < story->index_count);
+		assert(story->link[index->dense_id].in_index != NULL);
 		rlist_add(&story->link[index->dense_id].nearby_gaps,
 			  &item->in_nearby_gaps);
 	} else {

This patch fixes the problem too, but without iteration over tuple stories.

@drewdzzz drewdzzz assigned CuriousGeorgiy and unassigned drewdzzz Jul 26, 2022
@CuriousGeorgiy CuriousGeorgiy removed their assignment Jul 27, 2022
All the 'base' TREE index iterator `next` methods (including
`tree_iterator_start`) internally set the iterator's current tuple to the
one found in the index satisfying the conditions: setting the iterator's
current tuple to the clarified one is redundant and moreover gives a
performance penalty each iteration because of the iterator check logic.

Needed for tarantool#7409

NO_CHANGELOG=refactoring
NO_DOC=refactoring
NO_TEST=refactoring
@CuriousGeorgiy CuriousGeorgiy force-pushed the gh-7409-gap-tracking-rev-iters branch 4 times, most recently from 3a0489f to 3d789af Compare July 28, 2022 06:46
In case of reverse iterators, due to index limitations, we need to clarify
the successor tuple early: this implies that the successor's story is not
always at the top of the history chain, whilst we need to add the gap item
to the story currently present in index — fix this by reusing the
iterators' check logic to set the current iterator's tuple (which is
considered the successor) to a tuple in index.

CLoses tarantool#7409

NO_DOC=bugfix
@CuriousGeorgiy CuriousGeorgiy force-pushed the gh-7409-gap-tracking-rev-iters branch from 3d789af to 6ea662b Compare July 28, 2022 06:51
@drewdzzz drewdzzz requested a review from Korablev77 July 28, 2022 09:23
Copy link
Contributor

@drewdzzz drewdzzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but PR comment is stale.

@drewdzzz drewdzzz removed their assignment Jul 28, 2022
memtx_tree_lower_bound_elem(&index->tree, iterator->current,
&exact);
if (exact) {
struct memtx_tree_data<USE_HINT> *successor =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would not call it successor here since it is current in the context.

@alyapunov alyapunov added the full-ci Enables all tests for a pull request label Aug 4, 2022
@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 84.278% when pulling 6ea662b on CuriousGeorgiy:gh-7409-gap-tracking-rev-iters into 969b76a on tarantool:master.

@alyapunov alyapunov merged commit fda38e6 into tarantool:master Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working full-ci Enables all tests for a pull request memtx mvcc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reverse iterators phantom reads

5 participants