Skip to content

Commit 42b49df

Browse files
authored
apacheGH-40907: [Java][FlightSQL] Shade slf4j-api in JDBC driver (apache#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 <[email protected]> Signed-off-by: David Li <[email protected]>
1 parent 096cdad commit 42b49df

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Objects;
3232
import java.util.Optional;
3333
import java.util.Properties;
34+
import java.util.logging.Logger;
3435

3536
import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty;
3637
import org.apache.arrow.driver.jdbc.utils.UrlParser;
@@ -58,7 +59,7 @@ public class ArrowFlightJdbcDriver extends UnregisteredDriver {
5859
// Netty requires some extra properties to unlock some native memory management api
5960
// Setting this property if not already set externally
6061
// This has to be done before any netty class is being loaded
61-
final String key = "cfjd.io.netty.tryReflectionSetAccessible";
62+
final String key = "io.netty.tryReflectionSetAccessible";
6263
final String tryReflectionSetAccessible = System.getProperty(key);
6364
if (tryReflectionSetAccessible == null) {
6465
System.setProperty(key, Boolean.TRUE.toString());
@@ -67,6 +68,13 @@ public class ArrowFlightJdbcDriver extends UnregisteredDriver {
6768
new ArrowFlightJdbcDriver().register();
6869
}
6970

71+
@Override
72+
public Logger getParentLogger() {
73+
// Return the logger associated with the driver package ('org.apache.arrow.driver.jdbc')
74+
// When packaged in flight-sql-jdbc-driver, it will also apply to all shaded dependencies
75+
return Logger.getLogger(getClass().getPackage().getName());
76+
}
77+
7078
@Override
7179
public ArrowFlightConnection connect(final String url, final Properties info)
7280
throws SQLException {

java/flight/flight-sql-jdbc-driver/pom.xml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@
9797
<artifactId>slf4j-api</artifactId>
9898
<scope>runtime</scope>
9999
</dependency>
100+
<dependency>
101+
<groupId>org.slf4j</groupId>
102+
<artifactId>slf4j-jdk14</artifactId>
103+
<scope>runtime</scope>
104+
</dependency>
100105

101106
<dependency>
102107
<groupId>io.netty</groupId>
@@ -190,17 +195,16 @@
190195
<relocations>
191196
<relocation>
192197
<pattern>com.</pattern>
193-
<shadedPattern>cfjd.com.</shadedPattern>
198+
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.com.</shadedPattern>
194199
<excludes>
195200
<exclude>com.sun.**</exclude>
196201
</excludes>
197202
</relocation>
198203
<relocation>
199204
<pattern>org.</pattern>
200-
<shadedPattern>cfjd.org.</shadedPattern>
205+
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.org.</shadedPattern>
201206
<excludes>
202207
<exclude>org.apache.arrow.driver.jdbc.**</exclude>
203-
<exclude>org.slf4j.**</exclude>
204208
<!-- Avoid shading Flight JDBC Properties -->
205209
<exclude>org.apache.arrow.flight.name</exclude>
206210
<exclude>org.apache.arrow.flight.version</exclude>
@@ -210,24 +214,24 @@
210214
</relocation>
211215
<relocation>
212216
<pattern>io.</pattern>
213-
<shadedPattern>cfjd.io.</shadedPattern>
217+
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.io.</shadedPattern>
214218
</relocation>
215219
<relocation>
216220
<pattern>net.</pattern>
217-
<shadedPattern>cfjd.net.</shadedPattern>
221+
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.net.</shadedPattern>
218222
</relocation>
219223
<relocation>
220224
<pattern>mozilla.</pattern>
221-
<shadedPattern>cfjd.mozilla.</shadedPattern>
225+
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.mozilla.</shadedPattern>
222226
</relocation>
223227
<!-- Entries to relocate netty native libraries -->
224228
<relocation>
225229
<pattern>META-INF.native.libnetty_</pattern>
226-
<shadedPattern>META-INF.native.libcfjd_netty_</shadedPattern>
230+
<shadedPattern>META-INF.native.liboaadj_netty_</shadedPattern>
227231
</relocation>
228232
<relocation>
229233
<pattern>META-INF.native.netty_</pattern>
230-
<shadedPattern>META-INF.native.cfjd_netty_</shadedPattern>
234+
<shadedPattern>META-INF.native.oaadj_netty_</shadedPattern>
231235
</relocation>
232236
</relocations>
233237
<transformers>

java/flight/flight-sql-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/ITDriverJarValidation.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
/**
4343
* Check the content of the JDBC driver jar
4444
*
45-
* After shading everything should be either under org.apache.arrow.driver.jdbc.,
46-
* org.slf4j., or cfjd. packages
45+
* After shading everything should be either under org.apache.arrow.driver.jdbc. package
4746
*/
4847
public class ITDriverJarValidation {
4948
/**
@@ -57,8 +56,6 @@ public class ITDriverJarValidation {
5756
*/
5857
public static final Set<String> ALLOWED_PREFIXES = ImmutableSet.of(
5958
"org/apache/arrow/driver/jdbc/",
60-
"cfjd/",
61-
"org/slf4j/",
6259
"META-INF/");
6360

6461
/**

java/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,11 @@
680680
<artifactId>slf4j-api</artifactId>
681681
<version>${dep.slf4j.version}</version>
682682
</dependency>
683+
<dependency>
684+
<groupId>org.slf4j</groupId>
685+
<artifactId>slf4j-jdk14</artifactId>
686+
<version>${dep.slf4j.version}</version>
687+
</dependency>
683688
<dependency>
684689
<groupId>javax.annotation</groupId>
685690
<artifactId>javax.annotation-api</artifactId>

0 commit comments

Comments
 (0)