X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FSnapshotManager.java;h=cffd4222220041e5bf9a8ccf7cb2ea7ebff996a1;hb=36372c716205959311bb86256872cf9c7b2d350b;hp=9571173175ff220aa3fb5b6b9ba757eee150ffe4;hpb=f1c3050779d7770ef6a12a67a1870765c3dfd9eb;p=controller.git 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 9571173175..cffd422222 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 @@ -139,8 +139,8 @@ public class SnapshotManager implements SnapshotState { lastLogEntryIndex = lastLogEntry.getIndex(); lastLogEntryTerm = lastLogEntry.getTerm(); } else { - LOG.warn("Capturing Snapshot : lastLogEntry is null. Using lastAppliedIndex {} and lastAppliedTerm {} instead.", - lastAppliedIndex, lastAppliedTerm); + LOG.debug("{}: Capturing Snapshot : lastLogEntry is null. Using lastAppliedIndex {} and lastAppliedTerm {} instead.", + persistenceId(), lastAppliedIndex, lastAppliedTerm); } return new CaptureSnapshot(lastLogEntryIndex, lastLogEntryTerm, lastAppliedIndex, lastAppliedTerm, @@ -242,7 +242,7 @@ public class SnapshotManager implements SnapshotState { lastSequenceNumber = context.getPersistenceProvider().getLastSequenceNumber(); - LOG.debug("lastSequenceNumber prior to capture: {}", lastSequenceNumber); + LOG.debug("{}: lastSequenceNumber prior to capture: {}", persistenceId(), lastSequenceNumber); SnapshotManager.this.currentState = CREATING; @@ -303,7 +303,7 @@ public class SnapshotManager implements SnapshotState { captureSnapshot.getLastIndex(), captureSnapshot.getLastTerm(), captureSnapshot.getLastAppliedIndex(), captureSnapshot.getLastAppliedTerm(), context.getTermInformation().getCurrentTerm(), - context.getTermInformation().getVotedFor()); + context.getTermInformation().getVotedFor(), context.getPeerServerInfo(true)); context.getPersistenceProvider().saveSnapshot(snapshot); @@ -382,28 +382,32 @@ public class SnapshotManager implements SnapshotState { @Override public void commit(long sequenceNumber, RaftActorBehavior currentBehavior) { - LOG.debug("Snapshot success sequence number: {}", sequenceNumber); + LOG.debug("{}: Snapshot success - sequence number: {}", persistenceId(), sequenceNumber); if(applySnapshot != null) { try { Snapshot snapshot = applySnapshot.getSnapshot(); - applySnapshotProcedure.apply(snapshot.getState()); //clears the followers log, sets the snapshot index to ensure adjusted-index works context.setReplicatedLog(ReplicatedLogImpl.newInstance(snapshot, context, currentBehavior)); context.setLastApplied(snapshot.getLastAppliedIndex()); context.setCommitIndex(snapshot.getLastAppliedIndex()); + context.getTermInformation().update(snapshot.getElectionTerm(), snapshot.getElectionVotedFor()); + + if(snapshot.getState().length > 0 ) { + applySnapshotProcedure.apply(snapshot.getState()); + } applySnapshot.getCallback().onSuccess(); } catch (Exception e) { - LOG.error("Error applying snapshot", e); + LOG.error("{}: Error applying snapshot", context.getId(), e); } } else { context.getReplicatedLog().snapshotCommit(); } context.getPersistenceProvider().deleteSnapshots(new SnapshotSelectionCriteria( - sequenceNumber - context.getConfigParams().getSnapshotBatchCount(), 43200000)); + sequenceNumber - context.getConfigParams().getSnapshotBatchCount(), Long.MAX_VALUE)); context.getPersistenceProvider().deleteMessages(lastSequenceNumber);