Search in sources :

Example 6 with VSizeFrame

use of org.apache.hyracks.api.comm.VSizeFrame in project asterixdb by apache.

the class InputHandlerTest method testMemoryFixedSizeFrameWithSpillNoDiscard.

/*
     * Spill = true;
     * Discard = false;
     * Fixed size frames
     */
@Test
public void testMemoryFixedSizeFrameWithSpillNoDiscard() {
    try {
        IHyracksTaskContext ctx = TestUtils.create(DEFAULT_FRAME_SIZE);
        // Spill budget = Memory budget, No discard
        FeedPolicyAccessor fpa = createFeedPolicyAccessor(true, false, DEFAULT_FRAME_SIZE * NUM_FRAMES, DISCARD_ALLOWANCE);
        // Non-Active Writer
        TestControlledFrameWriter writer = FrameWriterTestUtils.create(DEFAULT_FRAME_SIZE, false);
        writer.freeze();
        // FramePool
        ConcurrentFramePool framePool = new ConcurrentFramePool(NODE_ID, FEED_MEM_BUDGET, DEFAULT_FRAME_SIZE);
        FeedRuntimeInputHandler handler = createInputHandler(ctx, writer, fpa, framePool);
        handler.open();
        VSizeFrame frame = new VSizeFrame(ctx);
        // add NUM_FRAMES times
        for (int i = 0; i < NUM_FRAMES; i++) {
            handler.nextFrame(frame.getBuffer());
        }
        // Next call should NOT block. we will do it in a different thread
        Future<?> result = EXECUTOR.submit(new Pusher(frame.getBuffer(), handler));
        result.get();
        // Check that no records were discarded
        Assert.assertEquals(handler.getNumDiscarded(), 0);
        // Check that one frame is spilled
        Assert.assertEquals(handler.getNumSpilled(), 1);
        // consume memory frames
        writer.unfreeze();
        handler.close();
        Assert.assertEquals(handler.framesOnDisk(), 0);
    // exit
    } catch (Throwable th) {
        th.printStackTrace();
        Assert.fail();
    }
    Assert.assertNull(cause);
}
Also used : ConcurrentFramePool(org.apache.asterix.common.memory.ConcurrentFramePool) FeedRuntimeInputHandler(org.apache.asterix.external.feed.dataflow.FeedRuntimeInputHandler) FeedPolicyAccessor(org.apache.asterix.external.feed.policy.FeedPolicyAccessor) TestControlledFrameWriter(org.apache.hyracks.api.test.TestControlledFrameWriter) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) Test(org.junit.Test)

Example 7 with VSizeFrame

use of org.apache.hyracks.api.comm.VSizeFrame in project asterixdb by apache.

the class InputHandlerTest method testMemoryFixedSizeFrameNoDiskNoDiscardFastConsumer.

/*
     * Spill = false;
     * Discard = false;
     * Fixed size frames
     * Very fast next operator
     */
@Test
public void testMemoryFixedSizeFrameNoDiskNoDiscardFastConsumer() {
    try {
        int numRounds = 10;
        IHyracksTaskContext ctx = TestUtils.create(DEFAULT_FRAME_SIZE);
        // No spill, No discard
        FeedPolicyAccessor fpa = createFeedPolicyAccessor(false, false, 0L, DISCARD_ALLOWANCE);
        // Non-Active Writer
        TestFrameWriter writer = FrameWriterTestUtils.create(Collections.emptyList(), Collections.emptyList(), false);
        // FramePool
        ConcurrentFramePool framePool = new ConcurrentFramePool(NODE_ID, FEED_MEM_BUDGET, DEFAULT_FRAME_SIZE);
        FeedRuntimeInputHandler handler = createInputHandler(ctx, writer, fpa, framePool);
        handler.open();
        VSizeFrame frame = new VSizeFrame(ctx);
        // add NUM_FRAMES times
        for (int i = 0; i < NUM_FRAMES * numRounds; i++) {
            handler.nextFrame(frame.getBuffer());
        }
        // Check that no records were discarded
        Assert.assertEquals(handler.getNumDiscarded(), 0);
        // Check that no records were spilled
        Assert.assertEquals(handler.getNumSpilled(), 0);
        writer.validate(false);
        handler.close();
        // Check that nextFrame was called
        Assert.assertEquals(NUM_FRAMES * numRounds, writer.nextFrameCount());
        writer.validate(true);
    } catch (Throwable th) {
        th.printStackTrace();
        Assert.fail();
    }
    Assert.assertNull(cause);
}
Also used : ConcurrentFramePool(org.apache.asterix.common.memory.ConcurrentFramePool) FeedRuntimeInputHandler(org.apache.asterix.external.feed.dataflow.FeedRuntimeInputHandler) FeedPolicyAccessor(org.apache.asterix.external.feed.policy.FeedPolicyAccessor) TestFrameWriter(org.apache.hyracks.api.test.TestFrameWriter) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) Test(org.junit.Test)

Example 8 with VSizeFrame

use of org.apache.hyracks.api.comm.VSizeFrame in project asterixdb by apache.

the class FrameFixedFieldTupleAppenderTest method testResetShouldWork.

