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
//! The `SEGMENTED` internal frame — the AOF's stitch to the cold
//! segment tier. Rides the ordinary record envelope as a two-element
//! multibulk, NUL-prefixed like the transaction markers so no RESP
//! verb a client can type ever collides with it.
//!
//! # What the frame means — and what it does not
//!
//! `[SEGMENTED, <seg-file>]` in a shard's AOF says: "every row this
//! segment holds had been evicted from the hot layer at this point in
//! the log". Replay uses it to re-do that eviction — the rows' SET
//! frames precede it, replay them in and this frame asks them back
//! out. The frame is a *timing stitch inside the log stream*, not the
//! segment set's source of truth: the truth about which segments are
//! live is the segment manifest, fsynced BEFORE this frame is
//! appended. Two consequences, both load-bearing:
//!
//! - A frame naming a segment the manifest does not hold means the
//! truth set was damaged after the fact (the manifest is written
//! first) — the rows' only durable copy is unreachable, so startup
//! refuses by name rather than silently dropping rows.
//! - A frame LOST to a snapshot truncation or an AOF rewrite is
//! harmless: by then the hot layer no longer holds the evicted rows
//! (the eviction preceded the SAVE/rewrite), or — if a rewrite view
//! froze mid-eviction — the rows survive in both tiers and
//! hot-first reads shadow the segment copy. Rewrite therefore needs
//! no seam for this frame.
use ArgvView;
/// The frame's verb. The leading NUL is what makes it internal: no
/// client-typed RESP verb can start with it.
///
/// ```
/// assert_eq!(kevy_persist::SEGMENTED[0], 0);
/// assert!(kevy_persist::SEGMENTED.ends_with(b"KEVYSEGMENTED"));
/// ```
pub const SEGMENTED: & = b"\0KEVYSEGMENTED";
/// If `args` is a `SEGMENTED` frame, its segment file name. Replay
/// drivers check this before ordinary dispatch — an unrecognized
/// internal frame must never fall through as a silent unknown verb.
///
/// ```
/// use kevy_persist::{Argv, segmented_argv, segmented_frame};
///
/// let mut frame = Argv::default();
/// for part in segmented_argv(b"seg-7.kseg") {
/// frame.push(part);
/// }
/// assert_eq!(segmented_frame(&frame), Some(&b"seg-7.kseg"[..]));
/// let set = Argv::from(vec![b"SET".to_vec(), b"k".to_vec()]);
/// assert_eq!(segmented_frame(&set), None);
/// ```
Sized>
/// The `SEGMENTED` frame as an argv, ready for the record writer.
///
/// ```
/// use kevy_persist::{Argv, RecordStep, SEGMENTED, next_record, segmented_argv};
///
/// let mut frame = Argv::default();
/// for part in segmented_argv(b"seg-7.kseg") {
/// frame.push(part);
/// }
/// let mut log = Vec::new();
/// kevy_persist::write_record_multibulk(&mut log, &frame, &mut Vec::new())?;
/// let RecordStep::Ok { payload, .. } = next_record(&log, 0) else { panic!("valid record") };
/// assert!(payload.windows(SEGMENTED.len()).any(|w| w == SEGMENTED));
/// # Ok::<(), std::io::Error>(())
/// ```
use ;
/// The rewrite's trailing SEGMENTED frames: one per segment the
/// frozen entries reference. Replay rebuilds the hot stream first,
/// then each frame re-establishes its rows' stubs — rows the stream
/// never carried are inserted straight from the segment.
pub
/// Two borrowed parts as an ArgvView (the SEGMENTED frame's shape).
;