Skip to content

Commit 04c31c2

Browse files
committed
SPDB-671: Block Bloom - Part 1
1 parent 6547c56 commit 04c31c2

File tree

8 files changed

+557
-4
lines changed

8 files changed

+557
-4
lines changed

db/db_bloom_filter_test.cc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,69 @@ TEST_F(DBBloomFilterTest, BloomFilterRate) {
599599
}
600600
}
601601

602+
template<class T>
603+
std::string FormatWithCommas(T value)
604+
{
605+
std::stringstream ss;
606+
ss.imbue(std::locale(""));
607+
ss << std::fixed << value;
608+
return ss.str();
609+
}
610+
611+
TEST_F(DBBloomFilterTest, DISABLED_SpdbBlockBloomFilterRate) {
612+
option_config_ = kSpdbBlockBloomFilter;
613+
Options options = CurrentOptions();
614+
options.statistics = ROCKSDB_NAMESPACE::CreateDBStatistics();
615+
616+
get_perf_context()->EnablePerLevelPerfContext();
617+
CreateAndReopenWithCF({"pikachu"}, options);
618+
619+
int num_keys = 1000 * 1000;
620+
int first_key = num_keys;
621+
int last_key = first_key + num_keys - 1;
622+
for (auto i = first_key; i <= last_key; i++) {
623+
ASSERT_OK(Put(1, Key(i), Key(i)));
624+
}
625+
626+
// Add a large key to make the file contain wide range
627+
int very_large_key_val = 1 << 31;
628+
ASSERT_OK(Put(1, Key(very_large_key_val), Key(very_large_key_val)));
629+
Flush(1);
630+
631+
// Check if they can be found
632+
std::cerr << "Checking that " << FormatWithCommas(num_keys) << " keys that are in the filter are found\n";
633+
for (auto i = first_key; i <= last_key; i++) {
634+
ASSERT_EQ(Key(i), Get(1, Key(i)));
635+
}
636+
637+
// Check if filter is useful
638+
int multiplier = 10;
639+
int num_not_found_keys = num_keys * multiplier;
640+
641+
std::cerr << "Checking that " << FormatWithCommas(num_not_found_keys) << " keys that are NOT in the filter are NOT found\n";
642+
auto first_not_found_key = last_key + 1;
643+
auto last_not_found_key = first_not_found_key + num_not_found_keys - 1;
644+
for (int not_found_key = first_not_found_key; not_found_key <= last_not_found_key; ++not_found_key) {
645+
if ((not_found_key - first_not_found_key) % 1000000 == 0) std::cerr << not_found_key << " Keys\n";
646+
ASSERT_EQ("NOT_FOUND", Get(1, Key(not_found_key)));
647+
}
648+
649+
std::cerr << "AFTER Get() for " << num_not_found_keys << " Keys NOT IN THE DB\n";
650+
auto useful = TestGetTickerCount(options, BLOOM_FILTER_USEFUL);
651+
auto full_positive = TestGetTickerCount(options, BLOOM_FILTER_FULL_POSITIVE);
652+
auto true_positive = TestGetTickerCount(options, BLOOM_FILTER_FULL_TRUE_POSITIVE);
653+
654+
std::cerr << "BLOOM_FILTER_USEFUL = " << FormatWithCommas(useful) << '\n';
655+
std::cerr << "BLOOM_FILTER_FULL_POSITIVE = " << FormatWithCommas(full_positive) << '\n';
656+
std::cerr << "BLOOM_FILTER_FULL_TRUE_POSITIVE = " << FormatWithCommas(true_positive) << '\n';
657+
658+
auto false_positive = full_positive - true_positive;
659+
auto fpr = false_positive / static_cast<double>(useful + false_positive);
660+
std::cerr << "FPR = 1 in " << static_cast<double>(1 / fpr) << '\n';
661+
662+
get_perf_context()->Reset();
663+
}
664+
602665
TEST_F(DBBloomFilterTest, BloomFilterCompatibility) {
603666
Options options = CurrentOptions();
604667
options.statistics = ROCKSDB_NAMESPACE::CreateDBStatistics();

db/db_test_util.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "rocksdb/utilities/object_registry.h"
1717
#include "util/random.h"
1818

19+
#include <iostream>
20+
1921
namespace ROCKSDB_NAMESPACE {
2022

2123
namespace {
@@ -261,9 +263,14 @@ bool DBTestBase::ChangeFilterOptions() {
261263
option_config_ = kFullFilterWithNewTableReaderForCompactions;
262264
} else if (option_config_ == kFullFilterWithNewTableReaderForCompactions) {
263265
option_config_ = kPartitionedFilterWithNewTableReaderForCompactions;
266+
} else if (option_config_ == kPartitionedFilterWithNewTableReaderForCompactions) {
267+
option_config_ = kSpdbBlockBloomFilter;
264268
} else {
269+
std::cerr << "ChangeFilterOptions - Returns False\n";
265270
return false;
266271
}
272+
std::cerr << "option_config_ = " << option_config_ << '\n';
273+
267274
Destroy(last_options_);
268275

269276
auto options = CurrentOptions();
@@ -431,6 +438,9 @@ Options DBTestBase::GetOptions(
431438
options.new_table_reader_for_compaction_inputs = true;
432439
options.compaction_readahead_size = 10 * 1024 * 1024;
433440
break;
441+
case kSpdbBlockBloomFilter:
442+
table_options.filter_policy.reset(NewSpdbBlockBloomFilterPolicy());
443+
break;
434444
case kUncompressed:
435445
options.compression = kNoCompression;
436446
break;

db/db_test_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,8 @@ class DBTestBase : public testing::Test {
946946
kUniversalSubcompactions,
947947
kxxHash64Checksum,
948948
kUnorderedWrite,
949+
kSpdbBlockBloomFilter,
950+
949951
// This must be the last line
950952
kEnd,
951953
};

include/rocksdb/filter_policy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,6 @@ inline const FilterPolicy* NewExperimentalRibbonFilterPolicy(
277277
}
278278

279279
extern const FilterPolicy* NewSpdbHybridFilterPolicy();
280+
extern const FilterPolicy* NewSpdbBlockBloomFilterPolicy();
280281

281282
} // namespace ROCKSDB_NAMESPACE

include/rocksdb/table.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ struct BlockBasedTableOptions {
339339
// Many applications will benefit from passing the result of
340340
// NewBloomFilterPolicy() here.
341341
std::shared_ptr<const FilterPolicy> filter_policy{
342-
NewSpdbHybridFilterPolicy()};
343-
342+
// // // NewSpdbHybridFilterPolicy()};
343+
NewSpdbBlockBloomFilterPolicy()};
344344
// If true, place whole keys in the filter (not just prefixes).
345345
// This must generally be true for gets to be efficient.
346346
bool whole_key_filtering = true;

0 commit comments

Comments
 (0)