我想通过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并将其复制到我的Spark的jars文件夹中。
我还配置: spark.tispark.pd。地址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
答案 0 :(得分:0)
我是tispark的开发人员。 是的,您有根据的猜测是正确的:)。运行期间有两种不同版本的tispark jars引起问题。 2.2版(在您的集群环境中)尚未正式发布到Maven回购工件。
由于您已经在集群中部署了tispark jar,因此只需删除pom中的tispark依赖项即可。在大多数情况下,除非您使用旧版本(<2.0),并且您仍然可以直接查询tidb,则不需要tispark的任何特殊api。
或者您可以删除集群环境中的所有jar,然后依靠pom中的tispark(如果是,请打包依赖项)。