Skip to main content

krabka_verified/
restore.rs

1//! Batch-offset continuity, record placement, and rewrite admission for
2//! offline restore verification.
3
4use creusot_std::prelude::*;
5
6/// Batch fate after folding the exact per-record selection results.
7#[krabka_macros::model_type]
8pub enum RestoreFilterDecision {
9    Keep,
10    Empty,
11    Filter,
12}
13
14/// Which operator exclusion predicates matched one record.
15///
16/// The host evaluates each pattern against the record; the kernel owns only
17/// how the matches combine.
18#[krabka_macros::model_type]
19pub struct RestoreExclusions {
20    /// `--exclude-producer-id` names the batch's producer.
21    pub producer: bool,
22    /// An `--exclude-offset` range covers the record's absolute offset.
23    pub offset: bool,
24    /// Regex matches over the record's own bytes.
25    pub content: RestoreContentExclusions,
26}
27
28/// Which content patterns matched one record's raw key and header bytes.
29#[krabka_macros::model_type]
30pub struct RestoreContentExclusions {
31    /// An `--exclude-key` pattern matches the record key.
32    pub key: bool,
33    /// An `--exclude-header` pattern matches one record header.
34    pub header: bool,
35}
36
37/// One remote segment's lifecycle state in the RLMM snapshot, or its absence.
38#[krabka_macros::model_type]
39pub enum RestoreSnapshotState {
40    /// The snapshot does not list the segment.
41    Missing,
42    /// `COPY_SEGMENT_STARTED` or `COPY_SEGMENT_FINISHED`.
43    Live,
44    /// `DELETE_SEGMENT_STARTED`.
45    DeleteStarted,
46    /// `DELETE_SEGMENT_FINISHED`.
47    DeleteFinished,
48}
49
50/// What restore does with one segment after comparing scan and snapshot.
51#[krabka_macros::model_type]
52pub enum RestoreReconcileDecision {
53    /// The scanned bytes are restored.
54    Keep,
55    /// The segment is absent or being deleted; nothing is restored for it.
56    Exclude,
57    /// The archive scan and the snapshot contradict each other.
58    Disagree,
59}
60
61/// Kafka's batch timestamp type: attributes bit 3
62/// (`DefaultRecordBatch.TIMESTAMP_TYPE_MASK`).
63#[krabka_macros::model_type]
64pub enum RestoreTimestampType {
65    CreateTime,
66    LogAppendTime,
67}
68
69/// The batch-header fields that place a record in offset and time.
70#[krabka_macros::model_type]
71pub struct RestoreBatchFrame {
72    pub base_offset: i64,
73    pub last_offset_delta: i32,
74    pub timestamp_type: RestoreTimestampType,
75    pub base_timestamp: i64,
76    pub max_timestamp: i64,
77}
78
79/// One record's encoded offset and timestamp deltas.
80#[krabka_macros::model_type]
81pub struct RestoreRecordDeltas {
82    pub offset_delta: i32,
83    pub timestamp_delta: i64,
84}
85
86/// Producer identity and batch kind of one rewritten batch.
87#[krabka_macros::model_type]
88pub struct RestoreProducer {
89    /// Attributes bit 5.
90    pub control: bool,
91    /// Attributes bit 4.
92    pub transactional: bool,
93    pub producer_id: i64,
94    pub producer_epoch: i16,
95    pub base_sequence: i32,
96}
97
98/// Offset layout of one rewritten batch.
99#[krabka_macros::model_type]
100pub struct RestoreLayout {
101    pub base_offset: i64,
102    pub last_offset_delta: i32,
103    pub records_count: i32,
104}
105
106mod record_coordinates;
107#[cfg(creusot)]
108pub use record_coordinates::{kafka_record_timestamp, restore_excluded, restore_record_placeable};
109pub use record_coordinates::{
110    restore_archive_reconcile, restore_batch_filter_decision, restore_batch_past_offset_bound,
111    restore_batch_step, restore_record_coordinates, restore_record_selected,
112};
113
114mod rewritten_record;
115#[cfg(creusot)]
116pub use rewritten_record::{
117    legal_header, legal_producer, non_idempotent_producer, restore_rewrite_record_legal,
118};
119pub use rewritten_record::{restore_rewritten_batch_header, restore_rewritten_record};
120
121#[cfg(test)]
122mod tests;