diff --git a/db/db_test.cc b/db/db_test.cc index 1e39454df..5b21b2f1b 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -240,6 +240,8 @@ class SpecialEnv : public EnvWrapper { class DBTest { private: const FilterPolicy* filter_policy_; + static std::unique_ptr prefix_1_transform; + static std::unique_ptr noop_transform; protected: // Sequence of option configurations to try @@ -356,13 +358,13 @@ class DBTest { break; case kPlainTableFirstBytePrefix: options.table_factory.reset(new PlainTableFactory()); - options.prefix_extractor = NewFixedPrefixTransform(1); + options.prefix_extractor = prefix_1_transform.get(); options.allow_mmap_reads = true; options.max_sequential_skip_in_iterations = 999999; break; case kPlainTableAllBytesPrefix: options.table_factory.reset(new PlainTableFactory()); - options.prefix_extractor = NewNoopTransform(); + options.prefix_extractor = noop_transform.get(); options.allow_mmap_reads = true; options.max_sequential_skip_in_iterations = 999999; break; @@ -694,6 +696,10 @@ class DBTest { delete iter; } }; +std::unique_ptr DBTest::prefix_1_transform( + NewFixedPrefixTransform(1)); +std::unique_ptr DBTest::noop_transform( + NewNoopTransform()); static std::string Key(int i) { char buf[100]; @@ -4694,20 +4700,22 @@ TEST(DBTest, PrefixScan) { snprintf(buf, sizeof(buf), "03______:"); prefix = Slice(buf, 8); key = Slice(buf, 9); - auto prefix_extractor = NewFixedPrefixTransform(8); // db configs env_->count_random_reads_ = true; Options options = CurrentOptions(); options.env = env_; options.no_block_cache = true; - options.filter_policy = NewBloomFilterPolicy(10); - options.prefix_extractor = prefix_extractor; + options.filter_policy = NewBloomFilterPolicy(10); + options.prefix_extractor = NewFixedPrefixTransform(8); options.whole_key_filtering = false; options.disable_auto_compactions = true; options.max_background_compactions = 2; options.create_if_missing = true; options.disable_seek_compaction = true; - options.memtable_factory.reset(NewHashSkipListRepFactory(prefix_extractor)); + // Tricky: options.prefix_extractor will be released by + // NewHashSkipListRepFactory after use. + options.memtable_factory.reset( + NewHashSkipListRepFactory(options.prefix_extractor)); // prefix specified, with blooms: 2 RAND I/Os // SeekToFirst diff --git a/db/plain_table_db_test.cc b/db/plain_table_db_test.cc index 17f871e4c..1ead9729a 100644 --- a/db/plain_table_db_test.cc +++ b/db/plain_table_db_test.cc @@ -35,16 +35,17 @@ using std::unique_ptr; namespace rocksdb { class PlainTableDBTest { -protected: -public: + protected: + private: std::string dbname_; Env* env_; DB* db_; Options last_options_; + static std::unique_ptr prefix_transform; - PlainTableDBTest() : - env_(Env::Default()) { + public: + PlainTableDBTest() : env_(Env::Default()) { dbname_ = test::TmpDir() + "/plain_table_db_test"; ASSERT_OK(DestroyDB(dbname_, Options())); db_ = nullptr; @@ -60,7 +61,7 @@ public: Options CurrentOptions() { Options options; options.table_factory.reset(new PlainTableFactory(16, 2, 0.8)); - options.prefix_extractor = NewFixedPrefixTransform(8); + options.prefix_extractor = prefix_transform.get(); options.allow_mmap_reads = true; return options; } @@ -167,8 +168,11 @@ public: } }; +std::unique_ptr PlainTableDBTest::prefix_transform( + NewFixedPrefixTransform(8)); + TEST(PlainTableDBTest, Empty) { - ASSERT_TRUE(db_ != nullptr); + ASSERT_TRUE(dbfull() != nullptr); ASSERT_EQ("NOT_FOUND", Get("0000000000000foo")); } diff --git a/table/table_test.cc b/table/table_test.cc index bff8ee529..a36e726a1 100644 --- a/table/table_test.cc +++ b/table/table_test.cc @@ -647,7 +647,7 @@ class Harness { case PLAIN_TABLE_FULL_STR_PREFIX: support_prev_ = false; only_support_prefix_seek_ = true; - options_.prefix_extractor = NewNoopTransform(); + options_.prefix_extractor = noop_transform.get(); options_.allow_mmap_reads = true; options_.table_factory.reset(new PlainTableFactory()); constructor_ = new TableConstructor(options_.comparator, true); @@ -849,8 +849,12 @@ class Harness { bool support_prev_; bool only_support_prefix_seek_; shared_ptr internal_comparator_; + static std::unique_ptr noop_transform; }; +std::unique_ptr Harness::noop_transform( + NewNoopTransform()); + static bool Between(uint64_t val, uint64_t low, uint64_t high) { bool result = (val >= low) && (val <= high); if (!result) {