I am using Cassandra 1.2.4 on my machine (windows 7).
I have 3 nodes in my DC1, which is located on my machine. I use only one DC (my car). I saved replication rate = 2 and "HConsistencyLevel.ONE". However, when one of the nodes is disconnected and I try to read or write to the database, I get the error message βThere may not be enough replicas to process the level of consistencyβ. I get the impression that when we maintain the level of consistency as "ONE", and even if one node is working, writing / reading should happen without errors. But I get this error. Can someone fix me like what I did wrong here. I did a google search, but didn't really help with this error, although this error is very relevant. I want read / write to happen in case of node failure. Below is my code.
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);
Kiran source share