]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/dynamic-resharding: Allow clean_index to take generation number as a parameter.
authorShilpa Jagannath <smanjara@redhat.com>
Thu, 21 May 2020 12:59:15 +0000 (18:29 +0530)
committerCasey Bodley <cbodley@redhat.com>
Thu, 4 Feb 2021 22:19:45 +0000 (17:19 -0500)
Signed-off-by: Shilpa Jagannath <smanjara@redhat.com>
src/rgw/rgw_rados.cc
src/rgw/rgw_reshard.cc
src/rgw/services/svc_bi.h
src/rgw/services/svc_bi_rados.cc
src/rgw/services/svc_bi_rados.h

index 51c942dd527ed2eaa4ee700e6e61acf1d7400240..2d1ffd10ae2797e33dff5e4bdd71b7cdaa5f638a 100644 (file)
@@ -2291,7 +2291,7 @@ int RGWRados::create_bucket(const RGWUserInfo& owner, rgw_bucket& bucket,
 
       /* only remove it if it's a different bucket instance */
       if (orig_info.bucket.bucket_id != bucket.bucket_id) {
-       int r = svc.bi->clean_index(info);
+       int r = svc.bi->clean_index(info, std::nullopt);
         if (r < 0) {
          ldout(cct, 0) << "WARNING: could not remove bucket index (r=" << r << ")" << dendl;
        }
@@ -8987,7 +8987,6 @@ int RGWRados::cls_bucket_head(const RGWBucketInfo& bucket_info, const rgw::bucke
   }
 
   r = CLSRGWIssueGetDirHeader(index_pool.ioctx(), oids, list_results, cct->_conf->rgw_bucket_index_max_aio)();
-  ldout(cct, 20) << "CLSRGWIssueGetDirHeader issued" << dendl;
   if (r < 0) {
     ldout(cct, 20) << "cls_bucket_head: CLSRGWIssueGetDirHeader() returned "
                    << r << dendl;
index 719c6b75bc2ae7730211a529528f30bedd5d7181..c34ad880a90ff44bf4966c6f3f5212ade742dd5d 100644 (file)
@@ -681,14 +681,13 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries,
 
   ret = update_num_shards(num_shards, dpp);
   if (ret < 0) {
-    return ret;
+    // shard state is uncertain, but this will attempt to remove them anyway
     goto error_out;
   }
 
   if (reshard_log) {
     ret = reshard_log->update(bucket_info);
     if (ret < 0) {
-      return ret;
       goto error_out;
     }
   }
@@ -719,7 +718,7 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries,
    // at this point since all we're using a best effor to to remove old
    // shard objects
 
-   ret = store->svc()->bi->clean_index(bucket_info);
+   ret = store->svc()->bi->clean_index(bucket_info, std::nullopt);
    if (ret < 0) {
      lderr(store->ctx()) << "Error: " << __func__ <<
       " failed to clean up old shards; " <<
@@ -740,7 +739,7 @@ error_out:
   // since the real problem is the issue that led to this error code
   // path, we won't touch ret and instead use another variable to
   // temporarily error codes
-  int ret2 = store->svc()->bi->clean_index(bucket_info);
+  int ret2 = store->svc()->bi->clean_index(bucket_info, std::nullopt);
   if (ret2 < 0) {
     lderr(store->ctx()) << "Error: " << __func__ <<
       " failed to clean up shards from failed incomplete resharding; " <<
@@ -780,6 +779,10 @@ void RGWReshard::get_bucket_logshard_oid(const string& tenant, const string& buc
 
 int RGWReshard::add(cls_rgw_reshard_entry& entry)
 {
+  if (!store->svc()->zone->can_reshard()) {
+    ldout(store->ctx(), 20) << __func__ << " Resharding is disabled"  << dendl;
+    return 0;
+  }
 
   string logshard_oid;
 
index cf6e605c87c3a882f09f93ba0927d1e412180919..93d5a033f0303e75ef4ffa7aa7a64331fff6952c 100644 (file)
@@ -30,7 +30,7 @@ public:
   virtual ~RGWSI_BucketIndex() {}
 
   virtual int init_index(RGWBucketInfo& bucket_info) = 0;
-  virtual int clean_index(RGWBucketInfo& bucket_info) = 0;
+  virtual int clean_index(RGWBucketInfo& bucket_info, std::optional<uint64_t> gen) = 0;
 
   virtual int read_stats(const RGWBucketInfo& bucket_info,
                          RGWBucketEnt *stats,
index a13d1a8c5c539c64cad84611e0b3fdbaa53f886e..5dc747580a4bd0f4ecb32ad7f6a58618a28804a1 100644 (file)
@@ -112,6 +112,45 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index(const RGWBucketInfo& bucket_info,
   return 0;
 }
 
+static void get_bucket_index_objects(const string& bucket_oid_base,
+                                     uint32_t num_shards, std::optional<uint64_t> _gen_id,
+                                     map<int, string> *_bucket_objects,
+                                     int shard_id = -1)
+{
+  auto& bucket_objects = *_bucket_objects;
+  auto gen_id = _gen_id.value_or(0);
+  if (!num_shards) {
+    bucket_objects[0] = bucket_oid_base;
+  } else {
+    char buf[bucket_oid_base.size() + 64];
+    if (shard_id < 0) {
+      for (uint32_t i = 0; i < num_shards; ++i) {
+        if (gen_id) {
+          snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, i);
+          bucket_objects[i] = buf;
+          } else {
+            snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), i);
+            bucket_objects[i] = buf;
+          }
+      }
+    } else {
+      if ((uint32_t)shard_id > num_shards) {
+        return;
+      } else {
+               if (gen_id) {
+                 snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id);
+                 bucket_objects[shard_id] = buf;
+               } else {
+                 // for backward compatibility, gen_id(0) will not be added in the object name
+                 snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), shard_id);
+                 bucket_objects[shard_id] = buf;
+               }
+      }
+    }
+  }
+}
+
+/*
 static void get_bucket_index_objects(const string& bucket_oid_base,
                                      uint32_t num_shards,
                                      map<int, string> *_bucket_objects,
@@ -136,6 +175,7 @@ static void get_bucket_index_objects(const string& bucket_oid_base,
     }
   }
 }
+*/
 
 static void get_bucket_instance_ids(const RGWBucketInfo& bucket_info,
                                     int shard_id,
@@ -179,10 +219,8 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index(const RGWBucketInfo& bucket_info,
     return ret;
   }
 
-  //auto gen = bucket_info.layout.current_index.gen;
-
- // TODO: need reshard changes to add gen_id here
-  get_bucket_index_objects(bucket_oid_base, bucket_info.layout.current_index.layout.normal.num_shards, bucket_objs, shard_id);
+  get_bucket_index_objects(bucket_oid_base, idx_layout.layout.normal.num_shards,
+                           idx_layout.gen, bucket_objs, shard_id);
   if (bucket_instance_ids) {
     // TODO: generation need to be passed here
     get_bucket_instance_ids(bucket_info, shard_id, bucket_instance_ids);
@@ -202,8 +240,9 @@ void RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_b
   } else {
     char buf[bucket_oid_base.size() + 64];
     if (gen_id != 0) {
-      snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id); 
+      snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id);
       (*bucket_obj) = buf;
+         ldout(cct, 10) << "bucket_obj is " << (*bucket_obj) << dendl;
     } else {
       // for backward compatibility, gen_id(0) will not be added in the object name
       snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), shard_id);
@@ -273,7 +312,7 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket
 
 int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket_info,
                                                      int shard_id,
-                                                     const rgw::bucket_index_layout_generation& idx_layout,
+                                                     const rgw::bucket_index_layout_generation& target_layout,
                                                      RGWSI_RADOS::Obj *bucket_obj)
 {
   RGWSI_RADOS::Pool index_pool;
@@ -287,8 +326,8 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket
 
   string oid;
 
-  get_bucket_index_object(bucket_oid_base, idx_layout.layout.normal.num_shards,
-                          shard_id, idx_layout.gen, &oid);
+  get_bucket_index_object(bucket_oid_base, target_layout.layout.normal.num_shards,
+                          shard_id, target_layout.gen, &oid);
 
   *bucket_obj = svc.rados->obj(index_pool, oid);
 
@@ -324,7 +363,6 @@ int RGWSI_BucketIndex_RADOS::cls_bucket_head(const RGWBucketInfo& bucket_info,
   return 0;
 }
 
-
 int RGWSI_BucketIndex_RADOS::init_index(RGWBucketInfo& bucket_info)
 {
   RGWSI_RADOS::Pool index_pool;
@@ -338,14 +376,15 @@ int RGWSI_BucketIndex_RADOS::init_index(RGWBucketInfo& bucket_info)
   dir_oid.append(bucket_info.bucket.bucket_id);
 
   map<int, string> bucket_objs;
-  get_bucket_index_objects(dir_oid, bucket_info.layout.current_index.layout.normal.num_shards, &bucket_objs);
+  get_bucket_index_objects(dir_oid, bucket_info.layout.current_index.layout.normal.num_shards, std::nullopt, &bucket_objs);
 
   return CLSRGWIssueBucketIndexInit(index_pool.ioctx(),
                                    bucket_objs,
                                    cct->_conf->rgw_bucket_index_max_aio)();
 }
 
-int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info)
+
+int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info, std::optional<uint64_t> gen)
 {
   RGWSI_RADOS::Pool index_pool;
 
@@ -358,7 +397,7 @@ int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info)
   dir_oid.append(bucket_info.bucket.bucket_id);
 
   std::map<int, std::string> bucket_objs;
-  get_bucket_index_objects(dir_oid, bucket_info.layout.current_index.layout.normal.num_shards, &bucket_objs);
+  get_bucket_index_objects(dir_oid, bucket_info.layout.current_index.layout.normal.num_shards, gen.value_or(0), &bucket_objs);
 
   return CLSRGWIssueBucketIndexClean(index_pool.ioctx(),
                                     bucket_objs,
index b7a09acf497334dec3e37a5753fc49fd7171692f..918697ad035a869a3ad137581ab02a0623f560ce 100644 (file)
@@ -94,8 +94,7 @@ public:
   }
 
   int init_index(RGWBucketInfo& bucket_info);
-  int clean_index(RGWBucketInfo& bucket_info);
-
+  int clean_index(RGWBucketInfo& bucket_info, std::optional<uint64_t> gen);
 
   /* RADOS specific */