Document the state by adding a label to the FLIP page with one of "discussion", "accepted", "released", "rejected".

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

SinkV2 already exposes JobInfo to writers and committers via InitContext.getJobInfo(). The Source API has no equivalent on SourceReaderContext or SplitEnumeratorContext. However, source implementations that also need JobID, for example for per-job authentication to external services, per-job metric tagging, per-job offset stores in external systems or per-job log correlation must currently either:

1. Cast SourceReaderContext to the @Experimental RichSourceReaderContext and access it through getRuntimeContext().getJobInfo(). The drawbacks are:

  • Reader-side only. There is no equivalent on the SplitEnumeratorContext.
  • Over-broad surface. It forces a connector to depend on the entire RuntimeContext just to read job identity. SinkV2 deliberately avoids this by exposing the narrow getJobInfo(). the Source side should match.

2. Parse metricGroup().getAllVariables().get("<job_id>") as a String and reconstruct JobID via JobID.fromHexString(...). Depends on the internal metric scope variable naming (ScopeFormat.SCOPE_JOB_ID), not an API contract.

The runtime already holds the data at both source execution points: SourceOperator has it via StreamingRuntimeContext (constructor-injected with env.getJobInfo()). SourceCoordinatorContext has it via the already @Internal OperatorCoordinator.Context.getJobID(). The gap is purely in the public API surface.

Public Interfaces

Two @Public interfaces gain one @PublicEvolving default method each:

  • org.apache.flink.api.connector.source.SourceReaderContext

  • org.apache.flink.api.connector.source.SplitEnumeratorContext

One @Internal interface gains one method to enable the enumerator-side implementation:

  • org.apache.flink.runtime.operators.coordination.OperatorCoordinator.Context add JobInfo getJobInfo(). Since it already exposes getJobID() this is a natural extension, being @Internal, it carries no FLIP-level compatibility burden but is disclosed here for completeness.

No new interfaces. No new packages. No changes to JobInfo itself.

Proposed Changes

Add a default method to both source contexts:

// SourceReaderContext
@PublicEvolving
default JobInfo getJobInfo() {
    throw new UnsupportedOperationException();
}
// SplitEnumeratorContext
@PublicEvolving
default JobInfo getJobInfo() {
    throw new UnsupportedOperationException();
}


The default throws UnsupportedOperationException pattern is already established on both interfaces: SourceReaderContext.currentParallelism(), SourceReaderContext.emitWatermark(), SplitEnumeratorContext.sendEventToSourceReader(int,int,SourceEvent), SplitEnumeratorContext.registeredReadersOfAttempts(), SplitEnumeratorContext.setIsProcessingBacklog(boolean). The new methods are consistent with existing style.

The runtime implementations override getJobInfo():

  • Reader side: the anonymous RichSourceReaderContext created in SourceOperator.initReader() already has access to StreamingRuntimeContext. The override returns runtimeContext.getJobInfo(). No structural change to SourceOperator is needed.

  • Enumerator side: SourceCoordinatorContext currently receives a bare JobID constructor parameter (used only for MDC scoping via MdcUtils.scopeToJob) and also holds an OperatorCoordinator.Context. The implementation strategy:

    1. Add JobInfo getJobInfo() to OperatorCoordinator.Context. Implementing classes (RecreateOnResetOperatorCoordinator.QuiesceableContext, and the test mock MockOperatorCoordinatorContext) override it.

    2. LazyInitializedCoordinatorContext's JobID constructor parameter is replaced with JobInfo because it is derivable from JobInfo.getJobId().

    3. SourceCoordinatorContext.getJobInfo() delegates to operatorCoordinatorContext.getJobInfo().

All Flink implementations of SplitEnumeratorContext and SourceReaderContext, including wrapping/delegating contexts (e.g. inside HybridSource) and core test utilities, are updated to provide a real JobInfo or to forward to their underlying context, so the default throw UnsupportedOperationException behavior is only encountered by third-party implementations that haven't opted in.

Compatibility, Deprecation, and Migration Plan

Existing users: no impact.

  • Source-compatible: the new methods carry default bodies and existing source code does not need to be updated.

  • Binary-compatible: existing compiled implementations of SourceReaderContext and SplitEnumeratorContext inherit the default body and do not need recompilation.

  • Behavioral: connectors that do not call getJobInfo() see no behavior change.

