int i = (specified_shard_id ? shard_id : 0);
for (; i < max_shards; i++) {
RGWRados::BucketShard bs(static_cast<rgw::sal::RadosStore*>(store)->getRados());
- int shard_id = (bucket->get_info().layout.current_index.layout.normal.num_shards > 0 ? i : -1);
- int ret = bs.init(bucket->get_key(), shard_id, index, nullptr /* no RGWBucketInfo */, dpp());
+ int ret = bs.init(bucket->get_key(), shard_id, index, std::nullopt, nullptr /* no RGWBucketInfo */, dpp());
marker.clear();
if (ret < 0) {
for (int i = 0; i < max_shards; i++) {
RGWRados::BucketShard bs(static_cast<rgw::sal::RadosStore*>(store)->getRados());
int shard_id = (bucket->get_info().layout.current_index.layout.normal.num_shards > 0 ? i : -1);
- int ret = bs.init(bucket->get_key(), shard_id, index, nullptr /* no RGWBucketInfo */, dpp());
+ int ret = bs.init(bucket->get_key(), shard_id, index, std::nullopt, nullptr /* no RGWBucketInfo */, dpp());
if (ret < 0) {
cerr << "ERROR: bs.init(bucket=" << bucket << ", shard=" << i << "): " << cpp_strerror(-ret) << std::endl;
return -ret;
int max_shards = index.layout.normal.num_shards;
for (int i = 0; i < max_shards; i++) {
RGWRados::BucketShard bs(static_cast<rgw::sal::RadosStore*>(store)->getRados());
- int ret = bs.init(bucket_info.bucket, i, bucket_info.layout.current_index, nullptr, dpp);
+ int ret = bs.init(bucket_info.bucket, i, bucket_info.layout.current_index,
+ std::nullopt, nullptr, dpp);
if (ret < 0) {
cerr << "ERROR: bs.init(bucket=" << bucket_info.bucket << ", shard=" << i
<< "): " << cpp_strerror(-ret) << std::endl;
struct bucket_index_layout_generation {
uint64_t gen = 0;
bucket_index_layout layout;
+
};
void encode(const bucket_index_layout_generation& l, bufferlist& bl, uint64_t f=0);
}
int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
- int sid, const rgw::bucket_index_layout_generation& idx_layout,
+ int sid, const rgw::bucket_index_layout_generation& current_layout,
+ std::optional<rgw::bucket_index_layout_generation> target_layout,
RGWBucketInfo* bucket_info_out,
- const DoutPrefixProvider *dpp)
+ const DoutPrefixProvider *dpp)
{
bucket = _bucket;
shard_id = sid;
string oid;
- ret = store->svc.bi_rados->open_bucket_index_shard(dpp, *bucket_info_p, shard_id, idx_layout, &bucket_obj);
+ if (target_layout) {
+ ret = store->svc.bi_rados->open_bucket_index_shard(dpp, *bucket_info_p, shard_id, target_layout->layout.normal.num_shards,
+ target_layout->gen, &bucket_obj);
+ } else {
+ ret = store->svc.bi_rados->open_bucket_index_shard(dpp, *bucket_info_p, shard_id, current_layout.layout.normal.num_shards,
+ current_layout.gen, &bucket_obj);
+ }
if (ret < 0) {
ldpp_dout(dpp, 0) << "ERROR: open_bucket_index_shard() returned ret=" << ret << dendl;
return ret;
return 0;
}
-int RGWRados::BucketShard::init(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& target_layout, int sid)
+int RGWRados::BucketShard::init(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& current_layout, int sid)
{
bucket = bucket_info.bucket;
shard_id = sid;
- int ret = store->svc.bi_rados->open_bucket_index_shard(dpp, bucket_info, shard_id, target_layout, &bucket_obj);
+ int ret = store->svc.bi_rados->open_bucket_index_shard(dpp, bucket_info, shard_id, current_layout.layout.normal.num_shards, std::nullopt, &bucket_obj);
if (ret < 0) {
ldpp_dout(dpp, 0) << "ERROR: open_bucket_index_shard() returned ret=" << ret << dendl;
return ret;
list<rgw_cls_bi_entry> *entries, bool *is_truncated)
{
BucketShard bs(this);
- int ret = bs.init(bucket_info.bucket, shard_id, bucket_info.layout.current_index, nullptr /* no RGWBucketInfo */, dpp);
+ int ret = bs.init(bucket_info.bucket, shard_id,
+ bucket_info.layout.current_index,
+ std::nullopt, nullptr /* no RGWBucketInfo */, dpp);
if (ret < 0) {
ldpp_dout(dpp, 5) << "bs.init() returned ret=" << ret << dendl;
return ret;
explicit BucketShard(RGWRados *_store) : store(_store), shard_id(-1) {}
int init(const rgw_bucket& _bucket, const rgw_obj& obj, RGWBucketInfo* out, const DoutPrefixProvider *dpp);
- int init(const rgw_bucket& _bucket, int sid, const rgw::bucket_index_layout_generation& idx_layout, RGWBucketInfo* out, const DoutPrefixProvider *dpp);
+ int init(const rgw_bucket& _bucket, int sid, const rgw::bucket_index_layout_generation& idx_layout, std::optional<rgw::bucket_index_layout_generation> target_layout, RGWBucketInfo* out, const DoutPrefixProvider *dpp);
int init(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj);
int init(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, int sid);
};
rgw::sal::RadosStore* store;
const RGWBucketInfo& bucket_info;
int num_shard;
- const rgw::bucket_index_layout_generation& target_layout;
RGWRados::BucketShard bs;
vector<rgw_cls_bi_entry> entries;
map<RGWObjCategory, rgw_bucket_category_stats> stats;
public:
BucketReshardShard(const DoutPrefixProvider *dpp,
rgw::sal::RadosStore *_store, const RGWBucketInfo& _bucket_info,
- int _num_shard, const rgw::bucket_index_layout_generation& _target_layout,
- deque<librados::AioCompletion *>& _completions) :
- store(_store), bucket_info(_bucket_info), target_layout(_target_layout), bs(store->getRados()),
+ int _num_shard, deque<librados::AioCompletion *>& _completions) :
+ store(_store), bucket_info(_bucket_info), bs(store->getRados()),
aio_completions(_completions)
{
- num_shard = (target_layout.layout.normal.num_shards > 0 ? _num_shard : -1);
+ num_shard = (bucket_info.layout.target_index->layout.normal.num_shards > 0 ? _num_shard : -1);
- bs.init(bucket_info.bucket, num_shard, target_layout, nullptr /* no RGWBucketInfo */, dpp);
+ bs.init(bucket_info.bucket, num_shard, bucket_info.layout.current_index,
+ bucket_info.layout.target_index, nullptr /* no RGWBucketInfo */, dpp);
max_aio_completions =
store->ctx()->_conf.get_val<uint64_t>("rgw_reshard_max_aio");
int _num_target_shards) :
store(_store), target_bucket_info(_target_bucket_info),
num_target_shards(_num_target_shards)
- {
- const auto& target_layout = *target_bucket_info.layout.target_index;
+ {
+
target_shards.resize(num_target_shards);
for (int i = 0; i < num_target_shards; ++i) {
- target_shards[i] = new BucketReshardShard(dpp, store, target_bucket_info, i, target_layout, completions);
+ target_shards[i] = new BucketReshardShard(dpp, store, target_bucket_info, i, completions);
}
}
map<string, bufferlist>& attrs,
const DoutPrefixProvider *dpp)
{
-
+ if (!bucket_info.layout.target_index) {
+ bucket_info.layout.target_index.emplace();
+ }
bucket_info.layout.target_index->layout.normal.num_shards = new_num_shards;
bucket_info.layout.resharding = rgw::BucketReshardState::None;
}
set_status(rgw::BucketReshardState::None, dpp);
}
- }
+ }
int start() {
int ret = set_status(rgw::BucketReshardState::InProgress, dpp);
while (is_truncated) {
entries.clear();
ret = store->getRados()->bi_list(dpp, bucket_info, i, null_object_filter, marker, max_entries, &entries, &is_truncated);
- if (ret < 0) {
- if (ret == -ENOENT && i < (num_source_shards - 1)) {
- continue;
- } else {
- derr << "ERROR: bi_list(): " << cpp_strerror(-ret) << dendl;
- return ret;
- }
+ if (ret < 0 && ret == -ENOENT) {
+ derr << "ERROR: bi_list(): " << cpp_strerror(-ret) << dendl;
+ return ret;
}
for (auto iter = entries.begin(); iter != entries.end(); ++iter) {
// since the real problem is the issue that led to this error code
// path, we won't touch ret and instead use another variable to
// temporarily error codes
- int ret2 = store->svc()->bi->clean_index(dpp, bucket_info, std::nullopt);
+ int ret2 = store->svc()->bi->clean_index(dpp, bucket_info, bucket_info.layout.target_index->gen);
if (ret2 < 0) {
ldpp_dout(dpp, -1) << "Error: " << __func__ <<
" failed to clean up shards from failed incomplete resharding; " <<
for (int i = 0; i < max_shards; i++) {
RGWRados::BucketShard bs(store->getRados());
int shard_id = (info.layout.current_index.layout.normal.num_shards > 0 ? i : -1);
- int ret = bs.init(info.bucket, shard_id, info.layout.current_index, nullptr, dpp);
+ int ret = bs.init(info.bucket, shard_id, info.layout.current_index, std::nullopt, nullptr, dpp);
if (ret < 0) {
cerr << "ERROR: bs.init(bucket=" << info.bucket << ", shard=" << shard_id
<< "): " << cpp_strerror(-ret) << std::endl;
void RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_base,
uint32_t num_shards,
int shard_id,
- uint64_t gen_id,
+ std::optional<uint64_t> _gen_id,
string *bucket_obj)
{
+ auto gen_id = _gen_id.value_or(0);
if (!num_shards) {
// By default with no sharding, we use the bucket oid as itself
(*bucket_obj) = bucket_oid_base;
} else {
char buf[bucket_oid_base.size() + 64];
- if (gen_id != 0) {
+ if (gen_id) {
snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id);
(*bucket_obj) = buf;
ldout(cct, 10) << "bucket_obj is " << (*bucket_obj) << dendl;
int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const DoutPrefixProvider *dpp,
const RGWBucketInfo& bucket_info,
int shard_id,
- const rgw::bucket_index_layout_generation& target_layout,
+ uint32_t num_shards,
+ std::optional<uint64_t> gen,
RGWSI_RADOS::Obj *bucket_obj)
{
RGWSI_RADOS::Pool index_pool;
string oid;
- get_bucket_index_object(bucket_oid_base, target_layout.layout.normal.num_shards,
- shard_id, target_layout.gen, &oid);
+ get_bucket_index_object(bucket_oid_base, num_shards,
+ shard_id, gen, &oid);
*bucket_obj = svc.rados->obj(index_pool, oid);
void get_bucket_index_object(const std::string& bucket_oid_base,
uint32_t num_shards,
int shard_id,
- uint64_t gen_id,
- std::string *bucket_obj);
- int get_bucket_index_object(const std::string& bucket_oid_base, const std::string& obj_key,
+ std::optional<uint64_t> gen_id,
+ std::string* bucket_obj);
+ int get_bucket_index_object(const std::string& bucket_oid_base,
+ const std::string& obj_key,
uint32_t num_shards, rgw::BucketHashType hash_type,
- std::string *bucket_obj, int *shard_id);
+ std::string* bucket_obj, int* shard_id);
int cls_bucket_head(const DoutPrefixProvider *dpp,
const RGWBucketInfo& bucket_info,
int open_bucket_index_shard(const DoutPrefixProvider *dpp,
const RGWBucketInfo& bucket_info,
int shard_id,
- const rgw::bucket_index_layout_generation& idx_layout,
+ uint32_t num_shards,
+ std::optional<uint64_t> gen,
RGWSI_RADOS::Obj *bucket_obj);
int open_bucket_index(const DoutPrefixProvider *dpp,