From 07ab62b31f45779a887c418b0bf8111c4fc94dbf Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Tue, 9 Feb 2016 16:11:30 -0500 Subject: [PATCH] Backport NPE fix in SnapshotManager Backported https://git.opendaylight.org/gerrit/#/c/26132/ that fixed an NPE in the SnapshotManager if there is no log entry from which to obtain the last term/index for the snapshot. In this case it uses the last applied term/index. Change-Id: Iabd7f7467fa09a71576611e8261a3c985e62a97c Signed-off-by: Tom Pantelis --- .../controller/cluster/raft/SnapshotManager.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/SnapshotManager.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/SnapshotManager.java index 970fb8fc71..16b4b2e498 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/SnapshotManager.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/SnapshotManager.java @@ -211,8 +211,18 @@ public class SnapshotManager implements SnapshotState { List 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.debug("{}: Capturing Snapshot : lastLogEntry is null. Using lastAppliedIndex {} and lastAppliedTerm {} instead.", + persistenceId(), lastAppliedIndex, lastAppliedTerm); + } + + captureSnapshot = new CaptureSnapshot(lastLogEntryIndex, + lastLogEntryTerm, lastAppliedIndex, lastAppliedTerm, newReplicatedToAllIndex, newReplicatedToAllTerm, unAppliedEntries, targetFollower != null); if(captureSnapshot.isInstallSnapshotInitiated()) { -- 2.36.6