diff --git a/db/db_impl/db_impl.cc b/db/db_impl/db_impl.cc index 7076f5ff4d..1321c26222 100644 --- a/db/db_impl/db_impl.cc +++ b/db/db_impl/db_impl.cc @@ -3802,7 +3802,6 @@ bool DBImpl::KeyMayExist(const ReadOptions& read_options, ColumnFamilyHandle* column_family, const Slice& key, std::string* value, std::string* timestamp, bool* value_found) { - assert(value != nullptr); assert(read_options.io_activity == Env::IOActivity::kUnknown); if (value_found != nullptr) { @@ -3819,7 +3818,9 @@ bool DBImpl::KeyMayExist(const ReadOptions& read_options, get_impl_options.value_found = value_found; get_impl_options.timestamp = timestamp; auto s = GetImpl(roptions, key, get_impl_options); - value->assign(pinnable_val.data(), pinnable_val.size()); + if (value_found && *value_found && value) { + value->assign(pinnable_val.data(), pinnable_val.size()); + } // If block_cache is enabled and the index block of the table didn't // not present in block_cache, the return value will be Status::Incomplete. diff --git a/db/db_test2.cc b/db/db_test2.cc index c4590def71..3fc72abc8a 100644 --- a/db/db_test2.cc +++ b/db/db_test2.cc @@ -2103,16 +2103,15 @@ TEST_P(PinL0IndexAndFilterBlocksTest, ASSERT_EQ(2, TestGetTickerCount(options, BLOCK_CACHE_ADD)); ASSERT_EQ(0, TestGetTickerCount(options, BLOCK_CACHE_DATA_MISS)); - std::string value; // Miss and hit count should remain the same, they're all pinned. - ASSERT_TRUE(db_->KeyMayExist(ReadOptions(), handles_[1], "key", &value)); + ASSERT_TRUE(db_->KeyMayExist(ReadOptions(), handles_[1], "key", nullptr)); ASSERT_EQ(1, TestGetTickerCount(options, BLOCK_CACHE_FILTER_MISS)); ASSERT_EQ(0, TestGetTickerCount(options, BLOCK_CACHE_FILTER_HIT)); ASSERT_EQ(1, TestGetTickerCount(options, BLOCK_CACHE_INDEX_MISS)); ASSERT_EQ(0, TestGetTickerCount(options, BLOCK_CACHE_INDEX_HIT)); // Miss and hit count should remain the same, they're all pinned. - value = Get(1, "key"); + std::string value = Get(1, "key"); ASSERT_EQ(1, TestGetTickerCount(options, BLOCK_CACHE_FILTER_MISS)); ASSERT_EQ(0, TestGetTickerCount(options, BLOCK_CACHE_FILTER_HIT)); ASSERT_EQ(1, TestGetTickerCount(options, BLOCK_CACHE_INDEX_MISS));