Fix assertion error with read_opts.iter_start_ts (#10279)

Summary:
If the internal iterator is not valid, `SeekToLast` with iter_start_ts should have `valid_` is false without assertion failure.
Test plan
make check

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10279

Reviewed By: ltamasi

Differential Revision: D37539393

Pulled By: riversand963

fbshipit-source-id: 8e94057838f8a05144fad5768f4d62f1893ec315
main
Yanqin Jin 2 years ago committed by Facebook GitHub Bot
parent 57a0e2f304
commit b87c355772
  1. 2
      db/db_iter.cc
  2. 8
      db/db_with_timestamp_basic_test.cc

@ -1612,7 +1612,7 @@ void DBIter::SeekToLast() {
SeekForPrev(*iterate_upper_bound_); SeekForPrev(*iterate_upper_bound_);
const bool is_ikey = (timestamp_size_ > 0 && timestamp_lb_ != nullptr); const bool is_ikey = (timestamp_size_ > 0 && timestamp_lb_ != nullptr);
Slice k = Valid() ? key() : Slice(); Slice k = Valid() ? key() : Slice();
if (is_ikey) { if (is_ikey && Valid()) {
k.remove_suffix(kNumInternalBytes + timestamp_size_); k.remove_suffix(kNumInternalBytes + timestamp_size_);
} }
while (Valid() && 0 == user_comparator_.CompareWithoutTimestamp( while (Valid() && 0 == user_comparator_.CompareWithoutTimestamp(

@ -1193,6 +1193,14 @@ TEST_F(DBBasicTestWithTimestamp, SimpleBackwardIterateLowerTsBound) {
it->SeekToLast(); it->SeekToLast();
CheckIterEntry(it.get(), "a", kTypeSingleDeletion, Slice(), CheckIterEntry(it.get(), "a", kTypeSingleDeletion, Slice(),
Timestamp(1, 0)); Timestamp(1, 0));
key_ub_str = "a"; // exclusive
key_ub = key_ub_str;
read_opts.iterate_upper_bound = &key_ub;
it.reset(db_->NewIterator(read_opts));
it->SeekToLast();
ASSERT_FALSE(it->Valid());
ASSERT_OK(it->status());
} }
Close(); Close();

Loading…
Cancel
Save