Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

nodetool flush

Flushes memtables from memory to SSTables on disk for one or more tables.


Terminal window
nodetool [connection_options] flush [--] [keyspace [table ...]]

See connection options for connection options.

nodetool flush forces an immediate flush of memtable data to disk as SSTables. Memtables hold recent writes in memory; flushing writes this data to immutable SSTable files.


ArgumentDescription
keyspaceKeyspace to flush. If omitted, flushes all keyspaces
tableSpecific table(s) to flush. If omitted, flushes all tables in keyspace

Terminal window
nodetool flush

Flushes all memtables for all keyspaces on the node.

Terminal window
nodetool flush my_keyspace

Flushes all tables in my_keyspace.

Terminal window
nodetool flush my_keyspace my_table

Flushes only my_table in my_keyspace.

Terminal window
nodetool flush my_keyspace table1 table2 table3

Flushes multiple specific tables.


Required Before Backups

Always flush before creating snapshots to ensure all data is on disk:

Terminal window
nodetool flush my_keyspace
nodetool snapshot -t backup_$(date +%Y%m%d) my_keyspace

Without flushing, recent writes in memtables will not be included in the snapshot.

Terminal window
nodetool flush
nodetool drain
sudo systemctl stop cassandra

Drain Includes Flush

nodetool drain automatically flushes all memtables. Explicit flush before drain is optional but makes the drain faster.

Terminal window
nodetool flush my_keyspace
nodetool compact my_keyspace

Ensures all data is in SSTables before compaction.

Terminal window
nodetool flush
nodetool upgradesstables

Ensures no data remains in memtables before SSTable upgrade.


Unnecessary Flushing

Avoid excessive flushing:

  • Frequent flushes: Creates many small SSTables, increasing compaction overhead
  • During normal operations: Let Cassandra manage memtable flushes automatically
  • Under heavy write load: Adds disk I/O pressure

Cassandra automatically flushes memtables when:

ConditionConfiguration
Memtable size thresholdmemtable_heap_space
Commit log segment fullcommitlog_segment_size
Time-basedmemtable_flush_period_in_ms (if configured)
Memory pressureWhen approaching heap limits

ResourceImpact
Disk I/OWrite burst during flush
MemoryTemporary increase while flushing
CPUCompression during SSTable write
  • Write operations continue to new memtable
  • Read operations may read from both memtable and SSTables
  • Flush is generally quick for reasonably-sized memtables

Each flush creates new SSTable files:

/var/lib/cassandra/data/my_keyspace/my_table-<uuid>/
├── nb-1-big-Data.db
├── nb-1-big-Index.db
├── nb-1-big-Filter.db
└── ...

Compaction Follows

New SSTables from flushes eventually get compacted according to the table's compaction strategy.


Terminal window
nodetool tpstats | grep -i flush

Shows flush-related thread pool activity.

Terminal window
nodetool tablestats my_keyspace.my_table | grep -i memtable

Shows current memtable size and flush statistics.


OperationScopeAdditional Actions
flushMemtables onlyNone
drainMemtables + connectionsDisables gossip and native transport, stops accepting writes

Use drain for graceful shutdown; use flush for data persistence while keeping node operational.


Large memtables increase flush time:

CauseSolution
Large memtable sizeReduce memtable_heap_space
Slow disk I/OImprove storage performance
Heavy write loadConsider flush during lower traffic

Disk Space Required

Ensure sufficient disk space before flushing:

  • Flush creates new SSTable files
  • Space needed: approximately memtable size × compression ratio
  • Monitor disk usage: df -h /var/lib/cassandra

Frequent flushes create fragmented SSTables:

Terminal window
# Check SSTable count
nodetool tablestats my_keyspace.my_table | grep "SSTable count"

Let compaction consolidate files, or investigate why flushes are frequent.


Flush Guidelines

  1. Before backups: Always flush before snapshots
  2. Before shutdown: Use drain which includes flush
  3. One node at a time: For cluster-wide operations
  4. Monitor disk space: Ensure capacity for new SSTables
  5. Avoid in scripts loops: Don't repeatedly flush same tables

CommandRelationship
drainFlush + disable node
snapshotCreate backup after flush
compactConsolidate SSTables
tablestatsCheck memtable and SSTable stats
tpstatsMonitor flush thread pool