]>
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) 2016 John Spray <john.spray@redhat.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 DAEMON_SERVER_H_ | |
15 | #define DAEMON_SERVER_H_ | |
16 | ||
3efd9988 | 17 | #include "PyModuleRegistry.h" |
7c673cae FG |
18 | |
19 | #include <set> | |
20 | #include <string> | |
9f95a23c | 21 | #include <boost/variant.hpp> |
7c673cae | 22 | |
9f95a23c | 23 | #include "common/ceph_mutex.h" |
7c673cae | 24 | #include "common/LogClient.h" |
11fdf7f2 | 25 | #include "common/Timer.h" |
7c673cae FG |
26 | |
27 | #include <msg/Messenger.h> | |
28 | #include <mon/MonClient.h> | |
29 | ||
224ce89b | 30 | #include "ServiceMap.h" |
7c673cae FG |
31 | #include "MgrSession.h" |
32 | #include "DaemonState.h" | |
9f95a23c | 33 | #include "MetricCollector.h" |
11fdf7f2 | 34 | #include "OSDPerfMetricCollector.h" |
f67539c2 | 35 | #include "MDSPerfMetricCollector.h" |
7c673cae FG |
36 | |
37 | class MMgrReport; | |
38 | class MMgrOpen; | |
2a845540 | 39 | class MMgrUpdate; |
11fdf7f2 | 40 | class MMgrClose; |
31f18b77 | 41 | class MMonMgrReport; |
7c673cae | 42 | class MCommand; |
9f95a23c | 43 | class MMgrCommand; |
c07f9fc5 | 44 | struct MonCommand; |
11fdf7f2 TL |
45 | class CommandContext; |
46 | struct OSDPerfMetricQuery; | |
f67539c2 TL |
47 | struct MDSPerfMetricQuery; |
48 | ||
49 | ||
50 | struct offline_pg_report { | |
51 | set<int> osds; | |
52 | set<pg_t> ok, not_ok, unknown; | |
53 | set<pg_t> ok_become_degraded, ok_become_more_degraded; // ok | |
54 | set<pg_t> bad_no_pool, bad_already_inactive, bad_become_inactive; // not ok | |
55 | ||
56 | bool ok_to_stop() const { | |
57 | return not_ok.empty() && unknown.empty(); | |
58 | } | |
59 | ||
60 | void dump(Formatter *f) const { | |
61 | f->dump_bool("ok_to_stop", ok_to_stop()); | |
62 | f->open_array_section("osds"); | |
63 | for (auto o : osds) { | |
64 | f->dump_int("osd", o); | |
65 | } | |
66 | f->close_section(); | |
67 | f->dump_unsigned("num_ok_pgs", ok.size()); | |
68 | f->dump_unsigned("num_not_ok_pgs", not_ok.size()); | |
69 | ||
70 | // ambiguous | |
71 | if (!unknown.empty()) { | |
72 | f->open_array_section("unknown_pgs"); | |
73 | for (auto pg : unknown) { | |
74 | f->dump_stream("pg") << pg; | |
75 | } | |
76 | f->close_section(); | |
77 | } | |
78 | ||
79 | // bad news | |
80 | if (!bad_no_pool.empty()) { | |
81 | f->open_array_section("bad_no_pool_pgs"); | |
82 | for (auto pg : bad_no_pool) { | |
83 | f->dump_stream("pg") << pg; | |
84 | } | |
85 | f->close_section(); | |
86 | } | |
87 | if (!bad_already_inactive.empty()) { | |
88 | f->open_array_section("bad_already_inactive"); | |
89 | for (auto pg : bad_already_inactive) { | |
90 | f->dump_stream("pg") << pg; | |
91 | } | |
92 | f->close_section(); | |
93 | } | |
94 | if (!bad_become_inactive.empty()) { | |
95 | f->open_array_section("bad_become_inactive"); | |
96 | for (auto pg : bad_become_inactive) { | |
97 | f->dump_stream("pg") << pg; | |
98 | } | |
99 | f->close_section(); | |
100 | } | |
101 | ||
102 | // informative | |
103 | if (!ok_become_degraded.empty()) { | |
104 | f->open_array_section("ok_become_degraded"); | |
105 | for (auto pg : ok_become_degraded) { | |
106 | f->dump_stream("pg") << pg; | |
107 | } | |
108 | f->close_section(); | |
109 | } | |
110 | if (!ok_become_more_degraded.empty()) { | |
111 | f->open_array_section("ok_become_more_degraded"); | |
112 | for (auto pg : ok_become_more_degraded) { | |
113 | f->dump_stream("pg") << pg; | |
114 | } | |
115 | f->close_section(); | |
116 | } | |
117 | } | |
118 | }; | |
7c673cae FG |
119 | |
120 | ||
121 | /** | |
122 | * Server used in ceph-mgr to communicate with Ceph daemons like | |
123 | * MDSs and OSDs. | |
124 | */ | |
3efd9988 | 125 | class DaemonServer : public Dispatcher, public md_config_obs_t |
7c673cae FG |
126 | { |
127 | protected: | |
128 | boost::scoped_ptr<Throttle> client_byte_throttler; | |
129 | boost::scoped_ptr<Throttle> client_msg_throttler; | |
130 | boost::scoped_ptr<Throttle> osd_byte_throttler; | |
131 | boost::scoped_ptr<Throttle> osd_msg_throttler; | |
132 | boost::scoped_ptr<Throttle> mds_byte_throttler; | |
133 | boost::scoped_ptr<Throttle> mds_msg_throttler; | |
134 | boost::scoped_ptr<Throttle> mon_byte_throttler; | |
135 | boost::scoped_ptr<Throttle> mon_msg_throttler; | |
136 | ||
137 | Messenger *msgr; | |
138 | MonClient *monc; | |
139 | Finisher &finisher; | |
140 | DaemonStateIndex &daemon_state; | |
141 | ClusterState &cluster_state; | |
3efd9988 | 142 | PyModuleRegistry &py_modules; |
7c673cae FG |
143 | LogChannelRef clog, audit_clog; |
144 | ||
3efd9988 FG |
145 | // Connections for daemons, and clients with service names set |
146 | // (i.e. those MgrClients that are allowed to send MMgrReports) | |
147 | std::set<ConnectionRef> daemon_connections; | |
148 | ||
31f18b77 | 149 | /// connections for osds |
20effc67 | 150 | ceph::unordered_map<int,std::set<ConnectionRef>> osd_cons; |
31f18b77 | 151 | |
224ce89b | 152 | ServiceMap pending_service_map; // uncommitted |
3efd9988 | 153 | |
224ce89b WB |
154 | epoch_t pending_service_map_dirty = 0; |
155 | ||
9f95a23c | 156 | ceph::mutex lock = ceph::make_mutex("DaemonServer"); |
7c673cae | 157 | |
11fdf7f2 | 158 | static void _generate_command_map(cmdmap_t& cmdmap, |
20effc67 TL |
159 | std::map<std::string,std::string> ¶m_str_map); |
160 | static const MonCommand *_get_mgrcommand(const std::string &cmd_prefix, | |
c07f9fc5 | 161 | const std::vector<MonCommand> &commands); |
7c673cae | 162 | bool _allowed_command( |
20effc67 TL |
163 | MgrSession *s, const std::string &service, const std::string &module, |
164 | const std::string &prefix, const cmdmap_t& cmdmap, | |
165 | const std::map<std::string,std::string>& param_str_map, | |
c07f9fc5 | 166 | const MonCommand *this_cmd); |
7c673cae FG |
167 | |
168 | private: | |
169 | friend class ReplyOnFinish; | |
170 | bool _reply(MCommand* m, | |
171 | int ret, const std::string& s, const bufferlist& payload); | |
172 | ||
224ce89b WB |
173 | void _prune_pending_service_map(); |
174 | ||
f67539c2 | 175 | void _check_offlines_pgs( |
20effc67 | 176 | const std::set<int>& osds, |
f67539c2 TL |
177 | const OSDMap& osdmap, |
178 | const PGMap& pgmap, | |
179 | offline_pg_report *report); | |
180 | void _maximize_ok_to_stop_set( | |
181 | const set<int>& orig_osds, | |
182 | unsigned max, | |
183 | const OSDMap& osdmap, | |
184 | const PGMap& pgmap, | |
185 | offline_pg_report *report); | |
186 | ||
224ce89b | 187 | utime_t started_at; |
3efd9988 | 188 | std::atomic<bool> pgmap_ready; |
224ce89b WB |
189 | std::set<int32_t> reported_osds; |
190 | void maybe_ready(int32_t osd_id); | |
191 | ||
11fdf7f2 TL |
192 | SafeTimer timer; |
193 | bool shutting_down; | |
194 | Context *tick_event; | |
195 | void tick(); | |
196 | void schedule_tick_locked(double delay_sec); | |
197 | ||
9f95a23c | 198 | class OSDPerfMetricCollectorListener : public MetricListener { |
11fdf7f2 TL |
199 | public: |
200 | OSDPerfMetricCollectorListener(DaemonServer *server) | |
201 | : server(server) { | |
202 | } | |
203 | void handle_query_updated() override { | |
204 | server->handle_osd_perf_metric_query_updated(); | |
205 | } | |
206 | private: | |
207 | DaemonServer *server; | |
208 | }; | |
209 | OSDPerfMetricCollectorListener osd_perf_metric_collector_listener; | |
210 | OSDPerfMetricCollector osd_perf_metric_collector; | |
211 | void handle_osd_perf_metric_query_updated(); | |
212 | ||
f67539c2 TL |
213 | class MDSPerfMetricCollectorListener : public MetricListener { |
214 | public: | |
215 | MDSPerfMetricCollectorListener(DaemonServer *server) | |
216 | : server(server) { | |
217 | } | |
218 | void handle_query_updated() override { | |
219 | server->handle_mds_perf_metric_query_updated(); | |
220 | } | |
221 | private: | |
222 | DaemonServer *server; | |
223 | }; | |
224 | MDSPerfMetricCollectorListener mds_perf_metric_collector_listener; | |
225 | MDSPerfMetricCollector mds_perf_metric_collector; | |
226 | void handle_mds_perf_metric_query_updated(); | |
227 | ||
9f95a23c TL |
228 | void handle_metric_payload(const OSDMetricPayload &payload) { |
229 | osd_perf_metric_collector.process_reports(payload); | |
230 | } | |
231 | ||
f67539c2 TL |
232 | void handle_metric_payload(const MDSMetricPayload &payload) { |
233 | mds_perf_metric_collector.process_reports(payload); | |
234 | } | |
235 | ||
9f95a23c TL |
236 | void handle_metric_payload(const UnknownMetricPayload &payload) { |
237 | ceph_abort(); | |
238 | } | |
239 | ||
240 | struct HandlePayloadVisitor : public boost::static_visitor<void> { | |
241 | DaemonServer *server; | |
242 | ||
243 | HandlePayloadVisitor(DaemonServer *server) | |
244 | : server(server) { | |
245 | } | |
246 | ||
247 | template <typename MetricPayload> | |
248 | inline void operator()(const MetricPayload &payload) const { | |
249 | server->handle_metric_payload(payload); | |
250 | } | |
251 | }; | |
252 | ||
f91f0fd5 TL |
253 | void update_task_status(DaemonKey key, |
254 | const std::map<std::string,std::string>& task_status); | |
9f95a23c | 255 | |
7c673cae | 256 | public: |
11fdf7f2 | 257 | int init(uint64_t gid, entity_addrvec_t client_addrs); |
7c673cae FG |
258 | void shutdown(); |
259 | ||
11fdf7f2 | 260 | entity_addrvec_t get_myaddrs() const; |
7c673cae FG |
261 | |
262 | DaemonServer(MonClient *monc_, | |
263 | Finisher &finisher_, | |
264 | DaemonStateIndex &daemon_state_, | |
265 | ClusterState &cluster_state_, | |
3efd9988 | 266 | PyModuleRegistry &py_modules_, |
7c673cae FG |
267 | LogChannelRef cl, |
268 | LogChannelRef auditcl); | |
269 | ~DaemonServer() override; | |
270 | ||
9f95a23c | 271 | bool ms_dispatch2(const ceph::ref_t<Message>& m) override; |
11fdf7f2 | 272 | int ms_handle_authentication(Connection *con) override; |
31f18b77 | 273 | bool ms_handle_reset(Connection *con) override; |
7c673cae FG |
274 | void ms_handle_remote_reset(Connection *con) override {} |
275 | bool ms_handle_refused(Connection *con) override; | |
9f95a23c | 276 | |
1911f103 | 277 | void fetch_missing_metadata(const DaemonKey& key, const entity_addr_t& addr); |
9f95a23c | 278 | bool handle_open(const ceph::ref_t<MMgrOpen>& m); |
2a845540 | 279 | bool handle_update(const ceph::ref_t<MMgrUpdate>& m); |
9f95a23c TL |
280 | bool handle_close(const ceph::ref_t<MMgrClose>& m); |
281 | bool handle_report(const ceph::ref_t<MMgrReport>& m); | |
282 | bool handle_command(const ceph::ref_t<MCommand>& m); | |
283 | bool handle_command(const ceph::ref_t<MMgrCommand>& m); | |
284 | bool _handle_command(std::shared_ptr<CommandContext>& cmdctx); | |
31f18b77 | 285 | void send_report(); |
224ce89b | 286 | void got_service_map(); |
11fdf7f2 TL |
287 | void got_mgr_map(); |
288 | void adjust_pgs(); | |
3efd9988 FG |
289 | |
290 | void _send_configure(ConnectionRef c); | |
291 | ||
9f95a23c | 292 | MetricQueryID add_osd_perf_query( |
11fdf7f2 TL |
293 | const OSDPerfMetricQuery &query, |
294 | const std::optional<OSDPerfMetricLimit> &limit); | |
9f95a23c | 295 | int remove_osd_perf_query(MetricQueryID query_id); |
f67539c2 TL |
296 | int get_osd_perf_counters(OSDPerfCollector *collector); |
297 | ||
298 | MetricQueryID add_mds_perf_query(const MDSPerfMetricQuery &query, | |
299 | const std::optional<MDSPerfMetricLimit> &limit); | |
300 | int remove_mds_perf_query(MetricQueryID query_id); | |
33c7a0ef | 301 | void reregister_mds_perf_queries(); |
f67539c2 | 302 | int get_mds_perf_counters(MDSPerfCollector *collector); |
11fdf7f2 | 303 | |
3efd9988 | 304 | virtual const char** get_tracked_conf_keys() const override; |
11fdf7f2 | 305 | virtual void handle_conf_change(const ConfigProxy& conf, |
3efd9988 | 306 | const std::set <std::string> &changed) override; |
11fdf7f2 TL |
307 | |
308 | void schedule_tick(double delay_sec); | |
92f5a8d4 TL |
309 | |
310 | void log_access_denied(std::shared_ptr<CommandContext>& cmdctx, | |
311 | MgrSession* session, std::stringstream& ss); | |
9f95a23c | 312 | void dump_pg_ready(ceph::Formatter *f); |
7c673cae FG |
313 | }; |
314 | ||
315 | #endif | |
316 |