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

Add archive manager index (#685)

* Optimize get_file_desc_by_ seqno/lt/ut

* Optimize get_next_file_desc

---------

Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
EmelyanenkoK 2023-04-28 12:58:02 +03:00 committed by GitHub
parent dd8658c4db
commit 8bc20ede2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 260 additions and 176 deletions

View file

@ -74,7 +74,7 @@ void ArchiveManager::add_handle(BlockHandle handle, td::Promise<td::Unit> promis
} }
void ArchiveManager::update_handle(BlockHandle handle, td::Promise<td::Unit> promise) { void ArchiveManager::update_handle(BlockHandle handle, td::Promise<td::Unit> promise) {
FileDescription *f; const FileDescription *f;
if (handle->handle_moved_to_archive()) { if (handle->handle_moved_to_archive()) {
CHECK(handle->inited_unix_time()); CHECK(handle->inited_unix_time());
if (!handle->need_flush()) { if (!handle->need_flush()) {
@ -439,15 +439,15 @@ void ArchiveManager::check_persistent_state(BlockIdExt block_id, BlockIdExt mast
void ArchiveManager::get_block_by_unix_time(AccountIdPrefixFull account_id, UnixTime ts, void ArchiveManager::get_block_by_unix_time(AccountIdPrefixFull account_id, UnixTime ts,
td::Promise<ConstBlockHandle> promise) { td::Promise<ConstBlockHandle> promise) {
auto f = get_file_desc_by_unix_time(account_id, ts, false); auto f1 = get_file_desc_by_unix_time(account_id, ts, false);
if (f) { auto f2 = get_next_file_desc(f1, account_id, false);
auto n = f; if (!f1) {
do { std::swap(f1, f2);
n = get_next_file_desc(n); }
} while (n != nullptr && !n->has_account_prefix(account_id)); if (f1) {
td::actor::ActorId<ArchiveSlice> aid; td::actor::ActorId<ArchiveSlice> aid;
if (n) { if (f2) {
aid = n->file_actor_id(); aid = f2->file_actor_id();
} }
auto P = td::PromiseCreator::lambda( auto P = td::PromiseCreator::lambda(
[aid, account_id, ts, promise = std::move(promise)](td::Result<ConstBlockHandle> R) mutable { [aid, account_id, ts, promise = std::move(promise)](td::Result<ConstBlockHandle> R) mutable {
@ -457,7 +457,7 @@ void ArchiveManager::get_block_by_unix_time(AccountIdPrefixFull account_id, Unix
td::actor::send_closure(aid, &ArchiveSlice::get_block_by_unix_time, account_id, ts, std::move(promise)); td::actor::send_closure(aid, &ArchiveSlice::get_block_by_unix_time, account_id, ts, std::move(promise));
} }
}); });
td::actor::send_closure(f->file_actor_id(), &ArchiveSlice::get_block_by_unix_time, account_id, ts, std::move(P)); td::actor::send_closure(f1->file_actor_id(), &ArchiveSlice::get_block_by_unix_time, account_id, ts, std::move(P));
} else { } else {
promise.set_error(td::Status::Error(ErrorCode::notready, "ts not in db")); promise.set_error(td::Status::Error(ErrorCode::notready, "ts not in db"));
} }
@ -465,15 +465,15 @@ void ArchiveManager::get_block_by_unix_time(AccountIdPrefixFull account_id, Unix
void ArchiveManager::get_block_by_lt(AccountIdPrefixFull account_id, LogicalTime lt, void ArchiveManager::get_block_by_lt(AccountIdPrefixFull account_id, LogicalTime lt,
td::Promise<ConstBlockHandle> promise) { td::Promise<ConstBlockHandle> promise) {
auto f = get_file_desc_by_lt(account_id, lt, false); auto f1 = get_file_desc_by_lt(account_id, lt, false);
if (f) { auto f2 = get_next_file_desc(f1, account_id, false);
auto n = f; if (!f1) {
do { std::swap(f1, f2);
n = get_next_file_desc(n); }
} while (n != nullptr && !n->has_account_prefix(account_id)); if (f1) {
td::actor::ActorId<ArchiveSlice> aid; td::actor::ActorId<ArchiveSlice> aid;
if (n) { if (f2) {
aid = n->file_actor_id(); aid = f2->file_actor_id();
} }
auto P = td::PromiseCreator::lambda( auto P = td::PromiseCreator::lambda(
[aid, account_id, lt, promise = std::move(promise)](td::Result<ConstBlockHandle> R) mutable { [aid, account_id, lt, promise = std::move(promise)](td::Result<ConstBlockHandle> R) mutable {
@ -483,7 +483,7 @@ void ArchiveManager::get_block_by_lt(AccountIdPrefixFull account_id, LogicalTime
td::actor::send_closure(aid, &ArchiveSlice::get_block_by_lt, account_id, lt, std::move(promise)); td::actor::send_closure(aid, &ArchiveSlice::get_block_by_lt, account_id, lt, std::move(promise));
} }
}); });
td::actor::send_closure(f->file_actor_id(), &ArchiveSlice::get_block_by_lt, account_id, lt, std::move(P)); td::actor::send_closure(f1->file_actor_id(), &ArchiveSlice::get_block_by_lt, account_id, lt, std::move(P));
} else { } else {
promise.set_error(td::Status::Error(ErrorCode::notready, "lt not in db")); promise.set_error(td::Status::Error(ErrorCode::notready, "lt not in db"));
} }
@ -558,7 +558,7 @@ void ArchiveManager::deleted_package(PackageId id, td::Promise<td::Unit> promise
auto it = m.find(id); auto it = m.find(id);
CHECK(it != m.end()); CHECK(it != m.end());
CHECK(it->second.deleted); CHECK(it->second.deleted);
it->second.clear_actor_id(); it->second.file.reset();
promise.set_value(td::Unit()); promise.set_value(td::Unit());
} }
@ -598,8 +598,8 @@ void ArchiveManager::load_package(PackageId id) {
get_file_map(id).emplace(id, std::move(desc)); get_file_map(id).emplace(id, std::move(desc));
} }
ArchiveManager::FileDescription *ArchiveManager::get_file_desc(ShardIdFull shard, PackageId id, BlockSeqno seqno, const ArchiveManager::FileDescription *ArchiveManager::get_file_desc(ShardIdFull shard, PackageId id, BlockSeqno seqno,
UnixTime ts, LogicalTime lt, bool force) { UnixTime ts, LogicalTime lt, bool force) {
auto &f = get_file_map(id); auto &f = get_file_map(id);
auto it = f.find(id); auto it = f.find(id);
if (it != f.end()) { if (it != f.end()) {
@ -607,7 +607,7 @@ ArchiveManager::FileDescription *ArchiveManager::get_file_desc(ShardIdFull shard
return nullptr; return nullptr;
} }
if (force && !id.temp) { if (force && !id.temp) {
update_desc(it->second, shard, seqno, ts, lt); update_desc(f, it->second, shard, seqno, ts, lt);
} }
return &it->second; return &it->second;
} }
@ -618,17 +618,18 @@ ArchiveManager::FileDescription *ArchiveManager::get_file_desc(ShardIdFull shard
return add_file_desc(shard, id, seqno, ts, lt); return add_file_desc(shard, id, seqno, ts, lt);
} }
ArchiveManager::FileDescription *ArchiveManager::add_file_desc(ShardIdFull shard, PackageId id, BlockSeqno seqno, const ArchiveManager::FileDescription *ArchiveManager::add_file_desc(ShardIdFull shard, PackageId id, BlockSeqno seqno,
UnixTime ts, LogicalTime lt) { UnixTime ts, LogicalTime lt) {
auto &f = get_file_map(id); auto &f = get_file_map(id);
CHECK(f.count(id) == 0); CHECK(f.count(id) == 0);
FileDescription desc{id, false}; FileDescription new_desc{id, false};
td::mkdir(db_root_ + id.path()).ensure(); td::mkdir(db_root_ + id.path()).ensure();
std::string prefix = PSTRING() << db_root_ << id.path() << id.name(); std::string prefix = PSTRING() << db_root_ << id.path() << id.name();
desc.file = td::actor::create_actor<ArchiveSlice>("slice", id.id, id.key, id.temp, false, db_root_); new_desc.file = td::actor::create_actor<ArchiveSlice>("slice", id.id, id.key, id.temp, false, db_root_);
const FileDescription &desc = f.emplace(id, std::move(new_desc));
if (!id.temp) { if (!id.temp) {
update_desc(desc, shard, seqno, ts, lt); update_desc(f, desc, shard, seqno, ts, lt);
} }
std::vector<tl_object_ptr<ton_api::db_files_package_firstBlock>> vec; std::vector<tl_object_ptr<ton_api::db_files_package_firstBlock>> vec;
@ -668,17 +669,16 @@ ArchiveManager::FileDescription *ArchiveManager::add_file_desc(ShardIdFull shard
.ensure(); .ensure();
} }
index_->commit_transaction().ensure(); index_->commit_transaction().ensure();
return &desc;
return &f.emplace(id, std::move(desc)).first->second;
} }
void ArchiveManager::update_desc(FileDescription &desc, ShardIdFull shard, BlockSeqno seqno, UnixTime ts, void ArchiveManager::update_desc(FileMap &f, const FileDescription &desc, ShardIdFull shard, BlockSeqno seqno,
LogicalTime lt) { UnixTime ts, LogicalTime lt) {
auto it = desc.first_blocks.find(shard); auto it = desc.first_blocks.find(shard);
if (it != desc.first_blocks.end() && it->second.seqno <= seqno) { if (it != desc.first_blocks.end() && it->second.seqno <= seqno) {
return; return;
} }
desc.first_blocks[shard] = FileDescription::Desc{seqno, ts, lt}; f.set_shard_first_block(desc, shard, FileDescription::Desc{seqno, ts, lt});
std::vector<tl_object_ptr<ton_api::db_files_package_firstBlock>> vec; std::vector<tl_object_ptr<ton_api::db_files_package_firstBlock>> vec;
for (auto &e : desc.first_blocks) { for (auto &e : desc.first_blocks) {
vec.push_back(create_tl_object<ton_api::db_files_package_firstBlock>(e.first.workchain, e.first.shard, vec.push_back(create_tl_object<ton_api::db_files_package_firstBlock>(e.first.workchain, e.first.shard,
@ -694,150 +694,91 @@ void ArchiveManager::update_desc(FileDescription &desc, ShardIdFull shard, Block
index_->commit_transaction().ensure(); index_->commit_transaction().ensure();
} }
ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_seqno(ShardIdFull shard, BlockSeqno seqno, const ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_seqno(ShardIdFull shard, BlockSeqno seqno,
bool key_block) { bool key_block) {
auto &f = get_file_map(PackageId{0, key_block, false}); return get_file_map(PackageId{0, key_block, false}).get_file_desc_by_seqno(shard, seqno);
for (auto it = f.rbegin(); it != f.rend(); it++) {
auto i = it->second.first_blocks.find(shard);
if (i != it->second.first_blocks.end() && i->second.seqno <= seqno) {
if (it->second.deleted) {
return nullptr;
} else {
return &it->second;
}
}
}
return nullptr;
} }
ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_unix_time(ShardIdFull shard, UnixTime ts, const ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_unix_time(ShardIdFull shard, UnixTime ts,
bool key_block) { bool key_block) {
auto &f = get_file_map(PackageId{0, key_block, false}); return get_file_map(PackageId{0, key_block, false}).get_file_desc_by_unix_time(shard, ts);
for (auto it = f.rbegin(); it != f.rend(); it++) {
auto i = it->second.first_blocks.find(shard);
if (i != it->second.first_blocks.end() && i->second.ts <= ts) {
if (it->second.deleted) {
return nullptr;
} else {
return &it->second;
}
}
}
return nullptr;
} }
ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_lt(ShardIdFull shard, LogicalTime lt, const ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_lt(ShardIdFull shard, LogicalTime lt,
bool key_block) { bool key_block) {
auto &f = get_file_map(PackageId{0, key_block, false}); return get_file_map(PackageId{0, key_block, false}).get_file_desc_by_lt(shard, lt);
for (auto it = f.rbegin(); it != f.rend(); it++) {
auto i = it->second.first_blocks.find(shard);
if (i != it->second.first_blocks.end() && i->second.lt <= lt) {
if (it->second.deleted) {
return nullptr;
} else {
return &it->second;
}
}
}
return nullptr;
} }
ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_seqno(AccountIdPrefixFull account, BlockSeqno seqno, const ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_seqno(AccountIdPrefixFull account,
bool key_block) { BlockSeqno seqno, bool key_block) {
auto &f = get_file_map(PackageId{0, key_block, false});
if (account.is_masterchain()) { if (account.is_masterchain()) {
return get_file_desc_by_seqno(ShardIdFull{masterchainId}, seqno, key_block); return get_file_desc_by_seqno(ShardIdFull{masterchainId}, seqno, key_block);
} }
for (auto it = f.rbegin(); it != f.rend(); it++) { auto &f = get_file_map(PackageId{0, key_block, false});
if (it->second.deleted) { const FileDescription *result = nullptr;
continue; for (int i = 0; i <= 60; i++) {
} const FileDescription *desc = f.get_file_desc_by_seqno(shard_prefix(account, i), seqno);
bool found = false; if (desc && (!result || result->id < desc->id)) {
for (int i = 0; i < 60; i++) { result = desc;
auto shard = shard_prefix(account, i); } else if (result && (!desc || desc->id < result->id)) {
auto it2 = it->second.first_blocks.find(shard); break;
if (it2 != it->second.first_blocks.end()) {
if (it2->second.seqno <= seqno) {
return &it->second;
}
found = true;
} else if (found) {
break;
}
} }
} }
return nullptr; return result;
} }
ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_unix_time(AccountIdPrefixFull account, UnixTime ts, const ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_unix_time(AccountIdPrefixFull account,
bool key_block) { UnixTime ts, bool key_block) {
auto &f = get_file_map(PackageId{0, key_block, false});
if (account.is_masterchain()) { if (account.is_masterchain()) {
return get_file_desc_by_unix_time(ShardIdFull{masterchainId}, ts, key_block); return get_file_desc_by_unix_time(ShardIdFull{masterchainId}, ts, key_block);
} }
for (auto it = f.rbegin(); it != f.rend(); it++) { auto &f = get_file_map(PackageId{0, key_block, false});
if (it->second.deleted) { const FileDescription *result = nullptr;
continue; for (int i = 0; i <= 60; i++) {
} const FileDescription *desc = f.get_file_desc_by_unix_time(shard_prefix(account, i), ts);
bool found = false; if (desc && (!result || result->id < desc->id)) {
for (int i = 0; i < 60; i++) { result = desc;
auto shard = shard_prefix(account, i); } else if (result && (!desc || desc->id < result->id)) {
auto it2 = it->second.first_blocks.find(shard); break;
if (it2 != it->second.first_blocks.end()) {
if (it2->second.ts <= ts) {
return &it->second;
}
found = true;
} else if (found) {
break;
}
} }
} }
return nullptr; return result;
} }
ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_lt(AccountIdPrefixFull account, LogicalTime lt, const ArchiveManager::FileDescription *ArchiveManager::get_file_desc_by_lt(AccountIdPrefixFull account, LogicalTime lt,
bool key_block) { bool key_block) {
auto &f = get_file_map(PackageId{0, key_block, false});
if (account.is_masterchain()) { if (account.is_masterchain()) {
return get_file_desc_by_lt(ShardIdFull{masterchainId}, lt, key_block); return get_file_desc_by_lt(ShardIdFull{masterchainId}, lt, key_block);
} }
for (auto it = f.rbegin(); it != f.rend(); it++) { auto &f = get_file_map(PackageId{0, key_block, false});
if (it->second.deleted) { const FileDescription *result = nullptr;
continue; for (int i = 0; i <= 60; i++) {
} const FileDescription *desc = f.get_file_desc_by_lt(shard_prefix(account, i), lt);
bool found = false; if (desc && (!result || result->id < desc->id)) {
for (int i = 0; i < 60; i++) { result = desc;
auto shard = shard_prefix(account, i); } else if (result && (!desc || desc->id < result->id)) {
auto it2 = it->second.first_blocks.find(shard); break;
if (it2 != it->second.first_blocks.end()) {
if (it2->second.lt <= lt) {
return &it->second;
}
found = true;
} else if (found) {
break;
}
} }
} }
return nullptr; return result;
} }
ArchiveManager::FileDescription *ArchiveManager::get_next_file_desc(FileDescription *f) { const ArchiveManager::FileDescription *ArchiveManager::get_next_file_desc(const FileDescription *f,
auto &m = get_file_map(f->id); AccountIdPrefixFull shard, bool key_block) {
auto it = m.find(f->id); auto &m = get_file_map(PackageId{0, key_block, false});
CHECK(it != m.end()); const FileDescription *result = nullptr;
while (true) { for (int i = 0; i <= 60; i++) {
it++; const FileDescription *desc = m.get_next_file_desc(shard_prefix(shard, i), f);
if (it == m.end()) { if (desc && (!result || desc->id < result->id)) {
return nullptr; result = desc;
} else if (!it->second.deleted) { } else if (result && (!desc || result->id < desc->id)) {
return &it->second; break;
} }
} }
return result;
} }
ArchiveManager::FileDescription *ArchiveManager::get_temp_file_desc_by_idx(PackageId idx) { const ArchiveManager::FileDescription *ArchiveManager::get_temp_file_desc_by_idx(PackageId idx) {
auto it = temp_files_.find(idx); auto it = temp_files_.find(idx);
if (it != temp_files_.end()) { if (it != temp_files_.end()) {
if (it->second.deleted) { if (it->second.deleted) {
@ -1257,14 +1198,100 @@ void ArchiveManager::truncate(BlockSeqno masterchain_seqno, ConstBlockHandle han
} }
} }
bool ArchiveManager::FileDescription::has_account_prefix(AccountIdPrefixFull account_id) const { void ArchiveManager::FileMap::shard_index_add(const FileDescription &desc) {
for (int i = 0; i < 60; i++) { for (const auto &p : desc.first_blocks) {
auto shard = shard_prefix(account_id, i); ShardIndex &s = shards_[p.first];
if (first_blocks.count(shard)) { s.seqno_index_[p.second.seqno] = &desc;
return true; s.lt_index_[p.second.lt] = &desc;
} s.unix_time_index_[p.second.ts] = &desc;
s.packages_index_[desc.id] = &desc;
} }
return false; }
void ArchiveManager::FileMap::shard_index_del(const FileDescription &desc) {
for (const auto &p : desc.first_blocks) {
ShardIndex &s = shards_[p.first];
s.seqno_index_.erase(p.second.seqno);
s.lt_index_.erase(p.second.lt);
s.unix_time_index_.erase(p.second.ts);
s.packages_index_.erase(desc.id);
}
}
void ArchiveManager::FileMap::set_shard_first_block(const FileDescription &desc, ShardIdFull shard,
FileDescription::Desc v) {
ShardIndex &s = shards_[shard];
auto &d = const_cast<FileDescription &>(desc);
auto it = d.first_blocks.find(shard);
if (it != d.first_blocks.end()) {
s.seqno_index_.erase(it->second.seqno);
s.lt_index_.erase(it->second.lt);
s.unix_time_index_.erase(it->second.ts);
}
d.first_blocks[shard] = v;
s.seqno_index_[v.seqno] = &d;
s.lt_index_[v.lt] = &d;
s.unix_time_index_[v.ts] = &d;
s.packages_index_[d.id] = &d;
}
const ArchiveManager::FileDescription *ArchiveManager::FileMap::get_file_desc_by_seqno(ShardIdFull shard,
BlockSeqno seqno) const {
auto it = shards_.find(shard);
if (it == shards_.end()) {
return nullptr;
}
const auto &map = it->second.seqno_index_;
auto it2 = map.upper_bound(seqno);
if (it2 == map.begin()) {
return nullptr;
}
--it2;
return it2->second->deleted ? nullptr : it2->second;
}
const ArchiveManager::FileDescription *ArchiveManager::FileMap::get_file_desc_by_lt(ShardIdFull shard,
LogicalTime lt) const {
auto it = shards_.find(shard);
if (it == shards_.end()) {
return nullptr;
}
const auto &map = it->second.lt_index_;
auto it2 = map.upper_bound(lt);
if (it2 == map.begin()) {
return nullptr;
}
--it2;
return it2->second->deleted ? nullptr : it2->second;
}
const ArchiveManager::FileDescription *ArchiveManager::FileMap::get_file_desc_by_unix_time(ShardIdFull shard,
UnixTime ts) const {
auto it = shards_.find(shard);
if (it == shards_.end()) {
return nullptr;
}
const auto &map = it->second.unix_time_index_;
auto it2 = map.upper_bound(ts);
if (it2 == map.begin()) {
return nullptr;
}
--it2;
return it2->second->deleted ? nullptr : it2->second;
}
const ArchiveManager::FileDescription *ArchiveManager::FileMap::get_next_file_desc(ShardIdFull shard,
const FileDescription *desc) const {
auto it = shards_.find(shard);
if (it == shards_.end()) {
return nullptr;
}
const auto &map = it->second.packages_index_;
auto it2 = desc ? map.upper_bound(desc->id) : map.begin();
if (it2 == map.end()) {
return nullptr;
}
return it2->second->deleted ? nullptr : it2->second;
} }
} // namespace validator } // namespace validator

View file

@ -71,7 +71,6 @@ class ArchiveManager : public td::actor::Actor {
void start_up() override; void start_up() override;
void begin_transaction();
void commit_transaction(); void commit_transaction();
void set_async_mode(bool mode, td::Promise<td::Unit> promise); void set_async_mode(bool mode, td::Promise<td::Unit> promise);
@ -94,26 +93,83 @@ class ArchiveManager : public td::actor::Actor {
auto file_actor_id() const { auto file_actor_id() const {
return file.get(); return file.get();
} }
void clear_actor_id() {
file.reset();
}
bool has_account_prefix(AccountIdPrefixFull account_id) const;
PackageId id; PackageId id;
bool deleted; mutable bool deleted;
std::map<ShardIdFull, Desc> first_blocks; std::map<ShardIdFull, Desc> first_blocks;
td::actor::ActorOwn<ArchiveSlice> file; mutable td::actor::ActorOwn<ArchiveSlice> file;
}; };
std::map<PackageId, FileDescription> files_; class FileMap {
std::map<PackageId, FileDescription> key_files_; public:
std::map<PackageId, FileDescription> temp_files_; std::map<PackageId, FileDescription>::const_iterator begin() const {
return files_.cbegin();
}
std::map<PackageId, FileDescription>::const_iterator end() const {
return files_.cend();
}
std::map<PackageId, FileDescription>::const_reverse_iterator rbegin() const {
return files_.crbegin();
}
std::map<PackageId, FileDescription>::const_reverse_iterator rend() const {
return files_.crend();
}
std::map<PackageId, FileDescription>::const_iterator find(PackageId x) const {
return files_.find(x);
}
size_t count(const PackageId &x) const {
return files_.count(x);
}
size_t size() const {
return files_.size();
}
std::map<PackageId, FileDescription>::const_iterator lower_bound(const PackageId &x) const {
return files_.lower_bound(x);
}
std::map<PackageId, FileDescription>::const_iterator upper_bound(const PackageId &x) const {
return files_.upper_bound(x);
}
void clear() {
files_.clear();
shards_.clear();
}
const FileDescription &emplace(const PackageId &id, FileDescription desc) {
auto it = files_.emplace(id, std::move(desc));
if (it.second) {
shard_index_add(it.first->second);
}
return it.first->second;
}
void erase(std::map<PackageId, FileDescription>::const_iterator it) {
shard_index_del(it->second);
files_.erase(it);
}
void set_shard_first_block(const FileDescription &desc, ShardIdFull shard, FileDescription::Desc v);
const FileDescription *get_file_desc_by_seqno(ShardIdFull shard, BlockSeqno seqno) const;
const FileDescription *get_file_desc_by_lt(ShardIdFull shard, LogicalTime lt) const;
const FileDescription *get_file_desc_by_unix_time(ShardIdFull shard, UnixTime ts) const;
const FileDescription *get_next_file_desc(ShardIdFull shard, const FileDescription *desc) const;
private:
std::map<PackageId, FileDescription> files_;
struct ShardIndex {
std::map<BlockSeqno, const FileDescription *> seqno_index_;
std::map<LogicalTime, const FileDescription *> lt_index_;
std::map<UnixTime, const FileDescription *> unix_time_index_;
std::map<PackageId, const FileDescription *> packages_index_;
};
std::map<ShardIdFull, ShardIndex> shards_;
void shard_index_add(const FileDescription &desc);
void shard_index_del(const FileDescription &desc);
};
FileMap files_, key_files_, temp_files_;
BlockSeqno finalized_up_to_{0}; BlockSeqno finalized_up_to_{0};
bool async_mode_ = false; bool async_mode_ = false;
bool huge_transaction_started_ = false; bool huge_transaction_started_ = false;
td::uint32 huge_transaction_size_ = 0; td::uint32 huge_transaction_size_ = 0;
auto &get_file_map(const PackageId &p) { FileMap &get_file_map(const PackageId &p) {
return p.key ? key_files_ : p.temp ? temp_files_ : files_; return p.key ? key_files_ : p.temp ? temp_files_ : files_;
} }
@ -126,18 +182,19 @@ class ArchiveManager : public td::actor::Actor {
void get_handle_finish(BlockHandle handle, td::Promise<BlockHandle> promise); void get_handle_finish(BlockHandle handle, td::Promise<BlockHandle> promise);
void get_file_short_cont(FileReference ref_id, PackageId idx, td::Promise<td::BufferSlice> promise); void get_file_short_cont(FileReference ref_id, PackageId idx, td::Promise<td::BufferSlice> promise);
FileDescription *get_file_desc(ShardIdFull shard, PackageId id, BlockSeqno seqno, UnixTime ts, LogicalTime lt, const FileDescription *get_file_desc(ShardIdFull shard, PackageId id, BlockSeqno seqno, UnixTime ts, LogicalTime lt,
bool force); bool force);
FileDescription *add_file_desc(ShardIdFull shard, PackageId id, BlockSeqno seqno, UnixTime ts, LogicalTime lt); const FileDescription *add_file_desc(ShardIdFull shard, PackageId id, BlockSeqno seqno, UnixTime ts, LogicalTime lt);
void update_desc(FileDescription &desc, ShardIdFull shard, BlockSeqno seqno, UnixTime ts, LogicalTime lt); void update_desc(FileMap &f, const FileDescription &desc, ShardIdFull shard, BlockSeqno seqno, UnixTime ts,
FileDescription *get_file_desc_by_seqno(ShardIdFull shard, BlockSeqno seqno, bool key_block); LogicalTime lt);
FileDescription *get_file_desc_by_lt(ShardIdFull shard, LogicalTime lt, bool key_block); const FileDescription *get_file_desc_by_seqno(ShardIdFull shard, BlockSeqno seqno, bool key_block);
FileDescription *get_file_desc_by_unix_time(ShardIdFull shard, UnixTime ts, bool key_block); const FileDescription *get_file_desc_by_lt(ShardIdFull shard, LogicalTime lt, bool key_block);
FileDescription *get_file_desc_by_seqno(AccountIdPrefixFull shard, BlockSeqno seqno, bool key_block); const FileDescription *get_file_desc_by_unix_time(ShardIdFull shard, UnixTime ts, bool key_block);
FileDescription *get_file_desc_by_lt(AccountIdPrefixFull shard, LogicalTime lt, bool key_block); const FileDescription *get_file_desc_by_seqno(AccountIdPrefixFull shard, BlockSeqno seqno, bool key_block);
FileDescription *get_file_desc_by_unix_time(AccountIdPrefixFull shard, UnixTime ts, bool key_block); const FileDescription *get_file_desc_by_lt(AccountIdPrefixFull shard, LogicalTime lt, bool key_block);
FileDescription *get_next_file_desc(FileDescription *f); const FileDescription *get_file_desc_by_unix_time(AccountIdPrefixFull shard, UnixTime ts, bool key_block);
FileDescription *get_temp_file_desc_by_idx(PackageId idx); const FileDescription *get_next_file_desc(const FileDescription *f, AccountIdPrefixFull shard, bool key_block);
const FileDescription *get_temp_file_desc_by_idx(PackageId idx);
PackageId get_max_temp_file_desc_idx(); PackageId get_max_temp_file_desc_idx();
PackageId get_prev_temp_file_desc_idx(PackageId id); PackageId get_prev_temp_file_desc_idx(PackageId id);