cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aweisberg <...@git.apache.org>
Subject [GitHub] cassandra pull request #239: Optimize Streaming
Date Fri, 06 Jul 2018 16:48:35 GMT
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: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Mime
View raw message