Bug 2461 : Adding capture snapshot JMX operation.
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / SnapshotManager.java
index 970fb8fc717c2b6d918c2e815fb9ef2b323a39fb..4c3fb109add982c9f2d5590d524d20dfbf7ea7b7 100644 (file)
@@ -211,8 +211,18 @@ public class SnapshotManager implements SnapshotState {
 
             List<ReplicatedLogEntry> unAppliedEntries = context.getReplicatedLog().getFrom(lastAppliedIndex + 1);
 
-            captureSnapshot = new CaptureSnapshot(lastLogEntry.getIndex(),
-                    lastLogEntry.getTerm(), lastAppliedIndex, lastAppliedTerm,
+            long lastLogEntryIndex = lastAppliedIndex;
+            long lastLogEntryTerm = lastAppliedTerm;
+            if(lastLogEntry != null) {
+                lastLogEntryIndex = lastLogEntry.getIndex();
+                lastLogEntryTerm = lastLogEntry.getTerm();
+            } else {
+                LOG.warn("Capturing Snapshot : lastLogEntry is null. Using lastAppliedIndex {} and lastAppliedTerm {} instead.",
+                    lastAppliedIndex, lastAppliedTerm);
+            }
+
+            captureSnapshot = new CaptureSnapshot(lastLogEntryIndex,
+                lastLogEntryTerm, lastAppliedIndex, lastAppliedTerm,
                     newReplicatedToAllIndex, newReplicatedToAllTerm, unAppliedEntries, targetFollower != null);
 
             if(captureSnapshot.isInstallSnapshotInitiated()) {