Why don't an upsert create Tombstones in Cassandra?

3.2k views Asked by At

As per Question regarding Tombstone, why doesn't upserts create tombstones? As per datastax documentation, How is data updated ? for every upsert, cassandra considers as delete followed by insert, as the new timestamps of the insert overwrites the old timestamp. The old timestamp data has to be marked as delete which relates to tombstone.

Why do we have contradicting statements? or else am I missing anything here?

Usecase: Data is inserted with unique key (uuid) in Cassandra and some of the columns in this data keeps updating frequently. Which approach do you recommend?

  1. Inserting the same data with new column values in the Insert query.
  2. Updating the existing record based on given uuid with new column values in the update query.

Which approach does or doesn't create tombstones? and how does Cassandra handle both queries?

1

There are 1 answers

0
Jeff Jirsa On

As Russ pointed out, you may want to read other similar questions on this topic. However,

An upsert/overwrite is just-another-cell, with a name, a timestamp and a value.

A tombstone is just like an overwrite, except it gets one extra field indicating that it's been deleted, so that it isn't returned as valid output. The reason tombstones are often harmful is that they can accumulate in bad data models, even when people think the data is gone - and skipping them to get to live data actually requires memory.

When you update/upsert as you describe, the cell you create SHADOWS (obsoletes) the previous cell, which will be removed upon compaction. That previous cell is NOT a tombstone, even though it's no longer live/active - it will be compacted away and completely replaced by the new, live, highest-timestamp value as soon as compaction allows.

The biggest thing to keep in mind is this: tombstones aren't necessarily removed by compaction - they're kept around (persisted/rewritten) for at least gc_grace_seconds, and potentially even long if they need to shadow/cover other cells in sstables not-yet-compacted. Because of this, tombstones stay around for a long time, but shadowed/overwritten cells are gc'd as soon as the sstable they're in is compacted.