@Test public void shouldCleanUpPendingDirOnFailingTakeSnapshot() { final var index = 1L; final var term = 0L; final var oldTransientSnapshot = persistedSnapshotStore.newTransientSnapshot(index, term, 1, 0).orElseThrow(); oldTransientSnapshot.take( path -> { try { FileUtil.ensureDirectoryExists(path); } catch (final IOException e) { throw new UncheckedIOException(e); } return false; }); assertThat(pendingSnapshotsDir.toFile().listFiles()).isEmpty(); assertThat(snapshotsDir.toFile().listFiles()).isEmpty(); }
@Override public boolean take(final Predicate<Path> takeSnapshot) { final var snapshotMetrics = snapshotStore.getSnapshotMetrics(); boolean failed; try (final var ignored = snapshotMetrics.startTimer()) { try { failed = !takeSnapshot.test(getPath()); } catch (final Exception exception) { LOGGER.warn("Catched unexpected exception on taking snapshot ({})", metadata, exception); failed = true; } } if (failed) { abort(); } return !failed; }
FileBasedTransientSnapshot implements TransientSnapshot { @Override public boolean take(final Predicate<Path> takeSnapshot) { final var snapshotMetrics = snapshotStore.getSnapshotMetrics(); boolean failed; try (final var ignored = snapshotMetrics.startTimer()) { try { failed = !takeSnapshot.test(getPath()); } catch (final Exception exception) { LOGGER.warn("Catched unexpected exception on taking snapshot ({})", metadata, exception); failed = true; } } if (failed) { abort(); } return !failed; } }
FileBasedTransientSnapshot implements TransientSnapshot { @Override public boolean take(final Predicate<Path> takeSnapshot) { final var snapshotMetrics = snapshotStore.getSnapshotMetrics(); boolean failed; try (final var ignored = snapshotMetrics.startTimer()) { try { failed = !takeSnapshot.test(getPath()); } catch (final Exception exception) { LOGGER.warn("Catched unexpected exception on taking snapshot ({})", metadata, exception); failed = true; } } if (failed) { abort(); } return !failed; } FileBasedTransientSnapshot(
      final FileBasedSnapshotMetadata metadata,
      final Path directory,
      final FileBasedSnapshotStore snapshotStore); }
FileBasedTransientSnapshot implements TransientSnapshot { @Override public boolean take(final Predicate<Path> takeSnapshot) { final var snapshotMetrics = snapshotStore.getSnapshotMetrics(); boolean failed; try (final var ignored = snapshotMetrics.startTimer()) { try { failed = !takeSnapshot.test(getPath()); } catch (final Exception exception) { LOGGER.warn("Catched unexpected exception on taking snapshot ({})", metadata, exception); failed = true; } } if (failed) { abort(); } return !failed; } FileBasedTransientSnapshot(
      final FileBasedSnapshotMetadata metadata,
      final Path directory,
      final FileBasedSnapshotStore snapshotStore); @Override boolean take(final Predicate<Path> takeSnapshot); @Override void abort(); @Override PersistedSnapshot persist(); Path getPath(); @Override String toString(); }
FileBasedTransientSnapshot implements TransientSnapshot { @Override public boolean take(final Predicate<Path> takeSnapshot) { final var snapshotMetrics = snapshotStore.getSnapshotMetrics(); boolean failed; try (final var ignored = snapshotMetrics.startTimer()) { try { failed = !takeSnapshot.test(getPath()); } catch (final Exception exception) { LOGGER.warn("Catched unexpected exception on taking snapshot ({})", metadata, exception); failed = true; } } if (failed) { abort(); } return !failed; } FileBasedTransientSnapshot(
      final FileBasedSnapshotMetadata metadata,
      final Path directory,
      final FileBasedSnapshotStore snapshotStore); @Override boolean take(final Predicate<Path> takeSnapshot); @Override void abort(); @Override PersistedSnapshot persist(); Path getPath(); @Override String toString();  }