Skip to content

Commit

Permalink
[FLINK-8186] Exclude flink-avro from flink-dist; fix AvroUtils loading
Browse files Browse the repository at this point in the history
Before, AvroUtils were loaded when the class was loaded which didn't
take into account the user-code ClassLoader. Now, we try loading avro
utils with the Thread context ClassLoader.
  • Loading branch information
aljoscha committed Dec 5, 2017
1 parent dd48a40 commit f6e24ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ public abstract class AvroUtils {

private static final String AVRO_KRYO_UTILS = "org.apache.flink.formats.avro.utils.AvroKryoSerializerUtils";

private static final AvroUtils INSTANCE = loadAvroKryoUtils();

private static AvroUtils loadAvroKryoUtils() {
/**
* Returns either the default {@link AvroUtils} which throw an exception in cases where Avro
* would be needed or loads the specific utils for Avro from flink-avro.
*/
public static AvroUtils getAvroUtils() {
// try and load the special AvroUtils from the flink-avro package
try {
Class<?> clazz = Class.forName(AVRO_KRYO_UTILS, false, AvroUtils.class.getClassLoader());
Class<?> clazz = Class.forName(AVRO_KRYO_UTILS, false, Thread.currentThread().getContextClassLoader());
return clazz.asSubclass(AvroUtils.class).getConstructor().newInstance();
} catch (ClassNotFoundException e) {
// cannot find the utils, return the default implementation
Expand All @@ -52,14 +54,6 @@ private static AvroUtils loadAvroKryoUtils() {
}
}

/**
* Returns either the default {@link AvroUtils} which throw an exception in cases where Avro
* would be needed or loads the specific utils for Avro from flink-avro.
*/
public static AvroUtils getAvroUtils() {
return INSTANCE;
}

// ------------------------------------------------------------------------

/**
Expand Down
10 changes: 0 additions & 10 deletions flink-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ under the License.
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-avro</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
Expand Down Expand Up @@ -492,10 +486,6 @@ under the License.
</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.codehaus.jackson</pattern>
<shadedPattern>org.apache.flink.formats.avro.shaded.org.codehaus.jackson</shadedPattern>
</relocation>
<relocation>
<!-- relocate jackson services, which isn't done by flink-shaded-jackson -->
<pattern>com.fasterxml.jackson</pattern>
Expand Down

0 comments on commit f6e24ab

Please sign in to comment.