我正在运行spark-cassandra-connector并遇到一个奇怪的问题: 我将spark-shell运行为:
bin/spark-shell --packages datastax:spark-cassandra-connector:2.0.0-M2-s_2.1
然后我运行以下命令:
import com.datastax.spark.connector._
val rdd = sc.cassandraTable("test_spark", "test")
println(rdd.first)
# CassandraRow{id: 2, name: john, age: 29}
问题是以下命令出错:
rdd.take(1).foreach(println)
# CassandraRow{id: 2, name: john, age: 29}
rdd.take(2).foreach(println)
# Caused by: com.datastax.driver.core.exceptions.UnavailableException: Not enough replicas available for query at consistency LOCAL_ONE (1 required but only 0 alive)
# at com.datastax.driver.core.exceptions.UnavailableException.copy(UnavailableException.java:128)
# at com.datastax.driver.core.Responses$Error.asException(Responses.java:114)
# at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:467)
# at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1012)
# at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:935)
# at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
以下命令只是挂起:
println(rdd.count)
我的Cassandra键空间似乎有正确的复制因子:
describe test_spark;
CREATE KEYSPACE test_spark WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'} AND durable_writes = true;
如何解决上述两个错误?
答案 0 :(得分:1)
我认为在使用LOCAL_ONE
(火花连接器默认值)一致性时,您遇到了SimpleStrategy和multi-dc的问题。它会在本地DC中寻找一个节点来发出请求,但是所有副本都存在于不同的DC并且不符合要求的可能性。 (CASSANDRA-12053)
如果您change your consistency level(input.consistency.level
到ONE
)我认为它会得到解决。您还应该考虑使用网络拓扑策略。