use crate::store::{AppendReceipt, HlcPoint, Open, Store, StoreError, WatermarkKind};
use std::time::Duration;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DurabilityGate {
pub kind: WatermarkKind,
pub timeout: Duration,
}
impl Store<Open> {
fn receipt_point(&self, receipt: &AppendReceipt) -> Result<HlcPoint, StoreError> {
self.index
.get_by_id(receipt.event_id)
.map(|entry| HlcPoint {
wall_ms: entry.wall_ms,
global_sequence: entry.global_sequence,
})
.ok_or_else(|| StoreError::InvariantViolation {
reason: format!(
"append receipt {:032x} was not visible for durability gate lookup",
receipt.event_id
),
})
}
pub(crate) fn wait_for_gate(
&self,
receipt: &AppendReceipt,
gate: DurabilityGate,
) -> Result<(), StoreError> {
let target = self.receipt_point(receipt)?;
match gate.kind {
WatermarkKind::Durable => self.wait_for_durable(target, gate.timeout),
WatermarkKind::Applied => self.wait_for_applied(target, gate.timeout),
WatermarkKind::Visible => self.wait_for_visible(target, gate.timeout),
}
}
}