Cassandra Notes

1 minute read

When to use Cassandra

Upgrade to cassandra 4.x driver and spring-data-cassandra 2.3.+

CQL Tips

Using timestamp columns in cql where clause

Although Cassandra stores timestamp fractions using the .ffffff format defined by the ISO 8601 standard. However, when interacting with the database (ie. INSERT, SELECT, …) you need to use the .fff format like so:

cqlsh:test_keyspace> select * from timestamp_table ;

timestamp                       | other_field
---------------------------------+---------------
2018-05-18 03:08:58.246000+0000 | Other content
2018-05-18 03:08:58.000000+0000 | Other content

cqlsh:test_keyspace> select * from timestamp_table WHERE timestamp='2018-05-18 03:08:58.123+0000';

timestamp                       | other_field
---------------------------------+---------------
2018-05-18 03:08:58.123000+0000 | Other content

Data modeling

Limitations of Materialized View

Performances

How to partition the data

Pagination

Tombstones

  • Partition tombstones
  • Row tombstones
  • Range tombstones
  • ComplexColumn tombstones
  • Cell tombstones
  • TTL tombstones

Reference: What are tombstones

Another very nice article describes issues around tombstones: https://thelastpickle.com/blog/2018/07/05/undetectable-tombstones-in-apache-cassandra.html

Allow filtering

In Query

Not using in query across multiple partitions, as explained in this article

Batch

batch_size_warn_threshold_in_kb

If you use batch with cassandra and saw warning in logs like this:

BatchStatement.java:287 - Batch of prepared statements for [test, test1] is of size 6419, exceeding specified threshold of 5120 by 1299.

Normally this is not really harmful as it’s just a warning. But you need to be careful about the usage of the batch and should avoid sending large paylaod to batch statement, especially when the statements are not against the same partition.

Lightweight Transaction (LWT)

Updated:

Comments