Search code examples
cassandracql3ttlcassandra-2.1

Cassandra incorrect TTL value for select ttl()


I have a 3 node cluster with replication factor : 2.

The column family in consideration has default_time_to_live = 3600 Which is set using alter table : cqlsh:summary> alter table match with default_time_to_live=3600;

After inserting data into columnfamily and immediately, querying, select ttl(column_name), i get incorrect results.

cqlsh:summary> select ttl(end_time) from match limit 5;

ttl(end_time)

      3132
      5342
      5342
      1802
      1802

(5 rows)

Keyspace definition:

CREATE KEYSPACE summary WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': '2'}  AND durable_writes = true;

Column family definition:

CREATE TABLE summary.match (
match_name text,
start_time bigint,
end_time bigint,
PRIMARY KEY (match_name, start_time)) WITH CLUSTERING ORDER BY (start_time ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
AND comment = ''
AND compaction = {'min_threshold': '4', 'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 3600
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99.0PERCENTILE';

Using : Cassandra 2.1.0 | CQL spec 3.2.0

Should it not be something less than 3600? Where is the TTL value of 5342 coming in account?

Question: How does the default_time_to_live value come into effect?


Solution

  • This is a non-issue. The timestamps of node in the cluster was out of sync.

    Running ntpdate -bu <ntp server> to sync clocks in each node. Then TTL is coming as expected.

    Some reading onto why syncing time is important for cassandra.

    https://blog.logentries.com/2014/03/synchronizing-clocks-in-a-cassandra-cluster-pt-1-the-problem/

    https://ria101.wordpress.com/2011/02/08/cassandra-the-importance-of-system-clocks-avoiding-oom-and-how-to-escape-oom-meltdown/