File tree Expand file tree Collapse file tree 4 files changed +23
-15
lines changed
cli/subcommands/chain_cmd Expand file tree Collapse file tree 4 files changed +23
-15
lines changed Original file line number Diff line number Diff line change 2727forest_check_db_stats
2828echo " Run snapshot GC"
2929forest_run_snap_gc
30- sleep 5
30+ forest_wait_api
3131echo " Wait the node to sync"
3232forest_wait_for_sync
3333forest_check_db_stats
Original file line number Diff line number Diff line change @@ -8,15 +8,18 @@ use std::time::Duration;
88#[ derive( Debug , Subcommand ) ]
99pub enum ChainPruneCommands {
1010 /// Run snapshot GC
11- Snap ,
11+ Snap {
12+ #[ arg( long) ]
13+ no_wait : bool ,
14+ } ,
1215}
1316
1417impl ChainPruneCommands {
1518 pub async fn run ( self , client : rpc:: Client ) -> anyhow:: Result < ( ) > {
1619 match self {
17- Self :: Snap => {
20+ Self :: Snap { no_wait } => {
1821 client
19- . call ( ChainPruneSnapshot :: request ( ( ) ) ?. with_timeout ( Duration :: MAX ) )
22+ . call ( ChainPruneSnapshot :: request ( ( !no_wait , ) ) ?. with_timeout ( Duration :: MAX ) )
2023 . await ?;
2124 }
2225 }
Original file line number Diff line number Diff line change @@ -87,13 +87,18 @@ where
8787 }
8888 }
8989
90- pub fn trigger ( & self ) -> flume:: Receiver < ( ) > {
91- let ( progress_tx, progress_rx) = flume:: unbounded ( ) ;
92- * self . progress_tx . write ( ) = Some ( progress_tx) ;
90+ pub fn trigger ( & self ) -> anyhow:: Result < flume:: Receiver < ( ) > > {
91+ if self . running . load ( Ordering :: Relaxed ) {
92+ anyhow:: bail!( "snap gc has already been running" ) ;
93+ }
94+
9395 if self . trigger_tx . try_send ( ( ) ) . is_err ( ) {
94- tracing :: warn !( "snap gc has already been triggered" ) ;
96+ anyhow :: bail !( "snap gc has already been triggered" ) ;
9597 }
96- progress_rx
98+
99+ let ( progress_tx, progress_rx) = flume:: unbounded ( ) ;
100+ * self . progress_tx . write ( ) = Some ( progress_tx) ;
101+ Ok ( progress_rx)
97102 }
98103
99104 async fn export_snapshot ( & self ) -> anyhow:: Result < ( ) > {
Original file line number Diff line number Diff line change @@ -196,22 +196,22 @@ impl RpcMethod<1> for ChainGetMessagesInTipset {
196196}
197197
198198pub enum ChainPruneSnapshot { }
199- impl RpcMethod < 0 > for ChainPruneSnapshot {
199+ impl RpcMethod < 1 > for ChainPruneSnapshot {
200200 const NAME : & ' static str = "Forest.SnapshotGC" ;
201- const PARAM_NAMES : [ & ' static str ; 0 ] = [ ] ;
201+ const PARAM_NAMES : [ & ' static str ; 1 ] = [ "blocking" ] ;
202202 const API_PATHS : BitFlags < ApiPaths > = ApiPaths :: all ( ) ;
203203 const PERMISSION : Permission = Permission :: Admin ;
204204
205- type Params = ( ) ;
205+ type Params = ( bool , ) ;
206206 type Ok = ( ) ;
207207
208208 async fn handle (
209209 _ctx : Ctx < impl Blockstore + Send + Sync + ' static > ,
210- ( ) : Self :: Params ,
210+ ( blocking , ) : Self :: Params ,
211211 ) -> Result < Self :: Ok , ServerError > {
212212 if let Some ( gc) = crate :: daemon:: GLOBAL_SNAPSHOT_GC . get ( ) {
213- let progress_rx = gc. trigger ( ) ;
214- while progress_rx. recv_async ( ) . await . is_ok ( ) { }
213+ let progress_rx = gc. trigger ( ) ? ;
214+ while blocking && progress_rx. recv_async ( ) . await . is_ok ( ) { }
215215 Ok ( ( ) )
216216 } else {
217217 Err ( anyhow:: anyhow!( "snapshot gc is not enabled" ) . into ( ) )
You can’t perform that action at this time.
0 commit comments