Skip to content

Commit

Permalink
enable bloom filters for celldb
Browse files Browse the repository at this point in the history
  • Loading branch information
dungeon-master-666 committed Feb 15, 2025
1 parent 3c245c6 commit 34f80e8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tddb/td/db/RocksDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "rocksdb/write_batch.h"
#include "rocksdb/utilities/optimistic_transaction_db.h"
#include "rocksdb/utilities/transaction.h"
#include "rocksdb/filter_policy.h"

namespace td {
namespace {
Expand Down Expand Up @@ -75,6 +76,9 @@ Result<RocksDb> RocksDb::open(std::string path, RocksDbOptions options) {
} else {
table_options.block_cache = options.block_cache;
}
if (options.enable_bloom_filter) {
table_options.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
}
db_options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_options));

db_options.use_direct_reads = options.use_direct_reads;
Expand Down
1 change: 1 addition & 0 deletions tddb/td/db/RocksDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct RocksDbOptions {
std::shared_ptr<RocksDbSnapshotStatistics> snapshot_statistics = nullptr;
bool use_direct_reads = false;
bool no_block_cache = false;
bool enable_bloom_filter = false;
};

class RocksDb : public KeyValue {
Expand Down
7 changes: 7 additions & 0 deletions validator-engine/validator-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,7 @@ td::Status ValidatorEngine::load_global_config() {
}
validator_options_.write().set_celldb_compress_depth(celldb_compress_depth_);
validator_options_.write().set_celldb_in_memory(celldb_in_memory_);
validator_options_.write().set_celldb_disable_bloom_filter(celldb_disable_bloom_filter_);
validator_options_.write().set_max_open_archive_files(max_open_archive_files_);
validator_options_.write().set_archive_preload_period(archive_preload_period_);
validator_options_.write().set_disable_rocksdb_stats(disable_rocksdb_stats_);
Expand Down Expand Up @@ -4520,6 +4521,12 @@ int main(int argc, char *argv[]) {
[&]() {
acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_celldb_in_memory, true); });
});
p.add_option(
'\0', "celldb-disable-bloom-filter",
"disable using bloom filter in CellDb. Enabled bloom filter reduces read latency, but increases memory usage",
[&]() {
acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_celldb_disable_bloom_filter, true); });
});
p.add_checked_option(
'\0', "catchain-max-block-delay", "delay before creating a new catchain block, in seconds (default: 0.4)",
[&](td::Slice s) -> td::Status {
Expand Down
4 changes: 4 additions & 0 deletions validator-engine/validator-engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class ValidatorEngine : public td::actor::Actor {
bool celldb_direct_io_ = false;
bool celldb_preload_all_ = false;
bool celldb_in_memory_ = false;
bool celldb_disable_bloom_filter_ = false;
td::optional<double> catchain_max_block_delay_, catchain_max_block_delay_slow_;
bool read_config_ = false;
bool started_keyring_ = false;
Expand Down Expand Up @@ -307,6 +308,9 @@ class ValidatorEngine : public td::actor::Actor {
void set_celldb_in_memory(bool value) {
celldb_in_memory_ = value;
}
void set_celldb_disable_bloom_filter(bool value) {
celldb_disable_bloom_filter_ = value;
}
void set_catchain_max_block_delay(double value) {
catchain_max_block_delay_ = value;
}
Expand Down
1 change: 1 addition & 0 deletions validator/db/celldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void CellDbIn::start_up() {
LOG(WARNING) << "Set CellDb block cache size to " << td::format::as_size(opts_->get_celldb_cache_size().value());
}
db_options.use_direct_reads = opts_->get_celldb_direct_io();
db_options.enable_bloom_filter = !opts_->get_celldb_disable_bloom_filter();

if (opts_->get_celldb_in_memory()) {
td::RocksDbOptions read_db_options;
Expand Down
7 changes: 7 additions & 0 deletions validator/validator-options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
bool get_celldb_in_memory() const override {
return celldb_in_memory_;
}
bool get_celldb_disable_bloom_filter() const override {
return celldb_disable_bloom_filter_;
}
td::optional<double> get_catchain_max_block_delay() const override {
return catchain_max_block_delay_;
}
Expand Down Expand Up @@ -234,6 +237,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
void set_celldb_in_memory(bool value) override {
celldb_in_memory_ = value;
}
void set_celldb_disable_bloom_filter(bool value) override {
celldb_disable_bloom_filter_ = value;
}
void set_catchain_max_block_delay(double value) override {
catchain_max_block_delay_ = value;
}
Expand Down Expand Up @@ -298,6 +304,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
bool celldb_direct_io_ = false;
bool celldb_preload_all_ = false;
bool celldb_in_memory_ = false;
bool celldb_disable_bloom_filter_ = false;
td::optional<double> catchain_max_block_delay_, catchain_max_block_delay_slow_;
bool state_serializer_enabled_ = true;
td::Ref<CollatorOptions> collator_options_{true};
Expand Down
2 changes: 2 additions & 0 deletions validator/validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ struct ValidatorManagerOptions : public td::CntObject {
virtual td::optional<td::uint64> get_celldb_cache_size() const = 0;
virtual bool get_celldb_direct_io() const = 0;
virtual bool get_celldb_preload_all() const = 0;
virtual bool get_celldb_disable_bloom_filter() const = 0;
virtual td::optional<double> get_catchain_max_block_delay() const = 0;
virtual td::optional<double> get_catchain_max_block_delay_slow() const = 0;
virtual bool get_state_serializer_enabled() const = 0;
Expand Down Expand Up @@ -142,6 +143,7 @@ struct ValidatorManagerOptions : public td::CntObject {
virtual void set_celldb_direct_io(bool value) = 0;
virtual void set_celldb_preload_all(bool value) = 0;
virtual void set_celldb_in_memory(bool value) = 0;
virtual void set_celldb_disable_bloom_filter(bool value) = 0;
virtual void set_catchain_max_block_delay(double value) = 0;
virtual void set_catchain_max_block_delay_slow(double value) = 0;
virtual void set_state_serializer_enabled(bool value) = 0;
Expand Down

0 comments on commit 34f80e8

Please sign in to comment.