package org.opendaylight.controller.cluster.raft;
import akka.actor.ActorRef;
-import akka.japi.Procedure;
import akka.persistence.SaveSnapshotFailure;
import akka.persistence.SaveSnapshotSuccess;
import com.google.common.annotations.VisibleForTesting;
private final RaftActorSnapshotCohort cohort;
private final Logger log;
- private final Procedure<Void> createSnapshotProcedure = new Procedure<Void>() {
- @Override
- public void apply(Void notUsed) {
- cohort.createSnapshot(context.getActor());
- }
- };
-
- private final Procedure<byte[]> applySnapshotProcedure = new Procedure<byte[]>() {
- @Override
- public void apply(byte[] state) {
- cohort.applySnapshot(state);
- }
- };
-
private Duration snapshotReplyActorTimeout = Duration.create(30, TimeUnit.SECONDS);
RaftActorSnapshotMessageSupport(final RaftActorContext context, final RaftActorSnapshotCohort cohort) {
this.cohort = cohort;
this.log = context.getLogger();
- context.getSnapshotManager().setCreateSnapshotCallable(createSnapshotProcedure);
- context.getSnapshotManager().setApplySnapshotProcedure(applySnapshotProcedure);
+ context.getSnapshotManager().setCreateSnapshotRunnable(() -> cohort.createSnapshot(context.getActor()));
+ context.getSnapshotManager().setApplySnapshotConsumer(cohort::applySnapshot);
}
boolean handleSnapshotMessage(Object message, ActorRef sender) {
} else if (message instanceof CaptureSnapshotReply) {
onCaptureSnapshotReply(((CaptureSnapshotReply) message).getSnapshot());
} else if (COMMIT_SNAPSHOT.equals(message)) {
- context.getSnapshotManager().commit(-1);
+ context.getSnapshotManager().commit(-1, -1);
} else if (message instanceof GetSnapshot) {
onGetSnapshot(sender);
} else {
}
private void onSaveSnapshotSuccess(SaveSnapshotSuccess success) {
- log.info("{}: SaveSnapshotSuccess received for snapshot", context.getId());
-
long sequenceNumber = success.metadata().sequenceNr();
- context.getSnapshotManager().commit(sequenceNumber);
+ log.info("{}: SaveSnapshotSuccess received for snapshot, sequenceNr: {}", context.getId(), sequenceNumber);
+
+ context.getSnapshotManager().commit(sequenceNumber, success.metadata().timestamp());
}
private void onApplySnapshot(ApplySnapshot message) {
- log.info("{}: Applying snapshot on follower with snapshotIndex: {}, snapshotTerm: {}", context.getId(),
- message.getSnapshot().getLastAppliedIndex(), message.getSnapshot().getLastAppliedTerm());
+ log.info("{}: Applying snapshot on follower: {}", context.getId(), message.getSnapshot());
context.getSnapshotManager().apply(message);
}