diff options
author | Casey Bodley <cbodley@users.noreply.github.com> | 2024-09-05 19:21:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-05 19:21:47 +0200 |
commit | 4ee8e591f39d7978438c83c8a245ee1e17df0edf (patch) | |
tree | 025a01d73ee2133e5543c1f01dcf907a81fcc5d0 /src/rgw/driver/rados/rgw_rados.cc | |
parent | Merge pull request #59170 from guits/remove-legacy-disk-sorting (diff) | |
parent | cls/rgw: add a helper function for calls to cls_cxx_map_remove_key() (diff) | |
download | ceph-4ee8e591f39d7978438c83c8a245ee1e17df0edf.tar.xz ceph-4ee8e591f39d7978438c83c8a245ee1e17df0edf.zip |
Merge pull request #56597 from liangmingyuanneo/optimize-reshard
rgw reshard: optimize reshard process to minimum blocking time
Reviewed-by: Casey Bodley <cbodley@redhat.com>
Diffstat (limited to 'src/rgw/driver/rados/rgw_rados.cc')
-rw-r--r-- | src/rgw/driver/rados/rgw_rados.cc | 114 |
1 files changed, 105 insertions, 9 deletions
diff --git a/src/rgw/driver/rados/rgw_rados.cc b/src/rgw/driver/rados/rgw_rados.cc index 23c149574ae..1f1d75cb07b 100644 --- a/src/rgw/driver/rados/rgw_rados.cc +++ b/src/rgw/driver/rados/rgw_rados.cc @@ -5597,7 +5597,9 @@ int RGWRados::bucket_resync_encrypted_multipart(const DoutPrefixProvider* dpp, return 0; } -int RGWRados::bucket_set_reshard(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const cls_rgw_bucket_instance_entry& entry) +int RGWRados::bucket_set_reshard(const DoutPrefixProvider *dpp, + const RGWBucketInfo& bucket_info, + const cls_rgw_bucket_instance_entry& entry) { librados::IoCtx index_pool; map<int, string> bucket_objs; @@ -5609,7 +5611,6 @@ int RGWRados::bucket_set_reshard(const DoutPrefixProvider *dpp, const RGWBucketI cpp_strerror(-r) << ")" << dendl; return r; } - r = CLSRGWIssueSetBucketResharding(index_pool, bucket_objs, entry, cct->_conf->rgw_bucket_index_max_aio)(); if (r < 0) { ldpp_dout(dpp, 0) << "ERROR: " << __func__ << @@ -6967,6 +6968,10 @@ int RGWRados::Bucket::UpdateIndex::guard_reshard(const DoutPrefixProvider *dpp, *pbs = bs; } + if (target->bucket_info.layout.resharding == rgw::BucketReshardState::InLogrecord) { + store->check_reshard_logrecord_status(target->bucket_info, y, dpp); + } + return 0; } @@ -7660,9 +7665,76 @@ int RGWRados::guard_reshard(const DoutPrefixProvider *dpp, return r; } + if (bucket_info.layout.resharding == rgw::BucketReshardState::InLogrecord) { + check_reshard_logrecord_status(bucket_info, y, dpp); + } + + return 0; +} + +int RGWRados::check_reshard_logrecord_status(RGWBucketInfo& bucket_info, optional_yield y, + const DoutPrefixProvider *dpp) +{ + real_time now = real_clock::now(); + double r = rand() / (double)RAND_MAX; + double reshard_progress_judge_interval = cct->_conf.get_val<uint64_t>("rgw_reshard_progress_judge_interval"); + // avoid getting reshard_lock simultaneously by mass differrent operation + reshard_progress_judge_interval += + reshard_progress_judge_interval * cct->_conf.get_val<double>("rgw_reshard_progress_judge_ratio") * r; + if (now - bucket_info.layout.judge_reshard_lock_time >= make_timespan(reshard_progress_judge_interval)) { + + map<string, bufferlist> bucket_attrs; + int ret = get_bucket_info(&svc, bucket_info.bucket.tenant, bucket_info.bucket.name, + bucket_info, nullptr, y, dpp, &bucket_attrs); + if (ret < 0) { + ldpp_dout(dpp, 0) << __func__ << + " ERROR: failed to refresh bucket info : " << cpp_strerror(-ret) << dendl; + return ret; + } + if (bucket_info.layout.resharding == rgw::BucketReshardState::InLogrecord && + now - bucket_info.layout.judge_reshard_lock_time >= make_timespan(reshard_progress_judge_interval)) + return recover_reshard_logrecord(bucket_info, bucket_attrs, y, dpp); + } return 0; } +int RGWRados::recover_reshard_logrecord(RGWBucketInfo& bucket_info, + map<string, bufferlist>& bucket_attrs, + optional_yield y, + const DoutPrefixProvider *dpp) +{ + RGWBucketReshardLock reshard_lock(this->driver, bucket_info, true); + int ret = reshard_lock.lock(dpp); + if (ret < 0) { + ldpp_dout(dpp, 20) << __func__ << + " INFO: failed to take reshard lock for bucket " << + bucket_info.bucket.bucket_id << "; expected if resharding underway" << dendl; + // update the judge time + bucket_info.layout.judge_reshard_lock_time = real_clock::now(); + ret = put_bucket_instance_info(bucket_info, false, real_time(), &bucket_attrs, dpp, y); + if (ret < 0) { + ldpp_dout(dpp, 0) << "RGWReshard::" << __func__ << + " ERROR: error putting bucket instance info: " << cpp_strerror(-ret) << dendl; + } + } else { + ldpp_dout(dpp,20) << __func__ << ": reshard lock success, " << + "that means the reshard has failed for bucekt " << bucket_info.bucket.bucket_id << dendl; + // clear the RESHARD_IN_PROGRESS status after reshard failed, set bucket instance status + // to CLS_RGW_RESHARD_NONE, also clear the reshard log entries + ret = RGWBucketReshard::clear_resharding(this->driver, bucket_info, bucket_attrs, dpp, y); + reshard_lock.unlock(); + if (ret < 0) { + ldpp_dout(dpp, 0) << __func__ << + " ERROR: failed to clear resharding flags for bucket " << + bucket_info.bucket.bucket_id << dendl; + } else { + ldpp_dout(dpp, 5) << __func__ << + " INFO: apparently successfully cleared resharding flags for " + "bucket " << bucket_info.bucket.bucket_id << dendl; + } // if clear resharding succeeded + } // if taking of lock succeeded + return 0; +} int RGWRados::block_while_resharding(RGWRados::BucketShard *bs, const rgw_obj& obj_instance, @@ -7728,7 +7800,7 @@ int RGWRados::block_while_resharding(RGWRados::BucketShard *bs, return ret; } - if (!entry.resharding_in_progress()) { + if (!entry.resharding()) { ret = fetch_new_bucket_info("get_bucket_resharding_succeeded"); if (ret < 0) { ldpp_dout(dpp, 0) << "ERROR: " << __func__ << @@ -9166,6 +9238,17 @@ int RGWRados::bi_get(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_ return cls_rgw_bi_get(ref.ioctx, ref.obj.oid, index_type, key, entry); } +int RGWRados::bi_get_vals(BucketShard& bs, set<string>& log_entries_wanted, + list<rgw_cls_bi_entry> *entries, optional_yield y) +{ + auto& ref = bs.bucket_obj; + int ret = cls_rgw_bi_get_vals(ref.ioctx, ref.obj.oid, log_entries_wanted, entries); + if (ret < 0) + return ret; + + return 0; +} + void RGWRados::bi_put(ObjectWriteOperation& op, BucketShard& bs, rgw_cls_bi_entry& entry, optional_yield y) { auto& ref = bs.bucket_obj; @@ -9203,7 +9286,8 @@ int RGWRados::bi_put(const DoutPrefixProvider *dpp, rgw_bucket& bucket, rgw_obj& int RGWRados::bi_list(const DoutPrefixProvider *dpp, rgw_bucket& bucket, const string& obj_name_filter, const string& marker, uint32_t max, - list<rgw_cls_bi_entry> *entries, bool *is_truncated, optional_yield y) + list<rgw_cls_bi_entry> *entries, bool *is_truncated, + bool reshardlog, optional_yield y) { rgw_obj obj(bucket, obj_name_filter); BucketShard bs(this); @@ -9214,7 +9298,7 @@ int RGWRados::bi_list(const DoutPrefixProvider *dpp, rgw_bucket& bucket, } auto& ref = bs.bucket_obj; - ret = cls_rgw_bi_list(ref.ioctx, ref.obj.oid, obj_name_filter, marker, max, entries, is_truncated); + ret = cls_rgw_bi_list(ref.ioctx, ref.obj.oid, obj_name_filter, marker, max, entries, is_truncated, reshardlog); if (ret == -ENOENT) { *is_truncated = false; } @@ -9225,10 +9309,10 @@ int RGWRados::bi_list(const DoutPrefixProvider *dpp, rgw_bucket& bucket, } int RGWRados::bi_list(BucketShard& bs, const string& obj_name_filter, const string& marker, uint32_t max, - list<rgw_cls_bi_entry> *entries, bool *is_truncated, optional_yield y) + list<rgw_cls_bi_entry> *entries, bool *is_truncated, bool reshardlog, optional_yield y) { auto& ref = bs.bucket_obj; - int ret = cls_rgw_bi_list(ref.ioctx, ref.obj.oid, obj_name_filter, marker, max, entries, is_truncated); + int ret = cls_rgw_bi_list(ref.ioctx, ref.obj.oid, obj_name_filter, marker, max, entries, is_truncated, reshardlog); if (ret < 0) return ret; @@ -9237,7 +9321,7 @@ int RGWRados::bi_list(BucketShard& bs, const string& obj_name_filter, const stri int RGWRados::bi_list(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, int shard_id, const string& obj_name_filter, const string& marker, uint32_t max, - list<rgw_cls_bi_entry> *entries, bool *is_truncated, optional_yield y) + list<rgw_cls_bi_entry> *entries, bool *is_truncated, bool reshardlog, optional_yield y) { BucketShard bs(this); int ret = bs.init(dpp, bucket_info, @@ -9248,7 +9332,7 @@ int RGWRados::bi_list(const DoutPrefixProvider *dpp, return ret; } - return bi_list(bs, obj_name_filter, marker, max, entries, is_truncated, y); + return bi_list(bs, obj_name_filter, marker, max, entries, is_truncated, reshardlog, y); } int RGWRados::bi_remove(const DoutPrefixProvider *dpp, BucketShard& bs) @@ -9266,6 +9350,18 @@ int RGWRados::bi_remove(const DoutPrefixProvider *dpp, BucketShard& bs) return 0; } +int RGWRados::trim_reshard_log_entries(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, optional_yield y) +{ + librados::IoCtx index_pool; + map<int, string> bucket_objs; + + int r = svc.bi_rados->open_bucket_index(dpp, bucket_info, std::nullopt, bucket_info.layout.current_index, &index_pool, &bucket_objs, nullptr); + if (r < 0) { + return r; + } + return CLSRGWIssueReshardLogTrim(index_pool, bucket_objs, cct->_conf->rgw_bucket_index_max_aio)(); +} + int RGWRados::gc_operate(const DoutPrefixProvider *dpp, string& oid, librados::ObjectWriteOperation *op, optional_yield y) { return rgw_rados_operate(dpp, gc_pool_ctx, oid, op, y); |