Cassandra : Does deleting a whole partition create tombstone?

Viewed 256

I'm new to Cassandra. I had a situation where delete per partition is performed. Does deleting the entire partition create tombstones? Right now space is not getting released after the deletion.

3 Answers

Yes, deletion of the whole partition creates a special type of the tombstone that "shadows" the all data in the partition. But like the other tombstones, it's kept for gc_grace_seconds, and only after that collected.

There is a great blog post from the The Last Pickle that explains tombstones in great details

As mentioned you can update gc_grace_seconds to 0 but I wouldn't recommend that unless you only have one node in your cluster or that your RF=1. You could try to reduce GC grace to an acceptable time for you. I'd like to put the maximum time I think a Cassandra node could stay down.

An other option to immediately releasing space is to change your data model to use truncate/drop. For instance if you only need your data for 24h you could create one table per day and at some point drop the tables that you don't need.

I made test with insert new data after delete by the same partition key.

create table message_routes (
  user_id bigint,
  route_id bigint,
  primary key ((user_id), service_id)
)
  1. insert into message_routes (user_id, route_id) values (1, 2)

  2. delete from message_routes where user_id = 1

  3. insert info message_routes (user_Id, route_id) values (1, 3)

After each stage was executed nodetool flush & nodetool compact but tombstone from stage 2 was't evicted as shown by sstablemetadata. After delete was executed new insert. I was hoping that Cassandra has optimizations for such cases.

It's interesting how this tombstones affect select queries by partition key if delete will be frequents?

select * from message_routes where user_id = 1
Related