From 888fbdc88921a476d3797820fe2bc72b14a794fe Mon Sep 17 00:00:00 2001 From: sdong Date: Wed, 19 Aug 2015 10:08:03 -0700 Subject: [PATCH] Remove the contstaint that iterator upper bound needs to be within a prefix Summary: There is a check to fail the iterator if prefix extractor is specified but upper bound is out of the prefix for the seek key. Relax this constraint to allow users to set upper bound to the next prefix of the current one. Test Plan: make commit-prereq Reviewers: igor, anthony, kradhakrishnan, yhchiang, rven Reviewed By: rven Subscribers: tnovak, leveldb, dhruba Differential Revision: https://reviews.facebook.net/D44949 --- db/db_iter.cc | 15 --------------- db/db_test.cc | 13 ++++++++++--- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/db/db_iter.cc b/db/db_iter.cc index fd341cc5f..2e17b4dd9 100644 --- a/db/db_iter.cc +++ b/db/db_iter.cc @@ -625,21 +625,6 @@ void DBIter::FindParseableKey(ParsedInternalKey* ikey, Direction direction) { void DBIter::Seek(const Slice& target) { StopWatch sw(env_, statistics_, DB_SEEK); - - // total ordering is not guaranteed if prefix_extractor is set - // hence prefix based seeks will not give correct results - if (iterate_upper_bound_ != nullptr && prefix_extractor_ != nullptr) { - if (!prefix_extractor_->InDomain(*iterate_upper_bound_) || - !prefix_extractor_->InDomain(target) || - prefix_extractor_->Transform(*iterate_upper_bound_).compare( - prefix_extractor_->Transform(target)) != 0) { - status_ = Status::InvalidArgument("read_options.iterate_*_bound " - " and seek target need to have the same prefix."); - valid_ = false; - return; - } - } - saved_key_.Clear(); // now savved_key is used to store internal key. saved_key_.SetInternalKey(target, sequence_); diff --git a/db/db_test.cc b/db/db_test.cc index b7aa39ef9..573b31139 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -5844,15 +5844,22 @@ TEST_F(DBTest, DBIteratorBoundTest) { // This should be an error { ReadOptions ro; - Slice prefix("g1"); - ro.iterate_upper_bound = &prefix; + Slice upper_bound("g"); + ro.iterate_upper_bound = &upper_bound; std::unique_ptr iter(db_->NewIterator(ro)); iter->Seek("foo"); + ASSERT_TRUE(iter->Valid()); + ASSERT_EQ("foo", iter->key().ToString()); + + iter->Next(); + ASSERT_TRUE(iter->Valid()); + ASSERT_EQ("foo1", iter->key().ToString()); + + iter->Next(); ASSERT_TRUE(!iter->Valid()); - ASSERT_TRUE(iter->status().IsInvalidArgument()); } // testing that iterate_upper_bound prevents iterating over deleted items -- GitLab