From 4f4bdbd5cb84bc84fd578d56fc3340ef4173b025 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 17 Jul 2013 16:34:50 -0700 Subject: [PATCH] rgw: fix bucket re-creation on secondary region 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 --- src/rgw/rgw_rados.cc | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 067a1adbabde..308adff5ae93 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -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; -- 2.47.3