use super::WarpTableRowGetError;
use super::dense_key_index::{CommitInconsistency, IndexInconsistency};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum WarpTableInconsistency {
IdColumnLengthMismatch {
ids: usize,
rows: usize,
},
PrimaryBucketUnavailable {
bucket: usize,
},
PrimaryStoredRowUnrepresentable {
stored_row: u32,
},
IdUnavailable {
row: usize,
},
PrimaryStoredRowMismatch {
expected: usize,
actual: usize,
},
PrimaryProbeLimitReached,
ColumnUnavailable {
column: usize,
row: usize,
},
PrimaryInsertRowUnrepresentable {
bucket: usize,
row: usize,
},
PrimaryInsertRowReserved {
bucket: usize,
row: usize,
},
PrimaryInsertVacancyUnavailable {
bucket: usize,
row: usize,
},
PrimaryInsertVacancyOccupied {
bucket: usize,
row: usize,
occupying_row: u32,
},
DenseRowUnavailable {
row: usize,
rows: usize,
},
IdentifierSequenceBlocked {
attempts: usize,
},
CapacityReachedDuringGeneratedInsert,
}
#[cold]
#[track_caller]
#[allow(
clippy::panic,
reason = "a bounded table's broken internal invariant is a library defect, not a recoverable outcome"
)]
pub fn invariant_violation(reason: impl core::fmt::Debug) -> ! {
panic!("WarpTable invariant violated: {reason:?}")
}
impl From<IndexInconsistency> for WarpTableInconsistency {
fn from(reason: IndexInconsistency) -> Self {
match reason {
IndexInconsistency::BucketUnavailable { bucket } => {
Self::PrimaryBucketUnavailable { bucket }
}
IndexInconsistency::StoredRowUnrepresentable { stored_row } => {
Self::PrimaryStoredRowUnrepresentable { stored_row }
}
IndexInconsistency::KeyUnavailable { row } => Self::IdUnavailable { row },
IndexInconsistency::StoredRowMismatch { expected, actual } => {
Self::PrimaryStoredRowMismatch { expected, actual }
}
IndexInconsistency::ProbeLimitReached => Self::PrimaryProbeLimitReached,
}
}
}
impl From<WarpTableRowGetError> for WarpTableInconsistency {
fn from(reason: WarpTableRowGetError) -> Self {
match reason {
WarpTableRowGetError::ColumnUnavailable { column, row } => {
Self::ColumnUnavailable { column, row }
}
}
}
}
impl From<CommitInconsistency> for WarpTableInconsistency {
fn from(reason: CommitInconsistency) -> Self {
match reason {
CommitInconsistency::RowUnrepresentable { vacancy, row } => {
Self::PrimaryInsertRowUnrepresentable {
bucket: vacancy.bucket(),
row,
}
}
CommitInconsistency::RowReserved { vacancy, row } => Self::PrimaryInsertRowReserved {
bucket: vacancy.bucket(),
row,
},
CommitInconsistency::VacancyUnavailable { vacancy, row } => {
Self::PrimaryInsertVacancyUnavailable {
bucket: vacancy.bucket(),
row,
}
}
CommitInconsistency::VacancyOccupied {
vacancy,
row,
occupying_row,
} => Self::PrimaryInsertVacancyOccupied {
bucket: vacancy.bucket(),
row,
occupying_row,
},
}
}
}