Skip to main content

feldera_storage/
checkpoint_synchronizer.rs

1use std::sync::{Arc, LazyLock};
2
3use feldera_types::{
4    checkpoint::{CheckpointMetadata, CheckpointSyncMetrics, HostInfo, RemoteCheckpoint},
5    config::{PipelineIdentity, SyncConfig},
6};
7
8use crate::StorageBackend;
9
10pub trait CheckpointSynchronizer: Sync {
11    /// Push a checkpoint to remote object storage.
12    ///
13    /// `host_info` identifies the calling host within a multihost pipeline.
14    /// When `Some`, the checkpoint zip and catalog are written under
15    /// `host{N}/` in the remote bucket; when `None` (solo pipeline), the
16    /// existing flat layout is used for backward compatibility.
17    ///
18    /// `pipeline` identifies the pipeline performing the push and is used to
19    /// enforce bucket ownership: the push fails before writing any data if the
20    /// bucket is already owned by a different pipeline.
21    fn push(
22        &self,
23        checkpoint: uuid::Uuid,
24        storage: Arc<dyn StorageBackend>,
25        remote_config: SyncConfig,
26        host_info: Option<HostInfo>,
27        pipeline: PipelineIdentity,
28    ) -> anyhow::Result<Option<CheckpointSyncMetrics>>;
29
30    /// Pull a checkpoint from remote object storage.
31    ///
32    /// `host_info` scopes the pull to the correct `host{N}/` subdirectory.
33    /// Pass `None` for solo pipelines to use the existing flat layout.
34    ///
35    /// `standby` indicates that the pipeline is in standby mode: the
36    /// local-storage cache is bypassed (always pull from remote) and a missing
37    /// remote checkpoint is treated as an error rather than a fresh start.
38    ///
39    /// `pipeline` identifies the pipeline performing the pull. It is used only
40    /// to warn (never fail) when pulling from a bucket owned by a different
41    /// pipeline.
42    fn pull(
43        &self,
44        storage: Arc<dyn StorageBackend>,
45        remote_config: SyncConfig,
46        host_info: Option<HostInfo>,
47        standby: bool,
48        pipeline: PipelineIdentity,
49    ) -> anyhow::Result<(CheckpointMetadata, Option<CheckpointSyncMetrics>)>;
50
51    /// List checkpoints available in remote object storage.
52    fn list_remote(&self, remote_config: SyncConfig) -> anyhow::Result<Vec<RemoteCheckpoint>>;
53}
54
55inventory::collect!(&'static dyn CheckpointSynchronizer);
56
57/// Lazily resolves the checkpoint synchronizer.
58///
59/// This panic is safe as all enterprise builds must include the checkpoint-sync
60/// crate.
61pub static SYNCHRONIZER: LazyLock<&'static dyn CheckpointSynchronizer> = LazyLock::new(|| {
62    *inventory::iter::<&dyn CheckpointSynchronizer>
63        .into_iter()
64        .next()
65        .expect("no checkpoint synchronizer found; are enterprise features enabled?")
66});