store_api/manifest/
storage.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use async_trait::async_trait;
16use common_error::ext::ErrorExt;
17
18use crate::manifest::ManifestVersion;
19
20#[async_trait]
21pub trait LogIterator: Send + Sync {
22    type Error: ErrorExt + Send + Sync;
23
24    async fn next_log(&mut self) -> Result<Option<(ManifestVersion, Vec<u8>)>, Self::Error>;
25}
26
27#[async_trait]
28pub trait ManifestLogStorage {
29    type Error: ErrorExt + Send + Sync;
30    type Iter: LogIterator<Error = Self::Error>;
31
32    /// Scan the logs in [start, end)
33    async fn scan(
34        &self,
35        start: ManifestVersion,
36        end: ManifestVersion,
37    ) -> Result<Self::Iter, Self::Error>;
38
39    /// Delete logs and checkpoints which version is less than specified `end`.
40    /// Keep the last checkpoint and remaining logs if `keep_last_checkpoint` is true.
41    ///
42    /// Returns the delete logs number.
43    async fn delete_until(
44        &self,
45        end: ManifestVersion,
46        keep_last_checkpoint: bool,
47    ) -> Result<usize, Self::Error>;
48
49    /// Delete all logs and checkpoints, and remove the manifest directory.
50    /// The delta file corresponding to the `remove_action_version` will be deleted along with the manifest directory at the end.
51    async fn delete_all(&self, remove_action_version: ManifestVersion) -> Result<(), Self::Error>;
52
53    /// Save a log
54    async fn save(&self, version: ManifestVersion, bytes: &[u8]) -> Result<(), Self::Error>;
55
56    /// Delete logs in [start, end) and ignore checkpoints.
57    async fn delete(&self, start: ManifestVersion, end: ManifestVersion)
58        -> Result<(), Self::Error>;
59
60    /// Save a checkpoint.
61    async fn save_checkpoint(
62        &self,
63        version: ManifestVersion,
64        bytes: &[u8],
65    ) -> Result<(), Self::Error>;
66
67    /// Load the latest checkpoint
68    async fn load_last_checkpoint(&self)
69        -> Result<Option<(ManifestVersion, Vec<u8>)>, Self::Error>;
70    /// Delete the checkpoint by version
71    async fn delete_checkpoint(&self, version: ManifestVersion) -> Result<(), Self::Error>;
72
73    /// Load the checkpoint by version
74    async fn load_checkpoint(
75        &self,
76        version: ManifestVersion,
77    ) -> Result<Option<(ManifestVersion, Vec<u8>)>, Self::Error>;
78}