Skip to content

Commit

Permalink
Mode 644 for db_stats.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
dungeon-master-666 committed Mar 20, 2024
1 parent 7a6bfa7 commit c84ca5e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
13 changes: 12 additions & 1 deletion validator/db/archive-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,18 @@ void ArchiveManager::start_up() {
void ArchiveManager::alarm() {
alarm_timestamp() = td::Timestamp::in(60.0);
auto stats = td::RocksDb::statistics_to_string(statistics_);
td::atomic_write_file(db_root_ + "/db_stats.txt", stats);
auto to_file_r = td::FileFd::open(db_root_ + "/db_stats.txt", td::FileFd::Truncate | td::FileFd::Create | td::FileFd::Write, 0644);
if (to_file_r.is_error()) {
LOG(ERROR) << "Failed to open db_stats.txt: " << to_file_r.move_as_error();
return;
}
auto to_file = to_file_r.move_as_ok();
auto res = to_file.write(stats);
to_file.close();
if (res.is_error()) {
LOG(ERROR) << "Failed to write to db_stats.txt: " << res.move_as_error();
return;
}
td::RocksDb::reset_statistics(statistics_);
}

Expand Down
21 changes: 18 additions & 3 deletions validator/db/celldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,27 @@ void CellDbIn::get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>>
promise.set_result(boc_->get_cell_db_reader());
}

void CellDbIn::flush_db_stats() {
auto stats = td::RocksDb::statistics_to_string(statistics_);
auto to_file_r = td::FileFd::open(path_ + "/db_stats.txt", td::FileFd::Truncate | td::FileFd::Create | td::FileFd::Write, 0644);
if (to_file_r.is_error()) {
LOG(ERROR) << "Failed to open db_stats.txt: " << to_file_r.move_as_error();
return;
}
auto to_file = to_file_r.move_as_ok();
auto res = to_file.write(stats);
to_file.close();
if (res.is_error()) {
LOG(ERROR) << "Failed to write to db_stats.txt: " << res.move_as_error();
return;
}
td::RocksDb::reset_statistics(statistics_);
}

void CellDbIn::alarm() {
if (statistics_flush_at_ && statistics_flush_at_.is_in_past()) {
statistics_flush_at_ = td::Timestamp::in(60.0);
auto stats = td::RocksDb::statistics_to_string(statistics_);
td::atomic_write_file(path_ + "/db_stats.txt", stats);
td::RocksDb::reset_statistics(statistics_);
flush_db_stats();
}

if (migrate_after_ && migrate_after_.is_in_past()) {
Expand Down
2 changes: 2 additions & 0 deletions validator/db/celldb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class CellDbIn : public CellDbBase {

void migrate_cell(td::Bits256 hash);

void flush_db_stats();

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

Expand Down

0 comments on commit c84ca5e

Please sign in to comment.