use of org.apache.hadoop.hbase.ByteBufferKeyValue in project hbase by apache.
the class TestSeekTo method testSeekBeforeWithReSeekToInternals.
protected void testSeekBeforeWithReSeekToInternals(TagUsage tagUsage) throws IOException {
Path p = makeNewFile(tagUsage);
FileSystem fs = TEST_UTIL.getTestFileSystem();
Configuration conf = TEST_UTIL.getConfiguration();
HFile.Reader reader = HFile.createReader(fs, p, new CacheConfig(conf), true, conf);
HFileScanner scanner = reader.getScanner(conf, false, true);
assertFalse(scanner.seekBefore(toKV("a", tagUsage)));
assertFalse(scanner.seekBefore(toKV("b", tagUsage)));
assertFalse(scanner.seekBefore(toKV("c", tagUsage)));
// seekBefore d, so the scanner points to c
assertTrue(scanner.seekBefore(toKV("d", tagUsage)));
assertFalse(scanner.getCell() instanceof ByteBufferKeyValue);
assertEquals("c", toRowStr(scanner.getCell()));
// reseekTo e and g
assertEquals(0, scanner.reseekTo(toKV("c", tagUsage)));
assertEquals("c", toRowStr(scanner.getCell()));
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore e, so the scanner points to c
assertTrue(scanner.seekBefore(toKV("e", tagUsage)));
assertEquals("c", toRowStr(scanner.getCell()));
// reseekTo e and g
assertEquals(0, scanner.reseekTo(toKV("e", tagUsage)));
assertEquals("e", toRowStr(scanner.getCell()));
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore f, so the scanner points to e
assertTrue(scanner.seekBefore(toKV("f", tagUsage)));
assertEquals("e", toRowStr(scanner.getCell()));
// reseekTo e and g
assertEquals(0, scanner.reseekTo(toKV("e", tagUsage)));
assertEquals("e", toRowStr(scanner.getCell()));
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore g, so the scanner points to e
assertTrue(scanner.seekBefore(toKV("g", tagUsage)));
assertEquals("e", toRowStr(scanner.getCell()));
// reseekTo e and g again
assertEquals(0, scanner.reseekTo(toKV("e", tagUsage)));
assertEquals("e", toRowStr(scanner.getCell()));
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore h, so the scanner points to g
assertTrue(scanner.seekBefore(toKV("h", tagUsage)));
assertEquals("g", toRowStr(scanner.getCell()));
// reseekTo g
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore i, so the scanner points to g
assertTrue(scanner.seekBefore(toKV("i", tagUsage)));
assertEquals("g", toRowStr(scanner.getCell()));
// reseekTo g
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore j, so the scanner points to i
assertTrue(scanner.seekBefore(toKV("j", tagUsage)));
assertEquals("i", toRowStr(scanner.getCell()));
// reseekTo i
assertEquals(0, scanner.reseekTo(toKV("i", tagUsage)));
assertEquals("i", toRowStr(scanner.getCell()));
// seekBefore k, so the scanner points to i
assertTrue(scanner.seekBefore(toKV("k", tagUsage)));
assertEquals("i", toRowStr(scanner.getCell()));
// reseekTo i and k
assertEquals(0, scanner.reseekTo(toKV("i", tagUsage)));
assertEquals("i", toRowStr(scanner.getCell()));
assertEquals(0, scanner.reseekTo(toKV("k", tagUsage)));
assertEquals("k", toRowStr(scanner.getCell()));
// seekBefore l, so the scanner points to k
assertTrue(scanner.seekBefore(toKV("l", tagUsage)));
assertEquals("k", toRowStr(scanner.getCell()));
// reseekTo k
assertEquals(0, scanner.reseekTo(toKV("k", tagUsage)));
assertEquals("k", toRowStr(scanner.getCell()));
deleteTestDir(fs);
}
use of org.apache.hadoop.hbase.ByteBufferKeyValue in project hbase by apache.
the class TestResult method getByteBufferBackedTagResult.
private Result getByteBufferBackedTagResult(Tag tag) {
List<Tag> tags = null;
if (tag != null) {
tags = Arrays.asList(tag);
}
KeyValue kvCell = new KeyValue(row, family, qual, 0L, KeyValue.Type.Put, value, tags);
ByteBuffer buf = ByteBuffer.allocateDirect(kvCell.getBuffer().length);
ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getBuffer(), 0, kvCell.getBuffer().length);
ByteBufferKeyValue bbKV = new ByteBufferKeyValue(buf, 0, buf.capacity(), 0L);
return Result.create(new Cell[] { bbKV });
}
use of org.apache.hadoop.hbase.ByteBufferKeyValue in project hbase by apache.
the class TestMemstoreLABWithoutPool method testLABRandomAllocation.
/**
* Test a bunch of random allocations
*/
@Test
public void testLABRandomAllocation() {
Random rand = new Random();
MemStoreLAB mslab = new MemStoreLABImpl();
int expectedOff = 0;
ByteBuffer lastBuffer = null;
int lastChunkId = -1;
// behavior
for (int i = 0; i < 100000; i++) {
int valSize = rand.nextInt(1000);
KeyValue kv = new KeyValue(rk, cf, q, new byte[valSize]);
int size = kv.getSerializedSize();
ByteBufferKeyValue newKv = (ByteBufferKeyValue) mslab.copyCellInto(kv);
if (newKv.getBuffer() != lastBuffer) {
// since we add the chunkID at the 0th offset of the chunk and the
// chunkid is an int we need to account for those 4 bytes
expectedOff = Bytes.SIZEOF_INT;
lastBuffer = newKv.getBuffer();
int chunkId = newKv.getBuffer().getInt(0);
assertTrue("chunkid should be different", chunkId != lastChunkId);
lastChunkId = chunkId;
}
assertEquals(expectedOff, newKv.getOffset());
assertTrue("Allocation overruns buffer", newKv.getOffset() + size <= newKv.getBuffer().capacity());
expectedOff += size;
}
}
use of org.apache.hadoop.hbase.ByteBufferKeyValue in project hbase by apache.
the class TestMemStoreChunkPool method testReusingChunks.
@Test
public void testReusingChunks() {
Random rand = new Random();
MemStoreLAB mslab = new MemStoreLABImpl(conf);
int expectedOff = 0;
ByteBuffer lastBuffer = null;
final byte[] rk = Bytes.toBytes("r1");
final byte[] cf = Bytes.toBytes("f");
final byte[] q = Bytes.toBytes("q");
// Randomly allocate some bytes
for (int i = 0; i < 100; i++) {
int valSize = rand.nextInt(1000);
KeyValue kv = new KeyValue(rk, cf, q, new byte[valSize]);
int size = kv.getSerializedSize();
ByteBufferKeyValue newKv = (ByteBufferKeyValue) mslab.copyCellInto(kv);
if (newKv.getBuffer() != lastBuffer) {
expectedOff = 4;
lastBuffer = newKv.getBuffer();
}
assertEquals(expectedOff, newKv.getOffset());
assertTrue("Allocation overruns buffer", newKv.getOffset() + size <= newKv.getBuffer().capacity());
expectedOff += size;
}
// chunks will be put back to pool after close
mslab.close();
int chunkCount = chunkCreator.getPoolSize();
assertTrue(chunkCount > 0);
// reconstruct mslab
mslab = new MemStoreLABImpl(conf);
// chunk should be got from the pool, so we can reuse it.
KeyValue kv = new KeyValue(rk, cf, q, new byte[10]);
mslab.copyCellInto(kv);
assertEquals(chunkCount - 1, chunkCreator.getPoolSize());
}
use of org.apache.hadoop.hbase.ByteBufferKeyValue in project hbase by apache.
the class TestWALCellCodecWithCompression method createOffheapKV.
private ByteBufferKeyValue createOffheapKV(byte[] row, byte[] value, int noOfTags) {
byte[] cf = Bytes.toBytes("myCF");
byte[] q = Bytes.toBytes("myQualifier");
List<Tag> tags = new ArrayList<>(noOfTags);
for (int i = 1; i <= noOfTags; i++) {
tags.add(new ArrayBackedTag((byte) i, Bytes.toBytes("tagValue" + i)));
}
KeyValue kv = new KeyValue(row, cf, q, HConstants.LATEST_TIMESTAMP, value, tags);
ByteBuffer dbb = ByteBuffer.allocateDirect(kv.getBuffer().length);
dbb.put(kv.getBuffer());
return new ByteBufferKeyValue(dbb, 0, kv.getBuffer().length);
}
Aggregations