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.
16 #include <boost/utility.hpp>
17 #include <boost/regex.hpp>
19 #include "MDSMonitor.h"
20 #include "FSCommands.h"
22 #include "MonitorDBStore.h"
23 #include "OSDMonitor.h"
24 #include "PGMonitor.h"
26 #include "common/strtol.h"
27 #include "common/perf_counters.h"
28 #include "common/config.h"
29 #include "common/cmdparse.h"
30 #include "messages/MMDSMap.h"
31 #include "messages/MFSMap.h"
32 #include "messages/MFSMapUser.h"
33 #include "messages/MMDSLoadTargets.h"
34 #include "messages/MMonCommand.h"
35 #include "messages/MGenericMessage.h"
37 #include "include/assert.h"
38 #include "include/str_list.h"
39 #include "include/stringify.h"
40 #include "mds/mdstypes.h"
43 #define dout_subsys ceph_subsys_mon
45 #define dout_prefix _prefix(_dout, mon, get_fsmap())
46 static ostream
& _prefix(std::ostream
*_dout
, Monitor
*mon
, const FSMap
& fsmap
) {
47 return *_dout
<< "mon." << mon
->name
<< "@" << mon
->rank
48 << "(" << mon
->get_state_name()
49 << ").mds e" << fsmap
.get_epoch() << " ";
52 static const string
MDS_METADATA_PREFIX("mds_metadata");
53 static const string
MDS_HEALTH_PREFIX("mds_health");
57 * Specialized implementation of cmd_getval to allow us to parse
58 * out strongly-typedef'd types
60 template<> bool cmd_getval(CephContext
*cct
, const cmdmap_t
& cmdmap
,
61 const std::string
& k
, mds_gid_t
&val
)
63 return cmd_getval(cct
, cmdmap
, k
, (int64_t&)val
);
66 template<> bool cmd_getval(CephContext
*cct
, const cmdmap_t
& cmdmap
,
67 const std::string
& k
, mds_rank_t
&val
)
69 return cmd_getval(cct
, cmdmap
, k
, (int64_t&)val
);
72 template<> bool cmd_getval(CephContext
*cct
, const cmdmap_t
& cmdmap
,
73 const std::string
& k
, MDSMap::DaemonState
&val
)
75 return cmd_getval(cct
, cmdmap
, k
, (int64_t&)val
);
80 void MDSMonitor::print_map(const FSMap
&m
, int dbl
)
82 dout(dbl
) << "print_map\n";
88 void MDSMonitor::create_initial()
90 dout(10) << "create_initial" << dendl
;
93 void MDSMonitor::get_store_prefixes(std::set
<string
>& s
)
95 s
.insert(service_name
);
96 s
.insert(MDS_METADATA_PREFIX
);
97 s
.insert(MDS_HEALTH_PREFIX
);
100 void MDSMonitor::update_from_paxos(bool *need_bootstrap
)
102 version_t version
= get_last_committed();
103 if (version
== get_fsmap().epoch
)
106 dout(10) << __func__
<< " version " << version
107 << ", my e " << get_fsmap().epoch
<< dendl
;
108 assert(version
> get_fsmap().epoch
);
115 int err
= get_version(version
, fsmap_bl
);
118 assert(fsmap_bl
.length() > 0);
119 dout(10) << __func__
<< " got " << version
<< dendl
;
120 PaxosFSMap::decode(fsmap_bl
);
123 dout(4) << "new map" << dendl
;
124 print_map(get_fsmap(), 0);
125 if (!g_conf
->mon_mds_skip_sanity
) {
126 get_fsmap().sanity();
133 void MDSMonitor::init()
135 (void)load_metadata(pending_metadata
);
138 void MDSMonitor::create_pending()
140 auto &fsmap
= PaxosFSMap::create_pending();
142 if (mon
->osdmon()->is_readable()) {
143 const auto &osdmap
= mon
->osdmon()->osdmap
;
144 fsmap
.sanitize([&osdmap
](int64_t pool
){return osdmap
.have_pg_pool(pool
);});
147 dout(10) << "create_pending e" << fsmap
.epoch
<< dendl
;
150 void MDSMonitor::encode_pending(MonitorDBStore::TransactionRef t
)
152 auto &pending
= get_pending_fsmap_writeable();
153 auto &epoch
= pending
.epoch
;
155 dout(10) << "encode_pending e" << epoch
<< dendl
;
157 // print map iff 'debug mon = 30' or higher
158 print_map(get_pending_fsmap(), 30);
159 if (!g_conf
->mon_mds_skip_sanity
) {
163 // Set 'modified' on maps modified this epoch
164 for (auto &p
: pending
.filesystems
) {
165 if (p
.second
->mds_map
.epoch
== epoch
) {
166 p
.second
->mds_map
.modified
= ceph_clock_now();
171 assert(get_last_committed() + 1 == pending
.epoch
);
172 bufferlist pending_bl
;
173 pending
.encode(pending_bl
, mon
->get_quorum_con_features());
175 /* put everything in the transaction */
176 put_version(t
, pending
.epoch
, pending_bl
);
177 put_last_committed(t
, pending
.epoch
);
179 // Encode MDSHealth data
180 for (std::map
<uint64_t, MDSHealth
>::iterator i
= pending_daemon_health
.begin();
181 i
!= pending_daemon_health
.end(); ++i
) {
183 i
->second
.encode(bl
);
184 t
->put(MDS_HEALTH_PREFIX
, stringify(i
->first
), bl
);
187 for (std::set
<uint64_t>::iterator i
= pending_daemon_health_rm
.begin();
188 i
!= pending_daemon_health_rm
.end(); ++i
) {
189 t
->erase(MDS_HEALTH_PREFIX
, stringify(*i
));
191 pending_daemon_health_rm
.clear();
192 remove_from_metadata(t
);
195 health_check_map_t new_checks
;
196 const auto &info_map
= pending
.get_mds_info();
197 for (const auto &i
: info_map
) {
198 const auto &gid
= i
.first
;
199 const auto &info
= i
.second
;
200 if (pending_daemon_health_rm
.count(gid
)) {
204 auto p
= pending_daemon_health
.find(gid
);
205 if (p
!= pending_daemon_health
.end()) {
209 mon
->store
->get(MDS_HEALTH_PREFIX
, stringify(gid
), bl
);
211 derr
<< "Missing health data for MDS " << gid
<< dendl
;
214 bufferlist::iterator bl_i
= bl
.begin();
217 for (const auto &metric
: health
.metrics
) {
218 const int rank
= info
.rank
;
219 health_check_t
*check
= &new_checks
.get_or_add(
220 mds_metric_name(metric
.type
),
222 mds_metric_summary(metric
.type
));
224 ss
<< "mds" << info
.name
<< "(mds." << rank
<< "): " << metric
.message
;
226 for (auto &p
: metric
.metadata
) {
232 ss
<< p
.first
<< ": " << p
.second
;
235 check
->detail
.push_back(ss
.str());
238 pending
.get_health_checks(&new_checks
);
239 for (auto& p
: new_checks
.checks
) {
240 p
.second
.summary
= boost::regex_replace(
242 boost::regex("%num%"),
243 stringify(p
.second
.detail
.size()));
244 p
.second
.summary
= boost::regex_replace(
246 boost::regex("%plurals%"),
247 p
.second
.detail
.size() > 1 ? "s" : "");
248 p
.second
.summary
= boost::regex_replace(
250 boost::regex("%isorare%"),
251 p
.second
.detail
.size() > 1 ? "are" : "is");
252 p
.second
.summary
= boost::regex_replace(
254 boost::regex("%hasorhave%"),
255 p
.second
.detail
.size() > 1 ? "have" : "has");
257 encode_health(new_checks
, t
);
260 version_t
MDSMonitor::get_trim_to()
263 if (g_conf
->mon_mds_force_trim_to
> 0 &&
264 g_conf
->mon_mds_force_trim_to
< (int)get_last_committed()) {
265 floor
= g_conf
->mon_mds_force_trim_to
;
266 dout(10) << __func__
<< " explicit mon_mds_force_trim_to = "
270 unsigned max
= g_conf
->mon_max_mdsmap_epochs
;
271 version_t last
= get_last_committed();
273 if (last
- get_first_committed() > max
&& floor
< last
- max
)
278 void MDSMonitor::update_logger()
280 dout(10) << "update_logger" << dendl
;
282 const auto &fsmap
= get_fsmap();
287 for (const auto &i
: fsmap
.filesystems
) {
288 const MDSMap
&mds_map
= i
.second
->mds_map
;
290 up
+= mds_map
.get_num_up_mds();
291 in
+= mds_map
.get_num_in_mds();
292 failed
+= mds_map
.get_num_failed_mds();
294 mon
->cluster_logger
->set(l_cluster_num_mds_up
, up
);
295 mon
->cluster_logger
->set(l_cluster_num_mds_in
, in
);
296 mon
->cluster_logger
->set(l_cluster_num_mds_failed
, failed
);
297 mon
->cluster_logger
->set(l_cluster_mds_epoch
, fsmap
.get_epoch());
300 bool MDSMonitor::preprocess_query(MonOpRequestRef op
)
302 op
->mark_mdsmon_event(__func__
);
303 PaxosServiceMessage
*m
= static_cast<PaxosServiceMessage
*>(op
->get_req());
304 dout(10) << "preprocess_query " << *m
<< " from " << m
->get_orig_source_inst() << dendl
;
306 switch (m
->get_type()) {
309 return preprocess_beacon(op
);
311 case MSG_MON_COMMAND
:
312 return preprocess_command(op
);
314 case MSG_MDS_OFFLOAD_TARGETS
:
315 return preprocess_offload_targets(op
);
323 void MDSMonitor::_note_beacon(MMDSBeacon
*m
)
325 mds_gid_t gid
= mds_gid_t(m
->get_global_id());
326 version_t seq
= m
->get_seq();
328 dout(15) << "_note_beacon " << *m
<< " noting time" << dendl
;
329 last_beacon
[gid
].stamp
= ceph_clock_now();
330 last_beacon
[gid
].seq
= seq
;
333 bool MDSMonitor::preprocess_beacon(MonOpRequestRef op
)
335 op
->mark_mdsmon_event(__func__
);
336 MMDSBeacon
*m
= static_cast<MMDSBeacon
*>(op
->get_req());
337 MDSMap::DaemonState state
= m
->get_state();
338 mds_gid_t gid
= m
->get_global_id();
339 version_t seq
= m
->get_seq();
340 MDSMap::mds_info_t info
;
341 epoch_t effective_epoch
= 0;
343 const auto &fsmap
= get_working_fsmap();
345 // check privileges, ignore if fails
346 MonSession
*session
= m
->get_session();
348 if (!session
->is_capable("mds", MON_CAP_X
)) {
349 dout(0) << "preprocess_beacon got MMDSBeacon from entity with insufficient privileges "
350 << session
->caps
<< dendl
;
354 if (m
->get_fsid() != mon
->monmap
->fsid
) {
355 dout(0) << "preprocess_beacon on fsid " << m
->get_fsid() << " != " << mon
->monmap
->fsid
<< dendl
;
359 dout(12) << "preprocess_beacon " << *m
360 << " from " << m
->get_orig_source_inst()
361 << " " << m
->get_compat()
364 // make sure the address has a port
365 if (m
->get_orig_source_addr().get_port() == 0) {
366 dout(1) << " ignoring boot message without a port" << dendl
;
371 if (!m
->get_compat().writeable(fsmap
.compat
)) {
372 dout(1) << " mds " << m
->get_source_inst() << " can't write to fsmap " << fsmap
.compat
<< dendl
;
380 // booted, but not in map?
381 if (!fsmap
.gid_exists(gid
)) {
382 if (state
!= MDSMap::STATE_BOOT
) {
383 dout(7) << "mds_beacon " << *m
<< " is not in fsmap (state "
384 << ceph_mds_state_name(state
) << ")" << dendl
;
387 null_map
.epoch
= fsmap
.epoch
;
388 null_map
.compat
= fsmap
.compat
;
389 mon
->send_reply(op
, new MMDSMap(mon
->monmap
->fsid
, &null_map
));
392 return false; // not booted yet.
395 dout(10) << __func__
<< ": GID exists in map: " << gid
<< dendl
;
396 info
= fsmap
.get_info_gid(gid
);
399 if (info
.state_seq
> seq
) {
400 dout(7) << "mds_beacon " << *m
<< " has old seq, ignoring" << dendl
;
404 // Work out the latest epoch that this daemon should have seen
406 fs_cluster_id_t fscid
= fsmap
.mds_roles
.at(gid
);
407 if (fscid
== FS_CLUSTER_ID_NONE
) {
408 effective_epoch
= fsmap
.standby_epochs
.at(gid
);
410 effective_epoch
= fsmap
.get_filesystem(fscid
)->mds_map
.epoch
;
412 if (effective_epoch
!= m
->get_last_epoch_seen()) {
413 dout(10) << "mds_beacon " << *m
414 << " ignoring requested state, because mds hasn't seen latest map" << dendl
;
421 return false; // no longer laggy, need to update map.
423 if (state
== MDSMap::STATE_BOOT
) {
424 // ignore, already booted.
427 // is there a state change here?
428 if (info
.state
!= state
) {
429 // legal state change?
430 if ((info
.state
== MDSMap::STATE_STANDBY
||
431 info
.state
== MDSMap::STATE_STANDBY_REPLAY
) && state
> 0) {
432 dout(10) << "mds_beacon mds can't activate itself (" << ceph_mds_state_name(info
.state
)
433 << " -> " << ceph_mds_state_name(state
) << ")" << dendl
;
437 if ((state
== MDSMap::STATE_STANDBY
|| state
== MDSMap::STATE_STANDBY_REPLAY
)
438 && info
.rank
!= MDS_RANK_NONE
)
440 dout(4) << "mds_beacon MDS can't go back into standby after taking rank: "
441 "held rank " << info
.rank
<< " while requesting state "
442 << ceph_mds_state_name(state
) << dendl
;
450 // Comparing known daemon health with m->get_health()
451 // and return false (i.e. require proposal) if they
452 // do not match, to update our stored
453 if (!(pending_daemon_health
[gid
] == m
->get_health())) {
454 dout(20) << __func__
<< " health metrics for gid " << gid
<< " were updated" << dendl
;
460 // note time and reply
461 assert(effective_epoch
> 0);
464 new MMDSBeacon(mon
->monmap
->fsid
, m
->get_global_id(), m
->get_name(),
465 effective_epoch
, state
, seq
,
466 CEPH_FEATURES_SUPPORTED_DEFAULT
));
470 // I won't reply this beacon, drop it.
475 bool MDSMonitor::preprocess_offload_targets(MonOpRequestRef op
)
477 op
->mark_mdsmon_event(__func__
);
478 MMDSLoadTargets
*m
= static_cast<MMDSLoadTargets
*>(op
->get_req());
479 dout(10) << "preprocess_offload_targets " << *m
<< " from " << m
->get_orig_source() << dendl
;
481 auto &fsmap
= get_working_fsmap();
483 // check privileges, ignore message if fails
484 MonSession
*session
= m
->get_session();
487 if (!session
->is_capable("mds", MON_CAP_X
)) {
488 dout(0) << "preprocess_offload_targets got MMDSLoadTargets from entity with insufficient caps "
489 << session
->caps
<< dendl
;
493 if (fsmap
.gid_exists(m
->global_id
) &&
494 m
->targets
== fsmap
.get_info_gid(m
->global_id
).export_targets
)
504 bool MDSMonitor::prepare_update(MonOpRequestRef op
)
506 op
->mark_mdsmon_event(__func__
);
507 PaxosServiceMessage
*m
= static_cast<PaxosServiceMessage
*>(op
->get_req());
508 dout(7) << "prepare_update " << *m
<< dendl
;
510 switch (m
->get_type()) {
513 return prepare_beacon(op
);
515 case MSG_MON_COMMAND
:
516 return prepare_command(op
);
518 case MSG_MDS_OFFLOAD_TARGETS
:
519 return prepare_offload_targets(op
);
528 bool MDSMonitor::prepare_beacon(MonOpRequestRef op
)
530 op
->mark_mdsmon_event(__func__
);
531 MMDSBeacon
*m
= static_cast<MMDSBeacon
*>(op
->get_req());
532 // -- this is an update --
533 dout(12) << "prepare_beacon " << *m
<< " from " << m
->get_orig_source_inst() << dendl
;
534 entity_addr_t addr
= m
->get_orig_source_inst().addr
;
535 mds_gid_t gid
= m
->get_global_id();
536 MDSMap::DaemonState state
= m
->get_state();
537 version_t seq
= m
->get_seq();
539 auto &pending
= get_pending_fsmap_writeable();
541 dout(20) << __func__
<< " got health from gid " << gid
<< " with " << m
->get_health().metrics
.size() << " metrics." << dendl
;
543 // Calculate deltas of health metrics created and removed
544 // Do this by type rather than MDSHealthMetric equality, because messages can
545 // change a lot when they include e.g. a number of items.
546 const auto &old_health
= pending_daemon_health
[gid
].metrics
;
547 const auto &new_health
= m
->get_health().metrics
;
549 std::set
<mds_metric_t
> old_types
;
550 for (const auto &i
: old_health
) {
551 old_types
.insert(i
.type
);
554 std::set
<mds_metric_t
> new_types
;
555 for (const auto &i
: new_health
) {
556 new_types
.insert(i
.type
);
559 for (const auto &new_metric
: new_health
) {
560 if (old_types
.count(new_metric
.type
) == 0) {
561 dout(10) << "MDS health message (" << m
->get_orig_source_inst().name
562 << "): " << new_metric
.sev
<< " " << new_metric
.message
<< dendl
;
566 // Log the disappearance of health messages at INFO
567 for (const auto &old_metric
: old_health
) {
568 if (new_types
.count(old_metric
.type
) == 0) {
569 mon
->clog
->info() << "MDS health message cleared ("
570 << m
->get_orig_source_inst().name
<< "): " << old_metric
.message
;
575 pending_daemon_health
[gid
] = m
->get_health();
578 if (state
== MDSMap::STATE_BOOT
) {
579 // zap previous instance of this name?
580 if (g_conf
->mds_enforce_unique_name
) {
581 bool failed_mds
= false;
582 while (mds_gid_t existing
= pending
.find_mds_gid_by_name(m
->get_name())) {
583 if (!mon
->osdmon()->is_writeable()) {
584 mon
->osdmon()->wait_for_writeable(op
, new C_RetryMessage(this, op
));
587 const MDSMap::mds_info_t
&existing_info
=
588 pending
.get_info_gid(existing
);
589 mon
->clog
->info() << existing_info
.human_name() << " restarted";
590 fail_mds_gid(existing
);
594 assert(mon
->osdmon()->is_writeable());
595 request_proposal(mon
->osdmon());
599 // Add this daemon to the map
600 if (pending
.mds_roles
.count(gid
) == 0) {
601 MDSMap::mds_info_t new_info
;
602 new_info
.global_id
= gid
;
603 new_info
.name
= m
->get_name();
604 new_info
.addr
= addr
;
605 new_info
.mds_features
= m
->get_mds_features();
606 new_info
.state
= MDSMap::STATE_STANDBY
;
607 new_info
.state_seq
= seq
;
608 new_info
.standby_for_rank
= m
->get_standby_for_rank();
609 new_info
.standby_for_name
= m
->get_standby_for_name();
610 new_info
.standby_for_fscid
= m
->get_standby_for_fscid();
611 new_info
.standby_replay
= m
->get_standby_replay();
612 pending
.insert(new_info
);
615 // Resolve standby_for_name to a rank
616 const MDSMap::mds_info_t
&info
= pending
.get_info_gid(gid
);
617 if (!info
.standby_for_name
.empty()) {
618 const MDSMap::mds_info_t
*leaderinfo
= pending
.find_by_name(
619 info
.standby_for_name
);
620 if (leaderinfo
&& (leaderinfo
->rank
>= 0)) {
621 const auto &fscid
= pending
.mds_roles
.at(leaderinfo
->global_id
);
622 const auto &fs
= pending
.get_filesystem(fscid
);
624 pending
.modify_daemon(gid
, [fscid
, leaderinfo
](
625 MDSMap::mds_info_t
*info
) {
626 info
->standby_for_rank
= leaderinfo
->rank
;
627 info
->standby_for_fscid
= fscid
;
632 // initialize the beacon timer
633 last_beacon
[gid
].stamp
= ceph_clock_now();
634 last_beacon
[gid
].seq
= seq
;
637 if (!pending
.compat
.writeable(m
->get_compat())) {
638 dout(10) << " fsmap " << pending
.compat
639 << " can't write to new mds' " << m
->get_compat()
640 << ", updating fsmap and killing old mds's"
642 pending
.update_compat(m
->get_compat());
645 update_metadata(m
->get_global_id(), m
->get_sys_info());
648 const MDSMap::mds_info_t
&info
= pending
.get_info_gid(gid
);
649 // Old MDS daemons don't mention that they're standby replay until
650 // after they've sent their boot beacon, so update this field.
651 if (info
.standby_replay
!= m
->get_standby_replay()) {
652 pending
.modify_daemon(info
.global_id
, [&m
](
653 MDSMap::mds_info_t
*i
)
655 i
->standby_replay
= m
->get_standby_replay();
659 if (info
.state
== MDSMap::STATE_STOPPING
&& state
!= MDSMap::STATE_STOPPED
) {
660 // we can't transition to any other states from STOPPING
661 dout(0) << "got beacon for MDS in STATE_STOPPING, ignoring requested state change"
668 dout(10) << "prepare_beacon clearing laggy flag on " << addr
<< dendl
;
669 pending
.modify_daemon(info
.global_id
, [](MDSMap::mds_info_t
*info
)
676 dout(10) << "prepare_beacon mds." << info
.rank
677 << " " << ceph_mds_state_name(info
.state
)
678 << " -> " << ceph_mds_state_name(state
)
679 << " standby_for_rank=" << m
->get_standby_for_rank()
681 if (state
== MDSMap::STATE_STOPPED
) {
682 const auto fscid
= pending
.mds_roles
.at(gid
);
683 const auto &fs
= pending
.get_filesystem(fscid
);
685 mon
->clog
->info() << info
.human_name() << " finished "
686 << "deactivating rank " << info
.rank
<< " in filesystem "
687 << fs
->mds_map
.fs_name
<< " (now has "
688 << fs
->mds_map
.get_num_in_mds() - 1 << " ranks)";
690 auto erased
= pending
.stop(gid
);
691 erased
.push_back(gid
);
693 for (const auto &erased_gid
: erased
) {
694 last_beacon
.erase(erased_gid
);
695 if (pending_daemon_health
.count(erased_gid
)) {
696 pending_daemon_health
.erase(erased_gid
);
697 pending_daemon_health_rm
.insert(erased_gid
);
702 } else if (state
== MDSMap::STATE_DAMAGED
) {
703 if (!mon
->osdmon()->is_writeable()) {
704 dout(4) << __func__
<< ": DAMAGED from rank " << info
.rank
705 << " waiting for osdmon writeable to blacklist it" << dendl
;
706 mon
->osdmon()->wait_for_writeable(op
, new C_RetryMessage(this, op
));
710 // Record this MDS rank as damaged, so that other daemons
711 // won't try to run it.
712 dout(4) << __func__
<< ": marking rank "
713 << info
.rank
<< " damaged" << dendl
;
715 utime_t until
= ceph_clock_now();
716 until
+= g_conf
->get_val
<double>("mon_mds_blacklist_interval");
717 const auto blacklist_epoch
= mon
->osdmon()->blacklist(info
.addr
, until
);
718 request_proposal(mon
->osdmon());
719 pending
.damaged(gid
, blacklist_epoch
);
720 last_beacon
.erase(gid
);
722 // Respond to MDS, so that it knows it can continue to shut down
725 mon
->monmap
->fsid
, m
->get_global_id(),
726 m
->get_name(), pending
.get_epoch(), state
, seq
,
727 CEPH_FEATURES_SUPPORTED_DEFAULT
));
728 } else if (state
== MDSMap::STATE_DNE
) {
729 if (!mon
->osdmon()->is_writeable()) {
730 dout(4) << __func__
<< ": DNE from rank " << info
.rank
731 << " waiting for osdmon writeable to blacklist it" << dendl
;
732 mon
->osdmon()->wait_for_writeable(op
, new C_RetryMessage(this, op
));
737 assert(mon
->osdmon()->is_writeable());
738 request_proposal(mon
->osdmon());
740 // Respond to MDS, so that it knows it can continue to shut down
743 mon
->monmap
->fsid
, m
->get_global_id(),
744 m
->get_name(), pending
.get_epoch(), state
, seq
,
745 CEPH_FEATURES_SUPPORTED_DEFAULT
));
746 } else if (info
.state
== MDSMap::STATE_STANDBY
&& state
!= info
.state
) {
747 // Standby daemons should never modify their own
748 // state. Reject any attempts to do so.
749 derr
<< "standby " << gid
<< " attempted to change state to "
750 << ceph_mds_state_name(state
) << ", rejecting" << dendl
;
752 } else if (info
.state
!= MDSMap::STATE_STANDBY
&& state
!= info
.state
&&
753 !MDSMap::state_transition_valid(info
.state
, state
)) {
754 // Validate state transitions for daemons that hold a rank
755 derr
<< "daemon " << gid
<< " (rank " << info
.rank
<< ") "
756 << "reported invalid state transition "
757 << ceph_mds_state_name(info
.state
) << " -> "
758 << ceph_mds_state_name(state
) << dendl
;
761 if (info
.state
!= MDSMap::STATE_ACTIVE
&& state
== MDSMap::STATE_ACTIVE
) {
762 const auto &fscid
= pending
.mds_roles
.at(gid
);
763 const auto &fs
= pending
.get_filesystem(fscid
);
764 mon
->clog
->info() << info
.human_name() << " is now active in "
765 << "filesystem " << fs
->mds_map
.fs_name
<< " as rank "
769 // Made it through special cases and validations, record the
770 // daemon's reported state to the FSMap.
771 pending
.modify_daemon(gid
, [state
, seq
](MDSMap::mds_info_t
*info
) {
773 info
->state_seq
= seq
;
778 dout(7) << "prepare_beacon pending map now:" << dendl
;
781 wait_for_finished_proposal(op
, new FunctionContext([op
, this](int r
){
783 _updated(op
); // success
784 else if (r
== -ECANCELED
) {
787 dispatch(op
); // try again
794 bool MDSMonitor::prepare_offload_targets(MonOpRequestRef op
)
796 auto &pending
= get_pending_fsmap_writeable();
798 op
->mark_mdsmon_event(__func__
);
799 MMDSLoadTargets
*m
= static_cast<MMDSLoadTargets
*>(op
->get_req());
800 mds_gid_t gid
= m
->global_id
;
801 if (pending
.gid_has_rank(gid
)) {
802 dout(10) << "prepare_offload_targets " << gid
<< " " << m
->targets
<< dendl
;
803 pending
.update_export_targets(gid
, m
->targets
);
805 dout(10) << "prepare_offload_targets " << gid
<< " not in map" << dendl
;
810 bool MDSMonitor::should_propose(double& delay
)
812 // delegate to PaxosService to assess whether we should propose
813 return PaxosService::should_propose(delay
);
816 void MDSMonitor::_updated(MonOpRequestRef op
)
818 const auto &fsmap
= get_fsmap();
819 op
->mark_mdsmon_event(__func__
);
820 MMDSBeacon
*m
= static_cast<MMDSBeacon
*>(op
->get_req());
821 dout(10) << "_updated " << m
->get_orig_source() << " " << *m
<< dendl
;
822 mon
->clog
->debug() << m
->get_orig_source_inst() << " "
823 << ceph_mds_state_name(m
->get_state());
825 if (m
->get_state() == MDSMap::STATE_STOPPED
) {
826 // send the map manually (they're out of the map, so they won't get it automatic)
828 null_map
.epoch
= fsmap
.epoch
;
829 null_map
.compat
= fsmap
.compat
;
830 mon
->send_reply(op
, new MMDSMap(mon
->monmap
->fsid
, &null_map
));
832 mon
->send_reply(op
, new MMDSBeacon(mon
->monmap
->fsid
,
838 CEPH_FEATURES_SUPPORTED_DEFAULT
));
842 void MDSMonitor::on_active()
848 mon
->clog
->debug() << "fsmap " << get_fsmap();
852 void MDSMonitor::get_health(list
<pair
<health_status_t
, string
> >& summary
,
853 list
<pair
<health_status_t
, string
> > *detail
,
854 CephContext
* cct
) const
856 const auto &fsmap
= get_fsmap();
858 fsmap
.get_health(summary
, detail
);
860 // For each MDS GID...
861 const auto &info_map
= fsmap
.get_mds_info();
862 for (const auto &i
: info_map
) {
863 const auto &gid
= i
.first
;
864 const auto &info
= i
.second
;
868 mon
->store
->get(MDS_HEALTH_PREFIX
, stringify(gid
), bl
);
870 derr
<< "Missing health data for MDS " << gid
<< dendl
;
874 bufferlist::iterator bl_i
= bl
.begin();
877 for (const auto &metric
: health
.metrics
) {
878 const int rank
= info
.rank
;
879 std::ostringstream message
;
880 message
<< "mds" << rank
<< ": " << metric
.message
;
881 summary
.push_back(std::make_pair(metric
.sev
, message
.str()));
884 // There is no way for us to clealy associate detail entries with summary entries (#7192), so
885 // we duplicate the summary message in the detail string and tag the metadata on.
886 std::ostringstream detail_message
;
887 detail_message
<< message
.str();
888 if (metric
.metadata
.size()) {
889 detail_message
<< "(";
890 auto k
= metric
.metadata
.begin();
891 while (k
!= metric
.metadata
.end()) {
892 detail_message
<< k
->first
<< ": " << k
->second
;
893 if (boost::next(k
) != metric
.metadata
.end()) {
894 detail_message
<< ", ";
898 detail_message
<< ")";
900 detail
->push_back(std::make_pair(metric
.sev
, detail_message
.str()));
906 void MDSMonitor::dump_info(Formatter
*f
)
908 f
->open_object_section("fsmap");
912 f
->dump_unsigned("mdsmap_first_committed", get_first_committed());
913 f
->dump_unsigned("mdsmap_last_committed", get_last_committed());
916 bool MDSMonitor::preprocess_command(MonOpRequestRef op
)
918 op
->mark_mdsmon_event(__func__
);
919 MMonCommand
*m
= static_cast<MMonCommand
*>(op
->get_req());
924 map
<string
, cmd_vartype
> cmdmap
;
925 const auto &fsmap
= get_working_fsmap();
927 if (!cmdmap_from_json(m
->cmd
, &cmdmap
, ss
)) {
928 // ss has reason for failure
929 string rs
= ss
.str();
930 mon
->reply_command(op
, -EINVAL
, rs
, rdata
, get_last_committed());
935 cmd_getval(g_ceph_context
, cmdmap
, "prefix", prefix
);
937 cmd_getval(g_ceph_context
, cmdmap
, "format", format
, string("plain"));
938 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
));
940 MonSession
*session
= m
->get_session();
942 mon
->reply_command(op
, -EACCES
, "access denied", rdata
, get_last_committed());
946 if (prefix
== "mds stat") {
948 f
->open_object_section("mds_stat");
956 } else if (prefix
== "mds dump") {
960 const FSMap
*fsmapp
= &get_fsmap();
962 if (cmd_getval(g_ceph_context
, cmdmap
, "epoch", epocharg
)) {
965 int err
= get_version(epoch
, b
);
966 if (err
== -ENOENT
) {
978 const MDSMap
*mdsmapp
= nullptr;
980 blank
.epoch
= fsmapp
->epoch
;
981 if (fsmapp
->legacy_client_fscid
!= FS_CLUSTER_ID_NONE
) {
982 mdsmapp
= &fsmapp
->filesystems
.at(fsmapp
->legacy_client_fscid
)->mds_map
;
987 f
->open_object_section("mdsmap");
988 mdsmapp
->dump(f
.get());
998 ss
<< "dumped fsmap epoch " << fsmapp
->get_epoch();
999 } else if (prefix
== "fs dump") {
1003 const FSMap
*fsmapp
= &get_fsmap();
1005 if (cmd_getval(g_ceph_context
, cmdmap
, "epoch", epocharg
)) {
1008 int err
= get_version(epoch
, b
);
1009 if (err
== -ENOENT
) {
1022 f
->open_object_section("fsmap");
1023 fsmapp
->dump(f
.get());
1033 ss
<< "dumped fsmap epoch " << fsmapp
->get_epoch();
1034 } else if (prefix
== "mds metadata") {
1036 f
.reset(Formatter::create("json-pretty"));
1039 bool all
= !cmd_getval(g_ceph_context
, cmdmap
, "who", who
);
1040 dout(1) << "all = " << all
<< dendl
;
1043 // Dump all MDSs' metadata
1044 const auto all_info
= fsmap
.get_mds_info();
1046 f
->open_array_section("mds_metadata");
1047 for(const auto &i
: all_info
) {
1048 const auto &info
= i
.second
;
1050 f
->open_object_section("mds");
1051 f
->dump_string("name", info
.name
);
1052 std::ostringstream get_err
;
1053 r
= dump_metadata(info
.name
, f
.get(), get_err
);
1054 if (r
== -EINVAL
|| r
== -ENOENT
) {
1055 // Drop error, list what metadata we do have
1056 dout(1) << get_err
.str() << dendl
;
1058 } else if (r
!= 0) {
1059 derr
<< "Unexpected error reading metadata: " << cpp_strerror(r
)
1061 ss
<< get_err
.str();
1069 // Dump a single daemon's metadata
1070 f
->open_object_section("mds_metadata");
1071 r
= dump_metadata(who
, f
.get(), ss
);
1075 } else if (prefix
== "mds versions") {
1077 f
.reset(Formatter::create("json-pretty"));
1078 count_metadata("ceph_version", f
.get());
1081 } else if (prefix
== "mds count-metadata") {
1083 f
.reset(Formatter::create("json-pretty"));
1085 cmd_getval(g_ceph_context
, cmdmap
, "property", field
);
1086 count_metadata(field
, f
.get());
1089 } else if (prefix
== "mds getmap") {
1093 if (cmd_getval(g_ceph_context
, cmdmap
, "epoch", epocharg
)) {
1095 int err
= get_version(e
, b
);
1096 if (err
== -ENOENT
) {
1103 mm
.encode(rdata
, m
->get_connection()->get_features());
1104 ss
<< "got fsmap epoch " << mm
.get_epoch();
1108 fsmap
.encode(rdata
, m
->get_connection()->get_features());
1109 ss
<< "got fsmap epoch " << fsmap
.get_epoch();
1112 } else if (prefix
== "mds compat show") {
1114 f
->open_object_section("mds_compat");
1115 fsmap
.compat
.dump(f
.get());
1122 } else if (prefix
== "fs get") {
1124 cmd_getval(g_ceph_context
, cmdmap
, "fs_name", fs_name
);
1125 const auto &fs
= fsmap
.get_filesystem(fs_name
);
1126 if (fs
== nullptr) {
1127 ss
<< "filesystem '" << fs_name
<< "' not found";
1131 f
->open_object_section("filesystem");
1141 } else if (prefix
== "fs ls") {
1143 f
->open_array_section("filesystems");
1145 for (const auto &p
: fsmap
.filesystems
) {
1146 const auto &fs
= p
.second
;
1147 f
->open_object_section("filesystem");
1149 const MDSMap
&mds_map
= fs
->mds_map
;
1150 f
->dump_string("name", mds_map
.fs_name
);
1151 /* Output both the names and IDs of pools, for use by
1152 * humans and machines respectively */
1153 f
->dump_string("metadata_pool", mon
->osdmon()->osdmap
.get_pool_name(
1154 mds_map
.metadata_pool
));
1155 f
->dump_int("metadata_pool_id", mds_map
.metadata_pool
);
1156 f
->open_array_section("data_pool_ids");
1158 for (auto dpi
= mds_map
.data_pools
.begin();
1159 dpi
!= mds_map
.data_pools
.end(); ++dpi
) {
1160 f
->dump_int("data_pool_id", *dpi
);
1165 f
->open_array_section("data_pools");
1167 for (auto dpi
= mds_map
.data_pools
.begin();
1168 dpi
!= mds_map
.data_pools
.end(); ++dpi
) {
1169 const auto &name
= mon
->osdmon()->osdmap
.get_pool_name(
1171 f
->dump_string("data_pool", name
);
1183 for (const auto &p
: fsmap
.filesystems
) {
1184 const auto &fs
= p
.second
;
1185 const MDSMap
&mds_map
= fs
->mds_map
;
1186 const string
&md_pool_name
= mon
->osdmon()->osdmap
.get_pool_name(
1187 mds_map
.metadata_pool
);
1189 ds
<< "name: " << mds_map
.fs_name
<< ", metadata pool: "
1190 << md_pool_name
<< ", data pools: [";
1191 for (auto dpi
: mds_map
.data_pools
) {
1192 const string
&pool_name
= mon
->osdmon()->osdmap
.get_pool_name(dpi
);
1193 ds
<< pool_name
<< " ";
1195 ds
<< "]" << std::endl
;
1198 if (fsmap
.filesystems
.empty()) {
1199 ds
<< "No filesystems enabled" << std::endl
;
1210 mon
->reply_command(op
, r
, rs
, rdata
, get_last_committed());
1216 bool MDSMonitor::fail_mds_gid(mds_gid_t gid
)
1218 auto &pending
= get_pending_fsmap_writeable();
1220 const MDSMap::mds_info_t
&info
= pending
.get_info_gid(gid
);
1221 dout(10) << "fail_mds_gid " << gid
<< " mds." << info
.name
<< " role " << info
.rank
<< dendl
;
1223 epoch_t blacklist_epoch
= 0;
1224 if (info
.rank
>= 0 && info
.state
!= MDSMap::STATE_STANDBY_REPLAY
) {
1225 utime_t until
= ceph_clock_now();
1226 until
+= g_conf
->get_val
<double>("mon_mds_blacklist_interval");
1227 blacklist_epoch
= mon
->osdmon()->blacklist(info
.addr
, until
);
1230 pending
.erase(gid
, blacklist_epoch
);
1231 last_beacon
.erase(gid
);
1232 if (pending_daemon_health
.count(gid
)) {
1233 pending_daemon_health
.erase(gid
);
1234 pending_daemon_health_rm
.insert(gid
);
1237 return blacklist_epoch
!= 0;
1240 mds_gid_t
MDSMonitor::gid_from_arg(const std::string
& arg
, std::ostream
&ss
)
1242 const auto &fsmap
= get_working_fsmap();
1244 // Try parsing as a role
1246 std::ostringstream ignore_err
; // Don't spam 'ss' with parse_role errors
1247 int r
= parse_role(arg
, &role
, ignore_err
);
1249 // See if a GID is assigned to this role
1250 const auto &fs
= fsmap
.get_filesystem(role
.fscid
);
1251 assert(fs
!= nullptr); // parse_role ensures it exists
1252 if (fs
->mds_map
.is_up(role
.rank
)) {
1253 dout(10) << __func__
<< ": validated rank/GID " << role
1254 << " as a rank" << dendl
;
1255 return fs
->mds_map
.get_mds_info(role
.rank
).global_id
;
1259 // Try parsing as a gid
1261 unsigned long long maybe_gid
= strict_strtoll(arg
.c_str(), 10, &err
);
1263 // Not a role or a GID, try as a daemon name
1264 const MDSMap::mds_info_t
*mds_info
= fsmap
.find_by_name(arg
);
1266 ss
<< "MDS named '" << arg
1267 << "' does not exist, or is not up";
1268 return MDS_GID_NONE
;
1270 dout(10) << __func__
<< ": resolved MDS name '" << arg
1271 << "' to GID " << mds_info
->global_id
<< dendl
;
1272 return mds_info
->global_id
;
1274 // Not a role, but parses as a an integer, might be a GID
1275 dout(10) << __func__
<< ": treating MDS reference '" << arg
1276 << "' as an integer " << maybe_gid
<< dendl
;
1278 if (fsmap
.gid_exists(mds_gid_t(maybe_gid
))) {
1279 return mds_gid_t(maybe_gid
);
1283 dout(1) << __func__
<< ": rank/GID " << arg
1284 << " not a existent rank or GID" << dendl
;
1285 return MDS_GID_NONE
;
1288 int MDSMonitor::fail_mds(std::ostream
&ss
, const std::string
&arg
,
1289 MDSMap::mds_info_t
*failed_info
)
1291 assert(failed_info
!= nullptr);
1293 mds_gid_t gid
= gid_from_arg(arg
, ss
);
1294 if (gid
== MDS_GID_NONE
) {
1297 if (!mon
->osdmon()->is_writeable()) {
1301 // Take a copy of the info before removing the MDS from the map,
1302 // so that the caller knows which mds (if any) they ended up removing.
1303 *failed_info
= get_pending_fsmap().get_info_gid(gid
);
1306 ss
<< "failed mds gid " << gid
;
1307 assert(mon
->osdmon()->is_writeable());
1308 request_proposal(mon
->osdmon());
1312 bool MDSMonitor::prepare_command(MonOpRequestRef op
)
1314 op
->mark_mdsmon_event(__func__
);
1315 MMonCommand
*m
= static_cast<MMonCommand
*>(op
->get_req());
1320 map
<string
, cmd_vartype
> cmdmap
;
1321 if (!cmdmap_from_json(m
->cmd
, &cmdmap
, ss
)) {
1322 string rs
= ss
.str();
1323 mon
->reply_command(op
, -EINVAL
, rs
, rdata
, get_last_committed());
1328 cmd_getval(g_ceph_context
, cmdmap
, "prefix", prefix
);
1330 /* Refuse access if message not associated with a valid session */
1331 MonSession
*session
= m
->get_session();
1333 mon
->reply_command(op
, -EACCES
, "access denied", rdata
, get_last_committed());
1337 auto &pending
= get_pending_fsmap_writeable();
1339 bool batched_propose
= false;
1340 for (const auto &h
: handlers
) {
1341 if (h
->can_handle(prefix
)) {
1342 batched_propose
= h
->batched_propose();
1343 if (batched_propose
) {
1346 r
= h
->handle(mon
, pending
, op
, cmdmap
, ss
);
1347 if (batched_propose
) {
1352 // message has been enqueued for retry; return.
1353 dout(4) << __func__
<< " enqueue for retry by prepare_command" << dendl
;
1357 // On successful updates, print the updated map
1360 // Successful or not, we're done: respond.
1366 r
= filesystem_command(op
, prefix
, cmdmap
, ss
);
1369 } else if (r
== -EAGAIN
) {
1370 // Do not reply, the message has been enqueued for retry
1371 dout(4) << __func__
<< " enqueue for retry by filesystem_command" << dendl
;
1373 } else if (r
!= -ENOSYS
) {
1377 // Only handle legacy commands if there is a filesystem configured
1378 if (pending
.legacy_client_fscid
== FS_CLUSTER_ID_NONE
) {
1379 if (pending
.filesystems
.size() == 0) {
1380 ss
<< "No filesystem configured: use `ceph fs new` to create a filesystem";
1382 ss
<< "No filesystem set for use with legacy commands";
1388 r
= legacy_filesystem_command(op
, prefix
, cmdmap
, ss
);
1390 if (r
== -ENOSYS
&& ss
.str().empty()) {
1391 ss
<< "unrecognized command";
1395 dout(4) << __func__
<< " done, r=" << r
<< dendl
;
1396 /* Compose response */
1401 // success.. delay reply
1402 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, r
, rs
,
1403 get_last_committed() + 1));
1404 if (batched_propose
) {
1405 force_immediate_propose();
1409 // reply immediately
1410 mon
->reply_command(op
, r
, rs
, rdata
, get_last_committed());
1417 * Given one of the following forms:
1422 * Parse into a mds_role_t. The rank-only form is only valid
1423 * if legacy_client_ns is set.
1425 int MDSMonitor::parse_role(
1426 const std::string
&role_str
,
1430 return get_working_fsmap().parse_role(role_str
, role
, ss
);
1433 int MDSMonitor::filesystem_command(
1435 std::string
const &prefix
,
1436 map
<string
, cmd_vartype
> &cmdmap
,
1437 std::stringstream
&ss
)
1439 dout(4) << __func__
<< " prefix='" << prefix
<< "'" << dendl
;
1440 op
->mark_mdsmon_event(__func__
);
1443 cmd_getval(g_ceph_context
, cmdmap
, "who", whostr
);
1445 auto &pending
= get_pending_fsmap_writeable();
1446 if (prefix
== "mds stop" ||
1447 prefix
== "mds deactivate") {
1449 r
= parse_role(whostr
, &role
, ss
);
1453 const auto &fs
= pending
.get_filesystem(role
.fscid
);
1455 if (!fs
->mds_map
.is_active(role
.rank
)) {
1457 ss
<< "mds." << role
<< " not active ("
1458 << ceph_mds_state_name(fs
->mds_map
.get_state(role
.rank
)) << ")";
1459 } else if (fs
->mds_map
.get_root() == role
.rank
||
1460 fs
->mds_map
.get_tableserver() == role
.rank
) {
1462 ss
<< "can't tell the root (" << fs
->mds_map
.get_root()
1463 << ") or tableserver (" << fs
->mds_map
.get_tableserver()
1464 << ") to deactivate";
1465 } else if (role
.rank
!= fs
->mds_map
.get_last_in_mds()) {
1467 ss
<< "mds." << role
<< " doesn't have the max rank ("
1468 << fs
->mds_map
.get_last_in_mds() << ")";
1469 } else if (fs
->mds_map
.get_num_in_mds() <= size_t(fs
->mds_map
.get_max_mds())) {
1471 ss
<< "must decrease max_mds or else MDS will immediately reactivate";
1474 mds_gid_t gid
= fs
->mds_map
.up
.at(role
.rank
);
1475 ss
<< "telling mds." << role
<< " "
1476 << pending
.get_info_gid(gid
).addr
<< " to deactivate";
1478 pending
.modify_daemon(gid
, [](MDSMap::mds_info_t
*info
) {
1479 info
->state
= MDSMap::STATE_STOPPING
;
1482 } else if (prefix
== "mds set_state") {
1484 if (!cmd_getval(g_ceph_context
, cmdmap
, "gid", gid
)) {
1485 ss
<< "error parsing 'gid' value '"
1486 << cmd_vartype_stringify(cmdmap
["gid"]) << "'";
1489 MDSMap::DaemonState state
;
1490 if (!cmd_getval(g_ceph_context
, cmdmap
, "state", state
)) {
1491 ss
<< "error parsing 'state' string value '"
1492 << cmd_vartype_stringify(cmdmap
["state"]) << "'";
1495 if (pending
.gid_exists(gid
)) {
1496 pending
.modify_daemon(gid
, [state
](MDSMap::mds_info_t
*info
) {
1497 info
->state
= state
;
1499 ss
<< "set mds gid " << gid
<< " to state " << state
<< " "
1500 << ceph_mds_state_name(state
);
1503 } else if (prefix
== "mds fail") {
1505 cmd_getval(g_ceph_context
, cmdmap
, "who", who
);
1507 MDSMap::mds_info_t failed_info
;
1508 r
= fail_mds(ss
, who
, &failed_info
);
1509 if (r
< 0 && r
== -EAGAIN
) {
1510 mon
->osdmon()->wait_for_writeable(op
, new C_RetryMessage(this, op
));
1511 return -EAGAIN
; // don't propose yet; wait for message to be retried
1512 } else if (r
== 0) {
1513 // Only log if we really did something (not when was already gone)
1514 if (failed_info
.global_id
!= MDS_GID_NONE
) {
1515 mon
->clog
->info() << failed_info
.human_name() << " marked failed by "
1516 << op
->get_session()->entity_name
;
1519 } else if (prefix
== "mds rm") {
1521 if (!cmd_getval(g_ceph_context
, cmdmap
, "gid", gid
)) {
1522 ss
<< "error parsing 'gid' value '"
1523 << cmd_vartype_stringify(cmdmap
["gid"]) << "'";
1526 if (!pending
.gid_exists(gid
)) {
1527 ss
<< "mds gid " << gid
<< " dne";
1530 const auto &info
= pending
.get_info_gid(gid
);
1531 MDSMap::DaemonState state
= info
.state
;
1533 ss
<< "cannot remove active mds." << info
.name
1534 << " rank " << info
.rank
;
1537 pending
.erase(gid
, {});
1538 ss
<< "removed mds gid " << gid
;
1542 } else if (prefix
== "mds rmfailed") {
1544 if (!cmd_getval(g_ceph_context
, cmdmap
, "confirm", confirm
) ||
1545 confirm
!= "--yes-i-really-mean-it") {
1546 ss
<< "WARNING: this can make your filesystem inaccessible! "
1547 "Add --yes-i-really-mean-it if you are sure you wish to continue.";
1551 std::string role_str
;
1552 cmd_getval(g_ceph_context
, cmdmap
, "who", role_str
);
1554 int r
= parse_role(role_str
, &role
, ss
);
1556 ss
<< "invalid role '" << role_str
<< "'";
1560 pending
.modify_filesystem(
1562 [role
](std::shared_ptr
<Filesystem
> fs
)
1564 fs
->mds_map
.failed
.erase(role
.rank
);
1567 ss
<< "removed failed mds." << role
;
1569 } else if (prefix
== "mds compat rm_compat") {
1571 if (!cmd_getval(g_ceph_context
, cmdmap
, "feature", f
)) {
1572 ss
<< "error parsing feature value '"
1573 << cmd_vartype_stringify(cmdmap
["feature"]) << "'";
1576 if (pending
.compat
.compat
.contains(f
)) {
1577 ss
<< "removing compat feature " << f
;
1578 CompatSet modified
= pending
.compat
;
1579 modified
.compat
.remove(f
);
1580 pending
.update_compat(modified
);
1582 ss
<< "compat feature " << f
<< " not present in " << pending
.compat
;
1585 } else if (prefix
== "mds compat rm_incompat") {
1587 if (!cmd_getval(g_ceph_context
, cmdmap
, "feature", f
)) {
1588 ss
<< "error parsing feature value '"
1589 << cmd_vartype_stringify(cmdmap
["feature"]) << "'";
1592 if (pending
.compat
.incompat
.contains(f
)) {
1593 ss
<< "removing incompat feature " << f
;
1594 CompatSet modified
= pending
.compat
;
1595 modified
.incompat
.remove(f
);
1596 pending
.update_compat(modified
);
1598 ss
<< "incompat feature " << f
<< " not present in " << pending
.compat
;
1601 } else if (prefix
== "mds repaired") {
1602 std::string role_str
;
1603 cmd_getval(g_ceph_context
, cmdmap
, "rank", role_str
);
1605 r
= parse_role(role_str
, &role
, ss
);
1610 bool modified
= pending
.undamaged(role
.fscid
, role
.rank
);
1612 dout(4) << "repaired: restoring rank " << role
<< dendl
;
1614 dout(4) << "repaired: no-op on rank " << role
<< dendl
;
1626 * Helper to legacy_filesystem_command
1628 void MDSMonitor::modify_legacy_filesystem(
1629 std::function
<void(std::shared_ptr
<Filesystem
> )> fn
)
1631 auto &pending_fsmap
= get_pending_fsmap_writeable();
1632 pending_fsmap
.modify_filesystem(
1633 pending_fsmap
.legacy_client_fscid
,
1641 * Handle a command that affects the filesystem (i.e. a filesystem
1642 * must exist for the command to act upon).
1644 * @retval 0 Command was successfully handled and has side effects
1645 * @retval -EAGAIN Messages has been requeued for retry
1646 * @retval -ENOSYS Unknown command
1647 * @retval < 0 An error has occurred; **ss** may have been set.
1649 int MDSMonitor::legacy_filesystem_command(
1651 std::string
const &prefix
,
1652 map
<string
, cmd_vartype
> &cmdmap
,
1653 std::stringstream
&ss
)
1655 dout(4) << __func__
<< " prefix='" << prefix
<< "'" << dendl
;
1656 op
->mark_mdsmon_event(__func__
);
1659 cmd_getval(g_ceph_context
, cmdmap
, "who", whostr
);
1661 auto &pending_fsmap
= get_pending_fsmap_writeable();
1663 assert (pending_fsmap
.legacy_client_fscid
!= FS_CLUSTER_ID_NONE
);
1665 if (prefix
== "mds set_max_mds") {
1666 // NOTE: deprecated by "fs set max_mds"
1668 if (!cmd_getval(g_ceph_context
, cmdmap
, "maxmds", maxmds
) || maxmds
<= 0) {
1672 const MDSMap
& mdsmap
=
1673 pending_fsmap
.filesystems
.at(pending_fsmap
.legacy_client_fscid
)->mds_map
;
1675 if (!mdsmap
.allows_multimds() &&
1676 maxmds
> mdsmap
.get_max_mds() &&
1678 ss
<< "multi-MDS clusters are not enabled; set 'allow_multimds' to enable";
1682 if (maxmds
> MAX_MDS
) {
1683 ss
<< "may not have more than " << MAX_MDS
<< " MDS ranks";
1687 modify_legacy_filesystem(
1688 [maxmds
](std::shared_ptr
<Filesystem
> fs
)
1690 fs
->mds_map
.set_max_mds(maxmds
);
1694 ss
<< "max_mds = " << maxmds
;
1695 } else if (prefix
== "mds cluster_down") {
1696 // NOTE: deprecated by "fs set cluster_down"
1697 modify_legacy_filesystem(
1698 [](std::shared_ptr
<Filesystem
> fs
)
1700 fs
->mds_map
.set_flag(CEPH_MDSMAP_DOWN
);
1702 ss
<< "marked fsmap DOWN";
1704 } else if (prefix
== "mds cluster_up") {
1705 // NOTE: deprecated by "fs set cluster_up"
1706 modify_legacy_filesystem(
1707 [](std::shared_ptr
<Filesystem
> fs
)
1709 fs
->mds_map
.clear_flag(CEPH_MDSMAP_DOWN
);
1711 ss
<< "unmarked fsmap DOWN";
1721 void MDSMonitor::check_subs()
1723 std::list
<std::string
> types
;
1725 // Subscriptions may be to "mdsmap" (MDS and legacy clients),
1726 // "mdsmap.<namespace>", or to "fsmap" for the full state of all
1727 // filesystems. Build a list of all the types we service
1728 // subscriptions for.
1729 types
.push_back("fsmap");
1730 types
.push_back("fsmap.user");
1731 types
.push_back("mdsmap");
1732 for (const auto &p
: get_fsmap().filesystems
) {
1733 const auto &fscid
= p
.first
;
1734 std::ostringstream oss
;
1735 oss
<< "mdsmap." << fscid
;
1736 types
.push_back(oss
.str());
1739 for (const auto &type
: types
) {
1740 if (mon
->session_map
.subs
.count(type
) == 0)
1742 xlist
<Subscription
*>::iterator p
= mon
->session_map
.subs
[type
]->begin();
1744 Subscription
*sub
= *p
;
1752 void MDSMonitor::check_sub(Subscription
*sub
)
1754 dout(20) << __func__
<< ": " << sub
->type
<< dendl
;
1756 const auto &fsmap
= get_fsmap();
1758 if (sub
->type
== "fsmap") {
1759 if (sub
->next
<= fsmap
.get_epoch()) {
1760 sub
->session
->con
->send_message(new MFSMap(mon
->monmap
->fsid
, fsmap
));
1762 mon
->session_map
.remove_sub(sub
);
1764 sub
->next
= fsmap
.get_epoch() + 1;
1767 } else if (sub
->type
== "fsmap.user") {
1768 if (sub
->next
<= fsmap
.get_epoch()) {
1770 fsmap_u
.epoch
= fsmap
.get_epoch();
1771 fsmap_u
.legacy_client_fscid
= fsmap
.legacy_client_fscid
;
1772 for (const auto &p
: fsmap
.filesystems
) {
1773 FSMapUser::fs_info_t
& fs_info
= fsmap_u
.filesystems
[p
.second
->fscid
];
1774 fs_info
.cid
= p
.second
->fscid
;
1775 fs_info
.name
= p
.second
->mds_map
.fs_name
;
1777 sub
->session
->con
->send_message(new MFSMapUser(mon
->monmap
->fsid
, fsmap_u
));
1779 mon
->session_map
.remove_sub(sub
);
1781 sub
->next
= fsmap
.get_epoch() + 1;
1784 } else if (sub
->type
.compare(0, 6, "mdsmap") == 0) {
1785 if (sub
->next
> fsmap
.get_epoch()) {
1789 const bool is_mds
= sub
->session
->inst
.name
.is_mds();
1790 mds_gid_t mds_gid
= MDS_GID_NONE
;
1791 fs_cluster_id_t fscid
= FS_CLUSTER_ID_NONE
;
1793 // What (if any) namespace are you assigned to?
1794 auto mds_info
= fsmap
.get_mds_info();
1795 for (const auto &i
: mds_info
) {
1796 if (i
.second
.addr
== sub
->session
->inst
.addr
) {
1798 fscid
= fsmap
.mds_roles
.at(mds_gid
);
1802 // You're a client. Did you request a particular
1804 if (sub
->type
.find("mdsmap.") == 0) {
1805 auto namespace_id_str
= sub
->type
.substr(std::string("mdsmap.").size());
1806 dout(10) << __func__
<< ": namespace_id " << namespace_id_str
<< dendl
;
1808 fscid
= strict_strtoll(namespace_id_str
.c_str(), 10, &err
);
1810 // Client asked for a non-existent namespace, send them nothing
1811 dout(1) << "Invalid client subscription '" << sub
->type
1815 if (fsmap
.filesystems
.count(fscid
) == 0) {
1816 // Client asked for a non-existent namespace, send them nothing
1817 // TODO: something more graceful for when a client has a filesystem
1818 // mounted, and the fileysstem is deleted. Add a "shut down you fool"
1820 dout(1) << "Client subscribed to non-existent namespace '" <<
1821 fscid
<< "'" << dendl
;
1825 // Unqualified request for "mdsmap": give it the one marked
1826 // for use by legacy clients.
1827 if (fsmap
.legacy_client_fscid
!= FS_CLUSTER_ID_NONE
) {
1828 fscid
= fsmap
.legacy_client_fscid
;
1830 dout(1) << "Client subscribed for legacy filesystem but "
1831 "none is configured" << dendl
;
1836 dout(10) << __func__
<< ": is_mds=" << is_mds
<< ", fscid= " << fscid
<< dendl
;
1838 // Work out the effective latest epoch
1839 const MDSMap
*mds_map
= nullptr;
1841 null_map
.compat
= fsmap
.compat
;
1842 if (fscid
== FS_CLUSTER_ID_NONE
) {
1843 // For a client, we should have already dropped out
1846 auto it
= fsmap
.standby_daemons
.find(mds_gid
);
1847 if (it
!= fsmap
.standby_daemons
.end()) {
1848 // For an MDS, we need to feed it an MDSMap with its own state in
1849 null_map
.mds_info
[mds_gid
] = it
->second
;
1850 null_map
.epoch
= fsmap
.standby_epochs
.at(mds_gid
);
1852 null_map
.epoch
= fsmap
.epoch
;
1854 mds_map
= &null_map
;
1856 // Check the effective epoch
1857 mds_map
= &fsmap
.get_filesystem(fscid
)->mds_map
;
1860 assert(mds_map
!= nullptr);
1861 dout(10) << __func__
<< " selected MDS map epoch " <<
1862 mds_map
->epoch
<< " for namespace " << fscid
<< " for subscriber "
1863 << sub
->session
->inst
.name
<< " who wants epoch " << sub
->next
<< dendl
;
1865 if (sub
->next
> mds_map
->epoch
) {
1868 auto msg
= new MMDSMap(mon
->monmap
->fsid
, mds_map
);
1870 sub
->session
->con
->send_message(msg
);
1872 mon
->session_map
.remove_sub(sub
);
1874 sub
->next
= mds_map
->get_epoch() + 1;
1880 void MDSMonitor::update_metadata(mds_gid_t gid
,
1881 const map
<string
, string
>& metadata
)
1883 if (metadata
.empty()) {
1886 pending_metadata
[gid
] = metadata
;
1888 MonitorDBStore::TransactionRef t
= paxos
->get_pending_transaction();
1890 ::encode(pending_metadata
, bl
);
1891 t
->put(MDS_METADATA_PREFIX
, "last_metadata", bl
);
1892 paxos
->trigger_propose();
1895 void MDSMonitor::remove_from_metadata(MonitorDBStore::TransactionRef t
)
1897 bool update
= false;
1898 for (map
<mds_gid_t
, Metadata
>::iterator i
= pending_metadata
.begin();
1899 i
!= pending_metadata
.end(); ) {
1900 if (!get_pending_fsmap().gid_exists(i
->first
)) {
1901 pending_metadata
.erase(i
++);
1910 ::encode(pending_metadata
, bl
);
1911 t
->put(MDS_METADATA_PREFIX
, "last_metadata", bl
);
1914 int MDSMonitor::load_metadata(map
<mds_gid_t
, Metadata
>& m
)
1917 int r
= mon
->store
->get(MDS_METADATA_PREFIX
, "last_metadata", bl
);
1919 dout(1) << "Unable to load 'last_metadata'" << dendl
;
1923 bufferlist::iterator it
= bl
.begin();
1928 void MDSMonitor::count_metadata(const string
& field
, map
<string
,int> *out
)
1930 map
<mds_gid_t
,Metadata
> meta
;
1931 load_metadata(meta
);
1932 for (auto& p
: meta
) {
1933 auto q
= p
.second
.find(field
);
1934 if (q
== p
.second
.end()) {
1935 (*out
)["unknown"]++;
1937 (*out
)[q
->second
]++;
1942 void MDSMonitor::count_metadata(const string
& field
, Formatter
*f
)
1944 map
<string
,int> by_val
;
1945 count_metadata(field
, &by_val
);
1946 f
->open_object_section(field
.c_str());
1947 for (auto& p
: by_val
) {
1948 f
->dump_int(p
.first
.c_str(), p
.second
);
1953 int MDSMonitor::dump_metadata(const std::string
&who
, Formatter
*f
, ostream
& err
)
1957 mds_gid_t gid
= gid_from_arg(who
, err
);
1958 if (gid
== MDS_GID_NONE
) {
1962 map
<mds_gid_t
, Metadata
> metadata
;
1963 if (int r
= load_metadata(metadata
)) {
1964 err
<< "Unable to load 'last_metadata'";
1968 if (!metadata
.count(gid
)) {
1971 const Metadata
& m
= metadata
[gid
];
1972 for (Metadata::const_iterator p
= m
.begin(); p
!= m
.end(); ++p
) {
1973 f
->dump_string(p
->first
.c_str(), p
->second
);
1978 int MDSMonitor::print_nodes(Formatter
*f
)
1982 map
<mds_gid_t
, Metadata
> metadata
;
1983 if (int r
= load_metadata(metadata
)) {
1987 map
<string
, list
<int> > mdses
; // hostname => rank
1988 for (map
<mds_gid_t
, Metadata
>::iterator it
= metadata
.begin();
1989 it
!= metadata
.end(); ++it
) {
1990 const Metadata
& m
= it
->second
;
1991 Metadata::const_iterator hostname
= m
.find("hostname");
1992 if (hostname
== m
.end()) {
1993 // not likely though
1996 const mds_gid_t gid
= it
->first
;
1997 if (!get_fsmap().gid_exists(gid
)) {
1998 dout(5) << __func__
<< ": GID " << gid
<< " not existent" << dendl
;
2001 const MDSMap::mds_info_t
& mds_info
= get_fsmap().get_info_gid(gid
);
2002 // FIXME: include filesystem name with rank here
2003 mdses
[hostname
->second
].push_back(mds_info
.rank
);
2006 dump_services(f
, mdses
, "mds");
2011 * If a cluster is undersized (with respect to max_mds), then
2012 * attempt to find daemons to grow it.
2014 bool MDSMonitor::maybe_expand_cluster(std::shared_ptr
<Filesystem
> &fs
)
2016 bool do_propose
= false;
2017 auto &pending
= get_pending_fsmap_writeable();
2019 if (fs
->mds_map
.test_flag(CEPH_MDSMAP_DOWN
)) {
2023 while (fs
->mds_map
.get_num_in_mds() < size_t(fs
->mds_map
.get_max_mds()) &&
2024 !fs
->mds_map
.is_degraded()) {
2025 mds_rank_t mds
= mds_rank_t(0);
2027 while (fs
->mds_map
.is_in(mds
)) {
2030 mds_gid_t newgid
= pending
.find_replacement_for({fs
->fscid
, mds
},
2031 name
, g_conf
->mon_force_standby_active
);
2032 if (newgid
== MDS_GID_NONE
) {
2036 const auto &new_info
= pending
.get_info_gid(newgid
);
2037 dout(1) << "assigned standby " << new_info
.addr
2038 << " as mds." << mds
<< dendl
;
2040 mon
->clog
->info() << new_info
.human_name() << " assigned to "
2041 "filesystem " << fs
->mds_map
.fs_name
<< " as rank "
2042 << mds
<< " (now has " << fs
->mds_map
.get_num_in_mds() + 1
2044 pending
.promote(newgid
, fs
, mds
);
2053 * If a daemon is laggy, and a suitable replacement
2054 * is available, fail this daemon (remove from map) and pass its
2055 * role to another daemon.
2057 void MDSMonitor::maybe_replace_gid(mds_gid_t gid
, const MDSMap::mds_info_t
& info
,
2058 bool *mds_propose
, bool *osd_propose
)
2060 assert(mds_propose
!= nullptr);
2061 assert(osd_propose
!= nullptr);
2063 auto &pending
= get_pending_fsmap_writeable();
2064 const auto fscid
= pending
.mds_roles
.at(gid
);
2066 // We will only take decisive action (replacing/removing a daemon)
2067 // if we have some indicating that some other daemon(s) are successfully
2068 // getting beacons through recently.
2069 utime_t latest_beacon
;
2070 for (const auto & i
: last_beacon
) {
2071 latest_beacon
= MAX(i
.second
.stamp
, latest_beacon
);
2073 const bool may_replace
= latest_beacon
>
2075 MAX(g_conf
->mds_beacon_interval
, g_conf
->mds_beacon_grace
* 0.5));
2078 // and is there a non-laggy standby that can take over for us?
2080 if (info
.rank
>= 0 &&
2081 info
.state
!= MDSMap::STATE_STANDBY
&&
2082 info
.state
!= MDSMap::STATE_STANDBY_REPLAY
&&
2084 !pending
.get_filesystem(fscid
)->mds_map
.test_flag(CEPH_MDSMAP_DOWN
) &&
2085 (sgid
= pending
.find_replacement_for({fscid
, info
.rank
}, info
.name
,
2086 g_conf
->mon_force_standby_active
)) != MDS_GID_NONE
)
2089 MDSMap::mds_info_t si
= pending
.get_info_gid(sgid
);
2090 dout(10) << " replacing " << gid
<< " " << info
.addr
<< " mds."
2091 << info
.rank
<< "." << info
.inc
2092 << " " << ceph_mds_state_name(info
.state
)
2093 << " with " << sgid
<< "/" << si
.name
<< " " << si
.addr
<< dendl
;
2095 mon
->clog
->warn() << info
.human_name()
2096 << " is not responding, replacing it "
2097 << "as rank " << info
.rank
2098 << " with standby " << si
.human_name();
2100 // Remember what NS the old one was in
2101 const fs_cluster_id_t fscid
= pending
.mds_roles
.at(gid
);
2103 // Remove the old one
2104 *osd_propose
|= fail_mds_gid(gid
);
2106 // Promote the replacement
2107 auto fs
= pending
.filesystems
.at(fscid
);
2108 pending
.promote(sgid
, fs
, info
.rank
);
2110 *mds_propose
= true;
2111 } else if ((info
.state
== MDSMap::STATE_STANDBY_REPLAY
||
2112 info
.state
== MDSMap::STATE_STANDBY
) && may_replace
) {
2113 dout(10) << " failing and removing " << gid
<< " " << info
.addr
<< " mds." << info
.rank
2114 << "." << info
.inc
<< " " << ceph_mds_state_name(info
.state
)
2116 mon
->clog
->info() << "Standby " << info
.human_name() << " is not "
2117 "responding, dropping it";
2119 *mds_propose
= true;
2120 } else if (!info
.laggy()) {
2121 dout(10) << " marking " << gid
<< " " << info
.addr
<< " mds." << info
.rank
<< "." << info
.inc
2122 << " " << ceph_mds_state_name(info
.state
)
2123 << " laggy" << dendl
;
2124 pending
.modify_daemon(info
.global_id
, [](MDSMap::mds_info_t
*info
) {
2125 info
->laggy_since
= ceph_clock_now();
2127 *mds_propose
= true;
2131 bool MDSMonitor::maybe_promote_standby(std::shared_ptr
<Filesystem
> &fs
)
2133 assert(!fs
->mds_map
.test_flag(CEPH_MDSMAP_DOWN
));
2135 auto &pending
= get_pending_fsmap_writeable();
2137 bool do_propose
= false;
2139 // have a standby take over?
2140 set
<mds_rank_t
> failed
;
2141 fs
->mds_map
.get_failed_mds_set(failed
);
2142 if (!failed
.empty()) {
2143 set
<mds_rank_t
>::iterator p
= failed
.begin();
2144 while (p
!= failed
.end()) {
2145 mds_rank_t f
= *p
++;
2146 mds_gid_t sgid
= pending
.find_replacement_for({fs
->fscid
, f
}, {},
2147 g_conf
->mon_force_standby_active
);
2149 const MDSMap::mds_info_t si
= pending
.get_info_gid(sgid
);
2150 dout(0) << " taking over failed mds." << f
<< " with " << sgid
2151 << "/" << si
.name
<< " " << si
.addr
<< dendl
;
2152 mon
->clog
->info() << "Standby " << si
.human_name()
2153 << " assigned to filesystem " << fs
->mds_map
.fs_name
2154 << " as rank " << f
;
2156 pending
.promote(sgid
, fs
, f
);
2161 // There were no failures to replace, so try using any available standbys
2162 // as standby-replay daemons.
2164 // Take a copy of the standby GIDs so that we can iterate over
2165 // them while perhaps-modifying standby_daemons during the loop
2166 // (if we promote anyone they are removed from standby_daemons)
2167 std::vector
<mds_gid_t
> standby_gids
;
2168 for (const auto &j
: pending
.standby_daemons
) {
2169 standby_gids
.push_back(j
.first
);
2172 for (const auto &gid
: standby_gids
) {
2173 const auto &info
= pending
.standby_daemons
.at(gid
);
2174 assert(info
.state
== MDSMap::STATE_STANDBY
);
2176 if (!info
.standby_replay
) {
2181 * This mds is standby but has no rank assigned.
2182 * See if we can find it somebody to shadow
2184 dout(20) << "gid " << gid
<< " is standby and following nobody" << dendl
;
2186 // standby for someone specific?
2187 if (info
.standby_for_rank
>= 0) {
2188 // The mds_info_t may or may not tell us exactly which filesystem
2189 // the standby_for_rank refers to: lookup via legacy_client_fscid
2190 mds_role_t target_role
= {
2191 info
.standby_for_fscid
== FS_CLUSTER_ID_NONE
?
2192 pending
.legacy_client_fscid
: info
.standby_for_fscid
,
2193 info
.standby_for_rank
};
2195 // It is possible that the map contains a standby_for_fscid
2196 // that doesn't correspond to an existing filesystem, especially
2197 // if we loaded from a version with a bug (#17466)
2198 if (info
.standby_for_fscid
!= FS_CLUSTER_ID_NONE
2199 && !pending
.filesystem_exists(info
.standby_for_fscid
)) {
2200 derr
<< "gid " << gid
<< " has invalid standby_for_fscid "
2201 << info
.standby_for_fscid
<< dendl
;
2205 // If we managed to resolve a full target role
2206 if (target_role
.fscid
!= FS_CLUSTER_ID_NONE
) {
2207 const auto &fs
= pending
.get_filesystem(target_role
.fscid
);
2208 if (fs
->mds_map
.is_followable(target_role
.rank
)) {
2209 do_propose
|= try_standby_replay(
2212 fs
->mds_map
.get_info(target_role
.rank
));
2220 for (const auto &p
: pending
.filesystems
) {
2221 if (info
.standby_for_fscid
!= FS_CLUSTER_ID_NONE
&&
2222 info
.standby_for_fscid
!= p
.first
)
2225 bool assigned
= false;
2226 const auto &fs
= p
.second
;
2227 const MDSMap
&mds_map
= fs
->mds_map
;
2228 for (const auto &mds_i
: mds_map
.mds_info
) {
2229 const MDSMap::mds_info_t
&cand_info
= mds_i
.second
;
2230 if (cand_info
.rank
>= 0 && mds_map
.is_followable(cand_info
.rank
)) {
2231 if ((info
.standby_for_name
.length() && info
.standby_for_name
!= cand_info
.name
) ||
2232 info
.standby_for_rank
!= MDS_RANK_NONE
) {
2233 continue; // we're supposed to follow someone else
2236 if (try_standby_replay(info
, *fs
, cand_info
)) {
2253 void MDSMonitor::tick()
2255 // make sure mds's are still alive
2256 // ...if i am an active leader
2258 if (!is_active()) return;
2260 dout(10) << get_working_fsmap() << dendl
;
2262 if (!is_leader()) return;
2264 auto &pending
= get_pending_fsmap_writeable();
2266 bool do_propose
= false;
2268 do_propose
|= pending
.check_health();
2270 // expand mds cluster (add new nodes to @in)?
2271 for (auto &p
: pending
.filesystems
) {
2272 do_propose
|= maybe_expand_cluster(p
.second
);
2275 const auto now
= ceph_clock_now();
2276 if (last_tick
.is_zero()) {
2280 if (now
- last_tick
> (g_conf
->mds_beacon_grace
- g_conf
->mds_beacon_interval
)) {
2281 // This case handles either local slowness (calls being delayed
2282 // for whatever reason) or cluster election slowness (a long gap
2283 // between calls while an election happened)
2284 dout(4) << __func__
<< ": resetting beacon timeouts due to mon delay "
2285 "(slow election?) of " << now
- last_tick
<< " seconds" << dendl
;
2286 for (auto &i
: last_beacon
) {
2287 i
.second
.stamp
= now
;
2293 // check beacon timestamps
2294 utime_t cutoff
= now
;
2295 cutoff
-= g_conf
->mds_beacon_grace
;
2297 // make sure last_beacon is fully populated
2298 for (auto &p
: pending
.mds_roles
) {
2299 auto &gid
= p
.first
;
2300 if (last_beacon
.count(gid
) == 0) {
2301 last_beacon
[gid
].stamp
= now
;
2302 last_beacon
[gid
].seq
= 0;
2306 bool propose_osdmap
= false;
2307 bool osdmap_writeable
= mon
->osdmon()->is_writeable();
2308 auto p
= last_beacon
.begin();
2309 while (p
!= last_beacon
.end()) {
2310 mds_gid_t gid
= p
->first
;
2311 auto beacon_info
= p
->second
;
2314 if (!pending
.gid_exists(gid
)) {
2316 last_beacon
.erase(gid
);
2320 if (beacon_info
.stamp
< cutoff
) {
2321 auto &info
= pending
.get_info_gid(gid
);
2322 dout(1) << "no beacon from mds." << info
.rank
<< "." << info
.inc
2323 << " (gid: " << gid
<< " addr: " << info
.addr
2324 << " state: " << ceph_mds_state_name(info
.state
) << ")"
2325 << " since " << beacon_info
.stamp
<< dendl
;
2326 // If the OSDMap is writeable, we can blacklist things, so we can
2327 // try failing any laggy MDS daemons. Consider each one for failure.
2328 if (osdmap_writeable
) {
2329 maybe_replace_gid(gid
, info
, &do_propose
, &propose_osdmap
);
2333 if (propose_osdmap
) {
2334 request_proposal(mon
->osdmon());
2337 for (auto &p
: pending
.filesystems
) {
2338 auto &fs
= p
.second
;
2339 if (!fs
->mds_map
.test_flag(CEPH_MDSMAP_DOWN
)) {
2340 do_propose
|= maybe_promote_standby(fs
);
2350 * finfo: the would-be follower
2351 * leader_fs: the Filesystem containing the would-be leader
2352 * ainfo: the would-be leader
2354 bool MDSMonitor::try_standby_replay(
2355 const MDSMap::mds_info_t
& finfo
,
2356 const Filesystem
&leader_fs
,
2357 const MDSMap::mds_info_t
& ainfo
)
2359 // someone else already following?
2360 if (leader_fs
.has_standby_replay(ainfo
.global_id
)) {
2361 dout(20) << " mds." << ainfo
.rank
<< " already has a follower" << dendl
;
2364 // Assign the new role to the standby
2365 dout(10) << " setting to follow mds rank " << ainfo
.rank
<< dendl
;
2366 get_pending_fsmap_writeable().assign_standby_replay(finfo
.global_id
, leader_fs
.fscid
, ainfo
.rank
);
2371 MDSMonitor::MDSMonitor(Monitor
*mn
, Paxos
*p
, string service_name
)
2372 : PaxosService(mn
, p
, service_name
)
2374 handlers
= FileSystemCommandHandler::load(p
);
2377 void MDSMonitor::on_restart()
2379 // Clear out the leader-specific state.
2380 last_tick
= utime_t();
2381 last_beacon
.clear();