Skip to content

Commit f8571d9

Browse files
committed
rgw: add radosgw-admin sub-command to set-min-shards for a bucket
There is now a mechansim to set the minimum number of shards when a bucket is created, and dynamic resharding adheres to that setting. This adds the ability to modify that minimum shard count that exists within the bucket layout of the bucket instance object. Example: radosgw-admin bucket set-min-shards --bucket=<bucket> \ --num-shards=<value> Signed-off-by: J. Eric Ivancich <[email protected]>
1 parent 5ee4a92 commit f8571d9

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

src/rgw/radosgw-admin/radosgw-admin.cc

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
32
// vim: ts=8 sw=2 smarttab ft=cpp
43

54
/*
65
* Copyright (C) 2025 IBM
7-
*/
6+
*/
87

98
#include <cerrno>
109
#include <string>
@@ -169,6 +168,7 @@ void usage()
169168
cout << " bucket check unlinked check for object versions that are not visible in a bucket listing \n";
170169
cout << " bucket chown link bucket to specified user and update its object ACLs\n";
171170
cout << " bucket reshard reshard bucket\n";
171+
cout << " bucket set-min-shards set the minimum number of shards that dynamic resharding will consider for a bucket\n";
172172
cout << " bucket rewrite rewrite all objects in the specified bucket\n";
173173
cout << " bucket sync checkpoint poll a bucket's sync status until it catches up to its remote\n";
174174
cout << " bucket sync disable disable bucket sync\n";
@@ -699,6 +699,7 @@ enum class OPT {
699699
BUCKET_RM,
700700
BUCKET_REWRITE,
701701
BUCKET_RESHARD,
702+
BUCKET_SET_MIN_SHARDS,
702703
BUCKET_CHOWN,
703704
BUCKET_RADOS_LIST,
704705
BUCKET_SHARD_OBJECTS,
@@ -937,6 +938,7 @@ static SimpleCmd::Commands all_cmds = {
937938
{ "bucket rm", OPT::BUCKET_RM },
938939
{ "bucket rewrite", OPT::BUCKET_REWRITE },
939940
{ "bucket reshard", OPT::BUCKET_RESHARD },
941+
{ "bucket set-min-shards", OPT::BUCKET_SET_MIN_SHARDS },
940942
{ "bucket chown", OPT::BUCKET_CHOWN },
941943
{ "bucket radoslist", OPT::BUCKET_RADOS_LIST },
942944
{ "bucket rados list", OPT::BUCKET_RADOS_LIST },
@@ -8803,6 +8805,51 @@ int main(int argc, const char **argv)
88038805
}
88048806
} // OPT_RESHARD_CANCEL
88058807

8808+
if (opt_cmd == OPT::BUCKET_SET_MIN_SHARDS) {
8809+
if (bucket_name.empty()) {
8810+
cerr << "ERROR: bucket not specified" << std::endl;
8811+
return -EINVAL;
8812+
}
8813+
8814+
if (!num_shards_specified) {
8815+
cerr << "ERROR: --num-shards not specified" << std::endl;
8816+
return -EINVAL;
8817+
}
8818+
8819+
if (num_shards < 1) {
8820+
cerr << "ERROR: --num-shards must be at least 1" << std::endl;
8821+
return -EINVAL;
8822+
}
8823+
8824+
int ret = init_bucket(tenant, bucket_name, bucket_id, &bucket);
8825+
if (ret < 0) {
8826+
return -ret;
8827+
}
8828+
auto& bucket_info = bucket->get_info();
8829+
8830+
const rgw::BucketIndexType type =
8831+
bucket_info.layout.current_index.layout.type;
8832+
if (type != rgw::BucketIndexType::Normal) {
8833+
cerr << "ERROR: the bucket's layout is type " << type <<
8834+
" instead of type " << rgw::BucketIndexType::Normal <<
8835+
" and therefore does not have a "
8836+
"minimum number of shards that can be altered" << std::endl;
8837+
return EINVAL;
8838+
}
8839+
8840+
uint32_t& min_num_shards =
8841+
bucket_info.layout.current_index.layout.normal.min_num_shards;
8842+
min_num_shards = num_shards;
8843+
8844+
ret = bucket->put_info(dpp(), false, real_time(), null_yield);
8845+
if (ret < 0) {
8846+
cerr << "ERROR: failed writing bucket instance info: " << cpp_strerror(-ret) << std::endl;
8847+
return -ret;
8848+
}
8849+
8850+
return 0;
8851+
} // SET_MIN_SHARDS
8852+
88068853
if (opt_cmd == OPT::OBJECT_UNLINK) {
88078854
int ret = init_bucket(tenant, bucket_name, bucket_id, &bucket);
88088855
if (ret < 0) {

src/rgw/rgw_sal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ class Driver {
686686

687687
/** Register admin APIs unique to this driver */
688688
virtual void register_admin_apis(RGWRESTMgr* mgr) = 0;
689-
};
689+
}; // class Driver
690690

691691

692692
/// \brief Ref-counted callback object for User/Bucket read_stats_async().

src/test/cli/radosgw-admin/help.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
bucket check unlinked check for object versions that are not visible in a bucket listing
3939
bucket chown link bucket to specified user and update its object ACLs
4040
bucket reshard reshard bucket
41+
bucket set-min-shards set the minimum number of shards that dynamic resharding will consider for a bucket
4142
bucket rewrite rewrite all objects in the specified bucket
4243
bucket sync checkpoint poll a bucket's sync status until it catches up to its remote
4344
bucket sync disable disable bucket sync

0 commit comments

Comments
 (0)