]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/DaemonState: Minimise time we hold the DaemonStateIndex lock 64764/head
authorBrad Hubbard <bhubbard@redhat.com>
Wed, 30 Jul 2025 23:12:23 +0000 (09:12 +1000)
committerBrad Hubbard <bhubbard@redhat.com>
Tue, 5 Aug 2025 00:55:48 +0000 (10:55 +1000)
Calling back into python functions whilst holding the lock can result in
this thread being queued for the GIL and resulting in extended delays
for threads waiting to acquire the lock.

Fixes: https://tracker.ceph.com/issues/72337
Signed-off-by: Brad Hubbard <bhubbard@redhat.com>
src/mgr/DaemonState.h

index d78e819405b02c1372356fdc4c36e02a44a314e9..960cbcbd3026c92ab6ed81856970167933508929 100644 (file)
@@ -261,9 +261,12 @@ public:
   template<typename Callback, typename...Args>
   auto with_daemons_by_server(Callback&& cb, Args&&... args) const ->
     decltype(cb(by_server, std::forward<Args>(args)...)) {
-    std::shared_lock l{lock};
-    
-    return std::forward<Callback>(cb)(by_server, std::forward<Args>(args)...);
+    const decltype(by_server) by_server_copy = [&] {
+      // Don't hold the lock any longer than necessary
+      std::shared_lock l{lock};
+      return by_server;
+    }();
+    return std::forward<Callback>(cb)(by_server_copy, std::forward<Args>(args)...);
   }
 
   template<typename Callback, typename...Args>