]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: wait for map on create_ioctx failure
authorSage Weil <sage@redhat.com>
Mon, 21 Jul 2014 21:11:42 +0000 (14:11 -0700)
committerJohn Spray <john.spray@redhat.com>
Mon, 25 Aug 2014 00:34:03 +0000 (01:34 +0100)
Ensure we have a map so we don't simply complain that a pool doesn't
exists.  Only take the lock and wait if we fail to lookup the pool,
though, so we avoid contending the lock in the general case.

Signed-off-by: Sage Weil <sage@redhat.com>
src/librados/RadosClient.cc

index 3f6fe74d85dfdddfdc73bd8d001cac2970fc9624..f59cca963cef4c47186fca86220391a4c18ea546 100644 (file)
@@ -315,8 +315,28 @@ librados::RadosClient::~RadosClient()
 int librados::RadosClient::create_ioctx(const char *name, IoCtxImpl **io)
 {
   int64_t poolid = lookup_pool(name);
-  if (poolid < 0)
-    return (int)poolid;
+  if (poolid < 0) {
+    // hmm, first make sure we have *a* map
+    {
+      Mutex::Locker l(lock);
+      int r = wait_for_osdmap();
+      if (r < 0)
+       return r;
+    }
+
+    poolid = lookup_pool(name);
+    if (poolid < 0) {
+      // make sure we have the *latest* map
+      int r = wait_for_latest_osdmap();
+      if (r < 0)
+       return r;
+
+      poolid = lookup_pool(name);
+      if (poolid < 0) {
+       return (int)poolid;
+      }
+    }
+  }
 
   *io = new librados::IoCtxImpl(this, objecter, &lock, poolid, name,
                                CEPH_NOSNAP);