private InputStream getLatestSnapshotInputStream() throws IOException { TimestampedFilename[] snapshots = listSnapshotFiles(); Arrays.sort(snapshots); if (snapshots.length > 0) { // last is the most recent return fs.open(snapshots[snapshots.length - 1].getPath(), BUFFER_SIZE); } LOG.info("No snapshot files found in {}", snapshotDir); return null; }
private InputStream getLatestSnapshotInputStream() throws IOException { TimestampedFilename[] snapshots = listSnapshotFiles(); Arrays.sort(snapshots); if (snapshots.length > 0) { // last is the most recent return fs.open(snapshots[snapshots.length - 1].getPath(), BUFFER_SIZE); } LOG.info("No snapshot files found in {}", snapshotDir); return null; }
@Override public long deleteOldSnapshots(int numberToKeep) throws IOException { TimestampedFilename[] snapshots = listSnapshotFiles(); if (snapshots.length == 0) { return -1; } Arrays.sort(snapshots, Collections.reverseOrder()); if (snapshots.length <= numberToKeep) { // nothing to remove, oldest timestamp is the last snapshot return snapshots[snapshots.length - 1].getTimestamp(); } int toRemoveCount = snapshots.length - numberToKeep; TimestampedFilename[] toRemove = new TimestampedFilename[toRemoveCount]; System.arraycopy(snapshots, numberToKeep, toRemove, 0, toRemoveCount); for (TimestampedFilename f : toRemove) { LOG.debug("Removing old snapshot file {}", f.getPath()); fs.delete(f.getPath(), false); } long oldestTimestamp = snapshots[numberToKeep - 1].getTimestamp(); LOG.debug("Removed {} old snapshot files prior to {}", toRemoveCount, oldestTimestamp); return oldestTimestamp; }
@Override public long deleteOldSnapshots(int numberToKeep) throws IOException { TimestampedFilename[] snapshots = listSnapshotFiles(); if (snapshots.length == 0) { return -1; } Arrays.sort(snapshots, Collections.reverseOrder()); if (snapshots.length <= numberToKeep) { // nothing to remove, oldest timestamp is the last snapshot return snapshots[snapshots.length - 1].getTimestamp(); } int toRemoveCount = snapshots.length - numberToKeep; TimestampedFilename[] toRemove = new TimestampedFilename[toRemoveCount]; System.arraycopy(snapshots, numberToKeep, toRemove, 0, toRemoveCount); for (TimestampedFilename f : toRemove) { LOG.debug("Removing old snapshot file {}", f.getPath()); fs.delete(f.getPath(), false); } long oldestTimestamp = snapshots[numberToKeep - 1].getTimestamp(); LOG.debug("Removed {} old snapshot files prior to {}", toRemoveCount, oldestTimestamp); return oldestTimestamp; }