@Test
public void testResetShouldWork() throws HyracksDataException {
    testAppendFieldShouldSucceed();
    appender.reset(new VSizeFrame(new FrameManager(TEST_FRAME_SIZE)), true);
    testAppendFieldShouldSucceed();
}
Also used : FrameManager(org.apache.hyracks.control.nc.resources.memory.FrameManager) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) Test(org.junit.Test)

Example 9 with VSizeFrame

use of org.apache.hyracks.api.comm.VSizeFrame in project asterixdb by apache.

the class AbstractIntegrationTest method readResults.

protected List<String> readResults(JobSpecification spec, JobId jobId, ResultSetId resultSetId) throws Exception {
    int nReaders = 1;
    IFrameTupleAccessor frameTupleAccessor = new ResultFrameTupleAccessor();
    IHyracksDataset hyracksDataset = new HyracksDataset(hcc, spec.getFrameSize(), nReaders);
    IHyracksDatasetReader reader = hyracksDataset.createReader(jobId, resultSetId);
    List<String> resultRecords = new ArrayList<>();
    ByteBufferInputStream bbis = new ByteBufferInputStream();
    FrameManager resultDisplayFrameMgr = new FrameManager(spec.getFrameSize());
    VSizeFrame frame = new VSizeFrame(resultDisplayFrameMgr);
    int readSize = reader.read(frame);
    while (readSize > 0) {
        try {
            frameTupleAccessor.reset(frame.getBuffer());
            for (int tIndex = 0; tIndex < frameTupleAccessor.getTupleCount(); tIndex++) {
                int start = frameTupleAccessor.getTupleStartOffset(tIndex);
                int length = frameTupleAccessor.getTupleEndOffset(tIndex) - start;
                bbis.setByteBuffer(frame.getBuffer(), start);
                byte[] recordBytes = new byte[length];
                bbis.read(recordBytes, 0, length);
                resultRecords.add(new String(recordBytes, 0, length));
            }
        } finally {
            bbis.close();
        }
        readSize = reader.read(frame);
    }
    return resultRecords;
}
Also used : ArrayList(java.util.ArrayList) ByteBufferInputStream(org.apache.hyracks.dataflow.common.comm.util.ByteBufferInputStream) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) HyracksDataset(org.apache.hyracks.client.dataset.HyracksDataset) IHyracksDataset(org.apache.hyracks.api.dataset.IHyracksDataset) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) FrameManager(org.apache.hyracks.control.nc.resources.memory.FrameManager) ResultFrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.ResultFrameTupleAccessor) IHyracksDatasetReader(org.apache.hyracks.api.dataset.IHyracksDatasetReader) IHyracksDataset(org.apache.hyracks.api.dataset.IHyracksDataset)

Example 10 with VSizeFrame

use of org.apache.hyracks.api.comm.VSizeFrame in project asterixdb by apache.

the class InputFrameGenerator method generateDataFrame.

public List<IFrame> generateDataFrame(RecordDescriptor recordDescriptor, List<Object[]> listOfObject) throws HyracksDataException {
    List<IFrame> listFrame = new ArrayList<>();
    VSizeFrame frame = new VSizeFrame(manager);
    FrameFixedFieldAppender appender = new FrameFixedFieldAppender(recordDescriptor.getFieldCount());
    appender.reset(frame, true);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(manager.getInitialFrameSize());
    DataOutputStream ds = new DataOutputStream(baos);
    for (Object[] objs : listOfObject) {
        for (int i = 0; i < recordDescriptor.getFieldCount(); i++) {
            baos.reset();
            recordDescriptor.getFields()[i].serialize(objs[i], ds);
            if (!appender.appendField(baos.toByteArray(), 0, baos.size())) {
                listFrame.add(frame);
                frame = new VSizeFrame(manager);
                appender.resetWithLeftOverData(frame);
                if (!appender.appendField(baos.toByteArray(), 0, baos.size())) {
                    throw new HyracksDataException("Should never happen!");
                }
            }
        }
    }
    listFrame.add(frame);
    return listFrame;
}
Also used : IFrame(org.apache.hyracks.api.comm.IFrame) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) FrameFixedFieldAppender(org.apache.hyracks.dataflow.common.comm.io.FrameFixedFieldAppender) ByteArrayOutputStream(java.io.ByteArrayOutputStream) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)63 FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)32 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)22 FrameTupleAccessor (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)18 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)17 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)16 Test (org.junit.Test)16 IFrame (org.apache.hyracks.api.comm.IFrame)13 ArrayList (java.util.ArrayList)11 DataOutput (java.io.DataOutput)10 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)9 FrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference)9 IOException (java.io.IOException)8 IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)8 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)8 ConcurrentFramePool (org.apache.asterix.common.memory.ConcurrentFramePool)7 FeedRuntimeInputHandler (org.apache.asterix.external.feed.dataflow.FeedRuntimeInputHandler)7 FeedPolicyAccessor (org.apache.asterix.external.feed.policy.FeedPolicyAccessor)7 TestFrameWriter (org.apache.hyracks.api.test.TestFrameWriter)7 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)6