2

I have a column family in Cassandra in which one of the column name is status with value Y. This status has to be updated to a new value - X after 30 minutes if it wasn't updated to some other value say N within the 30 minutes.

Basically, I want to mark the column to Expired - X if there wasn't any update within the specified time interval.

Also, once this is expired, it needs to trigger off an event to notify another system(API) saying that it was expired.

2 Answers2

2

You can try Cassandra's TTL (Time to Live) Feature

You can set an optional expiration period called TTL (time to live) for data in a column, other than a counter column. The TTL value for a column is a number of seconds. After the number of seconds since the column's creation exceeds the TTL value, TTL data is considered expired and is included in results

Every time you update the field, use TTL of 30 min or 1800 seconds

Example :

UPDATE users USING TTL 1800 SET password = 'ch@ngem4a' WHERE user_name = 'cbrown';

For first time insert, also use the above query.

So for above example, the password field will mark as deleted after 30 min, if it is not updated within 30 min.

But it is not possible to trigger off an event to notify your system.

Note : TTL or delete generate tombstone, Huge amount of tombstone can slow down your read performance

Read More about tombstone

Ashraful Islam
  • 12,470
  • 3
  • 32
  • 53
  • I've already considered TTL. Like I mentioned above, I need the row to be present, the column value has to be updated. Something like a Trigger perhaps? – gautam suddapalli Jun 06 '17 at 13:00
1

Agree with Ashraful's answer. If you use Spring Data for Apache Cassandra 2.0 (currently milestone), then you would use the following code to implements Ashraful's example:

@Table("users")
public class User {

    @PrimaryKey("user_name")
    String userName;
    String password;
}

WriteOptions options = WriteOptions.builder().ttl(1800).build();

template.update(query(where("userName").is("cbrown")).queryOptions(options), 
                update("password", "ch@ngem4a"), 
                User.class);
mp911de
  • 17,546
  • 2
  • 55
  • 95