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
77
78
79
80
//! Client API wire types sent over `/client/wire` (client-api, client-routing, read-consistency).
use serde::{Deserialize, Serialize};
use crate::{LogIndex, NodeId, Term};
/// A request from a client to the cluster.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ClientRequest {
/// A write: application-encoded command replicated through the Raft log.
Propose(Vec<u8>),
/// A linearizable read: application-encoded query answered via `ReadIndex`.
Query(Vec<u8>),
/// A write routed to the Raft group owning `key` (multi-Raft, write-sharding-multi-raft).
ProposeKeyed {
/// Shard routing key (typically the same key the command mutates).
key: Vec<u8>,
/// Application-encoded command body.
command: Vec<u8>,
},
/// A linearizable read routed to the Raft group owning `key`.
QueryKeyed {
/// Shard routing key.
key: Vec<u8>,
/// Application-encoded query body.
query: Vec<u8>,
},
/// Ask the leader to confirm a linearizable read index without executing a
/// query (etcd-style follower read setup, read-consistency).
ReadIndexConfirm {
/// Shard routing key for multi-Raft; `None` targets group 0.
route_key: Option<Vec<u8>>,
},
/// Stage a command in leader memory for cross-shard 2PC (optional Tier 2).
TwoPhasePrepare {
/// Shared transaction id.
tx_id: Vec<u8>,
/// Shard routing key.
key: Vec<u8>,
/// Application-encoded command to commit later.
command: Vec<u8>,
},
/// Commit a previously prepared command through the normal Raft log.
TwoPhaseCommit {
/// Shared transaction id.
tx_id: Vec<u8>,
/// Shard routing key.
key: Vec<u8>,
},
/// Drop a previously prepared command without committing.
TwoPhaseAbort {
/// Shared transaction id.
tx_id: Vec<u8>,
/// Shard routing key.
key: Vec<u8>,
},
}
/// The cluster's response to a [`ClientRequest`].
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ClientResponse {
/// Success with an application-encoded result body.
Ok(Vec<u8>),
/// `ReadIndex` confirmed at `index` in `term` (response to
/// [`ClientRequest::ReadIndexConfirm`]).
ReadIndexConfirmed {
/// The linearizable read barrier index.
index: LogIndex,
/// The leader term that confirmed the read.
term: Term,
},
/// The contacted node is not the leader (transparent forward usually
/// hides this; the hint aids clients that route themselves).
NotLeader {
/// Best-known current leader, if any.
leader: Option<NodeId>,
},
/// A processing error, human-readable.
Error(String),
}