Expose fewer exit variables

This commit is contained in:
Greg Fitzgerald
2018-07-09 14:53:18 -06:00
committed by Greg Fitzgerald
parent 0ee86ff313
commit c65c0d9b23
8 changed files with 89 additions and 110 deletions

View File

@@ -14,8 +14,6 @@ use solana::service::Service;
use std::fs::File;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::process::exit;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
//use std::time::Duration;
fn main() -> () {
@@ -68,11 +66,10 @@ fn main() -> () {
}
}
let mut node = TestNode::new_with_bind_addr(repl_data, bind_addr);
let exit = Arc::new(AtomicBool::new(false));
let fullnode = if let Some(t) = matches.value_of("testnet") {
let testnet_address_string = t.to_string();
let testnet_addr = testnet_address_string.parse().unwrap();
FullNode::new(node, false, InFile::StdIn, Some(testnet_addr), None, exit)
FullNode::new(node, false, InFile::StdIn, Some(testnet_addr), None)
} else {
node.data.current_leader_id = node.data.id.clone();
@@ -81,7 +78,7 @@ fn main() -> () {
} else {
OutFile::StdOut
};
FullNode::new(node, true, InFile::StdIn, None, Some(outfile), exit)
FullNode::new(node, true, InFile::StdIn, None, Some(outfile))
};
fullnode.join().expect("join");
}

View File

@@ -3,13 +3,14 @@
use packet::BlobRecycler;
use service::Service;
use std::net::UdpSocket;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::channel;
use std::sync::Arc;
use std::thread::{self, JoinHandle};
use streamer::{self, BlobReceiver};
pub struct BlobFetchStage {
exit: Arc<AtomicBool>,
thread_hdls: Vec<JoinHandle<()>>,
}
@@ -39,7 +40,11 @@ impl BlobFetchStage {
})
.collect();
(BlobFetchStage { thread_hdls }, blob_receiver)
(BlobFetchStage { exit, thread_hdls }, blob_receiver)
}
pub fn close(&self) {
self.exit.store(true, Ordering::Relaxed);
}
}

View File

@@ -3,13 +3,14 @@
use packet::PacketRecycler;
use service::Service;
use std::net::UdpSocket;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::channel;
use std::sync::Arc;
use std::thread::{self, JoinHandle};
use streamer::{self, PacketReceiver};
pub struct FetchStage {
exit: Arc<AtomicBool>,
thread_hdls: Vec<JoinHandle<()>>,
}
@@ -39,7 +40,11 @@ impl FetchStage {
})
.collect();
(FetchStage { thread_hdls }, packet_receiver)
(FetchStage { exit, thread_hdls }, packet_receiver)
}
pub fn close(&self) {
self.exit.store(true, Ordering::Relaxed);
}
}

View File

