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.
17 #include <boost/utility.hpp>
19 #include "MDSMonitor.h"
20 #include "FSCommands.h"
22 #include "MonitorDBStore.h"
23 #include "OSDMonitor.h"
25 #include "common/strtol.h"
26 #include "common/perf_counters.h"
27 #include "common/config.h"
28 #include "common/cmdparse.h"
29 #include "messages/MMDSMap.h"
30 #include "messages/MFSMap.h"
31 #include "messages/MFSMapUser.h"
32 #include "messages/MMDSLoadTargets.h"
33 #include "messages/MMonCommand.h"
34 #include "messages/MGenericMessage.h"
36 #include "include/ceph_assert.h"
37 #include "include/str_list.h"
38 #include "include/stringify.h"
39 #include "mds/mdstypes.h"
42 using namespace TOPNSPC::common
;
50 using std::ostringstream
;
54 using std::string_view
;
55 using std::stringstream
;
59 using ceph::bufferlist
;
62 using ceph::ErasureCodeInterfaceRef
;
63 using ceph::ErasureCodeProfile
;
64 using ceph::Formatter
;
65 using ceph::JSONFormatter
;
66 using ceph::make_message
;
67 using ceph::mono_clock
;
68 using ceph::mono_time
;
70 #define dout_subsys ceph_subsys_mon
72 #define dout_prefix _prefix(_dout, mon, get_fsmap())
73 static ostream
& _prefix(std::ostream
*_dout
, Monitor
&mon
, const FSMap
& fsmap
) {
74 return *_dout
<< "mon." << mon
.name
<< "@" << mon
.rank
75 << "(" << mon
.get_state_name()
76 << ").mds e" << fsmap
.get_epoch() << " ";
79 static const string
MDS_METADATA_PREFIX("mds_metadata");
80 static const string
MDS_HEALTH_PREFIX("mds_health");
84 * Specialized implementation of cmd_getval to allow us to parse
85 * out strongly-typedef'd types
87 namespace TOPNSPC::common
{
88 template<> bool cmd_getval(const cmdmap_t
& cmdmap
,
89 std::string_view k
, mds_gid_t
&val
)
91 return cmd_getval(cmdmap
, k
, (int64_t&)val
);
94 template<> bool cmd_getval(const cmdmap_t
& cmdmap
,
95 std::string_view k
, mds_rank_t
&val
)
97 return cmd_getval(cmdmap
, k
, (int64_t&)val
);
100 template<> bool cmd_getval(const cmdmap_t
& cmdmap
,
101 std::string_view k
, MDSMap::DaemonState
&val
)
103 return cmd_getval(cmdmap
, k
, (int64_t&)val
);
109 void MDSMonitor::print_map(const FSMap
& m
)
111 dout(dblV
) << "print_map\n";
117 void MDSMonitor::create_initial()
119 dout(10) << "create_initial" << dendl
;
122 void MDSMonitor::get_store_prefixes(std::set
<string
>& s
) const
124 s
.insert(service_name
);
125 s
.insert(MDS_METADATA_PREFIX
);
126 s
.insert(MDS_HEALTH_PREFIX
);
129 void MDSMonitor::update_from_paxos(bool *need_bootstrap
)
131 version_t version
= get_last_committed();
132 if (version
== get_fsmap().epoch
)
135 dout(10) << __func__
<< " version " << version
136 << ", my e " << get_fsmap().epoch
<< dendl
;
137 ceph_assert(version
> get_fsmap().epoch
);
144 int err
= get_version(version
, fsmap_bl
);
145 ceph_assert(err
== 0);
147 ceph_assert(fsmap_bl
.length() > 0);
148 dout(10) << __func__
<< " got " << version
<< dendl
;
150 PaxosFSMap::decode(fsmap_bl
);
151 } catch (const ceph::buffer::malformed_input
& e
) {
152 derr
<< "unable to decode FSMap: " << e
.what() << dendl
;
157 dout(0) << "new map" << dendl
;
158 print_map
<0>(get_fsmap());
159 if (!g_conf()->mon_mds_skip_sanity
) {
160 get_fsmap().sanity();
166 void MDSMonitor::init()
168 (void)load_metadata(pending_metadata
);
171 void MDSMonitor::create_pending()
173 auto &fsmap
= PaxosFSMap::create_pending();
175 if (mon
.osdmon()->is_readable()) {
176 const auto &osdmap
= mon
.osdmon()->osdmap
;
177 fsmap
.sanitize([&osdmap
](int64_t pool
){return osdmap
.have_pg_pool(pool
);});
180 dout(10) << "create_pending e" << fsmap
.epoch
<< dendl
;
183 void MDSMonitor::encode_pending(MonitorDBStore::TransactionRef t
)
185 auto &pending
= get_pending_fsmap_writeable();
186 auto &epoch
= pending
.epoch
;
188 dout(10) << "encode_pending e" << epoch
<< dendl
;
190 // print map iff 'debug mon = 30' or higher
191 print_map
<30>(pending
);
192 if (!g_conf()->mon_mds_skip_sanity
) {
193 pending
.sanity(true);
196 // Set 'modified' on maps modified this epoch
197 for (auto &p
: pending
.filesystems
) {
198 if (p
.second
->mds_map
.epoch
== epoch
) {
199 p
.second
->mds_map
.modified
= ceph_clock_now();
204 ceph_assert(get_last_committed() + 1 == pending
.epoch
);
205 bufferlist pending_bl
;
206 pending
.encode(pending_bl
, mon
.get_quorum_con_features());
208 /* put everything in the transaction */
209 put_version(t
, pending
.epoch
, pending_bl
);
210 put_last_committed(t
, pending
.epoch
);
212 // Encode MDSHealth data
213 for (std::map
<uint64_t, MDSHealth
>::iterator i
= pending_daemon_health
.begin();
214 i
!= pending_daemon_health
.end(); ++i
) {
216 i
->second
.encode(bl
);
217 t
->put(MDS_HEALTH_PREFIX
, stringify(i
->first
), bl
);
220 for (std::set
<uint64_t>::iterator i
= pending_daemon_health_rm
.begin();
221 i
!= pending_daemon_health_rm
.end(); ++i
) {
222 t
->erase(MDS_HEALTH_PREFIX
, stringify(*i
));
224 pending_daemon_health_rm
.clear();
225 remove_from_metadata(pending
, t
);
228 health_check_map_t new_checks
;
229 const auto &info_map
= pending
.get_mds_info();
230 for (const auto &i
: info_map
) {
231 const auto &gid
= i
.first
;
232 const auto &info
= i
.second
;
233 if (pending_daemon_health_rm
.count(gid
)) {
237 auto p
= pending_daemon_health
.find(gid
);
238 if (p
!= pending_daemon_health
.end()) {
242 mon
.store
->get(MDS_HEALTH_PREFIX
, stringify(gid
), bl
);
244 derr
<< "Missing health data for MDS " << gid
<< dendl
;
247 auto bl_i
= bl
.cbegin();
250 for (const auto &metric
: health
.metrics
) {
251 const auto rank
= info
.rank
;
252 health_check_t
*check
= &new_checks
.get_or_add(
253 mds_metric_name(metric
.type
),
255 mds_metric_summary(metric
.type
),
258 ss
<< "mds." << info
.name
<< "(mds." << rank
<< "): " << metric
.message
;
260 for (auto &p
: metric
.metadata
) {
266 ss
<< p
.first
<< ": " << p
.second
;
269 check
->detail
.push_back(ss
.str());
272 pending
.get_health_checks(&new_checks
);
273 for (auto& p
: new_checks
.checks
) {
274 p
.second
.summary
= std::regex_replace(
277 stringify(p
.second
.detail
.size()));
278 p
.second
.summary
= std::regex_replace(
280 std::regex("%plurals%"),
281 p
.second
.detail
.size() > 1 ? "s" : "");
282 p
.second
.summary
= std::regex_replace(
284 std::regex("%isorare%"),
285 p
.second
.detail
.size() > 1 ? "are" : "is");
286 p
.second
.summary
= std::regex_replace(
288 std::regex("%hasorhave%"),
289 p
.second
.detail
.size() > 1 ? "have" : "has");
291 encode_health(new_checks
, t
);
294 version_t
MDSMonitor::get_trim_to() const
297 if (g_conf()->mon_mds_force_trim_to
> 0 &&
298 g_conf()->mon_mds_force_trim_to
<= (int)get_last_committed()) {
299 floor
= g_conf()->mon_mds_force_trim_to
;
300 dout(10) << __func__
<< " explicit mon_mds_force_trim_to = "
304 unsigned max
= g_conf()->mon_max_mdsmap_epochs
;
305 version_t last
= get_last_committed();
307 if (last
- get_first_committed() > max
&& floor
< last
- max
) {
311 dout(20) << __func__
<< " = " << floor
<< dendl
;
315 bool MDSMonitor::preprocess_query(MonOpRequestRef op
)
317 op
->mark_mdsmon_event(__func__
);
318 auto m
= op
->get_req
<PaxosServiceMessage
>();
319 dout(10) << "preprocess_query " << *m
<< " from " << m
->get_orig_source()
320 << " " << m
->get_orig_source_addrs() << dendl
;
322 switch (m
->get_type()) {
325 return preprocess_beacon(op
);
327 case MSG_MON_COMMAND
:
329 return preprocess_command(op
);
330 } catch (const bad_cmd_get
& e
) {
332 mon
.reply_command(op
, -EINVAL
, e
.what(), bl
, get_last_committed());
336 case MSG_MDS_OFFLOAD_TARGETS
:
337 return preprocess_offload_targets(op
);
345 void MDSMonitor::_note_beacon(MMDSBeacon
*m
)
347 mds_gid_t gid
= mds_gid_t(m
->get_global_id());
348 version_t seq
= m
->get_seq();
350 dout(5) << "_note_beacon " << *m
<< " noting time" << dendl
;
351 auto &beacon
= last_beacon
[gid
];
352 beacon
.stamp
= mono_clock::now();
356 bool MDSMonitor::preprocess_beacon(MonOpRequestRef op
)
358 op
->mark_mdsmon_event(__func__
);
359 auto m
= op
->get_req
<MMDSBeacon
>();
360 MDSMap::DaemonState state
= m
->get_state();
361 mds_gid_t gid
= m
->get_global_id();
362 version_t seq
= m
->get_seq();
363 MDSMap::mds_info_t info
;
364 epoch_t effective_epoch
= 0;
366 const auto &fsmap
= get_fsmap();
368 // check privileges, ignore if fails
369 MonSession
*session
= op
->get_session();
372 if (!session
->is_capable("mds", MON_CAP_X
)) {
373 dout(0) << "preprocess_beacon got MMDSBeacon from entity with insufficient privileges "
374 << session
->caps
<< dendl
;
378 if (m
->get_fsid() != mon
.monmap
->fsid
) {
379 dout(0) << "preprocess_beacon on fsid " << m
->get_fsid() << " != " << mon
.monmap
->fsid
<< dendl
;
383 dout(5) << "preprocess_beacon " << *m
384 << " from " << m
->get_orig_source()
385 << " " << m
->get_orig_source_addrs()
386 << " " << m
->get_compat()
389 // make sure the address has a port
390 if (m
->get_orig_source_addr().get_port() == 0) {
391 dout(1) << " ignoring boot message without a port" << dendl
;
399 // booted, but not in map?
400 if (!fsmap
.gid_exists(gid
)) {
401 if (state
!= MDSMap::STATE_BOOT
) {
402 dout(7) << "mds_beacon " << *m
<< " is not in fsmap (state "
403 << ceph_mds_state_name(state
) << ")" << dendl
;
405 /* We can't send an MDSMap this MDS was a part of because we no longer
406 * know which FS it was part of. Nor does this matter. Sending an empty
407 * MDSMap is sufficient for getting the MDS to respawn.
409 auto m
= make_message
<MMDSMap
>(mon
.monmap
->fsid
, MDSMap::create_null_mdsmap());
410 mon
.send_reply(op
, m
.detach());
413 return false; // not booted yet.
416 dout(10) << __func__
<< ": GID exists in map: " << gid
<< dendl
;
417 info
= fsmap
.get_info_gid(gid
);
419 if (state
== MDSMap::STATE_DNE
) {
424 if (info
.state_seq
> seq
) {
425 dout(7) << "mds_beacon " << *m
<< " has old seq, ignoring" << dendl
;
429 // Work out the latest epoch that this daemon should have seen
431 fs_cluster_id_t fscid
= fsmap
.mds_roles
.at(gid
);
432 if (fscid
== FS_CLUSTER_ID_NONE
) {
433 effective_epoch
= fsmap
.standby_epochs
.at(gid
);
435 effective_epoch
= fsmap
.get_filesystem(fscid
)->mds_map
.epoch
;
437 if (effective_epoch
!= m
->get_last_epoch_seen()) {
438 dout(10) << "mds_beacon " << *m
439 << " ignoring requested state, because mds hasn't seen latest map" << dendl
;
446 return false; // no longer laggy, need to update map.
448 if (state
== MDSMap::STATE_BOOT
) {
449 // ignore, already booted.
453 // did the join_fscid change
454 if (m
->get_fs().size()) {
455 fs_cluster_id_t fscid
= FS_CLUSTER_ID_NONE
;
456 auto f
= fsmap
.get_filesystem(m
->get_fs());
460 if (info
.join_fscid
!= fscid
) {
461 dout(10) << __func__
<< " standby mds_join_fs changed to " << fscid
462 << " (" << m
->get_fs() << ")" << dendl
;
467 if (info
.join_fscid
!= FS_CLUSTER_ID_NONE
) {
468 dout(10) << __func__
<< " standby mds_join_fs was cleared" << dendl
;
474 // is there a state change here?
475 if (info
.state
!= state
) {
480 // Comparing known daemon health with m->get_health()
481 // and return false (i.e. require proposal) if they
482 // do not match, to update our stored
483 if (!(pending_daemon_health
[gid
] == m
->get_health())) {
484 dout(10) << __func__
<< " health metrics for gid " << gid
<< " were updated" << dendl
;
490 // note time and reply
491 ceph_assert(effective_epoch
> 0);
494 auto beacon
= make_message
<MMDSBeacon
>(mon
.monmap
->fsid
,
495 m
->get_global_id(), m
->get_name(), effective_epoch
,
496 state
, seq
, CEPH_FEATURES_SUPPORTED_DEFAULT
);
497 mon
.send_reply(op
, beacon
.detach());
502 // I won't reply this beacon, drop it.
507 bool MDSMonitor::preprocess_offload_targets(MonOpRequestRef op
)
509 op
->mark_mdsmon_event(__func__
);
510 auto m
= op
->get_req
<MMDSLoadTargets
>();
511 dout(10) << "preprocess_offload_targets " << *m
<< " from " << m
->get_orig_source() << dendl
;
513 const auto &fsmap
= get_fsmap();
515 // check privileges, ignore message if fails
516 MonSession
*session
= op
->get_session();
519 if (!session
->is_capable("mds", MON_CAP_X
)) {
520 dout(0) << "preprocess_offload_targets got MMDSLoadTargets from entity with insufficient caps "
521 << session
->caps
<< dendl
;
525 if (fsmap
.gid_exists(m
->global_id
) &&
526 m
->targets
== fsmap
.get_info_gid(m
->global_id
).export_targets
)
537 bool MDSMonitor::prepare_update(MonOpRequestRef op
)
539 op
->mark_mdsmon_event(__func__
);
540 auto m
= op
->get_req
<PaxosServiceMessage
>();
541 dout(7) << "prepare_update " << *m
<< dendl
;
543 switch (m
->get_type()) {
546 return prepare_beacon(op
);
548 case MSG_MON_COMMAND
:
550 return prepare_command(op
);
551 } catch (const bad_cmd_get
& e
) {
553 mon
.reply_command(op
, -EINVAL
, e
.what(), bl
, get_last_committed());
557 case MSG_MDS_OFFLOAD_TARGETS
:
558 return prepare_offload_targets(op
);
567 bool MDSMonitor::prepare_beacon(MonOpRequestRef op
)
569 op
->mark_mdsmon_event(__func__
);
570 auto m
= op
->get_req
<MMDSBeacon
>();
571 // -- this is an update --
572 dout(12) << "prepare_beacon " << *m
<< " from " << m
->get_orig_source()
573 << " " << m
->get_orig_source_addrs() << dendl
;
574 entity_addrvec_t addrs
= m
->get_orig_source_addrs();
575 mds_gid_t gid
= m
->get_global_id();
576 MDSMap::DaemonState state
= m
->get_state();
577 version_t seq
= m
->get_seq();
579 auto &pending
= get_pending_fsmap_writeable();
581 dout(15) << __func__
<< " got health from gid " << gid
<< " with " << m
->get_health().metrics
.size() << " metrics." << dendl
;
583 // Calculate deltas of health metrics created and removed
584 // Do this by type rather than MDSHealthMetric equality, because messages can
585 // change a lot when they include e.g. a number of items.
586 const auto &old_health
= pending_daemon_health
[gid
].metrics
;
587 const auto &new_health
= m
->get_health().metrics
;
589 std::set
<mds_metric_t
> old_types
;
590 for (const auto &i
: old_health
) {
591 old_types
.insert(i
.type
);
594 std::set
<mds_metric_t
> new_types
;
595 for (const auto &i
: new_health
) {
596 new_types
.insert(i
.type
);
599 for (const auto &new_metric
: new_health
) {
600 if (old_types
.count(new_metric
.type
) == 0) {
601 dout(10) << "MDS health message (" << m
->get_orig_source()
602 << "): " << new_metric
.sev
<< " " << new_metric
.message
<< dendl
;
606 // Log the disappearance of health messages at INFO
607 for (const auto &old_metric
: old_health
) {
608 if (new_types
.count(old_metric
.type
) == 0) {
609 mon
.clog
->info() << "MDS health message cleared ("
610 << m
->get_orig_source() << "): " << old_metric
.message
;
615 pending_daemon_health
[gid
] = m
->get_health();
617 const auto& cs
= m
->get_compat();
618 if (state
== MDSMap::STATE_BOOT
) {
619 // zap previous instance of this name?
620 if (g_conf()->mds_enforce_unique_name
) {
621 bool failed_mds
= false;
622 while (mds_gid_t existing
= pending
.find_mds_gid_by_name(m
->get_name())) {
623 if (!mon
.osdmon()->is_writeable()) {
624 mon
.osdmon()->wait_for_writeable(op
, new C_RetryMessage(this, op
));
627 const auto& existing_info
= pending
.get_info_gid(existing
);
628 mon
.clog
->info() << existing_info
.human_name() << " restarted";
629 fail_mds_gid(pending
, existing
);
633 ceph_assert(mon
.osdmon()->is_writeable());
634 request_proposal(mon
.osdmon());
638 // Add this daemon to the map
639 if (pending
.mds_roles
.count(gid
) == 0) {
640 MDSMap::mds_info_t new_info
;
641 new_info
.global_id
= gid
;
642 new_info
.name
= m
->get_name();
643 new_info
.addrs
= addrs
;
644 new_info
.mds_features
= m
->get_mds_features();
645 new_info
.state
= MDSMap::STATE_STANDBY
;
646 new_info
.state_seq
= seq
;
647 new_info
.compat
= cs
;
648 if (m
->get_fs().size()) {
649 fs_cluster_id_t fscid
= FS_CLUSTER_ID_NONE
;
650 auto f
= pending
.get_filesystem(m
->get_fs());
654 new_info
.join_fscid
= fscid
;
656 pending
.insert(new_info
);
659 // initialize the beacon timer
660 auto &beacon
= last_beacon
[gid
];
661 beacon
.stamp
= mono_clock::now();
664 update_metadata(m
->get_global_id(), m
->get_sys_info());
668 if (!pending
.gid_exists(gid
)) {
669 /* gid has been removed from pending, send null map */
670 dout(5) << "mds_beacon " << *m
<< " is not in fsmap (state "
671 << ceph_mds_state_name(state
) << ")" << dendl
;
673 /* We can't send an MDSMap this MDS was a part of because we no longer
674 * know which FS it was part of. Nor does this matter. Sending an empty
675 * MDSMap is sufficient for getting the MDS to respawn.
680 const auto& info
= pending
.get_info_gid(gid
);
682 // did the reported compat change? That's illegal!
683 if (cs
.compare(info
.compat
) != 0) {
684 if (!mon
.osdmon()->is_writeable()) {
685 mon
.osdmon()->wait_for_writeable(op
, new C_RetryMessage(this, op
));
688 mon
.clog
->warn() << info
.human_name() << " compat changed unexpectedly";
689 fail_mds_gid(pending
, gid
);
690 request_proposal(mon
.osdmon());
694 // legal state change?
695 if ((info
.state
== MDSMap::STATE_STANDBY
&& state
> 0) ||
696 (info
.state
== MDSMap::STATE_STANDBY_REPLAY
&& state
> 0 && state
!= MDSMap::STATE_DAMAGED
)) {
697 /* N.B.: standby-replay can indicate the rank is damaged due to failure to replay */
698 dout(10) << "mds_beacon mds can't activate itself (" << ceph_mds_state_name(info
.state
)
699 << " -> " << ceph_mds_state_name(state
) << ")" << dendl
;
701 } else if ((state
== MDSMap::STATE_STANDBY
|| state
== MDSMap::STATE_STANDBY_REPLAY
)
702 && info
.rank
!= MDS_RANK_NONE
)
704 dout(4) << "mds_beacon MDS can't go back into standby after taking rank: "
705 "held rank " << info
.rank
<< " while requesting state "
706 << ceph_mds_state_name(state
) << dendl
;
708 } else if (info
.state
== MDSMap::STATE_STOPPING
&&
709 state
!= MDSMap::STATE_STOPPING
&&
710 state
!= MDSMap::STATE_STOPPED
) {
711 // we can't transition to any other states from STOPPING
712 dout(0) << "got beacon for MDS in STATE_STOPPING, ignoring requested state change"
718 dout(1) << "prepare_beacon clearing laggy flag on " << addrs
<< dendl
;
719 pending
.modify_daemon(info
.global_id
, [](auto& info
)
726 dout(5) << "prepare_beacon mds." << info
.rank
727 << " " << ceph_mds_state_name(info
.state
)
728 << " -> " << ceph_mds_state_name(state
)
731 fs_cluster_id_t fscid
= FS_CLUSTER_ID_NONE
;
732 if (m
->get_fs().size()) {
733 auto f
= pending
.get_filesystem(m
->get_fs());
738 pending
.modify_daemon(gid
, [fscid
](auto& info
) {
739 info
.join_fscid
= fscid
;
742 if (state
== MDSMap::STATE_STOPPED
) {
743 const auto fscid
= pending
.mds_roles
.at(gid
);
744 const auto &fs
= pending
.get_filesystem(fscid
);
746 mon
.clog
->info() << info
.human_name() << " finished "
747 << "stopping rank " << info
.rank
<< " in filesystem "
748 << fs
->mds_map
.fs_name
<< " (now has "
749 << fs
->mds_map
.get_num_in_mds() - 1 << " ranks)";
751 auto erased
= pending
.stop(gid
);
752 erased
.push_back(gid
);
754 for (const auto& erased_gid
: erased
) {
755 last_beacon
.erase(erased_gid
);
756 if (pending_daemon_health
.count(erased_gid
)) {
757 pending_daemon_health
.erase(erased_gid
);
758 pending_daemon_health_rm
.insert(erased_gid
);
761 } else if (state
== MDSMap::STATE_DAMAGED
) {
762 if (!mon
.osdmon()->is_writeable()) {
763 dout(1) << __func__
<< ": DAMAGED from rank " << info
.rank
764 << " waiting for osdmon writeable to blocklist it" << dendl
;
765 mon
.osdmon()->wait_for_writeable(op
, new C_RetryMessage(this, op
));
769 auto rank
= info
.rank
;
771 // Record this MDS rank as damaged, so that other daemons
772 // won't try to run it.
773 dout(0) << __func__
<< ": marking rank " << rank
<< " damaged" << dendl
;
775 auto fs
= pending
.get_filesystem(gid
);
776 auto rankgid
= fs
->mds_map
.get_gid(rank
);
777 auto rankinfo
= pending
.get_info_gid(rankgid
);
778 auto followergid
= fs
->mds_map
.get_standby_replay(rank
);
780 ceph_assert(gid
== rankgid
|| gid
== followergid
);
782 utime_t until
= ceph_clock_now();
783 until
+= g_conf().get_val
<double>("mon_mds_blocklist_interval");
784 const auto blocklist_epoch
= mon
.osdmon()->blocklist(rankinfo
.addrs
, until
);
785 if (followergid
!= MDS_GID_NONE
) {
786 fail_mds_gid(pending
, followergid
);
787 last_beacon
.erase(followergid
);
789 request_proposal(mon
.osdmon());
790 pending
.damaged(rankgid
, blocklist_epoch
);
791 last_beacon
.erase(rankgid
);
793 /* MDS expects beacon reply back */
794 } else if (state
== MDSMap::STATE_DNE
) {
795 dout(1) << __func__
<< ": DNE from " << info
<< dendl
;
797 } else if (info
.state
== MDSMap::STATE_STANDBY
&& state
!= info
.state
) {
798 // Standby daemons should never modify their own
799 // state. Reject any attempts to do so.
800 derr
<< "standby " << gid
<< " attempted to change state to "
801 << ceph_mds_state_name(state
) << ", rejecting" << dendl
;
803 } else if (info
.state
!= MDSMap::STATE_STANDBY
&& state
!= info
.state
&&
804 !MDSMap::state_transition_valid(info
.state
, state
)) {
805 // Validate state transitions for daemons that hold a rank
806 derr
<< "daemon " << gid
<< " (rank " << info
.rank
<< ") "
807 << "reported invalid state transition "
808 << ceph_mds_state_name(info
.state
) << " -> "
809 << ceph_mds_state_name(state
) << dendl
;
812 if (info
.state
!= MDSMap::STATE_ACTIVE
&& state
== MDSMap::STATE_ACTIVE
) {
813 const auto &fscid
= pending
.mds_roles
.at(gid
);
814 const auto &fs
= pending
.get_filesystem(fscid
);
815 mon
.clog
->info() << info
.human_name() << " is now active in "
816 << "filesystem " << fs
->mds_map
.fs_name
<< " as rank "
820 // Made it through special cases and validations, record the
821 // daemon's reported state to the FSMap.
822 pending
.modify_daemon(gid
, [state
, seq
](auto& info
) {
824 info
.state_seq
= seq
;
829 dout(5) << "prepare_beacon pending map now:" << dendl
;
832 wait_for_finished_proposal(op
, new LambdaContext([op
, this](int r
){
834 _updated(op
); // success
835 else if (r
== -ECANCELED
) {
838 dispatch(op
); // try again
845 if (!mon
.osdmon()->is_writeable()) {
846 dout(1) << __func__
<< ": waiting for writeable OSDMap to evict" << dendl
;
847 mon
.osdmon()->wait_for_writeable(op
, new C_RetryMessage(this, op
));
851 fail_mds_gid(pending
, gid
);
852 request_proposal(mon
.osdmon());
853 dout(5) << __func__
<< ": pending map now:" << dendl
;
859 wait_for_finished_proposal(op
, new LambdaContext([op
, this](int r
){
861 auto m
= make_message
<MMDSMap
>(mon
.monmap
->fsid
, MDSMap::create_null_mdsmap());
862 mon
.send_reply(op
, m
.detach());
864 dispatch(op
); // try again
871 bool MDSMonitor::prepare_offload_targets(MonOpRequestRef op
)
873 auto &pending
= get_pending_fsmap_writeable();
875 op
->mark_mdsmon_event(__func__
);
876 auto m
= op
->get_req
<MMDSLoadTargets
>();
877 mds_gid_t gid
= m
->global_id
;
878 if (pending
.gid_has_rank(gid
)) {
879 dout(10) << "prepare_offload_targets " << gid
<< " " << m
->targets
<< dendl
;
880 pending
.update_export_targets(gid
, m
->targets
);
882 dout(10) << "prepare_offload_targets " << gid
<< " not in map" << dendl
;
888 bool MDSMonitor::should_propose(double& delay
)
890 // delegate to PaxosService to assess whether we should propose
891 return PaxosService::should_propose(delay
);
894 void MDSMonitor::_updated(MonOpRequestRef op
)
896 const auto &fsmap
= get_fsmap();
897 op
->mark_mdsmon_event(__func__
);
898 auto m
= op
->get_req
<MMDSBeacon
>();
899 dout(10) << "_updated " << m
->get_orig_source() << " " << *m
<< dendl
;
900 mon
.clog
->debug() << m
->get_orig_source() << " "
901 << m
->get_orig_source_addrs() << " "
902 << ceph_mds_state_name(m
->get_state());
904 if (m
->get_state() == MDSMap::STATE_STOPPED
) {
905 // send the map manually (they're out of the map, so they won't get it automatic)
906 auto m
= make_message
<MMDSMap
>(mon
.monmap
->fsid
, MDSMap::create_null_mdsmap());
907 mon
.send_reply(op
, m
.detach());
909 auto beacon
= make_message
<MMDSBeacon
>(mon
.monmap
->fsid
,
910 m
->get_global_id(), m
->get_name(), fsmap
.get_epoch(),
911 m
->get_state(), m
->get_seq(), CEPH_FEATURES_SUPPORTED_DEFAULT
);
912 mon
.send_reply(op
, beacon
.detach());
916 void MDSMonitor::on_active()
921 mon
.clog
->debug() << "fsmap " << get_fsmap();
925 void MDSMonitor::dump_info(Formatter
*f
)
927 f
->open_object_section("fsmap");
931 f
->dump_unsigned("mdsmap_first_committed", get_first_committed());
932 f
->dump_unsigned("mdsmap_last_committed", get_last_committed());
935 bool MDSMonitor::preprocess_command(MonOpRequestRef op
)
937 op
->mark_mdsmon_event(__func__
);
938 auto m
= op
->get_req
<MMonCommand
>();
944 if (!cmdmap_from_json(m
->cmd
, &cmdmap
, ss
)) {
945 // ss has reason for failure
946 string rs
= ss
.str();
947 mon
.reply_command(op
, -EINVAL
, rs
, rdata
, get_last_committed());
952 cmd_getval(cmdmap
, "prefix", prefix
);
953 string format
= cmd_getval_or
<string
>(cmdmap
, "format", "plain");
954 std::unique_ptr
<Formatter
> f(Formatter::create(format
));
956 MonSession
*session
= op
->get_session();
958 mon
.reply_command(op
, -EACCES
, "access denied", rdata
, get_last_committed());
962 // to use const qualifier filter fsmap beforehand
963 FSMap _fsmap_copy
= get_fsmap();
964 _fsmap_copy
.filter(session
->get_allowed_fs_names());
965 const auto& fsmap
= _fsmap_copy
;
967 if (prefix
== "mds stat") {
969 f
->open_object_section("mds_stat");
977 } else if (prefix
== "mds ok-to-stop") {
979 if (!cmd_getval(cmdmap
, "ids", ids
)) {
981 ss
<< "must specify mds id";
984 if (fsmap
.is_any_degraded()) {
985 ss
<< "one or more filesystems is currently degraded";
989 set
<mds_gid_t
> stopping
;
990 for (auto& id
: ids
) {
992 mds_gid_t gid
= gid_from_arg(fsmap
, id
, ess
);
993 if (gid
== MDS_GID_NONE
) {
994 // the mds doesn't exist, but no file systems are unhappy, so losing it
995 // can't have any effect.
998 stopping
.insert(gid
);
1000 set
<mds_gid_t
> active
;
1001 set
<mds_gid_t
> standby
;
1002 for (auto gid
: stopping
) {
1003 if (fsmap
.gid_has_rank(gid
)) {
1004 // ignore standby-replay daemons (at this level)
1005 if (!fsmap
.is_standby_replay(gid
)) {
1006 auto standby
= fsmap
.get_standby_replay(gid
);
1007 if (standby
== MDS_GID_NONE
||
1008 stopping
.count(standby
)) {
1009 // no standby-replay, or we're also stopping the standby-replay
1015 // net loss of a standby
1016 standby
.insert(gid
);
1019 if (fsmap
.get_num_standby() - standby
.size() < active
.size()) {
1021 ss
<< "insufficent standby MDS daemons to stop active gids "
1022 << stringify(active
)
1023 << " and/or standby gids " << stringify(standby
);;
1027 ss
<< "should be safe to stop " << ids
;
1028 } else if (prefix
== "fs dump") {
1032 const FSMap
*fsmapp
= &fsmap
;
1034 if (cmd_getval(cmdmap
, "epoch", epocharg
)) {
1037 int err
= get_version(epoch
, b
);
1038 if (err
== -ENOENT
) {
1042 ceph_assert(err
== 0);
1043 ceph_assert(b
.length());
1051 f
->open_object_section("fsmap");
1052 fsmapp
->dump(f
.get());
1062 ss
<< "dumped fsmap epoch " << fsmapp
->get_epoch();
1063 } else if (prefix
== "mds metadata") {
1065 f
.reset(Formatter::create("json-pretty"));
1068 bool all
= !cmd_getval(cmdmap
, "who", who
);
1069 dout(1) << "all = " << all
<< dendl
;
1072 // Dump all MDSs' metadata
1073 const auto all_info
= fsmap
.get_mds_info();
1075 f
->open_array_section("mds_metadata");
1076 for(const auto &i
: all_info
) {
1077 const auto &info
= i
.second
;
1079 f
->open_object_section("mds");
1080 f
->dump_string("name", info
.name
);
1081 std::ostringstream get_err
;
1082 r
= dump_metadata(fsmap
, info
.name
, f
.get(), get_err
);
1083 if (r
== -EINVAL
|| r
== -ENOENT
) {
1084 // Drop error, list what metadata we do have
1085 dout(1) << get_err
.str() << dendl
;
1087 } else if (r
!= 0) {
1088 derr
<< "Unexpected error reading metadata: " << cpp_strerror(r
)
1090 ss
<< get_err
.str();
1098 // Dump a single daemon's metadata
1099 f
->open_object_section("mds_metadata");
1100 r
= dump_metadata(fsmap
, who
, f
.get(), ss
);
1104 } else if (prefix
== "mds versions") {
1106 f
.reset(Formatter::create("json-pretty"));
1107 count_metadata("ceph_version", f
.get());
1110 } else if (prefix
== "mds count-metadata") {
1112 f
.reset(Formatter::create("json-pretty"));
1114 cmd_getval(cmdmap
, "property", field
);
1115 count_metadata(field
, f
.get());
1118 } else if (prefix
== "fs compat show") {
1120 cmd_getval(cmdmap
, "fs_name", fs_name
);
1121 const auto &fs
= fsmap
.get_filesystem(fs_name
);
1122 if (fs
== nullptr) {
1123 ss
<< "filesystem '" << fs_name
<< "' not found";
1129 f
->open_object_section("mds_compat");
1130 fs
->mds_map
.compat
.dump(f
.get());
1134 ds
<< fs
->mds_map
.compat
;
1137 } else if (prefix
== "mds compat show") {
1139 f
->open_object_section("mds_compat");
1140 fsmap
.default_compat
.dump(f
.get());
1144 ds
<< fsmap
.default_compat
;
1147 } else if (prefix
== "fs get") {
1149 cmd_getval(cmdmap
, "fs_name", fs_name
);
1150 const auto &fs
= fsmap
.get_filesystem(fs_name
);
1151 if (fs
== nullptr) {
1152 ss
<< "filesystem '" << fs_name
<< "' not found";
1156 f
->open_object_section("filesystem");
1166 } else if (prefix
== "fs ls") {
1168 f
->open_array_section("filesystems");
1169 for (const auto &p
: fsmap
.filesystems
) {
1170 const auto &fs
= p
.second
;
1171 f
->open_object_section("filesystem");
1173 const MDSMap
&mds_map
= fs
->mds_map
;
1174 f
->dump_string("name", mds_map
.fs_name
);
1175 /* Output both the names and IDs of pools, for use by
1176 * humans and machines respectively */
1177 f
->dump_string("metadata_pool", mon
.osdmon()->osdmap
.get_pool_name(
1178 mds_map
.metadata_pool
));
1179 f
->dump_int("metadata_pool_id", mds_map
.metadata_pool
);
1180 f
->open_array_section("data_pool_ids");
1181 for (const auto &id
: mds_map
.data_pools
) {
1182 f
->dump_int("data_pool_id", id
);
1186 f
->open_array_section("data_pools");
1187 for (const auto &id
: mds_map
.data_pools
) {
1188 const auto &name
= mon
.osdmon()->osdmap
.get_pool_name(id
);
1189 f
->dump_string("data_pool", name
);
1198 for (const auto &p
: fsmap
.filesystems
) {
1199 const auto &fs
= p
.second
;
1200 const MDSMap
&mds_map
= fs
->mds_map
;
1201 const string
&md_pool_name
= mon
.osdmon()->osdmap
.get_pool_name(
1202 mds_map
.metadata_pool
);
1204 ds
<< "name: " << mds_map
.fs_name
<< ", metadata pool: "
1205 << md_pool_name
<< ", data pools: [";
1206 for (const auto &id
: mds_map
.data_pools
) {
1207 const string
&pool_name
= mon
.osdmon()->osdmap
.get_pool_name(id
);
1208 ds
<< pool_name
<< " ";
1210 ds
<< "]" << std::endl
;
1213 if (fsmap
.filesystems
.empty()) {
1214 ds
<< "No filesystems enabled" << std::endl
;
1218 } else if (prefix
== "fs feature ls") {
1220 f
->open_array_section("cephfs_features");
1221 for (size_t i
= 0; i
<= CEPHFS_FEATURE_MAX
; ++i
) {
1222 f
->open_object_section("feature");
1223 f
->dump_int("index", i
);
1224 f
->dump_string("name", cephfs_feature_name(i
));
1230 for (size_t i
= 0; i
<= CEPHFS_FEATURE_MAX
; ++i
) {
1231 ds
<< i
<< " " << cephfs_feature_name(i
) << std::endl
;
1235 } else if (prefix
== "fs lsflags") {
1237 cmd_getval(cmdmap
, "fs_name", fs_name
);
1238 const auto &fs
= fsmap
.get_filesystem(fs_name
);
1240 ss
<< "filesystem '" << fs_name
<< "' not found";
1243 const MDSMap
&mds_map
= fs
->mds_map
;
1245 mds_map
.dump_flags_state(f
.get());
1249 mds_map
.print_flags(ds
);
1260 mon
.reply_command(op
, r
, rs
, rdata
, get_last_committed());
1266 bool MDSMonitor::fail_mds_gid(FSMap
&fsmap
, mds_gid_t gid
)
1268 const auto& info
= fsmap
.get_info_gid(gid
);
1269 dout(1) << "fail_mds_gid " << gid
<< " mds." << info
.name
<< " role " << info
.rank
<< dendl
;
1271 ceph_assert(mon
.osdmon()->is_writeable());
1273 epoch_t blocklist_epoch
= 0;
1274 if (info
.rank
>= 0 && info
.state
!= MDSMap::STATE_STANDBY_REPLAY
) {
1275 utime_t until
= ceph_clock_now();
1276 until
+= g_conf().get_val
<double>("mon_mds_blocklist_interval");
1277 blocklist_epoch
= mon
.osdmon()->blocklist(info
.addrs
, until
);
1280 fsmap
.erase(gid
, blocklist_epoch
);
1281 last_beacon
.erase(gid
);
1282 if (pending_daemon_health
.count(gid
)) {
1283 pending_daemon_health
.erase(gid
);
1284 pending_daemon_health_rm
.insert(gid
);
1287 return blocklist_epoch
!= 0;
1290 mds_gid_t
MDSMonitor::gid_from_arg(const FSMap
&fsmap
, const std::string
&arg
, std::ostream
&ss
)
1292 // Try parsing as a role
1294 std::ostringstream ignore_err
; // Don't spam 'ss' with parse_role errors
1295 int r
= fsmap
.parse_role(arg
, &role
, ignore_err
);
1297 // See if a GID is assigned to this role
1298 const auto &fs
= fsmap
.get_filesystem(role
.fscid
);
1299 ceph_assert(fs
!= nullptr); // parse_role ensures it exists
1300 if (fs
->mds_map
.is_up(role
.rank
)) {
1301 dout(10) << __func__
<< ": validated rank/GID " << role
1302 << " as a rank" << dendl
;
1303 return fs
->mds_map
.get_mds_info(role
.rank
).global_id
;
1307 // Try parsing as a gid
1309 unsigned long long maybe_gid
= strict_strtoll(arg
.c_str(), 10, &err
);
1311 // Not a role or a GID, try as a daemon name
1312 const MDSMap::mds_info_t
*mds_info
= fsmap
.find_by_name(arg
);
1314 ss
<< "MDS named '" << arg
1315 << "' does not exist, or is not up";
1316 return MDS_GID_NONE
;
1318 dout(10) << __func__
<< ": resolved MDS name '" << arg
1319 << "' to GID " << mds_info
->global_id
<< dendl
;
1320 return mds_info
->global_id
;
1322 // Not a role, but parses as a an integer, might be a GID
1323 dout(10) << __func__
<< ": treating MDS reference '" << arg
1324 << "' as an integer " << maybe_gid
<< dendl
;
1326 if (fsmap
.gid_exists(mds_gid_t(maybe_gid
))) {
1327 return mds_gid_t(maybe_gid
);
1331 dout(1) << __func__
<< ": rank/GID " << arg
1332 << " not a existent rank or GID" << dendl
;
1333 return MDS_GID_NONE
;
1336 int MDSMonitor::fail_mds(FSMap
&fsmap
, std::ostream
&ss
,
1337 const std::string
&arg
, MDSMap::mds_info_t
*failed_info
)
1339 ceph_assert(failed_info
!= nullptr);
1341 mds_gid_t gid
= gid_from_arg(fsmap
, arg
, ss
);
1342 if (gid
== MDS_GID_NONE
) {
1345 if (!mon
.osdmon()->is_writeable()) {
1349 // Take a copy of the info before removing the MDS from the map,
1350 // so that the caller knows which mds (if any) they ended up removing.
1351 *failed_info
= fsmap
.get_info_gid(gid
);
1353 fail_mds_gid(fsmap
, gid
);
1354 ss
<< "failed mds gid " << gid
;
1355 ceph_assert(mon
.osdmon()->is_writeable());
1356 request_proposal(mon
.osdmon());
1360 bool MDSMonitor::prepare_command(MonOpRequestRef op
)
1362 op
->mark_mdsmon_event(__func__
);
1363 auto m
= op
->get_req
<MMonCommand
>();
1369 if (!cmdmap_from_json(m
->cmd
, &cmdmap
, ss
)) {
1370 string rs
= ss
.str();
1371 mon
.reply_command(op
, -EINVAL
, rs
, rdata
, get_last_committed());
1376 cmd_getval(cmdmap
, "prefix", prefix
);
1378 /* Refuse access if message not associated with a valid session */
1379 MonSession
*session
= op
->get_session();
1381 mon
.reply_command(op
, -EACCES
, "access denied", rdata
, get_last_committed());
1385 auto &pending
= get_pending_fsmap_writeable();
1387 bool batched_propose
= false;
1388 for (const auto &h
: handlers
) {
1389 r
= h
->can_handle(prefix
, op
, pending
, cmdmap
, ss
);
1391 ; // pass, since we got the right handler.
1392 } else if (r
== 0) {
1398 batched_propose
= h
->batched_propose();
1399 if (batched_propose
) {
1402 r
= h
->handle(&mon
, pending
, op
, cmdmap
, ss
);
1403 if (batched_propose
) {
1408 // message has been enqueued for retry; return.
1409 dout(4) << __func__
<< " enqueue for retry by prepare_command" << dendl
;
1413 // On successful updates, print the updated map
1416 // Successful or not, we're done: respond.
1421 r
= filesystem_command(pending
, op
, prefix
, cmdmap
, ss
);
1424 } else if (r
== -EAGAIN
) {
1425 // Do not reply, the message has been enqueued for retry
1426 dout(4) << __func__
<< " enqueue for retry by filesystem_command" << dendl
;
1428 } else if (r
!= -ENOSYS
) {
1432 if (r
== -ENOSYS
&& ss
.str().empty()) {
1433 ss
<< "unrecognized command";
1437 dout(4) << __func__
<< " done, r=" << r
<< dendl
;
1438 /* Compose response */
1443 // success.. delay reply
1444 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, r
, rs
,
1445 get_last_committed() + 1));
1446 if (batched_propose
) {
1447 force_immediate_propose();
1451 // reply immediately
1452 mon
.reply_command(op
, r
, rs
, rdata
, get_last_committed());
1457 int MDSMonitor::filesystem_command(
1460 std::string
const &prefix
,
1461 const cmdmap_t
& cmdmap
,
1462 std::stringstream
&ss
)
1464 dout(4) << __func__
<< " prefix='" << prefix
<< "'" << dendl
;
1465 op
->mark_mdsmon_event(__func__
);
1468 cmd_getval(cmdmap
, "role", whostr
);
1470 if (prefix
== "mds set_state") {
1472 if (!cmd_getval(cmdmap
, "gid", gid
)) {
1473 ss
<< "error parsing 'gid' value '"
1474 << cmd_vartype_stringify(cmdmap
.at("gid")) << "'";
1477 MDSMap::DaemonState state
;
1478 if (!cmd_getval(cmdmap
, "state", state
)) {
1479 ss
<< "error parsing 'state' string value '"
1480 << cmd_vartype_stringify(cmdmap
.at("state")) << "'";
1483 if (fsmap
.gid_exists(gid
, op
->get_session()->get_allowed_fs_names())) {
1484 fsmap
.modify_daemon(gid
, [state
](auto& info
) {
1487 ss
<< "set mds gid " << gid
<< " to state " << state
<< " "
1488 << ceph_mds_state_name(state
);
1491 } else if (prefix
== "mds fail") {
1493 cmd_getval(cmdmap
, "role_or_gid", who
);
1495 MDSMap::mds_info_t failed_info
;
1496 mds_gid_t gid
= gid_from_arg(fsmap
, who
, ss
);
1497 if (gid
== MDS_GID_NONE
) {
1498 ss
<< "MDS named '" << who
<< "' does not exist, is not up or you "
1499 << "lack the permission to see.";
1502 if(!fsmap
.gid_exists(gid
, op
->get_session()->get_allowed_fs_names())) {
1503 ss
<< "MDS named '" << who
<< "' does not exist, is not up or you "
1504 << "lack the permission to see.";
1507 string_view fs_name
= fsmap
.fs_name_from_gid(gid
);
1508 if (!op
->get_session()->fs_name_capable(fs_name
, MON_CAP_W
)) {
1509 ss
<< "Permission denied.";
1513 r
= fail_mds(fsmap
, ss
, who
, &failed_info
);
1514 if (r
< 0 && r
== -EAGAIN
) {
1515 mon
.osdmon()->wait_for_writeable(op
, new C_RetryMessage(this, op
));
1516 return -EAGAIN
; // don't propose yet; wait for message to be retried
1517 } else if (r
== 0) {
1518 // Only log if we really did something (not when was already gone)
1519 if (failed_info
.global_id
!= MDS_GID_NONE
) {
1520 mon
.clog
->info() << failed_info
.human_name() << " marked failed by "
1521 << op
->get_session()->entity_name
;
1524 } else if (prefix
== "mds rm") {
1526 if (!cmd_getval(cmdmap
, "gid", gid
)) {
1527 ss
<< "error parsing 'gid' value '"
1528 << cmd_vartype_stringify(cmdmap
.at("gid")) << "'";
1531 if (!fsmap
.gid_exists(gid
, op
->get_session()->get_allowed_fs_names())) {
1532 ss
<< "mds gid " << gid
<< " does not exist";
1535 string_view fs_name
= fsmap
.fs_name_from_gid(gid
);
1536 if (!op
->get_session()->fs_name_capable(fs_name
, MON_CAP_W
)) {
1537 ss
<< "Permission denied.";
1540 const auto &info
= fsmap
.get_info_gid(gid
);
1541 MDSMap::DaemonState state
= info
.state
;
1543 ss
<< "cannot remove active mds." << info
.name
1544 << " rank " << info
.rank
;
1547 fsmap
.erase(gid
, {});
1548 ss
<< "removed mds gid " << gid
;
1551 } else if (prefix
== "mds rmfailed") {
1552 bool confirm
= false;
1553 cmd_getval(cmdmap
, "yes_i_really_mean_it", confirm
);
1555 ss
<< "WARNING: this can make your filesystem inaccessible! "
1556 "Add --yes-i-really-mean-it if you are sure you wish to continue.";
1560 std::string role_str
;
1561 cmd_getval(cmdmap
, "role", role_str
);
1563 const auto fs_names
= op
->get_session()->get_allowed_fs_names();
1564 int r
= fsmap
.parse_role(role_str
, &role
, ss
, fs_names
);
1566 ss
<< "invalid role '" << role_str
<< "'";
1569 string_view fs_name
= fsmap
.get_filesystem(role
.fscid
)->mds_map
.get_fs_name();
1570 if (!op
->get_session()->fs_name_capable(fs_name
, MON_CAP_W
)) {
1571 ss
<< "Permission denied.";
1575 fsmap
.modify_filesystem(
1577 [role
](std::shared_ptr
<Filesystem
> fs
)
1579 fs
->mds_map
.failed
.erase(role
.rank
);
1582 ss
<< "removed failed mds." << role
;
1584 /* TODO: convert to fs commands to update defaults */
1585 } else if (prefix
== "mds compat rm_compat") {
1587 if (!cmd_getval(cmdmap
, "feature", f
)) {
1588 ss
<< "error parsing feature value '"
1589 << cmd_vartype_stringify(cmdmap
.at("feature")) << "'";
1592 if (fsmap
.default_compat
.compat
.contains(f
)) {
1593 ss
<< "removing compat feature " << f
;
1594 fsmap
.default_compat
.compat
.remove(f
);
1596 ss
<< "compat feature " << f
<< " not present in " << fsmap
.default_compat
;
1599 } else if (prefix
== "mds compat rm_incompat") {
1601 if (!cmd_getval(cmdmap
, "feature", f
)) {
1602 ss
<< "error parsing feature value '"
1603 << cmd_vartype_stringify(cmdmap
.at("feature")) << "'";
1606 if (fsmap
.default_compat
.incompat
.contains(f
)) {
1607 ss
<< "removing incompat feature " << f
;
1608 fsmap
.default_compat
.incompat
.remove(f
);
1610 ss
<< "incompat feature " << f
<< " not present in " << fsmap
.default_compat
;
1613 } else if (prefix
== "mds repaired") {
1614 std::string role_str
;
1615 cmd_getval(cmdmap
, "role", role_str
);
1617 const auto fs_names
= op
->get_session()->get_allowed_fs_names();
1618 r
= fsmap
.parse_role(role_str
, &role
, ss
, fs_names
);
1622 string_view fs_name
= fsmap
.get_filesystem(role
.fscid
)->mds_map
.get_fs_name();
1623 if (!op
->get_session()->fs_name_capable(fs_name
, MON_CAP_W
)) {
1624 ss
<< "Permission denied.";
1628 bool modified
= fsmap
.undamaged(role
.fscid
, role
.rank
);
1630 ss
<< "repaired: restoring rank " << role
;
1632 ss
<< "nothing to do: rank is not damaged";
1636 } else if (prefix
== "mds freeze") {
1638 cmd_getval(cmdmap
, "role_or_gid", who
);
1639 mds_gid_t gid
= gid_from_arg(fsmap
, who
, ss
);
1640 if (gid
== MDS_GID_NONE
) {
1644 string_view fs_name
= fsmap
.fs_name_from_gid(gid
);
1645 if (!op
->get_session()->fs_name_capable(fs_name
, MON_CAP_W
)) {
1646 ss
<< "Permission denied.";
1650 bool freeze
= false;
1653 cmd_getval(cmdmap
, "val", str
);
1654 if ((r
= parse_bool(str
, &freeze
, ss
)) != 0) {
1659 auto f
= [freeze
,gid
,&ss
](auto& info
) {
1661 ss
<< "freezing mds." << gid
;
1664 ss
<< "unfreezing mds." << gid
;
1668 fsmap
.modify_daemon(gid
, f
);
1677 void MDSMonitor::check_subs()
1679 // Subscriptions may be to "mdsmap" (MDS and legacy clients),
1680 // "mdsmap.<namespace>", or to "fsmap" for the full state of all
1681 // filesystems. Build a list of all the types we service
1682 // subscriptions for.
1684 std::vector
<std::string
> types
= {
1690 for (const auto &p
: get_fsmap().filesystems
) {
1691 const auto &fscid
= p
.first
;
1692 CachedStackStringStream cos
;
1693 *cos
<< "mdsmap." << fscid
;
1694 types
.push_back(std::string(cos
->strv()));
1697 for (const auto &type
: types
) {
1698 auto& subs
= mon
.session_map
.subs
;
1699 auto subs_it
= subs
.find(type
);
1700 if (subs_it
== subs
.end())
1702 auto sub_it
= subs_it
->second
->begin();
1703 while (!sub_it
.end()) {
1705 ++sub_it
; // N.B. check_sub may remove sub!
1712 void MDSMonitor::check_sub(Subscription
*sub
)
1714 dout(20) << __func__
<< ": " << sub
->type
<< dendl
;
1716 // to use const qualifier filter fsmap beforehand
1717 FSMap _fsmap_copy
= get_fsmap();
1718 _fsmap_copy
.filter(sub
->session
->get_allowed_fs_names());
1719 const auto& fsmap
= _fsmap_copy
;
1720 if (sub
->next
> fsmap
.get_epoch()) {
1724 if (sub
->type
== "fsmap") {
1725 sub
->session
->con
->send_message(new MFSMap(mon
.monmap
->fsid
, fsmap
));
1727 mon
.session_map
.remove_sub(sub
);
1729 sub
->next
= fsmap
.get_epoch() + 1;
1731 } else if (sub
->type
== "fsmap.user") {
1733 fsmap_u
.epoch
= fsmap
.get_epoch();
1734 fsmap_u
.legacy_client_fscid
= fsmap
.legacy_client_fscid
;
1735 for (const auto &p
: fsmap
.filesystems
) {
1736 FSMapUser::fs_info_t
& fs_info
= fsmap_u
.filesystems
[p
.second
->fscid
];
1737 fs_info
.cid
= p
.second
->fscid
;
1738 fs_info
.name
= p
.second
->mds_map
.fs_name
;
1740 sub
->session
->con
->send_message(new MFSMapUser(mon
.monmap
->fsid
, fsmap_u
));
1742 mon
.session_map
.remove_sub(sub
);
1744 sub
->next
= fsmap
.get_epoch() + 1;
1746 } else if (sub
->type
.compare(0, 6, "mdsmap") == 0) {
1747 const bool is_mds
= sub
->session
->name
.is_mds();
1748 mds_gid_t mds_gid
= MDS_GID_NONE
;
1749 fs_cluster_id_t fscid
= FS_CLUSTER_ID_NONE
;
1751 // What (if any) namespace are you assigned to?
1752 auto mds_info
= fsmap
.get_mds_info();
1753 for (const auto &p
: mds_info
) {
1754 if (p
.second
.addrs
== sub
->session
->addrs
) {
1756 fscid
= fsmap
.mds_roles
.at(mds_gid
);
1760 // You're a client. Did you request a particular
1762 if (sub
->type
.compare(0, 7, "mdsmap.") == 0) {
1763 auto namespace_id_str
= sub
->type
.substr(std::string("mdsmap.").size());
1764 dout(10) << __func__
<< ": namespace_id " << namespace_id_str
<< dendl
;
1766 fscid
= strict_strtoll(namespace_id_str
.c_str(), 10, &err
);
1768 // Client asked for a non-existent namespace, send them nothing
1769 dout(1) << "Invalid client subscription '" << sub
->type
1774 // Unqualified request for "mdsmap": give it the one marked
1775 // for use by legacy clients.
1776 if (fsmap
.legacy_client_fscid
!= FS_CLUSTER_ID_NONE
) {
1777 fscid
= fsmap
.legacy_client_fscid
;
1779 dout(1) << "Client subscribed for legacy filesystem but "
1780 "none is configured" << dendl
;
1784 if (!fsmap
.filesystem_exists(fscid
)) {
1785 // Client asked for a non-existent namespace, send them nothing
1786 // TODO: something more graceful for when a client has a filesystem
1787 // mounted, and the fileysstem is deleted. Add a "shut down you fool"
1789 dout(1) << "Client subscribed to non-existent namespace '" <<
1790 fscid
<< "'" << dendl
;
1794 dout(10) << __func__
<< ": is_mds=" << is_mds
<< ", fscid=" << fscid
<< dendl
;
1796 // Work out the effective latest epoch
1797 const MDSMap
*mds_map
= nullptr;
1798 MDSMap null_map
= MDSMap::create_null_mdsmap();
1799 if (fscid
== FS_CLUSTER_ID_NONE
) {
1800 // For a client, we should have already dropped out
1801 ceph_assert(is_mds
);
1803 auto it
= fsmap
.standby_daemons
.find(mds_gid
);
1804 if (it
!= fsmap
.standby_daemons
.end()) {
1805 // For an MDS, we need to feed it an MDSMap with its own state in
1806 null_map
.mds_info
[mds_gid
] = it
->second
;
1807 null_map
.epoch
= fsmap
.standby_epochs
.at(mds_gid
);
1809 null_map
.epoch
= fsmap
.epoch
;
1811 mds_map
= &null_map
;
1813 // Check the effective epoch
1814 mds_map
= &fsmap
.get_filesystem(fscid
)->mds_map
;
1817 ceph_assert(mds_map
!= nullptr);
1818 dout(10) << __func__
<< " selected MDS map epoch " <<
1819 mds_map
->epoch
<< " for namespace " << fscid
<< " for subscriber "
1820 << sub
->session
->name
<< " who wants epoch " << sub
->next
<< dendl
;
1822 if (sub
->next
> mds_map
->epoch
) {
1825 auto msg
= make_message
<MMDSMap
>(mon
.monmap
->fsid
, *mds_map
);
1827 sub
->session
->con
->send_message(msg
.detach());
1829 mon
.session_map
.remove_sub(sub
);
1831 sub
->next
= mds_map
->get_epoch() + 1;
1837 void MDSMonitor::update_metadata(mds_gid_t gid
,
1838 const map
<string
, string
>& metadata
)
1840 if (metadata
.empty()) {
1843 pending_metadata
[gid
] = metadata
;
1845 MonitorDBStore::TransactionRef t
= paxos
.get_pending_transaction();
1847 encode(pending_metadata
, bl
);
1848 t
->put(MDS_METADATA_PREFIX
, "last_metadata", bl
);
1849 paxos
.trigger_propose();
1852 void MDSMonitor::remove_from_metadata(const FSMap
&fsmap
, MonitorDBStore::TransactionRef t
)
1854 bool update
= false;
1855 for (auto it
= pending_metadata
.begin(); it
!= pending_metadata
.end(); ) {
1856 if (!fsmap
.gid_exists(it
->first
)) {
1857 it
= pending_metadata
.erase(it
);
1866 encode(pending_metadata
, bl
);
1867 t
->put(MDS_METADATA_PREFIX
, "last_metadata", bl
);
1870 int MDSMonitor::load_metadata(map
<mds_gid_t
, Metadata
>& m
)
1873 int r
= mon
.store
->get(MDS_METADATA_PREFIX
, "last_metadata", bl
);
1875 dout(5) << "Unable to load 'last_metadata'" << dendl
;
1879 auto it
= bl
.cbegin();
1880 ceph::decode(m
, it
);
1884 void MDSMonitor::count_metadata(const std::string
&field
, map
<string
,int> *out
)
1886 map
<mds_gid_t
,Metadata
> meta
;
1887 load_metadata(meta
);
1888 for (auto& p
: meta
) {
1889 auto q
= p
.second
.find(field
);
1890 if (q
== p
.second
.end()) {
1891 (*out
)["unknown"]++;
1893 (*out
)[q
->second
]++;
1898 void MDSMonitor::count_metadata(const std::string
&field
, Formatter
*f
)
1900 map
<string
,int> by_val
;
1901 count_metadata(field
, &by_val
);
1902 f
->open_object_section(field
.c_str());
1903 for (auto& p
: by_val
) {
1904 f
->dump_int(p
.first
.c_str(), p
.second
);
1909 void MDSMonitor::get_versions(std::map
<string
, list
<string
> > &versions
)
1911 map
<mds_gid_t
,Metadata
> meta
;
1912 load_metadata(meta
);
1913 const auto &fsmap
= get_fsmap();
1914 std::map
<mds_gid_t
, mds_info_t
> map
= fsmap
.get_mds_info();
1915 dout(10) << __func__
<< " mds meta=" << meta
<< dendl
;
1916 for (auto& p
: meta
) {
1917 auto q
= p
.second
.find("ceph_version_short");
1918 if (q
== p
.second
.end()) continue;
1919 versions
[q
->second
].push_back(string("mds.") + map
[p
.first
].name
);
1923 int MDSMonitor::dump_metadata(const FSMap
& fsmap
, const std::string
&who
,
1924 Formatter
*f
, ostream
& err
)
1928 mds_gid_t gid
= gid_from_arg(fsmap
, who
, err
);
1929 if (gid
== MDS_GID_NONE
) {
1933 map
<mds_gid_t
, Metadata
> metadata
;
1934 if (int r
= load_metadata(metadata
)) {
1935 err
<< "Unable to load 'last_metadata'";
1939 if (!metadata
.count(gid
)) {
1942 const Metadata
& m
= metadata
[gid
];
1943 for (Metadata::const_iterator p
= m
.begin(); p
!= m
.end(); ++p
) {
1944 f
->dump_string(p
->first
.c_str(), p
->second
);
1949 int MDSMonitor::print_nodes(Formatter
*f
)
1953 const auto &fsmap
= get_fsmap();
1955 map
<mds_gid_t
, Metadata
> metadata
;
1956 if (int r
= load_metadata(metadata
)) {
1960 map
<string
, list
<string
> > mdses
; // hostname => mds
1961 for (const auto &p
: metadata
) {
1962 const mds_gid_t
& gid
= p
.first
;
1963 const Metadata
& m
= p
.second
;
1964 Metadata::const_iterator hostname
= m
.find("hostname");
1965 if (hostname
== m
.end()) {
1966 // not likely though
1969 if (!fsmap
.gid_exists(gid
)) {
1970 dout(5) << __func__
<< ": GID " << gid
<< " not existent" << dendl
;
1973 const MDSMap::mds_info_t
& mds_info
= fsmap
.get_info_gid(gid
);
1974 mdses
[hostname
->second
].push_back(mds_info
.name
);
1977 dump_services(f
, mdses
, "mds");
1982 * If a cluster is undersized (with respect to max_mds), then
1983 * attempt to find daemons to grow it. If the cluster is oversized
1984 * (with respect to max_mds) then shrink it by stopping its highest rank.
1986 bool MDSMonitor::maybe_resize_cluster(FSMap
&fsmap
, fs_cluster_id_t fscid
)
1988 auto ¤t_mds_map
= get_fsmap().get_filesystem(fscid
)->mds_map
;
1989 auto&& fs
= fsmap
.get_filesystem(fscid
);
1990 auto &mds_map
= fs
->mds_map
;
1992 int in
= mds_map
.get_num_in_mds();
1993 int max
= mds_map
.get_max_mds();
1995 dout(20) << __func__
<< " in " << in
<< " max " << max
<< dendl
;
1997 /* Check that both the current epoch mds_map is resizeable as well as the
1998 * current batch of changes in pending. This is important if an MDS is
1999 * becoming active in the next epoch.
2001 if (!current_mds_map
.is_resizeable() ||
2002 !mds_map
.is_resizeable()) {
2003 dout(5) << __func__
<< " mds_map is not currently resizeable" << dendl
;
2007 if (in
< max
&& !mds_map
.test_flag(CEPH_MDSMAP_NOT_JOINABLE
)) {
2008 mds_rank_t mds
= mds_rank_t(0);
2009 while (mds_map
.is_in(mds
)) {
2012 auto info
= fsmap
.find_replacement_for({fscid
, mds
});
2017 dout(1) << "assigned standby " << info
->addrs
2018 << " as mds." << mds
<< dendl
;
2019 mon
.clog
->info() << info
->human_name() << " assigned to "
2020 "filesystem " << mds_map
.fs_name
<< " as rank "
2021 << mds
<< " (now has " << mds_map
.get_num_in_mds() + 1
2023 fsmap
.promote(info
->global_id
, *fs
, mds
);
2025 } else if (in
> max
) {
2026 mds_rank_t target
= in
- 1;
2027 const auto &info
= mds_map
.get_info(target
);
2028 if (mds_map
.is_active(target
)) {
2029 dout(1) << "stopping " << target
<< dendl
;
2030 mon
.clog
->info() << "stopping " << info
.human_name();
2031 auto f
= [](auto& info
) {
2032 info
.state
= MDSMap::STATE_STOPPING
;
2034 fsmap
.modify_daemon(info
.global_id
, f
);
2037 dout(20) << "skipping stop of " << target
<< dendl
;
2047 * Fail a daemon and replace it with a suitable standby.
2049 bool MDSMonitor::drop_mds(FSMap
&fsmap
, mds_gid_t gid
, const mds_info_t
* rep_info
, bool *osd_propose
)
2051 ceph_assert(osd_propose
!= nullptr);
2053 const auto fscid
= fsmap
.mds_roles
.at(gid
);
2054 const auto& info
= fsmap
.get_info_gid(gid
);
2055 const auto rank
= info
.rank
;
2056 const auto state
= info
.state
;
2058 if (info
.is_frozen()) {
2060 } else if (state
== MDSMap::STATE_STANDBY_REPLAY
||
2061 state
== MDSMap::STATE_STANDBY
) {
2062 dout(1) << " failing and removing standby " << gid
<< " " << info
.addrs
2064 << "." << info
.inc
<< " " << ceph_mds_state_name(state
)
2066 *osd_propose
|= fail_mds_gid(fsmap
, gid
);
2068 } else if (rank
>= 0 && rep_info
) {
2069 auto fs
= fsmap
.filesystems
.at(fscid
);
2070 if (fs
->mds_map
.test_flag(CEPH_MDSMAP_NOT_JOINABLE
)) {
2074 // and is there a non-laggy standby that can take over for us?
2075 dout(1) << " replacing " << gid
<< " " << info
.addrs
2076 << " mds." << rank
<< "." << info
.inc
2077 << " " << ceph_mds_state_name(state
)
2078 << " with " << rep_info
->global_id
<< "/" << rep_info
->name
<< " " << rep_info
->addrs
2081 mon
.clog
->warn() << "Replacing " << info
.human_name()
2082 << " as rank " << rank
2083 << " with standby " << rep_info
->human_name();
2085 // Remove the old one
2086 *osd_propose
|= fail_mds_gid(fsmap
, gid
);
2088 // Promote the replacement
2089 fsmap
.promote(rep_info
->global_id
, *fs
, rank
);
2096 bool MDSMonitor::check_health(FSMap
& fsmap
, bool* propose_osdmap
)
2098 bool do_propose
= false;
2099 const auto now
= mono_clock::now();
2100 const bool osdmap_writeable
= mon
.osdmon()->is_writeable();
2101 const auto mds_beacon_grace
= g_conf().get_val
<double>("mds_beacon_grace");
2102 const auto mds_beacon_interval
= g_conf().get_val
<double>("mds_beacon_interval");
2104 if (mono_clock::is_zero(last_tick
)) {
2109 auto since_last
= std::chrono::duration
<double>(now
-last_tick
);
2111 if (since_last
.count() > (mds_beacon_grace
-mds_beacon_interval
)) {
2112 // This case handles either local slowness (calls being delayed
2113 // for whatever reason) or cluster election slowness (a long gap
2114 // between calls while an election happened)
2115 dout(1) << __func__
<< ": resetting beacon timeouts due to mon delay "
2116 "(slow election?) of " << since_last
.count() << " seconds" << dendl
;
2117 for (auto& p
: last_beacon
) {
2118 p
.second
.stamp
= now
;
2123 // make sure last_beacon is fully populated
2124 for (auto& p
: fsmap
.mds_roles
) {
2125 auto& gid
= p
.first
;
2126 last_beacon
.emplace(std::piecewise_construct
,
2127 std::forward_as_tuple(gid
),
2128 std::forward_as_tuple(now
, 0));
2131 // We will only take decisive action (replacing/removing a daemon)
2132 // if we have some indication that some other daemon(s) are successfully
2133 // getting beacons through recently.
2134 mono_time latest_beacon
= mono_clock::zero();
2135 for (const auto& p
: last_beacon
) {
2136 latest_beacon
= std::max(p
.second
.stamp
, latest_beacon
);
2138 auto since
= std::chrono::duration
<double>(now
-latest_beacon
);
2139 const bool may_replace
= since
.count() <
2140 std::max(g_conf()->mds_beacon_interval
, g_conf()->mds_beacon_grace
* 0.5);
2142 // check beacon timestamps
2143 std::vector
<mds_gid_t
> to_remove
;
2144 const bool mon_down
= mon
.is_mon_down();
2145 const auto mds_beacon_mon_down_grace
=
2146 g_conf().get_val
<std::chrono::seconds
>("mds_beacon_mon_down_grace");
2147 const auto quorum_age
= std::chrono::seconds(mon
.quorum_age());
2148 const bool new_quorum
= quorum_age
< mds_beacon_mon_down_grace
;
2149 for (auto it
= last_beacon
.begin(); it
!= last_beacon
.end(); ) {
2150 auto& [gid
, beacon_info
] = *it
;
2151 auto since_last
= std::chrono::duration
<double>(now
-beacon_info
.stamp
);
2153 if (!fsmap
.gid_exists(gid
)) {
2154 // gid no longer exists, remove from tracked beacons
2155 it
= last_beacon
.erase(it
);
2159 if (since_last
.count() >= g_conf()->mds_beacon_grace
) {
2160 auto& info
= fsmap
.get_info_gid(gid
);
2161 dout(1) << "no beacon from mds." << info
.rank
<< "." << info
.inc
2162 << " (gid: " << gid
<< " addr: " << info
.addrs
2163 << " state: " << ceph_mds_state_name(info
.state
) << ")"
2164 << " since " << since_last
.count() << dendl
;
2165 if ((mon_down
|| new_quorum
) && since_last
< mds_beacon_mon_down_grace
) {
2166 /* The MDS may be sending beacons to a monitor not yet in quorum or
2167 * temporarily partitioned. Hold off on removal for a little longer...
2169 dout(10) << "deferring removal for mds_beacon_mon_down_grace during MON_DOWN" << dendl
;
2173 // If the OSDMap is writeable, we can blocklist things, so we can
2174 // try failing any laggy MDS daemons. Consider each one for failure.
2175 if (!info
.laggy()) {
2176 dout(1) << " marking " << gid
<< " " << info
.addrs
2177 << " mds." << info
.rank
<< "." << info
.inc
2178 << " " << ceph_mds_state_name(info
.state
)
2179 << " laggy" << dendl
;
2180 fsmap
.modify_daemon(info
.global_id
, [](auto& info
) {
2181 info
.laggy_since
= ceph_clock_now();
2185 if (osdmap_writeable
&& may_replace
) {
2186 to_remove
.push_back(gid
); // drop_mds may invalidate iterator
2193 for (const auto& gid
: to_remove
) {
2194 auto info
= fsmap
.get_info_gid(gid
);
2195 const mds_info_t
* rep_info
= nullptr;
2196 if (info
.rank
>= 0) {
2197 auto fscid
= fsmap
.fscid_from_gid(gid
);
2198 rep_info
= fsmap
.find_replacement_for({fscid
, info
.rank
});
2200 bool dropped
= drop_mds(fsmap
, gid
, rep_info
, propose_osdmap
);
2202 mon
.clog
->info() << "MDS " << info
.human_name()
2203 << " is removed because it is dead or otherwise unavailable.";
2208 if (osdmap_writeable
) {
2209 for (auto& [fscid
, fs
] : fsmap
.filesystems
) {
2210 if (!fs
->mds_map
.test_flag(CEPH_MDSMAP_NOT_JOINABLE
) &&
2211 fs
->mds_map
.is_resizeable()) {
2212 // Check if a rank or standby-replay should be replaced with a stronger
2213 // affinity standby. This looks at ranks and standby-replay:
2214 for (const auto& [gid
, info
] : fs
->mds_map
.get_mds_info()) {
2215 const auto join_fscid
= info
.join_fscid
;
2216 if (join_fscid
== fscid
)
2218 const auto rank
= info
.rank
;
2219 const auto state
= info
.state
;
2220 const mds_info_t
* rep_info
= nullptr;
2221 if (state
== MDSMap::STATE_STANDBY_REPLAY
) {
2222 rep_info
= fsmap
.get_available_standby(*fs
);
2223 } else if (state
== MDSMap::STATE_ACTIVE
) {
2224 rep_info
= fsmap
.find_replacement_for({fscid
, rank
});
2226 /* N.B. !is_degraded() */
2227 ceph_abort_msg("invalid state in MDSMap");
2232 bool better_affinity
= false;
2233 if (join_fscid
== FS_CLUSTER_ID_NONE
) {
2234 better_affinity
= (rep_info
->join_fscid
== fscid
);
2236 better_affinity
= (rep_info
->join_fscid
== fscid
) ||
2237 (rep_info
->join_fscid
== FS_CLUSTER_ID_NONE
);
2239 if (better_affinity
) {
2240 if (state
== MDSMap::STATE_STANDBY_REPLAY
) {
2241 mon
.clog
->info() << "Dropping low affinity standby-replay "
2242 << info
.human_name()
2243 << " in favor of higher affinity standby.";
2244 *propose_osdmap
|= fail_mds_gid(fsmap
, gid
);
2245 /* Now let maybe_promote_standby do the promotion. */
2247 mon
.clog
->info() << "Dropping low affinity active "
2248 << info
.human_name()
2249 << " in favor of higher affinity standby.";
2250 do_propose
|= drop_mds(fsmap
, gid
, rep_info
, propose_osdmap
);
2252 break; /* don't replace more than one per tick per fs */
2261 bool MDSMonitor::maybe_promote_standby(FSMap
&fsmap
, Filesystem
& fs
)
2263 if (fs
.mds_map
.test_flag(CEPH_MDSMAP_NOT_JOINABLE
)) {
2267 bool do_propose
= false;
2269 // have a standby take over?
2270 set
<mds_rank_t
> failed
;
2271 fs
.mds_map
.get_failed_mds_set(failed
);
2272 for (const auto& rank
: failed
) {
2273 auto info
= fsmap
.find_replacement_for({fs
.fscid
, rank
});
2275 dout(1) << " taking over failed mds." << rank
<< " with " << info
->global_id
2276 << "/" << info
->name
<< " " << info
->addrs
<< dendl
;
2277 mon
.clog
->info() << "Standby " << info
->human_name()
2278 << " assigned to filesystem " << fs
.mds_map
.fs_name
2279 << " as rank " << rank
;
2281 fsmap
.promote(info
->global_id
, fs
, rank
);
2286 if (fs
.mds_map
.is_resizeable() && fs
.mds_map
.allows_standby_replay()) {
2287 // There were no failures to replace, so try using any available standbys
2288 // as standby-replay daemons. Don't do this when the cluster is degraded
2289 // as a standby-replay daemon may try to read a journal being migrated.
2291 auto info
= fsmap
.get_available_standby(fs
);
2293 dout(20) << "standby available mds." << info
->global_id
<< dendl
;
2294 bool changed
= false;
2295 for (const auto& rank
: fs
.mds_map
.in
) {
2296 dout(20) << "examining " << rank
<< dendl
;
2297 if (fs
.mds_map
.is_followable(rank
)) {
2298 dout(1) << " setting mds." << info
->global_id
2299 << " to follow mds rank " << rank
<< dendl
;
2300 fsmap
.assign_standby_replay(info
->global_id
, fs
.fscid
, rank
);
2306 if (!changed
) break;
2313 void MDSMonitor::tick()
2315 if (!is_active() || !is_leader()) return;
2317 auto &pending
= get_pending_fsmap_writeable();
2319 bool do_propose
= false;
2320 bool propose_osdmap
= false;
2322 if (check_fsmap_struct_version
) {
2323 /* Allow time for trimming otherwise PaxosService::is_writeable will always
2327 auto now
= clock::now();
2328 auto elapsed
= now
- last_fsmap_struct_flush
;
2329 if (elapsed
> std::chrono::seconds(30)) {
2332 auto v
= get_first_committed();
2333 int err
= get_version(v
, bl
);
2335 derr
<< "could not get version " << v
<< dendl
;
2340 } catch (const ceph::buffer::malformed_input
& e
) {
2341 dout(5) << "flushing old fsmap struct because unable to decode FSMap: " << e
.what() << dendl
;
2343 /* N.B. FSMap::is_struct_old is also true for undecoded (failed to decode) FSMap */
2344 if (fsmap
.is_struct_old()) {
2345 dout(5) << "fsmap struct is too old; proposing to flush out old versions" << dendl
;
2347 last_fsmap_struct_flush
= now
;
2349 dout(20) << "struct is recent" << dendl
;
2350 check_fsmap_struct_version
= false;
2355 do_propose
|= pending
.check_health();
2357 /* Check health and affinity of ranks */
2358 do_propose
|= check_health(pending
, &propose_osdmap
);
2360 /* Resize the cluster according to max_mds. */
2361 for (auto& p
: pending
.filesystems
) {
2362 do_propose
|= maybe_resize_cluster(pending
, p
.second
->fscid
);
2365 /* Replace any failed ranks. */
2366 for (auto& p
: pending
.filesystems
) {
2367 do_propose
|= maybe_promote_standby(pending
, *p
.second
);
2370 if (propose_osdmap
) {
2371 request_proposal(mon
.osdmon());
2378 last_tick
= mono_clock::now();
2381 MDSMonitor::MDSMonitor(Monitor
&mn
, Paxos
&p
, string service_name
)
2382 : PaxosService(mn
, p
, service_name
)
2384 handlers
= FileSystemCommandHandler::load(&p
);
2387 void MDSMonitor::on_restart()
2389 // Clear out the leader-specific state.
2390 last_tick
= mono_clock::now();
2391 last_beacon
.clear();