use core::fmt::Debug;
use super::refrecord::BranchRefRecord;
use super::time::Timestamp;
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) enum CreateExclusive {
Installed,
TargetExists(BranchRefRecord),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum EntryFence<'a> {
Present(&'a BranchRefRecord),
Absent(&'a str),
}
pub(super) trait DurableRecordStore: Debug {
type Error;
fn list_read_at_open(&mut self) -> Result<Vec<BranchRefRecord>, Self::Error>;
fn create_exclusive(
&mut self,
record: &BranchRefRecord,
) -> Result<CreateExclusive, Self::Error>;
fn cas_replace_install(
&mut self,
name: &str,
expected_created: Timestamp,
expected_seq: u64,
replacement: &BranchRefRecord,
) -> Result<BranchRefRecord, Self::Error>;
fn unlink(&mut self, name: &str) -> Result<bool, Self::Error>;
fn entry_fence(&mut self, expected: EntryFence<'_>) -> Result<(), Self::Error>;
}
pub(super) fn entry_fence_with_source<S: DurableRecordStore + ?Sized>(
store: &mut S,
expected: EntryFence<'_>,
) -> Result<(), super::operation_error::FenceOperationError<S::Error>> {
super::operation_error::preserve_record_entry_fence(store.entry_fence(expected))
}
#[cfg(test)]
pub(super) fn entry_fence_compat<S: DurableRecordStore + ?Sized>(
store: &mut S,
expected: EntryFence<'_>,
) -> Result<(), S::Error> {
entry_fence_with_source(store, expected).map_err(|error| match error {
super::operation_error::FenceOperationError::RecordEntry(source) => source,
super::operation_error::FenceOperationError::NodePublication(_) => {
unreachable!("node fence returned from record entry core")
}
})
}