使用Docker在集群中火花:BlockManagerId;本地类不兼容

时间:2018-06-21 23:35:28

标签: scala apache-spark docker cluster-computing

使用Spark和Docker分发操作时遇到类型不匹配。 The tutorial我遵循的似乎很清楚。这是我尝试的Scala代码:

package test

import com.datastax.spark.connector.cql.CassandraConnector
import org.apache.spark.{SparkConf, SparkContext}
import readhub.sharedkernel.config.Settings

object Application extends App {
    import com.datastax.spark.connector._


    val conf = new SparkConf(true)
      .setAppName("Coordinator")
      .setMaster("spark://localhost:7077")
      .set("spark.cassandra.connection.host", "valid host")

    val sc = new SparkContext(conf)

    CassandraConnector(conf).withSessionDo { session =>
      session.execute("CREATE KEYSPACE test2 WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1 }")
      session.execute("CREATE TABLE test2.words (word text PRIMARY KEY, count int)")
      session.execute("INSERT INTO test2.words(word, count) VALUES('hey', 32)")

      sc.cassandraTable("test2", "words")
        .map(r => r.getString("word"))
        .foreach(process)

    }

  def process(word: String): Unit = {
    // Dummy processing
    println(word)
  }
} 

build.sbt看起来像这样:

import sbt.project

val sparkSql = "org.apache.spark" %% "spark-sql" % "2.3.0" % "provided"
val sparkCassandraConnector = "com.datastax.spark" %% "spark-cassandra-connector" % "2.3.0" % "provided"

lazy val commonSettings = Seq(
  version := "0.1",
  scalaVersion := "2.11.12",
  organization := "ch.heig-vd"
)

lazy val root = (project in file("."))
  .settings(
    commonSettings,
    name := "Root"
  )
  .aggregate(
    coordinator
  )

lazy val coordinator = project
  .settings(
    commonSettings,
    name := "Coordinator",
    libraryDependencies ++= Seq(
      sparkSql,
      sparkCassandraConnector
    )
  )

Dockerfile取自this image,并进行了轻微修改以使用Spark的2.3.0版本:

FROM phusion/baseimage:0.9.22

ENV SPARK_VERSION 2.3.0
ENV SPARK_INSTALL /usr/local
ENV SPARK_HOME $SPARK_INSTALL/spark
ENV SPARK_ROLE master
ENV HADOOP_VERSION 2.7
ENV SPARK_MASTER_PORT 7077
ENV PYSPARK_PYTHON python3
ENV DOCKERIZE_VERSION v0.2.0

RUN apt-get update && \
    apt-get install -y openjdk-8-jdk autossh python3-pip && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

##### INSTALL DOCKERIZE
RUN curl -L -O https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
    tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
    rm -rf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

##### INSTALL APACHE SPARK WITH HDFS
RUN curl -s http://mirror.synyx.de/apache/spark/spark-$SPARK_VERSION/spark-$SPARK_VERSION-bin-hadoop$HADOOP_VERSION.tgz | tar -xz -C $SPARK_INSTALL && \
    cd $SPARK_INSTALL && ln -s spark-$SPARK_VERSION-bin-hadoop$HADOOP_VERSION spark

WORKDIR $SPARK_HOME

##### ADD Scripts
RUN mkdir /etc/service/spark
ADD runit/spark.sh /etc/service/spark/run
RUN chmod +x /etc/service/**/*

EXPOSE 4040 6066 7077 7078 8080 8081 8888

VOLUME ["$SPARK_HOME/logs"]

CMD ["/sbin/my_init"]

docker-compose.yml也非常简单:

version: "3"

services:
  master:
    build: birgerk-apache-spark

    ports:
      - "7077:7077"
      - "8080:8080"

  slave:
    build: birgerk-apache-spark
    environment:
      - SPARK_ROLE=slave
      - SPARK_MASTER=master
    depends_on:
      - master

我将git repo克隆到文件夹birgerk-apache-spark中,仅将Spark的版本更改为2.3.0。

最后,我使用以下方法粘合所有东西:

sbt coordinator/assembly

创建胖子和

spark-submit --class test.Application --packages com.datastax.spark:spark-cassandra-connector_2.11:2.3.0 --master spark://localhost:7077 ReadHub\ Coordinator-assembly-0.1.jar

将jar提交到集群中。当我发出spark-submit时出现错误:

  

错误TransportRequestHandler:199-调用时出错   RPC ID为7068633004064450609的RpcHandler#receive()   java.io.InvalidClassException:   org.apache.spark.storage.BlockManagerId;本地类不兼容:   流类desc serialVersionUID = 6155820641931972169,本地类   serialVersionUID = -3720498261147521051           在java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:687)           在java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1876)           在java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1745)           在java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2033)           在java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1567)           在java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2278)           在java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2202)   [..]

从我的角度来看,Dockerfile正确下载了对应版本的Spark,该版本可以在我的build.sbt中作为依赖项找到。

我确定我缺少一些基本知识。有人能指出我正确的方向吗?

非常感谢!

1 个答案:

答案 0 :(得分:0)

spark 2.3.3和spark 2.3.0之间的版本不匹配。

请注意不要提交主机上定义的SPARK_HOME作业,这可能会导致此类问题