laminar_core/tpc/router.rs
1//! Key routing specification and error types.
2//!
3//! Provides [`KeySpec`] for specifying how events are partitioned across cores
4//! and [`RouterError`] for routing failures.
5
6/// Routing errors with no heap allocation.
7///
8/// All error variants use static strings to avoid allocation on error paths,
9/// which is critical for Ring 0 hot path performance.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
11pub enum RouterError {
12 /// A column specified by name was not found in the schema.
13 #[error("column not found by name")]
14 ColumnNotFoundByName,
15
16 /// A column index is out of range for the batch.
17 #[error("column index out of range")]
18 ColumnIndexOutOfRange,
19
20 /// A row index is out of range for the array.
21 #[error("row index out of range")]
22 RowIndexOutOfRange,
23
24 /// The data type is not supported for key extraction.
25 #[error("unsupported data type for routing")]
26 UnsupportedDataType,
27
28 /// The batch is empty and cannot be routed.
29 #[error("empty batch")]
30 EmptyBatch,
31}
32
33/// Specifies how to extract routing keys from events.
34///
35/// The key determines which core processes an event. All events with the
36/// same key are guaranteed to go to the same core.
37#[derive(Debug, Clone, Default)]
38pub enum KeySpec {
39 /// Use specific column names as the key.
40 ///
41 /// The columns are concatenated in order to form the key.
42 Columns(Vec<String>),
43
44 /// Use column indices as the key.
45 ///
46 /// Useful when column names are not known or for performance.
47 ColumnIndices(Vec<usize>),
48
49 /// Round-robin distribution (no key).
50 ///
51 /// Events are distributed evenly across cores without regard to content.
52 /// Use this when state locality is not required.
53 #[default]
54 RoundRobin,
55
56 /// Use all columns as the key.
57 ///
58 /// The entire row is hashed to determine routing.
59 AllColumns,
60}