- 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 {