|
1 | 1 | use std::collections::BTreeSet;
|
2 |
| -use std::ops::Range; |
3 | 2 | use std::sync::Arc;
|
4 | 3 |
|
5 | 4 | use maplit::btreeset;
|
6 | 5 |
|
7 | 6 | use crate::core::ServerState;
|
| 7 | +use crate::engine::Command; |
8 | 8 | use crate::entry::RaftEntry;
|
9 | 9 | use crate::error::InitializeError;
|
10 | 10 | use crate::error::NotAMembershipEntry;
|
@@ -52,76 +52,6 @@ pub(crate) struct Engine<NID: NodeId> {
|
52 | 52 | pub(crate) commands: Vec<Command<NID>>,
|
53 | 53 | }
|
54 | 54 |
|
55 |
| -/// Commands to send to `RaftRuntime` to execute, to update the application state. |
56 |
| -#[derive(Debug, Clone, PartialEq, Eq)] |
57 |
| -pub(crate) enum Command<NID: NodeId> { |
58 |
| - // Update server state, e.g., Leader, Follower etc. |
59 |
| - // TODO: consider remove this variant. A runtime does not need to know about this. It is only meant for metrics |
60 |
| - // report. |
61 |
| - UpdateServerState { |
62 |
| - server_state: ServerState, |
63 |
| - }, |
64 |
| - |
65 |
| - // Append a `range` of entries in the input buffer. |
66 |
| - AppendInputEntries { |
67 |
| - range: Range<usize>, |
68 |
| - }, |
69 |
| - |
70 |
| - // Commit entries that are already in the store, upto `upto`, inclusive. |
71 |
| - // And send applied result to the client that proposed the entry. |
72 |
| - Commit { |
73 |
| - upto: LogId<NID>, |
74 |
| - }, |
75 |
| - |
76 |
| - // Replicate a `range` of entries in the input buffer. |
77 |
| - ReplicateInputEntries { |
78 |
| - range: Range<usize>, |
79 |
| - }, |
80 |
| - |
81 |
| - // Membership config changed, need to update replication stream etc. |
82 |
| - UpdateMembership { |
83 |
| - membership: Membership<NID>, |
84 |
| - }, |
85 |
| - |
86 |
| - // Move the cursor pointing to an entry in the input buffer. |
87 |
| - MoveInputCursorBy { |
88 |
| - n: usize, |
89 |
| - }, |
90 |
| - |
91 |
| - // Save vote to storage |
92 |
| - SaveVote { |
93 |
| - vote: Vote<NID>, |
94 |
| - }, |
95 |
| - |
96 |
| - // Send vote to all other members |
97 |
| - SendVote { |
98 |
| - vote_req: VoteRequest<NID>, |
99 |
| - }, |
100 |
| - |
101 |
| - // Install a timer to trigger an election after some `timeout` which is decided by the runtime. |
102 |
| - // An already installed timer should be cleared. |
103 |
| - InstallElectionTimer {}, |
104 |
| - |
105 |
| - // |
106 |
| - // --- Draft unimplemented commands: |
107 |
| - // |
108 |
| - |
109 |
| - // TODO: |
110 |
| - #[allow(dead_code)] |
111 |
| - PurgeAppliedLog { |
112 |
| - upto: LogId<NID>, |
113 |
| - }, |
114 |
| - // TODO: |
115 |
| - #[allow(dead_code)] |
116 |
| - DeleteConflictLog { |
117 |
| - since: LogId<NID>, |
118 |
| - }, |
119 |
| - |
120 |
| - // TODO: |
121 |
| - #[allow(dead_code)] |
122 |
| - BuildSnapshot {}, |
123 |
| -} |
124 |
| - |
125 | 55 | impl<NID: NodeId> Engine<NID> {
|
126 | 56 | pub(crate) fn new(id: NID, init_state: &RaftState<NID>) -> Self {
|
127 | 57 | Self {
|
@@ -347,7 +277,6 @@ impl<NID: NodeId> Engine<NID> {
|
347 | 277 | // // --- raft protocol API ---
|
348 | 278 | //
|
349 | 279 | // //
|
350 |
| - // pub(crate) fn handle_vote() {} |
351 | 280 | // pub(crate) fn handle_append_entries() {}
|
352 | 281 | // pub(crate) fn handle_install_snapshot() {}
|
353 | 282 | //
|
@@ -430,23 +359,7 @@ impl<NID: NodeId> Engine<NID> {
|
430 | 359 | }
|
431 | 360 |
|
432 | 361 | fn push_command(&mut self, cmd: Command<NID>) {
|
433 |
| - // Update flags for metrics that need to update, according to the queued commands. |
434 |
| - let f = &mut self.metrics_flags; |
435 |
| - match &cmd { |
436 |
| - Command::UpdateServerState { .. } => f.set_cluster_changed(), |
437 |
| - Command::AppendInputEntries { .. } => f.set_data_changed(), |
438 |
| - Command::Commit { .. } => f.set_data_changed(), |
439 |
| - Command::ReplicateInputEntries { .. } => {} |
440 |
| - Command::UpdateMembership { .. } => f.set_cluster_changed(), |
441 |
| - Command::MoveInputCursorBy { .. } => {} |
442 |
| - Command::SaveVote { .. } => f.set_data_changed(), |
443 |
| - Command::SendVote { .. } => {} |
444 |
| - Command::InstallElectionTimer { .. } => {} |
445 |
| - Command::PurgeAppliedLog { .. } => f.set_data_changed(), |
446 |
| - Command::DeleteConflictLog { .. } => f.set_data_changed(), |
447 |
| - Command::BuildSnapshot { .. } => f.set_data_changed(), |
448 |
| - } |
449 |
| - |
| 362 | + cmd.update_metrics_flags(&mut self.metrics_flags); |
450 | 363 | self.commands.push(cmd)
|
451 | 364 | }
|
452 | 365 | }
|
0 commit comments