Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yehudasa committed Oct 19, 2016
1 parent 218989c commit 71cf9c2
Show file tree
Hide file tree
Showing 12 changed files with 402 additions and 330 deletions.
5 changes: 0 additions & 5 deletions src/cls/user/cls_user_types.cc
Expand Up @@ -11,18 +11,13 @@ void cls_user_gen_test_bucket(cls_user_bucket *bucket, int i)
snprintf(buf, sizeof(buf), ".%d", i);

bucket->name = string("buck") + buf;
bucket->data_pool = string(".data.pool") + buf;
bucket->index_pool = string(".index.pool") + buf;
bucket->marker = string("mark") + buf;
bucket->bucket_id = string("bucket.id") + buf;
}

void cls_user_bucket::dump(Formatter *f) const
{
encode_json("name", name, f);
encode_json("data_pool", data_pool,f);
encode_json("data_extra_pool", data_extra_pool,f);
encode_json("index_pool", index_pool,f);
encode_json("marker", marker,f);
encode_json("bucket_id", bucket_id,f);
}
Expand Down
47 changes: 32 additions & 15 deletions src/cls/user/cls_user_types.h
Expand Up @@ -14,26 +14,34 @@
*/
struct cls_user_bucket {
std::string name;
std::string data_pool;
std::string index_pool;
std::string marker;
std::string bucket_id;
std::string data_extra_pool;
std::string placement_id;
struct {
std::string data_pool;
std::string index_pool;
std::string data_extra_pool;
} explicit_placement;

void encode(bufferlist& bl) const {
ENCODE_START(7, 3, bl);
ENCODE_START(8, 8, bl);
::encode(name, bl);
::encode(data_pool, bl);
::encode(marker, bl);
::encode(bucket_id, bl);
::encode(index_pool, bl);
::encode(data_extra_pool, bl);
::encode(placement_id, bl);
if (placement_id.empty()) {
::encode(explicit_placement.data_pool, bl);
::encode(explicit_placement.index_pool, bl);
::encode(explicit_placement.data_extra_pool, bl);
}
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START_LEGACY_COMPAT_LEN(7, 3, 3, bl);
DECODE_START_LEGACY_COMPAT_LEN(8, 3, 3, bl);
::decode(name, bl);
::decode(data_pool, bl);
if (struct_v < 8) {
::decode(explicit_placement.data_pool, bl);
}
if (struct_v >= 2) {
::decode(marker, bl);
if (struct_v <= 3) {
Expand All @@ -46,13 +54,22 @@ struct cls_user_bucket {
::decode(bucket_id, bl);
}
}
if (struct_v >= 5) {
::decode(index_pool, bl);
if (struct_v < 8) {
if (struct_v >= 5) {
::decode(explicit_placement.index_pool, bl);
} else {
explicit_placement.index_pool = explicit_placement.data_pool;
}
if (struct_v >= 7) {
::decode(explicit_placement.data_extra_pool, bl);
}
} else {
index_pool = data_pool;
}
if (struct_v >= 7) {
::decode(data_extra_pool, bl);
::decode(placement_id, bl);
if (placement_id.empty()) {
::decode(explicit_placement.data_pool, bl);
::decode(explicit_placement.index_pool, bl);
::decode(explicit_placement.data_extra_pool, bl);
}
}
DECODE_FINISH(bl);
}
Expand Down
14 changes: 7 additions & 7 deletions src/rgw/rgw_admin.cc
Expand Up @@ -853,14 +853,14 @@ int bucket_stats(rgw_bucket& bucket, int shard_id, Formatter *formatter)
map<RGWObjCategory, RGWStorageStats> stats;
string bucket_ver, master_ver;
string max_marker;
int ret = store->get_bucket_stats(bucket, shard_id, &bucket_ver, &master_ver, stats, &max_marker);
int ret = store->get_bucket_stats(bucket_info, shard_id, &bucket_ver, &master_ver, stats, &max_marker);
if (ret < 0) {
cerr << "error getting bucket stats ret=" << ret << std::endl;
return ret;
}
formatter->open_object_section("stats");
formatter->dump_string("bucket", bucket.name);
::encode_json("placement", bucket.placement, formatter);
::encode_json("explicit_placement", bucket.explicit_placement, formatter);

formatter->dump_string("id", bucket.bucket_id);
formatter->dump_string("marker", bucket.marker);
Expand Down Expand Up @@ -4517,7 +4517,7 @@ int main(int argc, char **argv)
formatter->open_array_section("objects");
while (is_truncated) {
map<string, RGWObjEnt> result;
int r = store->cls_bucket_list(bucket, RGW_NO_SHARD, marker, prefix, 1000, true,
int r = store->cls_bucket_list(bucket_info, RGW_NO_SHARD, marker, prefix, 1000, true,
result, &is_truncated, &marker,
bucket_object_check_filter);

Expand Down Expand Up @@ -4588,7 +4588,7 @@ int main(int argc, char **argv)
list<rgw_obj_key> oid_list;
rgw_obj_key key(object, object_version);
oid_list.push_back(key);
ret = store->remove_objs_from_index(bucket, oid_list);
ret = store->remove_objs_from_index(bucket_info, oid_list);
if (ret < 0) {
cerr << "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret) << std::endl;
return 1;
Expand Down Expand Up @@ -5318,7 +5318,7 @@ int main(int argc, char **argv)

do {
list<rgw_bi_log_entry> entries;
ret = store->list_bi_log_entries(bucket, shard_id, marker, max_entries - count, entries, &truncated);
ret = store->list_bi_log_entries(bucket_info, shard_id, marker, max_entries - count, entries, &truncated);
if (ret < 0) {
cerr << "ERROR: list_bi_log_entries(): " << cpp_strerror(-ret) << std::endl;
return -ret;
Expand Down Expand Up @@ -5427,7 +5427,7 @@ int main(int argc, char **argv)
cerr << "ERROR: could not init bucket: " << cpp_strerror(-ret) << std::endl;
return -ret;
}
ret = store->trim_bi_log_entries(bucket, shard_id, start_marker, end_marker);
ret = store->trim_bi_log_entries(bucket_info, shard_id, start_marker, end_marker);
if (ret < 0) {
cerr << "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret) << std::endl;
return -ret;
Expand All @@ -5446,7 +5446,7 @@ int main(int argc, char **argv)
return -ret;
}
map<int, string> markers;
ret = store->get_bi_log_status(bucket, shard_id, markers);
ret = store->get_bi_log_status(bucket_info, shard_id, markers);
if (ret < 0) {
cerr << "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret) << std::endl;
return -ret;
Expand Down
64 changes: 28 additions & 36 deletions src/rgw/rgw_bucket.cc
Expand Up @@ -151,13 +151,13 @@ int rgw_read_user_buckets(RGWRados * store,
return 0;
}

int rgw_bucket_sync_user_stats(RGWRados *store, const rgw_user& user_id, rgw_bucket& bucket)
int rgw_bucket_sync_user_stats(RGWRados *store, const rgw_user& user_id, RGWBucketInfo& bucket_info)
{
string buckets_obj_id;
rgw_get_buckets_obj(user_id, buckets_obj_id);
rgw_raw_obj obj(store->get_zone_params().user_uid_pool, buckets_obj_id);

return store->cls_user_sync_bucket_stats(obj, bucket);
return store->cls_user_sync_bucket_stats(obj, bucket_info);
}

int rgw_bucket_sync_user_stats(RGWRados *store, const string& tenant_name, const string& bucket_name)
Expand All @@ -170,7 +170,7 @@ int rgw_bucket_sync_user_stats(RGWRados *store, const string& tenant_name, const
return ret;
}

ret = rgw_bucket_sync_user_stats(store, bucket_info.owner, bucket_info.bucket);
ret = rgw_bucket_sync_user_stats(store, bucket_info.owner, bucket_info);
if (ret < 0) {
ldout(store->ctx(), 0) << "ERROR: could not sync user stats for bucket " << bucket_name << ": ret=" << ret << dendl;
return ret;
Expand Down Expand Up @@ -479,7 +479,6 @@ void check_bad_user_bucket_mapping(RGWRados *store, const rgw_user& user_id,

if (actual_bucket.name.compare(bucket.name) != 0 ||
actual_bucket.tenant.compare(bucket.tenant) != 0 ||
actual_bucket.placement.compare(bucket.placement) != 0 ||
actual_bucket.marker.compare(bucket.marker) != 0 ||
actual_bucket.bucket_id.compare(bucket.bucket_id) != 0) {
cout << "bucket info mismatch: expected " << actual_bucket << " got " << bucket << std::endl;
Expand Down Expand Up @@ -528,11 +527,11 @@ int rgw_remove_bucket(RGWRados *store, rgw_bucket& bucket, bool delete_children)

string bucket_ver, master_ver;

ret = store->get_bucket_stats(bucket, RGW_NO_SHARD, &bucket_ver, &master_ver, stats, NULL);
ret = store->get_bucket_info(obj_ctx, bucket.tenant, bucket.name, info, NULL);
if (ret < 0)
return ret;

ret = store->get_bucket_info(obj_ctx, bucket.tenant, bucket.name, info, NULL);
ret = store->get_bucket_stats(info, RGW_NO_SHARD, &bucket_ver, &master_ver, stats, NULL);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -563,14 +562,14 @@ int rgw_remove_bucket(RGWRados *store, rgw_bucket& bucket, bool delete_children)

}

ret = rgw_bucket_sync_user_stats(store, bucket.tenant, bucket.name);
ret = rgw_bucket_sync_user_stats(store, bucket.tenant, info);
if ( ret < 0) {
dout(1) << "WARNING: failed sync user stats before bucket delete. ret=" << ret << dendl;
}

RGWObjVersionTracker objv_tracker;

ret = store->delete_bucket(bucket, objv_tracker);
ret = store->delete_bucket(info, objv_tracker);
if (ret < 0) {
lderr(store->ctx()) << "ERROR: could not remove bucket " << bucket.name << dendl;
return ret;
Expand Down Expand Up @@ -619,11 +618,11 @@ int rgw_remove_bucket_bypass_gc(RGWRados *store, rgw_bucket& bucket,

string bucket_ver, master_ver;

ret = store->get_bucket_stats(bucket, RGW_NO_SHARD, &bucket_ver, &master_ver, stats, NULL);
ret = store->get_bucket_info(obj_ctx, bucket.tenant, bucket.name, info, NULL);
if (ret < 0)
return ret;

ret = store->get_bucket_info(obj_ctx, bucket.tenant, bucket.name, info, NULL);
ret = store->get_bucket_stats(info, RGW_NO_SHARD, &bucket_ver, &master_ver, stats, NULL);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -663,7 +662,7 @@ int rgw_remove_bucket_bypass_gc(RGWRados *store, rgw_bucket& bucket,
RGWObjManifest::obj_iterator miter = manifest.obj_begin();
rgw_obj head_obj = manifest.get_obj();
rgw_raw_obj raw_head_obj;
RGWRados::obj_to_raw(head_obj, &raw_head_obj);
store->obj_to_raw(head_obj, &raw_head_obj);


for (; miter != manifest.obj_end() && max_aio--; ++miter) {
Expand All @@ -689,7 +688,7 @@ int rgw_remove_bucket_bypass_gc(RGWRados *store, rgw_bucket& bucket,
}
} // for all shadow objs

ret = store->delete_obj_aio(head_obj, bucket, info, astate, handles, keep_index_consistent);
ret = store->delete_obj_aio(head_obj, info, astate, handles, keep_index_consistent);
if (ret < 0) {
lderr(store->ctx()) << "ERROR: delete obj aio failed with " << ret << dendl;
return ret;
Expand Down Expand Up @@ -718,7 +717,7 @@ int rgw_remove_bucket_bypass_gc(RGWRados *store, rgw_bucket& bucket,
return ret;
}

ret = rgw_bucket_sync_user_stats(store, bucket.tenant, bucket.name);
ret = rgw_bucket_sync_user_stats(store, bucket.tenant, info);
if (ret < 0) {
dout(1) << "WARNING: failed sync user stats before bucket delete. ret=" << ret << dendl;
}
Expand Down Expand Up @@ -1076,7 +1075,7 @@ int RGWBucket::check_bad_index_multipart(RGWBucketAdminOpState& op_state,
return 0;

if (fix_index) {
int r = store->remove_objs_from_index(bucket, objs_to_unlink);
int r = store->remove_objs_from_index(bucket_info, objs_to_unlink);
if (r < 0) {
set_err_msg(err_msg, "ERROR: remove_obj_from_index() returned error: " +
cpp_strerror(-r));
Expand All @@ -1093,18 +1092,15 @@ int RGWBucket::check_object_index(RGWBucketAdminOpState& op_state,
{

bool fix_index = op_state.will_fix_index();

rgw_bucket bucket = op_state.get_bucket();

if (!fix_index) {
set_err_msg(err_msg, "check-objects flag requires fix index enabled");
return -EINVAL;
}

/*
dout(0) << "Checking objects, decreasing bucket 2-phase commit timeout.\n"\
<< "** Note that timeout will reset only when operation completes successfully **" << dendl;
*/
store->cls_obj_set_bucket_tag_timeout(bucket, BUCKET_TAG_TIMEOUT);
store->cls_obj_set_bucket_tag_timeout(bucket_info, BUCKET_TAG_TIMEOUT);

string prefix;
rgw_obj_key marker;
Expand All @@ -1113,7 +1109,7 @@ int RGWBucket::check_object_index(RGWBucketAdminOpState& op_state,
while (is_truncated) {
map<string, RGWObjEnt> result;

int r = store->cls_bucket_list(bucket, RGW_NO_SHARD, marker, prefix, 1000, true,
int r = store->cls_bucket_list(bucket_info, RGW_NO_SHARD, marker, prefix, 1000, true,
result, &is_truncated, &marker,
bucket_object_check_filter);
if (r == -ENOENT) {
Expand All @@ -1123,7 +1119,7 @@ int RGWBucket::check_object_index(RGWBucketAdminOpState& op_state,
}
}

store->cls_obj_set_bucket_tag_timeout(bucket, 0);
store->cls_obj_set_bucket_tag_timeout(bucket_info, 0);

return 0;
}
Expand All @@ -1137,14 +1133,14 @@ int RGWBucket::check_index(RGWBucketAdminOpState& op_state,
rgw_bucket bucket = op_state.get_bucket();
bool fix_index = op_state.will_fix_index();

int r = store->bucket_check_index(bucket, &existing_stats, &calculated_stats);
int r = store->bucket_check_index(bucket_info, &existing_stats, &calculated_stats);
if (r < 0) {
set_err_msg(err_msg, "failed to check index error=" + cpp_strerror(-r));
return r;
}

if (fix_index) {
r = store->bucket_rebuild_index(bucket);
r = store->bucket_rebuild_index(bucket_info);
if (r < 0) {
set_err_msg(err_msg, "failed to rebuild index err=" + cpp_strerror(-r));
return r;
Expand Down Expand Up @@ -1363,7 +1359,6 @@ int RGWBucketAdminOp::remove_object(RGWRados *store, RGWBucketAdminOpState& op_s
static int bucket_stats(RGWRados *store, const std::string& tenant_name, std::string& bucket_name, Formatter *formatter)
{
RGWBucketInfo bucket_info;
rgw_bucket bucket;
map<RGWObjCategory, RGWStorageStats> stats;

real_time mtime;
Expand All @@ -1372,11 +1367,11 @@ static int bucket_stats(RGWRados *store, const std::string& tenant_name, std::st
if (r < 0)
return r;

bucket = bucket_info.bucket;
rgw_bucket& bucket = bucket_info.bucket;

string bucket_ver, master_ver;
string max_marker;
int ret = store->get_bucket_stats(bucket, RGW_NO_SHARD, &bucket_ver, &master_ver, stats, &max_marker);
int ret = store->get_bucket_stats(bucket_info, RGW_NO_SHARD, &bucket_ver, &master_ver, stats, &max_marker);
if (ret < 0) {
cerr << "error getting bucket stats ret=" << ret << std::endl;
return ret;
Expand All @@ -1386,7 +1381,6 @@ static int bucket_stats(RGWRados *store, const std::string& tenant_name, std::st

formatter->open_object_section("stats");
formatter->dump_string("bucket", bucket.name);
encode_json("placement", bucket.placement, formatter);
formatter->dump_string("id", bucket.bucket_id);
formatter->dump_string("marker", bucket.marker);
::encode_json("owner", bucket_info.owner, formatter);
Expand Down Expand Up @@ -2118,21 +2112,19 @@ class RGWBucketInstanceMetadataHandler : public RGWMetadataHandler {
string bucket_name;
parse_bucket(key, tenant_name, bucket_name);

rgw_bucket bucket;
RGWZonePlacementInfo rule_info;
ret = store->set_bucket_location_by_rule(bci.info.placement_rule,
tenant_name, bucket_name, bucket, &rule_info);
bci.info.bucket.name = bucket_name;
bci.info.bucket.tenant = tenant_name;
ret = store->select_bucket_location_by_rule(bci.info.placement_rule, bci.info.bucket, &rule_info);
if (ret < 0) {
ldout(store->ctx(), 0) << "ERROR: select_bucket_placement() returned " << ret << dendl;
return ret;
}
bci.info.bucket.tenant = bucket.tenant;
bci.info.bucket.placement = bucket.placement;
bci.info.index_type = rule_info.index_type;
} else {
/* existing bucket, keep its placement pools */
bci.info.bucket.placement = old_bci.info.bucket.placement;
bci.info.index_type = old_bci.info.index_type;
/* existing bucket, keep its placement */
bci.info.bucket.explicit_placement = old_bci.info.bucket.explicit_placement;
bci.info.placement_rule = old_bci.info.placement_rule;
}

// are we actually going to perform this put, or is it too old?
Expand All @@ -2153,7 +2145,7 @@ class RGWBucketInstanceMetadataHandler : public RGWMetadataHandler {

objv_tracker = bci.info.objv_tracker;

ret = store->init_bucket_index(bci.info.bucket, bci.info.num_shards);
ret = store->init_bucket_index(bci.info, bci.info.num_shards);
if (ret < 0)
return ret;

Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_bucket.h
Expand Up @@ -46,7 +46,7 @@ extern int rgw_bucket_delete_bucket_obj(RGWRados *store,
const string& bucket_name,
RGWObjVersionTracker& objv_tracker);

extern int rgw_bucket_sync_user_stats(RGWRados *store, const rgw_user& user_id, rgw_bucket& bucket);
extern int rgw_bucket_sync_user_stats(RGWRados *store, const rgw_user& user_id, const RGWBucketInfo& bucket_info);
extern int rgw_bucket_sync_user_stats(RGWRados *store, const string& tenant_name, const string& bucket_name);

extern void rgw_make_bucket_entry_name(const string& tenant_name,
Expand Down

0 comments on commit 71cf9c2

Please sign in to comment.