Diffinery

homeflare/celldpublic

64 lines · 2.1 KBRaw History
1//! client — the `ReplicaClient` trait.
2//!
3//! Ported from [email protected] `replica_client.go`. The trait is the storage
4//! abstraction that every backend implements.
5//!
6//! # Buffered I/O
7//! Go's `ReplicaClient` uses `io.Reader`/`io.ReadCloser`. We take/return owned
8//! byte buffers (`&[u8]` / `Vec<u8>`) instead. L0 files are bounded in size;
9//! large snapshots remain buffered.
10
11use crate::error::Result;
12use crate::ltx::FileInfo;
13use crate::TXID;
14use async_trait::async_trait;
15
16pub mod bundle;
17pub mod file;
18pub mod object_store;
19
20/// Client for reading and writing LTX files on a replica backend.
21///
22/// Ported from the `ReplicaClient` interface (replica_client.go:19-51). Methods
23/// take a compaction `level` (0 = L0, the only level in the one-shot scope).
24#[async_trait]
25pub trait ReplicaClient: Send + Sync {
26 /// Returns all LTX files for `level`, sorted ascending by `min_txid`, that
27 /// start at or after `seek`.
28 async fn ltx_files(&self, level: i32, seek: TXID) -> Result<Vec<FileInfo>>;
29
30 /// Returns at most `limit` LTX files at or after `seek`.
31 ///
32 /// Remote clients can stop their object listing after they collect the
33 /// requested prefix. The default keeps compatibility with local and custom
34 /// clients.
35 async fn ltx_files_bounded(
36 &self,
37 level: i32,
38 seek: TXID,
39 limit: usize,
40 ) -> Result<Vec<FileInfo>> {
41 let mut files = self.ltx_files(level, seek).await?;
42 files.truncate(limit);
43 Ok(files)
44 }
45
46 /// Reads an LTX file. Returns an `io::ErrorKind::NotFound` error (wrapped)
47 /// if the file does not exist.
48 async fn open_ltx_file(&self, level: i32, min_txid: TXID, max_txid: TXID) -> Result<Vec<u8>>;
49
50 /// Writes an LTX file to the replica and returns its metadata.
51 async fn write_ltx_file(
52 &self,
53 level: i32,
54 min_txid: TXID,
55 max_txid: TXID,
56 data: &[u8],
57 ) -> Result<FileInfo>;
58
59 /// Deletes the given LTX files.
60 async fn delete_ltx_files(&self, files: &[FileInfo]) -> Result<()>;
61
62 /// Deletes all files on the replica.
63 async fn delete_all(&self) -> Result<()>;
64}