mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 16:30:56 +00:00
fix forward iterator bug
Summary: obvious Test Plan: db_test Reviewers: sdong, haobo, igor Reviewed By: igor Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D18987
This commit is contained in:
parent
80f409ea37
commit
77db08f27b
|
@ -6704,6 +6704,53 @@ TEST(DBTest, TailingIteratorKeepAdding) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(DBTest, TailingIteratorSeekToNext) {
|
||||||
|
CreateAndReopenWithCF({"pikachu"});
|
||||||
|
ReadOptions read_options;
|
||||||
|
read_options.tailing = true;
|
||||||
|
|
||||||
|
std::unique_ptr<Iterator> iter(db_->NewIterator(read_options, handles_[1]));
|
||||||
|
std::string value(1024, 'a');
|
||||||
|
|
||||||
|
const int num_records = 1000;
|
||||||
|
for (int i = 1; i < num_records; ++i) {
|
||||||
|
char buf1[32];
|
||||||
|
char buf2[32];
|
||||||
|
snprintf(buf1, sizeof(buf1), "00a0%016d", i * 5);
|
||||||
|
|
||||||
|
Slice key(buf1, 20);
|
||||||
|
ASSERT_OK(Put(1, key, value));
|
||||||
|
|
||||||
|
if (i % 100 == 99) {
|
||||||
|
ASSERT_OK(Flush(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buf2, sizeof(buf2), "00a0%016d", i * 5 - 2);
|
||||||
|
Slice target(buf2, 20);
|
||||||
|
iter->Seek(target);
|
||||||
|
ASSERT_TRUE(iter->Valid());
|
||||||
|
ASSERT_EQ(iter->key().compare(key), 0);
|
||||||
|
}
|
||||||
|
for (int i = 2 * num_records; i > 0; --i) {
|
||||||
|
char buf1[32];
|
||||||
|
char buf2[32];
|
||||||
|
snprintf(buf1, sizeof(buf1), "00a0%016d", i * 5);
|
||||||
|
|
||||||
|
Slice key(buf1, 20);
|
||||||
|
ASSERT_OK(Put(1, key, value));
|
||||||
|
|
||||||
|
if (i % 100 == 99) {
|
||||||
|
ASSERT_OK(Flush(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buf2, sizeof(buf2), "00a0%016d", i * 5 - 2);
|
||||||
|
Slice target(buf2, 20);
|
||||||
|
iter->Seek(target);
|
||||||
|
ASSERT_TRUE(iter->Valid());
|
||||||
|
ASSERT_EQ(iter->key().compare(key), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(DBTest, TailingIteratorDeletes) {
|
TEST(DBTest, TailingIteratorDeletes) {
|
||||||
CreateAndReopenWithCF({"pikachu"});
|
CreateAndReopenWithCF({"pikachu"});
|
||||||
ReadOptions read_options;
|
ReadOptions read_options;
|
||||||
|
|
|
@ -322,7 +322,7 @@ void ForwardIterator::UpdateCurrent() {
|
||||||
assert(current_ != nullptr);
|
assert(current_ != nullptr);
|
||||||
assert(current_->Valid());
|
assert(current_->Valid());
|
||||||
int cmp = cfd_->internal_comparator().InternalKeyComparator::Compare(
|
int cmp = cfd_->internal_comparator().InternalKeyComparator::Compare(
|
||||||
mutable_iter_->key(), current_->key()) > 0;
|
mutable_iter_->key(), current_->key());
|
||||||
assert(cmp != 0);
|
assert(cmp != 0);
|
||||||
if (cmp > 0) {
|
if (cmp > 0) {
|
||||||
immutable_min_heap_.pop();
|
immutable_min_heap_.pop();
|
||||||
|
|
Loading…
Reference in a new issue