@@ -67,24 +67,35 @@ const CLUSTER_METRICS_INTERVAL_SECONDS: Interval = clokwerk::Interval::Minutes(1
67
67
68
68
pub async fn for_each_live_ingestor < F , Fut , E > ( api_fn : F ) -> Result < ( ) , E >
69
69
where
70
- F : Fn ( NodeMetadata ) -> Fut + Clone ,
71
- Fut : Future < Output = Result < ( ) , E > > ,
72
- E : From < anyhow:: Error > ,
70
+ F : Fn ( NodeMetadata ) -> Fut + Clone + Send + Sync + ' static ,
71
+ Fut : Future < Output = Result < ( ) , E > > + Send ,
72
+ E : From < anyhow:: Error > + Send + Sync + ' static ,
73
73
{
74
74
let ingestor_infos: Vec < NodeMetadata > =
75
75
get_node_info ( NodeType :: Ingestor ) . await . map_err ( |err| {
76
76
error ! ( "Fatal: failed to get ingestor info: {:?}" , err) ;
77
77
E :: from ( err)
78
78
} ) ?;
79
79
80
- // Process each live ingestor
80
+ let mut live_ingestors = Vec :: new ( ) ;
81
81
for ingestor in ingestor_infos {
82
- if !utils:: check_liveness ( & ingestor. domain_name ) . await {
82
+ if utils:: check_liveness ( & ingestor. domain_name ) . await {
83
+ live_ingestors. push ( ingestor) ;
84
+ } else {
83
85
warn ! ( "Ingestor {} is not live" , ingestor. domain_name) ;
84
- continue ;
85
86
}
87
+ }
88
+
89
+ // Process all live ingestors in parallel
90
+ let results = futures:: future:: join_all ( live_ingestors. into_iter ( ) . map ( |ingestor| {
91
+ let api_fn = api_fn. clone ( ) ;
92
+ async move { api_fn ( ingestor) . await }
93
+ } ) )
94
+ . await ;
86
95
87
- api_fn ( ingestor) . await ?;
96
+ // collect results
97
+ for result in results {
98
+ result?;
88
99
}
89
100
90
101
Ok ( ( ) )
0 commit comments