Search in sources :

Example 51 with DrillBuf

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

the class MSortTemplate method setup.

@Override
public void setup(final FragmentContext context, final BufferAllocator allocator, final SelectionVector4 vector4, final VectorContainer hyperBatch) throws SchemaChangeException {
    // we pass in the local hyperBatch since that is where we'll be reading data.
    Preconditions.checkNotNull(vector4);
    this.vector4 = vector4.createNewWrapperCurrent();
    this.context = context;
    vector4.clear();
    doSetup(context, hyperBatch, null);
    runStarts.add(0);
    int batch = 0;
    final int totalCount = this.vector4.getTotalCount();
    for (int i = 0; i < totalCount; i++) {
        final int newBatch = this.vector4.get(i) >>> 16;
        if (newBatch == batch) {
            continue;
        } else if (newBatch == batch + 1) {
            runStarts.add(i);
            batch = newBatch;
        } else {
            throw new UnsupportedOperationException(String.format("Missing batch. batch: %d newBatch: %d", batch, newBatch));
        }
    }
    final DrillBuf drillBuf = allocator.buffer(4 * totalCount);
    try {
        desiredRecordBatchCount = context.getConfig().getInt(ExecConstants.EXTERNAL_SORT_MSORT_MAX_BATCHSIZE);
    } catch (ConfigException.Missing e) {
        // value not found, use default value instead
        desiredRecordBatchCount = Character.MAX_VALUE;
    }
    aux = new SelectionVector4(drillBuf, totalCount, desiredRecordBatchCount);
}
Also used : ConfigException(com.typesafe.config.ConfigException) DrillBuf(io.netty.buffer.DrillBuf) SelectionVector4(org.apache.drill.exec.record.selection.SelectionVector4)

Example 52 with DrillBuf

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

the class PriorityQueueCopierTemplate method setup.

@Override
public void setup(FragmentContext context, BufferAllocator allocator, VectorAccessible hyperBatch, List<BatchGroup> batchGroups, VectorAccessible outgoing) throws SchemaChangeException {
    this.hyperBatch = hyperBatch;
    this.batchGroups = batchGroups;
    this.outgoing = outgoing;
    this.size = batchGroups.size();
    @SuppressWarnings("resource") final DrillBuf drillBuf = allocator.buffer(4 * size);
    vector4 = new SelectionVector4(drillBuf, size, Character.MAX_VALUE);
    doSetup(context, hyperBatch, outgoing);
    queueSize = 0;
    for (int i = 0; i < size; i++) {
        int index = batchGroups.get(i).getNextIndex();
        vector4.set(i, i, index);
        if (index > -1) {
            siftUp();
            queueSize++;
        }
    }
}
Also used : DrillBuf(io.netty.buffer.DrillBuf) SelectionVector4(org.apache.drill.exec.record.selection.SelectionVector4)

Example 53 with DrillBuf

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

the class PriorityQueueCopierTemplate method setup.

@Override
public void setup(FragmentContext context, BufferAllocator allocator, VectorAccessible hyperBatch, List<BatchGroup> batchGroups, VectorAccessible outgoing) throws SchemaChangeException {
    this.hyperBatch = hyperBatch;
    this.batchGroups = batchGroups;
    this.outgoing = outgoing;
    this.size = batchGroups.size();
    final DrillBuf drillBuf = allocator.buffer(4 * size);
    vector4 = new SelectionVector4(drillBuf, size, Character.MAX_VALUE);
    doSetup(context, hyperBatch, outgoing);
    queueSize = 0;
    for (int i = 0; i < size; i++) {
        vector4.set(i, i, batchGroups.get(i).getNextIndex());
        siftUp();
        queueSize++;
    }
}
Also used : DrillBuf(io.netty.buffer.DrillBuf) SelectionVector4(org.apache.drill.exec.record.selection.SelectionVector4)

Example 54 with DrillBuf

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

the class BaseAllocator method buffer.

@Override
public DrillBuf buffer(final int initialRequestSize, BufferManager manager) {
    assertOpen();
    Preconditions.checkArgument(initialRequestSize >= 0, "the requested size must be non-negative");
    if (initialRequestSize == 0) {
        return empty;
    }
    // round to next largest power of two if we're within a chunk since that is how our allocator operates
    final int actualRequestSize = initialRequestSize < CHUNK_SIZE ? nextPowerOfTwo(initialRequestSize) : initialRequestSize;
    AllocationOutcome outcome = this.allocateBytes(actualRequestSize);
    if (!outcome.isOk()) {
        throw new OutOfMemoryException(createErrorMsg(this, actualRequestSize, initialRequestSize));
    }
    boolean success = false;
    try {
        DrillBuf buffer = bufferWithoutReservation(actualRequestSize, manager);
        success = true;
        return buffer;
    } finally {
        if (!success) {
            releaseBytes(actualRequestSize);
        }
    }
}
Also used : OutOfMemoryException(org.apache.drill.exec.exception.OutOfMemoryException) DrillBuf(io.netty.buffer.DrillBuf)

Example 55 with DrillBuf

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

the class TestBaseAllocator method testAllocator_createSlices.

@Test
public void testAllocator_createSlices() throws Exception {
    try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
        testAllocator_sliceUpBufferAndRelease(rootAllocator, rootAllocator);
        try (final BufferAllocator childAllocator = rootAllocator.newChildAllocator("createSlices", 0, MAX_ALLOCATION)) {
            testAllocator_sliceUpBufferAndRelease(rootAllocator, childAllocator);
        }
        rootAllocator.verify();
        testAllocator_sliceUpBufferAndRelease(rootAllocator, rootAllocator);
        try (final BufferAllocator childAllocator = rootAllocator.newChildAllocator("createSlices", 0, MAX_ALLOCATION)) {
            try (final BufferAllocator childAllocator2 = childAllocator.newChildAllocator("createSlices", 0, MAX_ALLOCATION)) {
                final DrillBuf drillBuf1 = childAllocator2.buffer(MAX_ALLOCATION / 8);
                @SuppressWarnings("unused") final DrillBuf drillBuf2 = drillBuf1.slice(MAX_ALLOCATION / 16, MAX_ALLOCATION / 16);
                testAllocator_sliceUpBufferAndRelease(rootAllocator, childAllocator);
                drillBuf1.release();
                rootAllocator.verify();
            }
            rootAllocator.verify();
            testAllocator_sliceUpBufferAndRelease(rootAllocator, childAllocator);
        }
        rootAllocator.verify();
    }
}
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