use thiserror::Error;
#[derive(Debug, Error)]
pub enum MemtableError {
#[error("memtable is frozen and cannot accept writes")]
Frozen,
#[error("memtable capacity exceeded: current {current} bytes, limit {limit} bytes")]
CapacityExceeded {
current: usize,
limit: usize,
},
#[error("schema error: {0}")]
Schema(#[from] chronix_core::SchemaError),
#[error(
"timestamp {timestamp} is outside the out-of-order window \
[{earliest}, {latest}] (+/-{tolerance} shard(s) of {shard_secs}s \
around the newest admitted write); import history with a backfill \
write instead"
)]
ShardOutOfRange {
timestamp: i64,
earliest: i64,
latest: i64,
tolerance: i64,
shard_secs: u64,
},
#[error("no such shard: {0}")]
NoSuchShard(i64),
#[error("flush I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("segment write error: {0}")]
Segment(#[from] crate::segment::SegmentError),
#[error("segment registration failed: {0}")]
Flush(String),
#[error("no frozen memtable available for flush")]
NoFrozenMemtable,
#[error("WAL error: {0}")]
Wal(#[from] chronix_core::WalError),
}
pub type Result<T> = std::result::Result<T, MemtableError>;