@@ -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 < ( ) > {
@@ -146,52 +151,54 @@ where
146151 }
147152 }
148153 if let Some ( blessed_lite_snapshot) = { self . blessed_lite_snapshot . read ( ) . clone ( ) } {
149- let mut opts = ParityDb :: to_options ( self . db_root_dir . clone ( ) , & self . db_config ) ;
150- for col in [
151- DbColumn :: GraphDagCborBlake2b256 as u8 ,
152- DbColumn :: GraphFull as u8 ,
153- ] {
154- let start = Instant :: now ( ) ;
155- tracing:: info!( "pruning parity-db column {col}..." ) ;
156- loop {
157- match parity_db:: Db :: reset_column ( & mut opts, col, None ) {
158- Ok ( _) => break ,
159- Err ( _) => {
160- tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
154+ if blessed_lite_snapshot. is_file ( ) {
155+ let mut opts = ParityDb :: to_options ( self . db_root_dir . clone ( ) , & self . db_config ) ;
156+ for col in [
157+ DbColumn :: GraphDagCborBlake2b256 as u8 ,
158+ DbColumn :: GraphFull as u8 ,
159+ ] {
160+ let start = Instant :: now ( ) ;
161+ tracing:: info!( "pruning parity-db column {col}..." ) ;
162+ loop {
163+ match parity_db:: Db :: reset_column ( & mut opts, col, None ) {
164+ Ok ( _) => break ,
165+ Err ( _) => {
166+ tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
167+ }
161168 }
162169 }
170+ tracing:: info!(
171+ "pruned parity-db column {col}, took {}" ,
172+ humantime:: format_duration( start. elapsed( ) )
173+ ) ;
163174 }
164- tracing:: info!(
165- "pruned parity-db column {col}, took {}" ,
166- humantime:: format_duration( start. elapsed( ) )
167- ) ;
168- }
169175
170- for car_to_remove in walkdir:: WalkDir :: new ( & self . car_db_dir )
171- . max_depth ( 1 )
172- . into_iter ( )
173- . filter_map ( |entry| {
174- if let Ok ( entry) = entry {
175- if entry. path ( ) != blessed_lite_snapshot. as_path ( ) {
176- if let Some ( filename) = entry. file_name ( ) . to_str ( ) {
177- if filename. ends_with ( FOREST_CAR_FILE_EXTENSION ) {
178- return Some ( entry. into_path ( ) ) ;
176+ for car_to_remove in walkdir:: WalkDir :: new ( & self . car_db_dir )
177+ . max_depth ( 1 )
178+ . into_iter ( )
179+ . filter_map ( |entry| {
180+ if let Ok ( entry) = entry {
181+ if entry. path ( ) != blessed_lite_snapshot. as_path ( ) {
182+ if let Some ( filename) = entry. file_name ( ) . to_str ( ) {
183+ if filename. ends_with ( FOREST_CAR_FILE_EXTENSION ) {
184+ return Some ( entry. into_path ( ) ) ;
185+ }
179186 }
180187 }
181188 }
182- }
183- None
184- } )
185- {
186- match std :: fs :: remove_file ( & car_to_remove ) {
187- Ok ( _ ) => {
188- tracing :: info! ( "deleted car db at {}" , car_to_remove . display ( ) ) ;
189- }
190- Err ( e ) => {
191- tracing :: warn! (
192- "failed to delete car db at {}: {e}" ,
193- car_to_remove . display ( )
194- ) ;
189+ None
190+ } )
191+ {
192+ match std :: fs :: remove_file ( & car_to_remove ) {
193+ Ok ( _ ) => {
194+ tracing :: info! ( "deleted car db at {}" , car_to_remove . display ( ) ) ;
195+ }
196+ Err ( e ) => {
197+ tracing :: warn! (
198+ "failed to delete car db at {}: {e}" ,
199+ car_to_remove . display ( )
200+ ) ;
201+ }
195202 }
196203 }
197204 }
0 commit comments