import akka.persistence.SnapshotSelectionCriteria;
import com.google.common.annotations.VisibleForTesting;
import java.util.List;
import akka.persistence.SnapshotSelectionCriteria;
import com.google.common.annotations.VisibleForTesting;
import java.util.List;
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot;
import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot;
import org.opendaylight.controller.cluster.raft.base.messages.SendInstallSnapshot;
import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot;
import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot;
import org.opendaylight.controller.cluster.raft.base.messages.SendInstallSnapshot;
- public void persist(byte[] snapshotBytes, RaftActorBehavior currentBehavior, long totalMemory) {
- currentState.persist(snapshotBytes, currentBehavior, totalMemory);
+ public void persist(final byte[] snapshotBytes, final long totalMemory) {
+ currentState.persist(snapshotBytes, totalMemory);
- public void commit(long sequenceNumber, RaftActorBehavior currentBehavior) {
- currentState.commit(sequenceNumber, currentBehavior);
+ public void commit(final long sequenceNumber, long timeStamp) {
+ currentState.commit(sequenceNumber, timeStamp);
- public long trimLog(long desiredTrimIndex, RaftActorBehavior currentBehavior) {
- return currentState.trimLog(desiredTrimIndex, currentBehavior);
+ public long trimLog(final long desiredTrimIndex) {
+ return currentState.trimLog(desiredTrimIndex);
- 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,
}
return new CaptureSnapshot(lastLogEntryIndex, lastLogEntryTerm, lastAppliedIndex, lastAppliedTerm,
// we would want to keep the lastApplied as its used while capturing snapshots
long lastApplied = context.getLastApplied();
long tempMin = Math.min(desiredTrimIndex, (lastApplied > -1 ? lastApplied - 1 : -1));
// we would want to keep the lastApplied as its used while capturing snapshots
long lastApplied = context.getLastApplied();
long tempMin = Math.min(desiredTrimIndex, (lastApplied > -1 ? lastApplied - 1 : -1));
context.getReplicatedLog().snapshotPreCommit(tempMin, entry.getTerm());
context.getReplicatedLog().snapshotCommit();
return tempMin;
context.getReplicatedLog().snapshotPreCommit(tempMin, entry.getTerm());
context.getReplicatedLog().snapshotCommit();
return tempMin;
// It's possible a follower was lagging and an install snapshot advanced its match index past
// the current replicatedToAllIndex. Since the follower is now caught up we should advance the
// replicatedToAllIndex (to tempMin). The fact that tempMin wasn't found in the log is likely
// It's possible a follower was lagging and an install snapshot advanced its match index past
// the current replicatedToAllIndex. Since the follower is now caught up we should advance the
// replicatedToAllIndex (to tempMin). The fact that tempMin wasn't found in the log is likely
} catch (Exception e) {
SnapshotManager.this.currentState = IDLE;
LOG.error("Error creating snapshot", e);
} catch (Exception e) {
SnapshotManager.this.currentState = IDLE;
LOG.error("Error creating snapshot", e);
- public long trimLog(long desiredTrimIndex, RaftActorBehavior currentBehavior) {
- return doTrimLog(desiredTrimIndex, currentBehavior);
+ public long trimLog(final long desiredTrimIndex) {
+ return doTrimLog(desiredTrimIndex);
// create a snapshot object from the state provided and save it
// when snapshot is saved async, SaveSnapshotSuccess is raised.
// create a snapshot object from the state provided and save it
// when snapshot is saved async, SaveSnapshotSuccess is raised.
captureSnapshot.getLastIndex(), captureSnapshot.getLastTerm(),
captureSnapshot.getLastAppliedIndex(), captureSnapshot.getLastAppliedTerm(),
context.getTermInformation().getCurrentTerm(),
captureSnapshot.getLastIndex(), captureSnapshot.getLastTerm(),
captureSnapshot.getLastAppliedIndex(), captureSnapshot.getLastAppliedTerm(),
context.getTermInformation().getCurrentTerm(),
boolean logSizeExceededSnapshotBatchCount =
context.getReplicatedLog().size() >= context.getConfigParams().getSnapshotBatchCount();
boolean logSizeExceededSnapshotBatchCount =
context.getReplicatedLog().size() >= context.getConfigParams().getSnapshotBatchCount();
if (dataSizeThresholdExceeded || logSizeExceededSnapshotBatchCount) {
if(LOG.isDebugEnabled()) {
if(dataSizeThresholdExceeded) {
if (dataSizeThresholdExceeded || logSizeExceededSnapshotBatchCount) {
if(LOG.isDebugEnabled()) {
if(dataSizeThresholdExceeded) {
- public void commit(long sequenceNumber, RaftActorBehavior currentBehavior) {
- LOG.debug("Snapshot success sequence number: {}", sequenceNumber);
+ public void commit(final long sequenceNumber, long timeStamp) {
+ LOG.debug("{}: Snapshot success - sequence number: {}", persistenceId(), sequenceNumber);
if(applySnapshot != null) {
try {
Snapshot snapshot = applySnapshot.getSnapshot();
//clears the followers log, sets the snapshot index to ensure adjusted-index works
if(applySnapshot != null) {
try {
Snapshot snapshot = applySnapshot.getSnapshot();
//clears the followers log, sets the snapshot index to ensure adjusted-index works
context.setLastApplied(snapshot.getLastAppliedIndex());
context.setCommitIndex(snapshot.getLastAppliedIndex());
context.getTermInformation().update(snapshot.getElectionTerm(), snapshot.getElectionVotedFor());
context.setLastApplied(snapshot.getLastAppliedIndex());
context.setCommitIndex(snapshot.getLastAppliedIndex());
context.getTermInformation().update(snapshot.getElectionTerm(), snapshot.getElectionVotedFor());
- context.getPersistenceProvider().deleteSnapshots(new SnapshotSelectionCriteria(
- sequenceNumber - context.getConfigParams().getSnapshotBatchCount(), 43200000));
+ context.getPersistenceProvider().deleteSnapshots(new SnapshotSelectionCriteria(sequenceNumber,
+ timeStamp - 1, 0L, 0L));