1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Request persistent state size, add missing queries to full-node-master

This commit is contained in:
SpyCheese 2025-03-06 17:15:27 +03:00
parent cf50b4b5da
commit 61ef357941
19 changed files with 163 additions and 60 deletions

View file

@ -314,7 +314,15 @@ void ArchiveManager::register_perm_state(FileReferenceShort id) {
BlockSeqno masterchain_seqno = 0;
id.ref().visit(td::overloaded(
[&](const fileref::PersistentStateShort &x) { masterchain_seqno = x.masterchain_seqno; }, [&](const auto &) {}));
perm_states_[{masterchain_seqno, id.hash()}] = id;
td::uint64 size;
auto r_stat = td::stat(db_root_ + "/archive/states/" + id.filename_short());
if (r_stat.is_error()) {
LOG(WARNING) << "Cannot stat persistent state file " << id.filename_short() << " : " << r_stat.move_as_error();
size = 0;
} else {
size = r_stat.ok().size_;
}
perm_states_[{masterchain_seqno, id.hash()}] = {.id = id, .size = size};
}
void ArchiveManager::add_zero_state(BlockIdExt block_id, td::BufferSlice data, td::Promise<td::Unit> promise) {
@ -417,7 +425,7 @@ void ArchiveManager::get_previous_persistent_state_files(
BlockSeqno mc_seqno = it->first.first;
std::vector<std::pair<std::string, ShardIdFull>> files;
while (it->first.first == mc_seqno) {
files.emplace_back(db_root_ + "/archive/states/" + it->second.filename_short(), it->second.shard());
files.emplace_back(db_root_ + "/archive/states/" + it->second.id.filename_short(), it->second.id.shard());
if (it == perm_states_.begin()) {
break;
}
@ -452,15 +460,16 @@ void ArchiveManager::get_persistent_state_slice(BlockIdExt block_id, BlockIdExt
td::actor::create_actor<db::ReadFile>("readfile", path, offset, max_size, 0, std::move(promise)).release();
}
void ArchiveManager::check_persistent_state(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise<bool> promise) {
void ArchiveManager::get_persistent_state_file_size(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise<td::uint64> promise) {
auto id = FileReference{fileref::PersistentState{block_id, masterchain_block_id}};
auto hash = id.hash();
if (perm_states_.find({masterchain_block_id.seqno(), hash}) == perm_states_.end()) {
promise.set_result(false);
auto it = perm_states_.find({masterchain_block_id.seqno(), hash});
if (it == perm_states_.end()) {
promise.set_error(td::Status::Error(ErrorCode::notready));
return;
}
promise.set_result(true);
promise.set_result(it->second.size);
}
void ArchiveManager::get_block_by_unix_time(AccountIdPrefixFull account_id, UnixTime ts,
@ -1023,15 +1032,15 @@ void ArchiveManager::persistent_state_gc(std::pair<BlockSeqno, FileHash> last) {
int res = 0;
BlockSeqno seqno = 0;
F.ref().visit(td::overloaded([&](const fileref::ZeroStateShort &) { res = 1; },
[&](const fileref::PersistentStateShort &x) {
res = 0;
seqno = x.masterchain_seqno;
},
[&](const auto &obj) { res = -1; }));
F.id.ref().visit(td::overloaded([&](const fileref::ZeroStateShort &) { res = 1; },
[&](const fileref::PersistentStateShort &x) {
res = 0;
seqno = x.masterchain_seqno;
},
[&](const auto &obj) { res = -1; }));
if (res == -1) {
td::unlink(db_root_ + "/archive/states/" + F.filename_short()).ignore();
td::unlink(db_root_ + "/archive/states/" + F.id.filename_short()).ignore();
perm_states_.erase(it);
}
if (res != 0) {
@ -1081,7 +1090,7 @@ void ArchiveManager::got_gc_masterchain_handle(ConstBlockHandle handle, std::pai
CHECK(it != perm_states_.end());
auto &F = it->second;
if (to_del) {
td::unlink(db_root_ + "/archive/states/" + F.filename_short()).ignore();
td::unlink(db_root_ + "/archive/states/" + F.id.filename_short()).ignore();
perm_states_.erase(it);
}
delay_action(
@ -1202,12 +1211,7 @@ void ArchiveManager::prepare_stats(td::Promise<std::vector<std::pair<std::string
std::map<BlockSeqno, td::uint64> states;
for (auto &[key, file] : perm_states_) {
BlockSeqno seqno = key.first;
auto r_stat = td::stat(db_root_ + "/archive/states/" + file.filename_short());
if (r_stat.is_error()) {
LOG(WARNING) << "Cannot stat persistent state file " << file.filename_short() << " : " << r_stat.move_as_error();
} else {
states[seqno] += r_stat.move_as_ok().size_;
}
states[seqno] += file.size;
}
td::StringBuilder sb;
for (auto &[seqno, size] : states) {
@ -1308,7 +1312,7 @@ void ArchiveManager::truncate(BlockSeqno masterchain_seqno, ConstBlockHandle han
auto it = perm_states_.begin();
while (it != perm_states_.end()) {
int res = 0;
it->second.ref().visit(td::overloaded(
it->second.id.ref().visit(td::overloaded(
[&](const fileref::ZeroStateShort &x) { res = -1; },
[&](const fileref::PersistentStateShort &x) { res = x.masterchain_seqno <= masterchain_seqno ? -1 : 1; },
[&](const auto &obj) { res = 1; }));
@ -1317,7 +1321,7 @@ void ArchiveManager::truncate(BlockSeqno masterchain_seqno, ConstBlockHandle han
} else {
auto it2 = it;
it++;
td::unlink(db_root_ + "/archive/states/" + it2->second.filename_short()).ignore();
td::unlink(db_root_ + "/archive/states/" + it2->second.id.filename_short()).ignore();
perm_states_.erase(it2);
}
}

View file

@ -52,7 +52,8 @@ class ArchiveManager : public td::actor::Actor {
void get_persistent_state(BlockIdExt block_id, BlockIdExt masterchain_block_id, td::Promise<td::BufferSlice> promise);
void get_persistent_state_slice(BlockIdExt block_id, BlockIdExt masterchain_block_id, td::int64 offset,
td::int64 max_size, td::Promise<td::BufferSlice> promise);
void check_persistent_state(BlockIdExt block_id, BlockIdExt masterchain_block_id, td::Promise<bool> promise);
void get_persistent_state_file_size(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise<td::uint64> promise);
void check_zero_state(BlockIdExt block_id, td::Promise<bool> promise);
void get_previous_persistent_state_files(BlockSeqno cur_mc_seqno,
td::Promise<std::vector<std::pair<std::string, ShardIdFull>>> promise);
@ -189,7 +190,11 @@ class ArchiveManager : public td::actor::Actor {
return p.key ? key_files_ : p.temp ? temp_files_ : files_;
}
std::map<std::pair<BlockSeqno, FileHash>, FileReferenceShort> perm_states_; // Mc block seqno, hash -> state
struct PermState {
FileReferenceShort id;
td::uint64 size;
};
std::map<std::pair<BlockSeqno, FileHash>, PermState> perm_states_; // Mc block seqno, hash -> state
void load_package(PackageId seqno);
void delete_package(PackageId seqno, td::Promise<td::Unit> promise);

View file

@ -310,9 +310,9 @@ void RootDb::get_persistent_state_file_slice(BlockIdExt block_id, BlockIdExt mas
offset, max_size, std::move(promise));
}
void RootDb::check_persistent_state_file_exists(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise<bool> promise) {
td::actor::send_closure(archive_db_, &ArchiveManager::check_persistent_state, block_id, masterchain_block_id,
void RootDb::get_persistent_state_file_size(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise<td::uint64> promise) {
td::actor::send_closure(archive_db_, &ArchiveManager::get_persistent_state_file_size, block_id, masterchain_block_id,
std::move(promise));
}

View file

@ -80,8 +80,8 @@ class RootDb : public Db {
td::Promise<td::BufferSlice> promise) override;
void get_persistent_state_file_slice(BlockIdExt block_id, BlockIdExt masterchain_block_id, td::int64 offset,
td::int64 max_length, td::Promise<td::BufferSlice> promise) override;
void check_persistent_state_file_exists(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise<bool> promise) override;
void get_persistent_state_file_size(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise<td::uint64> promise) override;
void store_zero_state_file(BlockIdExt block_id, td::BufferSlice state, td::Promise<td::Unit> promise) override;
void get_zero_state_file(BlockIdExt block_id, td::Promise<td::BufferSlice> promise) override;
void check_zero_state_file_exists(BlockIdExt block_id, td::Promise<bool> promise) override;