Hello Everyone

I am new in databases and i am trying to understand some Cassandra commands. I would like to know about the following commands :

  • nodetool compact
  • nodetool cleanup
  • nodetool repair
  • nodetool garbagecollect

I would appreciate some simple and clear answers like -> nodetool help : it shows all the commands and their usage.

The problem i am trying to solve is that after i delete (a lot of data) the storage is still full. I change the gc_grace_seconds to 1 day and still nothing. So if i need to clear the space manualy right now which commands should i run and in what order?

Thanks for your time

1 Answer 1


Here is my attempt at explaining what each command does.

nodetool compact

A manual way to instruct Cassandra to consolidate/rewrite SSTables while also evicting expired (tombstoned) data. Tombstones are considered expired when they are past the GC grace configured on a table.

Note that running this command is NOT recommended. I've explained why in this post -- Why is forcing major compaction on a table not ideal?.

nodetool cleanup

Removes partitions (records) whose keys are no longer owned by a node because the token range(s) it owns has changed after another node has been added to the cluster.

For example, let's say node A owns token range 0-100. Node B was added to the cluster with ownership of token range 80-200. As a result of this, node A no longer owns the data in the token range 80-100 (now only owns data in the token range 0-79). You would run cleanup on this node to get rid of the data in the 80-100 range to reclaim the disk space.

nodetool repair

Cassandra has a distributed architecture where nothing is shared, not even the storage layer. Each node in the cluster is a separate instance on its own.

Due to this distributed nature, copies of the data on the nodes (replicas) can get out of sync. Repairs are the mechanism by which Cassandra fixes (repairs) the inconsistencies. The functionality is analogous to the way rsync works for filesystems.

nodetool garbagecollect

This command triggers compaction on an SSTable to remove "droppable" deleted (cell/row/partition) data.

This command is very new so there are some scenarios where it does not evict deleted data. The concept of "droppable" is quite complex particularly since parts of a partition (i.e. columns, rows) can be fragmented across multiple SSTables so working out whether deleted data can be dropped is not an easy task.

Now to your issue, you need to be aware that setting gc_grace_seconds too low is dangerous because if you run into a situation where one of the nodes encounter a hardware failure (for example), you need to be able to replace that node within GC grace. Otherwise, you cannot put that node back into the cluster because the tombstones would have expired. If you try to put a failed node back, the other nodes no longer have the tombstones (they've been GCd) so the deleted data on the failed node will get resurrected back to your cluster.

In the first instance, you can try to run nodetool garbagecollect on the problematic table to try to reclaim the space. If that does not work (for the reasons I described above), then you can try nodetool compact BUT be aware of the consequences I've explained in my post above. Cheers!

  • Wow! Thanks a lot Erick. This is the answer i was looking for! Aug 25, 2022 at 14:55
  • That's awesome! Happy to help. Cheers! Aug 25, 2022 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.