HBASE-10597 IOEngine#read() should return the number of bytes transferred

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1571445 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2014-02-24 21:28:23 +00:00
parent 9582b9b34d
commit b024de156c
5 changed files with 18 additions and 9 deletions

View File

@ -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;
}
/**

View File

@ -367,7 +367,10 @@ public class BucketCache implements BlockCache, HeapSize {
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;

View File

@ -59,12 +59,13 @@ public class ByteBufferIOEngine implements IOEngine {
* @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());
}

View File

@ -69,11 +69,12 @@ public class FileIOEngine implements IOEngine {
* 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);
}
/**

View File

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