M. Afathi
M. Afathi

Reputation: 65

Override TTL Cassandra

I am using a Cassandra database for my application, and I am setting a TTL per request. For testing purpose I am using another database (same schema, but in local) and I am willing to keep data and I was wondering if there is a way to override the ttl, I don't know, by setting it to default while creating tables or something like that.

Thank you.

Upvotes: 3

Views: 7149

Answers (2)

juniormint88
juniormint88

Reputation: 206

I don't think it works in that direction; since you are specifying TTL in the CQL and not at the table-level.

http://cassandra.apache.org/doc/latest/cql/dml.html

If the table has a default_time_to_live, a TTL of 0 will remove the TTL for the inserted or updated values. A TTL of null is equivalent to inserting with a TTL of 0.

THE CQL TTL overrides the default. If you have 9999 TTL at the table-level and use 50 in CQL; the 50 would be used.

refer here - http://www.mail-archive.com/[email protected]/msg50873.html

Upvotes: 0

undefined_variable
undefined_variable

Reputation: 6218

Setting a TTL for a specific column

Use CQL to set the TTL for data.

To change the TTL of a specific column, you must re-insert the data with a new TTL. Cassandra upserts the column with the new TTL, replacing the old value with the old TTL, if any exists.

Setting a TTL for a table

The CQL table definition supports the default_time_to_live property, which applies a specific TTL to each column in the table. After the default_time_to_live TTL value has been exceed, Cassandra tombstones the entire table. Apply this default TTL to a table in CQL using CREATE TABLE or ALTER TABLE.

If your table has TTL value not equal to 0 in local environment use

ALTER TABLE table_name
  WITH  default_time_to_live= 0

This will change table level TTL.

If column level TTL is set change the code to insert record with 0 or some higher TTL.

Details

Upvotes: 5

Related Questions