]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Initialize logs on layout initialization 39032/head
authorAdam C. Emerson <aemerson@redhat.com>
Fri, 15 Jan 2021 23:41:37 +0000 (18:41 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 22 Jan 2021 20:46:42 +0000 (15:46 -0500)
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h
src/rgw/rgw_rados.cc

index f1fd131c10e4e85d1c3c07eb1d250dbe582669bc..50b4d9e413287fe6b8910a163be5c42b6a03eade 100644 (file)
@@ -43,6 +43,7 @@
 #include "rgw_common.h"
 #include "rgw_reshard.h"
 #include "rgw_lc.h"
+#include "rgw_bucket_layout.h"
 
 // stolen from src/cls/version/cls_version.cc
 #define VERSION_ATTR "ceph.objclass.version"
@@ -2530,14 +2531,31 @@ int RGWBucketInstanceMetadataHandler::do_put(RGWSI_MetaBackend_Handler::Op *op,
   return do_put_operate(&put_op);
 }
 
-void init_default_bucket_layout(CephContext *cct, RGWBucketInfo& info, const RGWZone& zone) {
-  info.layout.current_index.gen = 0;
-  info.layout.current_index.layout.normal.hash_type = rgw::BucketHashType::Mod;
-  info.layout.current_index.layout.type = rgw::BucketIndexType::Normal;
+void init_default_bucket_layout(CephContext *cct, rgw::BucketLayout& layout,
+                               const RGWZone& zone,
+                               std::optional<uint32_t> shards,
+                               std::optional<rgw::BucketIndexType> type) {
+  layout.current_index.gen = 0;
+  layout.current_index.layout.normal.hash_type = rgw::BucketHashType::Mod;
 
-  info.layout.current_index.layout.normal.num_shards = (
-      cct->_conf->rgw_override_bucket_index_max_shards > 0 ?
-      cct->_conf->rgw_override_bucket_index_max_shards : zone.bucket_index_max_shards);
+  layout.current_index.layout.type =
+    type.value_or(rgw::BucketIndexType::Normal);
+
+  if (shards) {
+    layout.current_index.layout.normal.num_shards = *shards;
+  } else if (cct->_conf->rgw_override_bucket_index_max_shards > 0) {
+    layout.current_index.layout.normal.num_shards =
+      cct->_conf->rgw_override_bucket_index_max_shards;
+  } else {
+    layout.current_index.layout.normal.num_shards =
+      zone.bucket_index_max_shards;
+  }
+
+  if (layout.current_index.layout.type == rgw::BucketIndexType::Normal) {
+    layout.logs.push_back(log_layout_from_index(
+                           layout.current_index.gen,
+                           layout.current_index.layout.normal));
+  }
 }
 
 int RGWMetadataHandlerPut_BucketInstance::put_check()
@@ -2550,12 +2568,17 @@ int RGWMetadataHandlerPut_BucketInstance::put_check()
 
   RGWBucketCompleteInfo *old_bci = (orig_obj ? &orig_obj->get_bci() : nullptr);
 
-  bool exists = (!!orig_obj);
+  const bool exists = (!!orig_obj);
 
   if (from_remote_zone) {
     // don't sync bucket layout changes
     if (!exists) {
-      init_default_bucket_layout(cct, bci.info, bihandler->svc.zone->get_zone());
+      auto& bci_index = bci.info.layout.current_index.layout;
+      auto index_type = bci_index.type;
+      auto num_shards = bci_index.normal.num_shards;
+      init_default_bucket_layout(cct, bci.info.layout,
+                                bihandler->svc.zone->get_zone(),
+                                num_shards, index_type);
     } else {
       bci.info.layout = old_bci->info.layout;
     }
index ef70037ef5b71c78cb12993cba68eab86362f572..81d076bce5d9155f4bbce6bd5b879e8b04e3b7d2 100644 (file)
@@ -57,7 +57,10 @@ extern void rgw_parse_url_bucket(const string& bucket,
 // conforms to the type declaration of RGWRados::check_filter_t.
 extern bool rgw_bucket_object_check_filter(const string& oid);
 
-extern void init_default_bucket_layout(CephContext *cct, RGWBucketInfo& info, const RGWZone& zone);
+void init_default_bucket_layout(CephContext *cct, rgw::BucketLayout& layout,
+                               const RGWZone& zone,
+                               std::optional<uint32_t> shards,
+                               std::optional<rgw::BucketIndexType> type);
 
 struct RGWBucketCompleteInfo {
   RGWBucketInfo info;
index 1ab15e874a98d070c8f7be9ebdfa1f8cb62de73b..5a455340d233a9cb2a3a101d4d13f14fd5a672e2 100644 (file)
@@ -2238,19 +2238,12 @@ int RGWRados::create_bucket(const RGWUserInfo& owner, rgw_bucket& bucket,
     info.placement_rule = selected_placement_rule;
     info.swift_ver_location = swift_ver_location;
     info.swift_versioning = (!swift_ver_location.empty());
-    init_default_bucket_layout(cct, info, svc.zone->get_zone());
-    if (pmaster_num_shards) {
-      // TODO: remove this once sync doesn't require the same shard count
-      info.layout.current_index.layout.normal.num_shards = *pmaster_num_shards;
-    }
-    info.layout.current_index.layout.normal.hash_type = rgw::BucketHashType::Mod;
-    info.layout.current_index.layout.type = rule_info.index_type;
-    if (info.layout.current_index.layout.type == rgw::BucketIndexType::Normal) {
-      // use the same index layout for the bilog
-      const auto gen = info.layout.current_index.gen;
-      const auto& index = info.layout.current_index.layout.normal;
-      info.layout.logs.push_back(rgw::log_layout_from_index(gen, index));
-    }
+
+    init_default_bucket_layout(cct, info.layout, svc.zone->get_zone(),
+                              pmaster_num_shards ?
+                              std::optional{*pmaster_num_shards} :
+                              std::nullopt,
+                              rule_info.index_type);
 
     info.requester_pays = false;
     if (real_clock::is_zero(creation_time)) {