Skip to content

Commit

Permalink
rgw: bucket reshard updates stats
Browse files Browse the repository at this point in the history
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
(cherry picked from commit dd71238)
See: http://tracker.ceph.com/issues/17556
See: #11368
Signed-off-by: Robin H. Johnson <robin.johnson@dreamhost.com>
  • Loading branch information
yehudasa authored and Robin H. Johnson committed Feb 9, 2017
1 parent 678dac9 commit cd2e35e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
18 changes: 5 additions & 13 deletions src/cls/rgw/cls_rgw.cc
Expand Up @@ -53,9 +53,6 @@ cls_method_handle_t h_rgw_gc_list;
cls_method_handle_t h_rgw_gc_remove;


#define ROUND_BLOCK_SIZE 4096


#define BI_PREFIX_CHAR 0x80

#define BI_BUCKET_OBJS_INDEX 0
Expand All @@ -73,11 +70,6 @@ static string bucket_index_prefixes[] = { "", /* special handling for the objs l
/* this must be the last index */
"9999_",};

static uint64_t get_rounded_size(uint64_t size)
{
return (size + ROUND_BLOCK_SIZE - 1) & ~(ROUND_BLOCK_SIZE - 1);
}

static bool bi_is_objs_index(const string& s) {
return ((unsigned char)s[0] != BI_PREFIX_CHAR);
}
Expand Down Expand Up @@ -541,7 +533,7 @@ static int check_index(cls_method_context_t hctx, struct rgw_bucket_dir_header *
struct rgw_bucket_category_stats& stats = calc_header->stats[entry.meta.category];
stats.num_entries++;
stats.total_size += entry.meta.accounted_size;
stats.total_size_rounded += get_rounded_size(entry.meta.accounted_size);
stats.total_size_rounded += cls_rgw_get_rounded_size(entry.meta.accounted_size);

start_obj = kiter->first;
}
Expand Down Expand Up @@ -746,7 +738,7 @@ static void unaccount_entry(struct rgw_bucket_dir_header& header, struct rgw_buc
struct rgw_bucket_category_stats& stats = header.stats[entry.meta.category];
stats.num_entries--;
stats.total_size -= entry.meta.accounted_size;
stats.total_size_rounded -= get_rounded_size(entry.meta.accounted_size);
stats.total_size_rounded -= cls_rgw_get_rounded_size(entry.meta.accounted_size);
}

static void log_entry(const char *func, const char *str, struct rgw_bucket_dir_entry *entry)
Expand Down Expand Up @@ -931,7 +923,7 @@ int rgw_bucket_complete_op(cls_method_context_t hctx, bufferlist *in, bufferlist
entry.tag = op.tag;
stats.num_entries++;
stats.total_size += meta.accounted_size;
stats.total_size_rounded += get_rounded_size(meta.accounted_size);
stats.total_size_rounded += cls_rgw_get_rounded_size(meta.accounted_size);
bufferlist new_key_bl;
::encode(entry, new_key_bl);
int ret = cls_cxx_map_set_val(hctx, idx, &new_key_bl);
Expand Down Expand Up @@ -1961,7 +1953,7 @@ int rgw_dir_suggest_changes(cls_method_context_t hctx, bufferlist *in, bufferlis
CLS_LOG(10, "total_entries: %" PRId64 " -> %" PRId64 "\n", old_stats.num_entries, old_stats.num_entries - 1);
old_stats.num_entries--;
old_stats.total_size -= cur_disk.meta.accounted_size;
old_stats.total_size_rounded -= get_rounded_size(cur_disk.meta.accounted_size);
old_stats.total_size_rounded -= cls_rgw_get_rounded_size(cur_disk.meta.accounted_size);
header_changed = true;
}
struct rgw_bucket_category_stats& stats =
Expand All @@ -1988,7 +1980,7 @@ int rgw_dir_suggest_changes(cls_method_context_t hctx, bufferlist *in, bufferlis
cur_change.key.name.c_str(), cur_change.key.instance.c_str(), stats.num_entries, stats.num_entries + 1);
stats.num_entries++;
stats.total_size += cur_change.meta.accounted_size;
stats.total_size_rounded += get_rounded_size(cur_change.meta.accounted_size);
stats.total_size_rounded += cls_rgw_get_rounded_size(cur_change.meta.accounted_size);
header_changed = true;
cur_change.index_ver = header.ver;
bufferlist cur_state_bl;
Expand Down
2 changes: 1 addition & 1 deletion src/cls/rgw/cls_rgw_client.h
Expand Up @@ -305,7 +305,7 @@ class CLSRGWIssueSetTagTimeout : public CLSRGWConcurrentIO {
};

void cls_rgw_bucket_update_stats(librados::ObjectWriteOperation& o, bool absolute,
map<uint8_t, rgw_bucket_category_stats>& stats);
const map<uint8_t, rgw_bucket_category_stats>& stats);

void cls_rgw_bucket_prepare_op(librados::ObjectWriteOperation& o, RGWModifyOp op, string& tag,
const cls_rgw_obj_key& key, const string& locator, bool log_op,
Expand Down
10 changes: 9 additions & 1 deletion src/cls/rgw/cls_rgw_types.cc
Expand Up @@ -237,8 +237,9 @@ void rgw_cls_bi_entry::dump(Formatter *f) const
dump_bi_entry(data, type, f);
}

