4

I have a Cassandra Cluster (2 DC) with 6 nodes each and RF 2. 4 of the nodes (in each DC) getting full so I need to cleanup space very soon.

I tried to run a full repair but ended up as a bad idea since the space start increased even more and the repair eventually hanged. As a last solution I am thinking to start repairing and then cleanup specific columns starting from the smallest to the biggest.

i.e

nodetool repair -full foo_keyspace bar_columnfamily

nodetool cleanup foo_keyspace bar_columnfamily

Do you think that this procedure will be safe for the data?

Thank you

Nadav Har'El
  • 11,785
  • 1
  • 24
  • 45
Jibrilat
  • 347
  • 1
  • 3
  • 14
  • I'd suggest posting on dba.stackexchange.com. As this isn't programming-related, it's off-topic for Stack Overflow. – David Makogon Dec 11 '18 at 23:51
  • 1
    running cleanup would make sense if you would have added a node that would unload data from your existing nodes. Of course, this also depends on how you added your existing nodes and if you ran cleanup. The solution in your situation might be adding some larger disks, as described [here](https://stackoverflow.com/questions/30743626/cassandra-node-almost-out-of-space-but-nodetool-cleanup-is-increasing-disk-use). – Horia Dec 12 '18 at 04:42
  • You may try to remove old snapshot data from the system. – Mehul Gupta Dec 12 '18 at 06:49

3 Answers3

14

The commands that you presented in your question make several incorrect assumptions. First, "repair" is not supposed to, and will not, save any space. All repair does is to find inconsistencies between different replicas and repair them. It will either do nothing (if there's no inconsistencies), or add data, not remove data. Second, "cleanup" is something you need to do after adding new nodes to the cluster - after each node sent some of its data to the new node, a "cleanup" removes the data from the old nodes. But cleanup is not relevant when not adding node.

The command you may be looking for is "compact". This can save space, but only when you know you had a lot of overwrites (rewriting existing rows), deletions or data expirations (TTL). What compaction strategy are you using? If it's the default, size-tiered compaction strategy (STCS) you can start major compaction (nodetool compact) but should be aware of a big risk involved:

Major compaction merges all the data into one sstable (Cassandra's on-disk file format), dropping deleted, expired or overwritten data. However, during this compaction process, you have both input and output files, and at worst case this may double your disk usage, and may fail if the disk is more than 50% full. This is why a lot of Cassandra best-practice guides suggest never to fill more than 50% of the disk. But this is just the worst case. You can get along with less free space if you know that the output file will be much smaller than the input (because most of the data has been deleted). Perhaps more usefully, if you have many separate tables (column family), you can compact each one separately (as you suggested, from smallest to biggest) and the maximum amount of disk space needed temporarily during the compaction can be much less than 50% of the disk.

Scylla, a C++ reimplementation of Cassandra, is developing something known as "hybrid compaction" (see https://www.slideshare.net/ScyllaDB/scylla-summit-2017-how-to-ruin-your-performance-by-choosing-the-wrong-compaction-strategy) which is like Cassandra's size-tiered compaction but does compaction in small pieces instead of generating one huge file, to avoid the huge temporary disk usage during compaction. Unfortunately, Cassandra doesn't have this feature yet.

Nadav Har'El
  • 11,785
  • 1
  • 24
  • 45
  • Hi nyh, thank you for your answer. I am executing repair before cleanup in order to fix inconsistencies to the data and lower the risk of lost data when I will execute the cleanup. There are many articles out there which people complaining that lost data after a cleanup execution. In my case unfortunately I have 90%full in 3 nodes of every DC so I need desperately a way to get free space. – Jibrilat Dec 12 '18 at 20:57
1

Good idea is first start repair on smallest table on smallest keyspace one by one and complete repair. It will take time but safer way and no chance to hang and traffic loss. Once repair completed start cleanup in the same way as repair. This way no impact on node and cluster as well.

LetsNoSQL
  • 1,478
  • 1
  • 11
  • 23
0

You shouldn't fill more than about 50-60 % of your disks to make room for compaction. If you're above that amount of disk usage you need to consider getting bigger disks or add more nodes.

Datastax recommendations are usually good to follow: https://docs.datastax.com/en/dse-planning/doc/planning/planPlanningDiskCapacity.html

Simon Fontana Oscarsson
  • 2,114
  • 1
  • 17
  • 20