test::StringSource* string_source =
new test::StringSource(contents, 0, false);
- unique_ptr<RandomAccessFileReader> file_reader(
+ std::unique_ptr<RandomAccessFileReader> file_reader(
test::GetRandomAccessFileReader(string_source));
- unique_ptr<PlainTableReaderFileInfo> file_info(new PlainTableReaderFileInfo(
- std::move(file_reader), EnvOptions(), kLength));
+ std::unique_ptr<PlainTableReaderFileInfo> file_info(
+ new PlainTableReaderFileInfo(std::move(file_reader), EnvOptions(),
+ kLength));
{
PlainTableFileReader reader(file_info.get());
public:
PlainTableDBTest() : env_(Env::Default()) {}
- ~PlainTableDBTest() {
+ ~PlainTableDBTest() override {
delete db_;
EXPECT_OK(DestroyDB(dbname_, Options()));
}
db_ = nullptr;
}
+ bool mmap_mode() const { return mmap_mode_; }
+
void DestroyAndReopen(Options* options = nullptr) {
//Destroy using last options
Destroy(&last_options_);
return DB::Open(*options, dbname_, db);
}
+ Status ReopenForReadOnly(Options* options) {
+ delete db_;
+ db_ = nullptr;
+ return DB::OpenForReadOnly(*options, dbname_, &db_);
+ }
+
Status TryReopen(Options* options = nullptr) {
delete db_;
db_ = nullptr;
int bloom_bits_per_key, double hash_table_ratio,
size_t index_sparseness,
const TableProperties* table_properties,
- unique_ptr<RandomAccessFileReader>&& file,
+ std::unique_ptr<RandomAccessFileReader>&& file,
const ImmutableCFOptions& ioptions,
const SliceTransform* prefix_extractor,
bool* expect_bloom_not_match, bool store_index_in_file,
}
}
- virtual ~TestPlainTableReader() {}
+ ~TestPlainTableReader() override {}
private:
- virtual bool MatchBloom(uint32_t hash) const override {
+ bool MatchBloom(uint32_t hash) const override {
bool ret = PlainTableReader::MatchBloom(hash);
if (*expect_bloom_not_match_) {
EXPECT_TRUE(!ret);
Status NewTableReader(
const TableReaderOptions& table_reader_options,
- unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
- unique_ptr<TableReader>* table,
+ std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
+ std::unique_ptr<TableReader>* table,
bool /*prefetch_index_and_filter_in_cache*/) const override {
TableProperties* props = nullptr;
auto s =
}
}
+TEST_P(PlainTableDBTest, Immortal) {
+ for (EncodingType encoding_type : {kPlain, kPrefix}) {
+ Options options = CurrentOptions();
+ options.create_if_missing = true;
+ options.max_open_files = -1;
+ // Set only one bucket to force bucket conflict.
+ // Test index interval for the same prefix to be 1, 2 and 4
+ PlainTableOptions plain_table_options;
+ plain_table_options.hash_table_ratio = 0.75;
+ plain_table_options.index_sparseness = 16;
+ plain_table_options.user_key_len = kPlainTableVariableLength;
+ plain_table_options.bloom_bits_per_key = 10;
+ plain_table_options.encoding_type = encoding_type;
+ options.table_factory.reset(NewPlainTableFactory(plain_table_options));
+
+ DestroyAndReopen(&options);
+ ASSERT_OK(Put("0000000000000bar", "b"));
+ ASSERT_OK(Put("1000000000000foo", "v1"));
+ dbfull()->TEST_FlushMemTable();
+
+ int copied = 0;
+ rocksdb::SyncPoint::GetInstance()->SetCallBack(
+ "GetContext::SaveValue::PinSelf", [&](void* /*arg*/) { copied++; });
+ rocksdb::SyncPoint::GetInstance()->EnableProcessing();
+ ASSERT_EQ("b", Get("0000000000000bar"));
+ ASSERT_EQ("v1", Get("1000000000000foo"));
+ ASSERT_EQ(2, copied);
+ copied = 0;
+
+ Close();
+ ASSERT_OK(ReopenForReadOnly(&options));
+
+ ASSERT_EQ("b", Get("0000000000000bar"));
+ ASSERT_EQ("v1", Get("1000000000000foo"));
+ ASSERT_EQ("NOT_FOUND", Get("1000000000000bar"));
+ if (mmap_mode()) {
+ ASSERT_EQ(0, copied);
+ } else {
+ ASSERT_EQ(2, copied);
+ }
+ rocksdb::SyncPoint::GetInstance()->DisableProcessing();
+ }
+}
+
TEST_P(PlainTableDBTest, Iterator) {
for (size_t huge_page_tlb_size = 0; huge_page_tlb_size <= 2 * 1024 * 1024;
huge_page_tlb_size += 2 * 1024 * 1024) {