X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fmgr%2FClusterState.h;fp=src%2Fceph%2Fsrc%2Fmgr%2FClusterState.h;h=9513c763bd0ad2790a5b01e2ba810fc281f3032b;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/mgr/ClusterState.h b/src/ceph/src/mgr/ClusterState.h new file mode 100644 index 0000000..9513c76 --- /dev/null +++ b/src/ceph/src/mgr/ClusterState.h @@ -0,0 +1,135 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2014 John Spray + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + +#ifndef CLUSTER_STATE_H_ +#define CLUSTER_STATE_H_ + +#include "mds/FSMap.h" +#include "mon/MgrMap.h" +#include "common/Mutex.h" + +#include "osdc/Objecter.h" +#include "mon/MonClient.h" +#include "mon/PGMap.h" +#include "mgr/ServiceMap.h" + +class MMgrDigest; +class MMonMgrReport; +class MPGStats; + + +/** + * Cluster-scope state (things like cluster maps) as opposed + * to daemon-level state (things like perf counters and smart) + */ +class ClusterState +{ +protected: + MonClient *monc; + Objecter *objecter; + FSMap fsmap; + ServiceMap servicemap; + mutable Mutex lock; + + MgrMap mgr_map; + + set existing_pools; ///< pools that exist, as of PGMap epoch + PGMap pg_map; + PGMap::Incremental pending_inc; + + PGMapStatService pgservice; + + bufferlist health_json; + bufferlist mon_status_json; + +public: + + void load_digest(MMgrDigest *m); + void ingest_pgstats(MPGStats *stats); + + void update_delta_stats(); + + const bufferlist &get_health() const {return health_json;} + const bufferlist &get_mon_status() const {return mon_status_json;} + + ClusterState(MonClient *monc_, Objecter *objecter_, const MgrMap& mgrmap); + + void set_objecter(Objecter *objecter_); + void set_fsmap(FSMap const &new_fsmap); + void set_mgr_map(MgrMap const &new_mgrmap); + void set_service_map(ServiceMap const &new_service_map); + + void notify_osdmap(const OSDMap &osd_map); + + bool have_fsmap() const { + Mutex::Locker l(lock); + return fsmap.get_epoch() > 0; + } + + template + void with_servicemap(Callback&& cb, Args&&...args) const + { + Mutex::Locker l(lock); + std::forward(cb)(servicemap, std::forward(args)...); + } + + template + void with_fsmap(Callback&& cb, Args&&...args) const + { + Mutex::Locker l(lock); + std::forward(cb)(fsmap, std::forward(args)...); + } + + template + void with_mgrmap(Callback&& cb, Args&&...args) const + { + Mutex::Locker l(lock); + std::forward(cb)(mgr_map, std::forward(args)...); + } + + template + auto with_pgmap(Callback&& cb, Args&&...args) const -> + decltype(cb(pg_map, std::forward(args)...)) + { + Mutex::Locker l(lock); + return std::forward(cb)(pg_map, std::forward(args)...); + } + + template + auto with_pgservice(Callback&& cb, Args&&...args) const -> + decltype(cb(pgservice, std::forward(args)...)) + { + Mutex::Locker l(lock); + return std::forward(cb)(pg_map, std::forward(args)...); + } + + template + void with_monmap(Args &&... args) const + { + Mutex::Locker l(lock); + assert(monc != nullptr); + monc->with_monmap(std::forward(args)...); + } + + template + auto with_osdmap(Args &&... args) const -> + decltype(objecter->with_osdmap(std::forward(args)...)) + { + assert(objecter != nullptr); + return objecter->with_osdmap(std::forward(args)...); + } + +}; + +#endif +