Search in sources :

Example 1 with VariableFramePool

use of org.apache.hyracks.dataflow.std.buffermanager.VariableFramePool in project asterixdb by apache.

the class HeapSortRunGenerator method open.

@Override
public void open() throws HyracksDataException {
    IFramePool framePool = new VariableFramePool(ctx, (frameLimit - 1) * ctx.getInitialFrameSize());
    IDeletableTupleBufferManager bufferManager = new VariableDeletableTupleMemoryManager(framePool, recordDescriptor);
    tupleSorter = new TupleSorterHeapSort(ctx, bufferManager, topK, sortFields, nmkFactory, comparatorFactories);
    super.open();
}
Also used : VariableFramePool(org.apache.hyracks.dataflow.std.buffermanager.VariableFramePool) VariableDeletableTupleMemoryManager(org.apache.hyracks.dataflow.std.buffermanager.VariableDeletableTupleMemoryManager) IDeletableTupleBufferManager(org.apache.hyracks.dataflow.std.buffermanager.IDeletableTupleBufferManager) IFramePool(org.apache.hyracks.dataflow.std.buffermanager.IFramePool)

Example 2 with VariableFramePool

use of org.apache.hyracks.dataflow.std.buffermanager.VariableFramePool in project asterixdb by apache.

the class InMemorySortRuntimeFactory method createOneOutputPushRuntime.

@Override
public AbstractOneInputOneOutputPushRuntime createOneOutputPushRuntime(final IHyracksTaskContext ctx) throws HyracksDataException {
    return new AbstractOneInputOneOutputPushRuntime() {

        FrameSorterMergeSort frameSorter = null;

        @Override
        public void open() throws HyracksDataException {
            writer.open();
            if (frameSorter == null) {
                IFrameBufferManager manager = new VariableFrameMemoryManager(new VariableFramePool(ctx, VariableFramePool.UNLIMITED_MEMORY), FrameFreeSlotPolicyFactory.createFreeSlotPolicy(EnumFreeSlotPolicy.LAST_FIT));
                frameSorter = new FrameSorterMergeSort(ctx, manager, sortFields, firstKeyNormalizerFactory, comparatorFactories, outputRecordDesc);
            }
            frameSorter.reset();
        }

        @Override
        public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
            frameSorter.insertFrame(buffer);
        }

        @Override
        public void fail() throws HyracksDataException {
            writer.fail();
        }

        @Override
        public void close() throws HyracksDataException {
            try {
                frameSorter.sort();
                frameSorter.flush(writer);
            } finally {
                writer.close();
            }
        }
    };
}
Also used : VariableFramePool(org.apache.hyracks.dataflow.std.buffermanager.VariableFramePool) AbstractOneInputOneOutputPushRuntime(org.apache.hyracks.algebricks.runtime.operators.base.AbstractOneInputOneOutputPushRuntime) VariableFrameMemoryManager(org.apache.hyracks.dataflow.std.buffermanager.VariableFrameMemoryManager) FrameSorterMergeSort(org.apache.hyracks.dataflow.std.sort.FrameSorterMergeSort) IFrameBufferManager(org.apache.hyracks.dataflow.std.buffermanager.IFrameBufferManager) ByteBuffer(java.nio.ByteBuffer)

Example 3 with VariableFramePool

use of org.apache.hyracks.dataflow.std.buffermanager.VariableFramePool in project asterixdb by apache.

the class HybridTopKSortRunGenerator method nextFrame.

@Override
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
    if (topK <= 0) {
        return;
    }
    inAccessor.reset(buffer);
    if (tupleSorter != null) {
        boolean isBadK = false;
        for (int i = 0; i < inAccessor.getTupleCount(); i++) {
            if (!tupleSorter.insertTuple(inAccessor, i)) {
                flushFramesToRun();
                isBadK = true;
                if (!tupleSorter.insertTuple(inAccessor, i)) {
                    throw new HyracksDataException("The given tuple is too big to insert into the sorting memory.");
                }
            }
        }
        if (isBadK) {
            tupleSorterFlushedTimes++;
            if (tupleSorterFlushedTimes > SWITCH_TO_FRAME_SORTER_THRESHOLD) {
                if (tupleSorter.hasRemaining()) {
                    flushFramesToRun();
                }
                tupleSorter.close();
                tupleSorter = null;
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine("clear tupleSorter");
                }
            }
        }
    } else {
        if (frameSorter == null) {
            VariableFrameMemoryManager bufferManager = new VariableFrameMemoryManager(new VariableFramePool(ctx, (frameLimit - 1) * ctx.getInitialFrameSize()), FrameFreeSlotPolicyFactory.createFreeSlotPolicy(EnumFreeSlotPolicy.BIGGEST_FIT, frameLimit - 1));
            frameSorter = new FrameSorterMergeSort(ctx, bufferManager, sortFields, nmkFactory, comparatorFactories, recordDescriptor, topK);
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("create frameSorter");
            }
        }
        if (!frameSorter.insertFrame(buffer)) {
            flushFramesToRun();
            if (!frameSorter.insertFrame(buffer)) {
                throw new HyracksDataException("The given frame is too big to insert into the sorting memory.");
            }
        }
    }
}
Also used : VariableFramePool(org.apache.hyracks.dataflow.std.buffermanager.VariableFramePool) VariableFrameMemoryManager(org.apache.hyracks.dataflow.std.buffermanager.VariableFrameMemoryManager) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

VariableFramePool (org.apache.hyracks.dataflow.std.buffermanager.VariableFramePool)3 VariableFrameMemoryManager (org.apache.hyracks.dataflow.std.buffermanager.VariableFrameMemoryManager)2 ByteBuffer (java.nio.ByteBuffer)1 AbstractOneInputOneOutputPushRuntime (org.apache.hyracks.algebricks.runtime.operators.base.AbstractOneInputOneOutputPushRuntime)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 IDeletableTupleBufferManager (org.apache.hyracks.dataflow.std.buffermanager.IDeletableTupleBufferManager)1 IFrameBufferManager (org.apache.hyracks.dataflow.std.buffermanager.IFrameBufferManager)1 IFramePool (org.apache.hyracks.dataflow.std.buffermanager.IFramePool)1 VariableDeletableTupleMemoryManager (org.apache.hyracks.dataflow.std.buffermanager.VariableDeletableTupleMemoryManager)1 FrameSorterMergeSort (org.apache.hyracks.dataflow.std.sort.FrameSorterMergeSort)1