about "insert into table with IF NOT EXISTS" error

436 views
Skip to first unread message

Tom Zhou

unread,
Feb 9, 2015, 9:30:02 PM2/9/15
to nodejs-dr...@lists.datastax.com
Hi:

  I setup one node cassandra server, and using node.js driver cql to query db.

  But, when insert into table with "IF NOT EXISTS" statement, it report error as below:

:ResponseError: Cannot achieve consistency level QUORUM

And, I try set nodejs cql query with consistency to ONE, still see that error.

If I remove  "IF NOT EXISTS" from cql, insert passed. 

 Please advice. thx.

Best regards
  Tom

Jorge Bay Gondra

unread,
Feb 10, 2015, 3:35:05 AM2/10/15
to nodejs-dr...@lists.datastax.com
Hi Tom,
This could be caused by having a keyspace with a larger replication factor than amount of replicas, making paxos to fail.
You can try using cqlsh:

create keyspace ks1 WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};

use ks1;

create table tbl1 (id int primary key, val text);

--this will fail

insert into tbl1 (id, val) VALUES (1, 'aaa') IF NOT EXISTS;


But this wont fail as the replication factor is accurate:

create keyspace ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};

use ks2;

create table tbl2 (id int primary key, val text);

--this will NOT fail

insert into tbl2 (id, val) VALUES (1, 'aaa') IF NOT EXISTS;


Jorge

To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-u...@lists.datastax.com.

tom

unread,
Feb 10, 2015, 7:27:06 AM2/10/15
to nodejs-dr...@lists.datastax.com
Jorge:

after alter keyspace with  replicator: 1. the issue gone. thx a lot.

best regards
  Tom
Reply all
Reply to author
Forward
0 new messages