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%2FSnapshotManager.java;h=7d9a1bbf5bdbbfba4fd8df57bf17a17f8e8b125f;hp=e6dc8bb367d6f0c27c49765e52e6dbdbcaa7de73;hb=aad11d48fcace37e3365388f387e16fa67257a25;hpb=3859df9beca8f13f1ff2b2744ed3470a1715bec3 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 e6dc8bb367..7d9a1bbf5b 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 @@ -170,14 +170,19 @@ public class SnapshotManager implements SnapshotState { List unAppliedEntries = context.getReplicatedLog().getFrom(lastAppliedIndex + 1); - long lastLogEntryIndex = lastAppliedIndex; - long lastLogEntryTerm = lastAppliedTerm; - if (lastLogEntry != null) { + final long lastLogEntryIndex; + final long lastLogEntryTerm; + if (lastLogEntry == null) { + // When we don't have journal present, for example two captureSnapshots executed right after another with no + // new journal we still want to preserve the index and term in the snapshot. + lastAppliedIndex = lastLogEntryIndex = context.getReplicatedLog().getSnapshotIndex(); + lastAppliedTerm = lastLogEntryTerm = context.getReplicatedLog().getSnapshotTerm(); + + log.debug("{}: Capturing Snapshot : lastLogEntry is null. Using snapshot values lastAppliedIndex {} and " + + "lastAppliedTerm {} instead.", persistenceId(), lastAppliedIndex, lastAppliedTerm); + } else { lastLogEntryIndex = lastLogEntry.getIndex(); lastLogEntryTerm = lastLogEntry.getTerm(); - } else { - log.debug("{}: Capturing Snapshot : lastLogEntry is null. Using lastAppliedIndex {} and " - + "lastAppliedTerm {} instead.", persistenceId(), lastAppliedIndex, lastAppliedTerm); } return new CaptureSnapshot(lastLogEntryIndex, lastLogEntryTerm, lastAppliedIndex, lastAppliedTerm,