feldera_storage/checkpoint_synchronizer.rs
1use std::sync::{Arc, LazyLock};
2
3use feldera_types::{
4 checkpoint::{CheckpointMetadata, CheckpointSyncMetrics, HostInfo, RemoteCheckpoint},
5 config::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 fn push(
18 &self,
19 checkpoint: uuid::Uuid,
20 storage: Arc<dyn StorageBackend>,
21 remote_config: SyncConfig,
22 host_info: Option<HostInfo>,
23 ) -> anyhow::Result<Option<CheckpointSyncMetrics>>;
24
25 /// Pull a checkpoint from remote object storage.
26 ///
27 /// `host_info` scopes the pull to the correct `host{N}/` subdirectory.
28 /// Pass `None` for solo pipelines to use the existing flat layout.
29 ///
30 /// `standby` indicates that the pipeline is in standby mode: the
31 /// local-storage cache is bypassed (always pull from remote) and a missing
32 /// remote checkpoint is treated as an error rather than a fresh start.
33 fn pull(
34 &self,
35 storage: Arc<dyn StorageBackend>,
36 remote_config: SyncConfig,
37 host_info: Option<HostInfo>,
38 standby: bool,
39 ) -> anyhow::Result<(CheckpointMetadata, Option<CheckpointSyncMetrics>)>;
40
41 /// List checkpoints available in remote object storage.
42 fn list_remote(&self, remote_config: SyncConfig) -> anyhow::Result<Vec<RemoteCheckpoint>>;
43}
44
45inventory::collect!(&'static dyn CheckpointSynchronizer);
46
47/// Lazily resolves the checkpoint synchronizer.
48///
49/// This panic is safe as all enterprise builds must include the checkpoint-sync
50/// crate.
51pub static SYNCHRONIZER: LazyLock<&'static dyn CheckpointSynchronizer> = LazyLock::new(|| {
52 *inventory::iter::<&dyn CheckpointSynchronizer>
53 .into_iter()
54 .next()
55 .expect("no checkpoint synchronizer found; are enterprise features enabled?")
56});