1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::sync::Arc;

use crate::communicator::{CoordNumOf, RoundNumOf};
use crate::node::{NodeStatus, Shutdown, Snapshot};
use crate::state::{EventOf, LogEntryOf, State};
use crate::{CoordNum, RoundNum};

pub type ShutdownEventFor<S> = ShutdownEvent<
    <S as Shutdown>::State,
    RoundNumOf<<S as Shutdown>::Communicator>,
    CoordNumOf<<S as Shutdown>::Communicator>,
>;

/// Emitted by `Node`'s [`poll_events`][crate::Node::poll_events] method.
#[non_exhaustive]
#[derive(Debug)]
pub enum Event<S: State, R: RoundNum> {
    Init {
        status: NodeStatus,
        state: Option<Arc<S>>,
    },

    StatusChange {
        old_status: NodeStatus,
        new_status: NodeStatus,
    },

    /// A snapshot was installed.
    Install { round: R, state: Arc<S> },

    /// An entry has been committed to the log.
    ///
    /// The event does not imply that the entry was applied to the shared state.
    Commit {
        /// The round for which `log_entry` was committed.
        round: R,

        /// The log entry which was committed.
        log_entry: Arc<LogEntryOf<S>>,
    },

    /// The next log entry was applied to the state.
    Apply {
        round: R,
        log_entry: Arc<LogEntryOf<S>>,
        result: EventOf<S>,
    },

    /// A log entry was queued, preceeding entries are still missing.
    ///
    /// Note: This event is emitted even when the queued entry is within the
    /// concurrency bound or if this node created the gap itself. The second
    /// case can arise when the leader tries to concurrently append multiple
    /// entries and abandons some of the earlier appends.
    Gaps(Vec<Gap<R>>),
}

#[derive(Clone, Debug)]
pub struct Gap<R: RoundNum> {
    /// The point in time when the gap appeared.
    pub since: std::time::Instant,

    /// The locations of the gap within the log.
    pub rounds: std::ops::Range<R>,
}

/// Emitted by `Shutdown`'s [`poll_shutdown`][crate::Shutdown::poll_shutdown]
/// method.
#[derive(Debug)]
pub enum ShutdownEvent<S: State, R: RoundNum, C: CoordNum> {
    Regular(Event<S, R>),
    #[non_exhaustive]
    Last {
        snapshot: Option<Snapshot<S, R, C>>,
    },
}