Return early on failure when constructing CuckooTableReader (#6453)

Summary:
If file is not mmaped, CuckooTableReader should not try to read table properties from the file.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6453

Test Plan: Added a new unit test

Differential Revision: D20103334

Pulled By: cheng-chang

fbshipit-source-id: 48539f14d93f6c1ebe12c3df5a14719e9d7b8726
This commit is contained in:
Cheng Chang 2020-02-25 16:45:43 -08:00 committed by Facebook Github Bot
parent f52db84650
commit 741decfe37
2 changed files with 9 additions and 0 deletions

View File

@ -54,6 +54,7 @@ CuckooTableReader::CuckooTableReader(
get_slice_hash_(get_slice_hash) {
if (!ioptions.allow_mmap_reads) {
status_ = Status::InvalidArgument("File is not mmaped");
return;
}
TableProperties* props = nullptr;
status_ = ReadTableProperties(file_.get(), file_size, kCuckooTableMagicNumber,

View File

@ -215,6 +215,14 @@ class CuckooReaderTest : public testing::Test {
EnvOptions env_options;
};
TEST_F(CuckooReaderTest, FileNotMmaped) {
options.allow_mmap_reads = false;
ImmutableCFOptions ioptions(options);
CuckooTableReader reader(ioptions, nullptr, 0, nullptr, nullptr);
ASSERT_TRUE(reader.status().IsInvalidArgument());
ASSERT_STREQ("File is not mmaped", reader.status().getState());
}
TEST_F(CuckooReaderTest, WhenKeyExists) {
SetUp(kNumHashFunc);
fname = test::PerThreadDBPath("CuckooReader_WhenKeyExists");