laminar_connectors/connector/recency.rs
1//! Real-time recency: how far a source's upstream has been written, so a committed read can wait
2//! for a checkpoint that holds everything the source could see when the read arrived.
3
4use std::fmt::Debug;
5use std::time::Instant;
6
7use async_trait::async_trait;
8
9use crate::checkpoint::SourceCheckpoint;
10use crate::error::ConnectorError;
11
12/// Reports how far a source's upstream has been written. It is built from the source's
13/// configuration on any node and never touches the running reader or its position.
14#[async_trait]
15pub trait SourceRecency: Send + Sync + Debug {
16 /// The upstream's end now: every record a reader of this source could see.
17 ///
18 /// # Errors
19 ///
20 /// Returns an error when the upstream cannot be reached or described before `deadline`.
21 async fn upstream_end(
22 &self,
23 deadline: Instant,
24 ) -> Result<Box<dyn RecencyTarget>, ConnectorError>;
25}
26
27/// The upstream's end at one instant.
28#[async_trait]
29pub trait RecencyTarget: Send + Sync + Debug {
30 /// Whether `checkpoint`, a committed checkpoint of this source, holds every record before
31 /// this end. Positions only grow, so a later checkpoint of a covering one also covers it.
32 ///
33 /// # Errors
34 ///
35 /// Returns an error when `checkpoint` is not this connector's, or coverage cannot be decided
36 /// before `deadline`.
37 async fn covered_by(
38 &self,
39 checkpoint: &SourceCheckpoint,
40 deadline: Instant,
41 ) -> Result<bool, ConnectorError>;
42}