@@ -12,7 +12,7 @@ use std::collections::HashMap;
1212use std:: env;
1313use std:: process;
1414use std:: sync:: Arc ;
15- use tokio:: sync:: RwLock ;
15+ use tokio:: sync:: { RwLock , Semaphore } ;
1616use storage:: engine:: {
1717 AppState , ClusterData , delete_value, get_value, get_table_store, join_cluster, put_value,
1818 get_all_keys, get_multiple_keys, NodeInfo , NodeStatus , current_timestamp,
@@ -162,7 +162,13 @@ async fn main() -> std::io::Result<()> {
162162 }
163163 }
164164 }
165+ let http_client = reqwest:: Client :: builder ( )
166+ . timeout ( std:: time:: Duration :: from_secs ( 3 ) )
167+ . build ( )
168+ . unwrap ( ) ;
165169
170+ // 2) Build a semaphore to cap at 20 concurrent replications
171+ let sem = Arc :: new ( Semaphore :: new ( 20 ) ) ;
166172 // Spawn the periodic cold save task.
167173 tokio:: spawn ( cold_save ( state. clone ( ) , 30 ) ) ;
168174
@@ -216,6 +222,8 @@ async fn main() -> std::io::Result<()> {
216222 . app_data ( metrics_collector. clone ( ) )
217223 . app_data ( subscription_manager. clone ( ) )
218224 . app_data ( state. clone ( ) )
225+ . app_data ( web:: Data :: new ( http_client. clone ( ) ) )
226+ . app_data ( web:: Data :: new ( sem. clone ( ) ) )
219227 . app_data ( cluster_data. clone ( ) )
220228 . app_data ( web:: Data :: new ( current_node. clone ( ) ) )
221229 // Cluster management endpoints.
@@ -258,6 +266,8 @@ async fn main() -> std::io::Result<()> {
258266 . app_data ( metrics_collector. clone ( ) )
259267 . app_data ( subscription_manager. clone ( ) )
260268 . app_data ( state. clone ( ) )
269+ . app_data ( web:: Data :: new ( http_client. clone ( ) ) )
270+ . app_data ( web:: Data :: new ( sem. clone ( ) ) )
261271 . app_data ( cluster_data. clone ( ) )
262272 . app_data ( web:: Data :: new ( current_node. clone ( ) ) )
263273 // Cluster management endpoints.
0 commit comments