Skip to content

Commit

Permalink
Fix creating rocksdb cache
Browse files Browse the repository at this point in the history
  • Loading branch information
SpyCheese committed May 13, 2024
1 parent 1433f23 commit 297e6ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions tddb/td/db/RocksDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ Result<RocksDb> 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;
Expand Down
3 changes: 2 additions & 1 deletion tddb/td/db/RocksDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "td/db/KeyValue.h"
#include "td/utils/Status.h"
#include "td/utils/optional.h"

namespace rocksdb {
class OptimisticTransactionDB;
Expand All @@ -37,7 +38,7 @@ namespace td {

struct RocksDbOptions {
std::shared_ptr<rocksdb::Statistics> statistics = nullptr;
uint64 block_cache_size = 1 << 30;
optional<uint64> block_cache_size; // Default - one 1G cache for all RocksDb
};

class RocksDb : public KeyValue {
Expand Down
3 changes: 2 additions & 1 deletion validator-engine/validator-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<td::uint64>(s));
if (v == 0) {
Expand Down
2 changes: 1 addition & 1 deletion validator/db/celldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(td::RocksDb::open(path_, std::move(db_options)).move_as_ok());

Expand Down

0 comments on commit 297e6ee

Please sign in to comment.