mkit_server/relay/
hook.rs1use crate::rt::{BoxFuture, MaybeSend, MaybeSync};
4use crate::store::{Key, Partition, Precondition, StoreError, Value, Write, codec::RelayV1};
5
6pub(crate) const AUDIT_CAPACITY: &str = "automatic audit combined batch capacity";
7
8pub trait RelayHook: MaybeSend + MaybeSync {
13 fn read_keys(
16 &self,
17 _target: &Partition,
18 _rows: &[(u64, RelayV1)],
19 ) -> Result<Vec<Key>, StoreError> {
20 Ok(Vec::new())
21 }
22
23 fn before_apply_observed<'a>(
26 &'a self,
27 target: &'a Partition,
28 rows: &'a [(u64, RelayV1)],
29 _observed: &'a [(Key, Option<Value>)],
30 pre: &'a mut Vec<Precondition>,
31 writes: &'a mut Vec<Write>,
32 ) -> BoxFuture<'a, Result<(), StoreError>> {
33 self.before_apply(target, rows, pre, writes)
34 }
35
36 fn reserved_ops(&self, _target: &Partition, _rows: &[(u64, RelayV1)]) -> usize {
39 0
40 }
41
42 fn before_apply<'a>(
44 &'a self,
45 target: &'a Partition,
46 rows: &'a [(u64, RelayV1)],
47 pre: &'a mut Vec<Precondition>,
48 writes: &'a mut Vec<Write>,
49 ) -> BoxFuture<'a, Result<(), StoreError>>;
50}
51
52#[derive(Debug, Default, Clone, Copy)]
54pub struct NoHook;
55impl RelayHook for NoHook {
56 fn before_apply<'a>(
57 &'a self,
58 _target: &'a Partition,
59 _rows: &'a [(u64, RelayV1)],
60 _pre: &'a mut Vec<Precondition>,
61 _writes: &'a mut Vec<Write>,
62 ) -> BoxFuture<'a, Result<(), StoreError>> {
63 Box::pin(async { Ok(()) })
64 }
65}