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
//! Cfg-gated multi-generation streaming-merge resident-rows probe (issue #1579,
//! Epic D / D3).
//!
//! # Why this exists
//!
//! D3 makes `scan_stream` over more than one SSTable generation feed each
//! reconciled partition from the k-way merger STRAIGHT into the bounded output
//! channel, instead of collecting the ENTIRE reconciled table into a `Vec`,
//! sorting it, and only then dribbling it down the channel. A correct answer
//! never proves *how much memory* the merge held resident — the same rows come
//! out either way. This probe makes the peak resident set observable so the
//! O(window) claim is pinned the no-heuristics way: observe the *work* (rows the
//! streaming producer held resident at once), not just the result.
//!
//! # The counter
//!
//! - [`record_resident`] raises a process-global high-water mark to `n` — the
//! number of rows the streaming producer had materialized-but-not-yet-drained
//! at one instant. The streaming driver reports each stepped partition's row
//! count (its resident window is one partition at a time). The pre-D3 eager
//! path reported `merged.len()` — the whole reconciled table — so the peak was
//! proportional to the row count and the D3 memory guard
//! (`peak_resident` FLAT across fixture sizes) flips red without the streaming
//! rework.
//!
//! # Zero overhead in release (same pattern as [`crate::query::agg_stream_probe`])
//!
//! [`record_resident`] is an **unconditional** `#[inline(always)]` public
//! function; its body is `#[cfg(any(test, feature = "work-counters"))]`. In a
//! default/release build (no `work-counters`, no `cfg(test)`) the body is empty
//! and optimizes away — no atomic is even linked. The getter + [`reset`] are
//! `#[cfg(any(test, feature = "work-counters"))]`: in-crate unit tests reach them
//! via the `test` cfg; integration tests in `tests/` enable the `work-counters`
//! feature (they compile the lib WITHOUT its `test` cfg).
use ;
/// Process-global high-water mark of rows the streaming multi-generation merge
/// held resident at one instant since the last [`reset`] (test/feature builds
/// only).
static PEAK_RESIDENT: AtomicU64 = new;
/// Record that the streaming multi-generation merge held `n` rows resident at
/// one instant, raising the process-global high-water mark. Called
/// unconditionally by the streaming merge driver; the body compiles to a no-op
/// in a release build.
/// Peak resident rows the streaming multi-generation merge held at one instant
/// since the last [`reset`]. Streaming holds one partition at a time, so this is
/// FLAT across fixture sizes; the pre-D3 eager path reported the whole table.
/// Clear the process-global high-water mark. Integration tests call this before a
/// measured stream so a stale value cannot satisfy a later assertion; because the
/// global is shared, callers serialize on the shared test mutex (the counter-test
/// convention).