Shutdown the Snapshot Service early (#8658)
* Shutdown the Snapshot Service when shutting down the runner * Rename `service` to `client_service` * Fix tests
This commit is contained in:
parent
68d16b723a
commit
7fcb082cad
@ -29,7 +29,7 @@ use sync::PrivateTxHandler;
|
|||||||
use ethcore::client::{Client, ClientConfig, ChainNotify, ClientIoMessage};
|
use ethcore::client::{Client, ClientConfig, ChainNotify, ClientIoMessage};
|
||||||
use ethcore::miner::Miner;
|
use ethcore::miner::Miner;
|
||||||
use ethcore::snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
|
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::spec::Spec;
|
||||||
use ethcore::account_provider::AccountProvider;
|
use ethcore::account_provider::AccountProvider;
|
||||||
|
|
||||||
@ -168,6 +168,11 @@ impl ClientService {
|
|||||||
|
|
||||||
/// Get a handle to the database.
|
/// Get a handle to the database.
|
||||||
pub fn db(&self) -> Arc<KeyValueDB> { self.database.clone() }
|
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
|
/// IO interface for the Client handler
|
||||||
|
@ -743,6 +743,10 @@ impl SnapshotService for Service {
|
|||||||
trace!("Error sending snapshot service message: {:?}", e);
|
trace!("Error sending snapshot service message: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn shutdown(&self) {
|
||||||
|
self.abort_restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Service {
|
impl Drop for Service {
|
||||||
|
@ -54,4 +54,7 @@ pub trait SnapshotService : Sync + Send {
|
|||||||
/// Feed a raw block chunk to the service to be processed asynchronously.
|
/// Feed a raw block chunk to the service to be processed asynchronously.
|
||||||
/// no-op if currently restoring.
|
/// no-op if currently restoring.
|
||||||
fn restore_block_chunk(&self, hash: H256, chunk: Bytes);
|
fn restore_block_chunk(&self, hash: H256, chunk: Bytes);
|
||||||
|
|
||||||
|
/// Shutdown the Snapshot Service by aborting any ongoing restore
|
||||||
|
fn shutdown(&self);
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,10 @@ impl SnapshotService for TestSnapshotService {
|
|||||||
self.block_restoration_chunks.lock().insert(hash, chunk);
|
self.block_restoration_chunks.lock().insert(hash, chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn shutdown(&self) {
|
||||||
|
self.abort_restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -885,7 +885,8 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
|
|||||||
rpc: rpc_direct,
|
rpc: rpc_direct,
|
||||||
informant,
|
informant,
|
||||||
client,
|
client,
|
||||||
keep_alive: Box::new((watcher, service, updater, ws_server, http_server, ipc_server, ui_server, secretstore_key_server, ipfs_server, event_loop)),
|
client_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)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -909,6 +910,7 @@ enum RunningClientInner {
|
|||||||
rpc: jsonrpc_core::MetaIoHandler<Metadata, informant::Middleware<informant::ClientNotifier>>,
|
rpc: jsonrpc_core::MetaIoHandler<Metadata, informant::Middleware<informant::ClientNotifier>>,
|
||||||
informant: Arc<Informant<FullNodeInformantData>>,
|
informant: Arc<Informant<FullNodeInformantData>>,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
|
client_service: Arc<ClientService>,
|
||||||
keep_alive: Box<Any>,
|
keep_alive: Box<Any>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -946,11 +948,14 @@ impl RunningClient {
|
|||||||
drop(client);
|
drop(client);
|
||||||
wait_for_drop(weak_client);
|
wait_for_drop(weak_client);
|
||||||
},
|
},
|
||||||
RunningClientInner::Full { rpc, informant, client, keep_alive } => {
|
RunningClientInner::Full { rpc, informant, client, client_service, keep_alive } => {
|
||||||
info!("Finishing work, please wait...");
|
info!("Finishing work, please wait...");
|
||||||
// Create a weak reference to the client so that we can wait on shutdown
|
// Create a weak reference to the client so that we can wait on shutdown
|
||||||
// until it is dropped
|
// until it is dropped
|
||||||
let weak_client = Arc::downgrade(&client);
|
let weak_client = Arc::downgrade(&client);
|
||||||
|
// Shutdown and drop the ServiceClient
|
||||||
|
client_service.shutdown();
|
||||||
|
drop(client_service);
|
||||||
// drop this stuff as soon as exit detected.
|
// drop this stuff as soon as exit detected.
|
||||||
drop(rpc);
|
drop(rpc);
|
||||||
drop(keep_alive);
|
drop(keep_alive);
|
||||||
|
@ -50,4 +50,5 @@ impl SnapshotService for TestSnapshotService {
|
|||||||
fn abort_restore(&self) { }
|
fn abort_restore(&self) { }
|
||||||
fn restore_state_chunk(&self, _hash: H256, _chunk: Bytes) { }
|
fn restore_state_chunk(&self, _hash: H256, _chunk: Bytes) { }
|
||||||
fn restore_block_chunk(&self, _hash: H256, _chunk: Bytes) { }
|
fn restore_block_chunk(&self, _hash: H256, _chunk: Bytes) { }
|
||||||
|
fn shutdown(&self) { }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user