DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
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
RuntimeContextjust to read job identity. SinkV2 deliberately avoids this by exposing the narrowgetJobInfo(). 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.SourceReaderContextorg.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.ContextaddJobInfo getJobInfo(). Since it already exposesgetJobID()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
RichSourceReaderContextcreated inSourceOperator.initReader()already has access toStreamingRuntimeContext. The override returnsruntimeContext.getJobInfo(). No structural change toSourceOperatoris needed.Enumerator side:
SourceCoordinatorContextcurrently receives a bareJobIDconstructor parameter (used only for MDC scoping viaMdcUtils.scopeToJob) and also holds anOperatorCoordinator.Context. The implementation strategy:Add
JobInfo getJobInfo()toOperatorCoordinator.Context. Implementing classes (RecreateOnResetOperatorCoordinator.QuiesceableContext, and the test mockMockOperatorCoordinatorContext) override it.LazyInitializedCoordinatorContext'sJobIDconstructor parameter is replaced withJobInfobecause it is derivable fromJobInfo.getJobId().SourceCoordinatorContext.getJobInfo()delegates tooperatorCoordinatorContext.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
SourceReaderContextandSplitEnumeratorContextinherit 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:
Reader observes the running job's
JobID: a testSourcewhoseSourceReadercallsreaderContext.getJobInfo().getJobId()insidecreateReader()and emits the value as a record. Run against aMiniCluster, assert the emitted record equals the actualJobIDof the submitted job.Enumerator observes the running job's
JobID: the same testSourceinvokesenumContext.getJobInfo().getJobId()insidecreateEnumerator(...), stores it in enumerator state, signals it back to readers via aSourceEvent. Assert match against the job's actualJobID.Recovery path: stop and restart the job, assert both
createReader(...)(post-restart) andrestoreEnumerator(...)observe the sameJobID,JobInfois stable across recovery within a single job's lifetime.
Unit tests:
SourceOperatorTest: assert theSourceReaderContextconstructed bySourceOperator.initReader()returns a non-nullJobInfomatching the operator'sStreamingRuntimeContext.getJobInfo().SourceCoordinatorContextTest: assertSplitEnumeratorContext.getJobInfo()returns theJobInfoprovided by the underlyingOperatorCoordinator.Context.Default-body correctness: a barebones implementation of each interface (providing only the abstract methods) is verified to throw
UnsupportedOperationExceptionfrom 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.
InitContextis@Internalat the interface level,@Publicinterfaces extending an@Internalis a stability-tier violation.InitContextlives inorg.apache.flink.api.connector.sink2, source code depending on asink2-packaged interface inverts the package layering.InitContext.getTaskInfo()does not fitSplitEnumeratorContext: 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:
SourceReaderContextalready exposesgetIndexOfSubtask()andcurrentParallelism()directly, inheritinggetTaskInfo()would create dual access paths needing a deprecation cycle.Scope creep: would require first promoting
InitContextfrom@Internalto@PublicEvolving(separate FLIP) and moving it out of thesink2package (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.