Storage Engine

Commitlogs are an append only log of all mutations local to a Cassandra node. Any data written to Cassandra will first be written to a commit log before being written to a memtable. This provides durability in the case of unexpected shutdown. On startup, any mutations in the commit log will be applied to memtables.

All mutations write optimized by storing in commitlog segments, reducing the number of seeks needed to write to disk. Commitlog Segments are limited by the commitlog_segment_size option, once the size is reached, a new commitlog segment is created. Commitlog segments can be archived, deleted, or recycled once all its data has been flushed to SSTables. Commitlog segments are truncated when Cassandra has written data older than a certain point to the SSTables. Running "nodetool drain" before stopping Cassandra will write everything in the memtables to SSTables and remove the need to sync with the commitlogs on startup.

NOTE: If max_mutation_size is set explicitly then commitlog_segment_size must be set to at least twice the size of max_mutation_size .

Commitlogs are an append only log of all mutations local to a Cassandra node. Any data written to Cassandra will first be written to a commit log before being written to a memtable. This provides durability in the case of unexpected shutdown. On startup, any mutations in the commit log will be applied.

Default Value: batch

Default Value: /var/lib/cassandra/commitlog

(Default Value: (complex option):

# - class_name: LZ4Compressor # parameters:

If space gets above this value, Cassandra will flush every dirty CF in the oldest segment and remove it. So a small total commitlog space will tend to cause more flush activity on less-active columnfamilies.

The default value is the smaller of 8192, and 1/4 of the total space of the commitlog volume.

Default Value: 8192MiB

Memtables

Memtables are in-memory structures where Cassandra buffers writes. In general, there is one active memtable per table. Eventually, memtables are flushed onto disk and become immutable SSTables. This can be triggered in several ways:

Memtables may be stored entirely on-heap or partially off-heap, depending on memtable_allocation_type .

SSTables

SSTables are the immutable data files that Cassandra uses for persisting data on disk.

As SSTables are flushed to disk from memtables or are streamed from other nodes, Cassandra triggers compactions which combine multiple SSTables into one. Once the new SSTable has been written, the old SSTables can be removed.

Each SSTable is comprised of multiple components stored in separate files:

The actual data, i.e. the contents of rows.

An index from partition keys to positions in the Data.db file. For wide partitions, this may also include an index to rows within a partition.

A sampling of (by default) every 128th entry in the Index.db file.

A Bloom Filter of the partition keys in the SSTable.

Metadata about the offsets and lengths of compression chunks in the Data.db file.

Stores metadata about the SSTable, including information about timestamps, tombstones, clustering keys, compaction, repair, compression, TTLs, and more.

A CRC-32 digest of the Data.db file.

A plain text list of the component files for the SSTable.

Within the Data.db file, rows are organized by partition. These partitions are sorted in token order (i.e. by a hash of the partition key when the default partitioner, Murmur3Partition , is used). Within a partition, rows are stored in the order of their clustering keys.

SSTables can be optionally compressed using block-based compression.

SSTable Versions

This section was created using the following gist which utilized this original source.

The version numbers, to date are:

Version 0

Version 1

Version 2

Version 3

Example Code

The following example is useful for finding all sstables that do not match the "ib" SSTable version

include:example$find_sstables.sh[]