Search in sources :

Example 56 with DrillBuf

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

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

Example 57 with DrillBuf

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

the class TestBaseAllocator method test_privateMax.

/*
  // ---------------------------------------- DEBUG -----------------------------------

  @After
  public void checkBuffers() {
    final int bufferCount = UnsafeDirectLittleEndian.getBufferCount();
    if (bufferCount != 0) {
      UnsafeDirectLittleEndian.logBuffers(logger);
      UnsafeDirectLittleEndian.releaseBuffers();
    }

    assertEquals(0, bufferCount);
  }

//  @AfterClass
//  public static void dumpBuffers() {
//    UnsafeDirectLittleEndian.logBuffers(logger);
//  }

  // ---------------------------------------- DEBUG ------------------------------------
*/
@Test
public void test_privateMax() throws Exception {
    try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
        final DrillBuf drillBuf1 = rootAllocator.buffer(MAX_ALLOCATION / 2);
        assertNotNull("allocation failed", drillBuf1);
        try (final BufferAllocator childAllocator = rootAllocator.newChildAllocator("noLimits", 0, MAX_ALLOCATION)) {
            final DrillBuf drillBuf2 = childAllocator.buffer(MAX_ALLOCATION / 2);
            assertNotNull("allocation failed", drillBuf2);
            drillBuf2.release();
        }
        drillBuf1.release();
    }
}
Also used : DrillBuf(io.netty.buffer.DrillBuf) Test(org.junit.Test)

Example 58 with DrillBuf

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

the class TestAllocators method ensureDrillBufReadIndexIsZero.

/**
   * Contract for DrillBuf[] returned from getBuffers() is that buffers are returned in a reader appropriate state
   * (i.e., readIndex = 0)
   *
   * Before this patch, the following scenario breaks this contract:
   * As data being read from DrillBuf, readIndex will be pushed forward. And, later on,
   * when DrillBuf[] are read from the ValueVector, readIndex will point at the location of the most recent reading
   *
   * This unit test is added to ensure that the readIndex points at zero under this scenario
   */
// DRILL-3854
@Test
public void ensureDrillBufReadIndexIsZero() throws Exception {
    final int length = 10;
    final Properties props = new Properties() {

        {
            put(RootAllocatorFactory.TOP_LEVEL_MAX_ALLOC, "1000000");
        }
    };
    final DrillConfig config = DrillConfig.create(props);
    final BufferAllocator allc = RootAllocatorFactory.newRoot(config);
    final TypeProtos.MajorType.Builder builder = TypeProtos.MajorType.newBuilder();
    builder.setMinorType(TypeProtos.MinorType.INT);
    builder.setMode(TypeProtos.DataMode.REQUIRED);
    final IntVector iv = new IntVector(MaterializedField.create("Field", builder.build()), allc);
    iv.allocateNew();
    // Write data to DrillBuf
    for (int i = 0; i < length; ++i) {
        iv.getBuffer().writeInt(i);
    }
    // Read data to DrillBuf
    for (int i = 0; i < length; ++i) {
        assertEquals(i, iv.getBuffer().readInt());
    }
    for (DrillBuf drillBuf : iv.getBuffers(false)) {
        assertEquals(0, drillBuf.readInt());
    }
    final List<DrillBuf> toBeClean = Lists.newArrayList();
    for (DrillBuf drillBuf : iv.getBuffers(true)) {
        assertEquals(0, drillBuf.readInt());
        toBeClean.add(drillBuf);
    }
    for (DrillBuf drillBuf : toBeClean) {
        drillBuf.release();
    }
    allc.close();
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) IntVector(org.apache.drill.exec.vector.IntVector) Properties(java.util.Properties) DrillBuf(io.netty.buffer.DrillBuf) DrillTest(org.apache.drill.test.DrillTest) Test(org.junit.Test)

Example 59 with DrillBuf

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

the class TestAllocators method testTransfer.

@Test
public void testTransfer() throws Exception {
    final Properties props = new Properties() {

        {
            put(RootAllocatorFactory.TOP_LEVEL_MAX_ALLOC, "1049600");
        }
    };
    final DrillConfig config = DrillConfig.create(props);
    BufferAllocator a = RootAllocatorFactory.newRoot(config);
    BufferAllocator a1 = a.newChildAllocator("a1", 0, Integer.MAX_VALUE);
    BufferAllocator a2 = a.newChildAllocator("a2", 0, Integer.MAX_VALUE);
    DrillBuf buf1 = a1.buffer(1_000_000);
    DrillBuf buf2 = a2.buffer(1_000);
    DrillBuf buf3 = buf1.transferOwnership(a2).buffer;
    buf1.release();
    buf2.release();
    buf3.release();
    a1.close();
    a2.close();
    a.close();
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) Properties(java.util.Properties) DrillBuf(io.netty.buffer.DrillBuf) DrillTest(org.apache.drill.test.DrillTest) Test(org.junit.Test)

Example 60 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)

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