1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
//! Read-path metric emission at BATCH granularity (issue #1701, epic #1686).
//!
//! # Why this module exists
//!
//! The four headline read metrics — [`catalog::READ_ROWS`], [`catalog::READ_BYTES`],
//! [`catalog::READ_PARTITIONS`] and [`catalog::READ_DURATION`] — were documented,
//! registered as instruments, rendered in the operator metric reference and shown
//! in this module's parent doc example, while NO production read path ever updated
//! them (finding AI1 of `docs/reports/platform-observability-audit-2026-07-01.md`).
//! A documented metric that is never written is worse than an absent one: an
//! operator's dashboard shows a flat zero and reads it as "no reads happening".
//!
//! # The granularity rule
//!
//! The span-granularity doctrine in [`catalog`] applies to metrics too: emission is
//! per read OPERATION, never per row. [`ReadOpMeter`] accumulates a scan's rows and
//! partitions in two `u64` fields and emits ONE counter add per metric plus ONE
//! duration recording when the operation ends. `read.bytes` is emitted once per
//! decompressed chunk ([`record_decompressed_bytes`]) — the coarsest grain at which
//! the decompressed size is actually known.
//!
//! # Which SUBSYSTEM's bytes `read.bytes` counts (issue #1701, roborev F3)
//!
//! `read.rows` / `read.partitions` / `read.duration` are emitted at an ENUMERATED set
//! of core query read boundaries — `SSTableManager`'s materializing scans and point
//! reads, and the `JoinedStream` streaming handles — so a compaction can never
//! contribute to them: compaction reads its inputs through
//! `stream_all_partitions_for_compaction` on a reader directly, never through those
//! boundaries.
//!
//! That set is a CLAIM ABOUT THOSE BOUNDARIES, not about the whole product. A caller
//! that reaches the readers by another route is NOT metered by this module — notably
//! the Arrow Flight `do_get` path, which drives `KWayMerger`/`QueryRowStream` directly
//! and emits its own rows/partitions from `cqlite-flight`'s `ScanProgressMeter` with no
//! duration at all. Extending duration coverage there needs Flight-level metering and
//! capture infrastructure in that crate, and is deliberately out of scope here; nothing
//! in this module or the operator reference should be read as claiming it. Flight reads
//! DO contribute `read.bytes`, because they decode through the same chunk plane.
//!
//! `read.bytes` is different, and deliberately so. It is credited inside the CHUNK
//! DECODE PLANE (`reader::chunk_source`), which is handed a `ReadAt` + a
//! `CompressionInfo` and cannot know WHO asked — the same plane serves a query read,
//! a compaction read, and a verification scan. So the metric answers "how many
//! `Data.db` bytes did this process materialise", including compaction's own reads.
//!
//! That is a real limitation for an operator reading query amplification off
//! `read.bytes` while a compaction runs, and the honest fix is NOT to guess at the
//! plane: it needs a read-PURPOSE dimension threaded from each caller (or a separate
//! compaction-bytes-read instrument), which reaches into the compaction merge
//! producer and is a change to compaction plumbing rather than metric wiring. It is
//! therefore recorded here and left to a follow-up, not silently approximated: the
//! plane never invents a purpose label it cannot know, exactly as it never invents
//! the SSTable format label.
//!
//! # Zero-cost when off
//!
//! [`ReadOpMeter::start`] consults [`obs::metrics_active`] ONCE (the issue #2819 M1
//! pattern) and returns an INERT meter when metrics are not being collected: no
//! [`Instant`] is sampled, no key is retained, and every later `record_*` call is a
//! single branch on a `None`. With the `observability` feature off,
//! `metrics_active()` is a compile-time `false`, so the whole meter degenerates to
//! that branch and the emission helpers compile to no-ops.
use Arc;
use ;
use ;
use ;
use crateobservability as obs;
use crateCompressionAlgorithm;
use crateRowKey;
/// The bounded [`catalog::attr::COMPRESSION`] value for "this SSTable has no
/// compressor", so an uncompressed read is attributed to a NAMED series rather than
/// an anonymous one (issue #1701). Same spelling the write side uses for
/// `CompressionAlgorithm::None`.
pub const COMPRESSION_NONE: &str = "none";
/// Map a compression algorithm to its bounded [`catalog::attr::COMPRESSION`] value.
///
/// Bounded by the `CompressionAlgorithm` enum itself (five variants), never by a
/// string read out of `CompressionInfo.db` — an on-disk algorithm name is
/// file-controlled and would be an unbounded metric dimension. Mirrors the write
/// side's `CompressedDataWriter::compression_attr` (issue #1036).
pub
/// Count `bytes` of `Data.db` payload (post-decompression) into
/// [`catalog::READ_BYTES`], tagged with the bounded `compression` label.
///
/// Called once per chunk the read path materialises, from the single chunk decode
/// plane (`reader::chunk_source`) — every one of its four decode exits, INCLUDING
/// the ones that hand back raw bytes: an UNCOMPRESSED SSTable (`compression =
/// "none"`) and a Cassandra-stored-raw incompressible chunk read `Data.db` payload
/// exactly like a decompressed chunk does. Uncompressed is a first-class read path,
/// not an edge case — CQLite's own production write surface emits uncompressed
/// SSTables only (the #1406 claim boundary) — so a `"none"` read that went
/// uncounted would make the metric silently understate real I/O.
///
/// A resident decompressed-chunk cache HIT is counted too, and the reason is a fact
/// about the feed rather than a preference (issue #1701, roborev round 5): the
/// windowed scan calls `read_compressed_chunk_sync` /
/// `read_uncompressed_piece_sync` UNCONDITIONALLY and only then asks the cache, and
/// neither reader consults it — so the disk read has ALREADY happened and that cache
/// saves DECOMPRESSION, not I/O. An earlier version of this doc asserted the
/// opposite, and a test asserted it too; they agreed with each other and were both
/// wrong, which is how a warm scan came to report zero bytes for I/O it really
/// performed. The one place a read is genuinely skipped — `get_cached_data`'s
/// early return, which reads no `Data.db` at all — stays uncounted.
///
/// The label is a `&'static str` from [`compression_attr`]'s closed mapping, so this
/// costs no allocation and no formatting on the per-chunk path.
pub
/// One read OPERATION's row/partition/duration accounting, emitted ONCE at the end.
///
/// A scan stream owns one of these for its whole lifetime; a point read owns one for
/// the duration of the lookup. [`finish`](Self::finish) is idempotent and is also
/// called from `Drop`, so an ABANDONED read (the common `LIMIT` shape: the consumer
/// stops polling and drops the stream) still reports the work it did instead of
/// vanishing from the metrics.
pub ;