@@ -33,6 +33,7 @@ use dashmap::mapref::multiple::RefMulti;
3333use dashmap:: DashMap ;
3434use databend_common_base:: base:: Progress ;
3535use databend_common_base:: base:: ProgressValues ;
36+ use databend_common_base:: base:: SpillProgress ;
3637use databend_common_base:: runtime:: profile:: Profile ;
3738use databend_common_base:: runtime:: profile:: ProfileStatisticsName ;
3839use databend_common_base:: runtime:: GlobalIORuntime ;
@@ -318,7 +319,7 @@ impl QueryContext {
318319
319320 pub fn update_init_query_id ( & self , id : String ) {
320321 self . shared . spilled_files . write ( ) . clear ( ) ;
321- self . shared . cluster_spill_file_nums . write ( ) . clear ( ) ;
322+ self . shared . cluster_spill_progress . write ( ) . clear ( ) ;
322323 * self . shared . init_query_id . write ( ) = id;
323324 }
324325
@@ -363,32 +364,47 @@ impl QueryContext {
363364 & self ,
364365 location : crate :: spillers:: Location ,
365366 layout : crate :: spillers:: Layout ,
367+ data_size : usize ,
366368 ) {
367369 if matches ! ( location, crate :: spillers:: Location :: Remote ( _) ) {
368370 let current_id = self . get_cluster ( ) . local_id ( ) ;
369- let mut w = self . shared . cluster_spill_file_nums . write ( ) ;
370- w. entry ( current_id) . and_modify ( |e| * e += 1 ) . or_insert ( 1 ) ;
371+ let mut w = self . shared . cluster_spill_progress . write ( ) ;
372+ let p = SpillProgress :: new ( 1 , data_size) ;
373+ w. entry ( current_id)
374+ . and_modify ( |stats| {
375+ stats. incr ( & p) ;
376+ } )
377+ . or_insert ( p) ;
371378 }
372379 {
373380 let mut w = self . shared . spilled_files . write ( ) ;
374381 w. insert ( location, layout) ;
375382 }
376383 }
377384
378- pub fn set_cluster_spill_file_nums ( & self , source_target : & str , num : usize ) {
379- if num != 0 {
385+ pub fn set_cluster_spill_progress ( & self , source_target : & str , stats : SpillProgress ) {
386+ if stats . file_nums != 0 {
380387 let _ = self
381388 . shared
382- . cluster_spill_file_nums
389+ . cluster_spill_progress
383390 . write ( )
384- . insert ( source_target. to_string ( ) , num ) ;
391+ . insert ( source_target. to_string ( ) , stats ) ;
385392 }
386393 }
387394
388- pub fn get_spill_file_nums ( & self , node_id : Option < String > ) -> usize {
389- let r = self . shared . cluster_spill_file_nums . read ( ) ;
395+ pub fn get_spill_file_stats ( & self , node_id : Option < String > ) -> SpillProgress {
396+ let r = self . shared . cluster_spill_progress . read ( ) ;
390397 let node_id = node_id. unwrap_or ( self . get_cluster ( ) . local_id ( ) ) ;
391- r. get ( & node_id) . cloned ( ) . unwrap_or ( 0 )
398+ r. get ( & node_id) . cloned ( ) . unwrap_or ( SpillProgress :: default ( ) )
399+ }
400+
401+ pub fn get_total_spill_progress ( & self ) -> SpillProgress {
402+ let r = self . shared . cluster_spill_progress . read ( ) ;
403+ let mut total = SpillProgress :: default ( ) ;
404+ for ( _, stats) in r. iter ( ) {
405+ total. incr ( stats) ;
406+ }
407+ total
392408 }
393409
394410 pub fn get_spill_layout (
0 commit comments