From 249fb4f881c9ef01bbe46b29952bf3d237d391d5 Mon Sep 17 00:00:00 2001 From: Venkatesh Radhakrishnan Date: Tue, 25 Aug 2015 13:38:35 -0700 Subject: [PATCH] Fix use of deleted file iterators with incomplete iterators Summary: After deleting file iterators which are over the iterate upper bound, we also need to check for null pointers in ResetIncompletIterators. Test Plan: db_tailing_iter_test.TailingIteratorTrimSeekToNext Reviewers: tnovak, sdong Reviewed By: sdong Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D45525 --- db/db_tailing_iter_test.cc | 9 +++++++++ db/forward_iterator.cc | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/db/db_tailing_iter_test.cc b/db/db_tailing_iter_test.cc index e6731df6a4..478a48aa6e 100644 --- a/db/db_tailing_iter_test.cc +++ b/db/db_tailing_iter_test.cc @@ -171,6 +171,15 @@ TEST_F(DBTestTailingIterator, TailingIteratorTrimSeekToNext) { ASSERT_TRUE(itern->Valid()); ASSERT_EQ(itern->key().compare(key), 0); } + + read_options.read_tier = kBlockCacheTier; + std::unique_ptr iteri(db_->NewIterator(read_options, handles_[1])); + char buf5[32]; + snprintf(buf5, sizeof(buf5), "00a0%016d", (num_records / 2) * 5 - 2); + Slice target1(buf5, 20); + iteri->Seek(target1); + ASSERT_TRUE(iteri->Valid() || iteri->status().IsIncomplete()); + for (int i = 2 * num_records; i > 0; --i) { char buf1[32]; char buf2[32]; diff --git a/db/forward_iterator.cc b/db/forward_iterator.cc index 138dcd341b..c298f9f8bc 100644 --- a/db/forward_iterator.cc +++ b/db/forward_iterator.cc @@ -514,7 +514,7 @@ void ForwardIterator::ResetIncompleteIterators() { const auto& l0_files = sv_->current->storage_info()->LevelFiles(0); for (uint32_t i = 0; i < l0_iters_.size(); ++i) { assert(i < l0_files.size()); - if (!l0_iters_[i]->status().IsIncomplete()) { + if (!l0_iters_[i] || !l0_iters_[i]->status().IsIncomplete()) { continue; } delete l0_iters_[i];