]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Don't hold mutex over yield in LazyFIFO 54505/head
authorAdam Emerson <aemerson@redhat.com>
Thu, 21 Dec 2023 19:54:08 +0000 (14:54 -0500)
committerAdam Emerson <aemerson@redhat.com>
Thu, 21 Dec 2023 19:57:50 +0000 (14:57 -0500)
If the FIFO doesn't exist, let clients race to create it, then stash
and use whoever wins.

Fixes: https://tracker.ceph.com/issues/63373
Signed-off-by: Adam Emerson <aemerson@redhat.com>
src/rgw/driver/rados/rgw_log_backing.h

index 3dfdb8ee4ef11b342a88658bb80b472cd27edc6b..6cda9a4ca9787834dc8b35b0a1cb6140082750e2 100644 (file)
@@ -262,12 +262,24 @@ class LazyFIFO {
 
   int lazy_init(const DoutPrefixProvider *dpp, optional_yield y) {
     std::unique_lock l(m);
-    if (fifo) return 0;
-    auto r = rgw::cls::fifo::FIFO::create(dpp, ioctx, oid, &fifo, y);
-    if (r) {
-      fifo.reset();
+    if (fifo) {
+      return 0;
+    } else {
+      l.unlock();
+      // FIFO supports multiple clients by design, so it's safe to
+      // race to create them.
+      std::unique_ptr<rgw::cls::fifo::FIFO> fifo_tmp;
+      auto r = rgw::cls::fifo::FIFO::create(dpp, ioctx, oid, &fifo, y);
+      if (r) {
+       return r;
+      }
+      l.lock();
+      if (!fifo) {
+       // We won the race
+       fifo = std::move(fifo_tmp);
+      }
     }
-    return r;
+    return 0;
   }
 
 public: