Просмотр исходного кода

Move sync_log_entries.rs to using the new standalone daemon_watch.

Jing Yang 3 лет назад
Родитель
Сommit
0a93a0d6a5
2 измененных файлов с 7 добавлено и 7 удалено
  1. 4 1
      src/raft.rs
  2. 3 6
      src/sync_log_entries.rs

+ 4 - 1
src/raft.rs

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

+ 3 - 6
src/sync_log_entries.rs

@@ -4,7 +4,6 @@ use std::sync::Arc;
 use parking_lot::{Condvar, Mutex};
 
 use crate::daemon_env::ErrorKind;
-use crate::daemon_watch::Daemon;
 use crate::heartbeats::HEARTBEAT_INTERVAL;
 use crate::peer_progress::PeerProgress;
 use crate::term_marker::TermMarker;
@@ -120,10 +119,10 @@ impl<Command: ReplicableCommand> Raft<Command> {
     pub(crate) fn run_log_entry_daemon(
         &self,
         SyncLogEntriesDaemon { rx, peer_progress }: SyncLogEntriesDaemon,
-    ) {
+    ) -> impl FnOnce() {
         // Clone everything that the thread needs.
         let this = self.clone();
-        let sync_log_entry_daemon = move || {
+        move || {
             log::info!("{:?} sync log entries daemon running ...", this.me);
 
             let mut task_number = 0;
@@ -160,9 +159,7 @@ impl<Command: ReplicableCommand> Raft<Command> {
             }
 
             log::info!("{:?} sync log entries daemon done.", this.me);
-        };
-        self.daemon_watch
-            .create_daemon(Daemon::SyncLogEntries, sync_log_entry_daemon);
+        }
     }
 
     /// Syncs log entries to a peer once, requests a new sync if that fails.