Skip to content

Commit e376747

Browse files
committed
Don't create more than one BlockArchiver for a block
1 parent 1d75202 commit e376747

File tree

6 files changed

+29
-12
lines changed

6 files changed

+29
-12
lines changed

validator/db/archiver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ BlockArchiver::BlockArchiver(BlockHandle handle, td::actor::ActorId<ArchiveManag
3131

3232
void BlockArchiver::start_up() {
3333
VLOG(VALIDATOR_DEBUG) << "started block archiver for " << handle_->id().to_str();
34+
if (handle_->moved_to_archive()) {
35+
VLOG(VALIDATOR_DEBUG) << "already moved";
36+
finish_query();
37+
return;
38+
}
3439
if (handle_->id().is_masterchain()) {
3540
td::actor::send_closure(db_, &Db::get_block_state, handle_,
3641
[SelfId = actor_id(this), archive = archive_](td::Result<td::Ref<ShardState>> R) {

validator/db/rootdb.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,6 @@ void RootDb::try_get_static_file(FileHash file_hash, td::Promise<td::BufferSlice
388388
td::actor::send_closure(static_files_db_, &StaticFilesDb::load_file, file_hash, std::move(promise));
389389
}
390390

391-
void RootDb::apply_block(BlockHandle handle, td::Promise<td::Unit> promise) {
392-
td::actor::create_actor<BlockArchiver>(PSTRING() << "archiver" << handle->id().id.to_str(), std::move(handle),
393-
archive_db_.get(), actor_id(this), std::move(promise))
394-
.release();
395-
}
396-
397391
void RootDb::get_block_by_lt(AccountIdPrefixFull account, LogicalTime lt, td::Promise<ConstBlockHandle> promise) {
398392
td::actor::send_closure(archive_db_, &ArchiveManager::get_block_by_lt, account, lt, std::move(promise));
399393
}
@@ -464,8 +458,26 @@ void RootDb::start_up() {
464458
}
465459

466460
void RootDb::archive(BlockHandle handle, td::Promise<td::Unit> promise) {
467-
td::actor::create_actor<BlockArchiver>(PSTRING() << "archiver" << handle->id().id.to_str(), std::move(handle),
468-
archive_db_.get(), actor_id(this), std::move(promise))
461+
auto [it, inserted] = archive_block_waiters_.emplace(handle->id(), std::vector<td::Promise<td::Unit>>{});
462+
it->second.push_back(std::move(promise));
463+
if (!inserted) {
464+
VLOG(VALIDATOR_DEBUG) << "archive block " << handle->id().id.to_str() << " : already in progress";
465+
return;
466+
}
467+
td::actor::create_actor<BlockArchiver>(
468+
PSTRING() << "archiver" << handle->id().id.to_str(), handle, archive_db_.get(), actor_id(this),
469+
[this, SelfId = actor_id(this), block_id = handle->id()](td::Result<td::Unit> R) {
470+
td::actor::send_lambda(SelfId, [this, R = std::move(R), block_id]() {
471+
auto it2 = archive_block_waiters_.find(block_id);
472+
if (it2 == archive_block_waiters_.end()) {
473+
return;
474+
}
475+
for (auto &promise : it2->second) {
476+
promise.set_result(R.clone());
477+
}
478+
archive_block_waiters_.erase(it2);
479+
});
480+
})
469481
.release();
470482
}
471483

validator/db/rootdb.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class RootDb : public Db {
9797

9898
void try_get_static_file(FileHash file_hash, td::Promise<td::BufferSlice> promise) override;
9999

100-
void apply_block(BlockHandle handle, td::Promise<td::Unit> promise) override;
101100
void get_block_by_lt(AccountIdPrefixFull account, LogicalTime lt, td::Promise<ConstBlockHandle> promise) override;
102101
void get_block_by_unix_time(AccountIdPrefixFull account, UnixTime ts, td::Promise<ConstBlockHandle> promise) override;
103102
void get_block_by_seqno(AccountIdPrefixFull account, BlockSeqno seqno,
@@ -157,6 +156,8 @@ class RootDb : public Db {
157156
td::actor::ActorOwn<StateDb> state_db_;
158157
td::actor::ActorOwn<StaticFilesDb> static_files_db_;
159158
td::actor::ActorOwn<ArchiveManager> archive_db_;
159+
160+
std::map<BlockIdExt, std::vector<td::Promise<td::Unit>>> archive_block_waiters_;
160161
};
161162

162163
} // namespace validator

validator/interfaces/db.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class Db : public td::actor::Actor {
8888
virtual void store_block_handle(BlockHandle handle, td::Promise<td::Unit> promise) = 0;
8989
virtual void get_block_handle(BlockIdExt id, td::Promise<BlockHandle> promise) = 0;
9090

91-
virtual void apply_block(BlockHandle handle, td::Promise<td::Unit> promise) = 0;
9291
virtual void get_block_by_lt(AccountIdPrefixFull account, LogicalTime lt, td::Promise<ConstBlockHandle> promise) = 0;
9392
virtual void get_block_by_unix_time(AccountIdPrefixFull account, UnixTime ts,
9493
td::Promise<ConstBlockHandle> promise) = 0;

validator/manager-disk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ void ValidatorManagerImpl::new_block(BlockHandle handle, td::Ref<ShardState> sta
856856
std::move(promise));
857857
}
858858
});
859-
td::actor::send_closure(db_, &Db::apply_block, handle, std::move(P));
859+
td::actor::send_closure(db_, &Db::archive, handle, std::move(P));
860860
}
861861
}
862862

validator/manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ void ValidatorManagerImpl::new_block(BlockHandle handle, td::Ref<ShardState> sta
16661666
std::move(promise));
16671667
}
16681668
});
1669-
td::actor::send_closure(db_, &Db::apply_block, handle, std::move(P));
1669+
td::actor::send_closure(db_, &Db::archive, handle, std::move(P));
16701670
}
16711671
}
16721672

0 commit comments

Comments
 (0)