Merge pull request #6694 from paritytech/no-sleep

Prevent going offline when restoring or taking a snapshot
This commit is contained in:
Marek Kotewicz 2017-10-12 15:54:29 +02:00 committed by GitHub
commit e51e54eeeb
3 changed files with 15 additions and 9 deletions

View File

@ -988,10 +988,12 @@ impl Client {
/// Tick the client. /// Tick the client.
// TODO: manage by real events. // TODO: manage by real events.
pub fn tick(&self) { pub fn tick(&self, prevent_sleep: bool) {
self.check_garbage(); self.check_garbage();
if !prevent_sleep {
self.check_snooze(); self.check_snooze();
} }
}
fn check_garbage(&self) { fn check_garbage(&self) {
self.chain.read().collect_garbage(); self.chain.read().collect_garbage();
@ -1098,7 +1100,7 @@ impl Client {
if !self.liveness.load(AtomicOrdering::Relaxed) { if !self.liveness.load(AtomicOrdering::Relaxed) {
self.liveness.store(true, AtomicOrdering::Relaxed); self.liveness.store(true, AtomicOrdering::Relaxed);
self.notify(|n| n.start()); self.notify(|n| n.start());
trace!(target: "mode", "wake_up: Waking."); info!(target: "mode", "wake_up: Waking.");
} }
} }
@ -1108,11 +1110,11 @@ impl Client {
if self.queue_info().total_queue_size() <= MAX_QUEUE_SIZE_TO_SLEEP_ON { if self.queue_info().total_queue_size() <= MAX_QUEUE_SIZE_TO_SLEEP_ON {
self.liveness.store(false, AtomicOrdering::Relaxed); self.liveness.store(false, AtomicOrdering::Relaxed);
self.notify(|n| n.stop()); self.notify(|n| n.stop());
trace!(target: "mode", "sleep: Sleeping."); info!(target: "mode", "sleep: Sleeping.");
} else { } else {
trace!(target: "mode", "sleep: Cannot sleep - syncing ongoing."); info!(target: "mode", "sleep: Cannot sleep - syncing ongoing.");
// TODO: Consider uncommenting. // TODO: Consider uncommenting.
//*self.last_activity.lock() = Some(Instant::now()); //(*self.sleep_state.lock()).last_activity = Some(Instant::now());
} }
} }
} }

View File

@ -27,7 +27,7 @@ use error::*;
use client::{Client, ClientConfig, ChainNotify}; use client::{Client, ClientConfig, ChainNotify};
use miner::Miner; use miner::Miner;
use snapshot::ManifestData; use snapshot::{ManifestData, RestorationStatus};
use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams}; use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use ansi_term::Colour; use ansi_term::Colour;
@ -180,7 +180,11 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
fn timeout(&self, _io: &IoContext<ClientIoMessage>, timer: TimerToken) { fn timeout(&self, _io: &IoContext<ClientIoMessage>, timer: TimerToken) {
match timer { match timer {
CLIENT_TICK_TIMER => self.client.tick(), CLIENT_TICK_TIMER => {
use snapshot::SnapshotService;
let snapshot_restoration = if let RestorationStatus::Ongoing{..} = self.snapshot.status() { true } else { false };
self.client.tick(snapshot_restoration)
},
SNAPSHOT_TICK_TIMER => self.snapshot.tick(), SNAPSHOT_TICK_TIMER => self.snapshot.tick(),
_ => warn!("IO service triggered unregistered timer '{}'", timer), _ => warn!("IO service triggered unregistered timer '{}'", timer),
} }

View File

@ -195,7 +195,7 @@ fn imports_block_sequence() {
#[test] #[test]
fn can_collect_garbage() { fn can_collect_garbage() {
let client = generate_dummy_client(100); let client = generate_dummy_client(100);
client.tick(); client.tick(true);
assert!(client.blockchain_cache_info().blocks < 100 * 1024); assert!(client.blockchain_cache_info().blocks < 100 * 1024);
} }