]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix bucket re-creation on secondary region
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 17 Jul 2013 23:34:50 +0000 (16:34 -0700)
committerGreg Farnum <greg@inktank.com>
Fri, 19 Jul 2013 20:21:49 +0000 (13:21 -0700)
We had a problem with bucket recreation, where we identified
that bucket has already existed, but missed the fact that it's
the same bucket, so removal of the bucket index was wrong.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_rados.cc

index 067a1adbabdeb16debe2cbe6fca95aaaf9041386..308adff5ae9307f54a78231ceee81f22a6538d93 100644 (file)
@@ -1835,21 +1835,7 @@ int RGWRados::create_bucket(RGWUserInfo& owner, rgw_bucket& bucket,
       info.creation_time = creation_time;
     ret = put_linked_bucket_info(info, exclusive, 0, &attrs, true);
     if (ret == -EEXIST) {
-      /* remove bucket meta instance */
-      string entry;
-      get_bucket_instance_entry(bucket, entry);
-      r = rgw_bucket_instance_remove_entry(this, entry, &info.objv_tracker);
-      if (r < 0)
-        return r;
-
-      /* remove bucket index */
-      librados::IoCtx index_ctx; // context for new bucket
-      int r = open_bucket_index_ctx(bucket, index_ctx);
-      if (r < 0)
-        return r;
-
-      /* we need to reread the info and return it, caller will have a use for it */
-      index_ctx.remove(dir_oid);
+       /* we need to reread the info and return it, caller will have a use for it */
       r = get_bucket_info(NULL, bucket.name, info, NULL, NULL);
       if (r < 0) {
         if (r == -ENOENT) {
@@ -1858,6 +1844,24 @@ int RGWRados::create_bucket(RGWUserInfo& owner, rgw_bucket& bucket,
         ldout(cct, 0) << "get_bucket_info returned " << r << dendl;
         return r;
       }
+
+      /* only remove it if it's a different bucket instance */
+      if (info.bucket.bucket_id != bucket.bucket_id) {
+        /* remove bucket meta instance */
+        string entry;
+        get_bucket_instance_entry(bucket, entry);
+        r = rgw_bucket_instance_remove_entry(this, entry, &info.objv_tracker);
+        if (r < 0)
+          return r;
+
+        /* remove bucket index */
+        librados::IoCtx index_ctx; // context for new bucket
+        int r = open_bucket_index_ctx(bucket, index_ctx);
+        if (r < 0)
+          return r;
+
+        index_ctx.remove(dir_oid);
+      }
       /* ret == -ENOENT here */
     }
     return ret;