- public void commit(DataPersistenceProvider persistenceProvider, long sequenceNumber) {
- context.getReplicatedLog().snapshotCommit();
- persistenceProvider.deleteSnapshots(new SnapshotSelectionCriteria(
+ public void commit(long sequenceNumber, RaftActorBehavior currentBehavior) {
+ LOG.debug("Snapshot success sequence number: {}", sequenceNumber);
+
+ if(applySnapshot != null) {
+ try {
+ Snapshot snapshot = applySnapshot.getSnapshot();
+ applySnapshotProcedure.apply(snapshot.getState());
+
+ //clears the followers log, sets the snapshot index to ensure adjusted-index works
+ context.setReplicatedLog(ReplicatedLogImpl.newInstance(snapshot, context, currentBehavior));
+ context.setLastApplied(snapshot.getLastAppliedIndex());
+ context.setCommitIndex(snapshot.getLastAppliedIndex());
+
+ applySnapshot.getCallback().onSuccess();
+ } catch (Exception e) {
+ LOG.error("Error applying snapshot", e);
+ }
+ } else {
+ context.getReplicatedLog().snapshotCommit();
+ }
+
+ context.getPersistenceProvider().deleteSnapshots(new SnapshotSelectionCriteria(