private Collection < Snapshot > loadSnapshots ( ) { // Ensure log directories are created. storage . directory ( ) . mkdirs ( ) ; List < Snapshot > snapshots = new ArrayList <> ( ) ; // Iterate through all files in the log directory. for ( File file : storage . directory ( ) . listFiles ( File :: isFile ) ) { // If the file looks like a segment file, attempt to load the segment. if ( SnapshotFile . isSnapshotFile ( file ) ) { SnapshotFile snapshotFile = new SnapshotFile ( file ) ; SnapshotDescriptor descriptor = new SnapshotDescriptor ( FileBuffer . allocate ( file , SnapshotDescriptor . BYTES ) ) ; // Valid segments will have been locked. Segments that resulting from failures during log cleaning will be // unlocked and should ultimately be deleted from disk. if ( descriptor . isLocked ( ) ) { log . debug ( "Loaded disk snapshot: {} ({})" , descriptor . index ( ) , snapshotFile . file ( ) . getName ( ) ) ; snapshots . add ( new FileSnapshot ( snapshotFile , descriptor , this ) ) ; descriptor . close ( ) ; } // If the segment descriptor wasn't locked, close and delete the descriptor. else { log . debug ( "Deleting partial snapshot: {} ({})" , descriptor . index ( ) , snapshotFile . file ( ) . getName ( ) ) ; descriptor . close ( ) ; descriptor . delete ( ) ; } } } return snapshots ; }
Loads all available snapshots from disk .