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 <string_view>
20 #include "msg/Message.h"
21 #include "messages/PaxosServiceMessage.h"
23 #include "include/types.h"
25 #include "mds/MDSMap.h"
30 * Unique ID for each type of metric we can send to the mon, so that if the mon
31 * knows about the IDs then it can implement special behaviour for certain
37 MDS_HEALTH_CLIENT_RECALL
,
38 MDS_HEALTH_CLIENT_LATE_RELEASE
,
39 MDS_HEALTH_CLIENT_RECALL_MANY
,
40 MDS_HEALTH_CLIENT_LATE_RELEASE_MANY
,
41 MDS_HEALTH_CLIENT_OLDEST_TID
,
42 MDS_HEALTH_CLIENT_OLDEST_TID_MANY
,
45 MDS_HEALTH_SLOW_REQUEST
,
46 MDS_HEALTH_CACHE_OVERSIZED
,
47 MDS_HEALTH_SLOW_METADATA_IO
,
50 inline const char *mds_metric_name(mds_metric_t m
)
53 case MDS_HEALTH_TRIM
: return "MDS_TRIM";
54 case MDS_HEALTH_CLIENT_RECALL
: return "MDS_CLIENT_RECALL";
55 case MDS_HEALTH_CLIENT_LATE_RELEASE
: return "MDS_CLIENT_LATE_RELEASE";
56 case MDS_HEALTH_CLIENT_RECALL_MANY
: return "MDS_CLIENT_RECALL_MANY";
57 case MDS_HEALTH_CLIENT_LATE_RELEASE_MANY
: return "MDS_CLIENT_LATE_RELEASE_MANY";
58 case MDS_HEALTH_CLIENT_OLDEST_TID
: return "MDS_CLIENT_OLDEST_TID";
59 case MDS_HEALTH_CLIENT_OLDEST_TID_MANY
: return "MDS_CLIENT_OLDEST_TID_MANY";
60 case MDS_HEALTH_DAMAGE
: return "MDS_DAMAGE";
61 case MDS_HEALTH_READ_ONLY
: return "MDS_READ_ONLY";
62 case MDS_HEALTH_SLOW_REQUEST
: return "MDS_SLOW_REQUEST";
63 case MDS_HEALTH_CACHE_OVERSIZED
: return "MDS_CACHE_OVERSIZED";
64 case MDS_HEALTH_SLOW_METADATA_IO
: return "MDS_SLOW_METADATA_IO";
70 inline const char *mds_metric_summary(mds_metric_t m
)
74 return "%num% MDSs behind on trimming";
75 case MDS_HEALTH_CLIENT_RECALL
:
76 return "%num% clients failing to respond to cache pressure";
77 case MDS_HEALTH_CLIENT_LATE_RELEASE
:
78 return "%num% clients failing to respond to capability release";
79 case MDS_HEALTH_CLIENT_RECALL_MANY
:
80 return "%num% MDSs have many clients failing to respond to cache pressure";
81 case MDS_HEALTH_CLIENT_LATE_RELEASE_MANY
:
82 return "%num% MDSs have many clients failing to respond to capability "
84 case MDS_HEALTH_CLIENT_OLDEST_TID
:
85 return "%num% clients failing to advance oldest client/flush tid";
86 case MDS_HEALTH_CLIENT_OLDEST_TID_MANY
:
87 return "%num% MDSs have clients failing to advance oldest client/flush tid";
88 case MDS_HEALTH_DAMAGE
:
89 return "%num% MDSs report damaged metadata";
90 case MDS_HEALTH_READ_ONLY
:
91 return "%num% MDSs are read only";
92 case MDS_HEALTH_SLOW_REQUEST
:
93 return "%num% MDSs report slow requests";
94 case MDS_HEALTH_CACHE_OVERSIZED
:
95 return "%num% MDSs report oversized cache";
96 case MDS_HEALTH_SLOW_METADATA_IO
:
97 return "%num% MDSs report slow metadata IOs";
104 * This structure is designed to allow some flexibility in how we emit health
105 * complaints, such that:
106 * - The mon doesn't have to have foreknowledge of all possible metrics: we can
107 * implement new messages in the MDS and have the mon pass them through to the user
108 * (enables us to do complex checks inside the MDS, and allows mon to be older version
110 * - The mon has enough information to perform reductions on some types of metric, for
111 * example complaints about the same client from multiple MDSs where we might want
112 * to reduce three "client X is stale on MDS y" metrics into one "client X is stale
113 * on 3 MDSs" message.
115 struct MDSHealthMetric
120 std::map
<std::string
, std::string
> metadata
;
122 void encode(bufferlist
& bl
) const {
123 ENCODE_START(1, 1, bl
);
124 ceph_assert(type
!= MDS_HEALTH_NULL
);
125 encode((uint16_t)type
, bl
);
126 encode((uint8_t)sev
, bl
);
128 encode(metadata
, bl
);
132 void decode(bufferlist::const_iterator
& bl
) {
134 decode((uint16_t&)type
, bl
);
135 ceph_assert(type
!= MDS_HEALTH_NULL
);
136 decode((uint8_t&)sev
, bl
);
138 decode(metadata
, bl
);
142 bool operator==(MDSHealthMetric
const &other
) const
144 return (type
== other
.type
&& sev
== other
.sev
&& message
== other
.message
);
147 MDSHealthMetric() : type(MDS_HEALTH_NULL
), sev(HEALTH_OK
) {}
148 MDSHealthMetric(mds_metric_t type_
, health_status_t sev_
, std::string_view message_
)
149 : type(type_
), sev(sev_
), message(message_
) {}
151 WRITE_CLASS_ENCODER(MDSHealthMetric
)
155 * Health metrics send by the MDS to the mon, so that the mon can generate
156 * user friendly warnings about undesirable states.
160 std::vector
<MDSHealthMetric
> metrics
;
162 void encode(bufferlist
& bl
) const {
163 ENCODE_START(1, 1, bl
);
168 void decode(bufferlist::const_iterator
& bl
) {
174 bool operator==(MDSHealth
const &other
) const
176 return metrics
== other
.metrics
;
179 WRITE_CLASS_ENCODER(MDSHealth
)
182 class MMDSBeacon
: public PaxosServiceMessage
{
185 static constexpr int HEAD_VERSION
= 8;
186 static constexpr int COMPAT_VERSION
= 6;
189 mds_gid_t global_id
= MDS_GID_NONE
;
192 MDSMap::DaemonState state
= MDSMap::STATE_NULL
;
199 map
<string
, string
> sys_info
;
201 uint64_t mds_features
= 0;
206 MMDSBeacon() : PaxosServiceMessage(MSG_MDS_BEACON
, 0, HEAD_VERSION
, COMPAT_VERSION
)
208 set_priority(CEPH_MSG_PRIO_HIGH
);
210 MMDSBeacon(const uuid_d
&f
, mds_gid_t g
, const string
& n
, epoch_t les
, MDSMap::DaemonState st
, version_t se
, uint64_t feat
) :
211 PaxosServiceMessage(MSG_MDS_BEACON
, les
, HEAD_VERSION
, COMPAT_VERSION
),
212 fsid(f
), global_id(g
), name(n
), state(st
), seq(se
),
214 set_priority(CEPH_MSG_PRIO_HIGH
);
216 ~MMDSBeacon() override
{}
219 const uuid_d
& get_fsid() const { return fsid
; }
220 mds_gid_t
get_global_id() const { return global_id
; }
221 const string
& get_name() const { return name
; }
222 epoch_t
get_last_epoch_seen() const { return version
; }
223 MDSMap::DaemonState
get_state() const { return state
; }
224 version_t
get_seq() const { return seq
; }
225 std::string_view
get_type_name() const override
{ return "mdsbeacon"; }
226 uint64_t get_mds_features() const { return mds_features
; }
228 CompatSet
const& get_compat() const { return compat
; }
229 void set_compat(const CompatSet
& c
) { compat
= c
; }
231 MDSHealth
const& get_health() const { return health
; }
232 void set_health(const MDSHealth
&h
) { health
= h
; }
234 const string
& get_fs() const { return fs
; }
235 void set_fs(std::string_view s
) { fs
= s
; }
237 const map
<string
, string
>& get_sys_info() const { return sys_info
; }
238 void set_sys_info(const map
<string
, string
>& i
) { sys_info
= i
; }
240 void print(ostream
& out
) const override
{
241 out
<< "mdsbeacon(" << global_id
<< "/" << name
242 << " " << ceph_mds_state_name(state
);
246 out
<< " seq=" << seq
<< " v" << version
<< ")";
249 void encode_payload(uint64_t features
) override
{
252 encode(fsid
, payload
);
253 encode(global_id
, payload
);
254 encode((__u32
)state
, payload
);
255 encode(seq
, payload
);
256 encode(name
, payload
);
257 encode(MDS_RANK_NONE
, payload
);
258 encode(std::string(), payload
);
259 encode(compat
, payload
);
260 encode(health
, payload
);
261 if (state
== MDSMap::STATE_BOOT
) {
262 encode(sys_info
, payload
);
264 encode(mds_features
, payload
);
265 encode(FS_CLUSTER_ID_NONE
, payload
);
266 encode(false, payload
);
269 void decode_payload() override
{
271 auto p
= payload
.cbegin();
274 decode(global_id
, p
);
275 decode((__u32
&)state
, p
);
279 mds_rank_t standby_for_rank
;
280 decode(standby_for_rank
, p
);
283 std::string standby_for_name
;
284 decode(standby_for_name
, p
);
288 if (state
== MDSMap::STATE_BOOT
) {
291 decode(mds_features
, p
);
293 fs_cluster_id_t standby_for_fscid
;
294 decode(standby_for_fscid
, p
);
296 if (header
.version
>= 7) {
298 decode(standby_replay
, p
);
301 if (header
.version
< 7 && state
== MDSMap::STATE_STANDBY_REPLAY
) {
302 // Old MDS daemons request the state, instead of explicitly
303 // advertising that they are configured as a replay daemon.
304 state
= MDSMap::STATE_STANDBY
;
306 if (header
.version
>= 8) {
311 template<class T
, typename
... Args
>
312 friend boost::intrusive_ptr
<T
> ceph::make_message(Args
&&... args
);