Home » Java » cassandra – Update of an entity with ttl not working as expected with Datastax Java driver-Exceptionshub

cassandra – Update of an entity with ttl not working as expected with Datastax Java driver-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m trying to add ttl to an existing record(at the entity level and not column) which gets saved in a batch, there is an enum in that table which gets updated and ttl is applied whenever customer chooses that option, but what I see is after the ttl period expires the row doesn’t get deleted and only the enum is back to what it was before applying the ttl. The code looks something like below where customer is the entity being persisted, ttl is a transient Integer field which gets set > 0 only on updates while customerMapper is the Mapper< Customer>

            if(customer.getTtl() > 0) {
                batchStatement.add(customerMapper.saveQuery(customer, ttl(customer.getTtl())));
            } else {
                batchStatement.add(customerMapper.saveQuery(customer));
            }

the table_schema:

        CREATE TABLE customer (
            id uuid,
            tenant_id bigint,
            workspace_id bigint,
            creation_date timestamp,
            in_control_group boolean,
            monitored boolean,
            num_sessions int,
            id_status tinyint,
            recognized boolean,
            PRIMARY KEY (id, tenant_id, workspace_id)
            );

We’re using Cassandra 3+, The table has a read and write consistency set to LOCAL_QUORUM while the compaction is Level_Tiered. Any thoughts on what probably is wrong?

How to&Answers: