@@ -20,6 +20,7 @@ use crate::metastore::{
2020use crate :: mysql:: { MySqlServer , SqlAuthDefaultImpl , SqlAuthService } ;
2121use crate :: queryplanner:: query_executor:: { QueryExecutor , QueryExecutorImpl } ;
2222use crate :: queryplanner:: { QueryPlanner , QueryPlannerImpl } ;
23+ use crate :: remotefs:: cleanup:: RemoteFsCleanup ;
2324use crate :: remotefs:: gcs:: GCSRemoteFs ;
2425use crate :: remotefs:: minio:: MINIORemoteFs ;
2526use crate :: remotefs:: queue:: QueueRemoteFs ;
@@ -109,6 +110,14 @@ impl CubeServices {
109110 QueueRemoteFs :: wait_processing_loops ( remote_fs. clone ( ) ) . await
110111 } ) ) ;
111112
113+ if self . injector . has_service_typed :: < RemoteFsCleanup > ( ) . await {
114+ let cleanup = self . injector . get_service_typed :: < RemoteFsCleanup > ( ) . await ;
115+ futures. push ( cube_ext:: spawn ( async move {
116+ cleanup. wait_local_cleanup_loop ( ) . await ;
117+ Ok ( ( ) )
118+ } ) ) ;
119+ }
120+
112121 if !self . cluster . is_select_worker ( ) {
113122 let rocks_meta_store = self . rocks_meta_store . clone ( ) . unwrap ( ) ;
114123 futures. push ( cube_ext:: spawn ( async move {
@@ -220,6 +229,11 @@ impl CubeServices {
220229 scheduler. stop_processing_loops ( ) ?;
221230 }
222231
232+ if self . injector . has_service_typed :: < RemoteFsCleanup > ( ) . await {
233+ let cleanup = self . injector . get_service_typed :: < RemoteFsCleanup > ( ) . await ;
234+ cleanup. stop ( ) ;
235+ }
236+
223237 if self
224238 . injector
225239 . has_service_typed :: < CacheStoreSchedulerImpl > ( )
@@ -470,7 +484,13 @@ pub trait ConfigObj: DIService {
470484
471485 fn local_files_cleanup_interval_secs ( & self ) -> u64 ;
472486
487+ fn remote_files_cleanup_interval_secs ( & self ) -> u64 ;
488+
473489 fn local_files_cleanup_size_threshold ( & self ) -> u64 ;
490+
491+ fn local_files_cleanup_delay_secs ( & self ) -> u64 ;
492+
493+ fn remote_files_cleanup_delay_secs ( & self ) -> u64 ;
474494}
475495
476496#[ derive( Debug , Clone ) ]
@@ -544,7 +564,10 @@ pub struct ConfigObjImpl {
544564 pub transport_max_message_size : usize ,
545565 pub transport_max_frame_size : usize ,
546566 pub local_files_cleanup_interval_secs : u64 ,
567+ pub remote_files_cleanup_interval_secs : u64 ,
547568 pub local_files_cleanup_size_threshold : u64 ,
569+ pub local_files_cleanup_delay_secs : u64 ,
570+ pub remote_files_cleanup_delay_secs : u64 ,
548571}
549572
550573crate :: di_service!( ConfigObjImpl , [ ConfigObj ] ) ;
@@ -812,9 +835,21 @@ impl ConfigObj for ConfigObjImpl {
812835 self . local_files_cleanup_interval_secs
813836 }
814837
838+ fn remote_files_cleanup_interval_secs ( & self ) -> u64 {
839+ self . remote_files_cleanup_interval_secs
840+ }
841+
815842 fn local_files_cleanup_size_threshold ( & self ) -> u64 {
816843 self . local_files_cleanup_size_threshold
817844 }
845+
846+ fn local_files_cleanup_delay_secs ( & self ) -> u64 {
847+ self . local_files_cleanup_delay_secs
848+ }
849+
850+ fn remote_files_cleanup_delay_secs ( & self ) -> u64 {
851+ self . remote_files_cleanup_delay_secs
852+ }
818853}
819854
820855lazy_static ! {
@@ -1187,14 +1222,26 @@ impl Config {
11871222 ) ,
11881223 local_files_cleanup_interval_secs : env_parse (
11891224 "CUBESTORE_LOCAL_FILES_CLEANUP_INTERVAL_SECS" ,
1190- 3 * 600 ,
1225+ 600 ,
1226+ ) ,
1227+ remote_files_cleanup_interval_secs : env_parse (
1228+ "CUBESTORE_REMOTE_FILES_CLEANUP_INTERVAL_SECS" ,
1229+ 6 * 600 ,
11911230 ) ,
11921231 local_files_cleanup_size_threshold : env_parse_size (
11931232 "CUBESTORE_LOCAL_FILES_CLEANUP_SIZE_THRESHOLD" ,
11941233 1024 * 1024 * 1024 ,
11951234 None ,
11961235 None ,
11971236 ) as u64 ,
1237+ local_files_cleanup_delay_secs : env_parse (
1238+ "CUBESTORE_LOCAL_FILES_CLEANUP_DELAY_SECS" ,
1239+ 600 ,
1240+ ) ,
1241+ remote_files_cleanup_delay_secs : env_parse (
1242+ "CUBESTORE_REMOTE_FILES_CLEANUP_DELAY_SECS" ,
1243+ 3600 ,
1244+ ) ,
11981245 } ) ,
11991246 }
12001247 }
@@ -1280,7 +1327,10 @@ impl Config {
12801327 transport_max_message_size : 64 << 20 ,
12811328 transport_max_frame_size : 16 << 20 ,
12821329 local_files_cleanup_interval_secs : 600 ,
1330+ remote_files_cleanup_interval_secs : 600 ,
12831331 local_files_cleanup_size_threshold : 0 ,
1332+ local_files_cleanup_delay_secs : 600 ,
1333+ remote_files_cleanup_delay_secs : 3600 ,
12841334 } ) ,
12851335 }
12861336 }
@@ -1739,6 +1789,16 @@ impl Config {
17391789 ) )
17401790 } )
17411791 . await ;
1792+
1793+ self . injector
1794+ . register_typed :: < RemoteFsCleanup , _ , _ , _ > ( async move |i| {
1795+ Arc :: new ( RemoteFsCleanup :: new (
1796+ i. get_service_typed ( ) . await ,
1797+ i. get_service_typed ( ) . await ,
1798+ i. get_service_typed ( ) . await ,
1799+ ) )
1800+ } )
1801+ . await ;
17421802 }
17431803
17441804 pub async fn configure_common ( & self ) {
0 commit comments