1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
15 #ifndef CEPH_MMDSBEACON_H
16 #define CEPH_MMDSBEACON_H
18 #include <boost/utility/string_view.hpp>
20 #include "messages/PaxosServiceMessage.h"
22 #include "include/types.h"
24 #include "mds/MDSMap.h"
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
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
,
44 MDS_HEALTH_SLOW_REQUEST
,
45 MDS_HEALTH_CACHE_OVERSIZED
48 static inline const char *mds_metric_name(mds_metric_t 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";
67 static inline const char *mds_metric_summary(mds_metric_t m
)
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 "
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";
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
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.
110 struct MDSHealthMetric
115 std::map
<std::string
, std::string
> metadata
;
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
);
127 void decode(bufferlist::iterator
& 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
);
137 bool operator==(MDSHealthMetric
const &other
) const
139 return (type
== other
.type
&& sev
== other
.sev
&& message
== other
.message
);
142 MDSHealthMetric() : type(MDS_HEALTH_NULL
), sev(HEALTH_OK
) {}
143 MDSHealthMetric(mds_metric_t type_
, health_status_t sev_
, boost::string_view message_
)
144 : type(type_
), sev(sev_
), message(message_
) {}
146 WRITE_CLASS_ENCODER(MDSHealthMetric
)
150 * Health metrics send by the MDS to the mon, so that the mon can generate
151 * user friendly warnings about undesirable states.
155 std::list
<MDSHealthMetric
> metrics
;
157 void encode(bufferlist
& bl
) const {
158 ENCODE_START(1, 1, bl
);
159 ::encode(metrics
, bl
);
163 void decode(bufferlist::iterator
& bl
) {
165 ::decode(metrics
, bl
);
169 bool operator==(MDSHealth
const &other
) const
171 return metrics
== other
.metrics
;
174 WRITE_CLASS_ENCODER(MDSHealth
)
177 class MMDSBeacon
: public PaxosServiceMessage
{
179 static const int HEAD_VERSION
= 7;
180 static const int COMPAT_VERSION
= 6;
186 MDSMap::DaemonState state
;
189 mds_rank_t standby_for_rank
;
190 string standby_for_name
;
191 fs_cluster_id_t standby_for_fscid
;
198 map
<string
, string
> sys_info
;
200 uint64_t mds_features
;
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),
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
) {
216 ~MMDSBeacon() override
{}
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
; }
232 CompatSet
const& get_compat() const { return compat
; }
233 void set_compat(const CompatSet
& c
) { compat
= c
; }
235 MDSHealth
const& get_health() const { return health
; }
236 void set_health(const MDSHealth
&h
) { health
= h
; }
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
; }
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
; }
247 void print(ostream
& out
) const override
{
248 out
<< "mdsbeacon(" << global_id
<< "/" << name
<< " " << ceph_mds_state_name(state
)
249 << " seq " << seq
<< " v" << version
<< ")";
252 void encode_payload(uint64_t features
) override
{
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
);
266 ::encode(mds_features
, payload
);
267 ::encode(standby_for_fscid
, payload
);
268 ::encode(standby_replay
, payload
);
270 void decode_payload() override
{
271 bufferlist::iterator p
= payload
.begin();
274 ::decode(global_id
, p
);
275 ::decode((__u32
&)state
, p
);
278 ::decode(standby_for_rank
, p
);
279 ::decode(standby_for_name
, p
);
282 if (state
== MDSMap::STATE_BOOT
) {
283 ::decode(sys_info
, p
);
285 ::decode(mds_features
, p
);
286 ::decode(standby_for_fscid
, p
);
287 if (header
.version
>= 7) {
288 ::decode(standby_replay
, p
);
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
;