do_nothing.rs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #![cfg(feature = "integration-test")]
  2. use async_trait::async_trait;
  3. use crate::storage::{
  4. RaftLogEntryRef, RaftStorageMonitorTrait, RaftStoragePersisterTrait,
  5. RaftStorageTrait, RaftStoredState,
  6. };
  7. use crate::{
  8. AppendEntriesArgs, AppendEntriesReply, Index, InstallSnapshotArgs,
  9. InstallSnapshotReply, RemoteRaft, RequestVoteArgs, RequestVoteReply, Term,
  10. };
  11. #[derive(Clone)]
  12. pub struct DoNothingRemoteRaft;
  13. #[async_trait]
  14. impl<Command: 'static + Send> RemoteRaft<Command> for DoNothingRemoteRaft {
  15. async fn request_vote(
  16. &self,
  17. _args: RequestVoteArgs,
  18. ) -> std::io::Result<RequestVoteReply> {
  19. unimplemented!()
  20. }
  21. async fn append_entries(
  22. &self,
  23. _args: AppendEntriesArgs<Command>,
  24. ) -> std::io::Result<AppendEntriesReply> {
  25. unimplemented!()
  26. }
  27. async fn install_snapshot(
  28. &self,
  29. _args: InstallSnapshotArgs,
  30. ) -> std::io::Result<InstallSnapshotReply> {
  31. unimplemented!()
  32. }
  33. }
  34. pub struct DoNothingRaftStorage;
  35. impl RaftStorageTrait for DoNothingRaftStorage {
  36. type RaftStoragePersister<LogEntry: RaftLogEntryRef> =
  37. DoNothingRaftStoragePersister;
  38. type RaftStorageMonitor = DoNothingRaftStorageMonitor;
  39. fn persister<LogEntry>(
  40. self,
  41. ) -> std::sync::Arc<DoNothingRaftStoragePersister>
  42. where
  43. LogEntry: RaftLogEntryRef,
  44. {
  45. std::sync::Arc::new(DoNothingRaftStoragePersister)
  46. }
  47. fn read_state(&self) -> std::io::Result<RaftStoredState> {
  48. Ok(RaftStoredState {
  49. current_term: Term(0),
  50. voted_for: "".to_string(),
  51. log: vec![],
  52. snapshot_index: 0,
  53. snapshot_term: Term(0),
  54. snapshot: vec![],
  55. })
  56. }
  57. fn log_compaction_required(&self) -> bool {
  58. false
  59. }
  60. fn monitor(&self) -> DoNothingRaftStorageMonitor {
  61. DoNothingRaftStorageMonitor
  62. }
  63. }
  64. pub struct DoNothingRaftStorageMonitor;
  65. impl RaftStorageMonitorTrait for DoNothingRaftStorageMonitor {
  66. fn should_compact_log_now(&self) -> bool {
  67. return false;
  68. }
  69. }
  70. pub struct DoNothingRaftStoragePersister;
  71. impl<LogEntry: RaftLogEntryRef> RaftStoragePersisterTrait<LogEntry>
  72. for DoNothingRaftStoragePersister
  73. {
  74. fn save_term_vote(&self, _term: Term, _voted_for: String) {}
  75. fn append_one_entry(&self, _entry: &LogEntry) {}
  76. fn append_entries<'a, LogEntryList>(&self, _entries: LogEntryList)
  77. where
  78. LogEntry: 'a,
  79. LogEntryList: IntoIterator<Item = &'a LogEntry>,
  80. {
  81. }
  82. fn update_snapshot(&self, _index: Index, _term: Term, _snapshot: &[u8]) {}
  83. }