private List<File> findNValidSnapshots(int n) throws IOException {
        List<File> files = Util.sortDataDir(snapDir.listFiles(),"snapshot", false);
        int count = 0;
        List<File> list = new ArrayList<File>();
        for (File f : files) {
            // we should catch the exceptions
            // from the valid snapshot and continue
            // until we find a valid one
            try {
                if (Util.isValidSnapshot(f)) {
                    list.add(f);
                    count++;
                    if (count == n) {
                        break;
                    }
                }
            } catch (IOException e) {
                LOG.info("invalid snapshot " + f, e);
            }
        }
        return list;
    }
private List < File > findNValidSnapshots ( int n ) throws IOException { List < File > files = Util . sortDataDir ( snapDir . listFiles ( ) , "snapshot" , false ) ; int count = 0 ; List < File > list = new ArrayList < File > ( ) ; for ( File f : files ) { try { if ( Util . isValidSnapshot ( f ) ) { list . add ( f ) ; count ++ ; if ( count == n ) { break ; } } } catch ( IOException e ) { LOG . info ( "invalid snapshot " + f , e ) ; } } return list ; }
find the last (maybe) valid n snapshots. this does some
minor checks on the validity of the snapshots. It just
checks for / at the end of the snapshot. This does
not mean that the snapshot is truly valid but is
valid with a high probability. also, the most recent
will be first on the list.
@param n the number of most recent snapshots
@return the last n snapshots (the number might be
less than n in case enough snapshots are not available).
@throws IOException