|
1 | | - |
2 | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
3 | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
4 | 3 |
|
5 | 4 | /* |
6 | 5 | * Copyright (C) 2025 IBM |
7 | | -*/ |
| 6 | + */ |
8 | 7 |
|
9 | 8 | #include <cerrno> |
10 | 9 | #include <string> |
@@ -169,6 +168,7 @@ void usage() |
169 | 168 | cout << " bucket check unlinked check for object versions that are not visible in a bucket listing \n"; |
170 | 169 | cout << " bucket chown link bucket to specified user and update its object ACLs\n"; |
171 | 170 | 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"; |
172 | 172 | cout << " bucket rewrite rewrite all objects in the specified bucket\n"; |
173 | 173 | cout << " bucket sync checkpoint poll a bucket's sync status until it catches up to its remote\n"; |
174 | 174 | cout << " bucket sync disable disable bucket sync\n"; |
@@ -699,6 +699,7 @@ enum class OPT { |
699 | 699 | BUCKET_RM, |
700 | 700 | BUCKET_REWRITE, |
701 | 701 | BUCKET_RESHARD, |
| 702 | + BUCKET_SET_MIN_SHARDS, |
702 | 703 | BUCKET_CHOWN, |
703 | 704 | BUCKET_RADOS_LIST, |
704 | 705 | BUCKET_SHARD_OBJECTS, |
@@ -937,6 +938,7 @@ static SimpleCmd::Commands all_cmds = { |
937 | 938 | { "bucket rm", OPT::BUCKET_RM }, |
938 | 939 | { "bucket rewrite", OPT::BUCKET_REWRITE }, |
939 | 940 | { "bucket reshard", OPT::BUCKET_RESHARD }, |
| 941 | + { "bucket set-min-shards", OPT::BUCKET_SET_MIN_SHARDS }, |
940 | 942 | { "bucket chown", OPT::BUCKET_CHOWN }, |
941 | 943 | { "bucket radoslist", OPT::BUCKET_RADOS_LIST }, |
942 | 944 | { "bucket rados list", OPT::BUCKET_RADOS_LIST }, |
@@ -8803,6 +8805,51 @@ int main(int argc, const char **argv) |
8803 | 8805 | } |
8804 | 8806 | } // OPT_RESHARD_CANCEL |
8805 | 8807 |
|
| 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 | + |
8806 | 8853 | if (opt_cmd == OPT::OBJECT_UNLINK) { |
8807 | 8854 | int ret = init_bucket(tenant, bucket_name, bucket_id, &bucket); |
8808 | 8855 | if (ret < 0) { |
|
0 commit comments