]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/MDSMap.h
update sources to v12.2.3
[ceph.git] / ceph / src / mds / MDSMap.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
16#ifndef CEPH_MDSMAP_H
17#define CEPH_MDSMAP_H
18
19#include <errno.h>
20
21#include "include/types.h"
22#include "common/Clock.h"
23#include "msg/Message.h"
224ce89b 24#include "include/health.h"
7c673cae
FG
25
26#include <set>
27#include <map>
28#include <string>
31f18b77 29#include <algorithm>
7c673cae
FG
30
31#include "common/config.h"
32
33#include "include/CompatSet.h"
34#include "include/ceph_features.h"
35#include "common/Formatter.h"
36#include "mds/mdstypes.h"
37
38/*
39
40 boot --> standby, creating, or starting.
41
42
43 dne ----> creating -----> active*
44 ^ ^___________/ / ^ ^
45 | / / |
46 destroying / / |
47 ^ / / |
48 | / / |
49 stopped <---- stopping* <-/ / |
50 \ / |
51 ----- starting* ----/ |
52 |
53 failed |
54 \ |
55 \--> replay* --> reconnect* --> rejoin*
56
57 * = can fail
58
59*/
60
61class CephContext;
224ce89b 62class health_check_map_t;
7c673cae
FG
63
64extern CompatSet get_mdsmap_compat_set_all();
65extern CompatSet get_mdsmap_compat_set_default();
66extern CompatSet get_mdsmap_compat_set_base(); // pre v0.20
67
68#define MDS_FEATURE_INCOMPAT_BASE CompatSet::Feature(1, "base v0.20")
69#define MDS_FEATURE_INCOMPAT_CLIENTRANGES CompatSet::Feature(2, "client writeable ranges")
70#define MDS_FEATURE_INCOMPAT_FILELAYOUT CompatSet::Feature(3, "default file layouts on dirs")
71#define MDS_FEATURE_INCOMPAT_DIRINODE CompatSet::Feature(4, "dir inode in separate object")
72#define MDS_FEATURE_INCOMPAT_ENCODING CompatSet::Feature(5, "mds uses versioned encoding")
73#define MDS_FEATURE_INCOMPAT_OMAPDIRFRAG CompatSet::Feature(6, "dirfrag is stored in omap")
74#define MDS_FEATURE_INCOMPAT_INLINE CompatSet::Feature(7, "mds uses inline data")
75#define MDS_FEATURE_INCOMPAT_NOANCHOR CompatSet::Feature(8, "no anchor table")
b32b8144 76#define MDS_FEATURE_INCOMPAT_FILE_LAYOUT_V2 CompatSet::Feature(9, "file layout v2")
7c673cae
FG
77
78#define MDS_FS_NAME_DEFAULT "cephfs"
79
80class MDSMap {
81public:
82 /* These states are the union of the set of possible states of an MDS daemon,
83 * and the set of possible states of an MDS rank */
84 typedef enum {
85 // States of an MDS daemon not currently holding a rank
86 // ====================================================
87 STATE_NULL = CEPH_MDS_STATE_NULL, // null value for fns returning this type.
88 STATE_BOOT = CEPH_MDS_STATE_BOOT, // up, boot announcement. destiny unknown.
89 STATE_STANDBY = CEPH_MDS_STATE_STANDBY, // up, idle. waiting for assignment by monitor.
90 STATE_STANDBY_REPLAY = CEPH_MDS_STATE_STANDBY_REPLAY, // up, replaying active node, ready to take over.
91
92 // States of an MDS rank, and of any MDS daemon holding that rank
93 // ==============================================================
94 STATE_STOPPED = CEPH_MDS_STATE_STOPPED, // down, once existed, but no subtrees. empty log. may not be held by a daemon.
95
96 STATE_CREATING = CEPH_MDS_STATE_CREATING, // up, creating MDS instance (new journal, idalloc..).
97 STATE_STARTING = CEPH_MDS_STATE_STARTING, // up, starting prior stopped MDS instance.
98
99 STATE_REPLAY = CEPH_MDS_STATE_REPLAY, // up, starting prior failed instance. scanning journal.
100 STATE_RESOLVE = CEPH_MDS_STATE_RESOLVE, // up, disambiguating distributed operations (import, rename, etc.)
101 STATE_RECONNECT = CEPH_MDS_STATE_RECONNECT, // up, reconnect to clients
102 STATE_REJOIN = CEPH_MDS_STATE_REJOIN, // up, replayed journal, rejoining distributed cache
103 STATE_CLIENTREPLAY = CEPH_MDS_STATE_CLIENTREPLAY, // up, active
104 STATE_ACTIVE = CEPH_MDS_STATE_ACTIVE, // up, active
105 STATE_STOPPING = CEPH_MDS_STATE_STOPPING, // up, exporting metadata (-> standby or out)
106 STATE_DNE = CEPH_MDS_STATE_DNE, // down, rank does not exist
107
108 // State which a daemon may send to MDSMonitor in its beacon
109 // to indicate that offline repair is required. Daemon must stop
110 // immediately after indicating this state.
111 STATE_DAMAGED = CEPH_MDS_STATE_DAMAGED
112
113 /*
114 * In addition to explicit states, an MDS rank implicitly in state:
115 * - STOPPED if it is not currently associated with an MDS daemon gid but it
116 * is in MDSMap::stopped
117 * - FAILED if it is not currently associated with an MDS daemon gid but it
118 * is in MDSMap::failed
119 * - DNE if it is not currently associated with an MDS daemon gid and it is
120 * missing from both MDSMap::failed and MDSMap::stopped
121 */
122 } DaemonState;
123
124 struct mds_info_t {
125 mds_gid_t global_id;
126 std::string name;
127 mds_rank_t rank;
128 int32_t inc;
129 MDSMap::DaemonState state;
130 version_t state_seq;
131 entity_addr_t addr;
132 utime_t laggy_since;
133 mds_rank_t standby_for_rank;
134 std::string standby_for_name;
135 fs_cluster_id_t standby_for_fscid;
136 bool standby_replay;
137 std::set<mds_rank_t> export_targets;
c07f9fc5 138 uint64_t mds_features = 0;
7c673cae
FG
139
140 mds_info_t() : global_id(MDS_GID_NONE), rank(MDS_RANK_NONE), inc(0),
141 state(STATE_STANDBY), state_seq(0),
142 standby_for_rank(MDS_RANK_NONE),
143 standby_for_fscid(FS_CLUSTER_ID_NONE),
144 standby_replay(false)
145 { }
146
147 bool laggy() const { return !(laggy_since == utime_t()); }
148 void clear_laggy() { laggy_since = utime_t(); }
149
150 entity_inst_t get_inst() const { return entity_inst_t(entity_name_t::MDS(rank), addr); }
151
152 void encode(bufferlist& bl, uint64_t features) const {
153 if ((features & CEPH_FEATURE_MDSENC) == 0 ) encode_unversioned(bl);
154 else encode_versioned(bl, features);
155 }
156 void decode(bufferlist::iterator& p);
157 void dump(Formatter *f) const;
158 void print_summary(ostream &out) const;
d2e6a577
FG
159
160 // The long form name for use in cluster log messages`
161 std::string human_name() const;
162
7c673cae
FG
163 static void generate_test_instances(list<mds_info_t*>& ls);
164 private:
165 void encode_versioned(bufferlist& bl, uint64_t features) const;
166 void encode_unversioned(bufferlist& bl) const;
167 };
168
169
170protected:
171 // base map
172 epoch_t epoch;
173 bool enabled;
174 std::string fs_name;
175 uint32_t flags; // flags
176 epoch_t last_failure; // mds epoch of last failure
177 epoch_t last_failure_osd_epoch; // osd epoch of last failure; any mds entering replay needs
178 // at least this osdmap to ensure the blacklist propagates.
179 utime_t created, modified;
180
181 mds_rank_t tableserver; // which MDS has snaptable
182 mds_rank_t root; // which MDS has root directory
183
184 __u32 session_timeout;
185 __u32 session_autoclose;
186 uint64_t max_file_size;
187
31f18b77 188 std::vector<int64_t> data_pools; // file data pools available to clients (via an ioctl). first is the default.
7c673cae
FG
189 int64_t cas_pool; // where CAS objects go
190 int64_t metadata_pool; // where fs metadata objects go
191
192 /*
193 * in: the set of logical mds #'s that define the cluster. this is the set
194 * of mds's the metadata may be distributed over.
195 * up: map from logical mds #'s to the addrs filling those roles.
196 * failed: subset of @in that are failed.
197 * stopped: set of nodes that have been initialized, but are not active.
198 *
199 * @up + @failed = @in. @in * @stopped = {}.
200 */
201
202 mds_rank_t max_mds; /* The maximum number of active MDSes. Also, the maximum rank. */
203 mds_rank_t standby_count_wanted;
204 string balancer; /* The name/version of the mantle balancer (i.e. the rados obj name) */
205
206 std::set<mds_rank_t> in; // currently defined cluster
207
208 // which ranks are failed, stopped, damaged (i.e. not held by a daemon)
209 std::set<mds_rank_t> failed, stopped, damaged;
210 std::map<mds_rank_t, mds_gid_t> up; // who is in those roles
211 std::map<mds_gid_t, mds_info_t> mds_info;
212
213 uint8_t ever_allowed_features; //< bitmap of features the cluster has allowed
214 uint8_t explicitly_allowed_features; //< bitmap of features explicitly enabled
215
216 bool inline_data_enabled;
217
218 uint64_t cached_up_features;
219
220public:
221 CompatSet compat;
222
223 friend class MDSMonitor;
224 friend class Filesystem;
225 friend class FSMap;
226
227public:
228 MDSMap()
229 : epoch(0), enabled(false), fs_name(MDS_FS_NAME_DEFAULT),
230 flags(CEPH_MDSMAP_DEFAULTS), last_failure(0),
231 last_failure_osd_epoch(0),
232 tableserver(0), root(0),
233 session_timeout(0),
234 session_autoclose(0),
235 max_file_size(0),
236 cas_pool(-1),
237 metadata_pool(-1),
238 max_mds(0),
239 standby_count_wanted(-1),
240 ever_allowed_features(0),
241 explicitly_allowed_features(0),
242 inline_data_enabled(false),
243 cached_up_features(0)
244 { }
245
246 bool get_inline_data_enabled() const { return inline_data_enabled; }
247 void set_inline_data_enabled(bool enabled) { inline_data_enabled = enabled; }
248
249 utime_t get_session_timeout() const {
250 return utime_t(session_timeout,0);
251 }
b32b8144
FG
252
253 utime_t get_session_autoclose() const {
254 return utime_t(session_autoclose, 0);
255 }
256
7c673cae
FG
257 uint64_t get_max_filesize() const { return max_file_size; }
258 void set_max_filesize(uint64_t m) { max_file_size = m; }
259
260 int get_flags() const { return flags; }
261 bool test_flag(int f) const { return flags & f; }
262 void set_flag(int f) { flags |= f; }
263 void clear_flag(int f) { flags &= ~f; }
264
265 const std::string &get_fs_name() const {return fs_name;}
266
267 void set_snaps_allowed() {
268 set_flag(CEPH_MDSMAP_ALLOW_SNAPS);
269 ever_allowed_features |= CEPH_MDSMAP_ALLOW_SNAPS;
270 explicitly_allowed_features |= CEPH_MDSMAP_ALLOW_SNAPS;
271 }
272 void clear_snaps_allowed() { clear_flag(CEPH_MDSMAP_ALLOW_SNAPS); }
273 bool allows_snaps() const { return test_flag(CEPH_MDSMAP_ALLOW_SNAPS); }
274
275 void set_multimds_allowed() {
276 set_flag(CEPH_MDSMAP_ALLOW_MULTIMDS);
277 ever_allowed_features |= CEPH_MDSMAP_ALLOW_MULTIMDS;
278 explicitly_allowed_features |= CEPH_MDSMAP_ALLOW_MULTIMDS;
279 }
280 void clear_multimds_allowed() { clear_flag(CEPH_MDSMAP_ALLOW_MULTIMDS); }
281 bool allows_multimds() const { return test_flag(CEPH_MDSMAP_ALLOW_MULTIMDS); }
282
283 void set_dirfrags_allowed() {
284 set_flag(CEPH_MDSMAP_ALLOW_DIRFRAGS);
285 ever_allowed_features |= CEPH_MDSMAP_ALLOW_DIRFRAGS;
286 explicitly_allowed_features |= CEPH_MDSMAP_ALLOW_DIRFRAGS;
287 }
288 void clear_dirfrags_allowed() { clear_flag(CEPH_MDSMAP_ALLOW_DIRFRAGS); }
289 bool allows_dirfrags() const { return test_flag(CEPH_MDSMAP_ALLOW_DIRFRAGS); }
290
291 epoch_t get_epoch() const { return epoch; }
292 void inc_epoch() { epoch++; }
293
294 bool get_enabled() const { return enabled; }
295
296 const utime_t& get_created() const { return created; }
297 void set_created(utime_t ct) { modified = created = ct; }
298 const utime_t& get_modified() const { return modified; }
299 void set_modified(utime_t mt) { modified = mt; }
300
301 epoch_t get_last_failure() const { return last_failure; }
302 epoch_t get_last_failure_osd_epoch() const { return last_failure_osd_epoch; }
303
304 mds_rank_t get_max_mds() const { return max_mds; }
305 void set_max_mds(mds_rank_t m) { max_mds = m; }
306
307 mds_rank_t get_standby_count_wanted(mds_rank_t standby_daemon_count) const {
308 assert(standby_daemon_count >= 0);
309 std::set<mds_rank_t> s;
310 get_standby_replay_mds_set(s);
311 mds_rank_t standbys_avail = (mds_rank_t)s.size()+standby_daemon_count;
312 mds_rank_t wanted = std::max(0, standby_count_wanted);
313 return wanted > standbys_avail ? wanted - standbys_avail : 0;
314 }
315 void set_standby_count_wanted(mds_rank_t n) { standby_count_wanted = n; }
316 bool check_health(mds_rank_t standby_daemon_count);
317
318 const std::string get_balancer() const { return balancer; }
319 void set_balancer(std::string val) { balancer.assign(val); }
320
321 mds_rank_t get_tableserver() const { return tableserver; }
322 mds_rank_t get_root() const { return root; }
323
31f18b77 324 const std::vector<int64_t> &get_data_pools() const { return data_pools; }
7c673cae
FG
325 int64_t get_first_data_pool() const { return *data_pools.begin(); }
326 int64_t get_metadata_pool() const { return metadata_pool; }
327 bool is_data_pool(int64_t poolid) const {
c07f9fc5
FG
328 auto p = std::find(data_pools.begin(), data_pools.end(), poolid);
329 if (p == data_pools.end())
330 return false;
331 return true;
7c673cae
FG
332 }
333
334 bool pool_in_use(int64_t poolid) const {
335 return get_enabled() && (is_data_pool(poolid) || metadata_pool == poolid);
336 }
337
338 const std::map<mds_gid_t,mds_info_t>& get_mds_info() const { return mds_info; }
339 const mds_info_t& get_mds_info_gid(mds_gid_t gid) const {
340 return mds_info.at(gid);
341 }
342 const mds_info_t& get_mds_info(mds_rank_t m) const {
343 assert(up.count(m) && mds_info.count(up.at(m)));
344 return mds_info.at(up.at(m));
345 }
346 mds_gid_t find_mds_gid_by_name(const std::string& s) const {
347 for (std::map<mds_gid_t,mds_info_t>::const_iterator p = mds_info.begin();
348 p != mds_info.end();
349 ++p) {
350 if (p->second.name == s) {
351 return p->first;
352 }
353 }
354 return MDS_GID_NONE;
355 }
356
357 // counts
358 unsigned get_num_in_mds() const {
359 return in.size();
360 }
361 unsigned get_num_up_mds() const {
362 return up.size();
363 }
31f18b77
FG
364 mds_rank_t get_last_in_mds() const {
365 auto p = in.rbegin();
366 return p == in.rend() ? MDS_RANK_NONE : *p;
367 }
7c673cae
FG
368 int get_num_failed_mds() const {
369 return failed.size();
370 }
371 unsigned get_num_mds(int state) const {
372 unsigned n = 0;
373 for (std::map<mds_gid_t,mds_info_t>::const_iterator p = mds_info.begin();
374 p != mds_info.end();
375 ++p)
376 if (p->second.state == state) ++n;
377 return n;
378 }
379
380 // data pools
381 void add_data_pool(int64_t poolid) {
31f18b77 382 data_pools.push_back(poolid);
7c673cae
FG
383 }
384 int remove_data_pool(int64_t poolid) {
31f18b77 385 std::vector<int64_t>::iterator p = std::find(data_pools.begin(), data_pools.end(), poolid);
7c673cae
FG
386 if (p == data_pools.end())
387 return -ENOENT;
388 data_pools.erase(p);
389 return 0;
390 }
391
392 // sets
393 void get_mds_set(std::set<mds_rank_t>& s) const {
394 s = in;
395 }
396 void get_up_mds_set(std::set<mds_rank_t>& s) const {
397 for (std::map<mds_rank_t, mds_gid_t>::const_iterator p = up.begin();
398 p != up.end();
399 ++p)
400 s.insert(p->first);
401 }
402 void get_active_mds_set(std::set<mds_rank_t>& s) const {
403 get_mds_set(s, MDSMap::STATE_ACTIVE);
404 }
405 void get_standby_replay_mds_set(std::set<mds_rank_t>& s) const {
406 get_mds_set(s, MDSMap::STATE_STANDBY_REPLAY);
407 }
408 void get_failed_mds_set(std::set<mds_rank_t>& s) const {
409 s = failed;
410 }
411
412 // features
413 uint64_t get_up_features() {
414 if (!cached_up_features) {
415 bool first = true;
416 for (std::map<mds_rank_t, mds_gid_t>::const_iterator p = up.begin();
417 p != up.end();
418 ++p) {
419 std::map<mds_gid_t, mds_info_t>::const_iterator q =
420 mds_info.find(p->second);
421 assert(q != mds_info.end());
422 if (first) {
423 cached_up_features = q->second.mds_features;
424 first = false;
425 } else {
426 cached_up_features &= q->second.mds_features;
427 }
428 }
429 }
430 return cached_up_features;
431 }
432
433 /**
434 * Get MDS ranks which are in but not up.
435 */
436 void get_down_mds_set(std::set<mds_rank_t> *s) const
437 {
438 assert(s != NULL);
439 s->insert(failed.begin(), failed.end());
440 s->insert(damaged.begin(), damaged.end());
441 }
442
443 int get_failed() const {
444 if (!failed.empty()) return *failed.begin();
445 return -1;
446 }
447 void get_stopped_mds_set(std::set<mds_rank_t>& s) const {
448 s = stopped;
449 }
450 void get_recovery_mds_set(std::set<mds_rank_t>& s) const {
451 s = failed;
452 for (const auto& p : damaged)
453 s.insert(p);
454 for (const auto& p : mds_info)
455 if (p.second.state >= STATE_REPLAY && p.second.state <= STATE_STOPPING)
456 s.insert(p.second.rank);
457 }
458
459 void
460 get_clientreplay_or_active_or_stopping_mds_set(std::set<mds_rank_t>& s) const {
461 for (std::map<mds_gid_t, mds_info_t>::const_iterator p = mds_info.begin();
462 p != mds_info.end();
463 ++p)
464 if (p->second.state >= STATE_CLIENTREPLAY && p->second.state <= STATE_STOPPING)
465 s.insert(p->second.rank);
466 }
467 void get_mds_set(std::set<mds_rank_t>& s, DaemonState state) const {
468 for (std::map<mds_gid_t, mds_info_t>::const_iterator p = mds_info.begin();
469 p != mds_info.end();
470 ++p)
471 if (p->second.state == state)
472 s.insert(p->second.rank);
473 }
474
475 void get_health(list<pair<health_status_t,std::string> >& summary,
476 list<pair<health_status_t,std::string> > *detail) const;
477
224ce89b
WB
478 void get_health_checks(health_check_map_t *checks) const;
479
7c673cae
FG
480 typedef enum
481 {
482 AVAILABLE = 0,
483 TRANSIENT_UNAVAILABLE = 1,
484 STUCK_UNAVAILABLE = 2
485
486 } availability_t;
487
488 /**
489 * Return indication of whether cluster is available. This is a
490 * heuristic for clients to see if they should bother waiting to talk to
491 * MDSs, or whether they should error out at startup/mount.
492 *
493 * A TRANSIENT_UNAVAILABLE result indicates that the cluster is in a
494 * transition state like replaying, or is potentially about the fail over.
495 * Clients should wait for an updated map before making a final decision
496 * about whether the filesystem is mountable.
497 *
498 * A STUCK_UNAVAILABLE result indicates that we can't see a way that
499 * the cluster is about to recover on its own, so it'll probably require
500 * administrator intervention: clients should probaly not bother trying
501 * to mount.
502 */
503 availability_t is_cluster_available() const;
504
505 // mds states
506 bool is_down(mds_rank_t m) const { return up.count(m) == 0; }
507 bool is_up(mds_rank_t m) const { return up.count(m); }
508 bool is_in(mds_rank_t m) const { return up.count(m) || failed.count(m); }
509 bool is_out(mds_rank_t m) const { return !is_in(m); }
510
511 bool is_failed(mds_rank_t m) const { return failed.count(m); }
512 bool is_stopped(mds_rank_t m) const { return stopped.count(m); }
513
514 bool is_dne(mds_rank_t m) const { return in.count(m) == 0; }
515 bool is_dne_gid(mds_gid_t gid) const { return mds_info.count(gid) == 0; }
516
517 /**
518 * Get MDS rank state if the rank is up, else STATE_NULL
519 */
520 DaemonState get_state(mds_rank_t m) const {
521 std::map<mds_rank_t, mds_gid_t>::const_iterator u = up.find(m);
522 if (u == up.end())
523 return STATE_NULL;
524 return get_state_gid(u->second);
525 }
526
527 /**
528 * Get MDS daemon status by GID
529 */
530 DaemonState get_state_gid(mds_gid_t gid) const {
531 std::map<mds_gid_t,mds_info_t>::const_iterator i = mds_info.find(gid);
532 if (i == mds_info.end())
533 return STATE_NULL;
534 return i->second.state;
535 }
536
537 const mds_info_t& get_info(const mds_rank_t m) const {
538 return mds_info.at(up.at(m));
539 }
540 const mds_info_t& get_info_gid(const mds_gid_t gid) const {
541 return mds_info.at(gid);
542 }
543
544 bool is_boot(mds_rank_t m) const { return get_state(m) == STATE_BOOT; }
545 bool is_creating(mds_rank_t m) const { return get_state(m) == STATE_CREATING; }
546 bool is_starting(mds_rank_t m) const { return get_state(m) == STATE_STARTING; }
547 bool is_replay(mds_rank_t m) const { return get_state(m) == STATE_REPLAY; }
548 bool is_resolve(mds_rank_t m) const { return get_state(m) == STATE_RESOLVE; }
549 bool is_reconnect(mds_rank_t m) const { return get_state(m) == STATE_RECONNECT; }
550 bool is_rejoin(mds_rank_t m) const { return get_state(m) == STATE_REJOIN; }
551 bool is_clientreplay(mds_rank_t m) const { return get_state(m) == STATE_CLIENTREPLAY; }
552 bool is_active(mds_rank_t m) const { return get_state(m) == STATE_ACTIVE; }
553 bool is_stopping(mds_rank_t m) const { return get_state(m) == STATE_STOPPING; }
554 bool is_active_or_stopping(mds_rank_t m) const {
555 return is_active(m) || is_stopping(m);
556 }
557 bool is_clientreplay_or_active_or_stopping(mds_rank_t m) const {
558 return is_clientreplay(m) || is_active(m) || is_stopping(m);
559 }
560
561 bool is_followable(mds_rank_t m) const {
562 return (is_resolve(m) ||
563 is_replay(m) ||
564 is_rejoin(m) ||
565 is_clientreplay(m) ||
566 is_active(m) ||
567 is_stopping(m));
568 }
569
570 bool is_laggy_gid(mds_gid_t gid) const {
571 if (!mds_info.count(gid))
572 return false;
573 std::map<mds_gid_t,mds_info_t>::const_iterator p = mds_info.find(gid);
574 return p->second.laggy();
575 }
576
577 // degraded = some recovery in process. fixes active membership and
578 // recovery_set.
579 bool is_degraded() const {
580 if (!failed.empty() || !damaged.empty())
581 return true;
582 for (std::map<mds_gid_t,mds_info_t>::const_iterator p = mds_info.begin();
583 p != mds_info.end();
584 ++p)
585 if (p->second.state >= STATE_REPLAY && p->second.state <= STATE_CLIENTREPLAY)
586 return true;
587 return false;
588 }
589 bool is_any_failed() const {
590 return failed.size();
591 }
592 bool is_resolving() const {
593 return
594 get_num_mds(STATE_RESOLVE) > 0 &&
595 get_num_mds(STATE_REPLAY) == 0 &&
596 failed.empty() && damaged.empty();
597 }
598 bool is_rejoining() const {
599 // nodes are rejoining cache state
600 return
601 get_num_mds(STATE_REJOIN) > 0 &&
602 get_num_mds(STATE_REPLAY) == 0 &&
603 get_num_mds(STATE_RECONNECT) == 0 &&
604 get_num_mds(STATE_RESOLVE) == 0 &&
605 failed.empty() && damaged.empty();
606 }
607 bool is_stopped() const {
608 return up.empty();
609 }
610
611 /**
612 * Get whether a rank is 'up', i.e. has
613 * an MDS daemon's entity_inst_t associated
614 * with it.
615 */
616 bool have_inst(mds_rank_t m) const {
617 return up.count(m);
618 }
619
620 /**
621 * Get the MDS daemon entity_inst_t for a rank
622 * known to be up.
623 */
624 const entity_inst_t get_inst(mds_rank_t m) {
625 assert(up.count(m));
626 return mds_info[up[m]].get_inst();
627 }
628 const entity_addr_t get_addr(mds_rank_t m) {
629 assert(up.count(m));
630 return mds_info[up[m]].addr;
631 }
632
633 /**
634 * Get the MDS daemon entity_inst_t for a rank,
635 * if it is up.
636 *
637 * @return true if the rank was up and the inst
638 * was populated, else false.
639 */
640 bool get_inst(mds_rank_t m, entity_inst_t& inst) {
641 if (up.count(m)) {
642 inst = get_inst(m);
643 return true;
644 }
645 return false;
646 }
647
648 mds_rank_t get_rank_gid(mds_gid_t gid) const {
649 if (mds_info.count(gid)) {
650 return mds_info.at(gid).rank;
651 } else {
652 return MDS_RANK_NONE;
653 }
654 }
655
656 int get_inc_gid(mds_gid_t gid) const {
657 auto mds_info_entry = mds_info.find(gid);
658 if (mds_info_entry != mds_info.end())
659 return mds_info_entry->second.inc;
660 return -1;
661 }
662 void encode(bufferlist& bl, uint64_t features) const;
663 void decode(bufferlist::iterator& p);
664 void decode(bufferlist& bl) {
665 bufferlist::iterator p = bl.begin();
666 decode(p);
667 }
3efd9988 668 void sanitize(std::function<bool(int64_t pool)> pool_exists);
7c673cae
FG
669
670 void print(ostream& out) const;
671 void print_summary(Formatter *f, ostream *out) const;
672
673 void dump(Formatter *f) const;
674 static void generate_test_instances(list<MDSMap*>& ls);
675
676 static bool state_transition_valid(DaemonState prev, DaemonState next);
677};
678WRITE_CLASS_ENCODER_FEATURES(MDSMap::mds_info_t)
679WRITE_CLASS_ENCODER_FEATURES(MDSMap)
680
681inline ostream& operator<<(ostream &out, const MDSMap &m) {
682 m.print_summary(NULL, &out);
683 return out;
684}
685
686#endif