/cassandra-bug

Demo of Cassandra 4.0 bug when using conditional updates

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

Cassandra ordering bug

This repository demonstrates what seems to be a bug with Cassandra 4.0 when mixing Paxos with regular queries.

Assume a table t having a partition column p, a clustering column c and a static column s. The following four queries are issued to it:

-- noinspection SqlResolveForFile, SqlNoDataSourceInspectionForFile
insert into t (p, s) values ('P', 'S1');
update t set s = 'S2' where p = 'P' if s = 'S1';
insert into t (p, s) values ('P', 'S3');
update t set s = 'S4' where p = 'P' if s = 'S3';

The expected result would be for all four queries to succeed (applied: true) and for the table to contain at the end a single row with values (P, 'S4', -) Instead, the first three queries report as applied and the last query reports as not applied. The table contains a single row with values (P, 'S2', -). This explains why the fourth query doesn't apply, since the conditional failed. It seems the queries are actually executed in Q1, Q3, Q2 order, which leads to this result.

This bug can be avoided by introducing a delay between queries (>20ms).

Using external clusters

The environment variable CASSANDRA_URL may be used to specify the database to connect to. If omitted, the test spins a Cassandra container to use as database.

The format of the variable CASSANDRA_URL is:

cassandra://[user:password@]host[:port]/datacenter/keyspace

The keyspace should be prepared in advance with the script from init.cql, replace ks for the desired keyspace name.