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
main
Cheng Chang 5 years ago committed by Facebook Github Bot
parent f52db84650
commit 741decfe37
  1. 1
      table/cuckoo/cuckoo_table_reader.cc
  2. 8
      table/cuckoo/cuckoo_table_reader_test.cc

@ -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,

@ -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");

Loading…
Cancel
Save