Cassandra inconsistencies in batch inserts/updates

1.3k views Asked by At

I am getting the following error message:
Cassandra timeout during write query at consistency ONE (0 replica(s) acknowledged the write over 1 required)

I am using Cassandra with an replication factor of 3. Everything is working like as it should. But lately, I found an error. Maybe it occurs in Cassandra or in the datastax c# cassandra driver I am using.

To be 100% sure, I set in my tests all ConsistencyLevel-possiblities to ConsistencyLevel.Quorum. But I also tried ConsistencyLevel.Two.

The Problem occurred with both settings.

My problem is not the timeout, this is something I can solve. I am concerned about the fact that I get an error message saying that 1 acknowledge (consistency ONE) is required. Although I set everything to ConsistencyLevel.Quorum or ConsistencyLevel.Two.

Without the WriteTimeoutException I never would have noticed, that maybe there is an consistency problem.

I also used tracing and got the following (deeper) error:

Cassandra.Session: RequestHandler received exception Cassandra.WriteTimeoutException: Cassandra timeout during write query at consistency ONE (0 replica(s) acknowledged the write over 1 required)

Here is some test code:

var cluster =  Cluster.Builder().AddContactPoints("192.168.0.1", "192.168.0.2", "192.168.0.3", "192.168.0.4", "192.168.0.5")
.WithQueryOptions(new QueryOptions().SetConsistencyLevel(ConsistencyLevel.Quorum))
.WithCompression(CompressionType.LZ4).Build();
var session = cluster.Connect();
insertStatementTableX = session.Prepare(
   "INSERT INTO keyspace.x (a, b, c) VALUES (?, ?, ?);").SetConsistencyLevel(ConsistencyLevel.Quorum);
insertStatementTableY = session.Prepare(
   "INSERT INTO keyspace.y (a, b, c) VALUES (?, ?, ?);").SetConsistencyLevel(ConsistencyLevel.Quorum);
var batch = new BatchStatement();
batch.SetConsistencyLevel(ConsistencyLevel.Quorum);   
batch.Add(insertStatementTableX.Bind(1, 2, 3)).SetConsistencyLevel(ConsistencyLevel.Quorum);
batch.Add(insertStatementTableY.Bind(2, 3, 4)).SetConsistencyLevel(ConsistencyLevel.Quorum);
session.Execute(batch);

Can I assume, that all other inserts/updates now are also done with consistency level ONE although I set it to quorum? Or is just the error message wrong?

1

There are 1 answers

1
jorgebg On

In Cassandra, for write operations, a timeout is not a failure.

It means that time passed for the coordinator waiting for the actual replica to respond that the write succeeded.

It is not yet available for read but it was written to the batch log and you should not make the client retry. If you are looking for low latency and a guarantee that a write never fails (highest availability), you can change the write consistency to ANY.