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/06 06:29:05 UTC

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

chenxu14 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_r321591733
 
 

 ##########
 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
   
   nice find, use buffer instead
   
   > maybe we can try to combine the buffsIterator and curItem & curItemIndex into one iterator
   
   I think it's not easy to do that, the curItem is referenced in so many methods, maybe we should keep the current logic to avoid possible BUGs.

----------------------------------------------------------------
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