0

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 ?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Harry
  • 3,072
  • 6
  • 43
  • 100

1 Answers1

1

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.

Laxmikant
  • 1,551
  • 1
  • 13
  • 30
  • I understand the issue, but Is it not possible to set the consistency as '1' and replication factor as '3' and perform any LWT queries ? – Harry Oct 31 '18 at 08:15
  • No..but why u r setting RF 3 for one node? – Laxmikant Oct 31 '18 at 08:29
  • I have a scenario, where two nodes will be down for sometime, during that time I need the support for write and read using IF condition (like column = ''), so I use the downgrade retry policy which makes the write support with consistency as 1 – Harry Oct 31 '18 at 08:34
  • is it ok for you to perform simple INSERT in such case ? – Laxmikant Oct 31 '18 at 09:10
  • No, I need to perform IF statement, It is required in case of UPDATE – Harry Oct 31 '18 at 09:19
  • @Harry are you using cql or java? – Horia Oct 31 '18 at 12:24
  • I tried cqlsh, python and nodejs all tells the same for LWT :( @Horia – Harry Oct 31 '18 at 12:25
  • Maybe [ScalarDB](https://lists.apache.org/thread.html/39602a0b87ea0f507e66168072a7711c799d4db5522237cbb632d118@%3Cdev.cassandra.apache.org%3E) might solve your use case. I'm not sure if it will (since is LWT based), but maybe is worth having a look. Unfortunately, what you are describing is the normal behavior. On the 3rd step, the acceptance of the proposal is made with SERIAL/LOCAL_SERIAL CL. Only the 4th step, the mutation commit, is done at the CL ONE that you need. – Horia Oct 31 '18 at 12:34