我一直试图在scala中连接cassandra和Spark,但我遇到了一些问题。以下是使用的版本:
Spark 1.5.0
Cassandra 2.1.9
Scala 2.11.1
以下是我遵循的步骤:-下载了默认配置的Cassandra,我通过bin/casandra-f启动了它。Cassandra开局不错,收听127.0.0.1-我在spark密钥空间的try表中添加了一些模拟数据。-下载了Spark并通过sbin/start-master.sh启动了master。我可以在localhost:8888上看到master运行良好-我写了以下build.sbt:
val sparkVersion = "1.5.0"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
ws,
"org.scalatest" % "scalatest_2.11" % "3.0.0-M8",
"com.typesafe" % "scalalogging-slf4j_2.10" % "1.1.0",
"com.typesafe.scala-logging" %% "scala-logging" % "3.1.0",
"org.apache.spark" % "spark-core_2.11" % sparkVersion,
"org.apache.spark" % "spark-streaming_2.11" % sparkVersion,
"org.apache.spark" % "spark-streaming-twitter_2.11" % sparkVersion,
"org.apache.spark" %% "spark-streaming-kafka" % sparkVersion,
"org.apache.spark" % "spark-sql_2.11" % sparkVersion,
"com.datastax.cassandra" % "cassandra-driver-core" % "3.0.0-alpha2",
"com.datastax.spark" %% "spark-cassandra-connector" % "1.5.0-M1",
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
"org.mockito" % "mockito-all" % "1.9.5" % "test"
)
我写了以下主要内容:
val conf = new SparkConf(true) .setAppName("Test") .setMaster("spark://127.0.0.1:7077") .set("spark.cassandra.connection.host","127.0.0.1") .set("spark.cassandra.connection.port", "9042") .set("spark.driver.allowMultipleContexts", "true") /** Connect to the Spark cluster: */ lazy val sc = new SparkContext(conf) val rdd = sc.cassandraTable("spark", "try") val file_collect=rdd.collect() file_collect.map(println(_)) sc.stop()
然后我运行程序。
这是我用"spark.cassandra.connecter.host"=得到的堆栈跟踪spark://127.0.0.1:7077".
[error] o.a.s.u.SparkUncaughtExceptionHandler - Uncaught exception in thread Thread[appclient-registration-retry-thread,5,main]
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@b6391a7 rejected from java.util.concurrent.ThreadPoolExecutor@7f56044a[Running, pool size = 1, active threads = 0, queued tasks = 0, completed tasks = 3]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047) ~[na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823) [na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1369) [na:1.8.0_60]
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112) ~[na:1.8.0_60]
at org.apache.spark.deploy.client.AppClient$ClientEndpoint$$anonfun$tryRegisterAllMasters$1.apply(AppClient.scala:96) ~[spark-core_2.11-1.5.0.jar:1.5.0]
如果我把这个参数改为local[*],那么我会得到这个堆栈跟踪:
play.api.Application$$anon$1: Execution exception[[RuntimeException: java.lang.AbstractMethodError: com.datastax.spark.connector.cql.LocalNodeFirstLoadBalancingPolicy.close()V]]
at play.api.Application$class.handleError(Application.scala:296) ~[play_2.11-2.3.8.jar:2.3.8]
at play.api.DefaultApplication.handleError(Application.scala:402) [play_2.11-2.3.8.jar:2.3.8]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [play_2.11-2.3.8.jar:2.3.8]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [play_2.11-2.3.8.jar:2.3.8]
at scala.Option.map(Option.scala:146) [scala-library-2.11.7.jar:na]
Caused by: java.lang.RuntimeException: java.lang.AbstractMethodError: com.datastax.spark.connector.cql.LocalNodeFirstLoadBalancingPolicy.close()V
at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:523) ~[play_2.11-2.3.8.jar:2.3.8]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:130) ~[play_2.11-2.3.8.jar:2.3.8]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:130) ~[play_2.11-2.3.8.jar:2.3.8]
at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[play_2.11-2.3.8.jar:2.3.8]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:129) ~[play_2.11-2.3.8.jar:2.3.8]
Caused by: java.lang.AbstractMethodError: com.datastax.spark.connector.cql.LocalNodeFirstLoadBalancingPolicy.close()V
at com.datastax.driver.core.Cluster$Manager.close(Cluster.java:1423) ~[cassandra-driver-core-3.0.0-alpha2.jar:na]
at com.datastax.driver.core.Cluster$Manager.access$200(Cluster.java:1171) ~[cassandra-driver-core-3.0.0-alpha2.jar:na]
at com.datastax.driver.core.Cluster.closeAsync(Cluster.java:462) ~[cassandra-driver-core-3.0.0-alpha2.jar:na]
at com.datastax.driver.core.Cluster.close(Cluster.java:473) ~[cassandra-driver-core-3.0.0-alpha2.jar:na]
at com.datastax.spark.connector.cql.CassandraConnector$.com$datastax$spark$connector$cql$CassandraConnector$$createSession(CassandraConnector.scala:163) ~[spark-cassandra-connector_2.11-1.5.0-M1.jar:1.5.0-M1]
知道问题是从哪里来的吗?
Spark Cassandra连接器支持java驱动程序2.1版本。driver v.2.2支持:https://datastax-oss.atlassian.net/browse/SPARKC-229它将包含在spark-cassandra连接器1.5.0-M2中,也可以自己构建。我认为,它也将与3.0java驱动程序配合使用。另一方面,建议使用与C*相同的java驱动程序,因此Cassandra 2.1 使用java驱动程序2.1
export SPARK_MASTER_IP=master
所以我也有同样的问题。我把"master"改成了我的ip。所以我解决了这个问题。