From cd867bc19d9dae9aa20d60e382854c3b1ba62f6e Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 8 Jan 2025 14:25:20 -0500 Subject: [PATCH] rgw/rados: create_bucket() can override index type and shards Signed-off-by: Casey Bodley --- src/rgw/driver/rados/rgw_bucket.cc | 9 ++++++--- src/rgw/driver/rados/rgw_bucket.h | 3 ++- src/rgw/driver/rados/rgw_rados.cc | 7 ++++++- src/rgw/driver/rados/rgw_rados.h | 2 ++ src/rgw/driver/rados/rgw_sal_rados.cc | 10 +++++++++- src/rgw/rgw_sal.h | 2 ++ 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/rgw/driver/rados/rgw_bucket.cc b/src/rgw/driver/rados/rgw_bucket.cc index d043aea07831a..0dbc61460414d 100644 --- a/src/rgw/driver/rados/rgw_bucket.cc +++ b/src/rgw/driver/rados/rgw_bucket.cc @@ -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 type) { + std::optional type, + std::optional 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); } } diff --git a/src/rgw/driver/rados/rgw_bucket.h b/src/rgw/driver/rados/rgw_bucket.h index 9ee31c8814e60..8c2c65da6dd06 100644 --- a/src/rgw/driver/rados/rgw_bucket.h +++ b/src/rgw/driver/rados/rgw_bucket.h @@ -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 type); + std::optional type, + std::optional shards); struct RGWBucketCompleteInfo { RGWBucketInfo info; diff --git a/src/rgw/driver/rados/rgw_rados.cc b/src/rgw/driver/rados/rgw_rados.cc index c1534b2e35680..7406cfe54c40e 100644 --- a/src/rgw/driver/rados/rgw_rados.cc +++ b/src/rgw/driver/rados/rgw_rados.cc @@ -2362,6 +2362,8 @@ int RGWRados::create_bucket(const DoutPrefixProvider* dpp, const std::optional& swift_ver_location, const std::optional& quota, std::optional creation_time, + std::optional index_type, + std::optional 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; diff --git a/src/rgw/driver/rados/rgw_rados.h b/src/rgw/driver/rados/rgw_rados.h index 217159487bf53..a82d737d6e174 100644 --- a/src/rgw/driver/rados/rgw_rados.h +++ b/src/rgw/driver/rados/rgw_rados.h @@ -643,6 +643,8 @@ public: const std::optional& swift_ver_location, const std::optional& quota, std::optional creation_time, + std::optional index_type, + std::optional index_shards, obj_version* pep_objv, RGWBucketInfo& info); diff --git a/src/rgw/driver/rados/rgw_sal_rados.cc b/src/rgw/driver/rados/rgw_sal_rados.cc index ea2572b412115..5093467547f63 100644 --- a/src/rgw/driver/rados/rgw_sal_rados.cc +++ b/src/rgw/driver/rados/rgw_sal_rados.cc @@ -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; diff --git a/src/rgw/rgw_sal.h b/src/rgw/rgw_sal.h index 9838516cd0968..d721429138794 100644 --- a/src/rgw/rgw_sal.h +++ b/src/rgw/rgw_sal.h @@ -889,6 +889,8 @@ class Bucket { std::optional swift_ver_location; std::optional quota; std::optional creation_time; + std::optional index_type; + std::optional index_shards; }; /// Create this bucket in the backing store. -- 2.39.5