/// Reads states metadata file, returning an empty one if any errors occurs.
///
/// It's OK to miss some (or all) metadata entries as it will be re-computed
/// as part of the recovery procedure.
Reads states metadata file, returning an empty one if any errors occurs.
It's OK to miss some (or all) metadata entries as it will be re-computed
as part of the recovery procedure.
Reads states metadata file returning an empty one if any errors occurs . It ' s OK to miss some ( or all ) metadata entries as it will be re - computed as part of the recovery procedure .
fn load_metadata(log: &ReplicaLogger, path: &Path) -> PersistedStatesMetadata {
        use std::io::Read;
        let mut file = match OpenOptions::new().read(true).open(path) {
            Ok(file) => file,
            Err(io_err) if io_err.kind() == std::io::ErrorKind::NotFound => {
                return Default::default();
            }
            Err(io_err) => {
                error!(
                    log,
                    "Failed to open system metadata file {}: {}",
                    path.display(),
                    io_err
                );
                return Default::default();
            }
        };
        let mut buf = vec![];
        if let Err(e) = file.read_to_end(&mut buf) {
            warn!(
                log,
                "Failed to read metadata file {}: {}",
                path.display(),
                e
            );
            return Default::default();
        }
        match pb::StatesMetadata::decode(&buf[..]) {
            Ok(pb_meta) => {
                let mut map = StatesMetadata::new();
                for (h, pb) in pb_meta.by_height {
                    match StateMetadata::try_from(pb) {
                        Ok(meta) => {
                            map.insert(Height::new(h), meta);
                        }
                        Err(e) => {
                            warn!(log, "Failed to decode metadata for state {}: {}", h, e);
                        }
                    }
                }
                PersistedStatesMetadata {
                    by_height: map,
                    oldest_required_state: Height::new(pb_meta.oldest_required_state),
                }
            }
            Err(err) => {
                warn!(
                    log,
                    "Failed to deserialize states metadata at {}: {}",
                    path.display(),
                    err
                );
                Default::default()
            }
        }
    }
fn load_metadata ( log : & ReplicaLogger , path : & Path ) -> PersistedStatesMetadata { use std :: io :: Read ; let mut file = match OpenOptions :: new ( ) . read ( true ) . open ( path ) { Ok ( file ) => file , Err ( io_err ) if io_err . kind ( ) == std :: io :: ErrorKind :: NotFound => { return Default :: default ( ) ; } Err ( io_err ) => { error ! ( log " " path display ( ) io_err ) ; return Default :: default ( ) ; } } ; let mut buf = vec ! [ ] ; if let Err ( e ) = file . read_to_end ( & mut buf ) { warn ! ( log " " path display ( ) e ) ; return Default :: default ( ) ; } match pb :: StatesMetadata :: decode ( & buf [ .. ] ) { Ok ( pb_meta ) => { let mut map = StatesMetadata :: new ( ) ; for ( h , pb ) in pb_meta . by_height { match StateMetadata :: try_from ( pb ) { Ok ( meta ) => { map . insert ( Height :: new ( h ) , meta ) ; } Err ( e ) => { warn ! ( log " " h e ) ; } } } PersistedStatesMetadata { by_height : map , oldest_required_state : Height :: new ( pb_meta . oldest_required_state ) , } } Err ( err ) => { warn ! ( log " " path display ( ) err ) ; Default :: default ( ) } } }
Reads states metadata file, returning an empty one if any errors occurs.
Reads states metadata file returning an empty one if any errors occurs .
log
&ReplicaLogger
path
&Path