Skip to content

Commit

Permalink
Fix kBlockCacheTier read with table cache miss (facebook#12443)
Browse files Browse the repository at this point in the history
Summary:
Thanks ltamasi for pointing out this bug.

We were incorrectly overwriting `Status::Incomplete` with `Status::OK` after a table cache miss failed to open the file due to the read being memory-only (`kBlockCacheTier`). The fix is to simply stop overwriting the status.

Pull Request resolved: facebook#12443

Reviewed By: cbi42

Differential Revision: D54930128

Pulled By: ajkr

fbshipit-source-id: 52f912a2e93b46e71d79fc5968f8ca35b299213d
  • Loading branch information
ajkr authored and facebook-github-bot committed Mar 15, 2024
1 parent 3f5bd46 commit 4d5ebad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
21 changes: 21 additions & 0 deletions db/db_test2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7808,6 +7808,27 @@ TEST_F(DBTest2, ZSTDChecksum) {
}
#endif

TEST_F(DBTest2, TableCacheMissDuringReadFromBlockCacheTier) {
Options options = CurrentOptions();
options.statistics = ROCKSDB_NAMESPACE::CreateDBStatistics();
Reopen(options);

// Give table cache zero capacity to prevent preloading tables. That way,
// `kBlockCacheTier` reads will fail due to table cache misses.
dbfull()->TEST_table_cache()->SetCapacity(0);
ASSERT_OK(Put("foo", "bar"));
ASSERT_OK(Flush());

uint64_t orig_num_file_opens = TestGetTickerCount(options, NO_FILE_OPENS);

ReadOptions non_blocking_opts;
non_blocking_opts.read_tier = kBlockCacheTier;
std::string value;
ASSERT_TRUE(db_->Get(non_blocking_opts, "foo", &value).IsIncomplete());

ASSERT_EQ(orig_num_file_opens, TestGetTickerCount(options, NO_FILE_OPENS));
}

} // namespace ROCKSDB_NAMESPACE

int main(int argc, char** argv) {
Expand Down
5 changes: 2 additions & 3 deletions db/table_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,8 @@ Status TableCache::Get(
s = t->Get(options, k, get_context, prefix_extractor.get(), skip_filters);
get_context->SetReplayLog(nullptr);
} else if (options.read_tier == kBlockCacheTier && s.IsIncomplete()) {
// Couldn't find Table in cache but treat as kFound if no_io set
// Couldn't find table in cache and couldn't open it because of no_io.
get_context->MarkKeyMayExist();
s = Status::OK();
done = true;
}
}
Expand Down Expand Up @@ -729,4 +728,4 @@ uint64_t TableCache::ApproximateSize(

return result;
}
} // namespace ROCKSDB_NAMESPACE
} // namespace ROCKSDB_NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fixed `kBlockCacheTier` reads to return `Status::Incomplete` on table cache miss rather than incorrectly returning an empty value.

0 comments on commit 4d5ebad

Please sign in to comment.