use std::sync::atomic::{AtomicU8, Ordering};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum IndexState {
Pending = 0,
Ready = 1,
Retired = 2,
}
pub(crate) struct IndexStateCell(AtomicU8);
impl IndexStateCell {
pub(crate) fn new(state: IndexState) -> Self {
Self(AtomicU8::new(state as u8))
}
pub(crate) fn get(&self) -> IndexState {
match self.0.load(Ordering::Acquire) {
0 => IndexState::Pending,
1 => IndexState::Ready,
_ => IndexState::Retired,
}
}
pub(crate) fn set(&self, state: IndexState) {
self.0.store(state as u8, Ordering::Release);
}
}
pub(crate) const DIRECT_WRITE: &str =
"an index target takes no direct writes; its source's projection writes it";
pub(crate) const NO_RETENTION: &str = "an index target cannot use retention";
pub(crate) const NO_DROP: &str = "an index target cannot drop segments";
pub(crate) const KEEP_ONLY: &str = "an index target's own typed migration may only return Keep; change the source's projection instead";
pub(crate) const NO_HOOK: &str = "an index target takes no hook";