Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disk Space not freed up even after deleting keyspace from cassandra db and compaction

Tags:

cassandra

I created a keyspace and a table(columnfamily) within it. Let's say "ks.cf"

After entering few hundred thousand rows in the columnfamily cf, I saw the disk usage using df -h.

Then, I dropped the keyspace using the command DROP KEYSPACE ks from cqlsh.

After dropping also, the disk usage remains the same. I also did nodetool compact, but no luck.

Can anyone help me out in configuring these things so that disk usage gets freed up after deleting the data/rows ?

like image 744
Pankaj Goyal Avatar asked Oct 13 '15 13:10

Pankaj Goyal


People also ask

How do I free up space on Cassandra?

You can drop or truncate tables. This solution is quite efficient because no tombstones are written. Cassandra just create a snapshot of the table when you run the command. The disk space is released when you clear the snapshot.

How do I check disk space on Cassandra?

Check the on-disk usage of the cassandra data dir (by default /var/lib/cassandra/data ) with this command: du -ch /var/lib/cassandra/data You should then compare that to the size of your disk, which can be found with df -h .

How does Cassandra delete data?

Cassandra deletes data in each selected partition atomically and in isolation. Deleted data is not removed from disk immediately. Cassandra marks the deleted data with a tombstone and then removes it after the grace period.


2 Answers

Ran into this problem recently. After dropping a table a snapshot is made. This snapshot will allow you to roll this back if this was not intended. If you do however want that harddrive space back you need to run:

nodetool -h localhost -p 7199 clearsnapshot

on the appropriate nodes. Additionally you can turn snapshots off with auto_snapshot: false in your cassandra.yml.

edit: spelling/grammar

like image 183
Highstead Avatar answered Oct 06 '22 01:10

Highstead


If you are just trying to delete rows, then you need to let the deletion step go through the usual delete cycle(delete_row->tombstone_creation->compaction_actually_deletes_the_row).

Now if you completely want to get rid of your keyspace, check your cassandra data folder(it should be specified in your yaml file). In my case it is "/mnt/cassandra/data/". In this folder there is a subfolder for each keyspace(i.e. ks ). You can just completely delete the folder related to your keyspace.

If you want to keep the folder around, it is good to know that cassandra creates a snapshot of your keyspace before dropping it. Basically a backup of all of your data. You can just go into 'ks' folder, and find the snapshots subdirectory. Go into the snapshots subdirectory and delete the snapshot related to your keyspace drop.

like image 22
Aki Avatar answered Oct 06 '22 02:10

Aki