You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2014/02/24 22:29:23 UTC

svn commit: r1571446 - in /hbase/branches/0.98: hbase-common/src/main/java/org/apache/hadoop/hbase/util/ hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/

Author: tedyu
Date: Mon Feb 24 21:29:23 2014
New Revision: 1571446

URL: http://svn.apache.org/r1571446
Log:
HBASE-10597 IOEngine#read() should return the number of bytes transferred


Modified:
    hbase/branches/0.98/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferArray.java
    hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
    hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/ByteBufferIOEngine.java
    hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/FileIOEngine.java
    hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/IOEngine.java

Modified: hbase/branches/0.98/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferArray.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.98/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferArray.java?rev=1571446&r1=1571445&r2=1571446&view=diff
==============================================================================
--- hbase/branches/0.98/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferArray.java (original)
+++ hbase/branches/0.98/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferArray.java Mon Feb 24 21:29:23 2014
@@ -80,9 +80,10 @@ public final class ByteBufferArray {
    * @param start start position in the ByteBufferArray
    * @param len The maximum number of bytes to be written to the given array
    * @param dstArray The array into which bytes are to be written
+   * @return number of bytes read
    */
-  public void getMultiple(long start, int len, byte[] dstArray) {
-    getMultiple(start, len, dstArray, 0);
+  public int getMultiple(long start, int len, byte[] dstArray) {
+    return getMultiple(start, len, dstArray, 0);
   }
 
   /**
@@ -92,13 +93,15 @@ public final class ByteBufferArray {
    * @param dstArray The array into which bytes are to be written
    * @param dstOffset The offset within the given array of the first byte to be
    *          written
+   * @return number of bytes read
    */
-  public void getMultiple(long start, int len, byte[] dstArray, int dstOffset) {
+  public int getMultiple(long start, int len, byte[] dstArray, int dstOffset) {
     multiple(start, len, dstArray, dstOffset, new Visitor() {
       public void visit(ByteBuffer bb, byte[] array, int arrayIdx, int len) {
         bb.get(array, arrayIdx, len);
       }
     });
+    return len;
   }
 
   /**

Modified: hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java?rev=1571446&r1=1571445&r2=1571446&view=diff
==============================================================================
--- hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java (original)
+++ hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java Mon Feb 24 21:29:23 2014
@@ -367,7 +367,10 @@ public class BucketCache implements Bloc
         if (bucketEntry.equals(backingMap.get(key))) {
           int len = bucketEntry.getLength();
           ByteBuffer bb = ByteBuffer.allocate(len);
-          ioEngine.read(bb, bucketEntry.offset());
+          int lenRead = ioEngine.read(bb, bucketEntry.offset());
+          if (lenRead != len) {
+            throw new RuntimeException("Only " + lenRead + " bytes read, " + len + " expected");
+          }
           Cacheable cachedBlock = bucketEntry.deserializerReference(
               deserialiserMap).deserialize(bb, true);
           long timeTaken = System.nanoTime() - start;

Modified: hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/ByteBufferIOEngine.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/ByteBufferIOEngine.java?rev=1571446&r1=1571445&r2=1571446&view=diff
==============================================================================
--- hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/ByteBufferIOEngine.java (original)
+++ hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/ByteBufferIOEngine.java Mon Feb 24 21:29:23 2014
@@ -59,12 +59,13 @@ public class ByteBufferIOEngine implemen
    * @param dstBuffer the given byte buffer into which bytes are to be written
    * @param offset The offset in the ByteBufferArray of the first byte to be
    *          read
+   * @return number of bytes read
    * @throws IOException
    */
   @Override
-  public void read(ByteBuffer dstBuffer, long offset) throws IOException {
+  public int read(ByteBuffer dstBuffer, long offset) throws IOException {
     assert dstBuffer.hasArray();
-    bufferArray.getMultiple(offset, dstBuffer.remaining(), dstBuffer.array(),
+    return bufferArray.getMultiple(offset, dstBuffer.remaining(), dstBuffer.array(),
         dstBuffer.arrayOffset());
   }
 

Modified: hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/FileIOEngine.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/FileIOEngine.java?rev=1571446&r1=1571445&r2=1571446&view=diff
==============================================================================
--- hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/FileIOEngine.java (original)
+++ hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/FileIOEngine.java Mon Feb 24 21:29:23 2014
@@ -69,11 +69,12 @@ public class FileIOEngine implements IOE
    * Transfers data from file to the given byte buffer
    * @param dstBuffer the given byte buffer into which bytes are to be written
    * @param offset The offset in the file where the first byte to be read
+   * @return number of bytes read
    * @throws IOException
    */
   @Override
-  public void read(ByteBuffer dstBuffer, long offset) throws IOException {
-    fileChannel.read(dstBuffer, offset);
+  public int read(ByteBuffer dstBuffer, long offset) throws IOException {
+    return fileChannel.read(dstBuffer, offset);
   }
 
   /**

Modified: hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/IOEngine.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/IOEngine.java?rev=1571446&r1=1571445&r2=1571446&view=diff
==============================================================================
--- hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/IOEngine.java (original)
+++ hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/IOEngine.java Mon Feb 24 21:29:23 2014
@@ -39,9 +39,10 @@ public interface IOEngine {
    * Transfers data from IOEngine to the given byte buffer
    * @param dstBuffer the given byte buffer into which bytes are to be written
    * @param offset The offset in the IO engine where the first byte to be read
+   * @return number of bytes read
    * @throws IOException
    */
-  void read(ByteBuffer dstBuffer, long offset) throws IOException;
+  int read(ByteBuffer dstBuffer, long offset) throws IOException;
 
   /**
    * Transfers data from the given byte buffer to IOEngine