1pub mod action;
17mod storage;
18
19use async_trait::async_trait;
20use common_error::ext::ErrorExt;
21use serde::de::DeserializeOwned;
22use serde::Serialize;
23
24use crate::manifest::action::{ProtocolAction, ProtocolVersion};
25pub use crate::manifest::storage::*;
26
27pub type ManifestVersion = u64;
28pub const MIN_VERSION: u64 = 0;
29pub const MAX_VERSION: u64 = u64::MAX;
30
31pub trait MetaAction: Serialize + DeserializeOwned + Send + Sync + Clone + std::fmt::Debug {
33 type Error: ErrorExt + Send + Sync;
34
35 fn set_protocol(&mut self, action: ProtocolAction);
37
38 fn set_prev_version(&mut self, version: ManifestVersion);
40
41 fn encode(&self) -> Result<Vec<u8>, Self::Error>;
43
44 fn decode(
47 bs: &[u8],
48 reader_version: ProtocolVersion,
49 ) -> Result<(Self, Option<ProtocolAction>), Self::Error>;
50}
51pub trait Checkpoint: Send + Sync + Clone + std::fmt::Debug {
53 type Error: ErrorExt + Send + Sync;
54
55 fn set_protocol(&mut self, action: ProtocolAction);
57
58 fn last_version(&self) -> ManifestVersion;
60
61 fn encode(&self) -> Result<Vec<u8>, Self::Error>;
63
64 fn decode(bs: &[u8], reader_version: ProtocolVersion) -> Result<Self, Self::Error>;
67}
68
69#[async_trait]
70pub trait MetaActionIterator {
71 type MetaAction: MetaAction;
72 type Error: ErrorExt + Send + Sync;
73
74 async fn next_action(
75 &mut self,
76 ) -> Result<Option<(ManifestVersion, Self::MetaAction)>, Self::Error>;
77}
78
79#[async_trait]
81pub trait Manifest: Send + Sync + Clone + 'static {
82 type Error: ErrorExt + Send + Sync;
83 type MetaAction: MetaAction;
84 type MetaActionIterator: MetaActionIterator<Error = Self::Error, MetaAction = Self::MetaAction>;
85 type Checkpoint: Checkpoint;
86
87 async fn update(&self, action: Self::MetaAction) -> Result<ManifestVersion, Self::Error>;
89
90 async fn scan(
92 &self,
93 start: ManifestVersion,
94 end: ManifestVersion,
95 ) -> Result<Self::MetaActionIterator, Self::Error>;
96
97 async fn do_checkpoint(&self) -> Result<Option<Self::Checkpoint>, Self::Error>;
99
100 async fn last_checkpoint(&self) -> Result<Option<Self::Checkpoint>, Self::Error>;
102
103 fn last_version(&self) -> ManifestVersion;
105
106 async fn start(&self) -> Result<(), Self::Error> {
108 Ok(())
109 }
110 async fn stop(&self) -> Result<(), Self::Error> {
112 Ok(())
113 }
114}