Jelajahi Sumber

Move snapshot.rs to using the new standalone daemon_watch.

Jing Yang 3 tahun lalu
induk
melakukan
24715e57e3
2 mengubah file dengan 11 tambahan dan 6 penghapusan
  1. 4 1
      src/raft.rs
  2. 7 5
      src/snapshot.rs

+ 4 - 1
src/raft.rs

@@ -130,7 +130,10 @@ impl<Command: ReplicableCommand> Raft<Command> {
         // Running in a standalone thread.
         this.run_verify_authority_daemon();
         // Running in a standalone thread.
-        this.run_snapshot_daemon(max_state_size_bytes, request_snapshot);
+        daemon_watch.create_daemon(
+            Daemon::Snapshot,
+            this.run_snapshot_daemon(max_state_size_bytes, request_snapshot),
+        );
         // Running in a standalone thread.
         daemon_watch.create_daemon(
             Daemon::SyncLogEntries,

+ 7 - 5
src/snapshot.rs

@@ -6,7 +6,6 @@ use parking_lot::{Condvar, Mutex};
 
 use crate::check_or_record;
 use crate::daemon_env::ErrorKind;
-use crate::daemon_watch::Daemon;
 use crate::{Index, Raft};
 
 #[derive(Clone, Debug, Default)]
@@ -128,10 +127,10 @@ impl<C: 'static + Clone + Send + serde::Serialize> Raft<C> {
         &mut self,
         max_state_size: Option<usize>,
         mut request_snapshot: impl RequestSnapshotFnMut,
-    ) {
+    ) -> impl FnOnce() {
         let max_state_size = match max_state_size {
             Some(max_state_size) => max_state_size,
-            None => return,
+            None => usize::MAX,
         };
 
         let parker = Parker::new();
@@ -218,7 +217,10 @@ impl<C: 'static + Clone + Send + serde::Serialize> Raft<C> {
                 );
             }
         };
-        self.daemon_watch
-            .create_daemon(Daemon::Snapshot, snapshot_daemon);
+        move || {
+            if max_state_size != usize::MAX {
+                snapshot_daemon()
+            }
+        }
     }
 }