@Test public void testLABRandomAllocation() { Random rand = new Random(); MemStoreLAB mslab = new MemStoreLAB(); int expectedOff = 0; byte[] lastBuffer = null; for (int i = 0; i < 100000; i++) { int size = rand.nextInt(1000); Allocation alloc = mslab.allocateBytes(size); if (alloc.getData() != lastBuffer) { expectedOff = 0; lastBuffer = alloc.getData(); } assertEquals(expectedOff, alloc.getOffset()); assertTrue("Allocation " + alloc + " overruns buffer", alloc.getOffset() + size <= alloc.getData().length); expectedOff += size; } }
public Allocation allocateBytes(int size) { Preconditions.checkArgument(size >= 0, "negative size"); if (size > maxAlloc) { return null; } while (true) { Chunk c = getOrMakeChunk(); int allocOffset = c.alloc(size); if (allocOffset != -1) { return new Allocation(c.data, allocOffset); } tryRetireChunk(c); } }
MemStoreLAB { public Allocation allocateBytes(int size) { Preconditions.checkArgument(size >= 0, "negative size"); if (size > maxAlloc) { return null; } while (true) { Chunk c = getOrMakeChunk(); int allocOffset = c.alloc(size); if (allocOffset != -1) { return new Allocation(c.data, allocOffset); } tryRetireChunk(c); } } }
MemStoreLAB { public Allocation allocateBytes(int size) { Preconditions.checkArgument(size >= 0, "negative size"); if (size > maxAlloc) { return null; } while (true) { Chunk c = getOrMakeChunk(); int allocOffset = c.alloc(size); if (allocOffset != -1) { return new Allocation(c.data, allocOffset); } tryRetireChunk(c); } } MemStoreLAB();  MemStoreLAB(Configuration conf); }
MemStoreLAB { public Allocation allocateBytes(int size) { Preconditions.checkArgument(size >= 0, "negative size"); if (size > maxAlloc) { return null; } while (true) { Chunk c = getOrMakeChunk(); int allocOffset = c.alloc(size); if (allocOffset != -1) { return new Allocation(c.data, allocOffset); } tryRetireChunk(c); } } MemStoreLAB();  MemStoreLAB(Configuration conf); Allocation allocateBytes(int size); }
MemStoreLAB { public Allocation allocateBytes(int size) { Preconditions.checkArgument(size >= 0, "negative size"); if (size > maxAlloc) { return null; } while (true) { Chunk c = getOrMakeChunk(); int allocOffset = c.alloc(size); if (allocOffset != -1) { return new Allocation(c.data, allocOffset); } tryRetireChunk(c); } } MemStoreLAB();  MemStoreLAB(Configuration conf); Allocation allocateBytes(int size);  }