How to update time-to-live(TTL) of existing records in Cassandra DB?
I did some R&D on this issue and I have concluded following points.
- We can increase TTL for any record in Cassandra DB but it needs to reset all fields with update query for individual record.
- 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.
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
This work on Cassandra 2.0.7
You can RE-INSERT the same data changing only TTL.
INSERT INTO Table (col1, col2 ) VALUES ( '001','aaa') USING TTL 200;
INSERT INTO Table (col1, col2 ) VALUES ( '001','aaa') USING TTL 2;
Wait 2 sec and the row disappear;
I found also this by DataStax: To change the TTL of a specific column, you must re-insert the data with a new TTL. Apache Cassandra™ upserts the column with the new TTL, replacing the old value with the old TTL, if any exists.
See this link