#include "DaemonState.h"
+#include "MgrSession.h"
+
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_mgr
#undef dout_prefix
void DaemonStateIndex::insert(DaemonStatePtr dm)
{
- Mutex::Locker l(lock);
+ RWLock::WLocker l(lock);
if (all.count(dm->key)) {
_erase(dm->key);
void DaemonStateIndex::_erase(const DaemonKey& dmk)
{
- assert(lock.is_locked_by_me());
+ assert(lock.is_wlocked());
const auto to_erase = all.find(dmk);
assert(to_erase != all.end());
all.erase(to_erase);
}
-DaemonStateCollection DaemonStateIndex::get_by_type(uint8_t type) const
+DaemonStateCollection DaemonStateIndex::get_by_service(
+ const std::string& svc) const
{
- Mutex::Locker l(lock);
+ RWLock::RLocker l(lock);
DaemonStateCollection result;
for (const auto &i : all) {
- if (i.first.first == type) {
+ if (i.first.first == svc) {
result[i.first] = i.second;
}
}
return result;
}
-DaemonStateCollection DaemonStateIndex::get_by_server(const std::string &hostname) const
+DaemonStateCollection DaemonStateIndex::get_by_server(
+ const std::string &hostname) const
{
- Mutex::Locker l(lock);
+ RWLock::RLocker l(lock);
if (by_server.count(hostname)) {
return by_server.at(hostname);
bool DaemonStateIndex::exists(const DaemonKey &key) const
{
- Mutex::Locker l(lock);
+ RWLock::RLocker l(lock);
return all.count(key) > 0;
}
DaemonStatePtr DaemonStateIndex::get(const DaemonKey &key)
{
- Mutex::Locker l(lock);
+ RWLock::RLocker l(lock);
- return all.at(key);
+ auto iter = all.find(key);
+ if (iter != all.end()) {
+ return iter->second;
+ } else {
+ return nullptr;
+ }
}
-void DaemonStateIndex::cull(entity_type_t daemon_type,
+void DaemonStateIndex::cull(const std::string& svc_name,
const std::set<std::string>& names_exist)
{
std::vector<string> victims;
- Mutex::Locker l(lock);
- auto begin = all.lower_bound({daemon_type, ""});
+ RWLock::WLocker l(lock);
+ auto begin = all.lower_bound({svc_name, ""});
auto end = all.end();
for (auto &i = begin; i != end; ++i) {
const auto& daemon_key = i->first;
- if (daemon_key.first != daemon_type)
+ if (daemon_key.first != svc_name)
break;
if (names_exist.count(daemon_key.second) == 0) {
victims.push_back(daemon_key.second);
for (auto &i : victims) {
dout(4) << "Removing data for " << i << dendl;
- _erase({daemon_type, i});
+ _erase({svc_name, i});
}
}
<< types.size() << " types, got "
<< report->packed.length() << " bytes of data" << dendl;
+ // Retrieve session state
+ MgrSessionRef session(static_cast<MgrSession*>(
+ report->get_connection()->get_priv()));
+
// Load any newly declared types
for (const auto &t : report->declare_types) {
types.insert(std::make_pair(t.path, t));
- declared_types.insert(t.path);
+ session->declared_types.insert(t.path);
}
// Remove any old types
for (const auto &t : report->undeclare_types) {
- declared_types.erase(t);
+ session->declared_types.erase(t);
}
const auto now = ceph_clock_now();
// Parse packed data according to declared set of types
bufferlist::iterator p = report->packed.begin();
DECODE_START(1, p);
- for (const auto &t_path : declared_types) {
+ for (const auto &t_path : session->declared_types) {
const auto &t = types.at(t_path);
uint64_t val = 0;
uint64_t avgcount = 0;