Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Apache Flink HybridSourceSplitEnumerator HandleSourceEvent

From Leeroopedia


Knowledge Sources
Domains Stream_Processing, Source_Architecture
Last Updated 2026-02-09 00:00 GMT

Overview

Concrete tool for coordinating source transitions across parallel readers by collecting finish events and triggering atomic switches provided by the Apache Flink connector-base module.

Description

HybridSourceSplitEnumerator.handleSourceEvent processes SourceReaderFinishedEvent from readers. It tracks finished readers in a set. When all registered readers have finished the current source, it calls switchEnumerator which: closes the current enumerator, creates the next source via SourceFactory (passing SourceSwitchContext for position handoff), creates the new enumerator, sends SwitchSourceEvent to all readers, and starts the new enumerator.

Usage

This is an internal method that handles the coordination of source switching. Users configure the chain; the framework handles switching automatically.

Code Reference

Source Location

  • Repository: Apache Flink
  • File: flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/hybrid/HybridSourceSplitEnumerator.java
  • Lines: L198-311

Signature

public class HybridSourceSplitEnumerator
        implements SplitEnumerator<HybridSourceSplit, HybridSourceEnumeratorState>,
                SupportsBatchSnapshot {

    @Override
    public void handleSourceEvent(int subtaskId, SourceEvent sourceEvent) {
        // Collects SourceReaderFinishedEvent from all readers
        // When all finished -> switchEnumerator()
    }

    private void switchEnumerator() {
        // 1. Close current enumerator
        // 2. Increment currentSourceIndex
        // 3. Create next source via SourceFactory
        // 4. Send SwitchSourceEvent to all readers
        // 5. Create and start new enumerator
    }

    private void sendSwitchSourceEvent(int subtaskId, int sourceIndex) {
        // Sends SwitchSourceEvent with source object and isFinalSource flag
    }
}

Import

import org.apache.flink.connector.base.source.hybrid.HybridSourceSplitEnumerator;
// Internal class

I/O Contract

Inputs

Name Type Required Description
subtaskId int Yes Reader subtask that sent the event
sourceEvent SourceEvent Yes SourceReaderFinishedEvent or source-specific events

Outputs

Name Type Description
side effect SwitchSourceEvent Sent to all readers when switching
side effect New enumerator Created for the next source in the chain

Usage Examples

Switch Flow

// Source switching flow:
// 1. Reader 0 finishes source[0] -> sends SourceReaderFinishedEvent(0)
// 2. Reader 1 finishes source[0] -> sends SourceReaderFinishedEvent(0)
// 3. Enumerator: all readers finished source[0]
// 4. switchEnumerator():
//    a. Close source[0]'s enumerator
//    b. Create source[1] via SourceFactory (may receive source[0]'s enumerator)
//    c. Send SwitchSourceEvent(1, source[1], isFinal) to all readers
//    d. Create and start source[1]'s enumerator
// 5. Readers receive SwitchSourceEvent -> create source[1]'s reader

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment