Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mgr: optimize DaemonStateIndex::cull() a little bit #14967

Merged
merged 1 commit into from May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 18 additions & 16 deletions src/mgr/DaemonState.cc
Expand Up @@ -30,18 +30,20 @@ void DaemonStateIndex::insert(DaemonStatePtr dm)
all[dm->key] = dm;
}

void DaemonStateIndex::_erase(DaemonKey dmk)
void DaemonStateIndex::_erase(const DaemonKey& dmk)
{
assert(lock.is_locked_by_me());

const auto dm = all.at(dmk);
const auto to_erase = all.find(dmk);
assert(to_erase != all.end());
const auto dm = to_erase->second;
auto &server_collection = by_server[dm->hostname];
server_collection.erase(dm->key);
if (server_collection.empty()) {
by_server.erase(dm->hostname);
}

all.erase(dmk);
all.erase(to_erase);
}

DaemonStateCollection DaemonStateIndex::get_by_type(uint8_t type) const
Expand Down Expand Up @@ -85,25 +87,25 @@ DaemonStatePtr DaemonStateIndex::get(const DaemonKey &key)
}

void DaemonStateIndex::cull(entity_type_t daemon_type,
std::set<std::string> names_exist)
const std::set<std::string>& names_exist)
{
Mutex::Locker l(lock);

std::set<DaemonKey> victims;

for (const auto &i : all) {
if (i.first.first != daemon_type) {
continue;
}
std::vector<string> victims;

if (names_exist.count(i.first.second) == 0) {
victims.insert(i.first);
Mutex::Locker l(lock);
auto begin = all.lower_bound({daemon_type, ""});
auto end = all.end();
for (auto &i = begin; i != end; ++i) {
const auto& daemon_key = i->first;
if (daemon_key.first != daemon_type)
break;
if (names_exist.count(daemon_key.second) == 0) {
victims.push_back(daemon_key.second);
}
}

for (const auto &i : victims) {
for (auto &i : victims) {
dout(4) << "Removing data for " << i << dendl;
_erase(i);
_erase({daemon_type, i});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/mgr/DaemonState.h
Expand Up @@ -141,7 +141,7 @@ class DaemonStateIndex
PerfCounterTypes types;

void insert(DaemonStatePtr dm);
void _erase(DaemonKey dmk);
void _erase(const DaemonKey& dmk);

bool exists(const DaemonKey &key) const;
DaemonStatePtr get(const DaemonKey &key);
Expand All @@ -164,7 +164,7 @@ class DaemonStateIndex
* a cluster map and want to ensure that anything absent in the map
* is also absent in this class.
*/
void cull(entity_type_t daemon_type, std::set<std::string> names_exist);
void cull(entity_type_t daemon_type, const std::set<std::string>& names_exist);
};

#endif
Expand Down