make it more generic, will be reused for user's stats.
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
cout << std::endl;
}
-static void dump_bucket_usage(map<RGWObjCategory, RGWBucketStats>& stats, Formatter *formatter)
+static void dump_bucket_usage(map<RGWObjCategory, RGWStorageStats>& stats, Formatter *formatter)
{
- map<RGWObjCategory, RGWBucketStats>::iterator iter;
+ map<RGWObjCategory, RGWStorageStats>::iterator iter;
formatter->open_object_section("usage");
for (iter = stats.begin(); iter != stats.end(); ++iter) {
- RGWBucketStats& s = iter->second;
+ RGWStorageStats& s = iter->second;
const char *cat_name = rgw_obj_category_name(iter->first);
formatter->open_object_section(cat_name);
formatter->dump_int("size_kb", s.num_kb);
if (r < 0)
return r;
- map<RGWObjCategory, RGWBucketStats> stats;
+ map<RGWObjCategory, RGWStorageStats> stats;
uint64_t bucket_ver, master_ver;
string max_marker;
int ret = store->get_bucket_stats(bucket, &bucket_ver, &master_ver, stats, &max_marker);
int rgw_remove_bucket(RGWRados *store, const string& bucket_owner, rgw_bucket& bucket, bool delete_children)
{
int ret;
- map<RGWObjCategory, RGWBucketStats> stats;
+ map<RGWObjCategory, RGWStorageStats> stats;
std::vector<RGWObjEnt> objs;
std::string prefix, delim, marker, ns;
map<string, bool> common_prefixes;
}
}
-static void dump_bucket_usage(map<RGWObjCategory, RGWBucketStats>& stats, Formatter *formatter)
+static void dump_bucket_usage(map<RGWObjCategory, RGWStorageStats>& stats, Formatter *formatter)
{
- map<RGWObjCategory, RGWBucketStats>::iterator iter;
+ map<RGWObjCategory, RGWStorageStats>::iterator iter;
formatter->open_object_section("usage");
for (iter = stats.begin(); iter != stats.end(); ++iter) {
- RGWBucketStats& s = iter->second;
+ RGWStorageStats& s = iter->second;
const char *cat_name = rgw_obj_category_name(iter->first);
formatter->open_object_section(cat_name);
formatter->dump_int("size_kb", s.num_kb);
formatter->close_section();
}
-static void dump_index_check(map<RGWObjCategory, RGWBucketStats> existing_stats,
- map<RGWObjCategory, RGWBucketStats> calculated_stats,
+static void dump_index_check(map<RGWObjCategory, RGWStorageStats> existing_stats,
+ map<RGWObjCategory, RGWStorageStats> calculated_stats,
Formatter *formatter)
{
formatter->open_object_section("check_result");
int RGWBucket::check_index(RGWBucketAdminOpState& op_state,
- map<RGWObjCategory, RGWBucketStats>& existing_stats,
- map<RGWObjCategory, RGWBucketStats>& calculated_stats,
+ map<RGWObjCategory, RGWStorageStats>& existing_stats,
+ map<RGWObjCategory, RGWStorageStats>& calculated_stats,
std::string *err_msg)
{
rgw_bucket bucket = op_state.get_bucket();
{
int ret;
map<string, RGWObjEnt> result;
- map<RGWObjCategory, RGWBucketStats> existing_stats;
- map<RGWObjCategory, RGWBucketStats> calculated_stats;
+ map<RGWObjCategory, RGWStorageStats> existing_stats;
+ map<RGWObjCategory, RGWStorageStats> calculated_stats;
list<std::string> objs_to_unlink;
RGWBucket bucket;
{
RGWBucketInfo bucket_info;
rgw_bucket bucket;
- map<RGWObjCategory, RGWBucketStats> stats;
+ map<RGWObjCategory, RGWStorageStats> stats;
time_t mtime;
int r = store->get_bucket_info(NULL, bucket_name, bucket_info, &mtime);
map<string, RGWObjEnt> result, std::string *err_msg = NULL);
int check_index(RGWBucketAdminOpState& op_state,
- map<RGWObjCategory, RGWBucketStats>& existing_stats,
- map<RGWObjCategory, RGWBucketStats>& calculated_stats,
+ map<RGWObjCategory, RGWStorageStats>& existing_stats,
+ map<RGWObjCategory, RGWStorageStats>& calculated_stats,
std::string *err_msg = NULL);
int remove(RGWBucketAdminOpState& op_state, std::string *err_msg = NULL);
};
WRITE_CLASS_ENCODER(RGWBucketEntryPoint)
-struct RGWBucketStats
+struct RGWStorageStats
{
RGWObjCategory category;
uint64_t num_kb;
uint64_t num_kb_rounded;
uint64_t num_objects;
- RGWBucketStats() : num_kb(0), num_kb_rounded(0), num_objects(0) {}
+ RGWStorageStats() : num_kb(0), num_kb_rounded(0), num_objects(0) {}
};
struct req_state;
struct RGWQuotaBucketStats {
- RGWBucketStats stats;
+ RGWStorageStats stats;
utime_t expiration;
utime_t async_refresh_time;
};
lru_map<rgw_bucket, RGWQuotaBucketStats> stats_map;
RefCountedWaitObject *async_refcount;
- int fetch_bucket_totals(rgw_bucket& bucket, RGWBucketStats& stats);
+ int fetch_bucket_totals(rgw_bucket& bucket, RGWStorageStats& stats);
public:
RGWBucketStatsCache(RGWRados *_store) : store(_store), stats_map(store->ctx()->_conf->rgw_bucket_quota_cache_size) {
async_refcount->put_wait(); /* wait for all pending async requests to complete */
}
- int get_bucket_stats(rgw_bucket& bucket, RGWBucketStats& stats, RGWQuotaInfo& quota);
+ int get_bucket_stats(rgw_bucket& bucket, RGWStorageStats& stats, RGWQuotaInfo& quota);
void adjust_bucket_stats(const string& bucket_owner, rgw_bucket& bucket, int objs_delta, uint64_t added_bytes, uint64_t removed_bytes);
- bool can_use_cached_stats(RGWQuotaInfo& quota, RGWBucketStats& stats);
+ bool can_use_cached_stats(RGWQuotaInfo& quota, RGWStorageStats& stats);
- void set_stats(rgw_bucket& bucket, RGWQuotaBucketStats& qs, RGWBucketStats& stats);
+ void set_stats(rgw_bucket& bucket, RGWQuotaBucketStats& qs, RGWStorageStats& stats);
int async_refresh(rgw_bucket& bucket, RGWQuotaBucketStats& qs);
- void async_refresh_response(rgw_bucket& bucket, RGWBucketStats& stats);
+ void async_refresh_response(rgw_bucket& bucket, RGWStorageStats& stats);
};
-bool RGWBucketStatsCache::can_use_cached_stats(RGWQuotaInfo& quota, RGWBucketStats& cached_stats)
+bool RGWBucketStatsCache::can_use_cached_stats(RGWQuotaInfo& quota, RGWStorageStats& cached_stats)
{
if (quota.max_size_kb >= 0) {
if (quota.max_size_soft_threshold < 0) {
return true;
}
-int RGWBucketStatsCache::fetch_bucket_totals(rgw_bucket& bucket, RGWBucketStats& stats)
+int RGWBucketStatsCache::fetch_bucket_totals(rgw_bucket& bucket, RGWStorageStats& stats)
{
RGWBucketInfo bucket_info;
uint64_t bucket_ver;
uint64_t master_ver;
- map<RGWObjCategory, RGWBucketStats> bucket_stats;
+ map<RGWObjCategory, RGWStorageStats> bucket_stats;
int r = store->get_bucket_stats(bucket, &bucket_ver, &master_ver, bucket_stats, NULL);
if (r < 0) {
ldout(store->ctx(), 0) << "could not get bucket info for bucket=" << bucket.name << dendl;
return r;
}
- stats = RGWBucketStats();
+ stats = RGWStorageStats();
- map<RGWObjCategory, RGWBucketStats>::iterator iter;
+ map<RGWObjCategory, RGWStorageStats>::iterator iter;
for (iter = bucket_stats.begin(); iter != bucket_stats.end(); ++iter) {
- RGWBucketStats& s = iter->second;
+ RGWStorageStats& s = iter->second;
stats.num_kb += s.num_kb;
stats.num_kb_rounded += s.num_kb_rounded;
stats.num_objects += s.num_objects;
int AsyncRefreshHandler::init_fetch()
{
ldout(store->ctx(), 20) << "initiating async quota refresh for bucket=" << bucket << dendl;
- map<RGWObjCategory, RGWBucketStats> bucket_stats;
+ map<RGWObjCategory, RGWStorageStats> bucket_stats;
int r = store->get_bucket_stats_async(bucket, this);
if (r < 0) {
ldout(store->ctx(), 0) << "could not get bucket info for bucket=" << bucket.name << dendl;
return; /* nothing to do here */
}
- RGWBucketStats bs;
+ RGWStorageStats bs;
- map<RGWObjCategory, RGWBucketStats>::iterator iter;
+ map<RGWObjCategory, RGWStorageStats>::iterator iter;
for (iter = stats->begin(); iter != stats->end(); ++iter) {
- RGWBucketStats& s = iter->second;
+ RGWStorageStats& s = iter->second;
bs.num_kb += s.num_kb;
bs.num_kb_rounded += s.num_kb_rounded;
bs.num_objects += s.num_objects;
return 0;
}
-void RGWBucketStatsCache::async_refresh_response(rgw_bucket& bucket, RGWBucketStats& stats)
+void RGWBucketStatsCache::async_refresh_response(rgw_bucket& bucket, RGWStorageStats& stats)
{
ldout(store->ctx(), 20) << "async stats refresh response for bucket=" << bucket << dendl;
async_refcount->put();
}
-void RGWBucketStatsCache::set_stats(rgw_bucket& bucket, RGWQuotaBucketStats& qs, RGWBucketStats& stats)
+void RGWBucketStatsCache::set_stats(rgw_bucket& bucket, RGWQuotaBucketStats& qs, RGWStorageStats& stats)
{
qs.stats = stats;
qs.expiration = ceph_clock_now(store->ctx());
stats_map.add(bucket, qs);
}
-int RGWBucketStatsCache::get_bucket_stats(rgw_bucket& bucket, RGWBucketStats& stats, RGWQuotaInfo& quota) {
+int RGWBucketStatsCache::get_bucket_stats(rgw_bucket& bucket, RGWStorageStats& stats, RGWQuotaInfo& quota) {
RGWQuotaBucketStats qs;
utime_t now = ceph_clock_now(store->ctx());
if (stats_map.find(bucket, qs)) {
return 0;
}
- RGWBucketStats stats;
+ RGWStorageStats stats;
int ret = stats_cache.get_bucket_stats(bucket, stats, bucket_quota);
if (ret < 0)
return 0;
}
-static void translate_raw_stats(rgw_bucket_dir_header& header, map<RGWObjCategory, RGWBucketStats>& stats)
+static void translate_raw_stats(rgw_bucket_dir_header& header, map<RGWObjCategory, RGWStorageStats>& stats)
{
map<uint8_t, struct rgw_bucket_category_stats>::iterator iter = header.stats.begin();
for (; iter != header.stats.end(); ++iter) {
RGWObjCategory category = (RGWObjCategory)iter->first;
- RGWBucketStats& s = stats[category];
+ RGWStorageStats& s = stats[category];
struct rgw_bucket_category_stats& header_stats = iter->second;
s.category = (RGWObjCategory)iter->first;
s.num_kb = ((header_stats.total_size + 1023) / 1024);
}
int RGWRados::bucket_check_index(rgw_bucket& bucket,
- map<RGWObjCategory, RGWBucketStats> *existing_stats,
- map<RGWObjCategory, RGWBucketStats> *calculated_stats)
+ map<RGWObjCategory, RGWStorageStats> *existing_stats,
+ map<RGWObjCategory, RGWStorageStats> *calculated_stats)
{
librados::IoCtx index_ctx;
string oid;
return 0;
}
-int RGWRados::get_bucket_stats(rgw_bucket& bucket, uint64_t *bucket_ver, uint64_t *master_ver, map<RGWObjCategory, RGWBucketStats>& stats,
+int RGWRados::get_bucket_stats(rgw_bucket& bucket, uint64_t *bucket_ver, uint64_t *master_ver, map<RGWObjCategory, RGWStorageStats>& stats,
string *max_marker)
{
rgw_bucket_dir_header header;
public:
RGWGetBucketStatsContext(RGWGetBucketStats_CB *_cb) : cb(_cb) {}
void handle_response(int r, rgw_bucket_dir_header& header) {
- map<RGWObjCategory, RGWBucketStats> stats;
+ map<RGWObjCategory, RGWStorageStats> stats;
if (r >= 0) {
translate_raw_stats(header, stats);
rgw_bucket bucket;
uint64_t bucket_ver;
uint64_t master_ver;
- map<RGWObjCategory, RGWBucketStats> *stats;
+ map<RGWObjCategory, RGWStorageStats> *stats;
string max_marker;
public:
RGWGetBucketStats_CB(rgw_bucket& _bucket) : bucket(_bucket), stats(NULL) {}
virtual ~RGWGetBucketStats_CB() {}
virtual void handle_response(int r) = 0;
virtual void set_response(uint64_t _bucket_ver, uint64_t _master_ver,
- map<RGWObjCategory, RGWBucketStats> *_stats,
+ map<RGWObjCategory, RGWStorageStats> *_stats,
const string &_max_marker) {
bucket_ver = _bucket_ver;
master_ver = _master_ver;
}
int decode_policy(bufferlist& bl, ACLOwner *owner);
- int get_bucket_stats(rgw_bucket& bucket, uint64_t *bucket_ver, uint64_t *master_ver, map<RGWObjCategory, RGWBucketStats>& stats,
+ int get_bucket_stats(rgw_bucket& bucket, uint64_t *bucket_ver, uint64_t *master_ver, map<RGWObjCategory, RGWStorageStats>& stats,
string *max_marker);
int get_bucket_stats_async(rgw_bucket& bucket, RGWGetBucketStats_CB *cb);
void get_bucket_instance_obj(rgw_bucket& bucket, rgw_obj& obj);
int defer_gc(void *ctx, rgw_obj& obj);
int bucket_check_index(rgw_bucket& bucket,
- map<RGWObjCategory, RGWBucketStats> *existing_stats,
- map<RGWObjCategory, RGWBucketStats> *calculated_stats);
+ map<RGWObjCategory, RGWStorageStats> *existing_stats,
+ map<RGWObjCategory, RGWStorageStats> *calculated_stats);
int bucket_rebuild_index(rgw_bucket& bucket);
int remove_objs_from_index(rgw_bucket& bucket, list<string>& oid_list);
return;
}
}
- map<RGWObjCategory, RGWBucketStats> stats;
+ map<RGWObjCategory, RGWStorageStats> stats;
int ret = store->get_bucket_stats(bucket_info.bucket, &bucket_ver, &master_ver, stats, &max_marker);
if (ret < 0 && ret != -ENOENT) {
http_ret = ret;