Skip to content

Commit c59ae41

Browse files
committed
Merge branch 'cassandra-6.0' into trunk
2 parents 9c3caa8 + bbff4f8 commit c59ae41

7 files changed

Lines changed: 38 additions & 2 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Allow nodetool garbagecollect to take a user defined list of SSTables (CASSANDRA-16767)
44
* Add a guardrail for misprepared statements (CASSANDRA-21139)
55
Merged from 6.0:
6+
* Add rowsMutatedPerWriteHistogram metric to track rows mutated per write request (CASSANDRA-21320)
67
* Add TotalRowsRead and TotalRowsMutated counters to TableMetrics for accurate per-table row throughput tracking (CASSANDRA-21321)
78
* Move exception handling of SPI startup checks when iterating over them (CASSANDRA-21409)
89
* Avoid type lookup in SerializationHeader#getType if schema and SSTable are aligned (CASSANDRA-21402)

src/java/org/apache/cassandra/db/ColumnFamilyStore.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,9 @@ public void apply(PartitionUpdate update, CassandraWriteContext context, boolean
15301530
metric.topWritePartitionSize.addSample(key.getKey(), update.dataSize());
15311531
StorageHook.instance.reportWrite(metadata.id, update);
15321532
metric.writeLatency.addNano(nanoTime() - start);
1533-
metric.totalRowsMutated.inc(update.affectedRowCount());
1533+
int affectedRows = update.affectedRowCount();
1534+
metric.totalRowsMutated.inc(affectedRows);
1535+
metric.rowsMutatedPerWriteHistogram.update(affectedRows);
15341536
// CASSANDRA-11117 - certain resolution paths on memtable put can result in very
15351537
// large time deltas, either through a variety of sentinel timestamps (used for empty values, ensuring
15361538
// a minimal write, etc). This limits the time delta to the max value the histogram

src/java/org/apache/cassandra/db/virtual/TableMetricTables.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public static Collection<VirtualTable> getAll(String name)
7878
new HistogramTableMetric(name, "tombstones_per_read", t -> t.tombstoneScannedHistogram.cf),
7979
new HistogramTableMetric(name, "purgeable_tombstones_per_read", t -> t.purgeableTombstoneScannedHistogram.cf),
8080
new HistogramTableMetric(name, "rows_per_read", t -> t.liveScannedHistogram.cf),
81+
new HistogramTableMetric(name, "rows_per_write", t -> t.rowsMutatedPerWriteHistogram.cf),
8182
new StorageTableMetric(name, "disk_usage", (TableMetrics t) -> t.totalDiskSpaceUsed),
8283
new StorageTableMetric(name, "max_partition_size", (TableMetrics t) -> t.maxPartitionSize),
8384
new StorageTableMetric(name, "max_sstable_size", (TableMetrics t) -> t.maxSSTableSize),

src/java/org/apache/cassandra/metrics/KeyspaceMetrics.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public class KeyspaceMetrics
8989
public final Histogram purgeableTombstoneScannedHistogram;
9090
/** Live cells scanned in queries on this Keyspace */
9191
public final Histogram liveScannedHistogram;
92+
/** Rows mutated in writes on this Keyspace */
93+
public final Histogram rowsMutatedPerWriteHistogram;
9294
/** Column update time delta on this Keyspace */
9395
public final Histogram colUpdateTimeDeltaHistogram;
9496
/** time taken acquiring the partition lock for materialized view updates on this keyspace */
@@ -258,6 +260,7 @@ public KeyspaceMetrics(final Keyspace ks)
258260
tombstoneScannedHistogram = createKeyspaceHistogram("TombstoneScannedHistogram", false);
259261
purgeableTombstoneScannedHistogram = createKeyspaceHistogram("PurgeableTombstoneScannedHistogram", false);
260262
liveScannedHistogram = createKeyspaceHistogram("LiveScannedHistogram", false);
263+
rowsMutatedPerWriteHistogram = createKeyspaceHistogram("RowsMutatedPerWriteHistogram", false);
261264
colUpdateTimeDeltaHistogram = createKeyspaceHistogram("ColUpdateTimeDeltaHistogram", false);
262265
viewLockAcquireTime = createKeyspaceTimer("ViewLockAcquireTime");
263266
viewReadTime = createKeyspaceTimer("ViewReadTime");

src/java/org/apache/cassandra/metrics/TableMetrics.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ public class TableMetrics
170170
public final Counter totalRowsRead;
171171
/** Total number of rows mutated in writes to this CF (cumulative counter, suitable for rate/windowed calculations) */
172172
public final Counter totalRowsMutated;
173+
/** Rows mutated in writes on this CF */
174+
public final TableHistogram rowsMutatedPerWriteHistogram;
173175
/** Column update time delta on this CF */
174176
public final TableHistogram colUpdateTimeDeltaHistogram;
175177
/** time taken acquiring the partition lock for materialized view updates for this table */
@@ -818,6 +820,7 @@ public Long getValue()
818820
liveScannedHistogram = createTableHistogram("LiveScannedHistogram", cfs.keyspace.metric.liveScannedHistogram, false);
819821
totalRowsRead = createTableCounter("TotalRowsRead");
820822
totalRowsMutated = createTableCounter("TotalRowsMutated");
823+
rowsMutatedPerWriteHistogram = createTableHistogram("RowsMutatedPerWriteHistogram", cfs.keyspace.metric.rowsMutatedPerWriteHistogram, false);
821824
colUpdateTimeDeltaHistogram = createTableHistogram("ColUpdateTimeDeltaHistogram", cfs.keyspace.metric.colUpdateTimeDeltaHistogram, false);
822825
coordinatorReadLatency = createTableTimer("CoordinatorReadLatency");
823826
coordinatorScanLatency = createTableTimer("CoordinatorScanLatency");

test/distributed/org/apache/cassandra/distributed/test/metric/TableMetricTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class TableMetricTest extends TestBaseImpl
6262
ORG_APACHE_CASSANDRA_DISABLE_MBEAN_REGISTRATION.setBoolean(false);
6363
}
6464
private static volatile Map<String, Collection<String>> SYSTEM_TABLES = null;
65-
private static Set<String> TABLE_METRIC_NAMES = ImmutableSet.of("WriteLatency");
65+
private static Set<String> TABLE_METRIC_NAMES = ImmutableSet.of("WriteLatency", "RowsMutatedPerWriteHistogram");
6666

