Search in sources :

Example 91 with DrillBuf

use of io.netty.buffer.DrillBuf in project drill by axbaretto.

the class TestBaseAllocator method allocateAndFree.

private static void allocateAndFree(final BufferAllocator allocator) {
    final DrillBuf drillBuf = allocator.buffer(512);
    assertNotNull("allocation failed", drillBuf);
    drillBuf.release();
    final DrillBuf drillBuf2 = allocator.buffer(MAX_ALLOCATION);
    assertNotNull("allocation failed", drillBuf2);
    drillBuf2.release();
    final int nBufs = 8;
    final DrillBuf[] drillBufs = new DrillBuf[nBufs];
    for (int i = 0; i < drillBufs.length; ++i) {
        DrillBuf drillBufi = allocator.buffer(MAX_ALLOCATION / nBufs);
        assertNotNull("allocation failed", drillBufi);
        drillBufs[i] = drillBufi;
    }
    for (DrillBuf drillBufi : drillBufs) {
        drillBufi.release();
    }
}
Also used : DrillBuf(io.netty.buffer.DrillBuf)

Example 92 with DrillBuf

use of io.netty.buffer.DrillBuf in project drill by axbaretto.

the class TestBaseAllocator method testAllocator_transferSliced.

@Test
public void testAllocator_transferSliced() throws Exception {
    try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
        final BufferAllocator childAllocator1 = rootAllocator.newChildAllocator("transferSliced1", 0, MAX_ALLOCATION);
        final BufferAllocator childAllocator2 = rootAllocator.newChildAllocator("transferSliced2", 0, MAX_ALLOCATION);
        final DrillBuf drillBuf1 = childAllocator1.buffer(MAX_ALLOCATION / 8);
        final DrillBuf drillBuf2 = childAllocator2.buffer(MAX_ALLOCATION / 8);
        final DrillBuf drillBuf1s = drillBuf1.slice(0, drillBuf1.capacity() / 2);
        final DrillBuf drillBuf2s = drillBuf2.slice(0, drillBuf2.capacity() / 2);
        rootAllocator.verify();
        TransferResult result1 = drillBuf2s.transferOwnership(childAllocator1);
        rootAllocator.verify();
        TransferResult result2 = drillBuf1s.transferOwnership(childAllocator2);
        rootAllocator.verify();
        result1.buffer.release();
        result2.buffer.release();
        // releases drillBuf1
        drillBuf1s.release();
        // releases drillBuf2
        drillBuf2s.release();
        childAllocator1.close();
        childAllocator2.close();
    }
}
Also used : TransferResult(io.netty.buffer.DrillBuf.TransferResult) DrillBuf(io.netty.buffer.DrillBuf) MemoryTest(org.apache.drill.categories.MemoryTest) Test(org.junit.Test)

Example 93 with DrillBuf

use of io.netty.buffer.DrillBuf in project drill by axbaretto.

the class TestBaseAllocator method testAllocator_shareSliced.

@Test
public void testAllocator_shareSliced() throws Exception {
    try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
        final BufferAllocator childAllocator1 = rootAllocator.newChildAllocator("transferSliced", 0, MAX_ALLOCATION);
        final BufferAllocator childAllocator2 = rootAllocator.newChildAllocator("transferSliced", 0, MAX_ALLOCATION);
        final DrillBuf drillBuf1 = childAllocator1.buffer(MAX_ALLOCATION / 8);
        final DrillBuf drillBuf2 = childAllocator2.buffer(MAX_ALLOCATION / 8);
        final DrillBuf drillBuf1s = drillBuf1.slice(0, drillBuf1.capacity() / 2);
        final DrillBuf drillBuf2s = drillBuf2.slice(0, drillBuf2.capacity() / 2);
        rootAllocator.verify();
        final DrillBuf drillBuf2s1 = drillBuf2s.retain(childAllocator1);
        final DrillBuf drillBuf1s2 = drillBuf1s.retain(childAllocator2);
        rootAllocator.verify();
        // releases drillBuf1
        drillBuf1s.release();
        // releases drillBuf2
        drillBuf2s.release();
        rootAllocator.verify();
        // releases the shared drillBuf2 slice
        drillBuf2s1.release();
        // releases the shared drillBuf1 slice
        drillBuf1s2.release();
        childAllocator1.close();
        childAllocator2.close();
    }
}
Also used : DrillBuf(io.netty.buffer.DrillBuf) MemoryTest(org.apache.drill.categories.MemoryTest) Test(org.junit.Test)

Example 94 with DrillBuf

use of io.netty.buffer.DrillBuf in project drill by axbaretto.

the class TestBaseAllocator method multiple.

