From 554b0833b2bd0ec1a4493979090e88b5a773da14 Mon Sep 17 00:00:00 2001 From: Cameron Zemek Date: Sun, 6 Aug 2023 22:55:44 +1000 Subject: [PATCH] Include row TTL into TTL stats --- .../sstabletools/PartitionStatistics.java | 3 +++ .../sstabletools/cassandra/DataReader.java | 20 ++++++++++++++++--- .../cli/ColumnFamilyStatisticsCollector.java | 6 +++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/instaclustr/sstabletools/PartitionStatistics.java b/src/main/java/com/instaclustr/sstabletools/PartitionStatistics.java index e17486a..092bd48 100644 --- a/src/main/java/com/instaclustr/sstabletools/PartitionStatistics.java +++ b/src/main/java/com/instaclustr/sstabletools/PartitionStatistics.java @@ -89,7 +89,10 @@ public int compare(PartitionStatistics o1, PartitionStatistics o2) { */ public long droppableTombstoneCount = 0; + public final static int NO_TTL = -1; + public Map ttl = new HashMap<>(); + private static final Long ZERO = 0L; public void ttl(int key) { diff --git a/src/main/java/com/instaclustr/sstabletools/cassandra/DataReader.java b/src/main/java/com/instaclustr/sstabletools/cassandra/DataReader.java index 0775953..02e8383 100644 --- a/src/main/java/com/instaclustr/sstabletools/cassandra/DataReader.java +++ b/src/main/java/com/instaclustr/sstabletools/cassandra/DataReader.java @@ -3,6 +3,7 @@ import com.instaclustr.sstabletools.AbstractSSTableReader; import com.instaclustr.sstabletools.PartitionStatistics; import com.instaclustr.sstabletools.SSTableStatistics; +import org.apache.cassandra.db.LivenessInfo; import org.apache.cassandra.db.rows.Cell; import org.apache.cassandra.db.rows.Row; import org.apache.cassandra.db.rows.Unfiltered; @@ -70,15 +71,28 @@ public boolean next() { this.partitionStats.rowDeleteCount++; this.tableStats.rowDeleteCount++; } + LivenessInfo liveInfo = row.primaryKeyLivenessInfo(); + if (!liveInfo.isEmpty()) { + int ttl = liveInfo.ttl(); + if (ttl != Cell.NO_TTL) { + this.partitionStats.ttl(ttl); + } else { + this.partitionStats.ttl(PartitionStatistics.NO_TTL); + } + } for (Cell cell : row.cells()) { this.partitionStats.cellCount++; this.tableStats.cellCount++; if (cell.isLive(gcGrace)) { this.tableStats.liveCellCount++; } - int ttl = cell.ttl(); - if (ttl != Cell.NO_TTL) { - this.partitionStats.ttl(ttl); + if (liveInfo.isEmpty() || cell.ttl() != liveInfo.ttl()) { + int ttl = cell.ttl(); + if (ttl != Cell.NO_TTL) { + this.partitionStats.ttl(ttl); + } else { + this.partitionStats.ttl(PartitionStatistics.NO_TTL); + } } if (cell.isTombstone()) { this.partitionStats.tombstoneCount++; diff --git a/src/main/java/com/instaclustr/sstabletools/cli/ColumnFamilyStatisticsCollector.java b/src/main/java/com/instaclustr/sstabletools/cli/ColumnFamilyStatisticsCollector.java index 4ea65bf..6c09f59 100644 --- a/src/main/java/com/instaclustr/sstabletools/cli/ColumnFamilyStatisticsCollector.java +++ b/src/main/java/com/instaclustr/sstabletools/cli/ColumnFamilyStatisticsCollector.java @@ -185,7 +185,11 @@ public void run() { TableBuilder ttltb = new TableBuilder(); ttltb.setHeader("TTL", "Count"); for (Map.Entry entry : ttl.entrySet()) { - ttltb.addRow(Util.humanReadableDateDiff(0, entry.getKey() * 1000L), Long.toString(entry.getValue())); + if (entry.getKey() == PartitionStatistics.NO_TTL) { + ttltb.addRow("NO_TTL", Long.toString(entry.getValue())); + } else { + ttltb.addRow(Util.humanReadableDateDiff(0, entry.getKey() * 1000L), Long.toString(entry.getValue())); + } } System.out.println(ttltb); }