pub trait RaftApp: Sync + Send + 'static {
fn process_read<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn process_write<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 [u8],
entry_index: Index
) -> Pin<Box<dyn Future<Output = Result<(Vec<u8>, MakeSnapshot)>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn install_snapshot<'life0, 'async_trait>(
&'life0 self,
snapshot: Option<Index>
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait;
fn fold_snapshot<'life0, 'life1, 'async_trait>(
&'life0 self,
old_snapshot: Option<Index>,
requests: Vec<&'life1 [u8]>,
snapshot_index: Index
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn save_snapshot<'life0, 'async_trait>(
&'life0 self,
st: SnapshotStream,
snapshot_index: Index
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait;
fn open_snapshot<'life0, 'async_trait>(
&'life0 self,
x: Index
) -> Pin<Box<dyn Future<Output = Result<SnapshotStream>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait;
fn delete_snapshot<'life0, 'async_trait>(
&'life0 self,
x: Index
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where
Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
The abstraction of user-defined application.
Note about the error handling: In Raft, the great rule is the same log should result in the same state. This means the application of a log entry should result in the same state and it is not allowed the same entry succeeds in some node and fails in another node. Therefore function that may change the state (e.g. process_write) should not fail if there is any chance that other node succeeds the same entry.
Required Methods§
sourcefn process_read<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn process_read<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Process read request. This operation should not change the state of the application.
sourcefn process_write<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 [u8],
entry_index: Index
) -> Pin<Box<dyn Future<Output = Result<(Vec<u8>, MakeSnapshot)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn process_write<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 [u8],
entry_index: Index
) -> Pin<Box<dyn Future<Output = Result<(Vec<u8>, MakeSnapshot)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Process write request. This may change the state of the application.
This function may return MakeSnapshot
to make a new snapshot.
The snapshot entry corresponding to the copy snapshot is not guaranteed to be made
due to possible I/O errors, etc.
sourcefn install_snapshot<'life0, 'async_trait>(
&'life0 self,
snapshot: Option<Index>
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn install_snapshot<'life0, 'async_trait>(
&'life0 self,
snapshot: Option<Index>
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Special type of process_write but when the entry is a snapshot entry. Snapshot is None when apply_index is 1 which is the most youngest snapshot.
sourcefn fold_snapshot<'life0, 'life1, 'async_trait>(
&'life0 self,
old_snapshot: Option<Index>,
requests: Vec<&'life1 [u8]>,
snapshot_index: Index
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn fold_snapshot<'life0, 'life1, 'async_trait>(
&'life0 self,
old_snapshot: Option<Index>,
requests: Vec<&'life1 [u8]>,
snapshot_index: Index
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
This function is called from the compaction thread. It should return new snapshot from accumulative computation with the old_snapshot and the subsequent log entries.
sourcefn save_snapshot<'life0, 'async_trait>(
&'life0 self,
st: SnapshotStream,
snapshot_index: Index
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn save_snapshot<'life0, 'async_trait>(
&'life0 self,
st: SnapshotStream,
snapshot_index: Index
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Make a snapshot resource from an in-coming SnapshotStream
.
sourcefn open_snapshot<'life0, 'async_trait>(
&'life0 self,
x: Index
) -> Pin<Box<dyn Future<Output = Result<SnapshotStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn open_snapshot<'life0, 'async_trait>(
&'life0 self,
x: Index
) -> Pin<Box<dyn Future<Output = Result<SnapshotStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Open a SnapshotStream
from a snapshot resource.