d_engine_proto/exts/
cluster_ext.rs1use crate::common::NodeStatus;
2use crate::server::cluster::ClusterConfUpdateResponse;
3use crate::server::cluster::cluster_conf_update_response::ErrorCode;
4
5impl ClusterConfUpdateResponse {
6 pub fn success(
8 node_id: u32,
9 term: u64,
10 version: u64,
11 ) -> Self {
12 Self {
13 id: node_id,
14 term,
15 version,
16 success: true,
17 error_code: ErrorCode::None.into(),
18 }
19 }
20
21 pub fn higher_term(
23 node_id: u32,
24 term: u64,
25 version: u64,
26 ) -> Self {
27 Self {
28 id: node_id,
29 term,
30 version,
31 success: false,
32 error_code: ErrorCode::TermOutdated.into(),
33 }
34 }
35
36 pub fn not_leader(
38 node_id: u32,
39 term: u64,
40 version: u64,
41 ) -> Self {
42 Self {
43 id: node_id,
44 term,
45 version,
46 success: false,
47 error_code: ErrorCode::NotLeader.into(),
48 }
49 }
50
51 pub fn version_conflict(
53 node_id: u32,
54 term: u64,
55 version: u64,
56 ) -> Self {
57 Self {
58 id: node_id,
59 term,
60 version,
61 success: false,
62 error_code: ErrorCode::VersionConflict.into(),
63 }
64 }
65
66 #[allow(unused)]
68 pub fn invalid_change(
69 node_id: u32,
70 term: u64,
71 version: u64,
72 ) -> Self {
73 Self {
74 id: node_id,
75 term,
76 version,
77 success: false,
78 error_code: ErrorCode::InvalidChange.into(),
79 }
80 }
81
82 pub fn internal_error(
84 node_id: u32,
85 term: u64,
86 version: u64,
87 ) -> Self {
88 Self {
89 id: node_id,
90 term,
91 version,
92 success: false,
93 error_code: ErrorCode::InternalError.into(),
94 }
95 }
96
97 #[allow(unused)]
98 pub fn is_higher_term(&self) -> bool {
99 self.error_code == <ErrorCode as Into<i32>>::into(ErrorCode::TermOutdated)
100 }
101}
102
103impl NodeStatus {
104 pub fn is_promotable(&self) -> bool {
105 matches!(self, NodeStatus::Promotable)
106 }
107
108 pub fn is_i32_promotable(value: i32) -> bool {
109 matches!(value, v if v == (NodeStatus::Promotable as i32))
110 }
111}