Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
execute periodic snapshot in new thread (#3029)
Browse files Browse the repository at this point in the history
to ensure that the I/O worker isn't stalled.
  • Loading branch information
rphmeier authored and gavofyork committed Nov 1, 2016
1 parent cb3bb24 commit 42010ac
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ethcore/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {

#[cfg_attr(feature="dev", allow(single_match))]
fn message(&self, _io: &IoContext<ClientIoMessage>, net_message: &ClientIoMessage) {
use std::thread;

match *net_message {
ClientIoMessage::BlockVerified => { self.client.import_verified_blocks(); }
ClientIoMessage::NewTransactions(ref transactions) => { self.client.import_queued_transactions(transactions); }
Expand All @@ -199,9 +201,19 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
ClientIoMessage::FeedStateChunk(ref hash, ref chunk) => self.snapshot.feed_state_chunk(*hash, chunk),
ClientIoMessage::FeedBlockChunk(ref hash, ref chunk) => self.snapshot.feed_block_chunk(*hash, chunk),
ClientIoMessage::TakeSnapshot(num) => {
if let Err(e) = self.snapshot.take_snapshot(&*self.client, num) {
warn!("Failed to take snapshot at block #{}: {}", num, e);
let client = self.client.clone();
let snapshot = self.snapshot.clone();

let res = thread::Builder::new().name("Periodic Snapshot".into()).spawn(move || {
if let Err(e) = snapshot.take_snapshot(&*client, num) {
warn!("Failed to take snapshot at block #{}: {}", num, e);
}
});

if let Err(e) = res {
debug!(target: "snapshot", "Failed to initialize periodic snapshot thread: {:?}", e);
}

}
_ => {} // ignore other messages
}
Expand Down

0 comments on commit 42010ac

Please sign in to comment.