private boolean exists(final StateSnapshotMetadata metadata) { return storage.getSnapshotDirectoryFor(metadata).exists(); }
private boolean exists(final StateSnapshotMetadata metadata) { return storage.getSnapshotDirectoryFor(metadata).exists(); }
@Override public void purgeAll(Predicate<StateSnapshotMetadata> matcher) throws Exception { final List<StateSnapshotMetadata> others = storage.list(matcher); for (final StateSnapshotMetadata other : others) { FileUtil.deleteFolder(storage.getSnapshotDirectoryFor(other).getAbsolutePath()); LOG.trace("Purged snapshot {}", other); } }
@Override public void purgeAll(Predicate<StateSnapshotMetadata> matcher) throws Exception { final List<StateSnapshotMetadata> others = storage.list(matcher); for (final StateSnapshotMetadata other : others) { FileUtil.deleteFolder(storage.getSnapshotDirectoryFor(other).getAbsolutePath()); LOG.trace("Purged snapshot {}", other); } }
@Override public void takeSnapshot(final StateSnapshotMetadata metadata) { if (db == null) { throw new IllegalStateException("Cannot create snapshot of not open database."); } if (exists(metadata)) { return; } final File snapshotDir = storage.getSnapshotDirectoryFor(metadata); db.createSnapshot(snapshotDir); }
@Override public void takeSnapshot(final StateSnapshotMetadata metadata) { if (db == null) { throw new IllegalStateException("Cannot create snapshot of not open database."); } if (exists(metadata)) { return; } final File snapshotDir = storage.getSnapshotDirectoryFor(metadata); db.createSnapshot(snapshotDir); }
@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; }