ahmedabu98 opened a new pull request, #41872: URL: https://github.com/apache/beam/pull/41872
`scripts/beam-sql.sh` is slow the first time. It writes a POM for the shell's dependencies and runs maven-shade-plugin to repack all of them into one 430 MB JAR, including the 340 MB `beam-sdks-java-extensions-sql-jdbc` uber JAR. The repacking relocates nothing. It merges service files and marks the JAR Multi-Release, and a plain classpath gets both once the JDBC JAR itself is Multi-Release. There are two commits. **Make the Beam SQL JDBC JAR Multi-Release.** The JDBC JAR bundles dnsjava. dnsjava registers `org.xbill.DNS.spi.DnsjavaInetAddressResolverProvider` as a `java.net.spi.InetAddressResolverProvider`, and that class only exists in `META-INF/versions/18/`. Java only looks there in a JAR whose manifest says `Multi-Release: true`. So on Java 18+, with the JDBC JAR on a plain classpath (as a JDBC driver, for example), every host lookup fails: ``` java.util.ServiceConfigurationError: java.net.spi.InetAddressResolverProvider: Provider org.xbill.DNS.spi.DnsjavaInetAddressResolverProvider not found ``` The expansion service JARs had the same bug (#33471) and got the same fix (#33472). beam-sql.sh users haven't hit it because the shade step marks its JAR Multi-Release. Name resolution doesn't change. dnsjava's provider is opt-in: unless `-Dorg.dnsjava.spi.enable=true` is set, it returns the JDK's own resolver. The JAR's other versioned classes are Java 9+ builds of Byte Buddy, Bouncy Castle, JAXB, kotlin-reflect, snakeyaml and apicurio, plus faster number parsing in Jackson. Each comes from the same library JAR as its base class, and this module relocates nothing, so turning them on doesn't mix library versions. The commit also leaves out the bundled `META-INF/versions/*/module-info.class` files (commons-compress, jackson-jaxrs-json, dnsjava). In a Multi-Release JAR, Java would take one of them as the JAR's own descriptor on the module path. On Java 18+ the JAR would turn into the module `org.dnsjava`, which fails to resolve, instead of the automatic module `org.apache.beam.sdk.extensions.sql.jdbc` it is today. **Start beam-sql.sh from Maven's local repository.** The script now asks Maven for the classpath (`dependency:build-classpath`) and caches it as `~/.beam/cache/<config>.classpath`. Then it starts the shell with `java @argfile`, because the classpath can be too long for one argument. This is the default. `--uber-jar` builds the self-contained JAR as before. A cached JAR, from `--uber-jar` or from an earlier version of the script, is still used when it's there. Released versions still have a JDBC JAR that isn't Multi-Release. For those, the script copies dnsjava's provider out of the JDBC JAR into a small Multi-Release JAR at the end of the classpath, where it can only add classes that no other JAR has. In the 2.78.0 and 2.79.0-SNAPSHOT JDBC JARs, it's the only registered service whose class exists only in `META-INF/versions`. First start with a warm Maven cache on two CPUs (`taskset -c 0,1`), with `--io iceberg`: | | before | after | |---|---|---| | 2.78.0 | 69 s | 16 s | | 2.79.0-SNAPSHOT | 75 s | 20 s | A start with a cached JAR or classpath takes 1.3 s before and 1.7 s after. Other things I checked: * The same copy of a duplicated class wins. The shade step keeps the first copy in Maven's classpath order, which is also the order the classpath is searched in: all 183,588 class entries in a shaded 2.79.0-SNAPSHOT JAR came from the first JAR on the classpath that has them. Once the JDBC JAR is Multi-Release, 12 of about 180,000 classes load differently on Java 21: eight Jackson number-parsing variants in the vendored Calcite and Parquet JARs, which aren't Multi-Release, and four JAXB classes that the shaded JAR mixes from jaxb-impl 2.2.3 and 2.3.3. * Conscrypt (#41486): the POM keeps its exclusions, and the JDBC JAR is still the only JAR on the classpath with Conscrypt classes or native libraries. * Snapshots are listed by their timestamped file names (`-Daether.artifactResolver.snapshotNormalization=false`), which later downloads don't overwrite. A cached snapshot shell keeps its JARs, as the cached uber JAR did. The exception is snapshots you install yourself, for example with `publishToMavenLocal`. Those only have a `-SNAPSHOT.jar` name, so a shell started from them picks up later installs. * If a file on the cached classpath is gone from `~/.m2`, the script resolves the classpath again. * Dataflow stages the files on the classpath. With `--runner dataflow` and a local staging location, the shell staged all 362 JARs, including the JDBC JAR and the small dnsjava JAR, instead of one uber JAR. Testing: * `:sdks:java:extensions:sql:jdbc:test` and `:sdks:java:extensions:sql:jdbc:shadowJarTest` pass. * On Java 21 and 25, `InetAddress.getByName` with only the JDBC JAR on the classpath failed before this change and works after it. * `--io iceberg` with a Hadoop catalog in /tmp: CREATE CATALOG, CREATE DATABASE, CREATE EXTERNAL TABLE, INSERT and SELECT. * `--io iceberg` with a REST catalog at biglake.googleapis.com and a project that doesn't exist. The service answers with an HTTP error, so host lookups work. Taking the small dnsjava JAR off the classpath brings back `Failed to refresh Google access token`. * Both of those also work without the small dnsjava JAR, using a copy of the published JDBC JAR that only adds `Multi-Release: true`. * `--version 2.78.0` reaches GCS. It doesn't when I take the small dnsjava JAR off the classpath. * `--uber-jar` builds the same JAR as before (200,005 entries). I couldn't test on macOS (the script sticks to bash 3.2 and BSD tools), on ARM, or on Java 17, and I didn't submit a real Dataflow job. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
