我一直在尝试将cassandra与Spark连接在一起,但我一直面临着一些问题。 以下是使用的版本:
Spark 1.5.0
Cassandra 2.1.9
Scala 2.11.1
以下是我遵循的步骤: - 使用默认配置下载了Cassandra,我通过bin / cassandra -f启动它。 Cassandra开始很好,并在127.0.0.1上收听 - 我在spark键空间的try表中添加了一些模拟数据。 - 下载Spark并通过sbin / start-master.sh启动master。我可以在localhost:8888上看到主人运行良好 - 我写了以下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.connector.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]
知道问题的来源吗?
答案 0 :(得分:0)
export SPARK_MASTER_IP=master
所以我遇到了同样的问题。我将“master”改为我的ip。所以我解决了这个问题。
答案 1 :(得分:0)
Spark Cassandra连接器支持java-driver 2.1版。 驱动程序v.2.2支持:https://datastax-oss.atlassian.net/browse/SPARKC-229 它将包含在spark-cassandra-connector 1.5.0-M2中,或者您可以自己构建它。 我想,它也适用于3.0 java驱动程序。 另一方面,建议使用与C *相同的java驱动程序,SO使用java驱动程序2.1 for Cassandra 2.1