use crate::Cacheable;
use crate::watermark::DeltaSyncCacheable;
use std::collections::HashSet;
#[non_exhaustive]
pub struct DeltaResult<T: Cacheable, W = ()> {
pub items: Vec<T>,
pub tombstones: HashSet<T::Id>,
pub high_watermark: Option<W>,
}
impl<T: Cacheable, W> DeltaResult<T, W> {
pub fn new(items: Vec<T>, tombstones: HashSet<T::Id>) -> Self {
Self {
items,
tombstones,
high_watermark: None,
}
}
pub fn with_high_watermark(
items: Vec<T>,
tombstones: HashSet<T::Id>,
high_watermark: W,
) -> Self {
Self {
items,
tombstones,
high_watermark: Some(high_watermark),
}
}
pub(crate) fn without_high_watermark(self) -> DeltaResult<T> {
DeltaResult {
items: self.items,
tombstones: self.tombstones,
high_watermark: None,
}
}
}
impl<T: DeltaSyncCacheable> DeltaResult<T, T::Watermark> {
pub(crate) fn observed_watermark(&self) -> Option<T::Watermark> {
let item_watermark = self.items.iter().map(DeltaSyncCacheable::watermark).max();
match (&self.high_watermark, item_watermark) {
(Some(high_watermark), Some(item_watermark)) => {
Some(high_watermark.clone().max(item_watermark))
}
(Some(high_watermark), None) => Some(high_watermark.clone()),
(None, Some(item_watermark)) => Some(item_watermark),
(None, None) => None,
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct DeltaApplyStats {
pub applied_items: usize,
pub tombstones_evicted: usize,
pub lru_evictions: usize,
pub backend_reserved_skips: usize,
}