Class DynamicKafkaSourceReader<T>
java.lang.Object
org.apache.flink.connector.kafka.dynamic.source.reader.DynamicKafkaSourceReader<T>
- All Implemented Interfaces:
AutoCloseable,org.apache.flink.api.common.state.CheckpointListener,org.apache.flink.api.connector.source.SourceReader<T,DynamicKafkaSourceSplit>
@Internal
public class DynamicKafkaSourceReader<T>
extends Object
implements org.apache.flink.api.connector.source.SourceReader<T,DynamicKafkaSourceSplit>
Manages state about underlying
KafkaSourceReader to collect records and commit offsets
from multiple Kafka clusters. This reader also handles changes to Kafka topology by reacting to
restart sequence initiated by the enumerator and suspending inconsistent sub readers.
First, in the restart sequence, we will receive the MetadataUpdateEvent from the
enumerator, stop all KafkaSourceReaders, and retain the relevant splits. Second, enumerator will
send all new splits that readers should work on (old splits will not be sent again).
-
Constructor Summary
ConstructorsConstructorDescriptionDynamicKafkaSourceReader(org.apache.flink.api.connector.source.SourceReaderContext readerContext, KafkaRecordDeserializationSchema<T> deserializationSchema, Properties properties) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSplits(List<DynamicKafkaSourceSplit> splits) voidclose()org.apache.flink.streaming.runtime.io.MultipleFuturesAvailabilityHelpervoidhandleSourceEvents(org.apache.flink.api.connector.source.SourceEvent sourceEvent) Duplicate source events are handled with idempotency.booleanvoidnotifyCheckpointComplete(long checkpointId) voidorg.apache.flink.core.io.InputStatussnapshotState(long checkpointId) voidstart()This is invoked first only in reader startup without state.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.flink.api.common.state.CheckpointListener
notifyCheckpointAbortedMethods inherited from interface org.apache.flink.api.connector.source.SourceReader
pauseOrResumeSplits
-
Constructor Details
-
DynamicKafkaSourceReader
public DynamicKafkaSourceReader(org.apache.flink.api.connector.source.SourceReaderContext readerContext, KafkaRecordDeserializationSchema<T> deserializationSchema, Properties properties)
-
-
Method Details
-
start
public void start()This is invoked first only in reader startup without state. In stateful startup, splits are added before this method is invoked.- Specified by:
startin interfaceorg.apache.flink.api.connector.source.SourceReader<T,DynamicKafkaSourceSplit>
-
pollNext
public org.apache.flink.core.io.InputStatus pollNext(org.apache.flink.api.connector.source.ReaderOutput<T> readerOutput) throws Exception - Specified by:
pollNextin interfaceorg.apache.flink.api.connector.source.SourceReader<T,DynamicKafkaSourceSplit> - Throws:
Exception
-
addSplits
- Specified by:
addSplitsin interfaceorg.apache.flink.api.connector.source.SourceReader<T,DynamicKafkaSourceSplit>
-
handleSourceEvents
public void handleSourceEvents(org.apache.flink.api.connector.source.SourceEvent sourceEvent) Duplicate source events are handled with idempotency. No metadata change means we simply skip the restart logic.- Specified by:
handleSourceEventsin interfaceorg.apache.flink.api.connector.source.SourceReader<T,DynamicKafkaSourceSplit>
-
snapshotState
- Specified by:
snapshotStatein interfaceorg.apache.flink.api.connector.source.SourceReader<T,DynamicKafkaSourceSplit>
-
isAvailable
- Specified by:
isAvailablein interfaceorg.apache.flink.api.connector.source.SourceReader<T,DynamicKafkaSourceSplit>
-
notifyNoMoreSplits
public void notifyNoMoreSplits()- Specified by:
notifyNoMoreSplitsin interfaceorg.apache.flink.api.connector.source.SourceReader<T,DynamicKafkaSourceSplit>
-
notifyCheckpointComplete
- Specified by:
notifyCheckpointCompletein interfaceorg.apache.flink.api.common.state.CheckpointListener- Specified by:
notifyCheckpointCompletein interfaceorg.apache.flink.api.connector.source.SourceReader<T,DynamicKafkaSourceSplit> - Throws:
Exception
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
getAvailabilityHelper
@VisibleForTesting public org.apache.flink.streaming.runtime.io.MultipleFuturesAvailabilityHelper getAvailabilityHelper() -
isActivelyConsumingSplits
@VisibleForTesting public boolean isActivelyConsumingSplits()
-