]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/DaemonState: Minimise time we hold the DaemonStateIndex lock
authorBrad Hubbard <bhubbard@redhat.com>
Wed, 30 Jul 2025 23:12:23 +0000 (09:12 +1000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Mon, 22 Sep 2025 09:48:09 +0000 (09:48 +0000)
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)
(cherry picked from commit 2d227ab51fd72313fb359a0bf7b53722fe793fbc)

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>