Skip to content

Commit

Permalink
rgw: fix cls_bucket_head result order consistency
Browse files Browse the repository at this point in the history
headers's key is string but bucket_instance_ids's key is int
looked around and found no one use header's key, so change
header from map to vector

Signed-off-by: Tianshan Qu <tianshan@xsky.com>
  • Loading branch information
tianshan committed Nov 15, 2017
1 parent ffb129e commit 46657a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
44 changes: 22 additions & 22 deletions src/rgw/rgw_rados.cc
Expand Up @@ -11543,7 +11543,7 @@ int RGWRados::raw_obj_stat(rgw_raw_obj& obj, uint64_t *psize, real_time *pmtime,
int RGWRados::get_bucket_stats(RGWBucketInfo& bucket_info, int shard_id, string *bucket_ver, string *master_ver,
map<RGWObjCategory, RGWStorageStats>& stats, string *max_marker, bool *syncstopped)
{
map<string, rgw_bucket_dir_header> headers;
vector<rgw_bucket_dir_header> headers;
map<int, string> bucket_instance_ids;
int r = cls_bucket_head(bucket_info, shard_id, headers, &bucket_instance_ids);
if (r < 0) {
Expand All @@ -11552,25 +11552,25 @@ int RGWRados::get_bucket_stats(RGWBucketInfo& bucket_info, int shard_id, string

assert(headers.size() == bucket_instance_ids.size());

map<string, rgw_bucket_dir_header>::iterator iter = headers.begin();
auto iter = headers.begin();
map<int, string>::iterator viter = bucket_instance_ids.begin();
BucketIndexShardsManager ver_mgr;
BucketIndexShardsManager master_ver_mgr;
BucketIndexShardsManager marker_mgr;
char buf[64];
for(; iter != headers.end(); ++iter, ++viter) {
accumulate_raw_stats(iter->second, stats);
snprintf(buf, sizeof(buf), "%lu", (unsigned long)iter->second.ver);
accumulate_raw_stats(*iter, stats);
snprintf(buf, sizeof(buf), "%lu", (unsigned long)iter->ver);
ver_mgr.add(viter->first, string(buf));
snprintf(buf, sizeof(buf), "%lu", (unsigned long)iter->second.master_ver);
snprintf(buf, sizeof(buf), "%lu", (unsigned long)iter->master_ver);
master_ver_mgr.add(viter->first, string(buf));
if (shard_id >= 0) {
*max_marker = iter->second.max_marker;
*max_marker = iter->max_marker;
} else {
marker_mgr.add(viter->first, iter->second.max_marker);
marker_mgr.add(viter->first, iter->max_marker);
}
if (syncstopped != NULL)
*syncstopped = iter->second.syncstopped;
*syncstopped = iter->syncstopped;
}
ver_mgr.to_string(bucket_ver);
master_ver_mgr.to_string(master_ver);
Expand All @@ -11583,22 +11583,22 @@ int RGWRados::get_bucket_stats(RGWBucketInfo& bucket_info, int shard_id, string
int RGWRados::get_bi_log_status(RGWBucketInfo& bucket_info, int shard_id,
map<int, string>& markers)
{
map<string, rgw_bucket_dir_header> headers;
vector<rgw_bucket_dir_header> headers;
map<int, string> bucket_instance_ids;
int r = cls_bucket_head(bucket_info, shard_id, headers, &bucket_instance_ids);
if (r < 0)
return r;

assert(headers.size() == bucket_instance_ids.size());

map<string, rgw_bucket_dir_header>::iterator iter = headers.begin();
auto iter = headers.begin();
map<int, string>::iterator viter = bucket_instance_ids.begin();

for(; iter != headers.end(); ++iter, ++viter) {
if (shard_id >= 0) {
markers[shard_id] = iter->second.max_marker;
markers[shard_id] = iter->max_marker;
} else {
markers[viter->first] = iter->second.max_marker;
markers[viter->first] = iter->max_marker;
}
}
return 0;
Expand Down Expand Up @@ -12102,7 +12102,7 @@ int RGWRados::update_containers_stats(map<string, RGWBucketEnt>& m)
ent.size = 0;
ent.size_rounded = 0;

map<string, rgw_bucket_dir_header> headers;
vector<rgw_bucket_dir_header> headers;

RGWBucketInfo bucket_info;
int ret = get_bucket_instance_info(obj_ctx, bucket, bucket_info, NULL, NULL);
Expand All @@ -12114,11 +12114,11 @@ int RGWRados::update_containers_stats(map<string, RGWBucketEnt>& m)
if (r < 0)
return r;

map<string, rgw_bucket_dir_header>::iterator hiter = headers.begin();
auto hiter = headers.begin();
for (; hiter != headers.end(); ++hiter) {
RGWObjCategory category = main_category;
map<uint8_t, struct rgw_bucket_category_stats>::iterator iter = (hiter->second.stats).find((uint8_t)category);
if (iter != hiter->second.stats.end()) {
map<uint8_t, struct rgw_bucket_category_stats>::iterator iter = (hiter->stats).find((uint8_t)category);
if (iter != hiter->stats.end()) {
struct rgw_bucket_category_stats& stats = iter->second;
ent.count += stats.num_entries;
ent.size += stats.total_size;
Expand Down Expand Up @@ -13002,7 +13002,7 @@ int RGWRados::check_disk_state(librados::IoCtx io_ctx,
return 0;
}

int RGWRados::cls_bucket_head(const RGWBucketInfo& bucket_info, int shard_id, map<string, struct rgw_bucket_dir_header>& headers, map<int, string> *bucket_instance_ids)
int RGWRados::cls_bucket_head(const RGWBucketInfo& bucket_info, int shard_id, vector<rgw_bucket_dir_header>& headers, map<int, string> *bucket_instance_ids)
{
librados::IoCtx index_ctx;
map<int, string> oids;
Expand All @@ -13017,7 +13017,7 @@ int RGWRados::cls_bucket_head(const RGWBucketInfo& bucket_info, int shard_id, ma

map<int, struct rgw_cls_list_ret>::iterator iter = list_results.begin();
for(; iter != list_results.end(); ++iter) {
headers[oids[iter->first]] = iter->second.dir.header;
headers.push_back(std::move(iter->second.dir.header));
}
return 0;
}
Expand Down Expand Up @@ -13089,7 +13089,7 @@ int RGWRados::cls_user_get_header_async(const string& user_id, RGWGetUserHeader_

int RGWRados::cls_user_sync_bucket_stats(rgw_raw_obj& user_obj, const RGWBucketInfo& bucket_info)
{
map<string, struct rgw_bucket_dir_header> headers;
vector<rgw_bucket_dir_header> headers;
int r = cls_bucket_head(bucket_info, RGW_NO_SHARD, headers);
if (r < 0) {
ldout(cct, 20) << "cls_bucket_header() returned " << r << dendl;
Expand All @@ -13101,7 +13101,7 @@ int RGWRados::cls_user_sync_bucket_stats(rgw_raw_obj& user_obj, const RGWBucketI
bucket_info.bucket.convert(&entry.bucket);

for (const auto& hiter : headers) {
for (const auto& iter : hiter.second.stats) {
for (const auto& iter : hiter.stats) {
const struct rgw_bucket_category_stats& header_stats = iter.second;
entry.size += header_stats.total_size;
entry.size_rounded += header_stats.total_size_rounded;
Expand All @@ -13123,7 +13123,7 @@ int RGWRados::cls_user_sync_bucket_stats(rgw_raw_obj& user_obj, const RGWBucketI

int RGWRados::cls_user_get_bucket_stats(const rgw_bucket& bucket, cls_user_bucket_entry& entry)
{
map<string, struct rgw_bucket_dir_header> headers;
vector<rgw_bucket_dir_header> headers;
RGWBucketInfo bucket_info;
RGWObjectCtx obj_ctx(this);
int ret = get_bucket_instance_info(obj_ctx, bucket, bucket_info, NULL, NULL);
Expand All @@ -13140,7 +13140,7 @@ int RGWRados::cls_user_get_bucket_stats(const rgw_bucket& bucket, cls_user_bucke
bucket.convert(&entry.bucket);

for (const auto& hiter : headers) {
for (const auto& iter : hiter.second.stats) {
for (const auto& iter : hiter.stats) {
const struct rgw_bucket_category_stats& header_stats = iter.second;
entry.size += header_stats.total_size;
entry.size_rounded += header_stats.total_size_rounded;
Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_rados.h
Expand Up @@ -3431,7 +3431,7 @@ class RGWRados
uint32_t num_entries, bool list_versions, map<string, rgw_bucket_dir_entry>& m,
bool *is_truncated, rgw_obj_index_key *last_entry,
bool (*force_check_filter)(const string& name) = NULL);
int cls_bucket_head(const RGWBucketInfo& bucket_info, int shard_id, map<string, struct rgw_bucket_dir_header>& headers, map<int, string> *bucket_instance_ids = NULL);
int cls_bucket_head(const RGWBucketInfo& bucket_info, int shard_id, vector<rgw_bucket_dir_header>& headers, map<int, string> *bucket_instance_ids = NULL);
int cls_bucket_head_async(const RGWBucketInfo& bucket_info, int shard_id, RGWGetDirHeader_CB *ctx, int *num_aio);
int list_bi_log_entries(RGWBucketInfo& bucket_info, int shard_id, string& marker, uint32_t max, std::list<rgw_bi_log_entry>& result, bool *truncated);
int trim_bi_log_entries(RGWBucketInfo& bucket_info, int shard_id, string& marker, string& end_marker);
Expand Down

0 comments on commit 46657a0

Please sign in to comment.