Search in sources :

Example 6 with AbstractEvent

use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.

the class RecordOrEventCollectingResultPartitionWriter method broadcastEvent.

@Override
public void broadcastEvent(AbstractEvent event, boolean isPriorityEvent) throws IOException {
    // visible in ITCases or end to end tests.
    try (BufferConsumer eventBufferConsumer = EventSerializer.toBufferConsumer(event, isPriorityEvent)) {
        Buffer buffer = eventBufferConsumer.build();
        try {
            AbstractEvent deserializedEvent = EventSerializer.fromBuffer(buffer, getClass().getClassLoader());
            output.add(deserializedEvent);
        } finally {
            buffer.recycleBuffer();
        }
    }
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent)

Example 7 with AbstractEvent

use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.

the class EventSerializerTest method testToBufferConsumer.

@Test
public void testToBufferConsumer() throws IOException {
    for (AbstractEvent evt : events) {
        BufferConsumer bufferConsumer = EventSerializer.toBufferConsumer(evt, false);
        assertFalse(bufferConsumer.isBuffer());
        assertTrue(bufferConsumer.isFinished());
        assertTrue(bufferConsumer.isDataAvailable());
        assertFalse(bufferConsumer.isRecycled());
        if (evt instanceof CheckpointBarrier) {
            assertTrue(bufferConsumer.build().getDataType().isBlockingUpstream());
        } else {
            assertEquals(Buffer.DataType.EVENT_BUFFER, bufferConsumer.build().getDataType());
        }
    }
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) Test(org.junit.Test)

Example 8 with AbstractEvent

use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.

the class EventSerializerTest method testToBuffer.

@Test
public void testToBuffer() throws IOException {
    for (AbstractEvent evt : events) {
        Buffer buffer = EventSerializer.toBuffer(evt, false);
        assertFalse(buffer.isBuffer());
        assertTrue(buffer.readableBytes() > 0);
        assertFalse(buffer.isRecycled());
        if (evt instanceof CheckpointBarrier) {
            assertTrue(buffer.getDataType().isBlockingUpstream());
        } else {
            assertEquals(Buffer.DataType.EVENT_BUFFER, buffer.getDataType());
        }
    }
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent) Test(org.junit.Test)

Example 9 with AbstractEvent

use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.

the class StreamTestSingleInputGate method setupInputChannels.

private TestInputChannel[] setupInputChannels() {
    TestInputChannel[] inputChannels = new TestInputChannel[numInputChannels];
    for (int i = 0; i < numInputChannels; i++) {
        final int channelIndex = i;
        final DataOutputSerializer dataOutputSerializer = new DataOutputSerializer(128);
        final SerializationDelegate<StreamElement> delegate = new SerializationDelegate<>(new StreamElementSerializer<T>(serializer));
        inputQueues[channelIndex] = new ConcurrentLinkedQueue<>();
        inputChannels[channelIndex] = new TestInputChannel(inputGate, i);
        final BufferAndAvailabilityProvider answer = () -> {
            ConcurrentLinkedQueue<InputValue<Object>> inputQueue = inputQueues[channelIndex];
            InputValue<Object> input;
            Buffer.DataType nextType;
            synchronized (inputQueue) {
                input = inputQueue.poll();
                nextType = !inputQueue.isEmpty() ? Buffer.DataType.DATA_BUFFER : Buffer.DataType.NONE;
            }
            if (input != null && input.isStreamEnd()) {
                inputChannels[channelIndex].setReleased();
                return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE, false), nextType, 0, 0));
            } else if (input != null && input.isDataEnd()) {
                return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(new EndOfData(StopMode.DRAIN), false), nextType, 0, 0));
            } else if (input != null && input.isStreamRecord()) {
                StreamElement inputElement = input.getStreamRecord();
                delegate.setInstance(inputElement);
                ByteBuffer serializedRecord = RecordWriter.serializeRecord(dataOutputSerializer, delegate);
                BufferBuilder bufferBuilder = createBufferBuilder(bufferSize);
                BufferConsumer bufferConsumer = bufferBuilder.createBufferConsumer();
                bufferBuilder.appendAndCommit(serializedRecord);
                bufferBuilder.finish();
                bufferBuilder.close();
                // Call getCurrentBuffer to ensure size is set
                return Optional.of(new BufferAndAvailability(bufferConsumer.build(), nextType, 0, 0));
            } else if (input != null && input.isEvent()) {
                AbstractEvent event = input.getEvent();
                if (event instanceof EndOfPartitionEvent) {
                    inputChannels[channelIndex].setReleased();
                }
                return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(event, false), nextType, 0, 0));
            } else {
                return Optional.empty();
            }
        };
        inputChannels[channelIndex].addBufferAndAvailability(answer);
    }
    return inputChannels;
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) EndOfPartitionEvent(org.apache.flink.runtime.io.network.api.EndOfPartitionEvent) BufferBuilderTestUtils.createBufferBuilder(org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createBufferBuilder) BufferBuilder(org.apache.flink.runtime.io.network.buffer.BufferBuilder) StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) SerializationDelegate(org.apache.flink.runtime.plugable.SerializationDelegate) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent) ByteBuffer(java.nio.ByteBuffer) EndOfData(org.apache.flink.runtime.io.network.api.EndOfData) BufferAndAvailabilityProvider(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel.BufferAndAvailabilityProvider) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) BufferAndAvailability(org.apache.flink.runtime.io.network.partition.consumer.InputChannel.BufferAndAvailability)

