From 1fdf49c10edbc1f5544a75499c5a056b2ac01664 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Mon, 12 Oct 2020 13:43:52 -0700 Subject: [PATCH] Fix bug in pinned partitioned user key indexes Backports part of 75d3b6fdf0aa1007c4d26382f65be0adf4519a37. --- HISTORY.md | 1 + table/iterator_wrapper.h | 5 +++++ table/two_level_iterator.cc | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index bce9de018..aa1cf8be6 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ ## Unreleased ### Bug Fixes * Since 6.12, memtable lookup should report unrecognized value_type as corruption (#7121). +* Fixed a bug in the following combination of features: indexes with user keys (`format_version >= 3`), indexes are partitioned (`index_type == kTwoLevelIndexSearch`), and some index partitions are pinned in memory (`BlockBasedTableOptions::pin_l0_filter_and_index_blocks_in_cache`). The bug could cause keys to be truncated when read from the index leading to wrong read results or other unexpected behavior. ## 6.12.4 (2020-09-18) ### Public API Change diff --git a/table/iterator_wrapper.h b/table/iterator_wrapper.h index 010a23abf..91487708b 100644 --- a/table/iterator_wrapper.h +++ b/table/iterator_wrapper.h @@ -149,6 +149,11 @@ class IteratorWrapperBase { return result_.value_prepared; } + Slice user_key() const { + assert(Valid()); + return iter_->user_key(); + } + private: void Update() { valid_ = iter_->Valid(); diff --git a/table/two_level_iterator.cc b/table/two_level_iterator.cc index a17d56df5..d967deff8 100644 --- a/table/two_level_iterator.cc +++ b/table/two_level_iterator.cc @@ -43,6 +43,10 @@ class TwoLevelIndexIterator : public InternalIteratorBase { assert(Valid()); return second_level_iter_.key(); } + Slice user_key() const override { + assert(Valid()); + return second_level_iter_.user_key(); + } IndexValue value() const override { assert(Valid()); return second_level_iter_.value();