openinx commented on a change in pull request #467: HBASE-22802 Avoid temp 
ByteBuffer allocation in FileIOEngine#read
URL: https://github.com/apache/hbase/pull/467#discussion_r312765622
 
 

 ##########
 File path: hbase-common/src/main/java/org/apache/hadoop/hbase/nio/ByteBuff.java
 ##########
 @@ -475,6 +486,32 @@ public static int channelRead(ReadableByteChannel 
channel, ByteBuffer buf) throw
     return (nBytes > 0) ? nBytes : ret;
   }
 
+  public static int fileRead(FileChannel channel, ByteBuffer buf, long offset)
+      throws IOException {
+    if (buf.remaining() <= NIO_BUFFER_LIMIT) {
+      return channel.read(buf, offset);
+    }
+    int originalLimit = buf.limit();
+    int initialRemaining = buf.remaining();
+    int ret = 0;
+
+    while (buf.remaining() > 0) {
+      try {
+        int ioSize = Math.min(buf.remaining(), NIO_BUFFER_LIMIT);
+        buf.limit(buf.position() + ioSize);
+        offset += ret;
+        ret = channel.read(buf, offset);
+        if (ret < ioSize) {
+          break;
+        }
+      } finally {
+        buf.limit(originalLimit);
 
 Review comment:
   Only reset the limit ? should we also reset the position ? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to