@Test
public void multiple() throws Exception {
    final String owner = "test";
    try (RootAllocator allocator = new RootAllocator(Long.MAX_VALUE)) {
        final int op = 100000;
        BufferAllocator frag1 = allocator.newChildAllocator(owner, 1500000, Long.MAX_VALUE);
        BufferAllocator frag2 = allocator.newChildAllocator(owner, 500000, Long.MAX_VALUE);
        allocator.verify();
        BufferAllocator allocator11 = frag1.newChildAllocator(owner, op, Long.MAX_VALUE);
        DrillBuf b11 = allocator11.buffer(1000000);
        allocator.verify();
        BufferAllocator allocator12 = frag1.newChildAllocator(owner, op, Long.MAX_VALUE);
        DrillBuf b12 = allocator12.buffer(500000);
        allocator.verify();
        BufferAllocator allocator21 = frag1.newChildAllocator(owner, op, Long.MAX_VALUE);
        allocator.verify();
        BufferAllocator allocator22 = frag2.newChildAllocator(owner, op, Long.MAX_VALUE);
        DrillBuf b22 = allocator22.buffer(2000000);
        allocator.verify();
        BufferAllocator frag3 = allocator.newChildAllocator(owner, 1000000, Long.MAX_VALUE);
        allocator.verify();
        BufferAllocator allocator31 = frag3.newChildAllocator(owner, op, Long.MAX_VALUE);
        DrillBuf b31a = allocator31.buffer(200000);
        allocator.verify();
        // Previously running operator completes
        b22.release();
        allocator.verify();
        allocator22.close();
        b31a.release();
        allocator31.close();
        b12.release();
        allocator12.close();
        allocator21.close();
        b11.release();
        allocator11.close();
        frag1.close();
        frag2.close();
        frag3.close();
    }
}
Also used : DrillBuf(io.netty.buffer.DrillBuf) MemoryTest(org.apache.drill.categories.MemoryTest) Test(org.junit.Test)

Example 95 with DrillBuf

use of io.netty.buffer.DrillBuf in project drill by axbaretto.

the class TestBaseAllocator method testAllocator_shareOwnership.

@Test
public void testAllocator_shareOwnership() throws Exception {
    try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
        final BufferAllocator childAllocator1 = rootAllocator.newChildAllocator("shareOwnership1", 0, MAX_ALLOCATION);
        final BufferAllocator childAllocator2 = rootAllocator.newChildAllocator("shareOwnership2", 0, MAX_ALLOCATION);
        final DrillBuf drillBuf1 = childAllocator1.buffer(MAX_ALLOCATION / 4);
        rootAllocator.verify();
        // share ownership of buffer.
        final DrillBuf drillBuf2 = drillBuf1.retain(childAllocator2);
        rootAllocator.verify();
        assertNotNull(drillBuf2);
        assertNotEquals(drillBuf2, drillBuf1);
        // release original buffer (thus transferring ownership to allocator 2. (should leave allocator 1 in empty state)
        drillBuf1.release();
        rootAllocator.verify();
        childAllocator1.close();
        rootAllocator.verify();
        final BufferAllocator childAllocator3 = rootAllocator.newChildAllocator("shareOwnership3", 0, MAX_ALLOCATION);
        final DrillBuf drillBuf3 = drillBuf1.retain(childAllocator3);
        assertNotNull(drillBuf3);
        assertNotEquals(drillBuf3, drillBuf1);
        assertNotEquals(drillBuf3, drillBuf2);
        rootAllocator.verify();
        drillBuf2.release();
        rootAllocator.verify();
        childAllocator2.close();
        rootAllocator.verify();
        drillBuf3.release();
        rootAllocator.verify();
        childAllocator3.close();
    }
}
Also used : DrillBuf(io.netty.buffer.DrillBuf) MemoryTest(org.apache.drill.categories.MemoryTest) Test(org.junit.Test)

Aggregations

DrillBuf (io.netty.buffer.DrillBuf)187 Test (org.junit.Test)63 MemoryTest (org.apache.drill.categories.MemoryTest)38 SelectionVector4 (org.apache.drill.exec.record.selection.SelectionVector4)22 ValueVector (org.apache.drill.exec.vector.ValueVector)18 BaseTest (org.apache.drill.test.BaseTest)18 MaterializedField (org.apache.drill.exec.record.MaterializedField)16 IOException (java.io.IOException)13 VectorTest (org.apache.drill.categories.VectorTest)13 OutOfMemoryException (org.apache.drill.exec.exception.OutOfMemoryException)13 ExecTest (org.apache.drill.exec.ExecTest)11 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)11 VectorContainer (org.apache.drill.exec.record.VectorContainer)10 Stopwatch (com.google.common.base.Stopwatch)9 ByteBuffer (java.nio.ByteBuffer)9 BatchSchema (org.apache.drill.exec.record.BatchSchema)9 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)8 UserBitShared (org.apache.drill.exec.proto.UserBitShared)8 SerializedField (org.apache.drill.exec.proto.UserBitShared.SerializedField)8 DrillTest (org.apache.drill.test.DrillTest)8