Skip to content

Commit 889b499

Browse files
committed
use gflags in bloom_filter
1 parent 398c66b commit 889b499

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/flags.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ DEFINE_int32(snapshot_pool_size, 1, "the size of tablet thread pool for making s
121121

122122
DEFINE_uint32(load_index_max_wait_time, 120 * 60 * 1000, "config the max wait time of load index");
123123

124+
DEFINE_uint32(bloom_filter_bitset_size, 10000, "config the size of bitset in bloom filter");
125+
DEFINE_uint32(bloom_filter_hash_seed, 7, "config the count of hash seed in bloom filter, max 7");
126+
124127
DEFINE_string(recycle_bin_root_path, "/tmp/recycle", "specify the root path of recycle bin");
125128
DEFINE_string(recycle_bin_ssd_root_path, "", "specify the root path of recycle bin in ssd");
126129
DEFINE_string(recycle_bin_hdd_root_path, "", "specify the root path of recycle bin in hdd");

src/storage/disk_table.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ DECLARE_uint32(write_buffer_mb);
3131
DECLARE_uint32(block_cache_shardbits);
3232
DECLARE_bool(verify_compression);
3333

34+
DECLARE_uint32(bloom_filter_bitset_size);
35+
DECLARE_uint32(bloom_filter_hash_seed);
36+
3437
namespace openmldb {
3538
namespace storage {
3639

@@ -154,7 +157,7 @@ bool DiskTable::InitColumnFamilyDescriptor() {
154157
auto inner_indexs = table_index_.GetAllInnerIndex();
155158
for (uint32_t i = 0; i < inner_indexs->size(); i++) {
156159
pk_cnt_vec_.push_back(std::make_shared<std::atomic<uint64_t>>(0));
157-
bloom_filter_vec_.push_back(BloomFilter(1000, 100));
160+
bloom_filter_vec_.push_back(BloomFilter());
158161
}
159162
auto indexs = table_index_.GetAllIndex();
160163
for (uint32_t i = 0; i < indexs.size(); i++) {
@@ -1359,15 +1362,15 @@ bool BloomFilter::getBit(uint32_t bit) {
13591362
}
13601363

13611364
void BloomFilter::Set(const char* str) {
1362-
for (uint32_t i = 0; i < k_; ++i) {
1363-
uint32_t p = hash(str, base_[i]) % bitset_size_;
1365+
for (uint32_t i = 0; i < FLAGS_bloom_filter_hash_seed; ++i) {
1366+
uint32_t p = hash(str, base_[i]) % FLAGS_bloom_filter_bitset_size;
13641367
setBit(p);
13651368
}
13661369
}
13671370

13681371
bool BloomFilter::Valid(const char* str) {
1369-
for (uint32_t i = 0; i < k_; ++i) {
1370-
uint32_t p = hash(str, base_[i]) % bitset_size_;
1372+
for (uint32_t i = 0; i < FLAGS_bloom_filter_hash_seed; ++i) {
1373+
uint32_t p = hash(str, base_[i]) % FLAGS_bloom_filter_bitset_size;
13711374
if (!getBit(p)) {
13721375
return false;
13731376
}

src/storage/disk_table.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#include "storage/table.h"
4242
#include "base/glog_wapper.h" // NOLINT
4343

44+
DECLARE_uint32(bloom_filter_bitset_size);
45+
DECLARE_uint32(bloom_filter_hash_seed);
46+
4447
namespace openmldb {
4548
namespace storage {
4649

@@ -129,9 +132,8 @@ class KeyTSComparator : public rocksdb::Comparator {
129132

130133
class BloomFilter {
131134
public:
132-
BloomFilter(uint32_t bitset_size, uint32_t string_cnt) : k_(5), bitset_size_(bitset_size), string_cnt_(string_cnt) {
133-
bits_.reserve(10000);
134-
for (uint32_t i = 0; i < 10000; i++) {
135+
BloomFilter() {
136+
for (uint32_t i = 0; i < FLAGS_bloom_filter_bitset_size; i++) {
135137
bits_.push_back(std::make_shared<std::atomic<uint64_t>>(0));
136138
}
137139
}
@@ -146,10 +148,8 @@ class BloomFilter {
146148
void setBit(uint32_t bit);
147149
bool getBit(uint32_t bit);
148150

149-
uint32_t k_, bitset_size_,
150-
string_cnt_;
151151
std::vector<std::shared_ptr<std::atomic<uint64_t>>> bits_;
152-
uint32_t base_[100] = {5, 7, 11, 13, 31, 37, 61};
152+
uint32_t base_[7] = {5, 7, 11, 13, 31, 37, 61};
153153
};
154154

155155
class KeyTsPrefixTransform : public rocksdb::SliceTransform {

0 commit comments

Comments
 (0)