HUnavailableException: there may not be enough replicas to handle consistency

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); 
+4
source share
2 answers

Change the replication rate to 1, i.e. by the number of nodes you installed. I got the same error as the examples.

+1
source

Try changing the replication coefficient to zero the nodes available in the cluster ... it survives from such failures .... in my example with RF = 5, 5 node the cluster can survive 2 node failure, with RF = 4, 5 node the cluster can survive 1 node failure, with RF = 3, 5 node cluster can withstand only 1 node failure ....

I'm not sure if this approach is effective or not, but it should always work (i.e. RF = no nodes), any suggestions from experts will be very grateful ...

0
source

Source: https://habr.com/ru/post/1478874/


All Articles