@@ -70,8 +70,9 @@ void ArchiveManager::add_handle(BlockHandle handle, td::Promise<td::Unit> promis
7070 handle->unix_time (), handle->logical_time (),
7171 handle->inited_is_key_block () && handle->is_key_block ())
7272 : get_package_id (handle->masterchain_ref_block ());
73- auto f = get_file_desc (handle->id ().shard_full (), p, handle->id ().seqno (), handle->unix_time (),
74- handle->logical_time (), true );
73+ TRY_RESULT_PROMISE (promise, f,
74+ get_file_desc (handle->id ().shard_full (), p, handle->id ().seqno (), handle->unix_time (),
75+ handle->logical_time (), true ));
7576 td::actor::send_closure (f->file_actor_id (), &ArchiveSlice::add_handle, std::move (handle), std::move (promise));
7677}
7778
@@ -83,16 +84,17 @@ void ArchiveManager::update_handle(BlockHandle handle, td::Promise<td::Unit> pro
8384 promise.set_value (td::Unit ());
8485 return ;
8586 }
86- f = get_file_desc (handle->id ().shard_full (), get_package_id (handle->masterchain_ref_block ()), handle-> id (). seqno ( ),
87- handle->unix_time (), handle->logical_time (), true );
88- if (!f ) {
87+ auto F = get_file_desc (handle->id ().shard_full (), get_package_id (handle->masterchain_ref_block ()),
88+ handle-> id (). seqno (), handle->unix_time (), handle->logical_time (), true );
89+ if (F. is_error () ) {
8990 handle->flushed_upto (handle->version ());
9091 promise.set_value (td::Unit ());
9192 return ;
9293 }
94+ f = F.move_as_ok ();
9395 } else {
94- f = get_file_desc (handle-> id (). shard_full (), get_temp_package_id (), 0 , 0 , 0 , true );
95- CHECK (f );
96+ TRY_RESULT_PROMISE_ASSIGN (promise, f,
97+ get_file_desc (handle-> id (). shard_full (), get_temp_package_id (), 0 , 0 , 0 , true ) );
9698 }
9799 td::actor::send_closure (f->file_actor_id (), &ArchiveSlice::update_handle, std::move (handle), std::move (promise));
98100}
@@ -110,13 +112,17 @@ void ArchiveManager::add_file(BlockHandle handle, FileReference ref_id, td::Buff
110112 auto ig = mp.init_guard ();
111113 ig.add_promise (std::move (promise));
112114 auto f1 = get_file_desc (handle->id ().shard_full (), get_temp_package_id (), 0 , 0 , 0 , true );
113- td::actor::send_closure (f1->file_actor_id (), &ArchiveSlice::add_file, nullptr , std::move (ref_id), data.clone (),
114- ig.get_promise ());
115+ if (f1.is_ok ()) {
116+ td::actor::send_closure (f1.ok ()->file_actor_id (), &ArchiveSlice::add_file, nullptr , std::move (ref_id),
117+ data.clone (), ig.get_promise ());
118+ }
115119 if (copy_to_key) {
116120 auto f2 = get_file_desc (handle->id ().shard_full (), get_key_package_id (handle->masterchain_ref_block ()),
117121 handle->id ().seqno (), handle->unix_time (), handle->logical_time (), true );
118- td::actor::send_closure (f2->file_actor_id (), &ArchiveSlice::add_file, nullptr , ref_id, std::move (data),
119- ig.get_promise ());
122+ if (f2.is_ok ()) {
123+ td::actor::send_closure (f2.ok ()->file_actor_id (), &ArchiveSlice::add_file, nullptr , ref_id, std::move (data),
124+ ig.get_promise ());
125+ }
120126 }
121127 return ;
122128 }
@@ -128,24 +134,30 @@ void ArchiveManager::add_file(BlockHandle handle, FileReference ref_id, td::Buff
128134 ig.add_promise (std::move (promise));
129135 auto f1 = get_file_desc (handle->id ().shard_full (), get_package_id (handle->masterchain_ref_block ()),
130136 handle->id ().seqno (), handle->unix_time (), handle->logical_time (), true );
131- td::actor::send_closure (f1->file_actor_id (), &ArchiveSlice::add_file, handle, ref_id, data.clone (), ig.get_promise ());
137+ if (f1.is_ok ()) {
138+ td::actor::send_closure (f1.ok ()->file_actor_id (), &ArchiveSlice::add_file, handle, ref_id, data.clone (),
139+ ig.get_promise ());
140+ }
132141 if (copy_to_key) {
133142 auto f2 = get_file_desc (handle->id ().shard_full (), get_key_package_id (handle->masterchain_ref_block ()),
134143 handle->id ().seqno (), handle->unix_time (), handle->logical_time (), true );
135- td::actor::send_closure (f2->file_actor_id (), &ArchiveSlice::add_file, handle, ref_id, std::move (data),
136- ig.get_promise ());
144+ if (f2.is_ok ()) {
145+ td::actor::send_closure (f2.ok ()->file_actor_id (), &ArchiveSlice::add_file, handle, ref_id, std::move (data),
146+ ig.get_promise ());
147+ }
137148 }
138149}
139150
140151void ArchiveManager::add_key_block_proof (UnixTime ts, BlockSeqno seqno, LogicalTime lt, FileReference ref_id,
141152 td::BufferSlice data, td::Promise<td::Unit> promise) {
142- auto f = get_file_desc (ShardIdFull{masterchainId}, get_key_package_id (seqno), seqno, ts, lt, true );
153+ TRY_RESULT_PROMISE (promise, f,
154+ get_file_desc (ShardIdFull{masterchainId}, get_key_package_id (seqno), seqno, ts, lt, true ));
143155 td::actor::send_closure (f->file_actor_id (), &ArchiveSlice::add_file, nullptr , std::move (ref_id), std::move (data),
144156 std::move (promise));
145157}
146158
147159void ArchiveManager::add_temp_file_short (FileReference ref_id, td::BufferSlice data, td::Promise<td::Unit> promise) {
148- auto f = get_file_desc (ref_id.shard (), get_temp_package_id (), 0 , 0 , 0 , true );
160+ TRY_RESULT_PROMISE (promise, f, get_file_desc (ref_id.shard (), get_temp_package_id (), 0 , 0 , 0 , true ) );
149161 td::actor::send_closure (f->file_actor_id (), &ArchiveSlice::add_file, nullptr , std::move (ref_id), std::move (data),
150162 std::move (promise));
151163}
@@ -287,17 +299,17 @@ void ArchiveManager::get_temp_file_short_cont(FileReference ref_id, PackageId id
287299void ArchiveManager::get_file (ConstBlockHandle handle, FileReference ref_id, td::Promise<td::BufferSlice> promise) {
288300 if (handle->moved_to_archive ()) {
289301 auto f = get_file_desc (handle->id ().shard_full (), get_package_id (handle->masterchain_ref_block ()), 0 , 0 , 0 , false );
290- if (f) {
291- td::actor::send_closure (f->file_actor_id (), &ArchiveSlice::get_file, std::move (handle), std::move (ref_id),
302+ if (f. is_ok () ) {
303+ td::actor::send_closure (f. ok () ->file_actor_id (), &ArchiveSlice::get_file, std::move (handle), std::move (ref_id),
292304 std::move (promise));
293305 return ;
294306 }
295307 }
296308 if (handle->handle_moved_to_archive ()) {
297309 auto f = get_file_desc (handle->id ().shard_full (), get_package_id (handle->masterchain_ref_block ()), 0 , 0 , 0 , false );
298- if (f) {
310+ if (f. ok () ) {
299311 promise = [=, promise = std::move (promise),
300- file_actor = f->file_actor_id ()](td::Result<td::BufferSlice> R) mutable {
312+ file_actor = f. ok () ->file_actor_id ()](td::Result<td::BufferSlice> R) mutable {
301313 if (R.is_ok ()) {
302314 promise.set_value (R.move_as_ok ());
303315 return ;
@@ -656,21 +668,22 @@ void ArchiveManager::load_package(PackageId id) {
656668 update_permanent_slices ();
657669}
658670
659- const ArchiveManager::FileDescription *ArchiveManager::get_file_desc (ShardIdFull shard, PackageId id, BlockSeqno seqno,
660- UnixTime ts, LogicalTime lt, bool force) {
671+ td::Result<const ArchiveManager::FileDescription *> ArchiveManager::get_file_desc (ShardIdFull shard, PackageId id,
672+ BlockSeqno seqno, UnixTime ts,
673+ LogicalTime lt, bool force) {
661674 auto &f = get_file_map (id);
662675 auto it = f.find (id);
663676 if (it != f.end ()) {
664677 if (it->second .deleted ) {
665- return nullptr ;
678+ return td::Status::Error ( " file is deleted " ) ;
666679 }
667680 if (force && !id.temp ) {
668681 update_desc (f, it->second , shard, seqno, ts, lt);
669682 }
670683 return &it->second ;
671684 }
672685 if (!force) {
673- return nullptr ;
686+ return td::Status::Error ( " file not found " ) ;
674687 }
675688
676689 return add_file_desc (shard, id, seqno, ts, lt);
@@ -1186,13 +1199,9 @@ void ArchiveManager::get_archive_id(BlockSeqno masterchain_seqno, ShardIdFull sh
11861199void ArchiveManager::get_archive_slice (td::uint64 archive_id, td::uint64 offset, td::uint32 limit,
11871200 td::Promise<td::BufferSlice> promise) {
11881201 auto arch = static_cast <BlockSeqno>(archive_id);
1189- auto F = get_file_desc (ShardIdFull{masterchainId}, PackageId{arch, false , false }, 0 , 0 , 0 , false );
1190- if (!F) {
1191- promise.set_error (td::Status::Error (ErrorCode::notready, " archive not found" ));
1192- return ;
1193- }
1194-
1195- td::actor::send_closure (F->file_actor_id (), &ArchiveSlice::get_slice, archive_id, offset, limit, std::move (promise));
1202+ TRY_RESULT_PROMISE (promise, f,
1203+ get_file_desc (ShardIdFull{masterchainId}, PackageId{arch, false , false }, 0 , 0 , 0 , false ));
1204+ td::actor::send_closure (f->file_actor_id (), &ArchiveSlice::get_slice, archive_id, offset, limit, std::move (promise));
11961205}
11971206
11981207void ArchiveManager::commit_transaction () {
0 commit comments