@@ -14,7 +14,7 @@ use std::fs::{File, OpenOptions};
use std::io::{sink, stdin, stdout, BufReader};
use std::io::{Read, Write};
use std::net::SocketAddr;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock};
use std::thread::{JoinHandle, Result};
use std::time::Duration;
@@ -24,6 +24,7 @@ use tvu::Tvu;
//use std::time::Duration;
pub struct FullNode {
exit: Arc<AtomicBool>,
thread_hdls: Vec<JoinHandle<()>>,
}
@@ -44,7 +45,6 @@ impl FullNode {
infile: InFile,
network_entry_for_validator: Option<SocketAddr>,
outfile_for_leader: Option<OutFile>,
exit: Arc<AtomicBool>,
) -> FullNode {
info!("creating bank...");
let bank = Bank::default();
@@ -70,6 +70,7 @@ impl FullNode {
local_gossip_addr, node.data.contact_info.ncp
);
let requests_addr = node.data.contact_info.rpu.clone();
let exit = Arc::new(AtomicBool::new(false));
if !leader {
let testnet_addr = network_entry_for_validator.expect("validator requires entry");
@@ -215,7 +216,7 @@ impl FullNode {
);
thread_hdls.extend(vec![t_broadcast]);
FullNode { thread_hdls }
FullNode { exit, thread_hdls }
}
/// Create a server instance acting as a validator.
@@ -294,7 +295,12 @@ impl FullNode {
);
thread_hdls.extend(tvu.thread_hdls());
thread_hdls.extend(ncp.thread_hdls());
FullNode { thread_hdls }
FullNode { exit, thread_hdls }
}
pub fn close(self) -> Result<()> {
self.exit.store(true, Ordering::Relaxed);
self.join()
}
}
@@ -317,7 +323,7 @@ mod tests {
use crdt::TestNode;
use fullnode::FullNode;
use mint::Mint;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
#[test]
fn validator_exit() {
@@ -326,10 +332,7 @@ mod tests {
let bank = Bank::new(&alice);
let exit = Arc::new(AtomicBool::new(false));
let entry = tn.data.clone();
let v = FullNode::new_validator(bank, 0, None, tn, entry, exit.clone());
exit.store(true, Ordering::Relaxed);
for t in v.thread_hdls {
t.join().unwrap();
}
let v = FullNode::new_validator(bank, 0, None, tn, entry, exit);
v.close().unwrap();
}
}

View File

@@ -5,13 +5,14 @@ use packet::{BlobRecycler, SharedBlob};
use result::Result;
use service::Service;
use std::net::UdpSocket;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::channel;
use std::sync::{Arc, RwLock};
use std::thread::{self, JoinHandle};
use streamer;
pub struct Ncp {
exit: Arc<AtomicBool>,
thread_hdls: Vec<JoinHandle<()>>,
}
@@ -47,9 +48,14 @@ impl Ncp {
response_sender.clone(),
exit.clone(),
);
let t_gossip = Crdt::gossip(crdt.clone(), blob_recycler, response_sender, exit);
let t_gossip = Crdt::gossip(crdt.clone(), blob_recycler, response_sender, exit.clone());
let thread_hdls = vec![t_receiver, t_responder, t_listen, t_gossip];
Ok(Ncp { thread_hdls })
Ok(Ncp { exit, thread_hdls })
}
pub fn close(self) -> thread::Result<()> {
self.exit.store(true, Ordering::Relaxed);
self.join()
}
}
@@ -70,7 +76,7 @@ impl Service for Ncp {
mod tests {
use crdt::{Crdt, TestNode};
use ncp::Ncp;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, RwLock};
#[test]
@@ -89,9 +95,6 @@ mod tests {
tn.sockets.gossip_send,
exit.clone(),
).unwrap();
exit.store(true, Ordering::Relaxed);
for t in d.thread_hdls {
t.join().expect("thread join");
}
d.close().expect("thread join");
}
}

View File

@@ -87,6 +87,11 @@ impl Tpu {
};
(tpu, blob_receiver)
}
pub fn close(self) -> thread::Result<()> {
self.fetch_stage.close();
self.join()
}
}
impl Service for Tpu {

View File

@@ -101,6 +101,11 @@ impl Tvu {
window_stage,
}
}
pub fn close(self) -> thread::Result<()> {
self.fetch_stage.close();
self.join()
}
}
impl Service for Tvu {
@@ -136,7 +141,7 @@ pub mod tests {
use signature::{KeyPair, KeyPairUtil};
use std::collections::VecDeque;
use std::net::UdpSocket;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::atomic::AtomicBool;
use std::sync::mpsc::channel;
use std::sync::{Arc, RwLock};
use std::time::Duration;
@@ -279,8 +284,7 @@ pub mod tests {
let bob_balance = bank.get_balance(&bob_keypair.pubkey());
assert_eq!(bob_balance, starting_balance - alice_ref_balance);
exit.store(true, Ordering::Relaxed);
tvu.join().expect("join");
tvu.close().expect("close");
dr_l.0.join().expect("join");
dr_2.0.join().expect("join");
dr_1.0.join().expect("join");