0

我想通过 TiSpark 将我的 Spark 集群连接到 TIDB,但是当我运行我的 Spark 应用程序时遇到问题,出现错误:

java.io.InvalidClassException: com.pingcap.tikv.region.TiRegion; 本地类不兼容:流 classdesc serialVersionUID = -3091715739322916126,本地类 serialVersionUID = -3556238418089320368

我正在按照https://pingcap.com/docs/v3.0/how-to/get-started/deploy-tidb-from-binary/上的指南设置 TIDB 集群

之后,我按照https://pingcap.com/docs/v3.0/reference/tispark/上的指南下载 tispark-core-2.2.0-SNAPSHOT-jar-with-dependencies.jar 并将其复制到我的 jar Spark 中的文件夹。

我还配置: spark.tispark.pd.addresses 127.0.0.1:2379 spark.sql.extensions org.apache.spark.sql.TiExtensions

这是我的pom文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.vng</groupId>
  <artifactId>testlan102</artifactId>
  <version>1.0-SNAPSHOT</version>
  <inceptionYear>2019</inceptionYear>
  <properties>
    <scala.version>2.11.12</scala.version>
    <spark.version>2.4.3</spark.version>
  </properties>

  <repositories>
    <repository>
      <id>scala-tools.org</id>
      <name>Scala-Tools Maven2 Repository</name>
      <url>http://scala-tools.org/repo-releases</url>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>scala-tools.org</id>
      <name>Scala-Tools Maven2 Repository</name>
      <url>http://scala-tools.org/repo-releases</url>
    </pluginRepository>
  </pluginRepositories>

  <dependencies>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-core_2.11</artifactId>
      <version>2.4.3</version>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-sql_2.11</artifactId>
      <version>2.4.3</version>
    </dependency>
    <dependency>
      <groupId>org.scala-lang.modules</groupId>
      <artifactId>scala-xml_2.11</artifactId>
      <version>1.2.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-streaming_2.11</artifactId>
      <version>2.4.3</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.kafka</groupId>
      <artifactId>kafka-streams</artifactId>
      <version>2.3.0</version>
    </dependency>
    <dependency>
      <groupId>com.pingcap.tispark</groupId>
      <artifactId>tispark-core</artifactId>
      <version>2.1.1-spark_2.4</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.37</version>
    </dependency>

    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>2.11.12</version>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
          <args>
            <arg>-target:jvm-1.5</arg>
          </args>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <configuration>
          <downloadSources>true</downloadSources>
          <buildcommands>
            <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
          </buildcommands>
          <additionalProjectnatures>
            <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
          </additionalProjectnatures>
          <classpathContainers>
            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
            <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
          </classpathContainers>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>fully.qualified.MainClass</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
</project>

我的 Spark 会话是:

val _spark = SparkSession.builder()
      .master("spark://127.0.0.1:7077")
      .config("spark.tispark.pd.addresses", "127.0.0.1:2379")
      .config("spark.sql.extensions","org.apache.spark.sql.TiExtensions")
      .appName("SparkApp")
      .getOrCreate()

当我对数据库调用一个简单的查询时:

_spark.sql("use locdb")
val df = _spark.sql("select * from bang")
df.show()

我收到一个错误:java.io.InvalidClassException: com.pingcap.tikv.region.TiRegion; 本地类不兼容:流 classdesc serialVersionUID = -3091715739322916126,本地类 serialVersionUID = -3556238418089320368

我的完整日志在这里: https ://gist.github.com/lploc94/bb6bf9db14c030ee123630f6362f6160

我认为原因是我在 maven pom 文件中使用了 TiSpark 2.1.1-2.4,但我下载并复制到 jars 文件夹的 Tispark jar 文件是 2.2.0。但我看不到任何其他版本的 TiSpark,例如 tispark-core-2.1.1-SNAPSHOT-jar-with-dependencies.jar

4

1 回答 1

0

我是tispark的开发者。是的,您有根据的猜测是正确的:)。在您的运行过程中有两个不同版本的 tispark jar 会导致问题。版本 2.2(在您的集群环境中)尚未正式发布到 maven repo 工件。

由于您已经在集群中部署了 tispark jar,因此您只需在 pom.xml 中删除 tispark 依赖项即可。在大多数情况下,您不需要 tispark 的任何特殊 api,除非您使用的是旧版本(< 2.0)并且您仍然可以直接查询 tidb。

或者您可以删除集群环境中的所有 jars 并依赖 pom 中的 tispark(如果是这样,请将其与依赖项一起打包)。

于 2019-07-25T15:23:37.343 回答