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

Shutdown the Snapshot Service early #8658

Merged
merged 4 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ethcore/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use sync::PrivateTxHandler;
use ethcore::client::{Client, ClientConfig, ChainNotify, ClientIoMessage};
use ethcore::miner::Miner;
use ethcore::snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
use ethcore::snapshot::{RestorationStatus};
use ethcore::snapshot::{SnapshotService as _SnapshotService, RestorationStatus};
use ethcore::spec::Spec;
use ethcore::account_provider::AccountProvider;

Expand Down Expand Up @@ -168,6 +168,11 @@ impl ClientService {

/// Get a handle to the database.
pub fn db(&self) -> Arc<KeyValueDB> { self.database.clone() }

/// Shutdown the Client Service
pub fn shutdown(&self) {
self.snapshot.shutdown();
}
}

/// IO interface for the Client handler
Expand Down
4 changes: 4 additions & 0 deletions ethcore/src/snapshot/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@ impl SnapshotService for Service {
trace!("Error sending snapshot service message: {:?}", e);
}
}

fn shutdown(&self) {
self.abort_restore();
}
}

impl Drop for Service {
Expand Down
3 changes: 3 additions & 0 deletions ethcore/src/snapshot/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ pub trait SnapshotService : Sync + Send {
/// Feed a raw block chunk to the service to be processed asynchronously.
/// no-op if currently restoring.
fn restore_block_chunk(&self, hash: H256, chunk: Bytes);

/// Shutdown the Snapshot Service by aborting any ongoing restore
fn shutdown(&self);
}
4 changes: 4 additions & 0 deletions ethcore/sync/src/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ impl SnapshotService for TestSnapshotService {
self.block_restoration_chunks.lock().insert(hash, chunk);
}
}

fn shutdown(&self) {
self.abort_restore();
}
}

#[test]
Expand Down
9 changes: 7 additions & 2 deletions parity/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,8 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
rpc: rpc_direct,
informant,
client,
keep_alive: Box::new((watcher, service, updater, ws_server, http_server, ipc_server, ui_server, secretstore_key_server, ipfs_server, event_loop)),
service: Arc::new(service),
keep_alive: Box::new((watcher, updater, ws_server, http_server, ipc_server, ui_server, secretstore_key_server, ipfs_server, event_loop)),
}
})
}
Expand All @@ -909,6 +910,7 @@ enum RunningClientInner {
rpc: jsonrpc_core::MetaIoHandler<Metadata, informant::Middleware<informant::ClientNotifier>>,
informant: Arc<Informant<FullNodeInformantData>>,
client: Arc<Client>,
service: Arc<ClientService>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to something more descriptive, like snapshot_service, service in itself could be anything. Or is there any particular reason you picked service?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just because the variable was named service, but could change for sure to client_service

keep_alive: Box<Any>,
},
}
Expand Down Expand Up @@ -946,11 +948,14 @@ impl RunningClient {
drop(client);
wait_for_drop(weak_client);
},
RunningClientInner::Full { rpc, informant, client, keep_alive } => {
RunningClientInner::Full { rpc, informant, client, service, keep_alive } => {
info!("Finishing work, please wait...");
// Create a weak reference to the client so that we can wait on shutdown
// until it is dropped
let weak_client = Arc::downgrade(&client);
// Shutdown and drop the ServiceClient
service.shutdown();
drop(service);
// drop this stuff as soon as exit detected.
drop(rpc);
drop(keep_alive);
Expand Down