Skip to content

Commit

Permalink
rgw: Speed up the building of valid de-duplicated hostnames for regions.
Browse files Browse the repository at this point in the history
Signed-off-by: Robin H. Johnson <[email protected]>
  • Loading branch information
robbat2 committed Apr 15, 2015
1 parent f7311ec commit 044060f
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/rgw/rgw_rest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ string camelcase_dash_http_attr(const string& orig)
return string(buf);
}

static list<string> hostnames_list;
/* avoid duplicate hostnames in hostnames list */
static set<string> hostnames_set;

void rgw_rest_init(CephContext *cct, RGWRegion& region)
{
Expand Down Expand Up @@ -193,18 +194,10 @@ void rgw_rest_init(CephContext *cct, RGWRegion& region)
http_status_names[h->code] = h->name;
}

/* avoid duplicate hostnames in hostnames list */
map<string, bool> hostnames_map;
if (!cct->_conf->rgw_dns_name.empty()) {
hostnames_map[cct->_conf->rgw_dns_name] = true;
}
for (list<string>::iterator iter = region.hostnames.begin(); iter != region.hostnames.end(); ++iter) {
hostnames_map[*iter] = true;
}

for (map<string, bool>::iterator iter = hostnames_map.begin(); iter != hostnames_map.end(); ++iter) {
hostnames_list.push_back(iter->first);
hostnames_set.insert(cct->_conf->rgw_dns_name);
}
hostnames_set.insert(region.hostnames.begin(), region.hostnames.end());
}

static bool str_ends_with(const string& s, const string& suffix, size_t *pos)
Expand All @@ -224,8 +217,8 @@ static bool str_ends_with(const string& s, const string& suffix, size_t *pos)

static bool rgw_find_host_in_domains(const string& host, string *domain, string *subdomain)
{
list<string>::iterator iter;
for (iter = hostnames_list.begin(); iter != hostnames_list.end(); ++iter) {
set<string>::iterator iter;
for (iter = hostnames_set.begin(); iter != hostnames_set.end(); ++iter) {
size_t pos;
if (!str_ends_with(host, *iter, &pos))
continue;
Expand Down

0 comments on commit 044060f

Please sign in to comment.