Example 10 with AbstractEvent

use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.

the class SubtaskCheckpointCoordinatorTest method testSavepointNotResultingInPriorityEvents.

@Test
public void testSavepointNotResultingInPriorityEvents() throws Exception {
    MockEnvironment mockEnvironment = MockEnvironment.builder().build();
    try (SubtaskCheckpointCoordinator coordinator = new MockSubtaskCheckpointCoordinatorBuilder().setUnalignedCheckpointEnabled(true).setEnvironment(mockEnvironment).build()) {
        AtomicReference<Boolean> broadcastedPriorityEvent = new AtomicReference<>(null);
        final OperatorChain<?, ?> operatorChain = new RegularOperatorChain(new MockStreamTaskBuilder(mockEnvironment).build(), new NonRecordWriter<>()) {

            @Override
            public void broadcastEvent(AbstractEvent event, boolean isPriorityEvent) throws IOException {
                super.broadcastEvent(event, isPriorityEvent);
                broadcastedPriorityEvent.set(isPriorityEvent);
            }
        };
        coordinator.checkpointState(new CheckpointMetaData(0, 0), new CheckpointOptions(SavepointType.savepoint(SavepointFormatType.CANONICAL), CheckpointStorageLocationReference.getDefault()), new CheckpointMetricsBuilder(), operatorChain, false, () -> true);
        assertEquals(false, broadcastedPriorityEvent.get());
    }
}
Also used : MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) CheckpointMetricsBuilder(org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) Test(org.junit.Test)

Aggregations

AbstractEvent (org.apache.flink.runtime.event.AbstractEvent)24 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)6 IOException (java.io.IOException)5 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)5 Test (org.junit.Test)5 EventAnnouncement (org.apache.flink.runtime.io.network.api.EventAnnouncement)4 BufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferConsumer)4 ByteBuffer (java.nio.ByteBuffer)3 EndOfData (org.apache.flink.runtime.io.network.api.EndOfData)3 BufferOrEvent (org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent)3 StreamElement (org.apache.flink.streaming.runtime.streamrecord.StreamElement)3 ByteOrder (java.nio.ByteOrder)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Nullable (javax.annotation.Nullable)2 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)2 CheckpointMetricsBuilder (org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder)2 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)2 CancelCheckpointMarker (org.apache.flink.runtime.io.network.api.CancelCheckpointMarker)2 EndOfPartitionEvent (org.apache.flink.runtime.io.network.api.EndOfPartitionEvent)2 DeserializationResult (org.apache.flink.runtime.io.network.api.serialization.RecordDeserializer.DeserializationResult)2