From 0a3170eda750c6245f3e8450a2436a174c7ff3fa Mon Sep 17 00:00:00 2001 From: Dmitry Konstantinov Date: Mon, 6 Apr 2026 21:16:25 +0100 Subject: [PATCH] Avoid Cell iterator for alive rows in MetricsRecording transformation of ReadCommand patch by Dmitry Konstantinov; reviewed by TBD for CASSANDRA-21288 --- src/java/org/apache/cassandra/db/ReadCommand.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/cassandra/db/ReadCommand.java b/src/java/org/apache/cassandra/db/ReadCommand.java index f5f9105602ab..a47dc5cd72a1 100644 --- a/src/java/org/apache/cassandra/db/ReadCommand.java +++ b/src/java/org/apache/cassandra/db/ReadCommand.java @@ -644,12 +644,15 @@ public Row applyToStatic(Row row) public Row applyToRow(Row row) { boolean hasTombstones = false; - for (Cell cell : row.cells()) + if (row.hasDeletion(ReadCommand.this.nowInSec())) // perf optimization, to avoid iteration if all cells are alive { - if (!cell.isLive(ReadCommand.this.nowInSec())) + for (Cell cell : row.cells()) { - countTombstone(row.clustering()); - hasTombstones = true; // allows to avoid counting an extra tombstone if the whole row expired + if (!cell.isLive(ReadCommand.this.nowInSec())) + { + countTombstone(row.clustering()); + hasTombstones = true; // allows to avoid counting an extra tombstone if the whole row expired + } } }