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%2FRaftActorSnapshotMessageSupport.java;h=4d68d8ea160d20b9ba8ec30072bacb21dc2c44e0;hp=328de80a838e4685feba5de785e9b2f005fe738b;hb=0f02b7edeb1454c1a568f0f1b050757e7503ddf7;hpb=dc538304e4d5f91185c140cc227575f4305344df diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotMessageSupport.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotMessageSupport.java index 328de80a83..4d68d8ea16 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotMessageSupport.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotMessageSupport.java @@ -12,13 +12,15 @@ import akka.persistence.SaveSnapshotFailure; import akka.persistence.SaveSnapshotSuccess; import com.google.common.annotations.VisibleForTesting; import java.util.Collections; +import java.util.Optional; import java.util.concurrent.TimeUnit; -import org.apache.commons.lang3.SerializationUtils; 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.CaptureSnapshotReply; import org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot; import org.opendaylight.controller.cluster.raft.client.messages.GetSnapshotReply; +import org.opendaylight.controller.cluster.raft.persisted.EmptyState; +import org.opendaylight.controller.cluster.raft.persisted.Snapshot; import org.slf4j.Logger; import scala.concurrent.duration.Duration; @@ -46,21 +48,26 @@ class RaftActorSnapshotMessageSupport { this.cohort = cohort; this.log = context.getLogger(); - context.getSnapshotManager().setCreateSnapshotRunnable(() -> cohort.createSnapshot(context.getActor())); - context.getSnapshotManager().setApplySnapshotConsumer(cohort::applySnapshot); + context.getSnapshotManager().setCreateSnapshotConsumer( + outputStream -> cohort.createSnapshot(context.getActor(), outputStream)); + context.getSnapshotManager().setSnapshotCohort(cohort); + } + + RaftActorSnapshotCohort getSnapshotCohort() { + return cohort; } boolean handleSnapshotMessage(Object message, ActorRef sender) { - if (message instanceof ApplySnapshot ) { + if (message instanceof ApplySnapshot) { onApplySnapshot((ApplySnapshot) message); } else if (message instanceof SaveSnapshotSuccess) { onSaveSnapshotSuccess((SaveSnapshotSuccess) message); } else if (message instanceof SaveSnapshotFailure) { onSaveSnapshotFailure((SaveSnapshotFailure) message); } else if (message instanceof CaptureSnapshotReply) { - onCaptureSnapshotReply(((CaptureSnapshotReply) message).getSnapshot()); + onCaptureSnapshotReply((CaptureSnapshotReply) message); } else if (COMMIT_SNAPSHOT.equals(message)) { - context.getSnapshotManager().commit(-1); + context.getSnapshotManager().commit(-1, -1); } else if (message instanceof GetSnapshot) { onGetSnapshot(sender); } else { @@ -70,10 +77,11 @@ class RaftActorSnapshotMessageSupport { return true; } - private void onCaptureSnapshotReply(byte[] snapshotBytes) { - log.debug("{}: CaptureSnapshotReply received by actor: snapshot size {}", context.getId(), snapshotBytes.length); + private void onCaptureSnapshotReply(CaptureSnapshotReply reply) { + log.debug("{}: CaptureSnapshotReply received by actor", context.getId()); - context.getSnapshotManager().persist(snapshotBytes, context.getTotalMemory()); + context.getSnapshotManager().persist(reply.getSnapshotState(), reply.getInstallSnapshotStream(), + context.getTotalMemory()); } private void onSaveSnapshotFailure(SaveSnapshotFailure saveSnapshotFailure) { @@ -84,16 +92,15 @@ class RaftActorSnapshotMessageSupport { } private void onSaveSnapshotSuccess(SaveSnapshotSuccess success) { - log.info("{}: SaveSnapshotSuccess received for snapshot", context.getId()); - long sequenceNumber = success.metadata().sequenceNr(); - context.getSnapshotManager().commit(sequenceNumber); + log.info("{}: SaveSnapshotSuccess received for snapshot, sequenceNr: {}", context.getId(), sequenceNumber); + + context.getSnapshotManager().commit(sequenceNumber, success.metadata().timestamp()); } private void onApplySnapshot(ApplySnapshot message) { - log.info("{}: Applying snapshot on follower with snapshotIndex: {}, snapshotTerm: {}", context.getId(), - message.getSnapshot().getLastAppliedIndex(), message.getSnapshot().getLastAppliedTerm()); + log.info("{}: Applying snapshot on follower: {}", context.getId(), message.getSnapshot()); context.getSnapshotManager().apply(message); } @@ -101,22 +108,23 @@ class RaftActorSnapshotMessageSupport { private void onGetSnapshot(ActorRef sender) { log.debug("{}: onGetSnapshot", context.getId()); - if(context.getPersistenceProvider().isRecoveryApplicable()) { + if (context.getPersistenceProvider().isRecoveryApplicable()) { CaptureSnapshot captureSnapshot = context.getSnapshotManager().newCaptureSnapshot( - context.getReplicatedLog().last(), -1, false); + context.getReplicatedLog().last(), -1); ActorRef snapshotReplyActor = context.actorOf(GetSnapshotReplyActor.props(captureSnapshot, ImmutableElectionTerm.copyOf(context.getTermInformation()), sender, snapshotReplyActorTimeout, context.getId(), context.getPeerServerInfo(true))); - cohort.createSnapshot(snapshotReplyActor); + cohort.createSnapshot(snapshotReplyActor, Optional.empty()); } else { - Snapshot snapshot = Snapshot.create(new byte[0], Collections.emptyList(), -1, -1, -1, -1, + Snapshot snapshot = Snapshot.create( + EmptyState.INSTANCE, Collections.emptyList(), + -1, -1, -1, -1, context.getTermInformation().getCurrentTerm(), context.getTermInformation().getVotedFor(), context.getPeerServerInfo(true)); - sender.tell(new GetSnapshotReply(context.getId(), SerializationUtils.serialize(snapshot)), - context.getActor()); + sender.tell(new GetSnapshotReply(context.getId(), snapshot), context.getActor()); } }