[dist] Shade and relocate kafka-clients and jackson in flink-agents-dist - #1110
Open
ysymi wants to merge 1 commit into
Open
[dist] Shade and relocate kafka-clients and jackson in flink-agents-dist#1110ysymi wants to merge 1 commit into
ysymi wants to merge 1 commit into
Conversation
Relocate third-party packages that are commonly present in user job JARs or on the Flink classpath under org.apache.flink.agents.shaded.* so the dist fat JAR does not clash with user code sharing the same ClassLoader (dist submitted via --jars or placed in lib/). A version mismatch on these packages otherwise surfaces as NoSuchMethodError / ClassCastException at runtime. Relocations: org.apache.kafka (kafka-clients is ubiquitous in streaming jobs) and com.fasterxml (jackson is the de-facto JSON library in user code). Packages Flink already relocates in flink-shaded-* are not repeated, and kotlin/okhttp3/okio are intentionally NOT relocated: the shade plugin's resource-name string replacement corrupts Kotlin's .kotlin_builtins metadata files, and okhttp3/okio are Kotlin-based and must move together with kotlin stdlib. Also: merge META-INF/services entries across bundled JARs (ServicesResourceTransformer) so relocated service implementations stay discoverable, and drop third-party META-INF/versions/21 classes, which the shade plugin cannot reliably process — the base versions are used instead; our own versions/21 entries (JDK 21 Continuation support) are preserved. Verified by building dist/flink-2.3: relocated packages contain no un-relocated residue, bytecode of runtime/plan classes references only the shaded paths (remaining mentions are log-message string constants), and runtime unit tests pass unchanged. Generated-by: Pi coding agent 0.85.1 (glm-5.3) Co-Authored-By: Pi <noreply@earendil.works>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue: #652
Purpose of change
flink-agents-dist-*.jaris a fat JAR that bundles third-party dependencieswithout relocation. When users add it via
--jarsor place it in Flink'slib/, its dependencies share the ClassLoader with the user's job JAR, andversion mismatches surface as
NoSuchMethodError/ClassCastExceptionatruntime.
This PR adds shade relocation to
dist/pom.xml. Sincedistis the parentpom (packaging=pom), a single change applies to all five Flink-version
submodules (flink-1.20 / 2.0 / 2.1 / 2.2 / 2.3).
What is relocated (the two entries rated High/Medium in the issue's risk
table, present in almost every streaming job):
org.apache.kafka→org.apache.flink.agents.shaded.org.apache.kafkacom.fasterxml→org.apache.flink.agents.shaded.com.fasterxmlWhat is intentionally not relocated, and why:
replacement corrupts Kotlin's
.kotlin_builtinsmetadata files (verified inour internal production build). okhttp3/okio are Kotlin-based and must move
together with kotlin-stdlib, so they stay unshaded as a group.
issue itself; relocating them risks breaking SDK-internal hardcoded class
names for little benefit. Can be follow-ups if real conflict reports appear.
flink-shaded-*(e.g. guava, netty) arenot repeated.
Necessary companion changes:
ServicesResourceTransformermergesMETA-INF/servicesentries acrossbundled JARs so relocated SPI implementations stay discoverable.
META-INF/versions/21/classes are dropped — the shade plugincannot reliably process them and the base versions are used instead. Our own
versions/21/org/apache/flink/**entries (JDK 21 Continuation support) arepreserved.
Tests
Verified by building
dist/flink-2.3:original
org/apache/kafka/andcom/fasterxml/paths).javap -c): runtime/plan classes reference only theshaded paths; remaining mentions are log-message string constants.
Note: this is a pom-only change; community CI (
./tools/ut.sh,./tools/lint.sh) covers the full build across versions.API
No public API changes.
Documentation
doc-neededdoc-not-neededdoc-includedWas this patch authored or co-authored using generative AI tooling?
Generated-by: Pi coding agent 0.85.1 (glm-5.3)