diff --git a/db/db_iter.cc b/db/db_iter.cc index 1ffc82319..7f2cb8f49 100644 --- a/db/db_iter.cc +++ b/db/db_iter.cc @@ -1612,7 +1612,7 @@ void DBIter::SeekToLast() { SeekForPrev(*iterate_upper_bound_); const bool is_ikey = (timestamp_size_ > 0 && timestamp_lb_ != nullptr); Slice k = Valid() ? key() : Slice(); - if (is_ikey) { + if (is_ikey && Valid()) { k.remove_suffix(kNumInternalBytes + timestamp_size_); } while (Valid() && 0 == user_comparator_.CompareWithoutTimestamp( diff --git a/db/db_with_timestamp_basic_test.cc b/db/db_with_timestamp_basic_test.cc index e08133cb7..593dda903 100644 --- a/db/db_with_timestamp_basic_test.cc +++ b/db/db_with_timestamp_basic_test.cc @@ -1193,6 +1193,14 @@ TEST_F(DBBasicTestWithTimestamp, SimpleBackwardIterateLowerTsBound) { it->SeekToLast(); CheckIterEntry(it.get(), "a", kTypeSingleDeletion, Slice(), 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();