fresh-borzoni commented on code in PR #369:
URL: https://github.com/apache/fluss-rust/pull/369#discussion_r2908887936


##########
crates/fluss/src/client/connection.rs:
##########
@@ -76,7 +77,23 @@ impl FlussConnection {
     }
 
     pub async fn get_admin(&self) -> Result<FlussAdmin> {
-        FlussAdmin::new(self.network_connects.clone(), 
self.metadata.clone()).await
+        // 1. Fast path: return cached instance if already initialized.
+        if let Some(admin) = self.admin_client.read().as_ref() {
+            return Ok(admin.clone());
+        }
+
+        // 2. Slow path: acquire write lock.
+        let mut admin_guard = self.admin_client.write();
+
+        // 3. Double-check: another thread may have initialized while we 
waited.
+        if let Some(admin) = admin_guard.as_ref() {
+            return Ok(admin.clone());
+        }
+
+        // 4. Initialize and cache.
+        let admin = FlussAdmin::new(self.network_connects.clone(), 
self.metadata.clone());
+        *admin_guard = Some(admin.clone());
+        Ok(admin)

Review Comment:
   PTAL, if some integration tests depend on `get_admin.await.is_ok()`, we need 
to fix it.
   I think that we  call admin.get_server_nodes() in in python at least, so 
just check that other clients do this as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to