Skip to content

Commit

Permalink
root db
Browse files Browse the repository at this point in the history
  • Loading branch information
zjg555543 committed Oct 22, 2024
1 parent 132e27e commit 9b1165f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 24 deletions.
42 changes: 22 additions & 20 deletions validator/db/celldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,16 +468,18 @@ void CellDb::load_cell(RootHash hash, td::Promise<td::Ref<vm::DataCell>> promise
static int64_t ranCount = 0;
ranCount++;
if (ranCount % 1000 == 0) {
LOG(ERROR) << "yus " << this->get_name() << " " << this->get_actor_info_ptr()->mailbox().reader().calc_size() << ", ranNum: " << ranNum;
// LOG(ERROR) << "yus " << this->get_name() << " " << this->get_actor_info_ptr()->mailbox().reader().calc_size() << ", ranNum: " << ranNum;
LOG(ERROR) << "yus " << this->get_name() << " " << this->get_actor_info_ptr()->mailbox().reader().calc_size();
ranCount = 0;
}
if (!started_) {
LOG(INFO) << " load_cell: counter" << counter_ << ", 2";
td::actor::send_closure(cell_db_read_[ranNum], &CellDbIn::load_cell, hash, std::move(promise));
// td::actor::send_closure(cell_db_read_[ranNum], &CellDbIn::load_cell, hash, std::move(promise));
td::actor::send_closure(cell_db_, &CellDbIn::load_cell, hash, std::move(promise));
} else {
LOG(INFO) << " load_cell: counter" << counter_ << ", 3";
auto P = td::PromiseCreator::lambda(
[cell_db_in = cell_db_read_[ranNum].get(), hash, promise = std::move(promise), counter_](td::Result<td::Ref<vm::DataCell>> R) mutable {
[cell_db_in = cell_db_.get(), hash, promise = std::move(promise), counter_](td::Result<td::Ref<vm::DataCell>> R) mutable {
LOG(INFO) << " load_cell: counter" << counter_ << ", 5";
if (R.is_error()) {
LOG(DEBUG) << "yus err then send to cell db in";
Expand Down Expand Up @@ -512,23 +514,23 @@ void CellDb::start_up() {
boc_ = vm::DynamicBagOfCellsDb::create();
boc_->set_celldb_compress_depth(opts_->get_celldb_compress_depth());

td::RocksDbOptions db_options;
auto statistics_ = td::RocksDb::create_statistics();
if (!opts_->get_disable_rocksdb_stats()) {
db_options.snapshot_statistics = std::make_shared<td::RocksDbSnapshotStatistics>();
}
db_options.statistics = statistics_;
if (opts_->get_celldb_cache_size()) {
db_options.block_cache = td::RocksDb::create_cache(opts_->get_celldb_cache_size().value());
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();
auto rock_db = std::make_shared<td::RocksDb>(td::RocksDb::open(path_, std::move(db_options)).move_as_ok());

cell_db_ = td::actor::create_actor<CellDbIn>("celldbin", root_db_, actor_id(this), path_, opts_, rock_db);
for (int i = 0; i < 1000; i++) {
cell_db_read_[i] = td::actor::create_actor<CellDbIn>("celldbin", root_db_, actor_id(this), path_, opts_, rock_db);
}
// td::RocksDbOptions db_options;
// auto statistics_ = td::RocksDb::create_statistics();
// if (!opts_->get_disable_rocksdb_stats()) {
// db_options.snapshot_statistics = std::make_shared<td::RocksDbSnapshotStatistics>();
// }
// db_options.statistics = statistics_;
// if (opts_->get_celldb_cache_size()) {
// db_options.block_cache = td::RocksDb::create_cache(opts_->get_celldb_cache_size().value());
// 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();
// auto rock_db = std::make_shared<td::RocksDb>(td::RocksDb::open(path_, std::move(db_options)).move_as_ok());

cell_db_ = td::actor::create_actor<CellDbIn>("celldbin", root_db_, actor_id(this), path_, opts_, rocks_db_);
// for (int i = 0; i < 10; i++) {
// cell_db_read_[i] = td::actor::create_actor<CellDbIn>("celldbin", root_db_, actor_id(this), path_, opts_, rock_db);
// }

on_load_callback_ = [actor = std::make_shared<td::actor::ActorOwn<CellDbIn::MigrationProxy>>(
td::actor::create_actor<CellDbIn::MigrationProxy>("celldbmigration", cell_db_.get())),
Expand Down
5 changes: 3 additions & 2 deletions validator/db/celldb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ class CellDb : public CellDbBase {
void get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>> promise);
void get_last_deleted_mc_state(td::Promise<BlockSeqno> promise);

CellDb(td::actor::ActorId<RootDb> root_db, std::string path, td::Ref<ValidatorManagerOptions> opts)
: root_db_(root_db), path_(path), opts_(opts) {
CellDb(td::actor::ActorId<RootDb> root_db, std::string path, td::Ref<ValidatorManagerOptions> opts, std::shared_ptr<vm::KeyValue> rocks_db)
: root_db_(root_db), path_(path), opts_(opts), rocks_db_(rocks_db) {
}

void start_up() override;
Expand All @@ -184,6 +184,7 @@ class CellDb : public CellDbBase {

td::actor::ActorOwn<CellDbIn> cell_db_;
td::actor::ActorOwn<CellDbIn> cell_db_read_[1000];
std::shared_ptr<vm::KeyValue> rocks_db_;

std::unique_ptr<vm::DynamicBagOfCellsDb> boc_;
bool started_ = false;
Expand Down
42 changes: 40 additions & 2 deletions validator/db/rootdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "common/checksum.h"
#include "validator/stats-merger.h"
#include "td/actor/MultiPromise.h"
#include <iostream>
#include <random>

namespace ton {

Expand Down Expand Up @@ -248,6 +250,14 @@ void RootDb::store_block_state(BlockHandle handle, td::Ref<ShardState> state,
}
}

int getRandom(){
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distr(0, 99);
int random_number = distr(gen);
return random_number;
}

void RootDb::get_block_state(ConstBlockHandle handle, td::Promise<td::Ref<ShardState>> promise, std::uint64_t counter_) {
LOG(INFO) << "get_block_state, counter" << counter_ << ", 1";
if (handle->inited_state_boc()) {
Expand All @@ -273,7 +283,16 @@ void RootDb::get_block_state(ConstBlockHandle handle, td::Promise<td::Ref<ShardS
}
});
LOG(INFO) << "get_block_state, counter" << counter_ << ", 4";
td::actor::send_closure(cell_db_, &CellDb::load_cell, handle->state(), std::move(P), counter_);

int ranNum = getRandom();
static int64_t ranCount = 0;
ranCount++;
if (ranCount % 1000 == 0) {
LOG(ERROR) << "yus " << this->get_name() << " " << this->get_actor_info_ptr()->mailbox().reader().calc_size() << ", ranNum: " << ranNum;
ranCount = 0;
}

td::actor::send_closure(cell_db_read_[ranNum], &CellDb::load_cell, handle->state(), std::move(P), counter_);
LOG(INFO) << "get_block_state, counter" << counter_ << ", 4-1";
} else {
LOG(INFO) << "get_block_state, counter" << counter_ << ", 7-0";
Expand Down Expand Up @@ -424,7 +443,26 @@ void RootDb::get_hardforks(td::Promise<std::vector<BlockIdExt>> promise) {
}

void RootDb::start_up() {
cell_db_ = td::actor::create_actor<CellDb>("celldb", actor_id(this), root_path_ + "/celldb/", opts_);

td::RocksDbOptions db_options;
auto statistics_ = td::RocksDb::create_statistics();
if (!opts_->get_disable_rocksdb_stats()) {
db_options.snapshot_statistics = std::make_shared<td::RocksDbSnapshotStatistics>();
}
db_options.statistics = statistics_;
if (opts_->get_celldb_cache_size()) {
db_options.block_cache = td::RocksDb::create_cache(opts_->get_celldb_cache_size().value());
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();
auto path = root_path_ + "/celldb/";
auto rock_db = std::make_shared<td::RocksDb>(td::RocksDb::open(path, std::move(db_options)).move_as_ok());

cell_db_ = td::actor::create_actor<CellDb>("celldb", actor_id(this), path, opts_, rock_db);
for (int i = 0; i < 100; i++){
cell_db_read_[i] = td::actor::create_actor<CellDb>("celldb", actor_id(this), path, opts_, rock_db);
}

state_db_ = td::actor::create_actor<StateDb>("statedb", actor_id(this), root_path_ + "/state/");
static_files_db_ = td::actor::create_actor<StaticFilesDb>("staticfilesdb", actor_id(this), root_path_ + "/static/");
archive_db_ = td::actor::create_actor<ArchiveManager>("archive", actor_id(this), root_path_, opts_);
Expand Down
1 change: 1 addition & 0 deletions validator/db/rootdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class RootDb : public Db {
td::Ref<ValidatorManagerOptions> opts_;

td::actor::ActorOwn<CellDb> cell_db_;
td::actor::ActorOwn<CellDb> cell_db_read_[100];
td::actor::ActorOwn<StateDb> state_db_;
td::actor::ActorOwn<StaticFilesDb> static_files_db_;
td::actor::ActorOwn<ArchiveManager> archive_db_;
Expand Down

0 comments on commit 9b1165f

Please sign in to comment.