public void deallocate(ByteBuffer buffer) { deallocate(buffer, buffer.capacity()); }
public void run() { try { latch.await(); } catch (InterruptedException e) { e.printStackTrace(); } pool.deallocate(buffer); } };
@Override public void deallocate(ByteBuffer buffer, int size) { if (!allocatedBuffers.containsKey(buffer)) { throw new IllegalStateException("Deallocating a buffer that is not allocated"); } allocatedBuffers.remove(buffer); super.deallocate(buffer, size); }
public void run() { Time.SYSTEM.sleep(delayMs); pool.deallocate(buffer); } };
/** * Deallocate the record batch */ public void deallocate(ProducerBatch batch) { incomplete.remove(batch); // Only deallocate the batch if it is not a split batch because split batch are allocated outside the // buffer pool. if (!batch.isSplitBatch()) free.deallocate(batch.buffer(), batch.initialCapacity()); }
public void run() { try { for (int i = 0; i < iterations; i++) { int size; if (TestUtils.RANDOM.nextBoolean()) // allocate poolable size size = pool.poolableSize(); else // allocate a random size size = TestUtils.RANDOM.nextInt((int) pool.totalMemory()); ByteBuffer buffer = pool.allocate(size, maxBlockTimeMs); pool.deallocate(buffer); } success.set(true); } catch (Exception e) { e.printStackTrace(); } } }
/** * Test that we cannot try to allocate more memory then we have in the whole pool */ @Test(expected = IllegalArgumentException.class) public void testCantAllocateMoreMemoryThanWeHave() throws Exception { BufferPool pool = new BufferPool(1024, 512, metrics, time, metricGroup); ByteBuffer buffer = pool.allocate(1024, maxBlockTimeMs); assertEquals(1024, buffer.limit()); pool.deallocate(buffer); pool.allocate(1025, maxBlockTimeMs); }
free.deallocate(buffer); appendsInProgress.decrementAndGet();
/** * Test the simple non-blocking allocation paths */ @Test public void testSimple() throws Exception { long totalMemory = 64 * 1024; int size = 1024; BufferPool pool = new BufferPool(totalMemory, size, metrics, time, metricGroup); ByteBuffer buffer = pool.allocate(size, maxBlockTimeMs); assertEquals("Buffer size should equal requested size.", size, buffer.limit()); assertEquals("Unallocated memory should have shrunk", totalMemory - size, pool.unallocatedMemory()); assertEquals("Available memory should have shrunk", totalMemory - size, pool.availableMemory()); buffer.putInt(1); buffer.flip(); pool.deallocate(buffer); assertEquals("All memory should be available", totalMemory, pool.availableMemory()); assertEquals("But now some is on the free list", totalMemory - size, pool.unallocatedMemory()); buffer = pool.allocate(size, maxBlockTimeMs); assertEquals("Recycled buffer should be cleared.", 0, buffer.position()); assertEquals("Recycled buffer should be cleared.", buffer.capacity(), buffer.limit()); pool.deallocate(buffer); assertEquals("All memory should be available", totalMemory, pool.availableMemory()); assertEquals("Still a single buffer on the free list", totalMemory - size, pool.unallocatedMemory()); buffer = pool.allocate(2 * size, maxBlockTimeMs); pool.deallocate(buffer); assertEquals("All memory should be available", totalMemory, pool.availableMemory()); assertEquals("Non-standard size didn't go to the free list.", totalMemory - size, pool.unallocatedMemory()); }
public void deallocate(ByteBuffer buffer) { deallocate(buffer, buffer.capacity()); }
/** * Deallocate the record batch */ public void deallocate(RecordBatch batch) { free.deallocate(batch.records.buffer(), batch.records.capacity()); }
free.deallocate(buffer); return new RecordAppendResult(future, dq.size() > 1 || last.records.isFull(), false);