@Internal public class StoppableKafkaEnumContextProxy extends Object implements org.apache.flink.api.connector.source.SplitEnumeratorContext<KafkaPartitionSplit>, AutoCloseable
KafkaSourceEnumerator. This is
motivated by the need to cancel the periodic partition discovery in scheduled tasks when sub
Kafka Enumerators are restarted. The worker thread pool in org.apache.flink.runtime.source.coordinator.SourceCoordinatorContext should not contain tasks of
inactive KafkaSourceEnumerators, after source restart.
Due to the inability to cancel scheduled tasks from org.apache.flink.runtime.source.coordinator.SourceCoordinatorContext, this enumerator context
will safely catch exceptions during enumerator restart and use a closeable proxy scheduler to
invoke tasks on the coordinator main thread to maintain the single threaded property.
| Modifier and Type | Class and Description |
|---|---|
static class |
StoppableKafkaEnumContextProxy.HandledFlinkKafkaException
General exception to signal to internal exception handling mechanisms that a benign error
occurred.
|
static interface |
StoppableKafkaEnumContextProxy.StoppableKafkaEnumContextProxyFactory
This factory exposes a way to override the
StoppableKafkaEnumContextProxy used in the
enumerator. |
| Constructor and Description |
|---|
StoppableKafkaEnumContextProxy(String kafkaClusterId,
KafkaMetadataService kafkaMetadataService,
org.apache.flink.api.connector.source.SplitEnumeratorContext<DynamicKafkaSourceSplit> enumContext,
Runnable signalNoMoreSplitsCallback)
Constructor for the enumerator context.
|
| Modifier and Type | Method and Description |
|---|---|
void |
assignSplits(org.apache.flink.api.connector.source.SplitsAssignment<KafkaPartitionSplit> newSplitAssignments)
Wrap splits with cluster metadata.
|
<T> void |
callAsync(Callable<T> callable,
java.util.function.BiConsumer<T,Throwable> handler)
Execute the one time callables in the coordinator.
|
<T> void |
callAsync(Callable<T> callable,
java.util.function.BiConsumer<T,Throwable> handler,
long initialDelay,
long period)
Schedule task via internal thread pool to proxy task so that the task handler callback can
execute in the single threaded source coordinator thread pool to avoid synchronization needs.
|
void |
close()
Note that we can't close the source coordinator here, because these contexts can be closed
during metadata change when the coordinator still needs to continue to run.
|
int |
currentParallelism() |
boolean |
isNoMoreSplits() |
org.apache.flink.metrics.groups.SplitEnumeratorMetricGroup |
metricGroup() |
Map<Integer,org.apache.flink.api.connector.source.ReaderInfo> |
registeredReaders() |
void |
runInCoordinatorThread(Runnable runnable) |
void |
sendEventToSourceReader(int subtaskId,
org.apache.flink.api.connector.source.SourceEvent event) |
void |
signalNoMoreSplits(int subtask) |
protected <T> Callable<T> |
wrapCallAsyncCallable(Callable<T> callable)
Wraps callable in call async executed in worker thread pool with exception propagation to
optimize on doing IO in non-coordinator thread.
|
protected <T> java.util.function.BiConsumer<T,Throwable> |
wrapCallAsyncCallableHandler(java.util.function.BiConsumer<T,Throwable> mainHandler)
Handle exception that is propagated by a callable, executed on coordinator thread.
|
public StoppableKafkaEnumContextProxy(String kafkaClusterId, KafkaMetadataService kafkaMetadataService, org.apache.flink.api.connector.source.SplitEnumeratorContext<DynamicKafkaSourceSplit> enumContext, @Nullable Runnable signalNoMoreSplitsCallback)
kafkaClusterId - The Kafka cluster id in order to maintain the mapping to the sub
KafkaSourceEnumeratorkafkaMetadataService - the Kafka metadata service to facilitate error handlingenumContext - the underlying enumerator contextsignalNoMoreSplitsCallback - the callback when signal no more splits is invokedpublic org.apache.flink.metrics.groups.SplitEnumeratorMetricGroup metricGroup()
metricGroup in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<KafkaPartitionSplit>public void sendEventToSourceReader(int subtaskId,
org.apache.flink.api.connector.source.SourceEvent event)
sendEventToSourceReader in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<KafkaPartitionSplit>public int currentParallelism()
currentParallelism in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<KafkaPartitionSplit>public Map<Integer,org.apache.flink.api.connector.source.ReaderInfo> registeredReaders()
registeredReaders in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<KafkaPartitionSplit>public void assignSplits(org.apache.flink.api.connector.source.SplitsAssignment<KafkaPartitionSplit> newSplitAssignments)
assignSplits in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<KafkaPartitionSplit>public void signalNoMoreSplits(int subtask)
signalNoMoreSplits in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<KafkaPartitionSplit>public <T> void callAsync(Callable<T> callable, java.util.function.BiConsumer<T,Throwable> handler)
callAsync in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<KafkaPartitionSplit>public <T> void callAsync(Callable<T> callable, java.util.function.BiConsumer<T,Throwable> handler, long initialDelay, long period)
Having the scheduled task in the internal thread pool also allows us to cancel the task when the context needs to close due to dynamic enumerator restart.
In the case of KafkaEnumerator partition discovery, the callback modifies KafkaEnumerator object state.
callAsync in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<KafkaPartitionSplit>public void runInCoordinatorThread(Runnable runnable)
runInCoordinatorThread in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<KafkaPartitionSplit>public boolean isNoMoreSplits()
public void close()
throws Exception
TODO: Attach Flink JIRA ticket -- discuss with upstream how to cancel scheduled tasks belonging to enumerator.
close in interface AutoCloseableExceptionprotected <T> Callable<T> wrapCallAsyncCallable(Callable<T> callable)
protected <T> java.util.function.BiConsumer<T,Throwable> wrapCallAsyncCallableHandler(java.util.function.BiConsumer<T,Throwable> mainHandler)
Copyright © 2022–2024 The Apache Software Foundation. All rights reserved.