@@ -161,6 +161,16 @@ struct Node {
161
161
is_healthy : AtomicBool ,
162
162
last_accessed : RwLock < Instant > ,
163
163
}
164
+
165
+ impl Node {
166
+ /// Sets the health status of the node
167
+ #[ inline]
168
+ fn set_health ( & self , is_healthy : bool ) {
169
+ * self . last_accessed . write ( ) . unwrap ( ) = Instant :: now ( ) ;
170
+ self . is_healthy . store ( is_healthy, Ordering :: Relaxed ) ;
171
+ }
172
+ }
173
+
164
174
/// The main entry point for all interactions with the Typesense API.
165
175
///
166
176
/// The client manages connections to multiple nodes and provides access to different
@@ -296,13 +306,6 @@ impl Client {
296
306
self . nodes . get_safe_unchecked ( index)
297
307
}
298
308
299
- /// Sets the health status of a given node after a request attempt.
300
- #[ inline]
301
- fn set_node_health ( & self , node : & Node , is_healthy : bool ) {
302
- * node. last_accessed . write ( ) . unwrap ( ) = Instant :: now ( ) ;
303
- node. is_healthy . store ( is_healthy, Ordering :: Relaxed ) ;
304
- }
305
-
306
309
/// The core execution method that handles multi-node failover and retries.
307
310
/// This internal method is called by all public API methods.
308
311
pub ( super ) async fn execute < F , Fut , T , E , ' a > ( & ' a self , api_call : F ) -> Result < T , Error < E > >
@@ -318,12 +321,12 @@ impl Client {
318
321
let node = self . get_next_node ( ) ;
319
322
match api_call ( & node. config ) . await {
320
323
Ok ( response) => {
321
- self . set_node_health ( node , true ) ;
324
+ node . set_health ( true ) ;
322
325
return Ok ( response) ;
323
326
}
324
327
Err ( e) => {
325
328
if is_retriable ( & e) {
326
- self . set_node_health ( node , false ) ;
329
+ node . set_health ( false ) ;
327
330
last_api_error = Some ( e) ;
328
331
} else {
329
332
return Err ( e. into ( ) ) ;
0 commit comments