/// Computes manifest for the checkpoint located at `checkpoint_root_path`.
Computes manifest for the checkpoint located at `checkpoint_root_path`.
Computes manifest for the checkpoint located at ` checkpoint_root_path ` .
pub fn compute_manifest(
    thread_pool: &mut scoped_threadpool::Pool,
    metrics: &ManifestMetrics,
    log: &ReplicaLogger,
    version: u32,
    checkpoint_root_path: &Path,
    max_chunk_size: u32,
    opt_manifest_delta: Option<ManifestDelta>,
) -> Result<Manifest, CheckpointError> {
    let mut files = Vec::new();
    files_with_sizes(checkpoint_root_path, "".into(), &mut files)?;
    // We sort the table to make sure that the table is the same on all replicas
    files.sort_unstable_by(|lhs, rhs| lhs.0.cmp(&rhs.0));
    let chunk_actions = match opt_manifest_delta {
        Some(manifest_delta) => {
            // We have to check that the old manifest uses exactly the same chunk size.
            // Otherwise, if someone decides to change the chunk size in future,
            // all the tests are going to pass (because all of them will use the
            // new chunk size), but the manifest might be computed incorrectly
            // on the mainnet.
            if uses_chunk_size(&manifest_delta.base_manifest, max_chunk_size) {
                let dirty_file_chunks = dirty_pages_to_dirty_chunks(
                    &manifest_delta,
                    checkpoint_root_path,
                    &files,
                    max_chunk_size,
                )?;
                hash_plan(
                    &manifest_delta.base_manifest,
                    &files,
                    dirty_file_chunks,
                    max_chunk_size,
                    manifest_delta.target_height.get(),
                    REHASH_EVERY_NTH_CHUNK,
                )
            } else {
                default_hash_plan(&files, max_chunk_size)
            }
        }
        None => default_hash_plan(&files, max_chunk_size),
    };
    if files
        .iter()
        .any(|FileWithSize(path, _)| path.ends_with("state_file"))
    {
        // The parallel algorithm doesn't handle COW memory manager, which is a subject
        // for removal anyway.
        let (file_table, chunk_table) = build_chunk_table_sequential(
            metrics,
            log,
            checkpoint_root_path,
            files,
            max_chunk_size,
            chunk_actions,
        );
        Ok(Manifest {
            version,
            file_table,
            chunk_table,
        })
    } else {
        #[cfg(debug_assertions)]
        let (seq_file_table, seq_chunk_table) = {
            let metrics_registry = ic_metrics::MetricsRegistry::new();
            let metrics = ManifestMetrics::new(&metrics_registry);
            build_chunk_table_sequential(
                &metrics,
                log,
                checkpoint_root_path,
                files.clone(),
                max_chunk_size,
                chunk_actions.clone(),
            )
        };
        let (file_table, chunk_table) = build_chunk_table_parallel(
            thread_pool,
            metrics,
            log,
            checkpoint_root_path,
            files,
            max_chunk_size,
            chunk_actions,
        );
        #[cfg(debug_assertions)]
        {
            assert_eq!(file_table, seq_file_table);
            assert_eq!(chunk_table, seq_chunk_table);
        }
        Ok(Manifest {
            version,
            file_table,
            chunk_table,
        })
    }
}
pub fn compute_manifest ( thread_pool : & mut scoped_threadpool :: Pool , metrics : & ManifestMetrics , log : & ReplicaLogger , version : u32 , checkpoint_root_path : & Path , max_chunk_size : u32 , opt_manifest_delta : Option < ManifestDelta > , ) -> Result < Manifest , CheckpointError > { let mut files = Vec :: new ( ) ; files_with_sizes ( checkpoint_root_path , " " . into ( ) , & mut files ) ? ; // We sort the table to make sure that the table is the same on all replicas files . sort_unstable_by ( | lhs , rhs | lhs . 0 . cmp ( & rhs . 0 ) ) ; let chunk_actions = match opt_manifest_delta { Some ( manifest_delta ) => { // We have to check that the old manifest uses exactly the same chunk size. // Otherwise, if someone decides to change the chunk size in future, // all the tests are going to pass (because all of them will use the // new chunk size), but the manifest might be computed incorrectly // on the mainnet. if uses_chunk_size ( & manifest_delta . base_manifest , max_chunk_size ) { let dirty_file_chunks = dirty_pages_to_dirty_chunks ( & manifest_delta , checkpoint_root_path , & files , max_chunk_size , ) ? ; hash_plan ( & manifest_delta . base_manifest , & files , dirty_file_chunks , max_chunk_size , manifest_delta . target_height . get ( ) , REHASH_EVERY_NTH_CHUNK , ) } else { default_hash_plan ( & files , max_chunk_size ) } } None => default_hash_plan ( & files , max_chunk_size ) , } ; if files . iter ( ) . any ( | FileWithSize ( path , _ ) | path . ends_with ( " " ) ) { // The parallel algorithm doesn't handle COW memory manager, which is a subject // for removal anyway. let ( file_table , chunk_table ) = build_chunk_table_sequential ( metrics , log , checkpoint_root_path , files , max_chunk_size , chunk_actions , ) ; Ok ( Manifest { version , file_table , chunk_table , } ) } else { # [ cfg ( debug_assertions ) ] let ( seq_file_table , seq_chunk_table ) = { let metrics_registry = ic_metrics :: MetricsRegistry :: new ( ) ; let metrics = ManifestMetrics :: new ( & metrics_registry ) ; build_chunk_table_sequential ( & metrics , log , checkpoint_root_path , files . clone ( ) , max_chunk_size , chunk_actions . clone ( ) , ) } ; let ( file_table , chunk_table ) = build_chunk_table_parallel ( thread_pool , metrics , log , checkpoint_root_path , files , max_chunk_size , chunk_actions , ) ; # [ cfg ( debug_assertions ) ] { assert_eq ! ( file_table seq_file_table ) ; assert_eq ! ( chunk_table seq_chunk_table ) ; } Ok ( Manifest { version , file_table , chunk_table , } ) } }
Computes manifest for the checkpoint located at `checkpoint_root_path`.
Computes manifest for the checkpoint located at ` checkpoint_root_path ` .
thread_pool
&mut scoped_threadpool::Pool
metrics
&ManifestMetrics
log
&ReplicaLogger
version
u32
checkpoint_root_path
&Path
max_chunk_size
u32
opt_manifest_delta
Option<ManifestDelta>