Skip to content

Commit

Permalink
Merge pull request #27 from instaclustr/4.1-fixttl
Browse files Browse the repository at this point in the history
Include row TTL into TTL stats
  • Loading branch information
jfleming-ic authored Aug 16, 2023
2 parents 80c0b9a + 554b083 commit 45fc3bc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public int compare(PartitionStatistics o1, PartitionStatistics o2) {
*/
public long droppableTombstoneCount = 0;

public final static int NO_TTL = -1;

public Map<Integer,Long> ttl = new HashMap<>();

private static final Long ZERO = 0L;

public void ttl(int key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ public void run() {
TableBuilder ttltb = new TableBuilder();
ttltb.setHeader("TTL", "Count");
for (Map.Entry<Integer, Long> 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);
}
Expand Down

0 comments on commit 45fc3bc

Please sign in to comment.