diff --git a/db/db_iter.cc b/db/db_iter.cc index afc4596a5..0c4f2b685 100644 --- a/db/db_iter.cc +++ b/db/db_iter.cc @@ -512,8 +512,7 @@ void DBIter::ReverseToForward() { IterKey last_key; last_key.SetInternalKey(ParsedInternalKey( saved_key_.GetKey(), kMaxSequenceNumber, kValueTypeForSeek)); - Slice db_iter_key = last_key.GetKey(); - iter_->ResetPrefixSeekKey(&db_iter_key); + iter_->Seek(last_key.GetKey()); } FindNextUserKey(); direction_ = kForward; @@ -527,8 +526,7 @@ void DBIter::ReverseToBackward() { IterKey last_key; last_key.SetInternalKey( ParsedInternalKey(saved_key_.GetKey(), 0, kValueTypeForSeekForPrev)); - Slice db_iter_key = last_key.GetKey(); - iter_->ResetPrefixSeekKey(&db_iter_key); + iter_->SeekForPrev(last_key.GetKey()); } if (current_entry_is_merged_) { // Not placed in the same key. Need to call Prev() until finding the diff --git a/db/db_iterator_test.cc b/db/db_iterator_test.cc index e6bb25405..403cdc56a 100644 --- a/db/db_iterator_test.cc +++ b/db/db_iterator_test.cc @@ -666,7 +666,8 @@ TEST_F(DBIteratorTest, IterMultiWithDelete) { // TODO: merge operator does not support backward iteration yet if (kPlainTableAllBytesPrefix != option_config_ && kBlockBasedTableWithWholeKeyHashIndex != option_config_ && - kHashLinkList != option_config_) { + kHashLinkList != option_config_ && + kHashSkipList != option_config_) { // doesn't support SeekToLast iter->Prev(); ASSERT_EQ(IterStatus(iter), "ka->va"); } @@ -732,7 +733,7 @@ TEST_F(DBIteratorTest, IterWithSnapshot) { // TODO: merge operator does not support backward iteration yet if (kPlainTableAllBytesPrefix != option_config_ && kBlockBasedTableWithWholeKeyHashIndex != option_config_ && - kHashLinkList != option_config_) { + kHashLinkList != option_config_ && kHashSkipList != option_config_) { iter->Prev(); ASSERT_EQ(IterStatus(iter), "key4->val4"); iter->Prev(); @@ -751,7 +752,7 @@ TEST_F(DBIteratorTest, IterWithSnapshot) { // TODO(gzh): merge operator does not support backward iteration yet if (kPlainTableAllBytesPrefix != option_config_ && kBlockBasedTableWithWholeKeyHashIndex != option_config_ && - kHashLinkList != option_config_) { + kHashLinkList != option_config_ && kHashSkipList != option_config_) { iter->SeekForPrev("key1"); ASSERT_EQ(IterStatus(iter), "key1->val1"); iter->Next(); diff --git a/table/internal_iterator.h b/table/internal_iterator.h index 53a4a05ef..62248007c 100644 --- a/table/internal_iterator.h +++ b/table/internal_iterator.h @@ -94,12 +94,6 @@ class InternalIterator : public Cleanable { virtual Status GetProperty(std::string prop_name, std::string* prop) { return Status::NotSupported(""); } - // Reset the key used for Seek() in merge iterator, especially for prefix - // seek mode - // When in prefix_seek_mode, there is inconsistency between db_iterator and - // merge iterator. This inconsistency can cause problem when do Seek() in - // merge iterator in prefix mode. - virtual void ResetPrefixSeekKey(const Slice* prefix_seek_key = nullptr) {} protected: void SeekForPrevImpl(const Slice& target, const Comparator* cmp) { diff --git a/table/merger.cc b/table/merger.cc index 84fae2624..5e8c0d730 100644 --- a/table/merger.cc +++ b/table/merger.cc @@ -158,7 +158,7 @@ class MergingIterator : public InternalIterator { ClearHeaps(); for (auto& child : children_) { if (&child != current_) { - child.Seek(prefix_seek_key_ ? *prefix_seek_key_ : key()); + child.Seek(key()); if (child.Valid() && comparator_->Equal(key(), child.key())) { child.Next(); } @@ -204,7 +204,7 @@ class MergingIterator : public InternalIterator { InitMaxHeap(); for (auto& child : children_) { if (&child != current_) { - child.SeekForPrev(prefix_seek_key_ ? *prefix_seek_key_ : key()); + child.SeekForPrev(key()); if (child.Valid() && comparator_->Equal(key(), child.key())) { child.Prev(); } @@ -277,17 +277,6 @@ class MergingIterator : public InternalIterator { current_->IsValuePinned(); } - virtual void ResetPrefixSeekKey(const Slice* db_iter_key) override { - if (db_iter_key == nullptr) { - prefix_seek_key_.reset(); - return; - } - if (!prefix_seek_key_) { - prefix_seek_key_.reset(new std::string); - } - *prefix_seek_key_ = db_iter_key->ToString(); - } - private: // Clears heaps for both directions, used when changing direction or seeking void ClearHeaps(); @@ -314,7 +303,6 @@ class MergingIterator : public InternalIterator { // forward. Lazily initialize it to save memory. std::unique_ptr maxHeap_; PinnedIteratorsManager* pinned_iters_mgr_; - std::unique_ptr prefix_seek_key_; IteratorWrapper* CurrentForward() const { assert(direction_ == kForward);