use of org.apache.flink.runtime.source.event.ReaderRegistrationEvent 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);
}
use of org.apache.flink.runtime.source.event.ReaderRegistrationEvent in project flink by apache.
the class SourceOperatorTest method testOpen.
@Test
public void testOpen() throws Exception {
// Initialize the operator.
operator.initializeState(context.createStateContext());
// Open the operator.
operator.open();
// The source reader should have been assigned a split.
assertEquals(Collections.singletonList(SourceOperatorTestContext.MOCK_SPLIT), mockSourceReader.getAssignedSplits());
// The source reader should have started.
assertTrue(mockSourceReader.isStarted());
// A ReaderRegistrationRequest should have been sent.
assertEquals(1, mockGateway.getEventsSent().size());
OperatorEvent operatorEvent = mockGateway.getEventsSent().get(0);
assertTrue(operatorEvent instanceof ReaderRegistrationEvent);
assertEquals(SourceOperatorTestContext.SUBTASK_INDEX, ((ReaderRegistrationEvent) operatorEvent).subtaskId());
}
use of org.apache.flink.runtime.source.event.ReaderRegistrationEvent in project flink by apache.
the class SourceCoordinatorContextTest method registerReaders.
// ------------------------
private List<ReaderInfo> registerReaders() {
final List<ReaderInfo> infos = Arrays.asList(new ReaderInfo(0, "subtask_0_location"), new ReaderInfo(1, "subtask_1_location"), new ReaderInfo(2, "subtask_2_location"));
for (ReaderInfo info : infos) {
sourceCoordinator.handleEventFromOperator(info.getSubtaskId(), new ReaderRegistrationEvent(info.getSubtaskId(), info.getLocation()));
}
waitForCoordinatorToProcessActions();
return infos;
}
use of org.apache.flink.runtime.source.event.ReaderRegistrationEvent in project flink by apache.
the class SourceCoordinatorProviderTest method testCheckpointAndReset.
@Test
public void testCheckpointAndReset() throws Exception {
final OperatorCoordinator.Context context = new MockOperatorCoordinatorContext(OPERATOR_ID, NUM_SPLITS);
final RecreateOnResetOperatorCoordinator coordinator = (RecreateOnResetOperatorCoordinator) provider.create(context);
final SourceCoordinator<?, ?> sourceCoordinator = (SourceCoordinator<?, ?>) coordinator.getInternalCoordinator();
// Start the coordinator.
coordinator.start();
// register reader 0 and take a checkpoint.
coordinator.handleEventFromOperator(0, new ReaderRegistrationEvent(0, "location"));
CompletableFuture<byte[]> future = new CompletableFuture<>();
coordinator.checkpointCoordinator(0L, future);
byte[] bytes = future.get();
// Register reader 1.
coordinator.handleEventFromOperator(1, new ReaderRegistrationEvent(1, "location"));
// Wait until the coordinator context is updated with registration of reader 1.
while (sourceCoordinator.getContext().registeredReaders().size() < 2) {
Thread.sleep(1);
}
// reset the coordinator to the checkpoint which only contains reader 0.
coordinator.resetToCheckpoint(0L, bytes);
final SourceCoordinator<?, ?> restoredSourceCoordinator = (SourceCoordinator<?, ?>) coordinator.getInternalCoordinator();
assertNotEquals("The restored source coordinator should be a different instance", restoredSourceCoordinator, sourceCoordinator);
// FLINK-21452: do not (re)store registered readers
assertEquals("There should be no registered reader.", 0, restoredSourceCoordinator.getContext().registeredReaders().size());
}
Aggregations