Search in sources :

Example 61 with DrillBuf

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

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

Example 62 with DrillBuf

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

the class TestBaseAllocator method testAllocator_slicesOfSlices.

@Test
public void testAllocator_slicesOfSlices() throws Exception {
    //    final AllocatorOwner allocatorOwner = new NamedOwner("slicesOfSlices");
    try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
        // Populate a buffer with byte values corresponding to their indices.
        final DrillBuf drillBuf = rootAllocator.buffer(256);
        for (int i = 0; i < 256; ++i) {
            drillBuf.writeByte(i);
        }
        // Slice it up.
        final DrillBuf slice0 = drillBuf.slice(0, drillBuf.capacity());
        for (int i = 0; i < 256; ++i) {
            assertEquals((byte) i, drillBuf.getByte(i));
        }
        final DrillBuf slice10 = slice0.slice(10, drillBuf.capacity() - 10);
        for (int i = 10; i < 256; ++i) {
            assertEquals((byte) i, slice10.getByte(i - 10));
        }
        final DrillBuf slice20 = slice10.slice(10, drillBuf.capacity() - 20);
        for (int i = 20; i < 256; ++i) {
            assertEquals((byte) i, slice20.getByte(i - 20));
        }
        final DrillBuf slice30 = slice20.slice(10, drillBuf.capacity() - 30);
        for (int i = 30; i < 256; ++i) {
            assertEquals((byte) i, slice30.getByte(i - 30));
        }
        drillBuf.release();
    }
}
Also used : DrillBuf(io.netty.buffer.DrillBuf) Test(org.junit.Test)

Example 63 with DrillBuf

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

the class TestBaseAllocator method testAllocator_sliceRanges.

@Test
public void testAllocator_sliceRanges() throws Exception {
    //    final AllocatorOwner allocatorOwner = new NamedOwner("sliceRanges");
    try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
        // Populate a buffer with byte values corresponding to their indices.
        final DrillBuf drillBuf = rootAllocator.buffer(256);
        assertEquals(256, drillBuf.capacity());
        assertEquals(0, drillBuf.readerIndex());
        assertEquals(0, drillBuf.readableBytes());
        assertEquals(0, drillBuf.writerIndex());
        assertEquals(256, drillBuf.writableBytes());
        final DrillBuf slice3 = (DrillBuf) drillBuf.slice();
        assertEquals(0, slice3.readerIndex());
        assertEquals(0, slice3.readableBytes());
        assertEquals(0, slice3.writerIndex());
        for (int i = 0; i < 256; ++i) {
            drillBuf.writeByte(i);
        }
        assertEquals(0, drillBuf.readerIndex());
        assertEquals(256, drillBuf.readableBytes());
        assertEquals(256, drillBuf.writerIndex());
        assertEquals(0, drillBuf.writableBytes());
        final DrillBuf slice1 = (DrillBuf) drillBuf.slice();
        assertEquals(0, slice1.readerIndex());
        assertEquals(256, slice1.readableBytes());
        for (int i = 0; i < 10; ++i) {
            assertEquals(i, slice1.readByte());
        }
        assertEquals(256 - 10, slice1.readableBytes());
        for (int i = 0; i < 256; ++i) {
            assertEquals((byte) i, slice1.getByte(i));
        }
        final DrillBuf slice2 = (DrillBuf) drillBuf.slice(25, 25);
        assertEquals(0, slice2.readerIndex());
        assertEquals(25, slice2.readableBytes());
        for (int i = 25; i < 50; ++i) {
            assertEquals(i, slice2.readByte());
        }
        /*
      for(int i = 256; i > 0; --i) {
        slice3.writeByte(i - 1);
      }
      for(int i = 0; i < 256; ++i) {
        assertEquals(255 - i, slice1.getByte(i));
      }
*/
        // all the derived buffers share this fate
        drillBuf.release();
    }
}
Also used : DrillBuf(io.netty.buffer.DrillBuf) Test(org.junit.Test)

Example 64 with DrillBuf

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

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

Example 65 with DrillBuf

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

the class TestBaseAllocator method testAllocator_sliceUpBufferAndRelease.

private static void testAllocator_sliceUpBufferAndRelease(final RootAllocator rootAllocator, final BufferAllocator bufferAllocator) {
    final DrillBuf drillBuf1 = bufferAllocator.buffer(MAX_ALLOCATION / 2);
    rootAllocator.verify();
    final DrillBuf drillBuf2 = drillBuf1.slice(16, drillBuf1.capacity() - 32);
    rootAllocator.verify();
    final DrillBuf drillBuf3 = drillBuf2.slice(16, drillBuf2.capacity() - 32);
    rootAllocator.verify();
    @SuppressWarnings("unused") final DrillBuf drillBuf4 = drillBuf3.slice(16, drillBuf3.capacity() - 32);
    rootAllocator.verify();
    // since they share refcounts, one is enough to release them all
    drillBuf3.release();
    rootAllocator.verify();
}
Also used : DrillBuf(io.netty.buffer.DrillBuf)

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