Github user aweisberg commented on a diff in the pull request:
https://github.com/apache/cassandra/pull/239#discussion_r200710248
--- Diff:
src/java/org/apache/cassandra/net/async/ByteBufDataOutputStreamPlus.java ---
@@ -135,6 +140,53 @@ public ChannelFuture writeToChannel(ByteBuffer buffer)
throws IOException
return channelFuture;
}
+ /**
+ * Writes all data in file channel to stream BUFFER_SIZE at a time.
+ * Closes file channel when done
+ *
+ * @param f
+ * @return number of bytes transferred
+ * @throws IOException
+ */
+ public long writeToChannel(FileChannel f, StreamRateLimiter limiter)
throws IOException
+ {
+ final long length = f.size();
+ long bytesTransferred = 0;
+
+ try
+ {
+ while (bytesTransferred < length)
+ {
+ int toRead = (int) Math.min(bufferSize, length -
bytesTransferred);
+ NonClosingDefaultFileRegion fileRegion = new
NonClosingDefaultFileRegion(f, bytesTransferred, toRead);
+
+ if
(!Uninterruptibles.tryAcquireUninterruptibly(channelRateLimiter, toRead, 5,
TimeUnit.MINUTES))
+ throw new IOException(String.format("outbound channel
was not writable. Failed to acquire sufficient permits %d", toRead));
+
+ limiter.acquire(toRead);
+
+ bytesTransferred += toRead;
+ final boolean shouldClose = (bytesTransferred == length);
// this is the last buffer, can safely close channel
+
+ channel.writeAndFlush(fileRegion).addListener(future -> {
--- End diff --
Is the contract here that the entire region will be sent or an error
generated? I just want to make sure we don't need to check for the actual
amount transferred.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]