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
use crate::RaftTypeConfig;
use crate::TryAsRef;
use crate::errors::ForwardToLeader;
use crate::errors::QuorumNotEnough;
/// An error that keeps a node from serving a linearizable read.
///
/// [`Raft::ensure_linearizable()`], [`Raft::get_read_log_id()`], [`Raft::get_read_linearizer()`]
/// and [`Raft::get_local_read_linearizer()`] return it.
///
/// [`Raft::ensure_linearizable()`]: crate::Raft::ensure_linearizable
/// [`Raft::get_read_log_id()`]: crate::Raft::get_read_log_id
/// [`Raft::get_read_linearizer()`]: crate::Raft::get_read_linearizer
/// [`Raft::get_local_read_linearizer()`]: crate::Raft::get_local_read_linearizer
#[derive(Debug, Clone, thiserror::Error, derive_more::TryInto)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize), serde(bound = ""))]
pub enum LinearizableReadError<C>
where C: RaftTypeConfig
{
/// This node cannot serve the read; send it to the node the error names.
///
/// The node is not the leader, or it is a leader that is transferring its leadership.
/// [`ForwardToLeader::reason`] tells which; during a transfer, the named node may not be the
/// leader yet.
#[error(transparent)]
ForwardToLeader(#[from] ForwardToLeader<C>),
/// The leader has not heard from a write quorum recently enough to serve the read.
///
/// It is returned at once when the wait that the [`LinearizerOption`] allows is zero, and
/// otherwise when that wait ends. The peers may still be reachable: once a quorum acknowledges
/// a later heartbeat, a read can succeed.
///
/// [`LinearizerOption`]: crate::LinearizerOption
#[error(transparent)]
QuorumNotEnough(#[from] QuorumNotEnough<C>),
}
impl<C> TryAsRef<ForwardToLeader<C>> for LinearizableReadError<C>
where C: RaftTypeConfig
{
fn try_as_ref(&self) -> Option<&ForwardToLeader<C>> {
match self {
Self::ForwardToLeader(f) => Some(f),
_ => None,
}
}
}