use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SearchProjectionChangeBatchProbe {
pub start_commit_epoch: u64,
pub operation_count: usize,
pub complete_through_commit_epoch: Option<u64>,
pub source_commit_epoch: u64,
pub covers_source: bool,
}
pub(super) enum MaintainedSearchProjection<'a> {
Resident(&'a SearchIndex),
Incremental(SearchProjectionFreshness),
}
impl EmbeddedStore {
pub(super) fn maintained_search_projection(&self) -> Result<MaintainedSearchProjection<'_>> {
match (
self.search_projection.as_ref(),
self.out_of_core_search_projection.as_ref(),
) {
(Some(projection), None) => Ok(MaintainedSearchProjection::Resident(projection.index())),
(None, Some(projection)) if self.incremental_search_enabled() => Ok(
MaintainedSearchProjection::Incremental(projection.freshness()),
),
(None, Some(_)) => Err(HawDBError::Semantic(
"search projection has no catch-up maintenance: this out-of-core projection is qualified read-only; open it with incremental search maintenance"
.into(),
)),
(None, None) => Err(HawDBError::Semantic(
"search projection is not attached: open the store with a search projection, or reopen it after its incremental reader failed to attach the durable head"
.into(),
)),
(Some(_), Some(_)) => Err(HawDBError::Semantic(
"search projection ownership is ambiguous: both a resident and an out-of-core projection are attached"
.into(),
)),
}
}
pub fn search_projection_change_batch_probe(
&self,
max_operations: usize,
) -> Result<Option<SearchProjectionChangeBatchProbe>> {
if max_operations == 0 {
return Err(HawDBError::Semantic(
"search projection change batch probe max_operations must be greater than zero"
.to_string(),
));
}
let database = self.graph.database();
let (start_commit_epoch, batch) = match self.maintained_search_projection()? {
MaintainedSearchProjection::Incremental(freshness) => {
let start = freshness.durable_source_graph_commit_epoch.unwrap_or(0);
(
start,
database
.build_search_projection_change_batch_after(start, Some(max_operations))?,
)
}
MaintainedSearchProjection::Resident(index) => {
let start = index
.projection_freshness()
.source_graph_commit_epoch
.unwrap_or(0);
(
start,
database.build_search_projection_change_batch_from_freshness(
index,
Some(max_operations),
)?,
)
}
};
let Some(batch) = batch else {
return Ok(None);
};
let source_commit_epoch = database.commit_epoch()?;
let complete_through_commit_epoch = batch.complete_through_commit_epoch();
Ok(Some(SearchProjectionChangeBatchProbe {
start_commit_epoch,
operation_count: batch.operation_count(),
complete_through_commit_epoch,
source_commit_epoch,
covers_source: complete_through_commit_epoch == Some(source_commit_epoch),
}))
}
}
impl EmbeddedStoreHandle {
pub fn search_projection_change_batch_probe(
&self,
max_operations: usize,
) -> Result<Option<SearchProjectionChangeBatchProbe>> {
self.read_store()?
.search_projection_change_batch_probe(max_operations)
}
}