6767
/**
6868
* Makes sure that all system tables have the expected metrics

test/unit/org/apache/cassandra/metrics/TableMetricsTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,32 @@ private void assertMetricRows(String metricName, Counter counter)
269269
String.valueOf(counter.getCount())));
270270
}
271271

272+
@Test
273+
public void testRowsMutatedPerWriteHistogram()
274+
{
275+
ColumnFamilyStore cfs = recreateTable();
276+
assertEquals(0, cfs.metric.rowsMutatedPerWriteHistogram.cf.getCount());
277+
278+
session.execute(String.format("INSERT INTO %s.%s (id, val1, val2) VALUES (1, 'a', 'b')", KEYSPACE, TABLE));
279+
session.execute(String.format("INSERT INTO %s.%s (id, val1, val2) VALUES (1, 'c', 'd')", KEYSPACE, TABLE));
280+
281+
assertEquals(2, cfs.metric.rowsMutatedPerWriteHistogram.cf.getCount());
282+
assertGreaterThan(cfs.metric.rowsMutatedPerWriteHistogram.cf.getSnapshot().getMax(), 0);
283+
284+
String histogramMedian = Double.toString(cfs.metric.rowsMutatedPerWriteHistogram.cf.getSnapshot().getMedian());
285+
286+
assertRowsContains(cluster, session.execute("SELECT * FROM system_metrics.table_group"),
287+
row("org.apache.cassandra.metrics.Table.RowsMutatedPerWriteHistogram.junit.tablemetricstest",
288+
"junit.tablemetricstest",
289+
"histogram",
290+
histogramMedian));
291+
assertRowsContains(cluster, session.execute("SELECT * FROM system_metrics.column_family_group"),
292+
row("org.apache.cassandra.metrics.ColumnFamily.RowsMutatedPerWriteHistogram.junit.tablemetricstest",
293+
"junit.tablemetricstest",
294+
"histogram",
295+
histogramMedian));
296+
}
297+
272298
@Test
273299
public void testLoggedPartitionsPerBatch()
274300
{

0 commit comments

Comments
 (0)