Avinash
Avinash

Reputation: 2191

Timestamp data persistence in cassandra

In our crawling system we have 5 node cassandra cluster. I have a scenario in which I want to delete cassandra data as soon as it becomes older than x days.

Ex:

id | name | created_date

1 | Dan      |  "2017-08-01"             
2 | Monk     |  "2017-08-02" 
3 | Shibuya  |  "2017-08-03"             
4 | Rewa     |  "2017-08-04"             
5 | Himan    |  "2017-08-05"

if x = 3 Then following should be the scenario:

id | name | created_date

1 | Dan      |  "2017-08-01"   --------------> DELETE          
2 | Monk     |  "2017-08-02"   --------------> DELETE
3 | Shibuya  |  "2017-08-03"   -------------->(REMAIN)Latest 3 days data
4 | Rewa     |  "2017-08-04"   -------------->(REMAIN)Latest 3 days data
5 | Himan    |  "2017-08-05"   -------------->(REMAIN)Latest 3 days data

If new data is added then id=3 should be deleted. Is there any Cassandra configuration or any approach to do this?

Upvotes: 0

Views: 60

Answers (2)

Tolik Antoniuk
Tolik Antoniuk

Reputation: 51

You can use TTL.

But be careful with tombstouns and compaction procedure

Upvotes: 1

Jeff Jirsa
Jeff Jirsa

Reputation: 4426

Cassandra has a TTL feature, that allows you to specify how long each CQL cell is valid. Details are available on the INSERT docs, but it also applies to UPDATE.

Upvotes: 2

Related Questions