@Override public StateSnapshotMetadata recover( long commitPosition, int term, Predicate<StateSnapshotMetadata> filter) throws Exception { final File runtimeDirectory = storage.getRuntimeDirectory(); final List<StateSnapshotMetadata> snapshots = storage.listRecoverable(commitPosition); StateSnapshotMetadata recoveredMetadata = null; if (!snapshots.isEmpty()) { recoveredMetadata = snapshots.stream() .sorted(Comparator.reverseOrder()) .filter(filter) .findFirst() .orElse(null); } if (runtimeDirectory.exists()) { FileUtil.deleteFolder(runtimeDirectory.getAbsolutePath()); } if (recoveredMetadata != null) { final File snapshotPath = storage.getSnapshotDirectoryFor(recoveredMetadata); copySnapshot(runtimeDirectory, snapshotPath); } else { recoveredMetadata = StateSnapshotMetadata.createInitial(term); } return recoveredMetadata; }
@Override public StateSnapshotMetadata recover( long commitPosition, int term, Predicate<StateSnapshotMetadata> filter) throws Exception { final File runtimeDirectory = storage.getRuntimeDirectory(); final List<StateSnapshotMetadata> snapshots = storage.listRecoverable(commitPosition); StateSnapshotMetadata recoveredMetadata = null; if (!snapshots.isEmpty()) { recoveredMetadata = snapshots.stream() .sorted(Comparator.reverseOrder()) .filter(filter) .findFirst() .orElse(null); } if (runtimeDirectory.exists()) { FileUtil.deleteFolder(runtimeDirectory.getAbsolutePath()); } if (recoveredMetadata != null) { final File snapshotPath = storage.getSnapshotDirectoryFor(recoveredMetadata); copySnapshot(runtimeDirectory, snapshotPath); } else { recoveredMetadata = StateSnapshotMetadata.createInitial(term); } return recoveredMetadata; }