Search code examples
cassandracassandra-2.0cqlshttl

Cassandra add TTL to existing entries


How can I update an entire table and set a TTL for every entry?

Current Scenario (Cassandra 2.0.11):

table:

CREATE TABLE external_users (
  external_id text,
  type int,
  user_id text,
  PRIMARY KEY (external_id, type)
) 

currently there are ~40mio entries in this table and i want to add a TTL for lets say 86 400 seconds (1day). It's no problem for new entries with USING TTL(86400) or UPDATE current entries, but how do i apply a ttl for every already existing entry?

My idea was to select all data and update every single row with a little script. I was just wondering if there is an easier way to achieve this (because even with batch updates this is gonna take a while and is a big effort)

Thanks in advance


Solution

  • There is no way to alter TTL of existing data in C*. TTL is just an internal column attribute which is written together with all other column data into immutable SSTable. A quote from the docs:

    If you want to change the TTL of expiring data, you have to re-insert the data with a new TTL. In Cassandra, the insertion of data is actually an insertion or update operation, depending on whether or not a previous version of the data exists.