Skip to content

Commit

Permalink
Add "lastgcdmasterchainstate" to validator stats (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpyCheese authored Sep 5, 2024
1 parent e35b34d commit cb69f30
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions validator/db/celldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,17 @@ void CellDbIn::store_cell(BlockIdExt block_id, td::Ref<vm::Cell> cell, td::Promi
if (!opts_->get_disable_rocksdb_stats()) {
cell_db_statistics_.store_cell_time_.insert(timer.elapsed() * 1e6);
}
LOG(DEBUG) << "Stored state " << block_id.to_str();
}

void CellDbIn::get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>> promise) {
promise.set_result(boc_->get_cell_db_reader());
}

void CellDbIn::get_last_deleted_mc_state(td::Promise<BlockSeqno> promise) {
promise.set_result(last_deleted_mc_state_);
}

void CellDbIn::flush_db_stats() {
if (opts_->get_disable_rocksdb_stats()) {
return;
Expand Down Expand Up @@ -320,6 +325,10 @@ void CellDbIn::gc_cont2(BlockHandle handle) {
if (!opts_->get_disable_rocksdb_stats()) {
cell_db_statistics_.gc_cell_time_.insert(timer.elapsed() * 1e6);
}
if (handle->id().is_masterchain()) {
last_deleted_mc_state_ = handle->id().seqno();
}
LOG(DEBUG) << "Deleted state " << handle->id().to_str();
}

void CellDbIn::skip_gc() {
Expand Down Expand Up @@ -453,6 +462,10 @@ void CellDb::get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>> p
td::actor::send_closure(cell_db_, &CellDbIn::get_cell_db_reader, std::move(promise));
}

void CellDb::get_last_deleted_mc_state(td::Promise<BlockSeqno> promise) {
td::actor::send_closure(cell_db_, &CellDbIn::get_last_deleted_mc_state, std::move(promise));
}

void CellDb::start_up() {
CellDbBase::start_up();
boc_ = vm::DynamicBagOfCellsDb::create();
Expand Down
3 changes: 3 additions & 0 deletions validator/db/celldb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class CellDbIn : 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 get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>> promise);
void get_last_deleted_mc_state(td::Promise<BlockSeqno> promise);

void migrate_cell(td::Bits256 hash);

Expand Down Expand Up @@ -143,6 +144,7 @@ class CellDbIn : public CellDbBase {
std::shared_ptr<td::RocksDbSnapshotStatistics> snapshot_statistics_;
CellDbStatistics cell_db_statistics_;
td::Timestamp statistics_flush_at_ = td::Timestamp::never();
BlockSeqno last_deleted_mc_state_ = 0;

public:
class MigrationProxy : public td::actor::Actor {
Expand All @@ -167,6 +169,7 @@ class CellDb : public CellDbBase {
boc_->set_loader(std::make_unique<vm::CellLoader>(std::move(snapshot), on_load_callback_)).ensure();
}
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) {
Expand Down
4 changes: 4 additions & 0 deletions validator/db/rootdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ void RootDb::get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>> p
td::actor::send_closure(cell_db_, &CellDb::get_cell_db_reader, std::move(promise));
}

void RootDb::get_last_deleted_mc_state(td::Promise<BlockSeqno> promise) {
td::actor::send_closure(cell_db_, &CellDb::get_last_deleted_mc_state, std::move(promise));
}

void RootDb::store_persistent_state_file(BlockIdExt block_id, BlockIdExt masterchain_block_id, td::BufferSlice state,
td::Promise<td::Unit> promise) {
td::actor::send_closure(archive_db_, &ArchiveManager::add_persistent_state, block_id, masterchain_block_id,
Expand Down
1 change: 1 addition & 0 deletions validator/db/rootdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class RootDb : public Db {
td::Promise<td::Ref<ShardState>> promise) override;
void get_block_state(ConstBlockHandle handle, td::Promise<td::Ref<ShardState>> promise) override;
void get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>> promise) override;
void get_last_deleted_mc_state(td::Promise<BlockSeqno> promise) override;

void store_block_handle(BlockHandle handle, td::Promise<td::Unit> promise) override;
void get_block_handle(BlockIdExt id, td::Promise<BlockHandle> promise) override;
Expand Down
1 change: 1 addition & 0 deletions validator/interfaces/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Db : public td::actor::Actor {
td::Promise<td::Ref<ShardState>> promise) = 0;
virtual void get_block_state(ConstBlockHandle handle, td::Promise<td::Ref<ShardState>> promise) = 0;
virtual void get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>> promise) = 0;
virtual void get_last_deleted_mc_state(td::Promise<BlockSeqno> promise) = 0;

virtual void store_persistent_state_file(BlockIdExt block_id, BlockIdExt masterchain_block_id, td::BufferSlice state,
td::Promise<td::Unit> promise) = 0;
Expand Down
17 changes: 17 additions & 0 deletions validator/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,23 @@ void ValidatorManagerImpl::prepare_stats(td::Promise<std::vector<std::pair<std::
vec.emplace_back("rotatemasterchainblock", last_rotate_block_id_.to_str());
//vec.emplace_back("shardclientmasterchainseqno", td::to_string(min_confirmed_masterchain_seqno_));
vec.emplace_back("stateserializermasterchainseqno", td::to_string(state_serializer_masterchain_seqno_));

td::actor::send_closure(db_, &Db::get_last_deleted_mc_state,
[promise = merger.make_promise(""),
gc_seqno = gc_masterchain_handle_->id().seqno()](td::Result<BlockSeqno> R) mutable {
TRY_RESULT_PROMISE(promise, seqno, std::move(R));
std::string s;
if (seqno == 0) {
s = "none";
} else if (seqno <= gc_seqno) {
s = PSTRING() << seqno << " (gc_seqno-" << (gc_seqno - seqno) << ")";
} else {
s = PSTRING() << seqno << " (gc_seqno+" << (seqno - gc_seqno) << ")";
}
std::vector<std::pair<std::string, std::string>> vec;
vec.emplace_back("lastgcdmasterchainstate", std::move(s));
promise.set_value(std::move(vec));
});
}

if (!shard_client_.empty()) {
Expand Down

0 comments on commit cb69f30

Please sign in to comment.