Bug 4564: Implement restore from snapshot in RaftActor
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / SnapshotManager.java
index 9571173175ff220aa3fb5b6b9ba757eee150ffe4..0d0c910298f7cee9975b1d460c762b603a7ff9a1 100644 (file)
@@ -387,12 +387,16 @@ public class SnapshotManager implements SnapshotState {
             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());
+                    context.getTermInformation().update(snapshot.getElectionTerm(), snapshot.getElectionVotedFor());
+
+                    if(snapshot.getState().length > 0 ) {
+                        applySnapshotProcedure.apply(snapshot.getState());
+                    }
 
                     applySnapshot.getCallback().onSuccess();
                 } catch (Exception e) {