]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: update bucket instance with resharding details
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 24 May 2017 23:01:25 +0000 (16:01 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 5 Jun 2017 20:17:59 +0000 (13:17 -0700)
can be useful info for later in a cross zone sync

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_bucket.cc
src/rgw/rgw_common.h
src/rgw/rgw_json_enc.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_reshard.cc

index 8302b5a8e7fb338c885a1e2b69ded4227cd2cd8b..9d96adcd5a5d089872bd41410197f8dce2367957 100644 (file)
@@ -857,7 +857,7 @@ int RGWBucket::link(RGWBucketAdminOpState& op_state, std::string *err_msg)
     policy.create_default(user_info.user_id, display_name);
 
     owner = policy.get_owner();
-    r = store->set_bucket_owner(bucket, owner);
+    r = store->set_bucket_owner(bucket_info.bucket, owner);
     if (r < 0) {
       set_err_msg(err_msg, "failed to set bucket owner: " + cpp_strerror(-r));
       return r;
index fb78c4a0c9a06025413633febac3741133e33c54..30234bb9ae016f5df775d7622b52e412064ea317 100644 (file)
@@ -1184,7 +1184,7 @@ struct RGWBucketInfo
   map<string, uint32_t> mdsearch_config;
 
   /* resharding */
-  bool resharding;
+  uint8_t reshard_status;
   string new_bucket_instance_id;
 
   void encode(bufferlist& bl) const {
@@ -1213,7 +1213,7 @@ struct RGWBucketInfo
      }
      ::encode(creation_time, bl);
      ::encode(mdsearch_config, bl);
-     ::encode(resharding, bl);
+     ::encode(reshard_status, bl);
      ::encode(new_bucket_instance_id, bl);
      ENCODE_FINISH(bl);
   }
@@ -1279,7 +1279,7 @@ struct RGWBucketInfo
        ::decode(mdsearch_config, bl);
      }
      if (struct_v >= 19) {
-       ::decode(resharding, bl);
+       ::decode(reshard_status, bl);
        ::decode(new_bucket_instance_id, bl);
      }
      DECODE_FINISH(bl);
@@ -1299,7 +1299,7 @@ struct RGWBucketInfo
   }
 
   RGWBucketInfo() : flags(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD), requester_pays(false),
-                    has_website(false), swift_versioning(false),resharding(false) {}
+                    has_website(false), swift_versioning(false), reshard_status(0) {}
 };
 WRITE_CLASS_ENCODER(RGWBucketInfo)
 
index a77024e23fdb0c6c793b386d1157fd2445fcebf7..dbdaab310963ca1e02f1bc5dcdebc1058020e4f2 100644 (file)
@@ -738,7 +738,7 @@ void RGWBucketInfo::dump(Formatter *f) const
   encode_json("swift_ver_location", swift_ver_location, f);
   encode_json("index_type", (uint32_t)index_type, f);
   encode_json("mdsearch_config", mdsearch_config, f);
-  encode_json("resharding", resharding, f);
+  encode_json("reshard_status", (int)reshard_status, f);
   encode_json("new_bucket_instance_id", new_bucket_instance_id, f);
 }
 
@@ -772,7 +772,9 @@ void RGWBucketInfo::decode_json(JSONObj *obj) {
   JSONDecoder::decode_json("index_type", it, obj);
   index_type = (RGWBucketIndexType)it;
   JSONDecoder::decode_json("mdsearch_config", mdsearch_config, obj);
-  JSONDecoder::decode_json("resharding", resharding, obj);
+  int rs;
+  JSONDecoder::decode_json("reshard_status", rs, obj);
+  reshard_status = (cls_rgw_reshard_status)rs;
   JSONDecoder::decode_json("new_bucket_instance_id",new_bucket_instance_id, obj);
 }
 
