Skip to content
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

Incomplete runtime classpath #72

Merged
merged 1 commit into from
Feb 9, 2024
Merged

Incomplete runtime classpath #72

merged 1 commit into from
Feb 9, 2024

Conversation

cstamas
Copy link
Collaborator

@cstamas cstamas commented Feb 6, 2024

Similar fix to m-assembly-p: do not rely on Maven Core to provide
"runtime" resolution scope as it have issues, see:
https://issues.apache.org/jira/browse/MNG-8041

Instead, use Resolver APIs directly to get what is needed.
Contains several minor code improvements across Provisio
maven-plugin module.

Other changes in this PR:

  • added support for -X to dump proviso graph
  • marked Mojos as thread safe, removed now unneeded ask for resolution
    (as they use Resolver APIs)

Contains IT from #70
Fixes #71

@wendigo
Copy link
Collaborator

wendigo commented Feb 6, 2024

@cstamas can you rearrange/squash commits and update commit messages to better reflect the change?

@cstamas
Copy link
Collaborator Author

cstamas commented Feb 6, 2024

Done

private List<Artifact> resolveRuntimeScopeTransitively() {
DependencyFilter runtimeFilter = new ScopeDependencyFilter("system", "provided", "test");
List<org.eclipse.aether.graph.Dependency> dependencies = project.getDependencies().stream()
.map(d -> RepositoryUtils.toDependency(d, repositorySystemSession.getArtifactTypeRegistry()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/d/dependency

DependencyFilter runtimeFilter = new ScopeDependencyFilter("system", "provided", "test");
List<org.eclipse.aether.graph.Dependency> dependencies = project.getDependencies().stream()
.map(d -> RepositoryUtils.toDependency(d, repositorySystemSession.getArtifactTypeRegistry()))
.filter(d -> runtimeFilter.accept(new DefaultDependencyNode(d), Collections.emptyList()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/d/dependencyNode

@wendigo
Copy link
Collaborator

wendigo commented Feb 8, 2024

I tested this with Trino and now provided scope dependencies are included too. This shouldn't be the case afaik. Am I right @electrum ?

@cstamas
Copy link
Collaborator Author

cstamas commented Feb 8, 2024

That sound wrong. @wendigo could you provide a reproducer for that?

@cstamas
Copy link
Collaborator Author

cstamas commented Feb 8, 2024

Or at least point me at trino module that reproduce this?

@wendigo
Copy link
Collaborator

wendigo commented Feb 8, 2024

I've built locally Trino with the provisio build from this PR.

./mvnw clean install -T 2C -nsu -DskipTests

Comparing to the previous build (with the master version):

❯ tar -tvf ./core/trino-server/target/trino-server-439-SNAPSHOT.tar.gz | grep trino-spi | grep plugin | awk '{print $9}' | pbcopy
trino-server-439-SNAPSHOT/plugin/delta-lake/hdfs/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/delta-lake/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/geospatial/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/hive/hdfs/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/hive/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/hudi/hdfs/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/hudi/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/iceberg/hdfs/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/iceberg/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/kafka/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/kinesis/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/ml/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/raptor-legacy/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/redis/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/thrift/trino-spi-439-SNAPSHOT.jar

While before this change:

❯ tar -tvf ./core/trino-server/target/trino-server-439-SNAPSHOT.tar.gz | grep trino-spi | grep plugin | awk '{print $9}'
trino-server-439-SNAPSHOT/plugin/hudi/hdfs/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/delta-lake/hdfs/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/iceberg/hdfs/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/hive/hdfs/trino-spi-439-SNAPSHOT.jar

Both seems wrong too me but after this change it's even worse :)

@wendigo
Copy link
Collaborator

wendigo commented Feb 8, 2024

Mystery solved: trinodb/trino#20633

@cstamas
Copy link
Collaborator Author

cstamas commented Feb 8, 2024

Not quite: why are all trino-spi instanced there? As I debugged locally trino-server build, it even does not have dependencies (so modded code in BaseMojo does not kick in, well yes, but ends up with 0 deps), but MavenProvisioner.

@cstamas
Copy link
Collaborator Author

cstamas commented Feb 8, 2024

@wendigo please try with this one, after all, there is only one trino-spi needed (blind guess, I have no idea about server, but seems logical that /lib/trino-spi is shared across all plugins)

@wendigo
Copy link
Collaborator

wendigo commented Feb 8, 2024

@cstamas it is, it's added to the plugin classpath by the engine when it creates a plugin. That way plugin can communicate with the engine (they are sharing the same classes).

@cstamas
Copy link
Collaborator Author

cstamas commented Feb 8, 2024

As when I build locally trino-server now with latest changes in provisio, I end up with only one trino-spi, that is in lib.

@electrum
Copy link
Contributor

electrum commented Feb 8, 2024

I built this PR locally and updated Trino to use Provisio 1.0.21-SNAPSHOT, then built lib/trino-iceberg and I do see trino-spi, which should not be included as it's provided scope:

$ unzip -l plugin/trino-iceberg/target/trino-iceberg-439-SNAPSHOT.zip | grep trino-spi
   983789  02-08-2024 16:18   trino-iceberg-439-SNAPSHOT/trino-spi-439-SNAPSHOT.jar

@electrum
Copy link
Contributor

electrum commented Feb 8, 2024

On a positive note, when I change io.airlift:stats to test scope (from runtime scope), it is now included in the ZIP file, so that is working correctly.

@wendigo
Copy link
Collaborator

wendigo commented Feb 9, 2024

@cstamas I have once again tried this PR after I've merged trinodb/trino#20633 and now some plugins contains provide dependencies which shouldn't be the case:

trino-server-439-SNAPSHOT/lib/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/delta-lake/hdfs/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/delta-lake/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/geospatial/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/hive/hdfs/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/hive/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/hudi/hdfs/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/hudi/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/iceberg/hdfs/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/iceberg/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/kafka/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/kinesis/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/ml/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/raptor-legacy/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/redis/trino-spi-439-SNAPSHOT.jar
trino-server-439-SNAPSHOT/plugin/thrift/trino-spi-439-SNAPSHOT.jar

Same goes for jol-core:

trino-server-439-SNAPSHOT/lib/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/accumulo/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/atop/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/bigquery/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/blackhole/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/cassandra/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/clickhouse/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/delta-lake/hdfs/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/delta-lake/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/druid/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/elasticsearch/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/example-http/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/exchange-filesystem/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/exchange-hdfs/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/geospatial/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/google-sheets/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/hive/hdfs/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/hive/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/hudi/hdfs/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/hudi/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/iceberg/hdfs/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/iceberg/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/ignite/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/jmx/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/kafka/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/kinesis/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/kudu/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/local-file/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/mariadb/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/memory/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/ml/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/mongodb/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/mysql/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/opa/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/opensearch/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/oracle/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/password-authenticators/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/phoenix5/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/pinot/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/postgresql/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/prometheus/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/raptor-legacy/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/redis/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/redshift/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/resource-group-managers/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/session-property-managers/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/singlestore/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/sqlserver/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/thrift/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/tpcds/jol-core-0.17.jar
trino-server-439-SNAPSHOT/plugin/tpch/jol-core-0.17.jar

@wendigo
Copy link
Collaborator

wendigo commented Feb 9, 2024

If I check the dependency:tree for trino-tpch:

[INFO] +- org.openjdk.jol:jol-core:jar:0.17:provided

@wendigo
Copy link
Collaborator

wendigo commented Feb 9, 2024

Repro:

 ./mvnw provisio:1.0.22:provision -pl ':trino-tpch' -X -DskipTests
unzip plugin/trino-tpch/target/trino-tpch-439-SNAPSHOT.zip | grep jol-core
  inflating: trino-tpch-439-SNAPSHOT/jol-core-0.17.jar

@wendigo
Copy link
Collaborator

wendigo commented Feb 9, 2024

In the BaseMojo.resolveRuntimeScopeTransitively despite having DependencyFilter runtimeFilter = new ScopeDependencyFilter(JavaScopes.SYSTEM, JavaScopes.PROVIDED, JavaScopes.TEST); applied, we are getting this artifacts:

[com.fasterxml.jackson.core:jackson-databind:jar:2.16.1, com.fasterxml.jackson.core:jackson-annotations:jar:2.16.1, com.fasterxml.jackson.core:jackson-core:jar:2.16.1, com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.16.1, com.google.guava:guava:jar:33.0.0-jre, com.google.guava:failureaccess:jar:1.0.2, com.google.code.findbugs:jsr305:jar:3.0.2, org.checkerframework:checker-qual:jar:3.42.0, com.google.errorprone:error_prone_annotations:jar:2.24.1, com.google.j2objc:j2objc-annotations:jar:2.8, io.trino:trino-plugin-toolkit:jar:439-SNAPSHOT, com.google.inject:guice:jar:7.0.0, jakarta.inject:jakarta.inject-api:jar:2.0.1, aopalliance:aopalliance:jar:1.0, io.airlift:bootstrap:jar:240, io.airlift:log-manager:jar:240, org.apache.logging.log4j:log4j-to-slf4j:jar:2.17.1, org.apache.logging.log4j:log4j-api:jar:2.17.1, org.slf4j:jcl-over-slf4j:jar:2.0.11, org.slf4j:log4j-over-slf4j:jar:2.0.11, org.slf4j:slf4j-jdk14:jar:2.0.11, io.airlift:configuration:jar:240, net.bytebuddy:byte-buddy:jar:1.14.11, org.hibernate.validator:hibernate-validator:jar:8.0.1.Final, org.jboss.logging:jboss-logging:jar:3.4.3.Final, com.fasterxml:classmate:jar:1.5.1, io.airlift:http-client:jar:240, ch.qos.logback:logback-core:jar:1.4.14, io.airlift:concurrent:jar:240, io.airlift:trace-token:jar:240, io.opentelemetry:opentelemetry-api:jar:1.34.0, io.opentelemetry:opentelemetry-context:jar:1.34.0, io.opentelemetry.semconv:opentelemetry-semconv:jar:1.21.0-alpha, org.eclipse.jetty:jetty-client:jar:11.0.20, org.eclipse.jetty:jetty-alpn-client:jar:11.0.20, org.slf4j:slf4j-api:jar:2.0.11, org.eclipse.jetty:jetty-http:jar:11.0.20, org.eclipse.jetty:jetty-io:jar:11.0.20, org.eclipse.jetty:jetty-util:jar:11.0.20, org.eclipse.jetty.http2:http2-client:jar:11.0.20, org.eclipse.jetty.http2:http2-common:jar:11.0.20, org.eclipse.jetty.http2:http2-hpack:jar:11.0.20, org.eclipse.jetty.http2:http2-http-client-transport:jar:11.0.20, org.eclipse.jetty:jetty-alpn-java-client:jar:11.0.20, io.airlift:json:jar:240, com.fasterxml.jackson.datatype:jackson-datatype-guava:jar:2.16.1, com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.16.1, com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.16.1, com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.16.1, io.airlift:log:jar:240, io.airlift:security:jar:240, io.airlift:slice:jar:2.2, org.openjdk.jol:jol-core:jar:0.17, io.airlift:stats:jar:240, org.hdrhistogram:HdrHistogram:jar:2.1.9, io.airlift:units:jar:1.10, io.trino:trino-cache:jar:439-SNAPSHOT, io.trino:trino-matching:jar:439-SNAPSHOT, jakarta.annotation:jakarta.annotation-api:jar:2.1.1, jakarta.validation:jakarta.validation-api:jar:3.0.2, joda-time:joda-time:jar:2.12.7, org.gaul:modernizer-maven-annotations:jar:2.7.0, org.weakref:jmxutils:jar:1.25, io.airlift:node:jar:240, io.trino.tpch:tpch:jar:1.2]

which contains provided dependencies

@cstamas
Copy link
Collaborator Author

cstamas commented Feb 9, 2024

@wendigo see last commit, contains two things:

  • -X will now dump the collected graph (usable to verify)
  • resolution of "runtime" classpath fixed, as original fix was wrong: root provided ones were omitted, that allowed that deeper occurences of same dependency float up

Please retry!

@cstamas
Copy link
Collaborator Author

cstamas commented Feb 9, 2024

Extended the new IT with "case 2" as well (case1=guice+guava story, case2=deps via compile deps should not enter if provided). This is the verbose graph of IT project now:

[INFO] --- dependency:3.6.1:tree (default-cli) @ test ---
[INFO] ca.vanzyl.provisio.maven.plugins.its:test:provisio:1.0
[INFO] +- com.google.inject:guice:jar:7.0.0:compile
[INFO] |  +- jakarta.inject:jakarta.inject-api:jar:2.0.1:compile
[INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  \- (com.google.guava:guava:jar:31.0.1-jre:compile - omitted for duplicate)
[INFO] +- com.google.guava:guava:jar:31.0.1-jre:test (scope not updated to compile)
[INFO] |  +- com.google.guava:failureaccess:jar:1.0.1:test
[INFO] |  +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:test
[INFO] |  +- com.google.code.findbugs:jsr305:jar:3.0.2:test
[INFO] |  +- org.checkerframework:checker-qual:jar:3.12.0:test
[INFO] |  +- com.google.errorprone:error_prone_annotations:jar:2.7.1:test
[INFO] |  \- com.google.j2objc:j2objc-annotations:jar:1.3:test
[INFO] +- org.slf4j:slf4j-api:jar:2.0.11:provided (scope not updated to compile)
[INFO] \- org.slf4j:slf4j-simple:jar:2.0.11:compile
[INFO]    \- (org.slf4j:slf4j-api:jar:2.0.11:compile - omitted for duplicate)

And IT ensure two things:

  • on "runtime" classpath guava is present (as expected), on maven provided runtime is NOT (MNG-8041)
  • original PR introduced new bug: POM deps that were "provided" creeped in via deeper graph nodes (where they could be compile scoped, like here would slf4-api via slf4j-simple)

@cstamas
Copy link
Collaborator Author

cstamas commented Feb 9, 2024

With latest provisio changes rebuilt Trino, and in server tar I have these files (occurrence then file name):
https://gist.github.com/cstamas/3960feec5e502a9ea28b3ae2f199c75f

Unsure for the rest, but now the tarball has one trino-spi which is what is expected, I guess.

@wendigo
Copy link
Collaborator

wendigo commented Feb 9, 2024

I think that we can squash commits 3 and 4 together. I've tested it against Trino master and looks good - for some plugins it's now excluding test dependencies which were incorrectly includes in the zip.

Similar fix to m-assembly-p: do not rely on Maven Core to provide
"runtime" resolution scope as it have issues, see:
https://issues.apache.org/jira/browse/MNG-8041

Instead, use Resolver APIs directly to get what is needed.
Contains several minor code improvements across Provisio
maven-plugin module.

Other changes in this PR:
* added support for -X to dump proviso graph
* marked Mojos as thread safe, removed now unneeded ask for resolution
  (as they use Resolver APIs)

Contains IT from jvanzyl#70
Fixes jvanzyl#71
@wendigo wendigo merged commit 1f17f55 into jvanzyl:master Feb 9, 2024
3 checks passed
@cstamas cstamas deleted the issue-71 branch February 9, 2024 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incomplete runtime classpath
3 participants