2018-05-22 14:26:28 -07:00
|
|
|
//! The `replicate_stage` replicates transactions broadcast by the leader.
|
|
|
|
|
|
|
|
use packet;
|
2018-05-22 15:17:59 -07:00
|
|
|
use request_replicator::RequestReplicator;
|
|
|
|
use std::sync::Arc;
|
2018-05-22 15:18:07 -07:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
2018-05-22 14:26:28 -07:00
|
|
|
use std::thread::{spawn, JoinHandle};
|
|
|
|
use streamer;
|
|
|
|
|
|
|
|
pub struct ReplicateStage {
|
|
|
|
pub thread_hdl: JoinHandle<()>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ReplicateStage {
|
2018-05-22 15:18:07 -07:00
|
|
|
pub fn new(
|
|
|
|
request_replicator: RequestReplicator,
|
|
|
|
exit: Arc<AtomicBool>,
|
|
|
|
window_receiver: streamer::BlobReceiver,
|
|
|
|
blob_recycler: packet::BlobRecycler,
|
|
|
|
) -> Self {
|
2018-05-22 14:26:28 -07:00
|
|
|
let thread_hdl = spawn(move || loop {
|
|
|
|
let e = request_replicator.replicate_requests(&window_receiver, &blob_recycler);
|
2018-05-22 15:17:59 -07:00
|
|
|
if e.is_err() && exit.load(Ordering::Relaxed) {
|
2018-05-22 14:26:28 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2018-05-22 15:18:07 -07:00
|
|
|
ReplicateStage { thread_hdl }
|
2018-05-22 14:26:28 -07:00
|
|
|
}
|
|
|
|
}
|