]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw/rados: create_bucket() can override index type and shards
authorCasey Bodley <cbodley@redhat.com>
Wed, 8 Jan 2025 19:25:20 +0000 (14:25 -0500)
committerCasey Bodley <cbodley@redhat.com>
Tue, 25 Feb 2025 16:15:57 +0000 (11:15 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/driver/rados/rgw_bucket.cc
src/rgw/driver/rados/rgw_bucket.h
src/rgw/driver/rados/rgw_rados.cc
src/rgw/driver/rados/rgw_rados.h
src/rgw/driver/rados/rgw_sal_rados.cc
src/rgw/rgw_sal.h

index d043aea07831a6d85e4713a01ac95338abab310b..0dbc61460414deed479ee19b6421c17f393344cf 100644 (file)
@@ -2805,14 +2805,17 @@ int RGWBucketInstanceMetadataHandler::put(std::string& entry, RGWMetadataObject*
 
 void init_default_bucket_layout(CephContext *cct, rgw::BucketLayout& layout,
                                const RGWZone& zone,
-                               std::optional<rgw::BucketIndexType> type) {
+                               std::optional<rgw::BucketIndexType> type,
+                               std::optional<uint32_t> shards) {
   layout.current_index.gen = 0;
   layout.current_index.layout.normal.hash_type = rgw::BucketHashType::Mod;
 
   layout.current_index.layout.type =
     type.value_or(rgw::BucketIndexType::Normal);
 
-  if (cct->_conf->rgw_override_bucket_index_max_shards > 0) {
+  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 {
@@ -2842,7 +2845,7 @@ int RGWBucketInstanceMetadataHandler::put_prepare(
       bci.info.layout = rgw::BucketLayout{};
       init_default_bucket_layout(dpp->get_cct(), bci.info.layout,
                                 svc_zone->get_zone(),
-                                std::nullopt);
+                                std::nullopt, std::nullopt);
     }
   }
 
index 9ee31c8814e604fec80931b2220edacb8ceb0677..8c2c65da6dd0655b98d970701a507bfe0783c9a6 100644 (file)
@@ -44,7 +44,8 @@ extern bool rgw_bucket_object_check_filter(const std::string& oid);
 
 void init_default_bucket_layout(CephContext *cct, rgw::BucketLayout& layout,
                                const RGWZone& zone,
-                               std::optional<rgw::BucketIndexType> type);
+                               std::optional<rgw::BucketIndexType> type,
+                               std::optional<uint32_t> shards);
 
 struct RGWBucketCompleteInfo {
   RGWBucketInfo info;
index c1534b2e35680b8daf685762c0bce5172b9e8c13..7406cfe54c40ecfbbdac0b5e247d4fe210db31c0 100644 (file)
@@ -2362,6 +2362,8 @@ int RGWRados::create_bucket(const DoutPrefixProvider* dpp,
                             const std::optional<std::string>& swift_ver_location,
                             const std::optional<RGWQuotaInfo>& quota,
                             std::optional<ceph::real_time> creation_time,
+                            std::optional<rgw::BucketIndexType> index_type,
+                            std::optional<uint32_t> index_shards,
                             obj_version* pep_objv,
                             RGWBucketInfo& info)
 {
@@ -2392,8 +2394,11 @@ int RGWRados::create_bucket(const DoutPrefixProvider* dpp,
     }
 
     if (zone_placement) {
+      if (!index_type) {
+        index_type = zone_placement->index_type;
+      }
       init_default_bucket_layout(cct, info.layout, svc.zone->get_zone(),
-                                 zone_placement->index_type);
+                                 index_type, index_shards);
     }
 
     info.requester_pays = false;
index 217159487bf5369b1bceae2a36623d0e8e3b2d6e..a82d737d6e174ae1d102edd28f9de93b57c82786 100644 (file)
@@ -643,6 +643,8 @@ public:
                     const std::optional<std::string>& swift_ver_location,
                     const std::optional<RGWQuotaInfo>& quota,
                     std::optional<ceph::real_time> creation_time,
+                    std::optional<rgw::BucketIndexType> index_type,
+                    std::optional<uint32_t> index_shards,
                     obj_version* pep_objv,
                     RGWBucketInfo& info);
 
index ea2572b4121156a39dfd0ca1d2814d17f79d7406..5093467547f633edc3630daba49d1c282d48cd43 100644 (file)
@@ -174,7 +174,8 @@ int RadosBucket::create(const DoutPrefixProvider* dpp,
       dpp, y, key, params.owner, params.zonegroup_id,
       params.placement_rule, params.zone_placement, params.attrs,
       params.obj_lock_enabled, params.swift_ver_location,
-      params.quota, params.creation_time, &bucket_version, info);
+      params.quota, params.creation_time, params.index_type,
+      params.index_shards, &bucket_version, info);
 
   bool existed = false;
   if (ret == -EEXIST) {
@@ -188,6 +189,13 @@ int RadosBucket::create(const DoutPrefixProvider* dpp,
     if (info.owner != params.owner) {
       return -ERR_BUCKET_EXISTS;
     }
+    // prevent re-creation with different index type or shard count
+    if ((params.index_type && *params.index_type !=
+         info.layout.current_index.layout.type) ||
+        (params.index_shards && *params.index_shards !=
+         info.layout.current_index.layout.normal.num_shards)) {
+      return -ERR_BUCKET_EXISTS;
+    }
     ret = 0;
   } else if (ret != 0) {
     return ret;
index 9838516cd0968726bc65ac9e2d989af16cc7a655..d721429138794c8ad6b5e8363e6020eb6a2aa7a4 100644 (file)
@@ -889,6 +889,8 @@ class Bucket {
       std::optional<std::string> swift_ver_location;
       std::optional<RGWQuotaInfo> quota;
       std::optional<ceph::real_time> creation_time;
+      std::optional<rgw::BucketIndexType> index_type;
+      std::optional<uint32_t> index_shards;
     };
 
     /// Create this bucket in the backing store.