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

 ##########
 File path: 
hbase-common/src/main/java/org/apache/hadoop/hbase/nio/MultiByteBuff.java
 ##########
 @@ -1064,28 +1065,58 @@ public void get(ByteBuffer out, int sourceOffset, int 
length) {
     return output;
   }
 
-  @Override
-  public int read(ReadableByteChannel channel) throws IOException {
+  private int internalRead(ReadableByteChannel channel, long offset,
+      ChannelReader reader) throws IOException {
     checkRefCount();
     int total = 0;
     while (true) {
-      // Read max possible into the current BB
-      int len = channelRead(channel, this.curItem);
-      if (len > 0)
+      int len = read(channel, this.curItem, offset, reader);
+      if (len > 0) {
         total += len;
+        offset += len;
+      }
       if (this.curItem.hasRemaining()) {
-        // We were not able to read enough to fill the current BB itself. 
Means there is no point in
-        // doing more reads from Channel. Only this much there for now.
         break;
       } else {
-        if (this.curItemIndex >= this.limitedItemIndex) break;
+        if (this.curItemIndex >= this.limitedItemIndex) {
+          break;
+        }
         this.curItemIndex++;
         this.curItem = this.items[this.curItemIndex];
       }
     }
     return total;
   }
 
+  @Override
+  public int read(ReadableByteChannel channel) throws IOException {
+    return internalRead(channel, 0, CHANNEL_READER);
+  }
+
+  @Override
+  public int read(FileChannel channel, long offset) throws IOException {
+    return internalRead(channel, offset, FILE_READER);
+  }
+
+  @Override
+  public int write(FileChannel channel, long offset) throws IOException {
 
 Review comment:
   Here we can also use the Iterator  if we have one .

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to