Was this page helpful?
Caution
You're viewing documentation for an unstable version of ScyllaDB Enterprise. Switch to the latest stable version.
Consistency Level Console Demo¶
In this demo, we’ll bring up 3 nodes and demonstrate how writes and reads look, with tracing enabled in a cluster where our Replication Factor (RF) is set to 3. We’ll change the Consistency Level (CL) between operations to show how messages are passed between nodes, and finally take down a few nodes to show failure conditions in a ScyllaDB cluster.
You can also learn more in the High Availability lesson on ScyllaDB University.
Note: We use asciinema to generate the console casts used in this demo. These asciicasts are more readable than embedded video, and allow you to copy the text or commands directly from the console to your clipboard. We suggest viewing console casts in fullscreen to see the properly formatted output.
Step one: bring up the cluster¶
First, we’ll bring up a 3-node docker cluster. You’ll see all the nodes eventually read UN
for status. U
means up, and N
means normal. Read more about Nodetool Status.
Once all nodes are up, we can run our CQL shell.
We’ve run nodetool status
after we’ve waited for all nodes to come up:
Step two: take a single node down, check different consistency levels¶
So, what happens when we take a single node down? Here, we’ll take a single node down, check status with nodetool
, attempt a write with ALL and QUORUM consistency levels.
Note that we’ve turned tracing off. We can observe that our CL=ALL writes will always fail because one of the nodes is down. CL=QUORUM operations could fail, depending on whether a required partition replica falls on a node that is up or down.
Step three: take 2 nodes down, read and write with different consistency levels¶
Let’s take a second node down and attempt to read and write with QUORUM and ONE consistency levels.
With 2 nodes down on our 3 node cluster and RF=3, a CL=QUORUM will always fail as at least one of the required nodes will always be down. One the other hand, a CL=ONE will succeed, as it only requires one up node.
Step four: testing different consistency levels with tracing on¶
Finally, we’ll turn on tracing, and with all our nodes up, write to the table with CL=ALL and read from it with CL=QUORUM.
We’ve just written a record with our consistency level set to ALL.
cqlsh:mykeyspace> CONSISTENCY ALL
Consistency level set to ALL.
cqlsh:mykeyspace> CREATE TABLE users(user_id int PRIMARY KEY, fname text, lname text);
cqlsh:mykeyspace> TRACING ON
Now Tracing is enabled
cqlsh:mykeyspace> insert into users(user_id, lname, fname) values (1, 'tzach', 'livyatan');
Here’s the output:
With tracing on, we have verbose output. Also, with all nodes up, we should have no errors experiencing a CL=ALL write. (Later, we will try different consistency levels with 1 and 2 nodes down.) With RF=3, we see all three nodes involved in the interaction. Once the co-ordinator (172.17.0.4
) has received responses from the two other replicas - 172.17.0.2
and 172.17.0.3
- as well as itself- the operation is complete.
So what happens when we write under QUORUM instead of ALL? QUORUM means that we only require responses from (Replication Factor/2) + 1 nodes. Our replication factor is 3, therefore only a majority of 2 nodes must provide an acknowledgement for the eventually-consistent write to be considered successful. Below, we observe that our coordinator, after sending two other mutations to replicas 172.17.0.2
and 172.17.0.3
, executes a mutation locally. However, our coordinator only requires a write acknowledgement from itself and 172.17.0.3
before Mutation successfully completed
is returned. Note that the response from 172.17.0.2
actually comes later.
cqlsh:mykeyspace> CONSISTENCY QUORUM
Consistency level set to QUORUM.
cqlsh:mykeyspace> insert into users (user_id, fname, lname) values (2, 'john', 'hammink');
Output:
We can observe that reading under QUORUM consistency works similarly. In our example below, our coordinator 172.17.0.4
waits for only read_data
from 172.17.0.2
(as well as itself earlier: read_data: querying locally
) before the read is considered successful. Note that node 172.17.0.3
similarly handles read_digest
as 172.17.0.2
handles read_data
.
cqlsh:mykeyspace> CONSISTENCY QUORUM
Consistency level set to QUORUM.
cqlsh:mykeyspace> select * from users where user_id = 1;
Output: