]> git.proxmox.com Git - ceph.git/blame - ceph/src/messages/MMDSBeacon.h
patches: remove fuzz and re-format
[ceph.git] / ceph / src / messages / MMDSBeacon.h
CommitLineData
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) 2004-2006 Sage Weil <sage@newdream.net>
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
15#ifndef CEPH_MMDSBEACON_H
16#define CEPH_MMDSBEACON_H
17
94b18763
FG
18#include <boost/utility/string_view.hpp>
19
7c673cae
FG
20#include "messages/PaxosServiceMessage.h"
21
22#include "include/types.h"
23
24#include "mds/MDSMap.h"
25
26
27
28/**
29 * Unique ID for each type of metric we can send to the mon, so that if the mon
30 * knows about the IDs then it can implement special behaviour for certain
31 * messages.
32 */
33enum mds_metric_t {
34 MDS_HEALTH_NULL = 0,
35 MDS_HEALTH_TRIM,
36 MDS_HEALTH_CLIENT_RECALL,
37 MDS_HEALTH_CLIENT_LATE_RELEASE,
38 MDS_HEALTH_CLIENT_RECALL_MANY,
39 MDS_HEALTH_CLIENT_LATE_RELEASE_MANY,
40 MDS_HEALTH_CLIENT_OLDEST_TID,
41 MDS_HEALTH_CLIENT_OLDEST_TID_MANY,
42 MDS_HEALTH_DAMAGE,
43 MDS_HEALTH_READ_ONLY,
44 MDS_HEALTH_SLOW_REQUEST,
45 MDS_HEALTH_CACHE_OVERSIZED
46};
47
224ce89b
WB
48static inline const char *mds_metric_name(mds_metric_t m)
49{
50 switch (m) {
51 case MDS_HEALTH_TRIM: return "MDS_TRIM";
52 case MDS_HEALTH_CLIENT_RECALL: return "MDS_CLIENT_RECALL";
53 case MDS_HEALTH_CLIENT_LATE_RELEASE: return "MDS_CLIENT_LATE_RELEASE";
54 case MDS_HEALTH_CLIENT_RECALL_MANY: return "MDS_CLIENT_RECALL_MANY";
55 case MDS_HEALTH_CLIENT_LATE_RELEASE_MANY: return "MDS_CLIENT_LATE_RELEASE_MANY";
56 case MDS_HEALTH_CLIENT_OLDEST_TID: return "MDS_CLIENT_OLDEST_TID";
57 case MDS_HEALTH_CLIENT_OLDEST_TID_MANY: return "MDS_CLIENT_OLDEST_TID_MANY";
58 case MDS_HEALTH_DAMAGE: return "MDS_DAMAGE";
59 case MDS_HEALTH_READ_ONLY: return "MDS_READ_ONLY";
60 case MDS_HEALTH_SLOW_REQUEST: return "MDS_SLOW_REQUEST";
61 case MDS_HEALTH_CACHE_OVERSIZED: return "MDS_CACHE_OVERSIZED";
62 default:
63 return "???";
64 }
65}
66
67static inline const char *mds_metric_summary(mds_metric_t m)
68{
69 switch (m) {
70 case MDS_HEALTH_TRIM:
71 return "%num% MDSs behind on trimming";
72 case MDS_HEALTH_CLIENT_RECALL:
73 return "%num% clients failing to respond to cache pressure";
74 case MDS_HEALTH_CLIENT_LATE_RELEASE:
75 return "%num% clients failing to respond to capability release";
76 case MDS_HEALTH_CLIENT_RECALL_MANY:
77 return "%num% MDSs have many clients failing to respond to cache pressure";
78 case MDS_HEALTH_CLIENT_LATE_RELEASE_MANY:
79 return "%num% MDSs have many clients failing to respond to capability "
80 "release";
81 case MDS_HEALTH_CLIENT_OLDEST_TID:
82 return "%num% clients failing to advance oldest client/flush tid";
83 case MDS_HEALTH_CLIENT_OLDEST_TID_MANY:
84 return "%num% MDSs have clients failing to advance oldest client/flush tid";
85 case MDS_HEALTH_DAMAGE:
86 return "%num% MDSs report damaged metadata";
87 case MDS_HEALTH_READ_ONLY:
88 return "%num% MDSs are read only";
89 case MDS_HEALTH_SLOW_REQUEST:
90 return "%num% MDSs report slow requests";
91 case MDS_HEALTH_CACHE_OVERSIZED:
92 return "%num% MDSs report oversized cache";
93 default:
94 return "???";
95 }
96}
97
7c673cae
FG
98/**
99 * This structure is designed to allow some flexibility in how we emit health
100 * complaints, such that:
101 * - The mon doesn't have to have foreknowledge of all possible metrics: we can
102 * implement new messages in the MDS and have the mon pass them through to the user
103 * (enables us to do complex checks inside the MDS, and allows mon to be older version
104 * than MDS)
105 * - The mon has enough information to perform reductions on some types of metric, for
106 * example complaints about the same client from multiple MDSs where we might want
107 * to reduce three "client X is stale on MDS y" metrics into one "client X is stale
108 * on 3 MDSs" message.
109 */
110struct MDSHealthMetric
111{
112 mds_metric_t type;
113 health_status_t sev;
114 std::string message;
115 std::map<std::string, std::string> metadata;
116
117 void encode(bufferlist& bl) const {
118 ENCODE_START(1, 1, bl);
119 assert(type != MDS_HEALTH_NULL);
120 ::encode((uint16_t)type, bl);
121 ::encode((uint8_t)sev, bl);
122 ::encode(message, bl);
123 ::encode(metadata, bl);
124 ENCODE_FINISH(bl);
125 }
126
127 void decode(bufferlist::iterator& bl) {
128 DECODE_START(1, bl);
129 ::decode((uint16_t&)type, bl);
130 assert(type != MDS_HEALTH_NULL);
131 ::decode((uint8_t&)sev, bl);
132 ::decode(message, bl);
133 ::decode(metadata, bl);
134 DECODE_FINISH(bl);
135 }
136
137 bool operator==(MDSHealthMetric const &other) const
138 {
139 return (type == other.type && sev == other.sev && message == other.message);
140 }
141
142 MDSHealthMetric() : type(MDS_HEALTH_NULL), sev(HEALTH_OK) {}
94b18763 143 MDSHealthMetric(mds_metric_t type_, health_status_t sev_, boost::string_view message_)
7c673cae
FG
144 : type(type_), sev(sev_), message(message_) {}
145};
146WRITE_CLASS_ENCODER(MDSHealthMetric)
147
148
149/**
150 * Health metrics send by the MDS to the mon, so that the mon can generate
151 * user friendly warnings about undesirable states.
152 */
153struct MDSHealth
154{
155 std::list<MDSHealthMetric> metrics;
156
157 void encode(bufferlist& bl) const {
158 ENCODE_START(1, 1, bl);
159 ::encode(metrics, bl);
160 ENCODE_FINISH(bl);
161 }
162
163 void decode(bufferlist::iterator& bl) {
164 DECODE_START(1, bl);
165 ::decode(metrics, bl);
166 DECODE_FINISH(bl);
167 }
168
169 bool operator==(MDSHealth const &other) const
170 {
171 return metrics == other.metrics;
172 }
173};
174WRITE_CLASS_ENCODER(MDSHealth)
175
176
177class MMDSBeacon : public PaxosServiceMessage {
178
179 static const int HEAD_VERSION = 7;
180 static const int COMPAT_VERSION = 6;
181
182 uuid_d fsid;
183 mds_gid_t global_id;
184 string name;
185
186 MDSMap::DaemonState state;
187 version_t seq;
188
189 mds_rank_t standby_for_rank;
190 string standby_for_name;
191 fs_cluster_id_t standby_for_fscid;
192 bool standby_replay;
193
194 CompatSet compat;
195
196 MDSHealth health;
197
198 map<string, string> sys_info;
199
200 uint64_t mds_features;
201
202 public:
203 MMDSBeacon()
204 : PaxosServiceMessage(MSG_MDS_BEACON, 0, HEAD_VERSION, COMPAT_VERSION),
205 global_id(0), state(MDSMap::STATE_NULL), standby_for_rank(MDS_RANK_NONE),
206 standby_for_fscid(FS_CLUSTER_ID_NONE), standby_replay(false),
207 mds_features(0)
208 { }
209 MMDSBeacon(const uuid_d &f, mds_gid_t g, string& n, epoch_t les, MDSMap::DaemonState st, version_t se, uint64_t feat) :
210 PaxosServiceMessage(MSG_MDS_BEACON, les, HEAD_VERSION, COMPAT_VERSION),
211 fsid(f), global_id(g), name(n), state(st), seq(se),
212 standby_for_rank(MDS_RANK_NONE), standby_for_fscid(FS_CLUSTER_ID_NONE),
213 standby_replay(false), mds_features(feat) {
214 }
215private:
216 ~MMDSBeacon() override {}
217
218public:
219 uuid_d& get_fsid() { return fsid; }
220 mds_gid_t get_global_id() { return global_id; }
221 string& get_name() { return name; }
222 epoch_t get_last_epoch_seen() { return version; }
223 MDSMap::DaemonState get_state() { return state; }
224 version_t get_seq() { return seq; }
225 const char *get_type_name() const override { return "mdsbeacon"; }
226 mds_rank_t get_standby_for_rank() { return standby_for_rank; }
227 const string& get_standby_for_name() { return standby_for_name; }
228 const fs_cluster_id_t& get_standby_for_fscid() { return standby_for_fscid; }
229 bool get_standby_replay() const { return standby_replay; }
230 uint64_t get_mds_features() const { return mds_features; }
231
232 CompatSet const& get_compat() const { return compat; }
233 void set_compat(const CompatSet& c) { compat = c; }
234
235 MDSHealth const& get_health() const { return health; }
236 void set_health(const MDSHealth &h) { health = h; }
237
238 void set_standby_for_rank(mds_rank_t r) { standby_for_rank = r; }
239 void set_standby_for_name(string& n) { standby_for_name = n; }
240 void set_standby_for_name(const char* c) { standby_for_name.assign(c); }
241 void set_standby_for_fscid(fs_cluster_id_t f) { standby_for_fscid = f; }
242 void set_standby_replay(bool r) { standby_replay = r; }
243
244 const map<string, string>& get_sys_info() const { return sys_info; }
245 void set_sys_info(const map<string, string>& i) { sys_info = i; }
246
247 void print(ostream& out) const override {
248 out << "mdsbeacon(" << global_id << "/" << name << " " << ceph_mds_state_name(state)
249 << " seq " << seq << " v" << version << ")";
250 }
251
252 void encode_payload(uint64_t features) override {
253 paxos_encode();
254 ::encode(fsid, payload);
255 ::encode(global_id, payload);
256 ::encode((__u32)state, payload);
257 ::encode(seq, payload);
258 ::encode(name, payload);
259 ::encode(standby_for_rank, payload);
260 ::encode(standby_for_name, payload);
261 ::encode(compat, payload);
262 ::encode(health, payload);
263 if (state == MDSMap::STATE_BOOT) {
264 ::encode(sys_info, payload);
265 }
266 ::encode(mds_features, payload);
267 ::encode(standby_for_fscid, payload);
268 ::encode(standby_replay, payload);
269 }
270 void decode_payload() override {
271 bufferlist::iterator p = payload.begin();
272 paxos_decode(p);
273 ::decode(fsid, p);
274 ::decode(global_id, p);
275 ::decode((__u32&)state, p);
276 ::decode(seq, p);
277 ::decode(name, p);
278 ::decode(standby_for_rank, p);
279 ::decode(standby_for_name, p);
280 ::decode(compat, p);
281 ::decode(health, p);
282 if (state == MDSMap::STATE_BOOT) {
283 ::decode(sys_info, p);
284 }
285 ::decode(mds_features, p);
286 ::decode(standby_for_fscid, p);
287 if (header.version >= 7) {
288 ::decode(standby_replay, p);
289 }
290
291 if (header.version < 7 && state == MDSMap::STATE_STANDBY_REPLAY) {
292 // Old MDS daemons request the state, instead of explicitly
293 // advertising that they are configured as a replay daemon.
294 standby_replay = true;
295 state = MDSMap::STATE_STANDBY;
296 }
297 }
298};
299
300#endif