Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update time-to-live(TTL) of existing records in Cassandra DB?

Tags:

database

As Cassandra DB is providing a option to set Time-to-live(TTL) value to automatically delete the record on the basis of TTL value set with record. I have a case that user can change the date of data expiry, means user can change the data expiration date any time.

Case:

  1. Suppose default expiration period is 10 days.
  2. Then inserted some records with setting TTL for 10 days.
  3. after 2 days user change expiration period to 30 days.
  4. But the previous data inserted with 10 days TTL period automatically gets deleted after 10 days instead of 30 days.

Requirement: Whenever user changes the expiration period through UI, we wanted to change TTL in database. Is there any option to update the TTL for records in Cassandra DB.

like image 537
Anil Jadhav Avatar asked Jul 14 '14 08:07

Anil Jadhav


2 Answers

I did some R&D on this issue and I have concluded following points.

  1. We can increase TTL for any record in Cassandra DB but it needs to reset all fields with update query for individual record.
  2. We can’t reduce TTL for any record at any cost. Even if you update record with less TTL value, the record will remain in database till maximum TTL value which is either old or new. updated value.
like image 81
Anil Jadhav Avatar answered Sep 24 '22 03:09

Anil Jadhav


You can perform a "fake update"

INSERT INTO ttl_example (k, v) VALUES ('somekey', 'somevalue') USING TTL 60;
UPDATE ttl_example USING TTL 200 SET v = 'somevalue' WHERE k = 'somekey';

After the execution of second statement TTL will be 200 seconds.

HTH, Carlo

like image 39
Carlo Bertuccini Avatar answered Sep 21 '22 03:09

Carlo Bertuccini