return 0;
}
-static int check_index(cls_method_context_t hctx, struct rgw_bucket_dir_header *existing_header, struct rgw_bucket_dir_header *calc_header)
+static int check_index(cls_method_context_t hctx,
+ rgw_bucket_dir_header *existing_header,
+ rgw_bucket_dir_header *calc_header)
{
int rc = read_bucket_header(hctx, existing_header);
if (rc < 0) {
break;
}
- struct rgw_bucket_dir_entry entry;
+ rgw_bucket_dir_entry entry;
auto eiter = kiter->second.cbegin();
try {
decode(entry, eiter);
CLS_LOG(1, "ERROR: rgw_bucket_list(): failed to decode entry, key=%s\n", kiter->first.c_str());
return -EIO;
}
- struct rgw_bucket_category_stats& stats = calc_header->stats[entry.meta.category];
+ 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 += cls_rgw_get_rounded_size(entry.meta.accounted_size);
remove_key.name.c_str(), remove_key.instance.c_str(), ret);
continue;
}
- CLS_LOG(0, "rgw_bucket_complete_op(): entry.name=%s entry.instance=%s entry.meta.category=%d\n",
- remove_entry.key.name.c_str(), remove_entry.key.instance.c_str(), remove_entry.meta.category);
+ CLS_LOG(0,
+ "rgw_bucket_complete_op(): entry.name=%s entry.instance=%s entry.meta.category=%d\n",
+ remove_entry.key.name.c_str(),
+ remove_entry.key.instance.c_str(),
+ int(remove_entry.meta.category));
unaccount_entry(header, remove_entry);
if (op.log_op && !header.syncstopped) {
encode_olh_data_key(op.key, &idx);
break;
default:
- CLS_LOG(10, "%s(): invalid key type encoding: %d", __func__, op.type);
+ CLS_LOG(10, "%s(): invalid key type encoding: %d",
+ __func__, int(op.type));
return -EINVAL;
}
return issue_bucket_set_tag_timeout_op(io_ctx, oid, tag_timeout, &manager);
}
-void cls_rgw_bucket_update_stats(librados::ObjectWriteOperation& o, bool absolute,
- const map<uint8_t, rgw_bucket_category_stats>& stats)
+void cls_rgw_bucket_update_stats(librados::ObjectWriteOperation& o,
+ bool absolute,
+ const map<RGWObjCategory, rgw_bucket_category_stats>& stats)
{
struct rgw_cls_bucket_update_stats_op call;
call.absolute = absolute;
CLSRGWConcurrentIO(ioc, _bucket_objs, _max_aio), tag_timeout(_tag_timeout) {}
};
-void cls_rgw_bucket_update_stats(librados::ObjectWriteOperation& o, bool absolute,
- const map<uint8_t, rgw_bucket_category_stats>& stats);
+void cls_rgw_bucket_update_stats(librados::ObjectWriteOperation& o,
+ bool absolute,
+ const map<RGWObjCategory, 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,
{
rgw_cls_bucket_update_stats_op *r = new rgw_cls_bucket_update_stats_op;
r->absolute = true;
- rgw_bucket_category_stats& s = r->stats[0];
+ rgw_bucket_category_stats& s = r->stats[RGWObjCategory::None];
s.total_size = 1;
s.total_size_rounded = 4096;
s.num_entries = 1;
struct rgw_cls_bucket_update_stats_op
{
bool absolute{false};
- map<uint8_t, rgw_bucket_category_stats> stats;
+ map<RGWObjCategory, rgw_bucket_category_stats> stats;
rgw_cls_bucket_update_stats_op() {}
void rgw_bucket_dir_entry_meta::generate_test_instances(list<rgw_bucket_dir_entry_meta*>& o)
{
rgw_bucket_dir_entry_meta *m = new rgw_bucket_dir_entry_meta;
- m->category = 1;
+ m->category = RGWObjCategory::Main;
m->size = 100;
m->etag = "etag";
m->owner = "owner";
void rgw_bucket_dir_entry_meta::decode_json(JSONObj *obj) {
int val;
JSONDecoder::decode_json("category", val, obj);
- category = (uint8_t)val;
+ category = static_cast<RGWObjCategory>(val);
JSONDecoder::decode_json("size", size, obj);
utime_t ut;
JSONDecoder::decode_json("mtime", ut, obj);
dump_bi_entry(data, type, f);
}
-bool rgw_cls_bi_entry::get_info(cls_rgw_obj_key *key, uint8_t *category, rgw_bucket_category_stats *accounted_stats)
+bool rgw_cls_bi_entry::get_info(cls_rgw_obj_key *key,
+ RGWObjCategory *category,
+ rgw_bucket_category_stats *accounted_stats)
{
bool account = false;
auto iter = data.cbegin();
uint8_t i;
for (i = 0, iter = l.begin(); iter != l.end(); ++iter, ++i) {
+ RGWObjCategory c = static_cast<RGWObjCategory>(i);
rgw_bucket_dir_header *h = new rgw_bucket_dir_header;
rgw_bucket_category_stats *s = *iter;
- h->stats[i] = *s;
+ h->stats[c] = *s;
o.push_back(h);
{
f->dump_int("ver", ver);
f->dump_int("master_ver", master_ver);
- map<uint8_t, struct rgw_bucket_category_stats>::const_iterator iter = stats.begin();
f->open_array_section("stats");
- for (; iter != stats.end(); ++iter) {
- f->dump_int("category", (int)iter->first);
+ for (auto iter = stats.begin(); iter != stats.end(); ++iter) {
+ f->dump_int("category", int(iter->first));
f->open_object_section("category_stats");
iter->second.dump(f);
f->close_section();
};
WRITE_CLASS_ENCODER(rgw_bucket_pending_info)
+
+// categories of objects stored in a bucket index (b-i) and used to
+// differentiate their associated statistics (bucket stats, and in
+// some cases user stats)
+enum class RGWObjCategory : uint8_t {
+ None = 0, // b-i entries for delete markers; also used in
+ // testing and for default values in default
+ // constructors
+
+ Main = 1, // b-i entries for standard objs
+
+ Shadow = 2, // presumfably intended for multipart shadow
+ // uploads; not currently used in the codebase
+
+ MultiMeta = 3, // b-i entries for multipart upload metadata objs
+};
+
+
struct rgw_bucket_dir_entry_meta {
- uint8_t category;
+ RGWObjCategory category;
uint64_t size;
ceph::real_time mtime;
string etag;
string user_data;
rgw_bucket_dir_entry_meta() :
- category(0), size(0), accounted_size(0) { }
+ category(RGWObjCategory::None), size(0), accounted_size(0) { }
void encode(bufferlist &bl) const {
ENCODE_START(5, 3, bl);
void dump(Formatter *f) const;
void decode_json(JSONObj *obj, cls_rgw_obj_key *effective_key = NULL);
- bool get_info(cls_rgw_obj_key *key, uint8_t *category, rgw_bucket_category_stats *accounted_stats);
+ bool get_info(cls_rgw_obj_key *key, RGWObjCategory *category,
+ rgw_bucket_category_stats *accounted_stats);
};
WRITE_CLASS_ENCODER(rgw_cls_bi_entry)
WRITE_CLASS_ENCODER(cls_rgw_bucket_instance_entry)
struct rgw_bucket_dir_header {
- map<uint8_t, rgw_bucket_category_stats> stats;
+ map<RGWObjCategory, rgw_bucket_category_stats> stats;
uint64_t tag_timeout;
uint64_t ver;
uint64_t master_ver;
DEL_DIR = 1,
};
-enum RGWObjCategory {
- RGW_OBJ_CATEGORY_NONE = 0,
- RGW_OBJ_CATEGORY_MAIN = 1,
- RGW_OBJ_CATEGORY_SHADOW = 2,
- RGW_OBJ_CATEGORY_MULTIMETA = 3,
-};
-
enum HostStyle {
PathStyle = 0,
VirtualStyle = 1,
uint64_t num_objects;
RGWStorageStats()
- : category(RGW_OBJ_CATEGORY_NONE),
+ : category(RGWObjCategory::None),
size(0),
size_rounded(0),
num_objects(0) {}
static inline const char *rgw_obj_category_name(RGWObjCategory category)
{
switch (category) {
- case RGW_OBJ_CATEGORY_NONE:
+ case RGWObjCategory::None:
return "rgw.none";
- case RGW_OBJ_CATEGORY_MAIN:
+ case RGWObjCategory::Main:
return "rgw.main";
- case RGW_OBJ_CATEGORY_SHADOW:
+ case RGWObjCategory::Shadow:
return "rgw.shadow";
- case RGW_OBJ_CATEGORY_MULTIMETA:
+ case RGWObjCategory::MultiMeta:
return "rgw.multimeta";
}
RGWRados::ATTRSMOD_NONE,
copy_if_newer,
attrs,
- RGW_OBJ_CATEGORY_MAIN,
+ RGWObjCategory::Main,
versioned_epoch,
real_time(), /* delete_at */
NULL, /* string *ptag, */
if_nomatch,
attrs_mod,
copy_if_newer,
- attrs, RGW_OBJ_CATEGORY_MAIN,
+ attrs, RGWObjCategory::Main,
olh_epoch,
(delete_at ? *delete_at : real_time()),
(version_id.empty() ? NULL : &version_id),
RGWRados::Object::Write obj_op(&op_target);
obj_op.meta.owner = s->owner.get_id();
- obj_op.meta.category = RGW_OBJ_CATEGORY_MULTIMETA;
+ obj_op.meta.category = RGWObjCategory::MultiMeta;
obj_op.meta.flags = PUT_OBJ_CREATE_EXCL;
op_ret = obj_op.write_meta(0, 0, attrs);
static string default_storage_extra_pool_suffix = "rgw.buckets.non-ec";
static string log_lock_name = "rgw_log_lock";
-static RGWObjCategory main_category = RGW_OBJ_CATEGORY_MAIN;
+static RGWObjCategory main_category = RGWObjCategory::Main;
#define RGW_USAGE_OBJ_PREFIX "usage."
RGWRados::ATTRSMOD_NONE,
true, /* bool copy_if_newer */
state->attrset,
- RGW_OBJ_CATEGORY_MAIN,
+ RGWObjCategory::Main,
0, /* uint64_t olh_epoch */
real_time(), /* time_t delete_at */
NULL, /* string *version_id */
RGWRados::ATTRSMOD_NONE,
true, /* bool copy_if_newer */
no_attrs,
- RGW_OBJ_CATEGORY_MAIN,
+ RGWObjCategory::Main,
0, /* uint64_t olh_epoch */
real_time(), /* time_t delete_at */
nullptr, /* string *version_id */
int64_t poolid = ref.ioctx.get_id();
r = index_op.complete(poolid, epoch, state->size, state->accounted_size,
mtime, etag, content_type, &acl_bl,
- RGW_OBJ_CATEGORY_MAIN, NULL);
+ RGWObjCategory::Main, NULL);
} else {
int ret = index_op.cancel();
if (ret < 0) {
auto hiter = headers.begin();
for (; hiter != headers.end(); ++hiter) {
RGWObjCategory category = main_category;
- map<uint8_t, struct rgw_bucket_category_stats>::iterator iter = (hiter->stats).find((uint8_t)category);
+ auto iter = (hiter->stats).find(category);
if (iter != hiter->stats.end()) {
struct rgw_bucket_category_stats& stats = iter->second;
ent.count += stats.num_entries;
rgw_bucket_dir_entry ent;
ent.meta.mtime = removed_mtime;
obj.key.get_index_key(&ent.key);
- return cls_obj_complete_op(bs, obj, CLS_RGW_OP_DEL, tag, pool, epoch, ent, RGW_OBJ_CATEGORY_NONE, remove_objs, bilog_flags, zones_trace);
+ return cls_obj_complete_op(bs, obj, CLS_RGW_OP_DEL, tag, pool, epoch,
+ ent, RGWObjCategory::None, remove_objs,
+ bilog_flags, zones_trace);
}
int RGWRados::cls_obj_complete_cancel(BucketShard& bs, string& tag, rgw_obj& obj, uint16_t bilog_flags, rgw_zone_set *zones_trace)
{
rgw_bucket_dir_entry ent;
obj.key.get_index_key(&ent.key);
- return cls_obj_complete_op(bs, obj, CLS_RGW_OP_CANCEL, tag, -1 /* pool id */, 0, ent, RGW_OBJ_CATEGORY_NONE, NULL, bilog_flags, zones_trace);
+ return cls_obj_complete_op(bs, obj, CLS_RGW_OP_CANCEL, tag,
+ -1 /* pool id */, 0, ent,
+ RGWObjCategory::None, NULL, bilog_flags,
+ zones_trace);
}
int RGWRados::cls_obj_set_bucket_tag_timeout(RGWBucketInfo& bucket_info, uint64_t timeout)
for (const auto& hiter : headers) {
for (const auto& iter : hiter.stats) {
- if (uint8_t(RGW_OBJ_CATEGORY_MAIN) == iter.first ||
- uint8_t(RGW_OBJ_CATEGORY_MULTIMETA) == iter.first) {
+ if (RGWObjCategory::Main == iter.first ||
+ RGWObjCategory::MultiMeta == iter.first) {
const struct rgw_bucket_category_stats& header_stats = iter.second;
entry.size += header_stats.total_size;
entry.size_rounded += header_stats.total_size_rounded;
bool completeMultipart;
MetaParams() : mtime(NULL), rmattrs(NULL), data(NULL), manifest(NULL), ptag(NULL),
- remove_objs(NULL), category(RGW_OBJ_CATEGORY_MAIN), flags(0),
+ remove_objs(NULL), category(RGWObjCategory::Main), flags(0),
if_match(NULL), if_nomatch(NULL), canceled(false), user_data(nullptr), zones_trace(nullptr),
modify_tail(false), completeMultipart(false) {}
} meta;
int num_shard;
RGWRados::BucketShard bs;
vector<rgw_cls_bi_entry> entries;
- map<uint8_t, rgw_bucket_category_stats> stats;
+ map<RGWObjCategory, rgw_bucket_category_stats> stats;
deque<librados::AioCompletion *>& aio_completions;
uint64_t max_aio_completions;
uint64_t reshard_shard_batch_size;
return num_shard;
}
- int add_entry(rgw_cls_bi_entry& entry, bool account, uint8_t category,
+ int add_entry(rgw_cls_bi_entry& entry, bool account, RGWObjCategory category,
const rgw_bucket_category_stats& entry_stats) {
entries.push_back(entry);
if (account) {
}
int add_entry(int shard_index,
- rgw_cls_bi_entry& entry, bool account, uint8_t category,
+ rgw_cls_bi_entry& entry, bool account, RGWObjCategory category,
const rgw_bucket_category_stats& entry_stats) {
int ret = target_shards[shard_index]->add_entry(entry, account, category,
entry_stats);
int target_shard_id;
cls_rgw_obj_key cls_key;
- uint8_t category;
+ RGWObjCategory category;
rgw_bucket_category_stats stats;
bool account = entry.get_info(&cls_key, &category, &stats);
rgw_obj_key key(cls_key);
}
};
-void test_stats(librados::IoCtx& ioctx, string& oid, int category, uint64_t num_entries, uint64_t total_size)
+void test_stats(librados::IoCtx& ioctx, string& oid, RGWObjCategory category, uint64_t num_entries, uint64_t total_size)
{
map<int, struct rgw_cls_list_ret> results;
map<int, string> oids;
index_prepare(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, obj, loc);
- test_stats(ioctx, bucket_oid, 0, i, obj_size * i);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, i, obj_size * i);
op = mgr.write_op();
rgw_bucket_dir_entry_meta meta;
- meta.category = 0;
+ meta.category = RGWObjCategory::None;
meta.size = obj_size;
index_complete(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, epoch, obj, meta);
}
- test_stats(ioctx, bucket_oid, 0, NUM_OBJS, obj_size * NUM_OBJS);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, NUM_OBJS,
+ obj_size * NUM_OBJS);
}
TEST(cls_rgw, index_multiple_obj_writers)
index_prepare(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, obj, loc);
- test_stats(ioctx, bucket_oid, 0, 0, 0);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, 0, 0);
}
for (int i = NUM_OBJS; i > 0; i--) {
string tag = str_int("tag", i - 1);
rgw_bucket_dir_entry_meta meta;
- meta.category = 0;
+ meta.category = RGWObjCategory::None;
meta.size = obj_size * i;
index_complete(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, i, obj, meta);
/* verify that object size doesn't change, as we went back with epoch */
- test_stats(ioctx, bucket_oid, 0, 1, obj_size * NUM_OBJS);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, 1,
+ obj_size * NUM_OBJS);
}
}
index_prepare(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, obj, loc);
- test_stats(ioctx, bucket_oid, 0, i, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, i, total_size);
rgw_bucket_dir_entry_meta meta;
- meta.category = 0;
+ meta.category = RGWObjCategory::None;
meta.size = i * obj_size;
total_size += i * obj_size;
index_complete(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, ++epoch, obj, meta);
- test_stats(ioctx, bucket_oid, 0, i + 1, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, i + 1, total_size);
}
int i = NUM_OBJS / 2;
index_prepare(mgr, ioctx, bucket_oid, CLS_RGW_OP_DEL, tag_remove, obj, loc);
index_prepare(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag_modify, obj, loc);
- test_stats(ioctx, bucket_oid, 0, NUM_OBJS, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, NUM_OBJS, total_size);
rgw_bucket_dir_entry_meta meta;
/* verify stats correct */
total_size -= i * obj_size;
- test_stats(ioctx, bucket_oid, 0, NUM_OBJS - 1, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, NUM_OBJS - 1, total_size);
meta.size = 512;
- meta.category = 0;
+ meta.category = RGWObjCategory::None;
/* complete object modification */
index_complete(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag_modify, ++epoch, obj, meta);
/* verify stats correct */
total_size += meta.size;
- test_stats(ioctx, bucket_oid, 0, NUM_OBJS, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, NUM_OBJS, total_size);
/* prepare both removal and modification on the same object, this time we'll
/* complete modification */
total_size -= meta.size;
meta.size = i * obj_size * 2;
- meta.category = 0;
+ meta.category = RGWObjCategory::None;
/* complete object modification */
index_complete(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag_modify, ++epoch, obj, meta);
/* verify stats correct */
total_size += meta.size;
- test_stats(ioctx, bucket_oid, 0, NUM_OBJS, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, NUM_OBJS, total_size);
/* complete object removal */
index_complete(mgr, ioctx, bucket_oid, CLS_RGW_OP_DEL, tag_remove, ++epoch, obj, meta);
/* verify stats correct */
total_size -= meta.size;
- test_stats(ioctx, bucket_oid, 0, NUM_OBJS - 1, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, NUM_OBJS - 1,
+ total_size);
}
TEST(cls_rgw, index_suggest)
index_prepare(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, obj, loc);
- test_stats(ioctx, bucket_oid, 0, i, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, i, total_size);
rgw_bucket_dir_entry_meta meta;
- meta.category = 0;
+ meta.category = RGWObjCategory::None;
meta.size = obj_size;
total_size += meta.size;
index_complete(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, ++epoch, obj, meta);
- test_stats(ioctx, bucket_oid, 0, i + 1, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, i + 1, total_size);
}
/* prepare (without completion) some of the objects */
index_prepare(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, obj, loc);
- test_stats(ioctx, bucket_oid, 0, num_objs, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, num_objs, total_size);
}
int actual_num_objs = num_objs;
index_prepare(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, obj, loc);
- test_stats(ioctx, bucket_oid, 0, actual_num_objs, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, actual_num_objs, total_size);
rgw_bucket_dir_entry_meta meta;
index_complete(mgr, ioctx, bucket_oid, CLS_RGW_OP_DEL, tag, ++epoch, obj, meta);
total_size -= obj_size;
actual_num_objs--;
- test_stats(ioctx, bucket_oid, 0, actual_num_objs, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, actual_num_objs, total_size);
}
bufferlist updates;
cls_rgw_suggest_changes(*op, updates);
ASSERT_EQ(0, ioctx.operate(bucket_oid, op));
- test_stats(ioctx, bucket_oid, 0, num_objs / 2, total_size);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, num_objs / 2, total_size);
}
/*
op = mgr.write_op();
rgw_bucket_dir_entry_meta meta;
- meta.category = 0;
+ meta.category = RGWObjCategory::None;
meta.size = obj_size;
index_complete(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, epoch, obj, meta);
}
- test_stats(ioctx, bucket_oid, 0, num_objs, obj_size * num_objs);
+ test_stats(ioctx, bucket_oid, RGWObjCategory::None, num_objs, obj_size * num_objs);
map<int, string> oids = { {0, bucket_oid} };
map<int, struct rgw_cls_list_ret> list_results;
index_prepare(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, obj, loc, RGW_BILOG_FLAG_VERSIONED_OP);
op = mgr.write_op();
rgw_bucket_dir_entry_meta meta;
- meta.category = 0;
+ meta.category = RGWObjCategory::None;
meta.size = obj_size;
index_complete(mgr, ioctx, bucket_oid, CLS_RGW_OP_ADD, tag, epoch, obj, meta, RGW_BILOG_FLAG_VERSIONED_OP);
}