Search in sources :

Example 66 with DrillBuf

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

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) Test(org.junit.Test)

Example 67 with DrillBuf

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

the class TestBaseAllocator method testRootAllocator_createChildAndUse.

@Test
public void testRootAllocator_createChildAndUse() throws Exception {
    try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
        try (final BufferAllocator childAllocator = rootAllocator.newChildAllocator("createChildAndUse", 0, MAX_ALLOCATION)) {
            final DrillBuf drillBuf = childAllocator.buffer(512);
            assertNotNull("allocation failed", drillBuf);
            drillBuf.release();
        }
    }
}
Also used : DrillBuf(io.netty.buffer.DrillBuf) Test(org.junit.Test)

Example 68 with DrillBuf

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

the class TestBaseAllocator method testAllocator_transferShared.

@Test
public void testAllocator_transferShared() throws Exception {
    try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
        final BufferAllocator childAllocator1 = rootAllocator.newChildAllocator("transferShared1", 0, MAX_ALLOCATION);
        final BufferAllocator childAllocator2 = rootAllocator.newChildAllocator("transferShared2", 0, MAX_ALLOCATION);
        final BufferAllocator childAllocator3 = rootAllocator.newChildAllocator("transferShared3", 0, MAX_ALLOCATION);
        final DrillBuf drillBuf1 = childAllocator1.buffer(MAX_ALLOCATION / 8);
        boolean allocationFit;
        DrillBuf drillBuf2 = drillBuf1.retain(childAllocator2);
        rootAllocator.verify();
        assertNotNull(drillBuf2);
        assertNotEquals(drillBuf2, drillBuf1);
        TransferResult result = drillBuf1.transferOwnership(childAllocator3);
        allocationFit = result.allocationFit;
        final DrillBuf drillBuf3 = result.buffer;
        assertTrue(allocationFit);
        rootAllocator.verify();
        // Since childAllocator3 now has childAllocator1's buffer, 1, can close
        drillBuf1.release();
        childAllocator1.close();
        rootAllocator.verify();
        drillBuf2.release();
        childAllocator2.close();
        rootAllocator.verify();
        final BufferAllocator childAllocator4 = rootAllocator.newChildAllocator("transferShared4", 0, MAX_ALLOCATION);
        TransferResult result2 = drillBuf3.transferOwnership(childAllocator4);
        allocationFit = result.allocationFit;
        final DrillBuf drillBuf4 = result2.buffer;
        assertTrue(allocationFit);
        rootAllocator.verify();
        drillBuf3.release();
        childAllocator3.close();
        rootAllocator.verify();
        drillBuf4.release();
        childAllocator4.close();
        rootAllocator.verify();
    }
}
Also used : TransferResult(io.netty.buffer.DrillBuf.TransferResult) DrillBuf(io.netty.buffer.DrillBuf) Test(org.junit.Test)

Aggregations

DrillBuf (io.netty.buffer.DrillBuf)68 Test (org.junit.Test)24 SelectionVector4 (org.apache.drill.exec.record.selection.SelectionVector4)8 IOException (java.io.IOException)6 ValueVector (org.apache.drill.exec.vector.ValueVector)6 Stopwatch (com.google.common.base.Stopwatch)5 MaterializedField (org.apache.drill.exec.record.MaterializedField)5 ExecTest (org.apache.drill.exec.ExecTest)4 TransferResult (io.netty.buffer.DrillBuf.TransferResult)3 DrillConfig (org.apache.drill.common.config.DrillConfig)3 UserException (org.apache.drill.common.exceptions.UserException)3 OutOfMemoryException (org.apache.drill.exec.exception.OutOfMemoryException)3 SerializedField (org.apache.drill.exec.proto.UserBitShared.SerializedField)3 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)3 ByteBuf (io.netty.buffer.ByteBuf)2 ByteBuffer (java.nio.ByteBuffer)2 Properties (java.util.Properties)2 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)2 IntVector (org.apache.drill.exec.vector.IntVector)2 DrillTest (org.apache.drill.test.DrillTest)2