我使用以下命令在Cassandra中创建了表:
CREATE KEYSPACE test WITH REPLICATION = { 'class' :
'NetworkTopologyStrategy', 'dc1' : 3 } AND DURABLE_WRITES = false;
use test;
create table demo(id int primary key, name text);
成功创建表后,我运行以下代码将数据写入Spark的Cassandra . 但面临以下错误
Spark的代码片段
import com.datastax.spark.connector._
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
import com.datastax.spark.connector.cql._
val connectorToClusterOne = CassandraConnector(sc.getConf.set("spark.cassandra.connection.host","xx.xx.xx.xx").set("spark.cassandra.auth.username", "xxxxxxx").set("spark.cassandra.auth.password", "xxxxxxx"))
---K/V---
val data = sc.textFile("/home/ubuntu/test.txt").map(_.split(",")).map(p => demo(p(0).toInt,p(1)))
implicit val c = connectorToClusterOne
data.saveToCassandra("test","demo")
BELOW IS THE ERROR DESCRIPTION: .
使用数据中心dc1计算密钥空间测试的令牌映射时出错:无法实现复制因子3(仅找到0个副本),请检查密钥空间复制设置 .
Could any one suggest what could be the possible reason for this.
1 回答
此错误通常是因为请求未定向到正确的群集,或者数据中心不存在或名称不正确 .
要确保连接到正确的群集,请仔细检查用于spark应用程序的连接主机 .
要检查数据中心,请使用
nodetool status
确保您请求的数据中心存在且不包含任何无关的空格 .最后,数据中心中的所有节点都可能已关闭,因此请仔细检查 .