Framework implementations (anything implementing SourceReaderContext or SplitEnumeratorContext directly, test stubs, frameworks embedding Flink): existing implementations compile and run unchanged. Calling getJobInfo() on a context that doesn't override the default throws UnsupportedOperationException, the same contract as other default methods on these interfaces (currentParallelism(), emitWatermark(), etc.). Javadoc will document this explicitly.

OperatorCoordinator.Context is @Internal. Adding getJobInfo() to it carries no FLIP-level compatibility burden. Implementations within Flink's own codebase are updated as part of this change.

Behavior phase-out: none. This is a pure addition. No existing behavior is changed or removed. No deprecations. No migration tools required.

Removal timeline: not applicable. RichSourceReaderContext remains unaffected. A follow-up FLIP could consider deprecating RichSourceReaderContext.getRuntimeContext() once the targeted accessors are widely adopted, but that is explicitly out of scope here.

Test Plan

System-level (mini-cluster end-to-end) tests:

  1. Reader observes the running job's JobID: a test Source whose SourceReader calls readerContext.getJobInfo().getJobId() inside createReader() and emits the value as a record. Run against a MiniCluster, assert the emitted record equals the actual JobID of the submitted job.

  2. Enumerator observes the running job's JobID: the same test Source invokes enumContext.getJobInfo().getJobId() inside createEnumerator(...), stores it in enumerator state, signals it back to readers via a SourceEvent. Assert match against the job's actual JobID.

  3. Recovery path: stop and restart the job, assert both createReader(...) (post-restart) and restoreEnumerator(...) observe the same JobID, JobInfo is stable across recovery within a single job's lifetime.

Unit tests:

  • SourceOperatorTest: assert the SourceReaderContext constructed by SourceOperator.initReader() returns a non-null JobInfo matching the operator's StreamingRuntimeContext.getJobInfo().

  • SourceCoordinatorContextTest: assert SplitEnumeratorContext.getJobInfo() returns the JobInfo provided by the underlying OperatorCoordinator.Context.

  • Default-body correctness: a barebones implementation of each interface (providing only the abstract methods) is verified to throw UnsupportedOperationException from the new method.

Compatibility check:

  • CI passing across flink-connectors/* modules and downstream connector repositories without source changes is the implicit binary/source-compatibility test.

Existing tests for both interfaces continue to pass unmodified, demonstrating no regression.

Rejected Alternatives

1. Make SourceReaderContext / SplitEnumeratorContext extend InitContext. Rejected.

  • InitContext is @Internal at the interface level, @Public interfaces extending an @Internal is a stability-tier violation.

  • InitContext lives in org.apache.flink.api.connector.sink2, source code depending on a sink2-packaged interface inverts the package layering.

  • InitContext.getTaskInfo() does not fit SplitEnumeratorContext: the enumerator runs on the JM coordinator thread, not a task, it has no subtask index, attempt number, or allocation id.

  • InitContext.getRestoredCheckpointId() does not fit the source side: sources have their own typed restore protocol (Source.restoreEnumerator(ctx, checkpoint), SourceReader.addSplits(...)), not checkpoint-id-based restore.

  • Method overlap: SourceReaderContext already exposes getIndexOfSubtask() and currentParallelism() directly, inheriting getTaskInfo() would create dual access paths needing a deprecation cycle.

  • Scope creep: would require first promoting InitContext from @Internal to @PublicEvolving (separate FLIP) and moving it out of the sink2 package (separate FLIP) before this change could land.

2. Add JobID getJobId() instead of JobInfo getJobInfo(). Rejected. Sink v2's InitContext.getJobInfo() chose JobInfo as the carrier and mirroring its shape exactly is the cheapest design choice and lets JobInfo grow with new accessors (getJobName(), future fields) without subsequent FLIPs.

3. Metric variables side-channel (metricGroup().getAllVariables().get("<job_id>")). Rejected.

  • String-based, requires JobID.fromHexString(...) and error handling.

  • Depends on the metric scope variable naming convention (ScopeFormat.SCOPE_JOB_ID = asVariable("job_id")), which is implementation detail, not an API contract.

  • Awkward, undiscoverable, fragile.