index 72e222274fbaf94f5f0d0416a8c66e6975ecfbd8..23914530c0cc0055635f806deffff2a3813ccc9e 100644 (file)
@@ -8269,7 +8269,12 @@ int RGWRados::set_bucket_owner(rgw_bucket& bucket, ACLOwner& owner)
   RGWBucketInfo info;
   map<string, bufferlist> attrs;
   RGWObjectCtx obj_ctx(this);
-  int r = get_bucket_info(obj_ctx, bucket.tenant, bucket.name, info, NULL, &attrs);
+  int r;
+  if (bucket.bucket_id.empty()) {
+    r = get_bucket_info(obj_ctx, bucket.tenant, bucket.name, info, NULL, &attrs);
+  } else {
+    r = get_bucket_instance_info(obj_ctx, bucket, info, nullptr, &attrs);
+  }
   if (r < 0) {
     ldout(cct, 0) << "NOTICE: get_bucket_info on bucket=" << bucket.name << " returned err=" << r << dendl;
     return r;
index da43cef42d0fbb9182cf1476597c5a082301a8fc..faa15080f2d7c74d1868fd5f3cb0e309fcc8a5e8 100644 (file)
@@ -253,8 +253,11 @@ int RGWBucketReshard::clear_resharding()
   return 0;
 }
 
