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);
}
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++;
}
}
}
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++;
}
}
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);
}
}
}
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();
}
}
Aggregations