Use cleanup (#4347)

This commit is contained in:
Michael Vines 2019-05-20 09:58:27 -07:00 committed by GitHub
parent 55cee5742f
commit 6365c4c061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 25 deletions

View File

@ -9,8 +9,7 @@ use crate::packet::to_shared_blob;
use crate::repair_service::{RepairSlotRange, RepairStrategy}; use crate::repair_service::{RepairSlotRange, RepairStrategy};
use crate::result::Result; use crate::result::Result;
use crate::service::Service; use crate::service::Service;
use crate::streamer::receiver; use crate::streamer::{receiver, responder};
use crate::streamer::responder;
use crate::window_service::WindowService; use crate::window_service::WindowService;
use bincode::deserialize; use bincode::deserialize;
use rand::thread_rng; use rand::thread_rng;
@ -31,23 +30,15 @@ use solana_sdk::transaction::Transaction;
use solana_sdk::transport::TransportError; use solana_sdk::transport::TransportError;
use solana_storage_api::{get_segment_from_slot, storage_instruction, SLOTS_PER_SEGMENT}; use solana_storage_api::{get_segment_from_slot, storage_instruction, SLOTS_PER_SEGMENT};
use std::fs::File; use std::fs::File;
use std::io; use std::io::{self, BufReader, Error, ErrorKind, Read, Seek, SeekFrom};
use std::io::BufReader;
use std::io::Read;
use std::io::Seek;
use std::io::SeekFrom;
use std::io::{Error, ErrorKind};
use std::mem::size_of; use std::mem::size_of;
use std::net::{SocketAddr, UdpSocket}; use std::net::{SocketAddr, UdpSocket};
use std::path::Path; use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::result; use std::result;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use std::thread::sleep; use std::thread::{sleep, spawn, JoinHandle};
use std::thread::spawn;
use std::thread::JoinHandle;
use std::time::Duration; use std::time::Duration;
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -76,7 +67,7 @@ pub struct Replicator {
blocktree: Arc<Blocktree>, blocktree: Arc<Blocktree>,
} }
pub fn sample_file(in_path: &Path, sample_offsets: &[u64]) -> io::Result<Hash> { pub(crate) fn sample_file(in_path: &Path, sample_offsets: &[u64]) -> io::Result<Hash> {
let in_file = File::open(in_path)?; let in_file = File::open(in_path)?;
let metadata = in_file.metadata()?; let metadata = in_file.metadata()?;
let mut buffer_file = BufReader::new(in_file); let mut buffer_file = BufReader::new(in_file);
@ -214,7 +205,6 @@ impl Replicator {
let (storage_blockhash, storage_slot) = Self::poll_for_blockhash_and_slot(&cluster_info)?; let (storage_blockhash, storage_slot) = Self::poll_for_blockhash_and_slot(&cluster_info)?;
let node_info = node.info.clone();
let signature = storage_keypair.sign(storage_blockhash.as_ref()); let signature = storage_keypair.sign(storage_blockhash.as_ref());
let slot = get_slot_from_blockhash(&signature, storage_slot); let slot = get_slot_from_blockhash(&signature, storage_slot);
info!("replicating slot: {}", slot); info!("replicating slot: {}", slot);
@ -264,6 +254,7 @@ impl Replicator {
let exit = exit.clone(); let exit = exit.clone();
let blocktree = blocktree.clone(); let blocktree = blocktree.clone();
let cluster_info = cluster_info.clone(); let cluster_info = cluster_info.clone();
let node_info = node.info.clone();
spawn(move || { spawn(move || {
Self::wait_for_ledger_download(slot, &blocktree, &exit, &node_info, cluster_info) Self::wait_for_ledger_download(slot, &blocktree, &exit, &node_info, cluster_info)
}) })
@ -496,10 +487,6 @@ impl Replicator {
} }
} }
pub fn slot(&self) -> u64 {
self.slot
}
fn poll_for_blockhash_and_slot( fn poll_for_blockhash_and_slot(
cluster_info: &Arc<RwLock<ClusterInfo>>, cluster_info: &Arc<RwLock<ClusterInfo>>,
) -> Result<(String, u64)> { ) -> Result<(String, u64)> {
@ -535,14 +522,9 @@ impl Replicator {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::replicator::sample_file; use super::*;
use solana_sdk::hash::Hash;
use solana_sdk::signature::{Keypair, KeypairUtil};
use std::fs::File;
use std::fs::{create_dir_all, remove_file}; use std::fs::{create_dir_all, remove_file};
use std::io::Write; use std::io::Write;
use std::mem::size_of;
use std::path::PathBuf;
fn tmp_file_path(name: &str) -> PathBuf { fn tmp_file_path(name: &str) -> PathBuf {
use std::env; use std::env;