HBASE-17950 Write the chunkId also as Int instead of long into the first

byte of the chunk (Ram)
This commit is contained in:
Ramkrishna 2017-04-28 14:43:19 +05:30
parent 68b2e0f7d9
commit b401a35fdc
7 changed files with 17 additions and 17 deletions

View File

@ -100,8 +100,8 @@ public abstract class Chunk {
throw e;
}
// Mark that it's ready for use
// Move 8 bytes since the first 8 bytes are having the chunkid in it
boolean initted = nextFreeOffset.compareAndSet(UNINITIALIZED, Bytes.SIZEOF_LONG);
// Move 4 bytes since the first 4 bytes are having the chunkid in it
boolean initted = nextFreeOffset.compareAndSet(UNINITIALIZED, Bytes.SIZEOF_INT);
// We should always succeed the above CAS since only one thread
// calls init()!
Preconditions.checkState(initted, "Multiple threads tried to init same chunk");

View File

@ -41,7 +41,7 @@ public class OffheapChunk extends Chunk {
void allocateDataBuffer() {
if (data == null) {
data = ByteBuffer.allocateDirect(this.size);
data.putLong(0, this.getId());
data.putInt(0, this.getId());
}
}
}

View File

@ -39,7 +39,7 @@ public class OnheapChunk extends Chunk {
void allocateDataBuffer() {
if (data == null) {
data = ByteBuffer.allocate(this.size);
data.putLong(0, this.getId());
data.putInt(0, this.getId());
}
}
}

View File

@ -140,8 +140,8 @@ public class TestDefaultMemStore {
// make sure chunk size increased even when writing the same cell, if using MSLAB
if (msLab instanceof MemStoreLABImpl) {
// since we add the chunkID at the 0th offset of the chunk and the
// chunkid is a long we need to account for those 8 bytes
assertEquals(2 * Segment.getCellLength(kv) + Bytes.SIZEOF_LONG,
// chunkid is an int we need to account for those 4 bytes
assertEquals(2 * Segment.getCellLength(kv) + Bytes.SIZEOF_INT,
((MemStoreLABImpl) msLab).getCurrentChunk().getNextFreeOffset());
}
} else {

View File

@ -90,7 +90,7 @@ public class TestMemStoreChunkPool {
int size = KeyValueUtil.length(kv);
ByteBufferKeyValue newKv = (ByteBufferKeyValue) mslab.copyCellInto(kv);
if (newKv.getBuffer() != lastBuffer) {
expectedOff = 8;
expectedOff = 4;
lastBuffer = newKv.getBuffer();
}
assertEquals(expectedOff, newKv.getOffset());

View File

@ -76,7 +76,7 @@ public class TestMemStoreLAB {
MemStoreLAB mslab = new MemStoreLABImpl();
int expectedOff = 0;
ByteBuffer lastBuffer = null;
long lastChunkId = -1;
int lastChunkId = -1;
// 100K iterations by 0-1K alloc -> 50MB expected
// should be reasonable for unit test and also cover wraparound
// behavior
@ -87,10 +87,10 @@ public class TestMemStoreLAB {
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 a long we need to account for those 8 bytes
expectedOff = Bytes.SIZEOF_LONG;
// chunkid is an int we need to account for those 4 bytes
expectedOff = Bytes.SIZEOF_INT;
lastBuffer = newKv.getBuffer();
long chunkId = newKv.getBuffer().getLong(0);
int chunkId = newKv.getBuffer().getInt(0);
assertTrue("chunkid should be different", chunkId != lastChunkId);
lastChunkId = chunkId;
}
@ -172,8 +172,8 @@ public class TestMemStoreLAB {
// Now check each byte array to make sure allocations don't overlap
for (Map<Integer, AllocRecord> allocsInChunk : mapsByChunk.values()) {
// since we add the chunkID at the 0th offset of the chunk and the
// chunkid is a long we need to account for those 8 bytes
int expectedOff = Bytes.SIZEOF_LONG;
// chunkid is an int we need to account for those 4 bytes
int expectedOff = Bytes.SIZEOF_INT;
for (AllocRecord alloc : allocsInChunk.values()) {
assertEquals(expectedOff, alloc.offset);
assertTrue("Allocation overruns buffer",

View File

@ -66,7 +66,7 @@ public class TestMemstoreLABWithoutPool {
MemStoreLAB mslab = new MemStoreLABImpl();
int expectedOff = 0;
ByteBuffer lastBuffer = null;
long lastChunkId = -1;
int lastChunkId = -1;
// 100K iterations by 0-1K alloc -> 50MB expected
// should be reasonable for unit test and also cover wraparound
// behavior
@ -77,10 +77,10 @@ public class TestMemstoreLABWithoutPool {
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 a long we need to account for those 8 bytes
expectedOff = Bytes.SIZEOF_LONG;
// chunkid is an int we need to account for those 4 bytes
expectedOff = Bytes.SIZEOF_INT;
lastBuffer = newKv.getBuffer();
long chunkId = newKv.getBuffer().getLong(0);
int chunkId = newKv.getBuffer().getInt(0);
assertTrue("chunkid should be different", chunkId != lastChunkId);
lastChunkId = chunkId;
}