Bug:3260-Recovery misses flows installed on single node
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / SnapshotManager.java
index 847954816ccd33f1c916ead7641b57200e2303e2..9bbe285c29e863c885c88933c7f82fd7d739a704 100644 (file)
@@ -82,6 +82,10 @@ public class SnapshotManager implements SnapshotState {
         this.createSnapshotProcedure = createSnapshotProcedure;
     }
 
+    public long getLastSequenceNumber() {
+        return lastSequenceNumber;
+    }
+
     @VisibleForTesting
     public CaptureSnapshot getCaptureSnapshot() {
         return captureSnapshot;
@@ -201,14 +205,16 @@ public class SnapshotManager implements SnapshotState {
 
             LOG.debug("lastSequenceNumber prior to capture: {}", lastSequenceNumber);
 
+            SnapshotManager.this.currentState = CREATING;
+
             try {
                 createSnapshotProcedure.apply(null);
             } catch (Exception e) {
+                SnapshotManager.this.currentState = IDLE;
                 LOG.error("Error creating snapshot", e);
                 return false;
             }
 
-            SnapshotManager.this.currentState = CREATING;
             return true;
         }
 
@@ -317,6 +323,7 @@ public class SnapshotManager implements SnapshotState {
 
         @Override
         public void commit(long sequenceNumber) {
+            LOG.debug("Snapshot success sequence number:", sequenceNumber);
             context.getReplicatedLog().snapshotCommit();
             context.getPersistenceProvider().deleteSnapshots(new SnapshotSelectionCriteria(
                     sequenceNumber - context.getConfigParams().getSnapshotBatchCount(), 43200000));
@@ -363,6 +370,8 @@ public class SnapshotManager implements SnapshotState {
             this.term = -1L;
             if (!hasFollowers) {
                 if(lastLogEntry != null) {
+                    // since we have persisted the last-log-entry to persistent journal before the capture,
+                    // we would want to snapshot from this entry.
                     index = lastLogEntry.getIndex();
                     term = lastLogEntry.getTerm();
                 }