]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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" | |
224ce89b | 18 | #include "mon/MgrMap.h" |
7c673cae FG |
19 | #include "common/Mutex.h" |
20 | ||
21 | #include "osdc/Objecter.h" | |
22 | #include "mon/MonClient.h" | |
23 | #include "mon/PGMap.h" | |
224ce89b | 24 | #include "mgr/ServiceMap.h" |
7c673cae FG |
25 | |
26 | class MMgrDigest; | |
31f18b77 | 27 | class MMonMgrReport; |
7c673cae FG |
28 | class MPGStats; |
29 | ||
30 | ||
31 | /** | |
32 | * Cluster-scope state (things like cluster maps) as opposed | |
33 | * to daemon-level state (things like perf counters and smart) | |
34 | */ | |
35 | class ClusterState | |
36 | { | |
37 | protected: | |
38 | MonClient *monc; | |
39 | Objecter *objecter; | |
40 | FSMap fsmap; | |
224ce89b | 41 | ServiceMap servicemap; |
7c673cae FG |
42 | mutable Mutex lock; |
43 | ||
224ce89b WB |
44 | MgrMap mgr_map; |
45 | ||
31f18b77 | 46 | set<int64_t> existing_pools; ///< pools that exist, as of PGMap epoch |
7c673cae | 47 | PGMap pg_map; |
31f18b77 FG |
48 | PGMap::Incremental pending_inc; |
49 | ||
50 | PGMapStatService pgservice; | |
7c673cae FG |
51 | |
52 | bufferlist health_json; | |
53 | bufferlist mon_status_json; | |
54 | ||
55 | public: | |
56 | ||
57 | void load_digest(MMgrDigest *m); | |
58 | void ingest_pgstats(MPGStats *stats); | |
59 | ||
31f18b77 FG |
60 | void update_delta_stats(); |
61 | ||
7c673cae FG |
62 | const bufferlist &get_health() const {return health_json;} |
63 | const bufferlist &get_mon_status() const {return mon_status_json;} | |
64 | ||
224ce89b | 65 | ClusterState(MonClient *monc_, Objecter *objecter_, const MgrMap& mgrmap); |
7c673cae FG |
66 | |
67 | void set_objecter(Objecter *objecter_); | |
68 | void set_fsmap(FSMap const &new_fsmap); | |
224ce89b WB |
69 | void set_mgr_map(MgrMap const &new_mgrmap); |
70 | void set_service_map(ServiceMap const &new_service_map); | |
7c673cae FG |
71 | |
72 | void notify_osdmap(const OSDMap &osd_map); | |
73 | ||
74 | bool have_fsmap() const { | |
75 | Mutex::Locker l(lock); | |
76 | return fsmap.get_epoch() > 0; | |
77 | } | |
78 | ||
224ce89b WB |
79 | template<typename Callback, typename...Args> |
80 | void with_servicemap(Callback&& cb, Args&&...args) const | |
81 | { | |
82 | Mutex::Locker l(lock); | |
83 | std::forward<Callback>(cb)(servicemap, std::forward<Args>(args)...); | |
84 | } | |
85 | ||
7c673cae FG |
86 | template<typename Callback, typename...Args> |
87 | void with_fsmap(Callback&& cb, Args&&...args) const | |
88 | { | |
89 | Mutex::Locker l(lock); | |
90 | std::forward<Callback>(cb)(fsmap, std::forward<Args>(args)...); | |
224ce89b WB |
91 | } |
92 | ||
93 | template<typename Callback, typename...Args> | |
94 | void with_mgrmap(Callback&& cb, Args&&...args) const | |
95 | { | |
96 | Mutex::Locker l(lock); | |
97 | std::forward<Callback>(cb)(mgr_map, std::forward<Args>(args)...); | |
7c673cae FG |
98 | } |
99 | ||
100 | template<typename Callback, typename...Args> | |
101 | auto with_pgmap(Callback&& cb, Args&&...args) const -> | |
102 | decltype(cb(pg_map, std::forward<Args>(args)...)) | |
103 | { | |
104 | Mutex::Locker l(lock); | |
105 | return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...); | |
106 | } | |
107 | ||
31f18b77 FG |
108 | template<typename Callback, typename...Args> |
109 | auto with_pgservice(Callback&& cb, Args&&...args) const -> | |
110 | decltype(cb(pgservice, std::forward<Args>(args)...)) | |
111 | { | |
112 | Mutex::Locker l(lock); | |
113 | return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...); | |
114 | } | |
115 | ||
7c673cae FG |
116 | template<typename... Args> |
117 | void with_monmap(Args &&... args) const | |
118 | { | |
119 | Mutex::Locker l(lock); | |
120 | assert(monc != nullptr); | |
121 | monc->with_monmap(std::forward<Args>(args)...); | |
122 | } | |
123 | ||
124 | template<typename... Args> | |
125 | auto with_osdmap(Args &&... args) const -> | |
126 | decltype(objecter->with_osdmap(std::forward<Args>(args)...)) | |
127 | { | |
128 | assert(objecter != nullptr); | |
129 | return objecter->with_osdmap(std::forward<Args>(args)...); | |
130 | } | |
131 | ||
132 | }; | |
133 | ||
134 | #endif | |
135 |