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%2Fbehaviors%2FLeaderInstallSnapshotState.java;h=758345214841ba62ab41af0827427a505562198f;hp=23a0f6d027c53841644a6ab1c5273708a9e0a011;hb=refs%2Fchanges%2F25%2F82725%2F1;hpb=f33beecf2a10955a9219757529ba3017079816cc diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderInstallSnapshotState.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderInstallSnapshotState.java index 23a0f6d027..7583452148 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderInstallSnapshotState.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderInstallSnapshotState.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.cluster.raft.behaviors; +import com.google.common.base.MoreObjects; import com.google.common.base.Stopwatch; import com.google.common.io.ByteSource; import java.io.IOException; @@ -73,8 +74,12 @@ public final class LeaderInstallSnapshotState implements AutoCloseable { } int incrementOffset() { + // if first chunk was retried, reset offset back to initial 0 + if (offset == -1) { + offset = 0; + } if (replyStatus) { - // if prev chunk failed, we would want to sent the same chunk again + // if prev chunk failed, we would want to send the same chunk again offset = offset + snapshotChunkSize; } return offset; @@ -82,7 +87,7 @@ public final class LeaderInstallSnapshotState implements AutoCloseable { int incrementChunkIndex() { if (replyStatus) { - // if prev chunk failed, we would want to sent the same chunk again + // if prev chunk failed, we would want to send the same chunk again chunkIndex = chunkIndex + 1; } return chunkIndex; @@ -125,15 +130,17 @@ public final class LeaderInstallSnapshotState implements AutoCloseable { replyStatus = true; lastChunkHashCode = nextChunkHashCode; } else { - // if the chunk sent was failure - replyReceivedForOffset = offset; + // if the chunk sent was failure, revert offset to previous so we can retry + offset = replyReceivedForOffset; replyStatus = false; } } byte[] getNextChunk() throws IOException { + // increment offset to indicate next chunk is in flight, canSendNextChunk() wont let us hit this again until, + // markSendStatus() is called with either success or failure + int start = incrementOffset(); if (replyStatus || currentChunk == null) { - int start = incrementOffset(); int size = snapshotChunkSize; if (snapshotChunkSize > snapshotSize) { size = (int) snapshotSize; @@ -200,4 +207,20 @@ public final class LeaderInstallSnapshotState implements AutoCloseable { int getLastChunkHashCode() { return lastChunkHashCode; } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("snapshotChunkSize", snapshotChunkSize) + .add("offset", offset) + .add("replyReceivedForOffset", replyReceivedForOffset) + .add("replyStatus", replyStatus) + .add("chunkIndex", chunkIndex) + .add("totalChunks", totalChunks) + .add("lastChunkHashCode", lastChunkHashCode) + .add("nextChunkHashCode", nextChunkHashCode) + .add("snapshotSize", snapshotSize) + .add("chunkTimer", chunkTimer) + .toString(); + } }