File tree Expand file tree Collapse file tree 2 files changed +203
-60
lines changed
linera-core/src/client/requests_scheduler Expand file tree Collapse file tree 2 files changed +203
-60
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,43 @@ impl<N: Clone> InFlightTracker<N> {
173173 let peers = entry. alternative_peers . read ( ) . await ;
174174 Some ( peers. clone ( ) )
175175 }
176+
177+ /// Removes a specific peer from the alternative peers list.
178+ ///
179+ /// # Arguments
180+ /// - `key`: The request key to look up
181+ /// - `peer`: The peer to remove from alternatives
182+ pub ( super ) async fn remove_alternative_peer ( & self , key : & RequestKey , peer : & N )
183+ where
184+ N : PartialEq + Eq ,
185+ {
186+ if let Some ( entry) = self . entries . read ( ) . await . get ( key) {
187+ let mut alt_peers = entry. alternative_peers . write ( ) . await ;
188+ alt_peers. retain ( |p| p != peer) ;
189+ }
190+ }
191+
192+ /// Pops and returns one alternative peer if available.
193+ ///
194+ /// Atomically removes and returns the first alternative peer from the list
195+ /// for the given request key. Returns None if no entry exists or no alternatives
196+ /// are available.
197+ ///
198+ /// # Arguments
199+ /// - `key`: The request key to look up
200+ ///
201+ /// # Returns
202+ /// - `Option<N>`: The first alternative peer if available
203+ pub ( super ) async fn pop_alternative_peer ( & self , key : & RequestKey ) -> Option < N > {
204+ let in_flight = self . entries . read ( ) . await ;
205+ if let Some ( entry) = in_flight. get ( key) {
206+ let mut peers = entry. alternative_peers . write ( ) . await ;
207+ if !peers. is_empty ( ) {
208+ return Some ( peers. remove ( 0 ) ) ;
209+ }
210+ }
211+ None
212+ }
176213}
177214
178215/// Type of in-flight request match found.
You can’t perform that action at this time.
0 commit comments