Class KafkaSourceEnumerator

  • All Implemented Interfaces:
    AutoCloseable, org.apache.flink.api.common.state.CheckpointListener, org.apache.flink.api.connector.source.SplitEnumerator<KafkaPartitionSplit,​KafkaSourceEnumState>

    @Internal
    public class KafkaSourceEnumerator
    extends Object
    implements org.apache.flink.api.connector.source.SplitEnumerator<KafkaPartitionSplit,​KafkaSourceEnumState>
    The enumerator class for Kafka source.

    A core part of the enumerator is handling discovered splits. The following lifecycle applies to splits:

    1. getSubscribedTopicPartitions() initially or periodically retrieves a list of topic partitions in the worker thread.
    2. Partitions are consolidated in checkPartitionChanges(Set, Throwable) in the main thread.
    3. New partitions will result in new splits, which are initialized through initializePartitionSplits(PartitionChange) where start/offsets are resolved in the worker thread. Offset resolution happens through the KafkaSourceEnumerator.PartitionOffsetsRetrieverImpl which communicates with the broker.
    4. The new, initialized splits are put into unassignedSplits and pendingPartitionSplitAssignment in handlePartitionSplitChanges(PartitionSplitChange, Throwable) in the main thread.
    5. assignPendingPartitionSplits(Set) eventually assigns the pending splits to readers at which point there are removed from unassignedSplits and pendingPartitionSplitAssignment and moved into assignedSplits in the main thread.
    6. Checkpointing is performed in the main thread on unassignedSplits and assignedSplits. Information in pendingPartitionSplitAssignment is ephemeral because of FLINK-21817 (pretty much the actual assignment should be transient).
    7. In case of state migration, the start offset of unassignedSplits may not be initialized, so these partitions are reinjected into the discovery process during checkPartitionChanges(Set, Throwable).