LWT and Consisteny in Cassandra

268 Views Asked by At

It seems to be the bug for me,

1) I created a keyspace with replication factor as '3'

 CREATE KEYSPACE IF NOT EXISTS replicationtest WITH replication = {'class':'SimpleStrategy','replication_factor' : 3};

NOTE: This is a single node cluster, still I kept the replication factor as 3, so that I will add new nodes to the cluster later

2) I set the consistency level as ONE

 cqlsh:replicationtest> CONSISTENCY ONE

3) I created a 'testtable'

CREATE TABLE IF NOT EXISTS testtable("partitionId" text, "name" text, "value" text, primary key ("partitionId","name"));

4) Now I tried simple INSERT query

INSERT INTO testtable("partitionId", "name", "value") VALUES ('testtable','testname', 'testvalue');

THIS IS WORKING AS EXPECTED Since the consistency LEVEL is ONE

5) Now I tried INSERT query with LWT (IF NOT EXISTS)

INSERT INTO testtable("partitionId", "name", "value") VALUES ('testtable','testnameanew', 'testvaluenew') IF NOT EXISTS; 

NOW IT FAILED WITH NoHostAvailable: ERROR

Could someone explain how to fix this ? How to execute this LWT with consistency as 1 ?

1

There are 1 best solutions below

8
On

Lwt uses serial consistently level under the hood and as the RF is 3 , it expect s 2 node to be up. Hence the operation is failing as expected. Read this for more information.