Search in sources :

Example 1 with ReportedWatermarkEvent

use of org.apache.flink.runtime.source.event.ReportedWatermarkEvent in project flink by apache.

the class SourceCoordinator method handleEventFromOperator.

@Override
public void handleEventFromOperator(int subtask, OperatorEvent event) {
    runInEventLoop(() -> {
        if (event instanceof RequestSplitEvent) {
            LOG.info("Source {} received split request from parallel task {}", operatorName, subtask);
            enumerator.handleSplitRequest(subtask, ((RequestSplitEvent) event).hostName());
        } else if (event instanceof SourceEventWrapper) {
            final SourceEvent sourceEvent = ((SourceEventWrapper) event).getSourceEvent();
            LOG.debug("Source {} received custom event from parallel task {}: {}", operatorName, subtask, sourceEvent);
            enumerator.handleSourceEvent(subtask, sourceEvent);
        } else if (event instanceof ReaderRegistrationEvent) {
            final ReaderRegistrationEvent registrationEvent = (ReaderRegistrationEvent) event;
            LOG.info("Source {} registering reader for parallel task {} @ {}", operatorName, subtask, registrationEvent.location());
            handleReaderRegistrationEvent(registrationEvent);
        } else if (event instanceof ReportedWatermarkEvent) {
            handleReportedWatermark(subtask, new Watermark(((ReportedWatermarkEvent) event).getWatermark()));
        } else {
            throw new FlinkException("Unrecognized Operator Event: " + event);
        }
    }, "handling operator event %s from subtask %d", event, subtask);
}
Also used : RequestSplitEvent(org.apache.flink.runtime.source.event.RequestSplitEvent) SourceEventWrapper(org.apache.flink.runtime.source.event.SourceEventWrapper) ReaderRegistrationEvent(org.apache.flink.runtime.source.event.ReaderRegistrationEvent) Watermark(org.apache.flink.api.common.eventtime.Watermark) FlinkException(org.apache.flink.util.FlinkException) SourceEvent(org.apache.flink.api.connector.source.SourceEvent) ReportedWatermarkEvent(org.apache.flink.runtime.source.event.ReportedWatermarkEvent)

Example 2 with ReportedWatermarkEvent

use of org.apache.flink.runtime.source.event.ReportedWatermarkEvent in project flink by apache.

the class SourceCoordinatorAlignmentTest method reportWatermarkEvent.

private void reportWatermarkEvent(SourceCoordinator<?, ?> sourceCoordinator1, int subtask, long watermark) {
    sourceCoordinator1.handleEventFromOperator(subtask, new ReportedWatermarkEvent(watermark));
    waitForCoordinatorToProcessActions();
    sourceCoordinator1.announceCombinedWatermark();
}
Also used : ReportedWatermarkEvent(org.apache.flink.runtime.source.event.ReportedWatermarkEvent)

Example 3 with ReportedWatermarkEvent

use of org.apache.flink.runtime.source.event.ReportedWatermarkEvent in project flink by apache.

the class SourceOperator method emitLatestWatermark.

private void emitLatestWatermark(long time) {
    checkState(currentMainOutput != null);
    operatorEventGateway.sendEventToCoordinator(new ReportedWatermarkEvent(lastEmittedWatermark));
}
Also used : ReportedWatermarkEvent(org.apache.flink.runtime.source.event.ReportedWatermarkEvent)

Example 4 with ReportedWatermarkEvent

use of org.apache.flink.runtime.source.event.ReportedWatermarkEvent in project flink by apache.

the class SourceOperatorAlignmentTest method assertLatestReportedWatermarkEvent.

private void assertLatestReportedWatermarkEvent(SourceOperatorTestContext context, long expectedWatermark) {
    List<OperatorEvent> events = context.getGateway().getEventsSent().stream().filter(event -> event instanceof ReportedWatermarkEvent).collect(Collectors.toList());
    assertFalse(events.isEmpty());
    assertEquals(new ReportedWatermarkEvent(expectedWatermark), events.get(events.size() - 1));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) BeforeEach(org.junit.jupiter.api.BeforeEach) ReportedWatermarkEvent(org.apache.flink.runtime.source.event.ReportedWatermarkEvent) WatermarkGenerator(org.apache.flink.api.common.eventtime.WatermarkGenerator) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) MockSourceSplit(org.apache.flink.api.connector.source.mocks.MockSourceSplit) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) DataInputStatus(org.apache.flink.streaming.runtime.io.DataInputStatus) Duration(java.time.Duration) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) WatermarkAlignmentEvent(org.apache.flink.runtime.source.event.WatermarkAlignmentEvent) Nullable(javax.annotation.Nullable) WatermarkStrategy(org.apache.flink.api.common.eventtime.WatermarkStrategy) MockSourceSplitSerializer(org.apache.flink.api.connector.source.mocks.MockSourceSplitSerializer) AddSplitEvent(org.apache.flink.runtime.source.event.AddSplitEvent) WatermarkOutput(org.apache.flink.api.common.eventtime.WatermarkOutput) Collectors(java.util.stream.Collectors) StopMode(org.apache.flink.runtime.io.network.api.StopMode) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Watermark(org.apache.flink.api.common.eventtime.Watermark) CollectingDataOutput(org.apache.flink.streaming.api.operators.source.CollectingDataOutput) Collections(java.util.Collections) OperatorEvent(org.apache.flink.runtime.operators.coordination.OperatorEvent) OperatorEvent(org.apache.flink.runtime.operators.coordination.OperatorEvent) ReportedWatermarkEvent(org.apache.flink.runtime.source.event.ReportedWatermarkEvent)

Aggregations

ReportedWatermarkEvent (org.apache.flink.runtime.source.event.ReportedWatermarkEvent)4 Watermark (org.apache.flink.api.common.eventtime.Watermark)2 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 WatermarkGenerator (org.apache.flink.api.common.eventtime.WatermarkGenerator)1 WatermarkOutput (org.apache.flink.api.common.eventtime.WatermarkOutput)1 WatermarkStrategy (org.apache.flink.api.common.eventtime.WatermarkStrategy)1 SourceEvent (org.apache.flink.api.connector.source.SourceEvent)1 MockSourceSplit (org.apache.flink.api.connector.source.mocks.MockSourceSplit)1 MockSourceSplitSerializer (org.apache.flink.api.connector.source.mocks.MockSourceSplitSerializer)1 StopMode (org.apache.flink.runtime.io.network.api.StopMode)1 OperatorEvent (org.apache.flink.runtime.operators.coordination.OperatorEvent)1 AddSplitEvent (org.apache.flink.runtime.source.event.AddSplitEvent)1 ReaderRegistrationEvent (org.apache.flink.runtime.source.event.ReaderRegistrationEvent)1 RequestSplitEvent (org.apache.flink.runtime.source.event.RequestSplitEvent)1