]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/DaemonState: Minimise time we hold the DaemonStateIndex lock 65464/head
authorBrad Hubbard <bhubbard@redhat.com>
Wed, 30 Jul 2025 23:12:23 +0000 (09:12 +1000)
committerPrashant D <pdhange@redhat.com>
Wed, 10 Sep 2025 01:31:04 +0000 (21:31 -0400)
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>
(cherry picked from commit b4304d521f61b61515cade872824210e7d67f6db)

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>