I am using Cassandra 1.2.4 on my machine (windows 7).
I have got 3 nodes in my DC1, which is on my machine. I am only using one DC (my machine). I did keep replication factor=2 and "HConsistencyLevel.ONE". However, when one of the nodes is down, and I attempt to read or write to DB, I get the error - "May not be enough replicas present to handle consistency level.". I am under the impression that when we keep the consistency level as "ONE" and even if one node is up, the write/read should happen without errors. But I get this error. Could someone correct me as what I was doing wrong here. I did search in google but didn't get much help about this error although this error is quite relevant. I want to make the read/write happen in the event 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);