Skip to content

Commit

Permalink
apacheGH-40907: [Java][FlightSQL] Shade slf4j-api in JDBC driver (apa…
Browse files Browse the repository at this point in the history
…che#40908)

### Rationale for this change

FlightSQL JDBC Driver does not shade slfj4 api which may come into conflict into the version used by an application. If the application uses slf4j 1.x, it may cause the application slf4j backend to not be loaded properly.

The change configured maven-shade-plugin to also shade slf4j-api. To make sure log messages are still visible, slf4j-jdk14 is included as well so that all messages will be redirected to `java.util.logging` framework. The application can use jul-to-slf4j adapter to redirect log messages back to slf4j.

### What changes are included in this PR?

Overrides `Driver#getParentLogger()` to return the root logger for the JDBC driver (which is `org.apache.arrow.driver.jdbc`). To make sure shaded dependencies loggers are included as well, change relocation from `cfjd.`  to `org.apache.arrow.driver.jdbc.shaded. `(or `oaadj` for native libraries)

### Are these changes tested?

Verifying that slf4j-api is shaded along with the other relocation changes are covered by `ITDriverJarValidation`

### Are there any user-facing changes?

Yes. Driver will not expose directly slf4j api and the logger names for the shaded dependencies have been updated. For applications which were relying on configuring directly a slf4j logging backend for the driver, they may need to include `org.slf4j:slf4-api` and `org.slf4j:jul-to-slf4j` for logging configuration to work.
* GitHub Issue: apache#40907

Authored-by: Laurent Goujon <laurent@apache.org>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
laurentgo authored and tolleybot committed May 4, 2024
1 parent e24a4db commit 41f54ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
20 changes: 12 additions & 8 deletions java/flight/flight-sql-jdbc-driver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
<artifactId>slf4j-api</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>io.netty</groupId>
Expand Down Expand Up @@ -192,17 +197,16 @@
<relocations>
<relocation>
<pattern>com.</pattern>
<shadedPattern>cfjd.com.</shadedPattern>
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.com.</shadedPattern>
<excludes>
<exclude>com.sun.**</exclude>
</excludes>
</relocation>
<relocation>
<pattern>org.</pattern>
<shadedPattern>cfjd.org.</shadedPattern>
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.org.</shadedPattern>
<excludes>
<exclude>org.apache.arrow.driver.jdbc.**</exclude>
<exclude>org.slf4j.**</exclude>
<!-- Avoid shading Flight JDBC Properties -->
<exclude>org.apache.arrow.flight.name</exclude>
<exclude>org.apache.arrow.flight.version</exclude>
Expand All @@ -212,24 +216,24 @@
</relocation>
<relocation>
<pattern>io.</pattern>
<shadedPattern>cfjd.io.</shadedPattern>
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.io.</shadedPattern>
</relocation>
<relocation>
<pattern>net.</pattern>
<shadedPattern>cfjd.net.</shadedPattern>
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.net.</shadedPattern>
</relocation>
<relocation>
<pattern>mozilla.</pattern>
<shadedPattern>cfjd.mozilla.</shadedPattern>
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.mozilla.</shadedPattern>
</relocation>
<!-- Entries to relocate netty native libraries -->
<relocation>
<pattern>META-INF.native.libnetty_</pattern>
<shadedPattern>META-INF.native.libcfjd_netty_</shadedPattern>
<shadedPattern>META-INF.native.liboaadj_netty_</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.netty_</pattern>
<shadedPattern>META-INF.native.cfjd_netty_</shadedPattern>
<shadedPattern>META-INF.native.oaadj_netty_</shadedPattern>
</relocation>
</relocations>
<transformers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
/**
* Check the content of the JDBC driver jar
*
* After shading everything should be either under org.apache.arrow.driver.jdbc.,
* org.slf4j., or cfjd. packages
* After shading everything should be either under org.apache.arrow.driver.jdbc. package
*/
public class ITDriverJarValidation {
/**
Expand All @@ -57,8 +56,6 @@ public class ITDriverJarValidation {
*/
public static final Set<String> ALLOWED_PREFIXES = ImmutableSet.of(
"org/apache/arrow/driver/jdbc/",
"cfjd/",
"org/slf4j/",
"META-INF/");

/**
Expand Down

0 comments on commit 41f54ec

Please sign in to comment.