-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLINK-7973] fix shading and relocating Hadoop for the S3 filesystems #4961
Conversation
- do not shade everything, especially not JDK classes! -> instead define include patterns explicitly - do not shade core Flink classes (only those imported from flink-hadoop-fs) - hack around Hadoop loading (unshaded/non-relocated) classes based on names in the core-default.xml by overwriting the Configuration class (we may need to extend this for the mapred-default.xml and hdfs-defaults.xml): -> provide a core-default-shaded.xml file with shaded class names and copy and adapt the Configuration class of the respective Hadoop version to load this file instead of core-default.xml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to add a README.md to both modules explaining the reasoning for the Configuration class, how to properly update the hadoop dependency, including the Configuration shading, along with a checklist of what to verify when modifying anything.
@@ -33,6 +33,7 @@ under the License. | |||
<packaging>jar</packaging> | |||
|
|||
<properties> | |||
<!-- Do not change this without updating the copied Configuration class! --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add a similar comment to the presto hadoop dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done (also the other suggestions)
@@ -277,6 +336,7 @@ under the License. | |||
<exclude>META-INF/maven/org.apache.commons/**</exclude> | |||
<exclude>META-INF/maven/org.apache.flink/flink-hadoop-fs/**</exclude> | |||
<exclude>META-INF/maven/org.apache.flink/force-shading/**</exclude> | |||
<exclude>core-default.xml</exclude> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comment that we're using our own shaded core-default.xml
@@ -284,6 +322,7 @@ under the License. | |||
<exclude>META-INF/maven/org.apache.h*/**</exclude> | |||
<exclude>META-INF/maven/org.apache.flink/flink-hadoop-fs/**</exclude> | |||
<exclude>META-INF/maven/org.apache.flink/force-shading/**</exclude> | |||
<exclude>core-default.xml</exclude> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as in the other pom
- also fix the (integration) tests not working because they tried to load the relocated classes which are apparently not available there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
- `src/test/resources/core-site.xml` (as is) | ||
3. verify the shaded jar: | ||
- does not contain any unshaded classes except for `org.apache.flink.fs.s3presto.S3FileSystemFactory` | ||
- every other classes should be under `org.apache.flink.fs.s3presto.shaded` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"every other class" or "all other classes"
- `src/test/resources/core-site.xml` (as is) | ||
3. verify the shaded jar: | ||
- does not contain any unshaded classes except for `org.apache.flink.fs.s3hadoop.S3FileSystemFactory` | ||
- every other classes should be under `org.apache.flink.fs.s3hadoop.shaded` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"every other class" or "all other classes"
setup. For this to work, however, we needed to adapt Hadoop's `Configuration` | ||
class to load a (shaded) `core-default-shaded.xml` configuration with the | ||
relocated class names of classes loaded via reflection | ||
(in the fute, we may need to extend this to `mapred-default.xml` and `hdfs-defaults.xml` and their respective configuration classes). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "fute"
- `src/test/resources/core-site.xml` (as is) | ||
3. verify the shaded jar: | ||
- does not contain any unshaded classes except for `org.apache.flink.fs.s3hadoop.S3FileSystemFactory` | ||
- every other classes should be under `org.apache.flink.fs.s3hadoop.shaded` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "classes"
setup. For this to work, however, we needed to adapt Hadoop's `Configuration` | ||
class to load a (shaded) `core-default-shaded.xml` configuration with the | ||
relocated class names of classes loaded via reflection | ||
(in the fute, we may need to extend this to `mapred-default.xml` and `hdfs-defaults.xml` and their respective configuration classes). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "fute"
- `src/test/resources/core-site.xml` (as is) | ||
3. verify the shaded jar: | ||
- does not contain any unshaded classes except for `org.apache.flink.fs.s3presto.S3FileSystemFactory` | ||
- every other classes should be under `org.apache.flink.fs.s3presto.shaded` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "classes"
I think this looks good now that the comments are addressed. @zentol what do you think? |
|
I added two end-to-end tests and it seems for presto this currently fails with:
This is my branch with the end-to-end tests: https://github.com/aljoscha/flink/tree/finish-pr-4961-s3-shading-fixing |
This was causing "java.lang.ClassNotFoundException: org.apache.flink.fs.s3presto.shaded.org.apache.commons.logging.impl.LogFactoryImpl" since these classes are not statically imported and thus removed when minimizing.
unfortunately, it seems we cannot minimize the shaded |
This uses traps to ensure that we properly do cleanups, remove config values and shutdown things.
I did include your end-to-end tests (with some fixes) and the fixes for the errors they found. Should be fine now, let's see what travis says... |
Also improve some search patterns in general.
This look even better now! Waiting for Travis and then I'll merge. Thanks! 😃 |
Could you please close the PR if it doesn't auto-close? |
What is the purpose of the change
The current shading of the
flink-s3-fs-hadoop
andflink-s3-fs-presto
projects also relocates Flink core classes and even some from the JDK itself. Additionally, the relocation of Hadoop does not work as expected since Hadoop loads classes based on class names in itscore-default.xml
which are unshaded and thus use the original namespace.Brief change log
pom.xml
of bothflink-s3-fs-hadoop
andflink-s3-fs-presto
:core-default.xml
by overwriting theConfiguration
class (we may need to also extend this for themapred-default.xml
andhdfs-defaults.xml
and their respective configuration classes in the future):core-default-shaded.xml
file with shaded class names andConfiguration
class of the respective Hadoop version to load this file instead ofcore-default.xml
(Thanks @zentol and @StephanEwen for helping to find and fix this.)
Verifying this change
This change can (and was) manually tested as follows:
jar
file does not contain non-relocated classesConfiguration
classes reside in the shaded namespace where the original HadoopConfiguration
classes would go into, e.g.org.apache.flink.fs.s3hadoop.shaded.org.hadoop.conf
(look forcore-default-shaded.xml
string in theConfiguration.class
file)META-INF/services
files are still correct (name + content)Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (no)Documentation