nodetool flush
Flushes memtables from memory to SSTables on disk for one or more tables.
Synopsis
Section titled “Synopsis”nodetool [connection_options] flush [--] [keyspace [table ...]]See connection options for connection options.
Description
Section titled “Description”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.
Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
keyspace | Keyspace to flush. If omitted, flushes all keyspaces |
table | Specific table(s) to flush. If omitted, flushes all tables in keyspace |
Examples
Section titled “Examples”Flush All Keyspaces
Section titled “Flush All Keyspaces”nodetool flushFlushes all memtables for all keyspaces on the node.
Flush Specific Keyspace
Section titled “Flush Specific Keyspace”nodetool flush my_keyspaceFlushes all tables in my_keyspace.
Flush Specific Table
Section titled “Flush Specific Table”nodetool flush my_keyspace my_tableFlushes only my_table in my_keyspace.
Flush Multiple Tables
Section titled “Flush Multiple Tables”nodetool flush my_keyspace table1 table2 table3Flushes multiple specific tables.
When to Use
Section titled “When to Use”Before Taking Snapshots
Section titled “Before Taking Snapshots”Required Before Backups
Always flush before creating snapshots to ensure all data is on disk:
nodetool flush my_keyspacenodetool snapshot -t backup_$(date +%Y%m%d) my_keyspaceWithout flushing, recent writes in memtables will not be included in the snapshot.
Before Stopping Cassandra
Section titled “Before Stopping Cassandra”nodetool flushnodetool drainsudo systemctl stop cassandraDrain Includes Flush
nodetool drain automatically flushes all memtables. Explicit flush before drain is optional but makes the drain faster.
Before Major Compaction
Section titled “Before Major Compaction”nodetool flush my_keyspacenodetool compact my_keyspaceEnsures all data is in SSTables before compaction.
Before Upgrading SSTables
Section titled “Before Upgrading SSTables”nodetool flushnodetool upgradesstablesEnsures no data remains in memtables before SSTable upgrade.
When NOT to Use
Section titled “When NOT to Use”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's Automatic Flushing
Section titled “Cassandra's Automatic Flushing”Cassandra automatically flushes memtables when:
| Condition | Configuration |
|---|---|
| Memtable size threshold | memtable_heap_space |
| Commit log segment full | commitlog_segment_size |
| Time-based | memtable_flush_period_in_ms (if configured) |
| Memory pressure | When approaching heap limits |
Impact on Operations
Section titled “Impact on Operations”Resource Usage
Section titled “Resource Usage”| Resource | Impact |
|---|---|
| Disk I/O | Write burst during flush |
| Memory | Temporary increase while flushing |
| CPU | Compression during SSTable write |
During Flush
Section titled “During Flush”- Write operations continue to new memtable
- Read operations may read from both memtable and SSTables
- Flush is generally quick for reasonably-sized memtables
SSTable Creation
Section titled “SSTable Creation”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.
Monitoring Flush Operations
Section titled “Monitoring Flush Operations”Check Pending Flushes
Section titled “Check Pending Flushes”nodetool tpstats | grep -i flushShows flush-related thread pool activity.
Check Memtable Status
Section titled “Check Memtable Status”nodetool tablestats my_keyspace.my_table | grep -i memtableShows current memtable size and flush statistics.
Flush vs. Drain
Section titled “Flush vs. Drain”| Operation | Scope | Additional Actions |
|---|---|---|
flush | Memtables only | None |
drain | Memtables + connections | Disables gossip and native transport, stops accepting writes |
Use drain for graceful shutdown; use flush for data persistence while keeping node operational.
Common Issues
Section titled “Common Issues”Flush Takes Too Long
Section titled “Flush Takes Too Long”Large memtables increase flush time:
| Cause | Solution |
|---|---|
| Large memtable size | Reduce memtable_heap_space |
| Slow disk I/O | Improve storage performance |
| Heavy write load | Consider flush during lower traffic |
Out of Disk Space During Flush
Section titled “Out of Disk Space During Flush”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
Many Small SSTables After Flush
Section titled “Many Small SSTables After Flush”Frequent flushes create fragmented SSTables:
# Check SSTable countnodetool tablestats my_keyspace.my_table | grep "SSTable count"Let compaction consolidate files, or investigate why flushes are frequent.
Best Practices
Section titled “Best Practices”Flush Guidelines
- Before backups: Always flush before snapshots
- Before shutdown: Use
drainwhich includes flush - One node at a time: For cluster-wide operations
- Monitor disk space: Ensure capacity for new SSTables
- Avoid in scripts loops: Don't repeatedly flush same tables
Related Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| drain | Flush + disable node |
| snapshot | Create backup after flush |
| compact | Consolidate SSTables |
| tablestats | Check memtable and SSTable stats |
| tpstats | Monitor flush thread pool |