Source:
<code>public CompletableFuture<Long> takeSnapshot(long index) { CompletableFuture<Long> future = new CompletableFuture<>(); serviceExecutor.execute(() -> { if (currentIndex == 0) { return; } long snapshotIndex = Math.max(index, currentIndex); Snapshot currentSnapshot = raft.getSnapshotStore().getSnapshotById(serviceId); if (currentSnapshot != null && currentSnapshot.index() > index) { return; } log.debug("Taking snapshot {}", snapshotIndex); Snapshot snapshot = raft.getSnapshotStore() .newTemporarySnapshot(serviceId, serviceName, snapshotIndex, WallClockTimestamp.from(currentTimestamp)); PendingSnapshot pendingSnapshot = new PendingSnapshot(snapshot); pendingSnapshot.future.whenComplete((r, e) -> pendingSnapshots.remove(snapshotIndex)); try (SnapshotWriter writer = snapshot.openWriter()) { writer.writeLong(serviceId.id()); writer.writeString(serviceType.id()); writer.writeString(serviceName); writer.writeInt(sessions.getSessions().size()); for (RaftSessionContext session : sessions.getSessions()) { writer.writeLong(session.sessionId().id()); writer.writeString(session.memberId().id()); writer.writeString(session.readConsistency().name()); writer.writeLong(session.minTimeout()); writer.writeLong(session.maxTimeout()); writer.writeLong(session.getLastUpdated()); writer.writeLong(session.getRequestSequence()); writer.writeLong(session.getCommandSequence()); writer.writeLong(session.getEventIndex()); writer.writeLong(session.getLastCompleted()); } service.snapshot(writer); } catch (Exception e) { log.error("Snapshot failed: {}", e); } snapshotExecutor.execute(() -> { pendingSnapshot.persist(); <START> pendingSnapshots.put(snapshotIndex, pendingSnapshot); <END> future.complete(snapshotIndex); }); }); return future; }</code><technical_language>@kuujo persist if return of put is true</technical_language>

Target:
public CompletableFuture<Long> takeSnapshot(long index) { ComposableFuture<Long> future = new ComposableFuture<>(); serviceExecutor.execute(() -> { if (currentIndex == 0) { future.complete(currentIndex); return; } long snapshotIndex = Math.max(index, currentIndex); Snapshot existingSnapshot = raft.getSnapshotStore().getSnapshot(serviceId, snapshotIndex); if (existingSnapshot != null) { future.complete(snapshotIndex); return; } Snapshot currentSnapshot = raft.getSnapshotStore().getSnapshotById(serviceId); if (currentSnapshot != null && currentSnapshot.index() >= index) { future.complete(snapshotIndex); return; } Snapshot snapshot = raft.getSnapshotStore() .newTemporarySnapshot(serviceId, serviceName, snapshotIndex, WallClockTimestamp.from(currentTimestamp)); PendingSnapshot pendingSnapshot = new PendingSnapshot(snapshot); PendingSnapshot existingPendingSnapshot = pendingSnapshots.putIfAbsent(snapshotIndex, pendingSnapshot); if (existingPendingSnapshot != null) { existingPendingSnapshot.future.whenComplete(future); return; } pendingSnapshot.future.whenComplete((r, e) -> pendingSnapshots.remove(snapshotIndex)); log.debug("Taking snapshot {}", snapshotIndex); try (SnapshotWriter writer = snapshot.openWriter()) { writer.writeLong(serviceId.id()); writer.writeString(serviceType.id()); writer.writeString(serviceName); writer.writeInt(sessions.getSessions().size()); for (RaftSessionContext session : sessions.getSessions()) { writer.writeLong(session.sessionId().id()); writer.writeString(session.memberId().id()); writer.writeString(session.readConsistency().name()); writer.writeLong(session.minTimeout()); writer.writeLong(session.maxTimeout()); writer.writeLong(session.getLastUpdated()); writer.writeLong(session.getRequestSequence()); writer.writeLong(session.getCommandSequence()); writer.writeLong(session.getEventIndex()); writer.writeLong(session.getLastCompleted()); } service.snapshot(writer); } catch (Exception e) { log.error("Snapshot failed: {}", e); } snapshotExecutor.execute(() -> { pendingSnapshot.persist(); future.complete(snapshotIndex); }); }); return future; }