Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add diskcheck #3598

Merged
merged 12 commits into from
Aug 8, 2022
24 changes: 20 additions & 4 deletions node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use starcoin_rpc_server::module::{PubSubService, PubSubServiceFactory};
use starcoin_rpc_server::service::RpcService;
use starcoin_service_registry::bus::{Bus, BusService};
use starcoin_service_registry::{
ActorService, RegistryAsyncService, RegistryService, ServiceContext, ServiceFactory,
ServiceHandler, ServiceRef,
ActorService, EventHandler, RegistryAsyncService, RegistryService, ServiceContext,
ServiceFactory, ServiceHandler, ServiceRef,
};
use starcoin_state_service::ChainStateService;
use starcoin_storage::block_info::BlockInfoStore;
Expand All @@ -53,7 +53,7 @@ use starcoin_sync::sync::SyncService;
use starcoin_sync::txn_sync::TxnSyncService;
use starcoin_sync::verified_rpc_client::VerifiedRpcClient;
use starcoin_txpool::TxPoolActorService;
use starcoin_types::system_events::SystemStarted;
use starcoin_types::system_events::{SystemShutdown, SystemStarted};
use std::sync::Arc;
use std::time::{Duration, SystemTime};

Expand All @@ -69,7 +69,23 @@ impl ServiceFactory<Self> for NodeService {
}
}

impl ActorService for NodeService {}
impl ActorService for NodeService {
fn started(&mut self, ctx: &mut ServiceContext<Self>) -> Result<()> {
ctx.subscribe::<SystemShutdown>();
Ok(())
}

fn stopped(&mut self, ctx: &mut ServiceContext<Self>) -> Result<()> {
ctx.unsubscribe::<SystemShutdown>();
Ok(())
}
}

impl EventHandler<Self, SystemShutdown> for NodeService {
fn handle_event(&mut self, _: SystemShutdown, ctx: &mut ServiceContext<Self>) {
ctx.broadcast(NodeRequest::ShutdownSystem);
YouNeedWork marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl ServiceHandler<Self, NodeRequest> for NodeService {
fn handle(
Expand Down
15 changes: 6 additions & 9 deletions sync/src/block_connector/block_connector_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use starcoin_storage::{BlockStore, Storage};
use starcoin_sync_api::PeerNewBlock;
use starcoin_types::block::ExecutedBlock;
use starcoin_types::sync_status::SyncStatus;
use starcoin_types::system_events::{MinedBlock, SyncStatusChangeEvent};
use starcoin_types::system_events::{MinedBlock, SyncStatusChangeEvent, SystemShutdown};
use std::sync::Arc;
use sysinfo::{DiskExt, System, SystemExt};
use txpool::TxPoolService;
Expand Down Expand Up @@ -86,7 +86,7 @@ impl BlockConnectorService {
} else if DISK_CHECKPOINT_FOR_WARN > disk.available_space() {
return Some(Ok(disk.available_space() / 1024 / 1024));
}

break;
}
}
Expand Down Expand Up @@ -128,9 +128,9 @@ impl ActorService for BlockConnectorService {
ctx.subscribe::<MinedBlock>();

ctx.run_interval(std::time::Duration::from_secs(3), move |ctx| {
ctx.notify(crate::tasks::BlockDiskCheckEvent{});
ctx.notify(crate::tasks::BlockDiskCheckEvent {});
});

Ok(())
}

Expand All @@ -145,7 +145,7 @@ impl EventHandler<Self, BlockDiskCheckEvent> for BlockConnectorService {
fn handle_event(
&mut self,
_: BlockDiskCheckEvent,
_ctx: &mut ServiceContext<BlockConnectorService>,
ctx: &mut ServiceContext<BlockConnectorService>,
) {
if let Some(res) = self.check_disk_space() {
YouNeedWork marked this conversation as resolved.
Show resolved Hide resolved
match res {
Expand All @@ -154,13 +154,10 @@ impl EventHandler<Self, BlockDiskCheckEvent> for BlockConnectorService {
}
Err(e) => {
error!("{}", e);
//TODO: exit the starcoin
//ctx.notify(NodeRequest::ShutdownSystem);
ctx.broadcast(SystemShutdown);
}
}
}

error!("Check the disk space");
}
}

Expand Down
2 changes: 1 addition & 1 deletion sync/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ pub struct BlockConnectedEvent {
}

#[derive(Clone, Debug)]
pub struct BlockDiskCheckEvent{}
pub struct BlockDiskCheckEvent {}

pub trait BlockConnectedEventHandle: Send + Clone + std::marker::Unpin {
fn handle(&mut self, event: BlockConnectedEvent) -> Result<()>;
Expand Down
3 changes: 3 additions & 0 deletions types/src/system_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub struct MinedBlock(pub Arc<Block>);
#[derive(Clone, Debug)]
pub struct SystemStarted;

#[derive(Clone, Debug)]
pub struct SystemShutdown;

#[derive(Clone, Debug)]
pub struct SyncStatusChangeEvent(pub SyncStatus);

Expand Down