question

ashok.dcosta_187920 avatar image
ashok.dcosta_187920 asked Erick Ramirez edited

Does the coordinator enforce consistency level for writes?

Does the coordinator enforces consistency levels? For example consistency level is "Two" will it wait for the write operation to complete on 2 nodes ? If yes what happens if only one node responds will it return an error ?

driverconsistency level
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Erick Ramirez avatar image
Erick Ramirez answered

The consistency level for write requests determines the number of replicas which must respond to the coordinator with an acknowledgment that the mutation was written to (a) the commitlog and (b) the memtable so "enforce" is not quite the right word for it.

The driver will report an exception depending on the error that occurred. Using the Java driver for illustration purposes, the following exceptions are reported by the driver in the application logs:

Unavailable

In this situation the request reached the coordinator but not enough replicas were available to satisfy the the consistency level requested.

An example error message looks like this:

UnavailableException: Not enough replicas available for query at consistency TWO (2 required but only 0 alive)

Timeout error

In this situation the request reached the coordinator but one or more replicas were too slow to respond within write_request_timeout_in_ms.

An example error message looks like this:

WriteTimeoutException: Cassandra timeout during SIMPLE write query at consistency LOCAL_QUORUM (2 replica were required but only 1 acknowledged the write)"

Failure error

This is a non-timeout error and occurs when some replicas replied with an error. The kind of errors that could trigger this could be one of the replicas had a running out of disk space or a replica experiencing a hardware failure.

An example error message looks like this:

WriteFailureException: Cassandra failure during write query at consistency QUORUM (4 responses were required but only 3 replica responded, 1 failed)

For more info, see How write requests are accomplished in Cassandra. There's explanation of the server-side exceptions which result in driver errors in the Java driver Retries page. For other drivers, see the respective driver's documentation in the DataStax drivers matrix page. Cheers!

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

smadhavan avatar image
smadhavan answered Erick Ramirez commented

@ashok.dcosta_187920, the coordinator sends a write request to all replicas that own the row being written. As long as all replica nodes are up and available, they will get the write regardless of the consistency level specified by the client. The write consistency level determines how many replica nodes must respond with a success acknowledgment in order for the write to be considered successful.

For further reading, please refer to this documentation. Hope that helps!

2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

ashok.dcosta_187920 avatar image ashok.dcosta_187920 commented ·

Will there be a case that an error is returned it is not able to write to all the replicas or if the consistency level is not met? I am trying to understand if it is not able to process the transaction for a reason what will it return ?

0 Likes 0 ·
Erick Ramirez avatar image Erick Ramirez ♦♦ ashok.dcosta_187920 commented ·

A friendly note to let you know that I've converted your post to a comment since it's not an "answer". Cheers!

0 Likes 0 ·