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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//! Operator chain: statically composed push stages behind one type-erasure
//! boundary per batch.
//!
//! Stages compose via [`Collector`] (monomorphized, so a whole chain compiles
//! to one loop); the only virtual call on the data path is
//! [`RunnableChain::push_batch`], once per poll batch. Records are born
//! (deserialized) and die (encoded into shard frames, filtered, or skipped)
//! inside a single `push_batch` call, so borrowed payloads never cross or
//! outlive the boundary (ADR-0013).
//!
//! # Owned vs borrowed record families
//!
//! For owned families ([`Owned<T>`](crate::deser::Owned)) the builder
//! offers [`ChainBuilder::map`] / [`ChainBuilder::try_map`] with plain
//! closure bounds; bare closures infer. For **borrowing** families a
//! `rustc` limitation (E0582: a higher-ranked lifetime may not appear only
//! in associated-type positions) rules out `FnMut`-with-projection-output
//! bounds at the definition site; use [`ChainBuilder::map_rec`] /
//! [`ChainBuilder::try_map_rec`], whose bound goes through [`MapFn`] /
//! [`TryMapFn`]. Pass a **`fn` item** where you can: it satisfies a
//! higher-ranked bound by construction, where a closure satisfies it only
//! when the compiler infers a higher-ranked signature for it.
//!
//! A stage over a borrowing family, written as a `fn` item:
//!
//! ```
//! # use spate_core::checkpoint::AckRef;
//! # use spate_core::deser::{Deserializer, EmitRecord, RecFamily};
//! # use spate_core::error::DeserError;
//! # use spate_core::ops::chain;
//! # use spate_core::record::RawPayload;
//! # struct LogEvent<'buf> {
//! # key: &'buf str,
//! # }
//! # struct LogF;
//! # impl RecFamily for LogF {
//! # type Rec<'buf> = LogEvent<'buf>;
//! # }
//! # #[derive(Clone, Default)]
//! # struct LogDeser;
//! # impl Deserializer<LogF> for LogDeser {
//! # fn deserialize<'buf>(
//! # &mut self,
//! # raw: &RawPayload<'buf>,
//! # ack: &AckRef,
//! # out: &mut dyn EmitRecord<'buf, LogEvent<'buf>>,
//! # ) -> Result<(), DeserError> {
//! # let _ = (raw, ack, out);
//! # Ok(())
//! # }
//! # }
//! # let log_deser = LogDeser;
//! struct Compact<'buf> {
//! key: &'buf str,
//! }
//! struct CompactF;
//! impl RecFamily for CompactF {
//! type Rec<'buf> = Compact<'buf>;
//! }
//!
//! fn shrink<'a>(e: LogEvent<'a>) -> Compact<'a> {
//! Compact { key: e.key }
//! }
//! let stage = chain(log_deser).map_rec::<CompactF, _>(shrink);
//! # let _ = stage;
//! ```
//!
//! [`ChainBuilder::filter`], [`ChainBuilder::inspect`], and
//! [`ChainBuilder::flat_map`] have no output binding, so a single generic
//! method serves both kinds of family.
//!
//! ```
//! use spate_core::backpressure::InflightBudget;
//! use spate_core::deser::{BytesPassthrough, Owned};
//! use spate_core::error::ErrorPolicy;
//! use spate_core::ops::{ChunkConfig, chain};
//! use spate_core::record::Record;
//! use spate_core::sink::{KeyHashRouter, RowEncoder, shard_queues};
//! use std::sync::Arc;
//!
//! // A trivial encoder writing `<u32 len><bytes>` rows.
//! #[derive(Clone)]
//! struct LenPrefix;
//! impl RowEncoder<Owned<Vec<u8>>> for LenPrefix {
//! fn encode<'buf>(
//! &mut self,
//! rec: &Record<Vec<u8>>,
//! buf: &mut bytes::BytesMut,
//! ) -> Result<(), spate_core::error::SinkError> {
//! buf.extend_from_slice(&(rec.payload.len() as u32).to_le_bytes());
//! buf.extend_from_slice(&rec.payload);
//! Ok(())
//! }
//! }
//!
//! let (queues, _rx) = shard_queues(2, 64);
//! let budget = Arc::new(InflightBudget::new());
//!
//! let mut pipeline_chain = chain(BytesPassthrough)
//! .map(|mut bytes: Vec<u8>| {
//! bytes.make_ascii_uppercase();
//! bytes
//! })
//! .filter(|bytes: &Vec<u8>| !bytes.is_empty())
//! .try_map(
//! |bytes: Vec<u8>| String::from_utf8(bytes).map(String::into_bytes),
//! ErrorPolicy::Skip,
//! )
//! .sink(LenPrefix, KeyHashRouter, ChunkConfig::default(), queues, budget)
//! .build();
//! # let _ = &mut pipeline_chain;
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
use crateRecFamily;
use crateFatalError;
use crate;
use cratePayloadBatch;
/// Why a batch could not complete yet. Both cases are retried with the
/// resume cursor, but only [`BlockReason::Capacity`] engages the driver's
/// backpressure controller. A not-ready wait is an upstream dependency
/// (e.g. a schema fetch), not sink pressure, and pausing the source for it
/// would misreport the pipeline's state.
/// Result of pushing one batch (or a resumed suffix of one) through a
/// chain.
/// The one erasure boundary between a pipeline thread's driver loop and a
/// typed chain. The methods are generic over the buffer lifetime
/// only, so `Box<dyn RunnableChain>` is legal.
/// Push-model stage: receives one record, forwards 0..N downstream.
///
/// Composed statically; `Map<F, Filter<P, Term>>` monomorphizes into a
/// single inlined loop body.
/// Family-erased collector: accepts the family's record type at *any*
/// buffer lifetime through a lifetime-generic method, which keeps it
/// dyn-compatible. This is what lets `flat_map` closures hold a plain
/// `&mut Emitter<'_, OutF>` without naming the downstream stack type.