]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/ClusterState.h
ae08c75daa1a0d8f4d56e31a4f41dfffb9943fe0
[ceph.git] / ceph / src / mgr / ClusterState.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2014 John Spray <john.spray@inktank.com>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 */
13
14 #ifndef CLUSTER_STATE_H_
15 #define CLUSTER_STATE_H_
16
17 #include "mds/FSMap.h"
18 #include "common/Mutex.h"
19
20 #include "osdc/Objecter.h"
21 #include "mon/MonClient.h"
22 #include "mon/PGMap.h"
23
24 class MMgrDigest;
25 class MMonMgrReport;
26 class MPGStats;
27
28
29 /**
30 * Cluster-scope state (things like cluster maps) as opposed
31 * to daemon-level state (things like perf counters and smart)
32 */
33 class ClusterState
34 {
35 protected:
36 MonClient *monc;
37 Objecter *objecter;
38 FSMap fsmap;
39 mutable Mutex lock;
40
41 set<int64_t> existing_pools; ///< pools that exist, as of PGMap epoch
42 PGMap pg_map;
43 PGMap::Incremental pending_inc;
44
45 PGMapStatService pgservice;
46
47 bufferlist health_json;
48 bufferlist mon_status_json;
49
50 public:
51
52 void load_digest(MMgrDigest *m);
53 void ingest_pgstats(MPGStats *stats);
54
55 void update_delta_stats();
56
57 const bufferlist &get_health() const {return health_json;}
58 const bufferlist &get_mon_status() const {return mon_status_json;}
59
60 ClusterState(MonClient *monc_, Objecter *objecter_);
61
62 void set_objecter(Objecter *objecter_);
63 void set_fsmap(FSMap const &new_fsmap);
64
65 void notify_osdmap(const OSDMap &osd_map);
66
67 bool have_fsmap() const {
68 Mutex::Locker l(lock);
69 return fsmap.get_epoch() > 0;
70 }
71
72 template<typename Callback, typename...Args>
73 void with_fsmap(Callback&& cb, Args&&...args) const
74 {
75 Mutex::Locker l(lock);
76 std::forward<Callback>(cb)(fsmap, std::forward<Args>(args)...);
77 }
78
79 template<typename Callback, typename...Args>
80 auto with_pgmap(Callback&& cb, Args&&...args) const ->
81 decltype(cb(pg_map, std::forward<Args>(args)...))
82 {
83 Mutex::Locker l(lock);
84 return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...);
85 }
86
87 template<typename Callback, typename...Args>
88 auto with_pgservice(Callback&& cb, Args&&...args) const ->
89 decltype(cb(pgservice, std::forward<Args>(args)...))
90 {
91 Mutex::Locker l(lock);
92 return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...);
93 }
94
95 template<typename... Args>
96 void with_monmap(Args &&... args) const
97 {
98 Mutex::Locker l(lock);
99 assert(monc != nullptr);
100 monc->with_monmap(std::forward<Args>(args)...);
101 }
102
103 template<typename... Args>
104 auto with_osdmap(Args &&... args) const ->
105 decltype(objecter->with_osdmap(std::forward<Args>(args)...))
106 {
107 assert(objecter != nullptr);
108 return objecter->with_osdmap(std::forward<Args>(args)...);
109 }
110
111 };
112
113 #endif
114