From 2ee22667692c7e8b3c8529a9eef7da743eff246f Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Tue, 5 Jul 2022 18:33:09 -0400 Subject: [PATCH] rgwlc: activate lifecycle processing on non-master zones The basic idea of this change is the same as the proposal by Ilsoo Byun , but some details have changed. The main differences are to use the existing RGWLC::set(remove)_bucket_config methods, and to use the RGWBucketInstanceMetadataHandler infrastructue to dispatch the corresponding calls. Thank you! Fixes: https://tracker.ceph.com/issues/44268 Related PR: #33524 Signed-off-by: Matt Benjamin --- src/rgw/rgw_bucket.cc | 58 ++++++++++++++++++++++++++++++++------ src/rgw/rgw_bucket.h | 4 +-- src/rgw/rgw_data_sync.cc | 6 ++-- src/rgw/rgw_lc.cc | 23 +++++++++------ src/rgw/rgw_service.cc | 4 +-- src/rgw/rgw_sync_module.cc | 4 +-- src/rgw/rgw_sync_module.h | 2 +- 7 files changed, 74 insertions(+), 27 deletions(-) diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index 68fa4064adfdb..af1d2de03931e 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -2139,7 +2139,10 @@ public: RGWSI_BucketIndex *bi{nullptr}; } svc; - RGWBucketInstanceMetadataHandler() {} + rgw::sal::Store* store; + + RGWBucketInstanceMetadataHandler(rgw::sal::Store* store) + : store(store) {} void init(RGWSI_Zone *zone_svc, RGWSI_Bucket *bucket_svc, @@ -2371,12 +2374,51 @@ int RGWMetadataHandlerPut_BucketInstance::put_post(const DoutPrefixProvider *dpp return ret; } + /* update lifecyle policy */ + { + std::unique_ptr bucket; + ret = bihandler->store->get_bucket(nullptr, bci.info, &bucket); + if (ret < 0) { + ldpp_dout(dpp, 0) << __func__ << " failed to get_bucket(...) for " + << bci.info.bucket.name + << dendl; + return ret; + } + + auto lc = bihandler->store->get_rgwlc(); + + auto lc_it = bci.attrs.find(RGW_ATTR_LC); + if (lc_it != bci.attrs.end()) { + ldpp_dout(dpp, 20) << "set lc config for " << bci.info.bucket.name << dendl; + ret = lc->set_bucket_config(bucket.get(), bci.attrs, nullptr); + if (ret < 0) { + ldpp_dout(dpp, 0) << __func__ << " failed to set lc config for " + << bci.info.bucket.name + << dendl; + return ret; + } + + } else { + ldpp_dout(dpp, 20) << "remove lc config for " << bci.info.bucket.name << dendl; + ret = lc->remove_bucket_config(bucket.get(), bci.attrs); + if (ret < 0) { + ldpp_dout(dpp, 0) << __func__ << " failed to remove lc config for " + << bci.info.bucket.name + << dendl; + return ret; + } + } + } /* update lc */ + return STATUS_APPLIED; } class RGWArchiveBucketInstanceMetadataHandler : public RGWBucketInstanceMetadataHandler { public: - RGWArchiveBucketInstanceMetadataHandler() {} + RGWArchiveBucketInstanceMetadataHandler(rgw::sal::Store* store) + : RGWBucketInstanceMetadataHandler(store) {} + + // N.B. replication of lifecycle policy relies on logic in RGWBucketInstanceMetadataHandler::do_put(...), override with caution int do_remove(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWObjVersionTracker& objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) override { ldpp_dout(dpp, 0) << "SKIP: bucket instance removal is not allowed on archive zone: bucket.instance:" << entry << dendl; @@ -3027,24 +3069,24 @@ int RGWBucketCtl::bucket_imports_data(const rgw_bucket& bucket, return handler->bucket_imports_data(); } -RGWBucketMetadataHandlerBase *RGWBucketMetaHandlerAllocator::alloc() +RGWBucketMetadataHandlerBase* RGWBucketMetaHandlerAllocator::alloc() { return new RGWBucketMetadataHandler(); } -RGWBucketInstanceMetadataHandlerBase *RGWBucketInstanceMetaHandlerAllocator::alloc() +RGWBucketInstanceMetadataHandlerBase* RGWBucketInstanceMetaHandlerAllocator::alloc(rgw::sal::Store* store) { - return new RGWBucketInstanceMetadataHandler(); + return new RGWBucketInstanceMetadataHandler(store); } -RGWBucketMetadataHandlerBase *RGWArchiveBucketMetaHandlerAllocator::alloc() +RGWBucketMetadataHandlerBase* RGWArchiveBucketMetaHandlerAllocator::alloc() { return new RGWArchiveBucketMetadataHandler(); } -RGWBucketInstanceMetadataHandlerBase *RGWArchiveBucketInstanceMetaHandlerAllocator::alloc() +RGWBucketInstanceMetadataHandlerBase* RGWArchiveBucketInstanceMetaHandlerAllocator::alloc(rgw::sal::Store* store) { - return new RGWArchiveBucketInstanceMetadataHandler(); + return new RGWArchiveBucketInstanceMetadataHandler(store); } diff --git a/src/rgw/rgw_bucket.h b/src/rgw/rgw_bucket.h index 28c315e6ab2e7..10a7226f246d3 100644 --- a/src/rgw/rgw_bucket.h +++ b/src/rgw/rgw_bucket.h @@ -204,7 +204,7 @@ public: class RGWBucketInstanceMetaHandlerAllocator { public: - static RGWBucketInstanceMetadataHandlerBase *alloc(); + static RGWBucketInstanceMetadataHandlerBase *alloc(rgw::sal::Store* store); }; class RGWArchiveBucketMetaHandlerAllocator { @@ -214,7 +214,7 @@ public: class RGWArchiveBucketInstanceMetaHandlerAllocator { public: - static RGWBucketInstanceMetadataHandlerBase *alloc(); + static RGWBucketInstanceMetadataHandlerBase *alloc(rgw::sal::Store* store); }; extern int rgw_remove_object(const DoutPrefixProvider *dpp, rgw::sal::Store* store, rgw::sal::Bucket* bucket, rgw_obj_key& key); diff --git a/src/rgw/rgw_data_sync.cc b/src/rgw/rgw_data_sync.cc index ecc7a9596ae82..1b2b0ef835138 100644 --- a/src/rgw/rgw_data_sync.cc +++ b/src/rgw/rgw_data_sync.cc @@ -520,7 +520,7 @@ class RGWInitDataSyncStatusCoroutine : public RGWCoroutine { static constexpr uint32_t lock_duration = 30; RGWDataSyncCtx *sc; RGWDataSyncEnv *sync_env; - rgw::sal::RadosStore* store; + rgw::sal::RadosStore* store; // RGWDataSyncEnv also has a pointer to store const rgw_pool& pool; const uint32_t num_shards; @@ -2500,8 +2500,8 @@ public: RGWMetadataHandler *alloc_bucket_meta_handler() override { return RGWArchiveBucketMetaHandlerAllocator::alloc(); } - RGWBucketInstanceMetadataHandlerBase *alloc_bucket_instance_meta_handler() override { - return RGWArchiveBucketInstanceMetaHandlerAllocator::alloc(); + RGWBucketInstanceMetadataHandlerBase *alloc_bucket_instance_meta_handler(rgw::sal::Store* store) override { + return RGWArchiveBucketInstanceMetaHandlerAllocator::alloc(store); } }; diff --git a/src/rgw/rgw_lc.cc b/src/rgw/rgw_lc.cc index 8125b4ab8efd0..9233a442b4f8b 100644 --- a/src/rgw/rgw_lc.cc +++ b/src/rgw/rgw_lc.cc @@ -2455,16 +2455,21 @@ int RGWLC::set_bucket_config(rgw::sal::Bucket* bucket, const rgw::sal::Attrs& bucket_attrs, RGWLifecycleConfiguration *config) { + int ret{0}; rgw::sal::Attrs attrs = bucket_attrs; - bufferlist lc_bl; - config->encode(lc_bl); - - attrs[RGW_ATTR_LC] = std::move(lc_bl); - - int ret = - bucket->merge_and_store_attrs(this, attrs, null_yield); - if (ret < 0) - return ret; + if (config) { + /* if no RGWLifecycleconfiguration provided, it means + * RGW_ATTR_LC is already valid and present */ + bufferlist lc_bl; + config->encode(lc_bl); + attrs[RGW_ATTR_LC] = std::move(lc_bl); + + ret = + bucket->merge_and_store_attrs(this, attrs, null_yield); + if (ret < 0) { + return ret; + } + } rgw_bucket& b = bucket->get_key(); diff --git a/src/rgw/rgw_service.cc b/src/rgw/rgw_service.cc index 7df25a2dba5d8..0d6e4d530d698 100644 --- a/src/rgw/rgw_service.cc +++ b/src/rgw/rgw_service.cc @@ -365,10 +365,10 @@ int RGWCtlDef::init(RGWServices& svc, rgw::sal::Store* store, const DoutPrefixPr auto sync_module = svc.sync_modules->get_sync_module(); if (sync_module) { meta.bucket.reset(sync_module->alloc_bucket_meta_handler()); - meta.bucket_instance.reset(sync_module->alloc_bucket_instance_meta_handler()); + meta.bucket_instance.reset(sync_module->alloc_bucket_instance_meta_handler(store)); } else { meta.bucket.reset(RGWBucketMetaHandlerAllocator::alloc()); - meta.bucket_instance.reset(RGWBucketInstanceMetaHandlerAllocator::alloc()); + meta.bucket_instance.reset(RGWBucketInstanceMetaHandlerAllocator::alloc(store)); } meta.otp.reset(RGWOTPMetaHandlerAllocator::alloc()); diff --git a/src/rgw/rgw_sync_module.cc b/src/rgw/rgw_sync_module.cc index 9dd153c8660d1..b2588277270f4 100644 --- a/src/rgw/rgw_sync_module.cc +++ b/src/rgw/rgw_sync_module.cc @@ -22,9 +22,9 @@ RGWMetadataHandler *RGWSyncModuleInstance::alloc_bucket_meta_handler() return RGWBucketMetaHandlerAllocator::alloc(); } -RGWBucketInstanceMetadataHandlerBase *RGWSyncModuleInstance::alloc_bucket_instance_meta_handler() +RGWBucketInstanceMetadataHandlerBase* RGWSyncModuleInstance::alloc_bucket_instance_meta_handler(rgw::sal::Store* store) { - return RGWBucketInstanceMetaHandlerAllocator::alloc(); + return RGWBucketInstanceMetaHandlerAllocator::alloc(store); } RGWStatRemoteObjCBCR::RGWStatRemoteObjCBCR(RGWDataSyncCtx *_sc, diff --git a/src/rgw/rgw_sync_module.h b/src/rgw/rgw_sync_module.h index 135495b493440..f07a539523435 100644 --- a/src/rgw/rgw_sync_module.h +++ b/src/rgw/rgw_sync_module.h @@ -53,7 +53,7 @@ public: return false; } virtual RGWMetadataHandler *alloc_bucket_meta_handler(); - virtual RGWBucketInstanceMetadataHandlerBase *alloc_bucket_instance_meta_handler(); + virtual RGWBucketInstanceMetadataHandlerBase *alloc_bucket_instance_meta_handler(rgw::sal::Store* store); // indication whether the sync module start with full sync (default behavior) // incremental sync would follow anyway -- 2.39.5