@@ -15,11 +15,21 @@ pub trait Connection: Send {
1515 /// Returns the `InitWatermark` based on the existing watermark if it exists.
1616 /// Otherwise, initializes a new watermark record with `InitWatermark` and returns
1717 /// the value passed in.
18+ ///
19+ /// The default implementation does not perform initialization and delegates to `committer_watermark`.
1820 async fn init_watermark (
1921 & mut self ,
2022 pipeline_task : & str ,
21- init_watermark : InitWatermark ,
22- ) -> anyhow:: Result < InitWatermark > ;
23+ _init_watermark : InitWatermark ,
24+ ) -> anyhow:: Result < InitWatermark > {
25+ let checkpoint_hi_inclusive = self
26+ . committer_watermark ( pipeline_task)
27+ . await ?
28+ . map ( |w| w. checkpoint_hi_inclusive ) ;
29+ Ok ( InitWatermark {
30+ checkpoint_hi_inclusive,
31+ } )
32+ }
2333
2434 /// Given a `pipeline_task` representing either a pipeline name or a pipeline with an associated
2535 /// task (formatted as `{pipeline}{Store::DELIMITER}{task}`), return the committer watermark
@@ -45,6 +55,15 @@ pub trait Connection: Send {
4555/// the pruning subsystem.
4656#[ async_trait]
4757pub trait TrailingConnection : Connection {
58+ /// Returns the `InitWatermark` based on the existing watermark if it exists.
59+ /// Otherwise, initializes a new watermark record with `InitWatermark` and returns
60+ /// the value passed in.
61+ async fn trailing_init_watermark (
62+ & mut self ,
63+ pipeline_task : & str ,
64+ trailing_init_watermark : TrailingInitWatermark ,
65+ ) -> anyhow:: Result < TrailingInitWatermark > ;
66+
4867 /// Given a pipeline, return the reader watermark from the database. This is used by the indexer
4968 /// to determine the new `reader_lo` or inclusive lower bound of available data.
5069 async fn reader_watermark (
@@ -120,12 +139,18 @@ pub trait TransactionalStore: Store {
120139 & ' r mut Self :: Connection < ' _ > ,
121140 ) -> ScopedBoxFuture < ' a , ' r , anyhow:: Result < R > > ;
122141}
123-
124142/// Used during watermark initialization to set and return state.
125143#[ derive( Default , Debug , Clone , Copy , PartialEq ) ]
126144pub struct InitWatermark {
127145 /// Calculated by the framework as `default_next_checkpoint.checked_sub(1)`.
128146 pub checkpoint_hi_inclusive : Option < u64 > ,
147+ }
148+
149+ /// Used during watermark initialization to set and return state.
150+ #[ derive( Default , Debug , Clone , Copy , PartialEq ) ]
151+ pub struct TrailingInitWatermark {
152+ /// Calculated by the framework as `default_next_checkpoint.checked_sub(1)`.
153+ pub checkpoint_hi_inclusive : Option < u64 > ,
129154 /// Calculated by the framework as `default_next_checkpoint`.
130155 pub reader_lo : u64 ,
131156}
@@ -212,23 +237,6 @@ impl PrunerWatermark {
212237 }
213238}
214239
215- /// A utility function for connections that do not have special initialization logic. These
216- /// connections delegate initialization to `Connection::committer_watermark`.
217- pub async fn init_with_committer_watermark (
218- connection : & mut impl Connection ,
219- pipeline_task : & str ,
220- init_watermark : InitWatermark ,
221- ) -> anyhow:: Result < InitWatermark > {
222- let checkpoint_hi_inclusive = connection
223- . committer_watermark ( pipeline_task)
224- . await ?
225- . map ( |w| w. checkpoint_hi_inclusive ) ;
226- Ok ( InitWatermark {
227- checkpoint_hi_inclusive,
228- ..init_watermark
229- } )
230- }
231-
232240/// Check that the pipeline name does not contain the store's delimiter, and construct the string
233241/// used for tracking a pipeline's watermarks in the store. This is either the pipeline name itself,
234242/// or `{pipeline}{Store::DELIMITER}{task}` if a task name is provided.
0 commit comments