-int RGWBucketReshard::create_new_bucket_instance(int new_num_shards,
-                                                 RGWBucketInfo& new_bucket_info)
+static int create_new_bucket_instance(RGWRados *store,
+                                     int new_num_shards,
+                                     const RGWBucketInfo& bucket_info,
+                                     map<string, bufferlist>& attrs,
+                                     RGWBucketInfo& new_bucket_info)
 {
   new_bucket_info = bucket_info;
 
@@ -264,21 +267,81 @@ int RGWBucketReshard::create_new_bucket_instance(int new_num_shards,
   new_bucket_info.num_shards = new_num_shards;
   new_bucket_info.objv_tracker.clear();
 
+  new_bucket_info.new_bucket_instance_id.clear();
+  new_bucket_info.reshard_status = 0;
+
   int ret = store->init_bucket_index(new_bucket_info, new_bucket_info.num_shards);
   if (ret < 0) {
-    derr << "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret) << dendl;
+    cerr << "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret) << std::endl;
     return -ret;
   }
 
-  ret = store->put_bucket_instance_info(new_bucket_info, true, real_time(), &bucket_attrs);
+  ret = store->put_bucket_instance_info(new_bucket_info, true, real_time(), &attrs);
   if (ret < 0) {
-    derr << "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret) << dendl;
+    cerr << "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret) << std::endl;
     return -ret;
   }
 
   return 0;
 }
 
+int RGWBucketReshard::create_new_bucket_instance(int new_num_shards,
+                                                 RGWBucketInfo& new_bucket_info)
+{
+  return ::create_new_bucket_instance(store, new_num_shards, bucket_info, bucket_attrs, new_bucket_info);
+}
+
+class BucketInfoReshardUpdate
+{
+  RGWRados *store;
+  RGWBucketInfo bucket_info;
+  std::map<string, bufferlist> bucket_attrs;
+
+  bool in_progress{false};
+
+  int set_status(cls_rgw_reshard_status s) {
+    bucket_info.reshard_status = s;
+    int ret = store->put_bucket_instance_info(bucket_info, false, real_time(), &bucket_attrs);
+    if (ret < 0) {
+      ldout(store->ctx(), 0) << "ERROR: failed to write bucket info, ret=" << ret << dendl;
+      return ret;
+    }
+    return 0;
+  }
+
+public:
+  BucketInfoReshardUpdate(RGWRados *_store, RGWBucketInfo& _bucket_info,
+                          map<string, bufferlist>& _bucket_attrs, const string& new_bucket_id) : store(_store), 
+                                                                                                 bucket_info(_bucket_info),
+                                                                                                 bucket_attrs(_bucket_attrs) {
+    bucket_info.new_bucket_instance_id = new_bucket_id;
+  }
+  ~BucketInfoReshardUpdate() {
+    if (in_progress) {
+      bucket_info.new_bucket_instance_id.clear();
+      set_status(CLS_RGW_RESHARD_NONE);
+    }
+  }
+
+  int start() {
+    int ret = set_status(CLS_RGW_RESHARD_IN_PROGRESS);
+    if (ret < 0) {
+      return ret;
+    }
+    in_progress = true;
+    return 0;
+  }
+
+  int complete() {
+    int ret = set_status(CLS_RGW_RESHARD_DONE);
+    if (ret < 0) {
+      return ret;
+    }
+    in_progress = false;
+    return 0;
+  }
+};
+
 int RGWBucketReshard::do_reshard(
                   int num_shards,
                   const RGWBucketInfo& new_bucket_info,
@@ -300,6 +363,7 @@ int RGWBucketReshard::do_reshard(
     (*out) << "new bucket instance id: " << new_bucket_info.bucket.bucket_id << std::endl;
   }
 
+  /* update bucket info  -- in progress*/
   list<rgw_cls_bi_entry> entries;
 
   if (max_entries < 0) {
@@ -307,6 +371,14 @@ int RGWBucketReshard::do_reshard(
     return -EINVAL;
   }
 
+  BucketInfoReshardUpdate bucket_info_updater(store, bucket_info, bucket_attrs, new_bucket_info.bucket.bucket_id);
+
+  ret = bucket_info_updater.start();
+  if (ret < 0) {
+    ldout(store->ctx(), 0) << __func__ << ": failed to update bucket info ret=" << ret << dendl;
+    return ret;
+  }
+
   int num_target_shards = (new_bucket_info.num_shards > 0 ? new_bucket_info.num_shards : 1);
 
   BucketReshardManager target_shards_mgr(store, new_bucket_info, num_target_shards);
@@ -403,6 +475,12 @@ int RGWBucketReshard::do_reshard(
     lderr(store->ctx()) << "failed to link new bucket instance (bucket_id=" << new_bucket_info.bucket.bucket_id << ": " << err << "; " << cpp_strerror(-r) << ")" << dendl;
     return -r;
   }
+
+  ret = bucket_info_updater.complete();
+  if (ret < 0) {
+    ldout(store->ctx(), 0) << __func__ << ": failed to update bucket info ret=" << ret << dendl;
+    /* don't error out, reshard process succeeded */
+  }
   return 0;
 }
 
@@ -447,7 +525,6 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries,
     unlock_bucket();
     return ret;
   }
-
   ret = set_resharding_status(new_bucket_info.bucket.bucket_id, num_shards, CLS_RGW_RESHARD_IN_PROGRESS);
   if (ret < 0) {
     unlock_bucket();
@@ -634,34 +711,6 @@ int RGWReshardWait::block_while_resharding(RGWRados::BucketShard *bs, string *ne
 }
 
 
-static  int create_new_bucket_instance(RGWRados *store,
-                                     int new_num_shards,
-                                     const RGWBucketInfo& bucket_info,
-                                     map<string, bufferlist>& attrs,
-                                     RGWBucketInfo& new_bucket_info)
-{
-
-  store->create_bucket_id(&new_bucket_info.bucket.bucket_id);
-  new_bucket_info.bucket.oid.clear();
-
-  new_bucket_info.num_shards = new_num_shards;
-  new_bucket_info.objv_tracker.clear();
-
-  int ret = store->init_bucket_index(new_bucket_info, new_bucket_info.num_shards);
-  if (ret < 0) {
-    cerr << "ERROR: failed to init new bucket indexes: " << cpp_strerror(-ret) << std::endl;
-    return -ret;
-  }
-
-  ret = store->put_bucket_instance_info(new_bucket_info, true, real_time(), &attrs);
-  if (ret < 0) {
-    cerr << "ERROR: failed to store new bucket instance info: " << cpp_strerror(-ret) << std::endl;
-    return -ret;
-  }
-
-  return 0;
-}
-
 int RGWReshard::process_single_logshard(int logshard_num)
 {
   string marker;