exoware_server/engine.rs
1//! Storage callbacks for the store services.
2//!
3//! Implement this trait for your backend. Errors are surfaced to clients as internal RPC failures
4//! (string message only; keep messages safe to expose if you rely on that).
5
6use bytes::Bytes;
7
8/// Implement these operations for your store. All methods must be thread-safe.
9pub trait StoreEngine: Send + Sync + 'static {
10 /// Persist key-value pairs atomically and return the new global sequence number for this write.
11 fn put_batch(&self, kvs: &[(Bytes, Bytes)]) -> Result<u64, String>;
12
13 /// Fetch the value for a single key. Returns `None` when the key does not exist.
14 fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, String>;
15
16 /// Keys in `[start, end]` (inclusive) when `end` is non-empty; empty `end` means unbounded
17 /// above. Matches `store.query.v1.RangeRequest` / `ReduceRequest` on the wire. `limit` caps
18 /// rows returned.
19 fn range_scan(
20 &self,
21 start: &[u8],
22 end: &[u8],
23 limit: usize,
24 forward: bool,
25 ) -> Result<Vec<(Bytes, Bytes)>, String>;
26
27 /// Batch-get: returns `(key, Option<value>)` for each input key, preserving order.
28 fn get_many(&self, keys: &[&[u8]]) -> Result<Vec<(Vec<u8>, Option<Vec<u8>>)>, String> {
29 keys.iter()
30 .map(|k| Ok((k.to_vec(), self.get(k)?)))
31 .collect()
32 }
33
34 /// Delete a batch of keys atomically. Returns the new global sequence number.
35 fn delete_batch(&self, keys: &[&[u8]]) -> Result<u64, String>;
36
37 /// Current sequence number visible to readers (used for `min_sequence_number` checks).
38 fn current_sequence(&self) -> u64;
39
40 /// Return the (key, value) pairs written by the `put_batch` call that was
41 /// assigned `sequence_number`. `Ok(None)` = the batch has been pruned or
42 /// was never written (the store.stream.v1 service maps `None` to NOT_FOUND
43 /// with a `BATCH_EVICTED` detail).
44 ///
45 /// Engines that don't retain a batch log return `Ok(None)` unconditionally,
46 /// which disables `GetBatch` and since-cursored `Subscribe` for that
47 /// deployment.
48 fn get_batch(&self, sequence_number: u64) -> Result<Option<Vec<(Bytes, Bytes)>>, String>;
49
50 /// Lowest retained batch sequence number, or `None` when the batch log is
51 /// empty. Surfaced in `BATCH_EVICTED` error details so clients know where
52 /// to resume from.
53 fn oldest_retained_batch(&self) -> Result<Option<u64>, String>;
54
55 /// Delete all batch-log entries with `sequence_number < cutoff_exclusive`.
56 /// Returns the number of entries deleted. Invoked only by the compact
57 /// service's batch-log policy scope — never by ingest.
58 fn prune_batch_log(&self, cutoff_exclusive: u64) -> Result<u64, String>;
59}