void rgw_cls_bi_entry::get_key(cls_rgw_obj_key *key)
bool rgw_cls_bi_entry::get_info(cls_rgw_obj_key *key, uint8_t *category, rgw_bucket_category_stats *accounted_stats)
{
bool account = false;
bufferlist::iterator iter = data.begin();
switch (type) {
case PlainIdx:
Expand All @@ -247,6 +248,11 @@ void rgw_cls_bi_entry::get_key(cls_rgw_obj_key *key)
rgw_bucket_dir_entry entry;
::decode(entry, iter);
*key = entry.key;
*category = entry.meta.category;
accounted_stats->num_entries++;
accounted_stats->total_size += entry.meta.accounted_size;
accounted_stats->total_size_rounded += cls_rgw_get_rounded_size(entry.meta.accounted_size);
account = true;
}
break;
case OLHIdx:
Expand All @@ -259,6 +265,8 @@ void rgw_cls_bi_entry::get_key(cls_rgw_obj_key *key)
default:
break;
}

return account;
}

void rgw_bucket_olh_entry::dump(Formatter *f) const
Expand Down
11 changes: 10 additions & 1 deletion src/cls/rgw/cls_rgw_types.h
Expand Up @@ -49,6 +49,13 @@ enum RGWCheckMTimeType {
CLS_RGW_CHECK_TIME_MTIME_GE = 4,
};

#define ROUND_BLOCK_SIZE 4096

static inline uint64_t cls_rgw_get_rounded_size(uint64_t size)
{
return (size + ROUND_BLOCK_SIZE - 1) & ~(ROUND_BLOCK_SIZE - 1);
}

struct rgw_bucket_pending_info {
RGWPendingState state;
ceph::real_time timestamp;
Expand Down Expand Up @@ -361,6 +368,8 @@ enum BIIndexType {
OLHIdx = 3,
};

struct rgw_bucket_category_stats;

struct rgw_cls_bi_entry {
BIIndexType type;
string idx;
Expand Down Expand Up @@ -389,7 +398,7 @@ struct rgw_cls_bi_entry {
void dump(Formatter *f) const;
void decode_json(JSONObj *obj, cls_rgw_obj_key *effective_key = NULL);

void get_key(cls_rgw_obj_key *key);
bool get_info(cls_rgw_obj_key *key, uint8_t *category, rgw_bucket_category_stats *accounted_stats);
};
WRITE_CLASS_ENCODER(rgw_cls_bi_entry)

Expand Down
20 changes: 17 additions & 3 deletions src/rgw/rgw_admin.cc
Expand Up @@ -15,6 +15,8 @@
#include "common/errno.h"
#include "common/safe_io.h"

#include "cls/rgw/cls_rgw_client.h"

#include "global/global_init.h"

#include "include/utime.h"
Expand Down Expand Up @@ -2016,15 +2018,23 @@ class BucketReshardShard {
int num_shard;
RGWRados::BucketShard bs;
vector<rgw_cls_bi_entry> entries;
map<uint8_t, rgw_bucket_category_stats> stats;

public:
BucketReshardShard(RGWRados *_store, RGWBucketInfo& _bucket_info, int _num_shard) : store(_store), bucket_info(_bucket_info), bs(store) {
num_shard = (bucket_info.num_shards > 0 ? _num_shard : -1);
bs.init(bucket_info.bucket, num_shard);
}

int add_entry(rgw_cls_bi_entry& entry) {
int add_entry(rgw_cls_bi_entry& entry, bool account, uint8_t category,
rgw_bucket_category_stats entry_stats) {
entries.push_back(entry);
if (account) {
rgw_bucket_category_stats& target = stats[category];
target.num_entries += entry_stats.num_entries;
target.total_size += entry_stats.total_size;
target.total_size_rounded += entry_stats.total_size_rounded;
}
if (entries.size() >= RESHARD_SHARD_WINDOW) {
int ret = flush();
if (ret < 0) {
Expand All @@ -2042,12 +2052,14 @@ class BucketReshardShard {
for (auto& entry : entries) {
store->bi_put(op, bs, entry);
}
cls_rgw_bucket_update_stats(op, false, stats);
int ret = bs.index_ctx.operate(bs.bucket_obj, &op);
if (ret < 0) {
std::cerr << "ERROR: failed to store entries in target bucket shard (bs=" << bs.bucket << "/" << bs.shard_id << ") error=" << cpp_strerror(-ret) << std::endl;
return ret;
}
entries.clear();
stats.clear();
return 0;
}
};
Expand Down Expand Up @@ -4975,7 +4987,9 @@ int main(int argc, char **argv)

int target_shard_id;
cls_rgw_obj_key cls_key;
entry.get_key(&cls_key);
uint8_t category;
rgw_bucket_category_stats stats;
bool account = entry.get_info(&cls_key, &category, &stats);
rgw_obj_key key(cls_key);
rgw_obj obj(new_bucket_info.bucket, key);
int ret = store->get_target_shard_id(new_bucket_info, obj.get_hash_object(), &target_shard_id);
Expand All @@ -4986,7 +5000,7 @@ int main(int argc, char **argv)

int shard_index = (target_shard_id > 0 ? target_shard_id : 0);

ret = target_shards[shard_index]->add_entry(entry);
ret = target_shards[shard_index]->add_entry(entry, account, category, stats);
if (ret < 0) {
cerr << "ERROR: target_shards.add_entry(" << key << ") returned error: " << cpp_strerror(-ret) << std::endl;
return ret;
Expand Down

0 comments on commit cd2e35e

Please sign in to comment.