Procházet zdrojové kódy

Provide a default NO_SNAPSHOT function.

Jing Yang před 5 roky
rodič
revize
072964f8a4
3 změnil soubory, kde provedl 10 přidání a 10 odebrání
  1. 7 0
      src/lib.rs
  2. 1 5
      src/rpcs.rs
  3. 2 5
      tests/config/mod.rs

+ 7 - 0
src/lib.rs

@@ -962,3 +962,10 @@ impl ElectionState {
         self.signal.notify_one();
     }
 }
+
+impl<C> Raft<C> {
+    pub const NO_SNAPSHOT: fn(Index) -> Snapshot = |index| Snapshot {
+        last_included_index: index,
+        data: vec![],
+    };
+}

+ 1 - 5
src/rpcs.rs

@@ -165,7 +165,6 @@ mod tests {
     use crate::{Peer, Term};
 
     use super::*;
-    use crate::snapshot::Snapshot;
 
     type DoNothingPersister = ();
     impl crate::Persister for DoNothingPersister {
@@ -198,10 +197,7 @@ mod tests {
                 Arc::new(()),
                 |_, _: i32| {},
                 None,
-                |index| Snapshot {
-                    last_included_index: index,
-                    data: vec![],
-                },
+                Raft::<i32>::NO_SNAPSHOT,
             ));
             register_server(raft, name, network.as_ref())?;
 

+ 2 - 5
tests/config/mod.rs

@@ -8,7 +8,7 @@ use rand::{thread_rng, Rng};
 use tokio::time::Duration;
 
 use ruaft::rpcs::register_server;
-use ruaft::{Persister, Raft, RpcClient, Snapshot};
+use ruaft::{Persister, Raft, RpcClient};
 
 pub mod persister;
 
@@ -315,10 +315,7 @@ impl Config {
                 Self::apply_command(log_clone.clone(), index, cmd_index, cmd)
             },
             None,
-            |index| Snapshot {
-                last_included_index: index,
-                data: vec![],
-            },
+            Raft::<i32>::NO_SNAPSHOT,
         );
         self.state.lock().rafts[index].replace(raft.clone());