【问题标题】:Netty Version Conflict with Spark + Elasticsearch TransportNetty 版本与 Spark + Elasticsearch 传输冲突
【发布时间】:2018-05-14 22:19:42
【问题描述】:

这有几个以前的问题,有答案,但答案通常没有足够清晰的信息来解决问题。

我正在使用 Apache Spark 将数据提取到 Elasticsearch 中。我们正在使用 X-Pack 安全性及其相应的传输客户端。我使用传输客户端在特殊情况下创建/删除索引,然后使用 Spark 进行摄取。当我们的代码到达client.close() 时会抛出异常:

Exception in thread "elasticsearch[_client_][generic][T#2]" java.lang.NoSuchMethodError: io.netty.bootstrap.Bootstrap.config()Lio/netty/bootstrap/BootstrapConfig;
        at org.elasticsearch.transport.netty4.Netty4Transport.lambda$stopInternal$5(Netty4Transport.java:443)
        at org.apache.lucene.util.IOUtils.close(IOUtils.java:89)
        at org.elasticsearch.common.lease.Releasables.close(Releasables.java:36)
        at org.elasticsearch.common.lease.Releasables.close(Releasables.java:46)
        at org.elasticsearch.common.lease.Releasables.close(Releasables.java:51)
        at org.elasticsearch.transport.netty4.Netty4Transport.stopInternal(Netty4Transport.java:426)
        at org.elasticsearch.transport.TcpTransport.lambda$doStop$5(TcpTransport.java:959)
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:569)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

起初,我认为 X-Pack Transport 客户端使用的是从 Spark 进来的 Netty,所以我排除了它。即使在排除它之后,我们也会遇到同样的问题。这是我们的一组依赖项:

    libraryDependencies ++= Seq(
   "com.crealytics" % "spark-excel_2.11" % "0.9.1" exclude("io.netty", "netty-all"),
  "com.github.alexarchambault" %% "scalacheck-shapeless_1.13" % "1.1.6" % Test,
  "com.holdenkarau" % "spark-testing-base_2.11" % "2.2.0_0.7.4" % Test exclude("org.scalatest", "scalatest_2.11") ,
  "com.opentable.components" % "otj-pg-embedded" % "0.9.0" % Test,
  "org.apache.spark" % "spark-core_2.11" % "2.2.0" % "provided" exclude("org.scalatest", "scalatest_2.11") exclude("io.netty", "netty-all"),
  "org.apache.spark" % "spark-sql_2.11" % "2.2.0" % "provided" exclude("org.scalatest", "scalatest_2.11") exclude("io.netty", "netty-all"),
  "org.apache.spark" % "spark-hive_2.11" % "2.2.0" % "provided" exclude("org.scalatest", "scalatest_2.11") exclude("io.netty", "netty-all"),
  "org.apache.logging.log4j" % "log4j-core" %"2.8.2",
  "org.elasticsearch" % "elasticsearch-spark-20_2.11" % "5.5.0" exclude("org.scalatest", "scalatest_2.11") exclude("io.netty", "netty-all"),
  "org.elasticsearch.client" % "x-pack-transport" % "5.5.0",
  "org.elasticsearch.client" % "transport" % "5.5.0",
  "org.elasticsearch.test" % "framework" % "5.4.3" % Test,
  "org.postgresql" % "postgresql" % "42.1.4",
  "org.scalamock" %% "scalamock-scalatest-support" % "3.5.0" % Test,
  "org.scalatest" % "scalatest_2.11" % "3.0.1" % Test,
  "org.scalacheck" %% "scalacheck" % "1.13.4" % Test,
  "org.scalactic" %% "scalactic" % "3.0.1",
  "org.scalatest" %% "scalatest" % "3.0.1" % Test,
  "mysql" % "mysql-connector-java" % "5.1.44"
      )

我通过sbt dependencyTree 验证了 SBT 不排除来自 Spark 和 spark-excel 的 netty,我不确定为什么...我们使用的是 SBT 1.0.4。

更新:spark-submit/Spark 是罪魁祸首,请在下面回答!

【问题讨论】:

  • ExclusionRule() 似乎不接受版本...
  • 将 excludeAll 改为 exclude 无效
  • excludeAll ExclusionRule(organization = "com.fasterxml.jackson.core"), "io.confluent" % "common-config" % "3.1.2" 你可以这样做吗?跨度>
  • @AkhilanandBenkalVenkanna 实际上,我的排除项现在正在工作,我只看到 4.1.11 及更高版本。但是,我打开 SBT 制作的 jar 包,发现 org.jboss.netty 被包含在内,但是在 SBT 中拉起依赖关系树并没有显示任何包含此依赖关系。
  • Kool.. 请务必发布您最终有效的解决方案,以便其他人可以从中受益!

标签: scala apache-spark elasticsearch sbt netty


【解决方案1】:

好的,经过多次考验和磨难,我想通了。问题不在于 SBT 未能排除库,而是完美地排除了它们。问题是,即使我排除了任何不是 4.1.11.Final 的 Netty 版本,Spark 仍在使用它自己的 jar,在 SBT 和我构建的 jar 之外。

spark-submit 运行时,它包含来自$SPARK_HOME/lib 目录的jar。其中之一是旧版本的 Netty 4。此调用显示了此问题:

bootstrap.getClass().getProtectionDomain().getCodeSource()

结果是/usr/local/Cellar/apache-spark/2.2.0/libexec/jars/netty-all-4.0.43.Final.jar的jar位置

因此,Spark 包含了它自己的 Netty 依赖项。当我在 SBT 中创建我的 jar 时,它有正确的 jar。 Spark 对此有一个名为 spark.driver.userClassPathFirst 的配置,记录在 in the Spark config documentation 但是当我将其设置为 true 时,我最终会遇到与使用更高版本的 Netty 相关的问题。

我决定放弃使用传输客户端,转而使用可靠的旧 HTTP 请求。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,需要将 Netty 与 Spark 结合使用的依赖项。我还尝试了spark.driver.userClassPathFirst 选项,但它不起作用。我确实找到了另一种解决方法,我认为我会分享,以防将来对其他人有帮助。

    由于我们正在创建一个与 spark-submit 一起使用的程序集 jar,我想我可以在程序集 jar 中隐藏依赖项,以便 spark-submit 可以引入它自己的 Netty 版本而不会发生冲突。我们正在使用https://github.com/sbt/sbt-assembly 插件,所以我需要做的就是将其包含在我的build.sbt 中的相关模块中:

    assemblyShadeRules in assembly := Seq(
      ShadeRule.rename("io.netty.**" -> "shadenetty.@1").inAll
    )
    

    【讨论】:

      【解决方案3】:

      从 spark-core 中排除 Netty 依赖项对我们有用

              <dependency>
                  <groupId>org.apache.spark</groupId>
                  <artifactId>spark-core_2.10</artifactId>
                  <version>${spark.version}</version>
                  <exclusions>
                      <exclusion>
                          <groupId>io.netty</groupId>
                          <artifactId>netty-all</artifactId>
                      </exclusion>
                      <exclusion>
                          <groupId>io.netty</groupId>
                          <artifactId>netty</artifactId>
                      </exclusion>
                  </exclusions>
              </dependency>
      

      【讨论】:

        猜你喜欢
        • 2016-10-17
        • 2019-06-21
        • 1970-01-01
        • 2020-11-13
        • 1970-01-01
        • 2020-03-10
        • 2017-06-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多