From c84ca5e5737efe933492f37fc9e0f748f1a0abb3 Mon Sep 17 00:00:00 2001 From: ms Date: Wed, 20 Mar 2024 13:25:27 +0100 Subject: [PATCH] Mode 644 for db_stats.txt --- validator/db/archive-manager.cpp | 13 ++++++++++++- validator/db/celldb.cpp | 21 ++++++++++++++++++--- validator/db/celldb.hpp | 2 ++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/validator/db/archive-manager.cpp b/validator/db/archive-manager.cpp index adb6f4821..d4d9e76c4 100644 --- a/validator/db/archive-manager.cpp +++ b/validator/db/archive-manager.cpp @@ -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_); } diff --git a/validator/db/celldb.cpp b/validator/db/celldb.cpp index fae853baf..d9803cbe2 100644 --- a/validator/db/celldb.cpp +++ b/validator/db/celldb.cpp @@ -161,12 +161,27 @@ void CellDbIn::get_cell_db_reader(td::Promise> 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()) { diff --git a/validator/db/celldb.hpp b/validator/db/celldb.hpp index fb437a26a..573d4b995 100644 --- a/validator/db/celldb.hpp +++ b/validator/db/celldb.hpp @@ -60,6 +60,8 @@ class CellDbIn : public CellDbBase { void migrate_cell(td::Bits256 hash); + void flush_db_stats(); + CellDbIn(td::actor::ActorId root_db, td::actor::ActorId parent, std::string path, td::Ref opts);