Trait lol_core::RaftApp

source ·
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§

Process read request. This operation should not change the state of the application.

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.

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.

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.

Make a snapshot resource from an in-coming SnapshotStream.

Open a SnapshotStream from a snapshot resource.

Delete a snapshot resource.

Implementors§