Clearing up tombstones in cassandra

Steven Lacerda
1 min readOct 7, 2020

Tombstones can be created in many different ways, but the most common are:

  1. DELETE statements
  2. INSERT null
  3. TTL’s

Dealing with DELETE statements is a more difficult issue, but typically is better handled with TTL’s than DELETE. The reason is that a TTL is actually stored with the column value, thus, each column knows when the data should be invalidated. Thus, cleanup becomes much easier because the data doesn’t rely on any other data from other sstables.

INSERT null is also usually pretty easy prevent, just insert empty strings or data instead. Alternatively, if using something like SPARK, then you can use ignoreNulls to avoid inserting nulls on ingestion.

To get rid of tombstones that already exist:

  1. Temporarily lower your gc_grace_seconds setting:
ALTER TABLE foobar WITH gc_grace_seconds=10800;

2. Run nodetool garbagecollect foobar — the command is node specific, so you’ll need to run it on each node. If the tombstones are cell level, you’ll need to run the command with nodetool garbagecollect -g CELL foobar.

3. Alter the gc_grace_seconds back to normal:

ALTER TABLE foobar WITH gc_grace_seconds=<previous value>;

--

--

Steven Lacerda

Steve Lacerda is a software engineer specializing in web development. His favorite 80’s song is Let’s Put the X in Sex by Kiss.