use core::fmt;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum NodeState {
Idle,
Connecting,
EstablishingGroup,
Active,
Resyncing,
Failed,
Closed,
}
impl NodeState {
pub fn can_transition_to(self, next: NodeState) -> bool {
use NodeState::*;
matches!(
(self, next),
(Idle, Connecting)
| (Idle, Failed)
| (Connecting, EstablishingGroup)
| (Connecting, Failed)
| (EstablishingGroup, Active)
| (EstablishingGroup, Failed)
| (Active, Resyncing)
| (Active, Closed)
| (Active, Failed)
| (Resyncing, Active)
| (Resyncing, Failed)
| (_, Closed)
)
}
}
impl fmt::Display for NodeState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Idle => "IDLE",
Self::Connecting => "CONNECTING",
Self::EstablishingGroup => "ESTABLISHING_GROUP",
Self::Active => "ACTIVE",
Self::Resyncing => "RESYNCING",
Self::Failed => "FAILED",
Self::Closed => "CLOSED",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum TransitionState {
TIdle,
TPrepared,
TCommitProcessed,
TReady,
TExecuted,
TAborted,
}
impl TransitionState {
pub fn can_transition_to(self, next: TransitionState) -> bool {
use TransitionState::*;
matches!(
(self, next),
(TIdle, TPrepared)
| (TPrepared, TCommitProcessed)
| (TPrepared, TAborted)
| (TCommitProcessed, TReady)
| (TCommitProcessed, TAborted)
| (TReady, TExecuted)
| (TReady, TAborted)
| (TExecuted, TIdle)
| (TAborted, TIdle)
)
}
}
pub mod timeouts {
pub const T_PREPARE_MAX_MS: u64 = 5_000;
pub const T_READY_MAX_MS: u64 = 5_000;
pub const T_EXECUTE_MAX_MS: u64 = 10_000;
pub const T_QUORUM_GRACE_MS: u64 = 2_000;
pub const T_COORDINATOR_GRACE_MS: u64 = 10_000;
pub const T_GAP_KEY_OVERLAP_MS: u64 = 10_000;
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum SubprotocolState {
Disabled,
Negotiating,
Enabled,
Degraded,
Suspended,
}