import akka.japi.Procedure;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Stopwatch;
-import com.google.common.io.ByteSource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Optional;
if (snapshotTracker.addChunk(installSnapshot.getChunkIndex(), installSnapshot.getData(),
installSnapshot.getLastChunkHashCode())) {
- ByteSource snapshotBytes = ByteSource.wrap(snapshotTracker.getSnapshot());
Snapshot snapshot = Snapshot.create(
- context.getSnapshotManager().convertSnapshot(snapshotBytes),
+ context.getSnapshotManager().convertSnapshot(snapshotTracker.getSnapshotBytes()),
new ArrayList<>(),
installSnapshot.getLastIncludedIndex(),
installSnapshot.getLastIncludedTerm(),
actor().tell(new ApplySnapshot(snapshot, applySnapshotCallback), actor());
- snapshotTracker = null;
+ closeSnapshotTracker();
} else {
log.debug("{}: handleInstallSnapshot returning: {}", logName(), reply);
sender.tell(reply, actor());
}
- } catch (SnapshotTracker.InvalidChunkException | IOException e) {
+ } catch (IOException e) {
log.debug("{}: Exception in InstallSnapshot of follower", logName(), e);
sender.tell(new InstallSnapshotReply(currentTerm(), context.getId(),
-1, false), actor());
- snapshotTracker = null;
+ closeSnapshotTracker();
+ }
+ }
+
+ private void closeSnapshotTracker() {
+ if (snapshotTracker != null) {
+ snapshotTracker.close();
+ snapshotTracker = null;
}
}
@Override
public void close() {
+ closeSnapshotTracker();
stopElection();
}