HBASE-15064 BufferUnderflowException after last Cell fetched from an HFile Block served from L2 offheap cache - Addendum.

This commit is contained in:
anoopsjohn 2016-03-23 15:03:50 +05:30
parent 5fcadb86ab
commit cadfb21f4b
2 changed files with 27 additions and 1 deletions

View File

@ -472,7 +472,8 @@ public class MultiByteBuff extends ByteBuff {
*/ */
@Override @Override
public final boolean hasRemaining() { public final boolean hasRemaining() {
return this.curItem.hasRemaining() || this.curItemIndex < this.items.length - 1; return this.curItem.hasRemaining() || (this.curItemIndex < this.limitedItemIndex
&& this.items[this.curItemIndex + 1].hasRemaining());
} }
/** /**

View File

@ -378,4 +378,29 @@ public class TestMultiByteBuff {
assertTrue(Bytes.equals(actual, 0, actual.length, assertTrue(Bytes.equals(actual, 0, actual.length,
b, 1, 3)); b, 1, 3));
} }
@Test
public void testHasRemaining() {
ByteBuffer b1 = ByteBuffer.allocate(8);
ByteBuffer b2 = ByteBuffer.allocate(8);
ByteBuffer b3 = ByteBuffer.allocate(8);
MultiByteBuff mbb1 = new MultiByteBuff(b1, b2, b3);
assertTrue(mbb1.hasRemaining());
mbb1.limit(20); // Limit in mid of last of BB
mbb1.position(15);
mbb1.get();// We are at the end of second BB
assertTrue(mbb1.hasRemaining());
mbb1.position(20);
assertFalse(mbb1.hasRemaining());
mbb1.limit(12); // Limit in mid of second BB
mbb1.position(11);
assertTrue(mbb1.hasRemaining());
mbb1.get(); // Now we have reached the limit
assertFalse(mbb1.hasRemaining());
mbb1.limit(16);// Limit at begin of the last BB
mbb1.position(15);
assertTrue(mbb1.hasRemaining());
mbb1.get(); // Now we have reached the limit
assertFalse(mbb1.hasRemaining());
}
} }