@@ -126,7 +126,7 @@ impl InternalArtifactDownloader {
126
126
. immutables
127
127
. average_size_uncompressed ;
128
128
129
- let tasks = VecDeque :: from ( self . build_download_tasks_for_immutables (
129
+ let mut tasks = VecDeque :: from ( self . build_download_tasks_for_immutables (
130
130
immutable_locations,
131
131
immutable_file_number_range,
132
132
target_dir,
@@ -135,13 +135,12 @@ impl InternalArtifactDownloader {
135
135
) ?) ;
136
136
if download_unpack_options. include_ancillary {
137
137
let ancillary = & cardano_database_snapshot. ancillary ;
138
- self . download_unpack_ancillary_file (
138
+ tasks . push_back ( self . new_ancillary_download_task (
139
139
& ancillary. locations ,
140
- ancillary. size_uncompressed ,
141
140
target_dir,
141
+ ancillary. size_uncompressed ,
142
142
& download_id,
143
- )
144
- . await ?;
143
+ ) ?) ;
145
144
}
146
145
self . batch_download_unpack ( tasks, download_unpack_options. max_parallel_downloads )
147
146
. await ?;
@@ -290,6 +289,50 @@ impl InternalArtifactDownloader {
290
289
} )
291
290
}
292
291
292
+ fn new_ancillary_download_task (
293
+ & self ,
294
+ locations : & [ AncillaryLocation ] ,
295
+ ancillary_file_target_dir : & Path ,
296
+ size_uncompressed : u64 ,
297
+ download_id : & str ,
298
+ ) -> MithrilResult < DownloadTask > {
299
+ let mut locations_to_try = vec ! [ ] ;
300
+ let mut locations_sorted = locations. to_owned ( ) ;
301
+ locations_sorted. sort ( ) ;
302
+ for location in locations_sorted {
303
+ let location_to_try = match location {
304
+ AncillaryLocation :: CloudStorage {
305
+ uri,
306
+ compression_algorithm,
307
+ } => {
308
+ let file_downloader = self . http_file_downloader . clone ( ) ;
309
+ let file_downloader_uri = FileDownloaderUri :: from ( uri) ;
310
+
311
+ LocationToDownload {
312
+ file_downloader,
313
+ file_downloader_uri,
314
+ compression_algorithm : compression_algorithm. to_owned ( ) ,
315
+ }
316
+ }
317
+ AncillaryLocation :: Unknown => {
318
+ return Err ( anyhow ! ( "Unknown location type to download immutable" ) ) ;
319
+ }
320
+ } ;
321
+
322
+ locations_to_try. push ( location_to_try) ;
323
+ }
324
+
325
+ Ok ( DownloadTask {
326
+ name : "ancillary" . to_string ( ) ,
327
+ locations_to_try,
328
+ target_dir : ancillary_file_target_dir. to_path_buf ( ) ,
329
+ size_uncompressed,
330
+ download_event : DownloadEvent :: Ancillary {
331
+ download_id : download_id. to_string ( ) ,
332
+ } ,
333
+ } )
334
+ }
335
+
293
336
/// Download and unpack the files in parallel.
294
337
async fn batch_download_unpack (
295
338
& self ,
@@ -355,56 +398,6 @@ impl InternalArtifactDownloader {
355
398
356
399
Box :: pin ( download_future)
357
400
}
358
-
359
- /// Download and unpack the ancillary files.
360
- pub ( crate ) async fn download_unpack_ancillary_file (
361
- & self ,
362
- locations : & [ AncillaryLocation ] ,
363
- file_size : u64 ,
364
- ancillary_file_target_dir : & Path ,
365
- download_id : & str ,
366
- ) -> MithrilResult < ( ) > {
367
- let mut locations_sorted = locations. to_owned ( ) ;
368
- locations_sorted. sort ( ) ;
369
- for location in locations_sorted {
370
- let ( file_downloader, compression_algorithm) = match & location {
371
- AncillaryLocation :: CloudStorage {
372
- uri : _,
373
- compression_algorithm,
374
- } => ( self . http_file_downloader . clone ( ) , * compression_algorithm) ,
375
- AncillaryLocation :: Unknown => {
376
- continue ;
377
- }
378
- } ;
379
- let file_downloader_uri = location. try_into ( ) ?;
380
- let downloaded = file_downloader
381
- . download_unpack (
382
- & file_downloader_uri,
383
- file_size,
384
- ancillary_file_target_dir,
385
- compression_algorithm,
386
- DownloadEvent :: Ancillary {
387
- download_id : download_id. to_string ( ) ,
388
- } ,
389
- )
390
- . await ;
391
- match downloaded {
392
- Ok ( _) => {
393
- return Ok ( ( ) ) ;
394
- }
395
- Err ( e) => {
396
- slog:: error!(
397
- self . logger,
398
- "Failed downloading and unpacking ancillaries for location {file_downloader_uri:?}" ; "error" => ?e
399
- ) ;
400
- }
401
- }
402
- }
403
-
404
- Err ( anyhow ! (
405
- "Failed downloading and unpacking ancillaries for all locations"
406
- ) )
407
- }
408
401
}
409
402
410
403
#[ cfg( test) ]
@@ -992,38 +985,44 @@ mod tests {
992
985
test_utils:: test_logger ( ) ,
993
986
) ;
994
987
995
- artifact_downloader
996
- . download_unpack_ancillary_file (
988
+ let task = artifact_downloader
989
+ . new_ancillary_download_task (
997
990
& [ AncillaryLocation :: CloudStorage {
998
991
uri : "http://whatever-1/ancillary.tar.gz" . to_string ( ) ,
999
992
compression_algorithm : Some ( CompressionAlgorithm :: default ( ) ) ,
1000
993
} ] ,
1001
- 0 ,
1002
994
target_dir,
995
+ 0 ,
1003
996
"download_id" ,
1004
997
)
998
+ . unwrap ( ) ;
999
+
1000
+ artifact_downloader
1001
+ . batch_download_unpack ( vec ! [ task] . into ( ) , 1 )
1005
1002
. await
1006
- . expect_err ( "download_unpack_ancillary_file should fail" ) ;
1003
+ . expect_err ( "batch_download_unpack of ancillary file should fail" ) ;
1007
1004
}
1008
1005
1009
1006
#[ tokio:: test]
1010
- async fn download_unpack_ancillary_files_fails_if_location_is_unknown ( ) {
1007
+ async fn building_ancillary_download_task_fails_if_location_is_unknown ( ) {
1011
1008
let target_dir = Path :: new ( "." ) ;
1012
1009
let artifact_downloader = InternalArtifactDownloader :: new (
1013
1010
Arc :: new ( MockFileDownloader :: new ( ) ) ,
1014
1011
FeedbackSender :: new ( & [ ] ) ,
1015
1012
test_utils:: test_logger ( ) ,
1016
1013
) ;
1017
1014
1018
- artifact_downloader
1019
- . download_unpack_ancillary_file (
1020
- & [ AncillaryLocation :: Unknown { } ] ,
1021
- 0 ,
1022
- target_dir,
1023
- "download_id" ,
1024
- )
1025
- . await
1026
- . expect_err ( "download_unpack_ancillary_file should fail" ) ;
1015
+ let build_tasks_result = artifact_downloader. new_ancillary_download_task (
1016
+ & [ AncillaryLocation :: Unknown { } ] ,
1017
+ target_dir,
1018
+ 0 ,
1019
+ "download_id" ,
1020
+ ) ;
1021
+
1022
+ assert ! (
1023
+ build_tasks_result. is_err( ) ,
1024
+ "building tasks should fail if a location is unknown"
1025
+ ) ;
1027
1026
}
1028
1027
1029
1028
#[ tokio:: test]
@@ -1045,8 +1044,8 @@ mod tests {
1045
1044
test_utils:: test_logger ( ) ,
1046
1045
) ;
1047
1046
1048
- artifact_downloader
1049
- . download_unpack_ancillary_file (
1047
+ let task = artifact_downloader
1048
+ . new_ancillary_download_task (
1050
1049
& [
1051
1050
AncillaryLocation :: CloudStorage {
1052
1051
uri : "http://whatever-1/ancillary.tar.gz" . to_string ( ) ,
@@ -1057,10 +1056,14 @@ mod tests {
1057
1056
compression_algorithm : Some ( CompressionAlgorithm :: default ( ) ) ,
1058
1057
} ,
1059
1058
] ,
1060
- 0 ,
1061
1059
target_dir,
1060
+ 0 ,
1062
1061
"download_id" ,
1063
1062
)
1063
+ . unwrap ( ) ;
1064
+
1065
+ artifact_downloader
1066
+ . batch_download_unpack ( vec ! [ task] . into ( ) , 1 )
1064
1067
. await
1065
1068
. unwrap ( ) ;
1066
1069
}
@@ -1080,8 +1083,8 @@ mod tests {
1080
1083
test_utils:: test_logger ( ) ,
1081
1084
) ;
1082
1085
1083
- artifact_downloader
1084
- . download_unpack_ancillary_file (
1086
+ let task = artifact_downloader
1087
+ . new_ancillary_download_task (
1085
1088
& [
1086
1089
AncillaryLocation :: CloudStorage {
1087
1090
uri : "http://whatever-1/ancillary.tar.gz" . to_string ( ) ,
@@ -1092,10 +1095,14 @@ mod tests {
1092
1095
compression_algorithm : Some ( CompressionAlgorithm :: default ( ) ) ,
1093
1096
} ,
1094
1097
] ,
1095
- 0 ,
1096
1098
target_dir,
1099
+ 0 ,
1097
1100
"download_id" ,
1098
1101
)
1102
+ . unwrap ( ) ;
1103
+
1104
+ artifact_downloader
1105
+ . batch_download_unpack ( vec ! [ task] . into ( ) , 1 )
1099
1106
. await
1100
1107
. unwrap ( ) ;
1101
1108
}
0 commit comments