pub fn add_bank_snapshot<P: AsRef<Path>>(
    bank_snapshots_dir: P,
    bank: &Bank,
    snapshot_storages: &[SnapshotStorage],
    snapshot_version: SnapshotVersion,
) -> Result<BankSnapshotInfo> {
    let slot = bank.slot();
    // bank_snapshots_dir/slot
    let bank_snapshots_dir = get_bank_snapshots_dir(bank_snapshots_dir, slot);
    fs::create_dir_all(&bank_snapshots_dir)?;

    // the bank snapshot is stored as bank_snapshots_dir/slot/slot
    let snapshot_bank_file_path = bank_snapshots_dir.join(get_snapshot_file_name(slot));
    info!(
        "Creating snapshot for slot {}, path: {:?}",
        slot, snapshot_bank_file_path,
    );

    let mut bank_serialize = Measure::start("bank-serialize-ms");
    let bank_snapshot_serializer = move |stream: &mut BufWriter<File>| -> Result<()> {
        let serde_style = match snapshot_version {
            SnapshotVersion::V1_2_0 => SerdeStyle::Newer,
        };
        bank_to_stream(serde_style, stream.by_ref(), bank, snapshot_storages)?;
        Ok(())
    };
    let consumed_size =
        serialize_snapshot_data_file(&snapshot_bank_file_path, bank_snapshot_serializer)?;
    bank_serialize.stop();

    // Monitor sizes because they're capped to MAX_SNAPSHOT_DATA_FILE_SIZE
    datapoint_info!(
        "snapshot-bank-file",
        ("slot", slot, i64),
        ("size", consumed_size, i64)
    );

    inc_new_counter_info!("bank-serialize-ms", bank_serialize.as_ms() as usize);

    info!(
        "{} for slot {} at {:?}",
        bank_serialize, slot, snapshot_bank_file_path,
    );

    Ok(BankSnapshotInfo {
        slot,
        snapshot_path: snapshot_bank_file_path,
    })
}
/// Serialize a bank to a snapshot
Serialize a bank to a snapshot
Serialize a bank to a snapshot
pub fn add_bank_snapshot<P: AsRef<Path>>(
    bank_snapshots_dir: P,
    bank: &Bank,
    snapshot_storages: &[SnapshotStorage],
    snapshot_version: SnapshotVersion,
) -> Result<BankSnapshotInfo> {
    let slot = bank.slot();
    // bank_snapshots_dir/slot
    let bank_snapshots_dir = get_bank_snapshots_dir(bank_snapshots_dir, slot);
    fs::create_dir_all(&bank_snapshots_dir)?;
    // the bank snapshot is stored as bank_snapshots_dir/slot/slot
    let snapshot_bank_file_path = bank_snapshots_dir.join(get_snapshot_file_name(slot));
    info!(
        "Creating snapshot for slot {}, path: {:?}",
        slot, snapshot_bank_file_path,
    );
    let mut bank_serialize = Measure::start("bank-serialize-ms");
    let bank_snapshot_serializer = move |stream: &mut BufWriter<File>| -> Result<()> {
        let serde_style = match snapshot_version {
            SnapshotVersion::V1_2_0 => SerdeStyle::Newer,
        };
        bank_to_stream(serde_style, stream.by_ref(), bank, snapshot_storages)?;
        Ok(())
    };
    let consumed_size =
        serialize_snapshot_data_file(&snapshot_bank_file_path, bank_snapshot_serializer)?;
    bank_serialize.stop();
    // Monitor sizes because they're capped to MAX_SNAPSHOT_DATA_FILE_SIZE
    datapoint_info!(
        "snapshot-bank-file",
        ("slot", slot, i64),
        ("size", consumed_size, i64)
    );
    inc_new_counter_info!("bank-serialize-ms", bank_serialize.as_ms() as usize);
    info!(
        "{} for slot {} at {:?}",
        bank_serialize, slot, snapshot_bank_file_path,
    );
    Ok(BankSnapshotInfo {
        slot,
        snapshot_path: snapshot_bank_file_path,
    })
}
pub fn add_bank_snapshot < P : AsRef < Path > > ( bank_snapshots_dir : P , bank : & Bank , snapshot_storages : & [ SnapshotStorage ] , snapshot_version : SnapshotVersion , ) -> Result < BankSnapshotInfo > { let slot = bank . slot ( ) ; // bank_snapshots_dir/slot let bank_snapshots_dir = get_bank_snapshots_dir ( bank_snapshots_dir , slot ) ; fs :: create_dir_all ( & bank_snapshots_dir ) ? ; // the bank snapshot is stored as bank_snapshots_dir/slot/slot let snapshot_bank_file_path = bank_snapshots_dir . join ( get_snapshot_file_name ( slot ) ) ; info ! ( " " slot snapshot_bank_file_path ) ; let mut bank_serialize = Measure :: start ( " " ) ; let bank_snapshot_serializer = move | stream : & mut BufWriter < File > | -> Result < ( ) > { let serde_style = match snapshot_version { SnapshotVersion :: V1_2_0 => SerdeStyle :: Newer , } ; bank_to_stream ( serde_style , stream . by_ref ( ) , bank , snapshot_storages ) ? ; Ok ( ( ) ) } ; let consumed_size = serialize_snapshot_data_file ( & snapshot_bank_file_path , bank_snapshot_serializer ) ? ; bank_serialize . stop ( ) ; // Monitor sizes because they're capped to MAX_SNAPSHOT_DATA_FILE_SIZE datapoint_info ! ( " " ( " " slot i64 ) ( " " consumed_size i64 ) ) ; inc_new_counter_info ! ( " " bank_serialize as_ms ( ) as usize ) ; info ! ( " " bank_serialize slot snapshot_bank_file_path ) ; Ok ( BankSnapshotInfo { slot , snapshot_path : snapshot_bank_file_path , } ) }
Serialize a bank to a snapshot
Serialize a bank to a snapshot
bank_snapshots_dir
P
bank
&Bank
snapshot_storages
&[SnapshotStorage]
snapshot_version
SnapshotVersion