From 297e6ee8f0ded5c10de3602db5ccac8b0f6cdf96 Mon Sep 17 00:00:00 2001 From: SpyCheese Date: Mon, 13 May 2024 13:11:58 +0300 Subject: [PATCH] Fix creating rocksdb cache --- tddb/td/db/RocksDb.cpp | 8 ++++++-- tddb/td/db/RocksDb.h | 3 ++- validator-engine/validator-engine.cpp | 3 ++- validator/db/celldb.cpp | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tddb/td/db/RocksDb.cpp b/tddb/td/db/RocksDb.cpp index d15b8e19f..91c5ca662 100644 --- a/tddb/td/db/RocksDb.cpp +++ b/tddb/td/db/RocksDb.cpp @@ -64,10 +64,14 @@ Result RocksDb::open(std::string path, RocksDbOptions options) { { rocksdb::Options db_options; - static auto cache = rocksdb::NewLRUCache(options.block_cache_size); + static auto cache = rocksdb::NewLRUCache(1 << 30); rocksdb::BlockBasedTableOptions table_options; - table_options.block_cache = cache; + if (options.block_cache_size) { + table_options.block_cache = rocksdb::NewLRUCache(options.block_cache_size.value()); + } else { + table_options.block_cache = cache; + } db_options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_options)); db_options.manual_wal_flush = true; diff --git a/tddb/td/db/RocksDb.h b/tddb/td/db/RocksDb.h index 44ef9de69..babfadb73 100644 --- a/tddb/td/db/RocksDb.h +++ b/tddb/td/db/RocksDb.h @@ -24,6 +24,7 @@ #include "td/db/KeyValue.h" #include "td/utils/Status.h" +#include "td/utils/optional.h" namespace rocksdb { class OptimisticTransactionDB; @@ -37,7 +38,7 @@ namespace td { struct RocksDbOptions { std::shared_ptr statistics = nullptr; - uint64 block_cache_size = 1 << 30; + optional block_cache_size; // Default - one 1G cache for all RocksDb }; class RocksDb : public KeyValue { diff --git a/validator-engine/validator-engine.cpp b/validator-engine/validator-engine.cpp index 154085108..f52fe8cf7 100644 --- a/validator-engine/validator-engine.cpp +++ b/validator-engine/validator-engine.cpp @@ -3971,7 +3971,8 @@ int main(int argc, char *argv[]) { acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_nonfinal_ls_queries_enabled); }); }); p.add_checked_option( - '\0', "celldb-cache-size", "block cache size for RocksDb in CellDb, in bytes (default: 1G)", + '\0', "celldb-cache-size", + "block cache size for RocksDb in CellDb, in bytes (default: 1G cache shared by archive DB)", [&](td::Slice s) -> td::Status { TRY_RESULT(v, td::to_integer_safe(s)); if (v == 0) { diff --git a/validator/db/celldb.cpp b/validator/db/celldb.cpp index 007bedc89..bc315b599 100644 --- a/validator/db/celldb.cpp +++ b/validator/db/celldb.cpp @@ -92,7 +92,7 @@ void CellDbIn::start_up() { db_options.statistics = statistics_; if (opts_->get_celldb_cache_size()) { db_options.block_cache_size = opts_->get_celldb_cache_size().value(); - LOG(WARNING) << "Set CellDb block cache size to " << td::format::as_size(db_options.block_cache_size); + LOG(WARNING) << "Set CellDb block cache size to " << td::format::as_size(db_options.block_cache_size.value()); } cell_db_ = std::make_shared(td::RocksDb::open(path_, std::move(db_options)).move_as_ok());