]>
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" |
9f95a23c | 19 | #include "common/ceph_mutex.h" |
7c673cae FG |
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; |
9f95a23c | 42 | mutable ceph::mutex lock = ceph::make_mutex("ClusterState"); |
7c673cae | 43 | |
224ce89b WB |
44 | MgrMap mgr_map; |
45 | ||
11fdf7f2 | 46 | map<int64_t,unsigned> existing_pools; ///< pools that exist, and pg_num, as of PGMap epoch |
7c673cae | 47 | PGMap pg_map; |
31f18b77 FG |
48 | PGMap::Incremental pending_inc; |
49 | ||
7c673cae FG |
50 | bufferlist health_json; |
51 | bufferlist mon_status_json; | |
52 | ||
eafe8130 TL |
53 | class ClusterSocketHook *asok_hook; |
54 | ||
7c673cae FG |
55 | public: |
56 | ||
57 | void load_digest(MMgrDigest *m); | |
9f95a23c | 58 | void ingest_pgstats(ceph::ref_t<MPGStats> stats); |
7c673cae | 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 { | |
11fdf7f2 | 75 | std::lock_guard l(lock); |
7c673cae FG |
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 | { | |
11fdf7f2 | 82 | std::lock_guard l(lock); |
224ce89b WB |
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 | { | |
11fdf7f2 | 89 | std::lock_guard l(lock); |
7c673cae | 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 | { | |
11fdf7f2 | 96 | std::lock_guard l(lock); |
224ce89b | 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 | { | |
11fdf7f2 | 104 | std::lock_guard l(lock); |
7c673cae FG |
105 | return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...); |
106 | } | |
107 | ||
31f18b77 | 108 | template<typename Callback, typename...Args> |
11fdf7f2 TL |
109 | auto with_mutable_pgmap(Callback&& cb, Args&&...args) -> |
110 | decltype(cb(pg_map, std::forward<Args>(args)...)) | |
31f18b77 | 111 | { |
11fdf7f2 | 112 | std::lock_guard l(lock); |
31f18b77 FG |
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 | { | |
11fdf7f2 TL |
119 | std::lock_guard l(lock); |
120 | ceph_assert(monc != nullptr); | |
7c673cae FG |
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 | { | |
11fdf7f2 | 128 | ceph_assert(objecter != nullptr); |
7c673cae FG |
129 | return objecter->with_osdmap(std::forward<Args>(args)...); |
130 | } | |
131 | ||
11fdf7f2 TL |
132 | // call cb(osdmap, pg_map, ...args) with the appropriate locks |
133 | template <typename Callback, typename ...Args> | |
134 | auto with_osdmap_and_pgmap(Callback&& cb, Args&& ...args) const { | |
135 | ceph_assert(objecter != nullptr); | |
136 | std::lock_guard l(lock); | |
137 | return objecter->with_osdmap( | |
138 | std::forward<Callback>(cb), | |
139 | pg_map, | |
140 | std::forward<Args>(args)...); | |
141 | } | |
eafe8130 TL |
142 | void final_init(); |
143 | void shutdown(); | |
9f95a23c TL |
144 | bool asok_command(std::string_view admin_command, |
145 | const cmdmap_t& cmdmap, | |
146 | Formatter *f, | |
147 | ostream& ss); | |
7c673cae FG |
148 | }; |
149 | ||
150 | #endif | |
151 |