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=71ef8ffcea04360b6db573de04d5344d44b3cf7c;hb=200164de7246237ee45f761c4db15b8b51f6a93c;hp=12508aebffedc10195ad6c3bd482a1905c23fa7a;hpb=2faf656bf68dd3843fd59520b27a7ec2abbdcc68;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 12508aebff..71ef8ffcea 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 @@ -11,13 +11,13 @@ package org.opendaylight.controller.cluster.raft; import akka.persistence.SnapshotSelectionCriteria; import com.google.common.annotations.VisibleForTesting; import com.google.common.io.ByteSource; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.List; import java.util.Optional; import java.util.function.Consumer; import javax.annotation.Nonnull; +import org.opendaylight.controller.cluster.io.FileBackedOutputStream; 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; @@ -278,7 +278,7 @@ public class SnapshotManager implements SnapshotState { OutputStream installSnapshotStream = null; if (targetFollower != null) { - installSnapshotStream = new ByteArrayOutputStream(); + installSnapshotStream = context.newFileBackedOutputStream(); log.info("{}: Initiating snapshot capture {} to install on {}", persistenceId(), captureSnapshot, targetFollower); } else { @@ -410,18 +410,17 @@ public class SnapshotManager implements SnapshotState { context.getReplicatedLog().getSnapshotTerm()); if (installSnapshotStream.isPresent()) { - try { - installSnapshotStream.get().close(); - } catch (IOException e) { - log.warn("Error closing install snapshot OutputStream", e); - } - if (context.getId().equals(currentBehavior.getLeaderId())) { - ByteSource snapshotBytes = ByteSource.wrap(((ByteArrayOutputStream)installSnapshotStream.get()) - .toByteArray()); - - // this would be call straight to the leader and won't initiate in serialization - currentBehavior.handleMessage(context.getActor(), new SendInstallSnapshot(snapshot, snapshotBytes)); + try { + ByteSource snapshotBytes = ((FileBackedOutputStream)installSnapshotStream.get()).asByteSource(); + currentBehavior.handleMessage(context.getActor(), + new SendInstallSnapshot(snapshot, snapshotBytes)); + } catch (IOException e) { + log.error("{}: Snapshot install failed due to an unrecoverable streaming error", + context.getId(), e); + } + } else { + ((FileBackedOutputStream)installSnapshotStream.get()).cleanup(); } }