rgw: parameterized bucket_index_layout_generation in BucketShard::init()

for better flexibility.

Signed-off-by: Shilpa Jagannath <smanjara@redhat.com>
This commit is contained in:
Shilpa Jagannath 2020-04-02 23:47:08 +05:30
parent 3f6e071f65
commit 48cae3f866
8 changed files with 31 additions and 29 deletions

View File

@ -6521,7 +6521,8 @@ next:
for (; i < max_shards; i++) {
RGWRados::BucketShard bs(store->getRados());
int shard_id = (bucket_info.layout.current_index.layout.normal.num_shards > 0 ? i : -1);
int ret = bs.init(bucket, shard_id, nullptr /* no RGWBucketInfo */);
int ret = bs.init(bucket, shard_id, bucket_info.layout.current_index, nullptr /* no RGWBucketInfo */);
marker.clear();
if (ret < 0) {
@ -6585,7 +6586,7 @@ next:
for (int i = 0; i < max_shards; i++) {
RGWRados::BucketShard bs(store->getRados());
int shard_id = (bucket_info.layout.current_index.layout.normal.num_shards > 0 ? i : -1);
int ret = bs.init(bucket, shard_id, nullptr /* no RGWBucketInfo */);
int ret = bs.init(bucket, shard_id, bucket_info.layout.current_index, nullptr /* no RGWBucketInfo */);
if (ret < 0) {
cerr << "ERROR: bs.init(bucket=" << bucket << ", shard=" << shard_id << "): " << cpp_strerror(-ret) << std::endl;
return -ret;

View File

@ -1641,7 +1641,7 @@ static int purge_bucket_instance(rgw::sal::RGWRadosStore *store, const RGWBucket
for (int i = 0; i < max_shards; i++) {
RGWRados::BucketShard bs(store->getRados());
int shard_id = (bucket_info.layout.current_index.layout.normal.num_shards > 0 ? i : -1);
int ret = bs.init(bucket_info.bucket, shard_id, nullptr);
int ret = bs.init(bucket_info.bucket, shard_id, bucket_info.layout.current_index, nullptr);
if (ret < 0) {
cerr << "ERROR: bs.init(bucket=" << bucket_info.bucket << ", shard=" << shard_id
<< "): " << cpp_strerror(-ret) << std::endl;

View File

@ -602,7 +602,7 @@ RGWRadosBILogTrimCR::RGWRadosBILogTrimCR(rgw::sal::RGWRadosStore *store,
start_marker(BucketIndexShardsManager::get_shard_marker(start_marker)),
end_marker(BucketIndexShardsManager::get_shard_marker(end_marker))
{
bs.init(bucket_info, shard_id);
bs.init(bucket_info, bucket_info.layout.current_index, shard_id);
}
int RGWRadosBILogTrimCR::send_request()

View File

@ -2626,7 +2626,7 @@ int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
}
int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
int sid,
int sid, const rgw::bucket_index_layout_generation& idx_layout,
RGWBucketInfo* bucket_info_out)
{
bucket = _bucket;
@ -2634,8 +2634,6 @@ int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
auto obj_ctx = store->svc.sysobj->init_obj_ctx();
rgw::bucket_index_layout_generation generator;
uint64_t gen_number = generator.gen;
RGWBucketInfo bucket_info;
RGWBucketInfo* bucket_info_p =
@ -2647,7 +2645,7 @@ int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
string oid;
ret = store->svc.bi_rados->open_bucket_index_shard(*bucket_info_p, shard_id, gen_number, &bucket_obj);
ret = store->svc.bi_rados->open_bucket_index_shard(*bucket_info_p, shard_id, idx_layout, &bucket_obj);
if (ret < 0) {
ldout(store->ctx(), 0) << "ERROR: open_bucket_index_shard() returned ret=" << ret << dendl;
return ret;
@ -2675,14 +2673,12 @@ int RGWRados::BucketShard::init(const RGWBucketInfo& bucket_info,
return 0;
}
int RGWRados::BucketShard::init(const RGWBucketInfo& bucket_info, int sid)
int RGWRados::BucketShard::init(const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, int sid)
{
bucket = bucket_info.bucket;
shard_id = sid;
rgw::bucket_index_layout_generation generator;
uint64_t gen_number = generator.gen;
int ret = store->svc.bi_rados->open_bucket_index_shard(bucket_info, shard_id, gen_number, &bucket_obj);
int ret = store->svc.bi_rados->open_bucket_index_shard(bucket_info, shard_id, idx_layout, &bucket_obj);
if (ret < 0) {
ldout(store->ctx(), 0) << "ERROR: open_bucket_index_shard() returned ret=" << ret << dendl;
return ret;
@ -8007,10 +8003,10 @@ int RGWRados::bi_remove(BucketShard& bs)
return 0;
}
int RGWRados::bi_list(rgw_bucket& bucket, int shard_id, const string& filter_obj, const string& marker, uint32_t max, list<rgw_cls_bi_entry> *entries, bool *is_truncated)
int RGWRados::bi_list(RGWBucketInfo& bucket_info, int shard_id, const string& filter_obj, const string& marker, uint32_t max, list<rgw_cls_bi_entry> *entries, bool *is_truncated)
{
BucketShard bs(this);
int ret = bs.init(bucket, shard_id, nullptr /* no RGWBucketInfo */);
int ret = bs.init(bucket_info.bucket, shard_id, bucket_info.layout.current_index, nullptr /* no RGWBucketInfo */);
if (ret < 0) {
ldout(cct, 5) << "bs.init() returned ret=" << ret << dendl;
return ret;

View File

@ -682,9 +682,9 @@ public:
explicit BucketShard(RGWRados *_store) : store(_store), shard_id(-1) {}
int init(const rgw_bucket& _bucket, const rgw_obj& obj, RGWBucketInfo* out);
int init(const rgw_bucket& _bucket, int sid, RGWBucketInfo* out);
int init(const rgw_bucket& _bucket, int sid, const rgw::bucket_index_layout_generation& idx_layout, RGWBucketInfo* out);
int init(const RGWBucketInfo& bucket_info, const rgw_obj& obj);
int init(const RGWBucketInfo& bucket_info, int sid);
int init(const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, int sid);
};
class Object {
@ -1411,7 +1411,7 @@ public:
void bi_put(librados::ObjectWriteOperation& op, BucketShard& bs, rgw_cls_bi_entry& entry);
int bi_put(BucketShard& bs, rgw_cls_bi_entry& entry);
int bi_put(rgw_bucket& bucket, rgw_obj& obj, rgw_cls_bi_entry& entry);
int bi_list(rgw_bucket& bucket, int shard_id, const string& filter_obj, const string& marker, uint32_t max, list<rgw_cls_bi_entry> *entries, bool *is_truncated);
int bi_list(RGWBucketInfo& bucket_info, int shard_id, const string& filter_obj, const string& marker, uint32_t max, list<rgw_cls_bi_entry> *entries, bool *is_truncated);
int bi_list(BucketShard& bs, const string& filter_obj, const string& marker, uint32_t max, list<rgw_cls_bi_entry> *entries, bool *is_truncated);
int bi_list(rgw_bucket& bucket, const string& obj_name, const string& marker, uint32_t max,
list<rgw_cls_bi_entry> *entries, bool *is_truncated);

View File

@ -62,6 +62,7 @@ class BucketReshardShard {
rgw::sal::RGWRadosStore *store;
const RGWBucketInfo& bucket_info;
int num_shard;
const rgw::bucket_index_layout_generation& idx_layout;
RGWRados::BucketShard bs;
vector<rgw_cls_bi_entry> entries;
map<RGWObjCategory, rgw_bucket_category_stats> stats;
@ -102,13 +103,14 @@ class BucketReshardShard {
public:
BucketReshardShard(rgw::sal::RGWRadosStore *_store, const RGWBucketInfo& _bucket_info,
int _num_shard,
int _num_shard, const rgw::bucket_index_layout_generation& _idx_layout,
deque<librados::AioCompletion *>& _completions) :
store(_store), bucket_info(_bucket_info), bs(store->getRados()),
store(_store), bucket_info(_bucket_info), idx_layout(_idx_layout), bs(store->getRados()),
aio_completions(_completions)
{
num_shard = (bucket_info.layout.current_index.layout.normal.num_shards > 0 ? _num_shard : -1);
bs.init(bucket_info.bucket, num_shard, nullptr /* no RGWBucketInfo */);
num_shard = (idx_layout.layout.normal.num_shards > 0 ? _num_shard : -1);
bs.init(bucket_info.bucket, num_shard, idx_layout, nullptr /* no RGWBucketInfo */);
max_aio_completions =
store->ctx()->_conf.get_val<uint64_t>("rgw_reshard_max_aio");
@ -192,10 +194,11 @@ public:
int _num_target_shards) :
store(_store), target_bucket_info(_target_bucket_info),
num_target_shards(_num_target_shards)
{
{
const auto& idx_layout = target_bucket_info.layout.current_index;
target_shards.resize(num_target_shards);
for (int i = 0; i < num_target_shards; ++i) {
target_shards[i] = new BucketReshardShard(store, target_bucket_info, i, completions);
target_shards[i] = new BucketReshardShard(store, target_bucket_info, i, idx_layout, completions);
}
}
@ -580,7 +583,7 @@ int RGWBucketReshard::do_reshard(int num_shards,
marker.clear();
while (is_truncated) {
entries.clear();
ret = store->getRados()->bi_list(bucket, i, string(), marker, max_entries, &entries, &is_truncated);
ret = store->getRados()->bi_list(bucket_info, i, string(), marker, max_entries, &entries, &is_truncated);
if (ret < 0 && ret != -ENOENT) {
derr << "ERROR: bi_list(): " << cpp_strerror(-ret) << dendl;
return ret;

View File

@ -196,9 +196,10 @@ void RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_b
} else {
char buf[bucket_oid_base.size() + 64];
if (gen_id != 0) {
snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id);
snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id);
(*bucket_obj) = buf;
} else {
// for backward compatibility, gen_id(0) will not be added in the object name
snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), shard_id);
(*bucket_obj) = buf;
}
@ -266,7 +267,7 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket
int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket_info,
int shard_id,
uint64_t gen_id,
const rgw::bucket_index_layout_generation& idx_layout,
RGWSI_RADOS::Obj *bucket_obj)
{
RGWSI_RADOS::Pool index_pool;
@ -280,8 +281,8 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket
string oid;
get_bucket_index_object(bucket_oid_base, bucket_info.layout.current_index.layout.normal.num_shards,
shard_id, gen_id, &oid);
get_bucket_index_object(bucket_oid_base, idx_layout.layout.normal.num_shards,
shard_id, idx_layout.gen, &oid);
*bucket_obj = svc.rados->obj(index_pool, oid);

View File

@ -115,7 +115,8 @@ public:
int *shard_id);
int open_bucket_index_shard(const RGWBucketInfo& bucket_info,
int shard_id, uint64_t gen_id,
int shard_id,
const rgw::bucket_index_layout_generation& idx_layout,
RGWSI_RADOS::Obj *bucket_obj);
int open_bucket_index(const RGWBucketInfo& bucket_info,