Skip to content

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

nodetool drain

Drains the node by flushing all memtables, stopping acceptance of writes, and preparing for shutdown.


Terminal window
nodetool [connection_options] drain

See connection options for connection options.

nodetool drain gracefully prepares a node for shutdown by:

  1. Flushing all memtables to SSTables
  2. Stopping native transport (CQL connections)
  3. Stopping gossip
  4. Stopping accepting writes
  5. Completing in-flight requests

This ensures no data loss when stopping Cassandra.


Always Drain Before Shutdown

Terminal window
nodetool drain
sudo systemctl stop cassandra

Without drain, Cassandra must replay commit logs on restart, which takes longer.

Terminal window
nodetool drain
sudo systemctl stop cassandra
# Perform upgrade
sudo systemctl start cassandra
Terminal window
nodetool drain
# Node is now safe to work on

If Cassandra needs to restart quickly and data persistence is not critical:

Terminal window
# Faster but commit log replay on startup
sudo systemctl stop cassandra

However, this is rarely recommended.

If decommissioning the node:

Terminal window
# Use decommission instead
nodetool decommission

StepActionDescription
1Stop accepting new connectionsNo new client connections accepted
2Complete in-flight requestsAllow current requests to finish
3Flush all memtables to diskEnsures all data in memory is written to SSTables
4Stop gossipNode stops communicating with cluster
5Stop native transportCQL connections closed
6Enter DRAINED stateNode is safe to stop

After Drain

Node is now safe to stop. The Cassandra process is still running but not accepting work.


Terminal window
nodetool info
# Shows: Mode: DRAINED
FeatureState
CQL connectionsRefused
GossipStopped
WritesRejected
ReadsMay still work briefly
JMXStill available
Terminal window
# After drain completes
sudo systemctl stop cassandra
# Or
pkill -f CassandraDaemon

Terminal window
nodetool drain
sudo systemctl stop cassandra
#!/bin/bash
echo "Draining node..."
nodetool drain
echo "Waiting for drain to complete..."
while nodetool info 2>/dev/null | grep -q "Mode: NORMAL"; do
sleep 1
done
echo "Stopping Cassandra..."
sudo systemctl stop cassandra
echo "Done"
Terminal window
ssh 192.168.1.101 "nodetool drain"
ssh 192.168.1.101 'sudo systemctl stop cassandra'

Terminal window
# Watch memtable flush
nodetool tpstats | grep -i flush
# Check mode
nodetool info | grep Mode

When drain completes:

Mode: DRAINED
Terminal window
tail -f /var/log/cassandra/system.log | grep -i drain

If drain takes too long:

  1. Check for large memtables
  2. Check disk I/O performance
  3. Check for pending tasks
Terminal window
nodetool tpstats
nodetool compactionstats

Node was already drained:

Terminal window
# Just stop the process
sudo systemctl stop cassandra

Some connections may linger briefly. Drain stops new connections but allows in-flight requests to complete.

If drain doesn't complete:

Terminal window
# Check what's blocking
nodetool tpstats
nodetool info
# Last resort: force stop
sudo systemctl stop cassandra

Force Stop Risk

Force stopping without drain completing requires commit log replay on restart.


CommandPurposeContinues Running
drainPrepare for shutdownYes (drained state)
stopdaemonStop Cassandra immediatelyNo
disablebinaryStop CQL onlyYes (operational)
disablegossipStop gossip onlyYes (isolated)
ScenarioCommand
Graceful shutdowndrain then stop
Emergency stopstopdaemon (last resort)
Maintenance (keep running)disablebinary
Network troubleshootingdisablegossip

To return a drained node to service:

Terminal window
# Must restart Cassandra
sudo systemctl restart cassandra

There is no "undrain" command. The node must be restarted.


Drain Guidelines

  1. Always drain before shutdown - Prevents data loss
  2. Wait for completion - Check mode is DRAINED
  3. Include in scripts - Automate shutdown procedures
  4. Monitor during drain - Catch any issues
  5. Plan for duration - Large memtables take time to flush
  • Check node status: nodetool status
  • Drain the node: nodetool drain
  • Verify drained: nodetool info | grep Mode
  • Stop service: sudo systemctl stop cassandra
  • Verify stopped: pgrep -f CassandraDaemon

CommandRelationship
flushFlushes memtables only
disablebinaryDisables CQL only
disablegossipDisables gossip only
infoCheck drain state