mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
error handling in lite client, speed up message dequeue in blocks
This commit is contained in:
parent
dfc040cb00
commit
cf97f48cd7
15 changed files with 224 additions and 88 deletions
|
@ -98,12 +98,13 @@ void ArchiveManager::add_file(BlockHandle handle, FileReference ref_id, td::Buff
|
|||
auto ig = mp.init_guard();
|
||||
ig.add_promise(std::move(promise));
|
||||
auto f1 = get_file_desc(handle->id().shard_full(), get_temp_package_id(), 0, 0, 0, true);
|
||||
td::actor::send_closure(f1->file_actor_id(), &ArchiveSlice::add_file, std::move(ref_id), data.clone(),
|
||||
td::actor::send_closure(f1->file_actor_id(), &ArchiveSlice::add_file, nullptr, std::move(ref_id), data.clone(),
|
||||
ig.get_promise());
|
||||
if (copy_to_key) {
|
||||
auto f2 = get_file_desc(handle->id().shard_full(), get_key_package_id(handle->masterchain_ref_block()),
|
||||
handle->id().seqno(), handle->unix_time(), handle->logical_time(), true);
|
||||
td::actor::send_closure(f2->file_actor_id(), &ArchiveSlice::add_file, ref_id, std::move(data), ig.get_promise());
|
||||
td::actor::send_closure(f2->file_actor_id(), &ArchiveSlice::add_file, nullptr, ref_id, std::move(data),
|
||||
ig.get_promise());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -115,24 +116,25 @@ void ArchiveManager::add_file(BlockHandle handle, FileReference ref_id, td::Buff
|
|||
ig.add_promise(std::move(promise));
|
||||
auto f1 = get_file_desc(handle->id().shard_full(), get_package_id(handle->masterchain_ref_block()),
|
||||
handle->id().seqno(), handle->unix_time(), handle->logical_time(), true);
|
||||
td::actor::send_closure(f1->file_actor_id(), &ArchiveSlice::add_file, ref_id, data.clone(), ig.get_promise());
|
||||
td::actor::send_closure(f1->file_actor_id(), &ArchiveSlice::add_file, handle, ref_id, data.clone(), ig.get_promise());
|
||||
if (copy_to_key) {
|
||||
auto f2 = get_file_desc(handle->id().shard_full(), get_key_package_id(handle->masterchain_ref_block()),
|
||||
handle->id().seqno(), handle->unix_time(), handle->logical_time(), true);
|
||||
td::actor::send_closure(f2->file_actor_id(), &ArchiveSlice::add_file, ref_id, std::move(data), ig.get_promise());
|
||||
td::actor::send_closure(f2->file_actor_id(), &ArchiveSlice::add_file, handle, ref_id, std::move(data),
|
||||
ig.get_promise());
|
||||
}
|
||||
}
|
||||
|
||||
void ArchiveManager::add_key_block_proof(UnixTime ts, BlockSeqno seqno, LogicalTime lt, FileReference ref_id,
|
||||
td::BufferSlice data, td::Promise<td::Unit> promise) {
|
||||
auto f = get_file_desc(ShardIdFull{masterchainId}, get_key_package_id(seqno), seqno, ts, lt, true);
|
||||
td::actor::send_closure(f->file_actor_id(), &ArchiveSlice::add_file, std::move(ref_id), std::move(data),
|
||||
td::actor::send_closure(f->file_actor_id(), &ArchiveSlice::add_file, nullptr, std::move(ref_id), std::move(data),
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void ArchiveManager::add_temp_file_short(FileReference ref_id, td::BufferSlice data, td::Promise<td::Unit> promise) {
|
||||
auto f = get_file_desc(ref_id.shard(), get_temp_package_id(), 0, 0, 0, true);
|
||||
td::actor::send_closure(f->file_actor_id(), &ArchiveSlice::add_file, std::move(ref_id), std::move(data),
|
||||
td::actor::send_closure(f->file_actor_id(), &ArchiveSlice::add_file, nullptr, std::move(ref_id), std::move(data),
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
|
@ -537,7 +539,7 @@ void ArchiveManager::load_package(PackageId id) {
|
|||
}
|
||||
}
|
||||
|
||||
desc.file = td::actor::create_actor<ArchiveSlice>("slice", id.key, id.temp, prefix);
|
||||
desc.file = td::actor::create_actor<ArchiveSlice>("slice", id.id, id.key, id.temp, prefix);
|
||||
|
||||
get_file_map(id).emplace(id, std::move(desc));
|
||||
}
|
||||
|
@ -571,7 +573,7 @@ ArchiveManager::FileDescription *ArchiveManager::add_file_desc(ShardIdFull shard
|
|||
FileDescription desc{id, false};
|
||||
td::mkdir(db_root_ + id.path()).ensure();
|
||||
std::string prefix = PSTRING() << db_root_ << id.path() << id.name();
|
||||
desc.file = td::actor::create_actor<ArchiveSlice>("slice", id.key, id.temp, prefix);
|
||||
desc.file = td::actor::create_actor<ArchiveSlice>("slice", id.id, id.key, id.temp, prefix);
|
||||
if (!id.temp) {
|
||||
update_desc(desc, shard, seqno, ts, lt);
|
||||
}
|
||||
|
@ -992,23 +994,19 @@ void ArchiveManager::get_archive_id(BlockSeqno masterchain_seqno, td::Promise<td
|
|||
return;
|
||||
}
|
||||
|
||||
promise.set_result(F->id.id);
|
||||
td::actor::send_closure(F->file_actor_id(), &ArchiveSlice::get_archive_id, masterchain_seqno, std::move(promise));
|
||||
}
|
||||
|
||||
void ArchiveManager::get_archive_slice(td::uint64 archive_id, td::uint64 offset, td::uint32 limit,
|
||||
td::Promise<td::BufferSlice> promise) {
|
||||
if (archive_id != static_cast<td::uint32>(archive_id)) {
|
||||
promise.set_error(td::Status::Error(ErrorCode::notready, "archive not found"));
|
||||
return;
|
||||
}
|
||||
auto F = get_file_desc(ShardIdFull{masterchainId}, PackageId{static_cast<BlockSeqno>(archive_id), false, false}, 0, 0,
|
||||
0, false);
|
||||
auto arch = static_cast<BlockSeqno>(archive_id);
|
||||
auto F = get_file_desc(ShardIdFull{masterchainId}, PackageId{arch, false, false}, 0, 0, 0, false);
|
||||
if (!F) {
|
||||
promise.set_error(td::Status::Error(ErrorCode::notready, "archive not found"));
|
||||
return;
|
||||
}
|
||||
|
||||
td::actor::send_closure(F->file_actor_id(), &ArchiveSlice::get_slice, offset, limit, std::move(promise));
|
||||
td::actor::send_closure(F->file_actor_id(), &ArchiveSlice::get_slice, archive_id, offset, limit, std::move(promise));
|
||||
}
|
||||
|
||||
void ArchiveManager::commit_transaction() {
|
||||
|
|
|
@ -162,7 +162,8 @@ void ArchiveSlice::update_handle(BlockHandle handle, td::Promise<td::Unit> promi
|
|||
promise.set_value(td::Unit());
|
||||
}
|
||||
|
||||
void ArchiveSlice::add_file(FileReference ref_id, td::BufferSlice data, td::Promise<td::Unit> promise) {
|
||||
void ArchiveSlice::add_file(BlockHandle handle, FileReference ref_id, td::BufferSlice data,
|
||||
td::Promise<td::Unit> promise) {
|
||||
if (destroyed_) {
|
||||
promise.set_error(td::Status::Error(ErrorCode::notready, "package already gc'd"));
|
||||
return;
|
||||
|
@ -409,7 +410,12 @@ td::BufferSlice ArchiveSlice::get_db_key_block_info(BlockIdExt block_id) {
|
|||
return create_serialize_tl_object<ton_api::db_blockdb_key_value>(create_tl_block_id(block_id));
|
||||
}
|
||||
|
||||
void ArchiveSlice::get_slice(td::uint64 offset, td::uint32 limit, td::Promise<td::BufferSlice> promise) {
|
||||
void ArchiveSlice::get_slice(td::uint64 archive_id, td::uint64 offset, td::uint32 limit,
|
||||
td::Promise<td::BufferSlice> promise) {
|
||||
if (archive_id != archive_id_) {
|
||||
promise.set_error(td::Status::Error(ErrorCode::error, "bad archive id"));
|
||||
return;
|
||||
}
|
||||
td::actor::create_actor<db::ReadFile>("readfile", prefix_ + ".pack", offset, limit, 0, std::move(promise)).release();
|
||||
}
|
||||
|
||||
|
@ -467,8 +473,8 @@ void ArchiveSlice::set_async_mode(bool mode, td::Promise<td::Unit> promise) {
|
|||
td::actor::send_closure(writer_, &PackageWriter::set_async_mode, mode, std::move(promise));
|
||||
}
|
||||
|
||||
ArchiveSlice::ArchiveSlice(bool key_blocks_only, bool temp, std::string prefix)
|
||||
: key_blocks_only_(key_blocks_only), temp_(temp), prefix_(std::move(prefix)) {
|
||||
ArchiveSlice::ArchiveSlice(td::uint32 archive_id, bool key_blocks_only, bool temp, std::string prefix)
|
||||
: archive_id_(archive_id), key_blocks_only_(key_blocks_only), temp_(temp), prefix_(std::move(prefix)) {
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -47,11 +47,15 @@ class PackageWriter : public td::actor::Actor {
|
|||
|
||||
class ArchiveSlice : public td::actor::Actor {
|
||||
public:
|
||||
ArchiveSlice(bool key_blocks_only, bool temp, std::string prefix);
|
||||
ArchiveSlice(td::uint32 archive_id, bool key_blocks_only, bool temp, std::string prefix);
|
||||
|
||||
void get_archive_id(BlockSeqno masterchain_seqno, td::Promise<td::uint64> promise) {
|
||||
promise.set_result(archive_id_);
|
||||
}
|
||||
|
||||
void add_handle(BlockHandle handle, td::Promise<td::Unit> promise);
|
||||
void update_handle(BlockHandle handle, td::Promise<td::Unit> promise);
|
||||
void add_file(FileReference ref_id, td::BufferSlice data, td::Promise<td::Unit> promise);
|
||||
void add_file(BlockHandle handle, FileReference ref_id, td::BufferSlice data, td::Promise<td::Unit> promise);
|
||||
void get_handle(BlockIdExt block_id, td::Promise<BlockHandle> promise);
|
||||
void get_temp_handle(BlockIdExt block_id, td::Promise<ConstBlockHandle> promise);
|
||||
void get_file(FileReference ref_id, td::Promise<td::BufferSlice> promise);
|
||||
|
@ -65,7 +69,7 @@ class ArchiveSlice : public td::actor::Actor {
|
|||
std::function<td::int32(ton_api::db_lt_el_value &)> compare, bool exact,
|
||||
td::Promise<ConstBlockHandle> promise);
|
||||
|
||||
void get_slice(td::uint64 offset, td::uint32 limit, td::Promise<td::BufferSlice> promise);
|
||||
void get_slice(td::uint64 archive_id, td::uint64 offset, td::uint32 limit, td::Promise<td::BufferSlice> promise);
|
||||
|
||||
void start_up() override;
|
||||
void destroy(td::Promise<td::Unit> promise);
|
||||
|
@ -84,6 +88,8 @@ class ArchiveSlice : public td::actor::Actor {
|
|||
td::BufferSlice get_db_key_block_info(BlockIdExt block_id);
|
||||
td::BufferSlice get_lt_from_db(ShardIdFull shard, td::uint32 idx);
|
||||
|
||||
td::uint32 archive_id_;
|
||||
|
||||
bool key_blocks_only_;
|
||||
bool temp_;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue