You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/09/05 09:32:59 UTC

[GitHub] [hbase] openinx commented on a change in pull request #583: HBASE-22802 Avoid temp ByteBuffer allocation in FileIOEngine#read

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

 ##########
 File path: hbase-common/src/main/java/org/apache/hadoop/hbase/nio/MultiByteBuff.java
 ##########
 @@ -1064,23 +1084,44 @@ public void get(ByteBuffer out, int sourceOffset, int length) {
     return output;
   }
 
+  private int internalRead(ReadableByteChannel channel, long offset,
+      ChannelReader reader) throws IOException {
+    checkRefCount();
+    int total = 0;
+    while (buffsIterator.hasNext()) {
+      ByteBuffer buffer = buffsIterator.next();
+      int len = read(channel, buffer, offset, reader);
+      if (len > 0) {
+        total += len;
+        offset += len;
+      }
+      if (buffer.hasRemaining()) {
+        break;
+      }
+    }
+    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 {
     checkRefCount();
     int total = 0;
-    while (true) {
-      // Read max possible into the current BB
-      int len = channelRead(channel, this.curItem);
-      if (len > 0)
+    while (buffsIterator.hasNext()) {
+      ByteBuffer buffer = buffsIterator.next();
+      while (buffer.hasRemaining()) {
+        int len = channel.write(curItem, offset);
 
 Review comment:
   Better to use buffer instead of curItem here,  otherwise seems strange here although no much difference in logics. Also maybe we can try to combine the  buffsIterator and curItem & curItemIndex into  one iterator, seems they are doing the same thing , say tracking the current buffer. 

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


With regards,
Apache Git Services