use of org.opendaylight.controller.cluster.raft.persisted.EmptyState in project controller by opendaylight.
the class RaftActorRecoverySupport method onRecoveredSnapshot.
private void onRecoveredSnapshot(SnapshotOffer offer) {
log.debug("{}: SnapshotOffer called.", context.getId());
initRecoveryTimer();
Snapshot snapshot = (Snapshot) offer.snapshot();
for (ReplicatedLogEntry entry : snapshot.getUnAppliedEntries()) {
if (isMigratedPayload(entry)) {
hasMigratedDataRecovered = true;
}
}
if (!context.getPersistenceProvider().isRecoveryApplicable()) {
// We may have just transitioned to disabled and have a snapshot containing state data and/or log
// entries - we don't want to preserve these, only the server config and election term info.
snapshot = Snapshot.create(EmptyState.INSTANCE, Collections.emptyList(), -1, -1, -1, -1, snapshot.getElectionTerm(), snapshot.getElectionVotedFor(), snapshot.getServerConfiguration());
}
// Create a replicated log with the snapshot information
// The replicated log can be used later on to retrieve this snapshot
// when we need to install it on a peer
context.setReplicatedLog(ReplicatedLogImpl.newInstance(snapshot, context));
context.setLastApplied(snapshot.getLastAppliedIndex());
context.setCommitIndex(snapshot.getLastAppliedIndex());
context.getTermInformation().update(snapshot.getElectionTerm(), snapshot.getElectionVotedFor());
Stopwatch timer = Stopwatch.createStarted();
// Apply the snapshot to the actors state
if (!(snapshot.getState() instanceof EmptyState)) {
cohort.applyRecoverySnapshot(snapshot.getState());
}
if (snapshot.getServerConfiguration() != null) {
context.updatePeerIds(snapshot.getServerConfiguration());
}
timer.stop();
log.info("Recovery snapshot applied for {} in {}: snapshotIndex={}, snapshotTerm={}, journal-size={}", context.getId(), timer.toString(), replicatedLog().getSnapshotIndex(), replicatedLog().getSnapshotTerm(), replicatedLog().size());
}
Aggregations