Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zjg555543 committed Oct 23, 2024
1 parent 0211d6f commit f313f65
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
22 changes: 7 additions & 15 deletions validator/db/celldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ void CellDbBase::execute_sync(std::function<void()> f) {
}

CellDbIn::CellDbIn(td::actor::ActorId<RootDb> root_db, td::actor::ActorId<CellDb> parent, std::string path,
td::Ref<ValidatorManagerOptions> opts)
: root_db_(root_db), parent_(parent), path_(std::move(path)), opts_(opts), std::shared_ptr<vm::KeyValue> cell_db{
td::Ref<ValidatorManagerOptions> opts, std::shared_ptr<vm::KeyValue> cell_db)
: root_db_(root_db), parent_(parent), path_(std::move(path)), opts_(opts){
if (cell_db != NULL) {
LOG(INFO) << "zjg: using provided KeyValue";
LOG(INFO) << "Using provided cell_db";
cell_db_ = cell_db;
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ void CellDbIn::start_up() {
}
db_options.use_direct_reads = opts_->get_celldb_direct_io();
if (cell_db_ == NULL){
LOG(INFO) << "zjg: using new KeyValue";
LOG(INFO) << "CellDbIn using a new rocksdb instance";
cell_db_ = std::make_shared<td::RocksDb>(td::RocksDb::open(path_, std::move(db_options)).move_as_ok());
}

Expand Down Expand Up @@ -444,20 +444,12 @@ void CellDbIn::migrate_cells() {
}
}

int GetRandom(){
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distr(0, THREAD_COUNTS -1 );
int random_number = distr(gen);
return random_number;
}

void CellDb::load_cell(RootHash hash, td::Promise<td::Ref<vm::DataCell>> promise) {
int ranNum = GetRandom();
int ranNum = GetDBRandomNum();
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) << "CellDb mailbox: " << 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;
}
Expand Down Expand Up @@ -492,7 +484,7 @@ void CellDb::start_up() {
CellDbBase::start_up();
boc_ = vm::DynamicBagOfCellsDb::create();
boc_->set_celldb_compress_depth(opts_->get_celldb_compress_depth());
cell_db_ = td::actor::create_actor<CellDbIn>("celldbin", root_db_, actor_id(this), path_, opts_);
cell_db_ = td::actor::create_actor<CellDbIn>("celldbin", root_db_, actor_id(this), path_, opts_, rocks_db_);

// cell_db_ = td::actor::create_actor<CellDbIn>("celldbin", root_db_, actor_id(this), path_, opts_, rocks_db_);
for (int i = 0; i < THREAD_COUNTS; i++) {
Expand Down
9 changes: 1 addition & 8 deletions validator/db/celldb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,12 @@
#include "validator.h"
#include "db-utils.h"
#include "td/db/RocksDb.h"
#include <iostream>
#include <random>

namespace rocksdb {
class Statistics;
}

namespace ton {

const int THREAD_COUNTS = 20;

int GetRandom();

namespace validator {

class RootDb;
Expand Down Expand Up @@ -74,7 +67,7 @@ class CellDbIn : public CellDbBase {
void flush_db_stats();

CellDbIn(td::actor::ActorId<RootDb> root_db, td::actor::ActorId<CellDb> parent, std::string path,
td::Ref<ValidatorManagerOptions> opts, std::shared_ptr<vm::KeyValue> cell_db, std::shared_ptr<vm::KeyValue>);
td::Ref<ValidatorManagerOptions> opts, std::shared_ptr<vm::KeyValue> cell_db);

void start_up() override;
void alarm() override;
Expand Down
10 changes: 10 additions & 0 deletions validator/db/db-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "td/utils/logging.h"

#include <cmath>
#include <iostream>
#include <random>

namespace ton::validator {

Expand Down Expand Up @@ -51,4 +53,12 @@ void PercentileStats::clear() {
values_.clear();
}

int GetDBRandomNum(){
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distr(0, THREAD_COUNTS -1);
int random_number = distr(gen);
return random_number;
}

} // namespace ton::validator
4 changes: 4 additions & 0 deletions validator/db/db-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ class PercentileStats {
std::multiset<double> values_;
};

const int THREAD_COUNTS = 10;
int GetDBRandomNum();


} // namespace ton::validator
4 changes: 2 additions & 2 deletions validator/db/rootdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ void RootDb::get_block_state(ConstBlockHandle handle, td::Promise<td::Ref<ShardS
}
});

int ranNum = GetRandom();
int ranNum = GetDBRandomNum();
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) << "RootDb mailbox: " << this->get_name() << " " << this->get_actor_info_ptr()->mailbox().reader().calc_size() << ", ranNum: " << ranNum;
ranCount = 0;
}

Expand Down

0 comments on commit f313f65

Please sign in to comment.