@@ -161,6 +161,16 @@ struct Node {
161161 is_healthy : AtomicBool ,
162162 last_accessed : RwLock < Instant > ,
163163}
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+
164174/// The main entry point for all interactions with the Typesense API.
165175///
166176/// The client manages connections to multiple nodes and provides access to different
@@ -296,13 +306,6 @@ impl Client {
296306 self . nodes . get_safe_unchecked ( index)
297307 }
298308
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-
306309 /// The core execution method that handles multi-node failover and retries.
307310 /// This internal method is called by all public API methods.
308311 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 {
318321 let node = self . get_next_node ( ) ;
319322 match api_call ( & node. config ) . await {
320323 Ok ( response) => {
321- self . set_node_health ( node , true ) ;
324+ node . set_health ( true ) ;
322325 return Ok ( response) ;
323326 }
324327 Err ( e) => {
325328 if is_retriable ( & e) {
326- self . set_node_health ( node , false ) ;
329+ node . set_health ( false ) ;
327330 last_api_error = Some ( e) ;
328331 } else {
329332 return Err ( e. into ( ) ) ;
0 commit comments