@@ -14,9 +14,8 @@ use std::{
14
14
15
15
use anyhow:: { anyhow, bail} ;
16
16
use async_trait:: async_trait;
17
- use catalyst_types:: conversion:: from_saturating;
17
+ use catalyst_types:: { conversion:: from_saturating, mmap_file :: MemoryMapFile } ;
18
18
use dashmap:: DashSet ;
19
- use fmmap:: MmapFileExt ;
20
19
use memx:: memcmp;
21
20
use mithril_client:: {
22
21
common:: CompressionAlgorithm , snapshot_downloader:: SnapshotDownloader , MithrilResult ,
@@ -134,8 +133,7 @@ impl Inner {
134
133
self . ext_size . fetch_add ( entry_size, Ordering :: SeqCst ) ;
135
134
136
135
// Try and deduplicate the file if we can, otherwise just extract it.
137
- if let Ok ( ( prev_mmap, _) ) =
138
- Self :: can_deduplicate ( & rel_file, entry_size, prev_file. as_ref ( ) )
136
+ if let Ok ( prev_mmap) = Self :: can_deduplicate ( & rel_file, entry_size, prev_file. as_ref ( ) )
139
137
{
140
138
let expected_file_size = from_saturating ( entry_size) ;
141
139
let mut buf: Vec < u8 > = Vec :: with_capacity ( expected_file_size) ;
@@ -225,7 +223,7 @@ impl Inner {
225
223
/// Check if a given path from the archive is able to be deduplicated.
226
224
fn can_deduplicate (
227
225
rel_file : & Path , file_size : u64 , prev_file : Option < & PathBuf > ,
228
- ) -> MithrilResult < ( fmmap :: MmapFile , u64 ) > {
226
+ ) -> MithrilResult < MemoryMapFile > {
229
227
// Can't dedup if the current file is not de-dupable (must be immutable)
230
228
if rel_file. starts_with ( "immutable" ) {
231
229
// Can't dedup if we don't have a previous file to dedup against.
@@ -234,8 +232,8 @@ impl Inner {
234
232
// If the current file is not exactly the same as the previous file size, we
235
233
// can't dedup.
236
234
if file_size == current_size {
237
- if let Ok ( pref_file_loaded) = mmap_open_sync ( prev_file) {
238
- if pref_file_loaded. 1 == file_size {
235
+ if let Ok ( pref_file_loaded) = Self :: mmap_open_sync ( prev_file) {
236
+ if pref_file_loaded. size ( ) == file_size {
239
237
return Ok ( pref_file_loaded) ;
240
238
}
241
239
}
@@ -245,6 +243,17 @@ impl Inner {
245
243
}
246
244
bail ! ( "Can not deduplicate." ) ;
247
245
}
246
+
247
+ /// Open a file using mmap for performance.
248
+ fn mmap_open_sync ( path : & Path ) -> MithrilResult < MemoryMapFile > {
249
+ match MemoryMapFile :: try_from ( path) {
250
+ Ok ( mmap_file) => Ok ( mmap_file) ,
251
+ Err ( error) => {
252
+ error ! ( error=%error, file=%path. to_string_lossy( ) , "Failed to open file" ) ;
253
+ Err ( error. into ( ) )
254
+ } ,
255
+ }
256
+ }
248
257
}
249
258
250
259
/// A snapshot downloader that accelerates Download using `aria2`.
@@ -302,7 +311,17 @@ impl MithrilTurboDownloader {
302
311
let target_dir = target_dir. to_owned ( ) ;
303
312
304
313
// This is fully synchronous IO, so do it on a sync thread.
305
- let result = spawn_blocking ( move || inner. dl_and_dedup ( & location, & target_dir) ) . await ;
314
+ let result = spawn_blocking ( move || {
315
+ stats:: start_thread (
316
+ inner. cfg . chain ,
317
+ stats:: thread:: name:: MITHRIL_DL_DEDUP ,
318
+ false ,
319
+ ) ;
320
+ let result = inner. dl_and_dedup ( & location, & target_dir) ;
321
+ stats:: stop_thread ( inner. cfg . chain , stats:: thread:: name:: MITHRIL_DL_DEDUP ) ;
322
+ result
323
+ } )
324
+ . await ;
306
325
307
326
if let Ok ( result) = result {
308
327
return result;
@@ -321,20 +340,6 @@ fn get_file_size_sync(file: &Path) -> Option<u64> {
321
340
Some ( metadata. len ( ) )
322
341
}
323
342
324
- /// Open a file using mmap for performance.
325
- fn mmap_open_sync ( path : & Path ) -> MithrilResult < ( fmmap:: MmapFile , u64 ) > {
326
- match fmmap:: MmapFile :: open_with_options ( path, fmmap:: Options :: new ( ) . read ( true ) . populate ( ) ) {
327
- Ok ( file) => {
328
- let len = file. len ( ) as u64 ;
329
- Ok ( ( file, len) )
330
- } ,
331
- Err ( error) => {
332
- error ! ( error=%error, file=%path. to_string_lossy( ) , "Failed to open file" ) ;
333
- Err ( error. into ( ) )
334
- } ,
335
- }
336
- }
337
-
338
343
#[ async_trait]
339
344
impl SnapshotDownloader for MithrilTurboDownloader {
340
345
async fn download_unpack (
@@ -366,9 +371,9 @@ impl SnapshotDownloader for MithrilTurboDownloader {
366
371
367
372
async fn probe ( & self , location : & str ) -> MithrilResult < ( ) > {
368
373
debug ! ( "Probe Snapshot location='{location}'." ) ;
369
-
370
374
let dl_config = self . inner . cfg . dl_config . clone ( ) . unwrap_or_default ( ) ;
371
- let dl_processor = ParallelDownloadProcessor :: new ( location, dl_config) . await ?;
375
+ let dl_processor =
376
+ ParallelDownloadProcessor :: new ( location, dl_config, self . inner . cfg . chain ) . await ?;
372
377
373
378
// Decompress and extract and de-dupe each file in the archive.
374
379
stats:: mithril_extract_started ( self . inner . cfg . chain ) ;
0 commit comments