X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FRaftActorSnapshotMessageSupport.java;h=bf0fc10aad944ae8539c8b3b2a4da70020500944;hp=cab76e90ce69756f084668bd3f695c12a9a71012;hb=3fda1a923defdbf18849c6080c3aa19f1ebf2c5f;hpb=2727bea09c83646b6cbd2ef9672d0b7f6cf3b22f diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotMessageSupport.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotMessageSupport.java index cab76e90ce..bf0fc10aad 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotMessageSupport.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotMessageSupport.java @@ -30,11 +30,18 @@ class RaftActorSnapshotMessageSupport { private final Procedure createSnapshotProcedure = new Procedure() { @Override - public void apply(Void notUsed) throws Exception { + public void apply(Void notUsed) { cohort.createSnapshot(context.getActor()); } }; + private final Procedure applySnapshotProcedure = new Procedure() { + @Override + public void apply(byte[] state) { + cohort.applySnapshot(state); + } + }; + RaftActorSnapshotMessageSupport(RaftActorContext context, RaftActorBehavior currentBehavior, RaftActorSnapshotCohort cohort) { this.context = context; @@ -43,11 +50,12 @@ class RaftActorSnapshotMessageSupport { this.log = context.getLogger(); context.getSnapshotManager().setCreateSnapshotCallable(createSnapshotProcedure); + context.getSnapshotManager().setApplySnapshotProcedure(applySnapshotProcedure); } boolean handleSnapshotMessage(Object message) { if(message instanceof ApplySnapshot ) { - onApplySnapshot(((ApplySnapshot) message).getSnapshot()); + onApplySnapshot((ApplySnapshot) message); return true; } else if (message instanceof SaveSnapshotSuccess) { onSaveSnapshotSuccess((SaveSnapshotSuccess) message); @@ -59,7 +67,7 @@ class RaftActorSnapshotMessageSupport { onCaptureSnapshotReply(((CaptureSnapshotReply) message).getSnapshot()); return true; } else if (message.equals(COMMIT_SNAPSHOT)) { - context.getSnapshotManager().commit(-1); + context.getSnapshotManager().commit(-1, currentBehavior); return true; } else { return false; @@ -84,20 +92,13 @@ class RaftActorSnapshotMessageSupport { long sequenceNumber = success.metadata().sequenceNr(); - context.getSnapshotManager().commit(sequenceNumber); + context.getSnapshotManager().commit(sequenceNumber, currentBehavior); } - private void onApplySnapshot(Snapshot snapshot) { - if(log.isDebugEnabled()) { - log.debug("{}: ApplySnapshot called on Follower Actor " + - "snapshotIndex:{}, snapshotTerm:{}", context.getId(), snapshot.getLastAppliedIndex(), - snapshot.getLastAppliedTerm()); - } - - cohort.applySnapshot(snapshot.getState()); + private void onApplySnapshot(ApplySnapshot message) { + log.info("{}: Applying snapshot on follower with snapshotIndex: {}, snapshotTerm: {}", context.getId(), + message.getSnapshot().getLastAppliedIndex(), message.getSnapshot().getLastAppliedTerm()); - //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.getSnapshotManager().apply(message); } }