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
//! Opt-in, default-OFF presence-oracle false-negative verification switch
//! (issue #2163).
//!
//! A presence oracle (the BIG bloom filter / BTI Partitions.db trie) must NEVER
//! report a false negative: a "definitely absent" verdict for a key that is
//! actually present would silently drop data. This switch turns on an
//! AUTHORITATIVE confirmation scan of an SSTable whenever its oracle reports a
//! key absent; a contradiction increments `cqlite.read.bloom.false_negatives`
//! (see [`crate::observability::catalog::READ_BLOOM_FALSE_NEGATIVES`]). Under a
//! correct oracle the counter stays 0 — a non-zero value is a corruption alarm.
//!
//! It is **off by default** and gated by an explicit runtime switch, because the
//! confirmation scan is the one presence-oracle counter that costs real work. The
//! switch is read once from the `CQLITE_VERIFY_PRESENCE_ORACLE` environment
//! variable (booleans: `1/0`, `true/false`, `yes/no`, `on/off`), then cached. The
//! `observability-testing`-gated [`set_enabled_for_testing`] lets the correctness
//! tests toggle it deterministically without touching process env.
//!
//! # Config plumbing + precedence (issue #2163, roborev r4)
//!
//! [`crate::observability::ObservabilityConfig::verify_presence_oracle`] is a
//! PROGRAMMATIC way to set this switch (e.g. `ObservabilityConfig::builder()
//! .verify_presence_oracle(true).build()`), for callers that construct config in
//! code rather than through the environment. [`crate::observability::init`] calls
//! [`apply_config`] with that field so the config value actually reaches this
//! switch — it is not merely decorative. Precedence (conventional
//! env-overrides-config, matching every other `ObservabilityConfig` field's own
//! `from_env` behaviour): if [`ENV_VAR`] is explicitly set to a parseable boolean,
//! it ALWAYS wins over the config value; otherwise the config value applies.
use ;
const UNINIT: u8 = 0;
const OFF: u8 = 1;
const ON: u8 = 2;
/// Tri-state cache: `UNINIT` until first resolved from the environment, then
/// pinned to `OFF`/`ON`. Test overrides store `OFF`/`ON` directly.
static STATE: AtomicU8 = new;
/// Environment variable that enables the opt-in verification when truthy.
pub const ENV_VAR: &str = "CQLITE_VERIFY_PRESENCE_ORACLE";
/// Whether presence-oracle false-negative verification is enabled.
///
/// Resolves lazily from [`ENV_VAR`] on first call (default `false` when unset or
/// unparseable), caching the result so subsequent reads are a single relaxed
/// atomic load. Always `false` unless explicitly turned on — so the default
/// production read path performs no confirmation scan and costs nothing beyond
/// the existing presence check.
/// Apply an [`ObservabilityConfig`](crate::observability::ObservabilityConfig)-
/// sourced enablement value to this runtime switch (issue #2163, roborev r4 —
/// closes the "config field is decorative" gap).
///
/// [`ENV_VAR`], when explicitly set to a parseable boolean, ALWAYS takes
/// precedence over `config_value` — the conventional env-overrides-config rule
/// [`crate::observability::ObservabilityConfig::from_env`] already applies to
/// every other field. Otherwise `config_value` becomes the switch's state. Called
/// from [`crate::observability::init`] (both the `observability`-feature-enabled
/// and inert builds) so a programmatic
/// `ObservabilityConfig::builder().verify_presence_oracle(true).build()` actually
/// flips the switch the read path consults. Idempotent and safe to call multiple
/// times (e.g. across repeated `init` calls in a test process) — it always
/// recomputes from scratch and FORCES the result into the shared state, so a
/// later `init` call can still correct an earlier one.
pub
/// Force the switch on/off for tests (issue #2163). Gated behind
/// `observability-testing` so production builds never expose a runtime mutator;
/// integration tests compile the library with that feature and toggle the switch
/// deterministically around a flow.