From b4ba5b156d102b60c2d77bcacccca2864aaa75e7 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 17 Jun 2019 18:35:42 -0700 Subject: [PATCH] rgw: use stl.user->read_stats() instead of cls_user_get_header() Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_op.cc | 3 +-- src/rgw/rgw_op.h | 1 + src/rgw/rgw_quota.cc | 11 +++++++---- src/rgw/rgw_rest_s3.cc | 6 +++--- src/rgw/rgw_user.cc | 7 +++++-- src/rgw/rgw_user.h | 4 +++- src/rgw/services/svc_user.h | 4 +++- src/rgw/services/svc_user_rados.cc | 12 +++++++++++- src/rgw/services/svc_user_rados.h | 4 +++- 9 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index b3b92581a21..2beb247839e 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2430,8 +2430,7 @@ void RGWGetUsage::execute() return; } - string user_str = s->user->user_id.to_str(); - op_ret = store->cls_user_get_header(user_str, &header); + op_ret = store->ctl.user->read_stats(s->user->user_id, &stats); if (op_ret < 0) { ldpp_dout(this, 0) << "ERROR: can't read user header" << dendl; return; diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 38e961b67ee..0d9a7f1ba30 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -744,6 +744,7 @@ protected: map summary_map; map buckets_usage; cls_user_header header; + RGWStorageStats stats; public: RGWGetUsage() : sent_data(false), show_log_entries(true), show_log_sum(true){ } diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc index 496daf0564d..e78e8a095e6 100644 --- a/src/rgw/rgw_quota.cc +++ b/src/rgw/rgw_quota.cc @@ -646,21 +646,24 @@ int RGWUserStatsCache::sync_bucket(const rgw_user& user, rgw_bucket& bucket) int RGWUserStatsCache::sync_user(const rgw_user& user) { - cls_user_header header; string user_str = user.to_str(); - int ret = store->cls_user_get_header(user_str, &header); + RGWStorageStats stats; + ceph::real_time last_stats_sync; + ceph::real_time last_stats_update; + + int ret = store->ctl.user->read_stats(user_str, &stats, &last_stats_sync, &last_stats_update); if (ret < 0) { ldout(store->ctx(), 5) << "ERROR: can't read user header: ret=" << ret << dendl; return ret; } if (!store->ctx()->_conf->rgw_user_quota_sync_idle_users && - header.last_stats_update < header.last_stats_sync) { + last_stats_update < last_stats_sync) { ldout(store->ctx(), 20) << "user is idle, not doing a full sync (user=" << user << ")" << dendl; return 0; } - real_time when_need_full_sync = header.last_stats_sync; + real_time when_need_full_sync = last_stats_sync; when_need_full_sync += make_timespan(store->ctx()->_conf->rgw_user_quota_sync_wait_time); // check if enough time passed since last full sync diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index ca5b044461b..d91d23cd746 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -758,9 +758,9 @@ void RGWGetUsage_ObjStore_S3::send_response() formatter->open_object_section("Stats"); } - encode_json("TotalBytes", header.stats.total_bytes, formatter); - encode_json("TotalBytesRounded", header.stats.total_bytes_rounded, formatter); - encode_json("TotalEntries", header.stats.total_entries, formatter); + encode_json("TotalBytes", stats.size, formatter); + encode_json("TotalBytesRounded", stats.size_rounded, formatter); + encode_json("TotalEntries", stats.num_objects, formatter); if (s->cct->_conf->rgw_rest_getusage_op_compat) { formatter->close_section(); //Stats diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index 1602e5d591d..9e19ccdab2e 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -2723,10 +2723,13 @@ int RGWUserCtl::reset_stats(const rgw_user& user) }); } -int RGWUserCtl::read_stats(const rgw_user& user, RGWStorageStats *stats) +int RGWUserCtl::read_stats(const rgw_user& user, RGWStorageStats *stats, + ceph::real_time *last_stats_sync, + ceph::real_time *last_stats_update) { return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - return svc.user->read_stats(op->ctx(), user, stats); + return svc.user->read_stats(op->ctx(), user, stats, + last_stats_sync, last_stats_update); }); } diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h index 20462b6e365..a17be948239 100644 --- a/src/rgw/rgw_user.h +++ b/src/rgw/rgw_user.h @@ -936,7 +936,9 @@ public: const RGWBucketEnt& ent); int complete_flush_stats(const rgw_user& user); int reset_stats(const rgw_user& user); - int read_stats(const rgw_user& user, RGWStorageStats *stats); + int read_stats(const rgw_user& user, RGWStorageStats *stats, + ceph::real_time *last_stats_sync = nullptr, /* last time a full stats sync completed */ + ceph::real_time *last_stats_update = nullptr); /* last time a stats update was done */ }; class RGWUserMetaHandlerAllocator { diff --git a/src/rgw/services/svc_user.h b/src/rgw/services/svc_user.h index fe7928a32de..ac164b26f20 100644 --- a/src/rgw/services/svc_user.h +++ b/src/rgw/services/svc_user.h @@ -110,6 +110,8 @@ public: virtual int reset_bucket_stats(RGWSI_MetaBackend::Context *ctx, const rgw_user& user) = 0; virtual int read_stats(RGWSI_MetaBackend::Context *ctx, - const rgw_user& user, RGWStorageStats *stats) = 0; + const rgw_user& user, RGWStorageStats *stats, + ceph::real_time *last_stats_sync, /* last time a full stats sync completed */ + ceph::real_time *last_stats_update) = 0; /* last time a stats update was done */ }; diff --git a/src/rgw/services/svc_user_rados.cc b/src/rgw/services/svc_user_rados.cc index 3c9cb0e7ca2..737b3824678 100644 --- a/src/rgw/services/svc_user_rados.cc +++ b/src/rgw/services/svc_user_rados.cc @@ -815,7 +815,9 @@ int RGWSI_User_RADOS::cls_user_get_header(const rgw_user& user, cls_user_header } int RGWSI_User_RADOS::read_stats(RGWSI_MetaBackend::Context *ctx, - const rgw_user& user, RGWStorageStats *stats) + const rgw_user& user, RGWStorageStats *stats, + ceph::real_time *last_stats_sync, + ceph::real_time *last_stats_update) { string user_str = user.to_str(); @@ -830,6 +832,14 @@ int RGWSI_User_RADOS::read_stats(RGWSI_MetaBackend::Context *ctx, stats->size_rounded = hs.total_bytes_rounded; stats->num_objects = hs.total_entries; + if (last_stats_sync) { + *last_stats_sync = header.last_stats_sync; + } + + if (last_stats_update) { + *last_stats_update = header.last_stats_update; + } + return 0; } diff --git a/src/rgw/services/svc_user_rados.h b/src/rgw/services/svc_user_rados.h index 70b8f7c7845..d717d707b37 100644 --- a/src/rgw/services/svc_user_rados.h +++ b/src/rgw/services/svc_user_rados.h @@ -180,6 +180,8 @@ public: int reset_bucket_stats(RGWSI_MetaBackend::Context *ctx, const rgw_user& user) override; int read_stats(RGWSI_MetaBackend::Context *ctx, - const rgw_user& user, RGWStorageStats *stats) override; + const rgw_user& user, RGWStorageStats *stats, + ceph::real_time *last_stats_sync, /* last time a full stats sync completed */ + ceph::real_time *last_stats_update) override; /* last time a stats update was done */ }; -- 2.39.5