Skip to content

Commit de90732

Browse files
committed
RGW/standalone: refactor RGWPeriodConfig with configstore
Signed-off-by: Ali Masarwa <[email protected]>
1 parent 976889f commit de90732

File tree

4 files changed

+14
-49
lines changed

4 files changed

+14
-49
lines changed

src/rgw/driver/rados/rgw_zone.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,6 @@ struct RGWPeriodConfig
517517
void dump(Formatter *f) const;
518518
void decode_json(JSONObj *obj);
519519

520-
// the period config must be stored in a local object outside of the period,
521-
// so that it can be used in a default configuration where no realm/period
522-
// exists
523-
int read(const DoutPrefixProvider *dpp, RGWSI_SysObj *sysobj_svc, const std::string& realm_id, optional_yield y);
524-
int write(const DoutPrefixProvider *dpp, RGWSI_SysObj *sysobj_svc, const std::string& realm_id, optional_yield y);
525-
526520
static std::string get_oid(const std::string& realm_id);
527521
static rgw_pool get_pool(CephContext *cct);
528522
};

src/rgw/rgw_rest_ratelimit.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
22
// vim: ts=8 sw=2 smarttab ft=cpp
33
#include "rgw_rest_ratelimit.h"
4+
#include "rgw_sal.h"
5+
#include "rgw_sal_config.h"
6+
47
class RGWOp_Ratelimit_Info : public RGWRESTOp {
58
int check_caps(const RGWUserCaps& caps) override {
69
return caps.check_cap("ratelimit", RGW_CAP_READ);
@@ -101,7 +104,9 @@ void RGWOp_Ratelimit_Info::execute(optional_yield y)
101104
if (global) {
102105
std::string realm_id = driver->get_zone()->get_realm_id();
103106
RGWPeriodConfig period_config;
104-
op_ret = period_config.read(this, static_cast<rgw::sal::RadosStore*>(driver)->svc()->sysobj, realm_id, y);
107+
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
108+
auto cfgstore = DriverManager::create_config_store(this, config_store_type);
109+
op_ret = cfgstore->read_period_config(this, y, realm_id, period_config);
105110
if (op_ret && op_ret != -ENOENT) {
106111
ldpp_dout(this, 0) << "Error on period config read" << dendl;
107112
return;
@@ -302,10 +307,13 @@ void RGWOp_Ratelimit_Set::execute(optional_yield y)
302307
op_ret = bucket->merge_and_store_attrs(this, attr, y);
303308
return;
304309
}
310+
311+
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
312+
auto cfgstore = DriverManager::create_config_store(s, config_store_type);
305313
if (global) {
306314
std::string realm_id = driver->get_zone()->get_realm_id();
307315
RGWPeriodConfig period_config;
308-
op_ret = period_config.read(s, static_cast<rgw::sal::RadosStore*>(driver)->svc()->sysobj, realm_id, y);
316+
op_ret = cfgstore->read_period_config(s, y, realm_id, period_config);
309317
if (op_ret && op_ret != -ENOENT) {
310318
ldpp_dout(this, 0) << "Error on period config read" << dendl;
311319
return;
@@ -316,7 +324,7 @@ void RGWOp_Ratelimit_Set::execute(optional_yield y)
316324
have_max_read_bytes, max_read_bytes, have_max_write_bytes, max_write_bytes,
317325
have_enabled, enabled, ratelimit_configured, ratelimit_info);
318326
period_config.bucket_ratelimit = ratelimit_info;
319-
op_ret = period_config.write(s, static_cast<rgw::sal::RadosStore*>(driver)->svc()->sysobj, realm_id, y);
327+
op_ret = cfgstore->write_period_config(s, y, false, realm_id, period_config);
320328
return;
321329
}
322330
if (ratelimit_scope == "anon") {
@@ -325,7 +333,7 @@ void RGWOp_Ratelimit_Set::execute(optional_yield y)
325333
have_max_read_bytes, max_read_bytes, have_max_write_bytes, max_write_bytes,
326334
have_enabled, enabled, ratelimit_configured, ratelimit_info);
327335
period_config.anon_ratelimit = ratelimit_info;
328-
op_ret = period_config.write(s, static_cast<rgw::sal::RadosStore*>(driver)->svc()->sysobj, realm_id, y);
336+
op_ret = cfgstore->write_period_config(s, y, false, realm_id, period_config);
329337
return;
330338
}
331339
if (ratelimit_scope == "user") {
@@ -334,7 +342,7 @@ void RGWOp_Ratelimit_Set::execute(optional_yield y)
334342
have_max_read_bytes, max_read_bytes, have_max_write_bytes, max_write_bytes,
335343
have_enabled, enabled, ratelimit_configured, ratelimit_info);
336344
period_config.user_ratelimit = ratelimit_info;
337-
op_ret = period_config.write(s, static_cast<rgw::sal::RadosStore*>(driver)->svc()->sysobj, realm_id, y);
345+
op_ret = cfgstore->write_period_config(s, y, false, realm_id, period_config);
338346
return;
339347
}
340348
}

src/rgw/rgw_zone.cc

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -613,43 +613,6 @@ int RGWZoneParams::fix_pool_names(const DoutPrefixProvider *dpp, optional_yield
613613
return 0;
614614
}
615615

616-
int RGWPeriodConfig::read(const DoutPrefixProvider *dpp, RGWSI_SysObj *sysobj_svc, const std::string& realm_id,
617-
optional_yield y)
618-
{
619-
const auto& pool = get_pool(sysobj_svc->ctx());
620-
const auto& oid = get_oid(realm_id);
621-
bufferlist bl;
622-
623-
auto sysobj = sysobj_svc->get_obj(rgw_raw_obj{pool, oid});
624-
int ret = sysobj.rop().read(dpp, &bl, y);
625-
if (ret < 0) {
626-
return ret;
627-
}
628-
using ceph::decode;
629-
try {
630-
auto iter = bl.cbegin();
631-
decode(*this, iter);
632-
} catch (buffer::error& err) {
633-
return -EIO;
634-
}
635-
return 0;
636-
}
637-
638-
int RGWPeriodConfig::write(const DoutPrefixProvider *dpp,
639-
RGWSI_SysObj *sysobj_svc,
640-
const std::string& realm_id, optional_yield y)
641-
{
642-
const auto& pool = get_pool(sysobj_svc->ctx());
643-
const auto& oid = get_oid(realm_id);
644-
bufferlist bl;
645-
using ceph::encode;
646-
encode(*this, bl);
647-
auto sysobj = sysobj_svc->get_obj(rgw_raw_obj{pool, oid});
648-
return sysobj.wop()
649-
.set_exclusive(false)
650-
.write(dpp, bl, y);
651-
}
652-
653616
void RGWPeriodConfig::decode_json(JSONObj *obj)
654617
{
655618
JSONDecoder::decode_json("bucket_quota", quota.bucket_quota, obj);

src/rgw/services/svc_zone.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ int RGWSI_Zone::do_start(optional_yield y, const DoutPrefixProvider *dpp)
291291
}
292292
// read period_config into current_period
293293
auto& period_config = current_period->get_config();
294-
ret = period_config.read(dpp, sysobj_svc, zonegroup->realm_id, y);
294+
ret = cfgstore->read_period_config(dpp, y, zonegroup->realm_id, period_config);
295295
if (ret < 0 && ret != -ENOENT) {
296296
ldout(cct, 0) << "ERROR: failed to read period config: "
297297
<< cpp_strerror(ret) << dendl;

0 commit comments

Comments
 (0)