Skip to content

Commit

Permalink
Revert "add log"
Browse files Browse the repository at this point in the history
This reverts commit 3759807.
  • Loading branch information
oker authored and oker committed Oct 30, 2024
1 parent 7c33942 commit 1c05fae
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 81 deletions.
52 changes: 26 additions & 26 deletions crypto/vm/db/DynamicBagOfCellsDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,29 @@ class DynamicBagOfCellsDbImpl : public DynamicBagOfCellsDb, private ExtCellCreat
}
SimpleExtCellCreator ext_cell_creator(cell_db_reader_);
auto promise_ptr = std::make_shared<td::Promise<Ref<DataCell>>>(std::move(promise));
executor->execute_async([executor, loader = *loader_, hash = CellHash::from_slice(hash), db = this,
ext_cell_creator = std::move(ext_cell_creator),
promise = std::move(promise_ptr)]() mutable {
TRY_RESULT_PROMISE((*promise), res, loader.load(hash.as_slice(), true, ext_cell_creator));
if (res.status != CellLoader::LoadResult::Ok) {
promise->set_error(td::Status::Error("cell not found 1"));
return;
}
Ref<Cell> cell = res.cell();
executor->execute_sync([hash, db, res = std::move(res),
ext_cell_creator = std::move(ext_cell_creator)]() mutable {
db->hash_table_.apply(hash.as_slice(), [&](CellInfo &info) {
db->update_cell_info_loaded(info, hash.as_slice(), std::move(res));
executor->execute_async(
[executor, loader = *loader_, hash = CellHash::from_slice(hash), db = this,
ext_cell_creator = std::move(ext_cell_creator), promise = std::move(promise_ptr)]() mutable {
TRY_RESULT_PROMISE((*promise), res, loader.load(hash.as_slice(), true, ext_cell_creator));
if (res.status != CellLoader::LoadResult::Ok) {
promise->set_error(td::Status::Error("cell not found"));
return;
}
Ref<Cell> cell = res.cell();
executor->execute_sync([hash, db, res = std::move(res),
ext_cell_creator = std::move(ext_cell_creator)]() mutable {
db->hash_table_.apply(hash.as_slice(), [&](CellInfo &info) {
db->update_cell_info_loaded(info, hash.as_slice(), std::move(res));
});
for (auto &ext_cell : ext_cell_creator.get_created_cells()) {
auto ext_cell_hash = ext_cell->get_hash();
db->hash_table_.apply(ext_cell_hash.as_slice(), [&](CellInfo &info) {
db->update_cell_info_created_ext(info, std::move(ext_cell));
});
}
});
promise->set_result(std::move(cell));
});
for (auto &ext_cell : ext_cell_creator.get_created_cells()) {
auto ext_cell_hash = ext_cell->get_hash();
db->hash_table_.apply(ext_cell_hash.as_slice(),
[&](CellInfo &info) { db->update_cell_info_created_ext(info, std::move(ext_cell)); });
}
});
promise->set_result(std::move(cell));
});
}
CellInfo &get_cell_info_force(td::Slice hash) {
return hash_table_.apply(hash, [&](CellInfo &info) { update_cell_info_force(info, hash); });
Expand Down Expand Up @@ -213,7 +214,7 @@ class DynamicBagOfCellsDbImpl : public DynamicBagOfCellsDb, private ExtCellCreat
celldb_compress_depth_ = value;
}

vm::ExtCellCreator &as_ext_cell_creator() override {
vm::ExtCellCreator& as_ext_cell_creator() override {
return *this;
}

Expand All @@ -233,9 +234,8 @@ class DynamicBagOfCellsDbImpl : public DynamicBagOfCellsDb, private ExtCellCreat

class SimpleExtCellCreator : public ExtCellCreator {
public:
explicit SimpleExtCellCreator(std::shared_ptr<CellDbReader> cell_db_reader)
: cell_db_reader_(std::move(cell_db_reader)) {
}
explicit SimpleExtCellCreator(std::shared_ptr<CellDbReader> cell_db_reader) :
cell_db_reader_(std::move(cell_db_reader)) {}

td::Result<Ref<Cell>> ext_cell(Cell::LevelMask level_mask, td::Slice hash, td::Slice depth) override {
TRY_RESULT(ext_cell, DynamicBocExtCell::create(PrunnedCellInfo{level_mask, hash, depth},
Expand All @@ -244,7 +244,7 @@ class DynamicBagOfCellsDbImpl : public DynamicBagOfCellsDb, private ExtCellCreat
return std::move(ext_cell);
}

std::vector<Ref<Cell>> &get_created_cells() {
std::vector<Ref<Cell>>& get_created_cells() {
return created_cells_;
}

Expand Down
88 changes: 37 additions & 51 deletions validator/db/celldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ class CellDbAsyncExecutor : public vm::DynamicBagOfCellsDb::AsyncExecutor {
void execute_async(std::function<void()> f) override {
class Runner : public td::actor::Actor {
public:
explicit Runner(std::function<void()> f) : f_(std::move(f)) {
}
explicit Runner(std::function<void()> f) : f_(std::move(f)) {}
void start_up() override {
f_();
stop();
}

private:
std::function<void()> f_;
};
Expand All @@ -54,7 +52,6 @@ class CellDbAsyncExecutor : public vm::DynamicBagOfCellsDb::AsyncExecutor {
void execute_sync(std::function<void()> f) override {
td::actor::send_closure(cell_db_, &CellDbBase::execute_sync, std::move(f));
}

private:
td::actor::ActorId<CellDbBase> cell_db_;
};
Expand All @@ -69,11 +66,11 @@ 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, 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) << "Using provided cell_db";
cell_db_ = cell_db;
}
: root_db_(root_db), parent_(parent), path_(std::move(path)), opts_(opts){
if (cell_db != NULL) {
LOG(INFO) << "Using provided cell_db";
cell_db_ = cell_db;
}
}

void CellDbIn::start_up() {
Expand Down Expand Up @@ -104,14 +101,13 @@ 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();
if (cell_db_ == NULL) {
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());
if (cell_db_ == NULL){
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());
}

boc_ = vm::DynamicBagOfCellsDb::create();
boc_->set_celldb_compress_depth(opts_->get_celldb_compress_depth());
LOG(INFO) << "CellDbIn::start_up. update snapshot";
boc_->set_loader(std::make_unique<vm::CellLoader>(cell_db_->snapshot(), on_load_callback_)).ensure();
td::actor::send_closure(parent_, &CellDb::update_snapshot, cell_db_->snapshot(), cell_db_->snapshot());

Expand All @@ -127,30 +123,27 @@ void CellDbIn::start_up() {

if (opts_->get_celldb_preload_all()) {
// Iterate whole DB in a separate thread
delay_action(
[snapshot = cell_db_->snapshot()]() {
LOG(WARNING) << "CellDb: pre-loading all keys";
td::uint64 total = 0;
td::Timer timer;
auto S = snapshot->for_each([&](td::Slice, td::Slice) {
++total;
if (total % 1000000 == 0) {
LOG(INFO) << "CellDb: iterated " << total << " keys";
}
return td::Status::OK();
});
if (S.is_error()) {
LOG(ERROR) << "CellDb: pre-load failed: " << S.move_as_error();
} else {
LOG(WARNING) << "CellDb: iterated " << total << " keys in " << timer.elapsed() << "s";
}
},
td::Timestamp::now());
delay_action([snapshot = cell_db_->snapshot()]() {
LOG(WARNING) << "CellDb: pre-loading all keys";
td::uint64 total = 0;
td::Timer timer;
auto S = snapshot->for_each([&](td::Slice, td::Slice) {
++total;
if (total % 1000000 == 0) {
LOG(INFO) << "CellDb: iterated " << total << " keys";
}
return td::Status::OK();
});
if (S.is_error()) {
LOG(ERROR) << "CellDb: pre-load failed: " << S.move_as_error();
} else {
LOG(WARNING) << "CellDb: iterated " << total << " keys in " << timer.elapsed() << "s";
}
}, td::Timestamp::now());
}
}

void CellDbIn::load_cell(RootHash hash, td::Promise<td::Ref<vm::DataCell>> promise) {
LOG(INFO) << "CellDbIn::load_cell";
boc_->load_cell_async(hash.as_slice(), async_executor, std::move(promise));
}

Expand Down Expand Up @@ -414,7 +407,7 @@ void CellDbIn::migrate_cells() {
boc_->set_loader(std::make_unique<vm::CellLoader>(*loader)).ensure();
cell_db_->begin_write_batch().ensure();
td::uint32 checked = 0, migrated = 0;
for (auto it = cells_to_migrate_.begin(); it != cells_to_migrate_.end() && checked < 128;) {
for (auto it = cells_to_migrate_.begin(); it != cells_to_migrate_.end() && checked < 128; ) {
++checked;
td::Bits256 hash = *it;
it = cells_to_migrate_.erase(it);
Expand Down Expand Up @@ -456,25 +449,21 @@ 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) << "CellDb mailbox: " << 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;
}
if (!started_) {
LOG(INFO) << "CellDb::load_cell. not started_";
td::actor::send_closure(cell_db_read_, &CellDbIn::load_cell, hash, std::move(promise));
} else {
LOG(INFO) << "CellDb::load_cell. started_ is true";
auto P = td::PromiseCreator::lambda([cell_db_in = cell_db_read_.get(), hash,
promise = std::move(promise)](td::Result<td::Ref<vm::DataCell>> R) mutable {
if (R.is_error()) {
LOG(INFO) << "CellDb::load_cell. R is error. send closure to CellDbIn::load_cell";
td::actor::send_closure(cell_db_in, &CellDbIn::load_cell, hash, std::move(promise));
} else {
promise.set_result(R.move_as_ok());
}
});
auto P = td::PromiseCreator::lambda(
[cell_db_in = cell_db_read_.get(), hash, promise = std::move(promise)](td::Result<td::Ref<vm::DataCell>> R) mutable {
if (R.is_error()) {
td::actor::send_closure(cell_db_in, &CellDbIn::load_cell, hash, std::move(promise));
} else {
promise.set_result(R.move_as_ok());
}
});
boc_->load_cell_async(hash.as_slice(), async_executor, std::move(P));
}
}
Expand All @@ -495,11 +484,8 @@ void CellDb::start_up() {
CellDbBase::start_up();
boc_ = vm::DynamicBagOfCellsDb::create();
boc_->set_celldb_compress_depth(opts_->get_celldb_compress_depth());
LOG(INFO) << "CellDb::start_up. create write celldbin";
cell_db_write_ =
td::actor::create_actor<CellDbIn>("celldbinwrite", root_db_, actor_id(this), path_, opts_, rocks_db_);
cell_db_write_ = td::actor::create_actor<CellDbIn>("celldbinwrite", root_db_, actor_id(this), path_, opts_, rocks_db_);

LOG(INFO) << "CellDb::start_up. create read celldbin";
cell_db_read_ = td::actor::create_actor<CellDbIn>("celldbinread", root_db_, actor_id(this), path_, opts_, rocks_db_);
on_load_callback_ = [actor = std::make_shared<td::actor::ActorOwn<CellDbIn::MigrationProxy>>(
td::actor::create_actor<CellDbIn::MigrationProxy>("celldbmigration", cell_db_write_.get())),
Expand Down
5 changes: 1 addition & 4 deletions validator/db/celldb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class CellDbIn : public CellDbBase {
void get_last_deleted_mc_state(td::Promise<BlockSeqno> promise);

void update_snapshot(std::unique_ptr<td::KeyValueReader> snapshot) {
LOG(INFO) << "CellDbIn::update_snapshot";
boc_->set_loader(std::make_unique<vm::CellLoader>(std::move(snapshot), on_load_callback_)).ensure();
}

Expand Down Expand Up @@ -169,16 +168,14 @@ class CellDb : public CellDbBase {
void load_cell(RootHash hash, td::Promise<td::Ref<vm::DataCell>> promise);
void store_cell(BlockIdExt block_id, td::Ref<vm::Cell> cell, td::Promise<td::Ref<vm::DataCell>> promise);
void update_snapshot(std::unique_ptr<td::KeyValueReader> snapshot, std::unique_ptr<td::KeyValueReader> snapshot2) {
LOG(INFO) << "CellDb::update_snapshot. update self and reader";
started_ = true;
boc_->set_loader(std::make_unique<vm::CellLoader>(std::move(snapshot), on_load_callback_)).ensure();
td::actor::send_closure(cell_db_read_, &CellDbIn::update_snapshot, std::move(snapshot2));
}
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,
std::shared_ptr<vm::KeyValue> rocks_db)
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) {
}

Expand Down

0 comments on commit 1c05fae

Please sign in to comment.