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
//! Test-only checkpoint for the mutable-table sink.
//!
//! Compiled only under `feature = "test-hooks"`. The `mutable_crash_recovery.rs`
//! integration test spawns a child process with [`READY_FILE_ENV`] and
//! [`CHECKPOINT_AFTER_ENV`] set; the child inserts a known number of rows
//! through the sink, this hook fires once the per-write-call row counter
//! crosses the threshold, writes [`READY_FILE_ENV`] so the parent knows the
//! child is mid-transaction, then awaits an unsignalled notifier so the child
//! parks until the parent sends `SIGKILL`. The transaction never commits;
//! RAII rollback delivers the spec's zero-row guarantee.
//!
//! When the env vars are unset (the default for every other test and every
//! production build), [`maybe_signal`] is a single `if` returning early. No
//! production code path observes this module.
use PathBuf;
use OnceLock;
use Notify;
/// Path the child writes once `rows_so_far >= CHECKPOINT_AFTER_ENV`. The
/// parent polls `try_exists` on this path and `SIGKILL`s the child as soon
/// as it appears.
pub const READY_FILE_ENV: &str = "JAMMI_TEST_CHECKPOINT_READY_FILE";
/// Row threshold the child must cross before signalling. The child increments
/// `rows_so_far` once per `insert_batch` call; a test that wants to fire after
/// the 50th row passes a 50-row batch and sets this to 50.
pub const CHECKPOINT_AFTER_ENV: &str = "JAMMI_TEST_CHECKPOINT_AFTER";
/// Park forever once the signal fires. Park-and-die is the contract: the
/// caller has SIGKILL teed up.
static PARK: = new;
/// One-shot guard so a test that calls `insert_batch` multiple times only
/// signals once. Without this, the second call would re-write the ready file
/// and re-park (the first park has already returned), wasting wall-clock.
static SIGNALLED: = new;
/// Resolve env-driven checkpoint configuration. `Some` only when both vars
/// are set and the threshold is a parseable `u64`.
/// Signal-and-park if `rows_so_far` has crossed the configured threshold.
/// First call past the threshold writes the ready file and parks forever on
/// a notifier that no one signals. Subsequent calls are no-ops.
pub async