我在我的机器(Windows 7)上使用 Cassandra 1.2.4。
我的 DC1 中有 3 个节点,它在我的机器上。我只使用一台 DC(我的机器)。我确实保留了复制因子 = 2 和“HConsistencyLevel.ONE”。但是,当其中一个节点关闭并且我尝试读取或写入 DB 时,我收到错误消息 - “可能没有足够的副本来处理一致性级别。”。我的印象是,当我们将一致性级别保持为“ONE”时,即使一个节点启动,写入/读取也应该不会出错。但我得到这个错误。有人可以纠正我在这里做错了什么。我确实在谷歌搜索过,但没有得到关于这个错误的太多帮助,尽管这个错误非常相关。我想在节点故障的情况下进行读/写。下面是我的代码。
String keySpaceName="kspace";
String clusterName="Test Cluster";
String columFamilyName="ktable";
String host="127.0.0.1:9160,127.0.0.2:9161,127.0.0.3:9162";
int replicationFactor=2;
CassandraHostConfigurator cassandraHostConfigurator = new
CassandraHostConfigurator(host);
Cluster cluster = HFactory.getOrCreateCluster(clusterName,cassandraHostConfigurator);
KeyspaceDefinition keyspaceDef = cluster.describeKeyspace(keySpaceName);
ConfigurableConsistencyLevel configurableConsistencyLevel = new
ConfigurableConsistencyLevel();
Map<String, HConsistencyLevel> clmap = new HashMap<String, HConsistencyLevel>();
// Define CL.ONE for ColumnFamily "ktable"
clmap.put(columFamilyName, HConsistencyLevel.ONE);
configurableConsistencyLevel.setReadCfConsistencyLevels(clmap);
configurableConsistencyLevel.setWriteCfConsistencyLevels(clmap);
if(keyspaceDef==null)
{
KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(
keySpaceName, ThriftKsDef.DEF_STRATEGY_CLASS,replicationFactor, null);
cluster.addKeyspace(newKeyspace, true);
}
Keyspace keyspace = HFactory.createKeyspace(keySpaceName, cluster,
configurableConsistencyLevel);
StringSerializer ss = StringSerializer.get();
ColumnFamilyTemplate<String, String> cft = new ThriftColumnFamilyTemplate<String,
String>(keyspace, columFamilyName, ss, ss);
ColumnFamilyUpdater<String, String> updater = cft.createUpdater("xkey");
UUID uid = new UUID();
updater.setValue("id",Long.toString(uid.getClockSeqAndNode()),ss);
updater.setValue("name", "Catherine", ss);
updater.setValue("state", "GA", ss);
cft.update(updater);