1use std::path::PathBuf;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5 #[error("io error on {path}: {source}")]
6 Io {
7 path: PathBuf,
8 #[source]
9 source: std::io::Error,
10 },
11
12 #[error(transparent)]
13 Arrow(#[from] arrow_schema::ArrowError),
14
15 #[error("dictionary key space exhausted for column `{0}`; seal the block")]
18 DictionaryFull(&'static str),
19
20 #[error("{path} is not an Arrow IPC file (bad ARROW1 magic)")]
21 BadMagic { path: PathBuf },
22
23 #[error("{path} failed checksum: footer says {expected:#010x}, body hashes to {actual:#010x}")]
24 BadChecksum {
25 path: PathBuf,
26 expected: u32,
27 actual: u32,
28 },
29
30 #[error("{path} has no {key} in its IPC footer metadata; not a Mira block")]
31 MissingMetadata { path: PathBuf, key: &'static str },
32
33 #[error("{path}: this block's body cannot be decoded: {source}")]
45 Undecodable {
46 path: PathBuf,
47 #[source]
48 source: arrow_schema::ArrowError,
49 },
50
51 #[error(
54 "{path} is on {fs}, a network filesystem. Mira reads blocks through mmap, \
55 and on {fs} a server-side error surfaces as SIGBUS — a signal, not an \
56 error, with no recovery path from Rust. Point --data-dir at a local \
57 block device (in Kubernetes: a local PV, an EBS/PD volume, or an \
58 emptyDir, not an NFS/CSI network mount)."
59 )]
60 NetworkFilesystem { path: PathBuf, fs: String },
61
62 #[error(
65 "{path} is not writable: {source}. Mira writes nowhere else, so this is \
66 fatal at startup rather than degraded at 3am. Check that the mount is \
67 read-write and that this process owns the path (in Kubernetes: a \
68 volume mounted readOnly, or a missing fsGroup)."
69 )]
70 NotWritable {
71 path: PathBuf,
72 #[source]
73 source: std::io::Error,
74 },
75
76 #[error(
79 "--offload {uri}: only file:// is implemented. Everything after the \
80 prefix is a path, so file:///srv/cold and file://./cold both work, and \
81 a bucket already mounted into the filesystem is reached that way. \
82 s3:// is not in this binary: signing a request needs HMAC-SHA256 and \
83 reading a listing needs an XML parser, and neither is in the crate \
84 graph the README counts."
85 )]
86 OffloadScheme { uri: String },
87
88 #[error(
91 "{dest} is already in the store and does not match the block being \
92 pushed ({why}). A block name is its identity, so this one cannot be \
93 reported as already archived — a scale-in would take that as licence \
94 to delete the volume. The likely cause is a replica re-created on a \
95 fresh volume: it keeps its node id and restarts its sequence, so it \
96 reissues (node, seq) pairs the store still holds. Move the copy in \
97 the store aside, then push again."
98 )]
99 OffloadCollision { dest: PathBuf, why: String },
100
101 #[error("export of {len} bytes exceeds the {max}-byte WAL frame limit")]
105 WalFrameTooLarge { len: usize, max: u32 },
106
107 #[error("{path}: corrupt write-ahead log frame: {why}")]
112 WalCorrupt { path: PathBuf, why: &'static str },
113
114 #[error(
116 "{path} is held by another process writing as node {node:#010x}. A \
117 write-ahead log has one writer: both would resume to the same \
118 sequence and hand it out twice, and a block that claims the watermark \
119 for one frame would cover the other — an acknowledged export never \
120 replayed. Two replicas may share a volume, but not a node id: give \
121 each one its own --node."
122 )]
123 WalLocked { path: PathBuf, node: u32 },
124
125 #[error("{path}: write-ahead log version {found}, this build writes {expected}")]
129 WalVersion {
130 path: PathBuf,
131 found: u16,
132 expected: u16,
133 },
134}
135
136pub type Result<T, E = Error> = std::result::Result<T, E>;
137
138pub(crate) trait IoContext<T> {
139 fn ctx(self, path: impl Into<PathBuf>) -> Result<T>;
140}
141
142impl<T> IoContext<T> for std::io::Result<T> {
143 fn ctx(self, path: impl Into<PathBuf>) -> Result<T> {
144 self.map_err(|source| Error::Io {
145 path: path.into(),
146 source,
147 })
148 }
149}