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) 2016 John Spray <john.spray@redhat.com>
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.
14 #include <boost/tokenizer.hpp>
16 #include "messages/MMgrBeacon.h"
17 #include "messages/MMgrMap.h"
18 #include "messages/MMgrDigest.h"
20 #include "PGStatService.h"
21 #include "include/stringify.h"
22 #include "mgr/MgrContext.h"
23 #include "mgr/mgr_commands.h"
24 #include "OSDMonitor.h"
26 #include "MgrMonitor.h"
28 #define MGR_METADATA_PREFIX "mgr_metadata"
30 #define dout_subsys ceph_subsys_mon
32 #define dout_prefix _prefix(_dout, mon, map)
33 static ostream
& _prefix(std::ostream
*_dout
, Monitor
*mon
,
34 const MgrMap
& mgrmap
) {
35 return *_dout
<< "mon." << mon
->name
<< "@" << mon
->rank
36 << "(" << mon
->get_state_name()
37 << ").mgr e" << mgrmap
.get_epoch() << " ";
40 // Prefix for mon store of active mgr's command descriptions
41 const static std::string command_descs_prefix
= "mgr_command_descs";
44 void MgrMonitor::create_initial()
46 boost::tokenizer
<> tok(g_conf
->mgr_initial_modules
);
48 pending_map
.modules
.insert(m
);
50 pending_command_descs
= mgr_commands
;
51 dout(10) << __func__
<< " initial modules " << pending_map
.modules
52 << ", " << pending_command_descs
.size() << " commands"
56 void MgrMonitor::update_from_paxos(bool *need_bootstrap
)
58 version_t version
= get_last_committed();
59 if (version
!= map
.epoch
) {
60 dout(4) << "loading version " << version
<< dendl
;
63 int err
= get_version(version
, bl
);
66 bool old_available
= map
.get_available();
67 uint64_t old_gid
= map
.get_active_gid();
69 bufferlist::iterator p
= bl
.begin();
72 dout(4) << "active server: " << map
.active_addr
73 << "(" << map
.active_gid
<< ")" << dendl
;
75 ever_had_active_mgr
= get_value("ever_had_active_mgr");
80 first_seen_inactive
= utime_t();
82 first_seen_inactive
= ceph_clock_now();
88 || (map
.get_available()
89 && (!old_available
|| old_gid
!= map
.get_active_gid()))) {
90 dout(4) << "mkfs or daemon transitioned to available, loading commands"
92 bufferlist loaded_commands
;
93 int r
= mon
->store
->get(command_descs_prefix
, "", loaded_commands
);
95 derr
<< "Failed to load mgr commands: " << cpp_strerror(r
) << dendl
;
97 auto p
= loaded_commands
.begin();
98 ::decode(command_descs
, p
);
103 // feed our pet MgrClient
104 mon
->mgr_client
.ms_dispatch(new MMgrMap(map
));
107 void MgrMonitor::create_pending()
113 health_status_t
MgrMonitor::should_warn_about_mgr_down()
115 utime_t now
= ceph_clock_now();
117 // - we've ever had an active mgr, or
118 // - we have osds AND we've exceeded the grace period
119 // which means a new mon cluster and be HEALTH_OK indefinitely as long as
120 // no OSDs are ever created.
121 if (ever_had_active_mgr
||
122 (mon
->osdmon()->osdmap
.get_num_osds() > 0 &&
123 now
> mon
->monmap
->created
+ g_conf
->mon_mgr_mkfs_grace
)) {
124 health_status_t level
= HEALTH_WARN
;
125 if (first_seen_inactive
!= utime_t() &&
126 now
- first_seen_inactive
> g_conf
->mon_mgr_inactive_grace
) {
134 void MgrMonitor::encode_pending(MonitorDBStore::TransactionRef t
)
136 dout(10) << __func__
<< " " << pending_map
<< dendl
;
138 pending_map
.encode(bl
, mon
->get_quorum_con_features());
139 put_version(t
, pending_map
.epoch
, bl
);
140 put_last_committed(t
, pending_map
.epoch
);
142 for (auto& p
: pending_metadata
) {
143 dout(10) << __func__
<< " set metadata for " << p
.first
<< dendl
;
144 t
->put(MGR_METADATA_PREFIX
, p
.first
, p
.second
);
146 for (auto& name
: pending_metadata_rm
) {
147 dout(10) << __func__
<< " rm metadata for " << name
<< dendl
;
148 t
->erase(MGR_METADATA_PREFIX
, name
);
150 pending_metadata
.clear();
151 pending_metadata_rm
.clear();
153 health_check_map_t next
;
154 if (pending_map
.active_gid
== 0) {
155 auto level
= should_warn_about_mgr_down();
156 if (level
!= HEALTH_OK
) {
157 next
.add("MGR_DOWN", level
, "no active mgr");
159 dout(10) << __func__
<< " no health warning (never active and new cluster)"
163 put_value(t
, "ever_had_active_mgr", 1);
165 encode_health(next
, t
);
167 if (pending_command_descs
.size()) {
168 dout(4) << __func__
<< " encoding " << pending_command_descs
.size()
169 << " command_descs" << dendl
;
170 for (auto& p
: pending_command_descs
) {
171 p
.set_flag(MonCommand::FLAG_MGR
);
174 ::encode(pending_command_descs
, bl
);
175 t
->put(command_descs_prefix
, "", bl
);
176 pending_command_descs
.clear();
180 bool MgrMonitor::check_caps(MonOpRequestRef op
, const uuid_d
& fsid
)
183 MonSession
*session
= op
->get_session();
186 if (!session
->is_capable("mgr", MON_CAP_X
)) {
187 dout(1) << __func__
<< " insufficient caps " << session
->caps
<< dendl
;
190 if (fsid
!= mon
->monmap
->fsid
) {
191 dout(1) << __func__
<< " op fsid " << fsid
192 << " != " << mon
->monmap
->fsid
<< dendl
;
198 bool MgrMonitor::preprocess_query(MonOpRequestRef op
)
200 PaxosServiceMessage
*m
= static_cast<PaxosServiceMessage
*>(op
->get_req());
201 switch (m
->get_type()) {
203 return preprocess_beacon(op
);
204 case MSG_MON_COMMAND
:
205 return preprocess_command(op
);
208 derr
<< "Unhandled message type " << m
->get_type() << dendl
;
213 bool MgrMonitor::prepare_update(MonOpRequestRef op
)
215 PaxosServiceMessage
*m
= static_cast<PaxosServiceMessage
*>(op
->get_req());
216 switch (m
->get_type()) {
218 return prepare_beacon(op
);
220 case MSG_MON_COMMAND
:
221 return prepare_command(op
);
225 derr
<< "Unhandled message type " << m
->get_type() << dendl
;
232 class C_Updated
: public Context
{
236 C_Updated(MgrMonitor
*a
, MonOpRequestRef c
) :
238 void finish(int r
) override
{
241 } else if (r
== -ECANCELED
) {
242 mm
->mon
->no_reply(op
);
244 mm
->dispatch(op
); // try again
249 bool MgrMonitor::preprocess_beacon(MonOpRequestRef op
)
251 MMgrBeacon
*m
= static_cast<MMgrBeacon
*>(op
->get_req());
252 dout(4) << "beacon from " << m
->get_gid() << dendl
;
254 if (!check_caps(op
, m
->get_fsid())) {
255 // drop it on the floor
259 // always send this to the leader's prepare_beacon()
263 bool MgrMonitor::prepare_beacon(MonOpRequestRef op
)
265 MMgrBeacon
*m
= static_cast<MMgrBeacon
*>(op
->get_req());
266 dout(4) << "beacon from " << m
->get_gid() << dendl
;
268 // See if we are seeing same name, new GID for the active daemon
269 if (m
->get_name() == pending_map
.active_name
270 && m
->get_gid() != pending_map
.active_gid
)
272 dout(4) << "Active daemon restart (mgr." << m
->get_name() << ")" << dendl
;
273 mon
->clog
->info() << "Active manager daemon " << m
->get_name()
278 // See if we are seeing same name, new GID for any standbys
279 for (const auto &i
: pending_map
.standbys
) {
280 const StandbyInfo
&s
= i
.second
;
281 if (s
.name
== m
->get_name() && s
.gid
!= m
->get_gid()) {
282 dout(4) << "Standby daemon restart (mgr." << m
->get_name() << ")" << dendl
;
283 mon
->clog
->debug() << "Standby manager daemon " << m
->get_name()
285 drop_standby(i
.first
);
290 last_beacon
[m
->get_gid()] = ceph::coarse_mono_clock::now();
292 // Track whether we modified pending_map
293 bool updated
= false;
295 if (pending_map
.active_gid
== m
->get_gid()) {
296 // A beacon from the currently active daemon
297 if (pending_map
.active_addr
!= m
->get_server_addr()) {
298 dout(4) << "learned address " << m
->get_server_addr()
299 << " (was " << pending_map
.active_addr
<< ")" << dendl
;
300 pending_map
.active_addr
= m
->get_server_addr();
304 if (pending_map
.get_available() != m
->get_available()) {
305 dout(4) << "available " << m
->get_gid() << dendl
;
306 mon
->clog
->info() << "Manager daemon " << pending_map
.active_name
307 << " is now available";
309 // This beacon should include command descriptions
310 pending_command_descs
= m
->get_command_descs();
311 if (pending_command_descs
.empty()) {
312 // This should not happen, but it also isn't fatal: we just
313 // won't successfully update our list of commands.
314 dout(4) << "First available beacon from " << pending_map
.active_name
315 << "(" << m
->get_gid() << ") does not include command descs"
318 dout(4) << "First available beacon from " << pending_map
.active_name
319 << "(" << m
->get_gid() << ") includes "
320 << pending_command_descs
.size() << " command descs" << dendl
;
323 pending_map
.available
= m
->get_available();
326 if (pending_map
.available_modules
!= m
->get_available_modules()) {
327 dout(4) << "available_modules " << m
->get_available_modules()
328 << " (was " << pending_map
.available_modules
<< ")" << dendl
;
329 pending_map
.available_modules
= m
->get_available_modules();
332 } else if (pending_map
.active_gid
== 0) {
333 // There is no currently active daemon, select this one.
334 if (pending_map
.standbys
.count(m
->get_gid())) {
335 drop_standby(m
->get_gid(), false);
337 dout(4) << "selecting new active " << m
->get_gid()
338 << " " << m
->get_name()
339 << " (was " << pending_map
.active_gid
<< " "
340 << pending_map
.active_name
<< ")" << dendl
;
341 pending_map
.active_gid
= m
->get_gid();
342 pending_map
.active_name
= m
->get_name();
343 pending_map
.available_modules
= m
->get_available_modules();
344 ::encode(m
->get_metadata(), pending_metadata
[m
->get_name()]);
345 pending_metadata_rm
.erase(m
->get_name());
347 mon
->clog
->info() << "Activating manager daemon "
348 << pending_map
.active_name
;
352 if (pending_map
.standbys
.count(m
->get_gid()) > 0) {
353 dout(10) << "from existing standby " << m
->get_gid() << dendl
;
354 if (pending_map
.standbys
[m
->get_gid()].available_modules
!=
355 m
->get_available_modules()) {
356 dout(10) << "existing standby " << m
->get_gid() << " available_modules "
357 << m
->get_available_modules() << " (was "
358 << pending_map
.standbys
[m
->get_gid()].available_modules
<< ")"
360 pending_map
.standbys
[m
->get_gid()].available_modules
=
361 m
->get_available_modules();
365 dout(10) << "new standby " << m
->get_gid() << dendl
;
366 mon
->clog
->debug() << "Standby manager daemon " << m
->get_name()
368 pending_map
.standbys
[m
->get_gid()] = {m
->get_gid(), m
->get_name(),
369 m
->get_available_modules()};
370 ::encode(m
->get_metadata(), pending_metadata
[m
->get_name()]);
371 pending_metadata_rm
.erase(m
->get_name());
377 dout(4) << "updating map" << dendl
;
378 wait_for_finished_proposal(op
, new C_Updated(this, op
));
380 dout(10) << "no change" << dendl
;
386 void MgrMonitor::check_subs()
388 const std::string type
= "mgrmap";
389 if (mon
->session_map
.subs
.count(type
) == 0)
391 for (auto sub
: *(mon
->session_map
.subs
[type
])) {
396 void MgrMonitor::check_sub(Subscription
*sub
)
398 if (sub
->type
== "mgrmap") {
399 if (sub
->next
<= map
.get_epoch()) {
400 dout(20) << "Sending map to subscriber " << sub
->session
->con
401 << " " << sub
->session
->con
->get_peer_addr() << dendl
;
402 sub
->session
->con
->send_message(new MMgrMap(map
));
404 mon
->session_map
.remove_sub(sub
);
406 sub
->next
= map
.get_epoch() + 1;
410 assert(sub
->type
== "mgrdigest");
411 if (sub
->next
== 0) {
412 // new registration; cancel previous timer
415 if (digest_event
== nullptr) {
422 * Handle digest subscriptions separately (outside of check_sub) because
423 * they are going to be periodic rather than version-driven.
425 void MgrMonitor::send_digests()
432 dout(10) << __func__
<< dendl
;
434 const std::string type
= "mgrdigest";
435 if (mon
->session_map
.subs
.count(type
) == 0)
438 for (auto sub
: *(mon
->session_map
.subs
[type
])) {
439 dout(10) << __func__
<< " sending digest to subscriber " << sub
->session
->con
440 << " " << sub
->session
->con
->get_peer_addr() << dendl
;
441 MMgrDigest
*mdigest
= new MMgrDigest
;
444 mon
->get_health_status(true, &f
, nullptr, nullptr, nullptr);
445 f
.flush(mdigest
->health_json
);
448 std::ostringstream ss
;
449 mon
->get_mon_status(&f
, ss
);
450 f
.flush(mdigest
->mon_status_json
);
453 sub
->session
->con
->send_message(mdigest
);
456 digest_event
= new C_MonContext(mon
, [this](int){
459 mon
->timer
.add_event_after(g_conf
->mon_mgr_digest_period
, digest_event
);
462 void MgrMonitor::cancel_timer()
465 mon
->timer
.cancel_event(digest_event
);
466 digest_event
= nullptr;
470 void MgrMonitor::on_active()
472 if (mon
->is_leader()) {
473 mon
->clog
->debug() << "mgrmap e" << map
.epoch
<< ": " << map
;
477 void MgrMonitor::get_health(
478 list
<pair
<health_status_t
,string
> >& summary
,
479 list
<pair
<health_status_t
,string
> > *detail
,
480 CephContext
*cct
) const
482 // start mgr warnings as soon as the mons and osds are all upgraded,
483 // but before the require_luminous osdmap flag is set. this way the
484 // user gets some warning before the osd flag is set and mgr is
485 // actually *required*.
486 if (!mon
->monmap
->get_required_features().contains_all(
487 ceph::features::mon::FEATURE_LUMINOUS
) ||
488 !HAVE_FEATURE(mon
->osdmon()->osdmap
.get_up_osd_features(),
493 if (map
.active_gid
== 0) {
494 auto level
= HEALTH_WARN
;
495 // do not escalate to ERR if they are still upgrading to jewel.
496 if (mon
->osdmon()->osdmap
.require_osd_release
>= CEPH_RELEASE_LUMINOUS
) {
497 utime_t now
= ceph_clock_now();
498 if (first_seen_inactive
!= utime_t() &&
499 now
- first_seen_inactive
> g_conf
->mon_mgr_inactive_grace
) {
503 summary
.push_back(make_pair(level
, "no active mgr"));
507 void MgrMonitor::tick()
509 if (!is_active() || !mon
->is_leader())
512 const auto now
= ceph::coarse_mono_clock::now();
513 const auto cutoff
= now
- std::chrono::seconds(g_conf
->mon_mgr_beacon_grace
);
515 // Populate any missing beacons (i.e. no beacon since MgrMonitor
516 // instantiation) with the current time, so that they will
517 // eventually look laggy if they fail to give us a beacon.
518 if (pending_map
.active_gid
!= 0
519 && last_beacon
.count(pending_map
.active_gid
) == 0) {
520 last_beacon
[pending_map
.active_gid
] = now
;
522 for (auto s
: pending_map
.standbys
) {
523 if (last_beacon
.count(s
.first
) == 0) {
524 last_beacon
[s
.first
] = now
;
528 // Cull standbys first so that any remaining standbys
529 // will be eligible to take over from the active if we cull him.
530 std::list
<uint64_t> dead_standbys
;
531 for (const auto &i
: pending_map
.standbys
) {
532 auto last_beacon_time
= last_beacon
.at(i
.first
);
533 if (last_beacon_time
< cutoff
) {
534 dead_standbys
.push_back(i
.first
);
538 bool propose
= false;
540 for (auto i
: dead_standbys
) {
541 dout(4) << "Dropping laggy standby " << i
<< dendl
;
546 if (pending_map
.active_gid
!= 0
547 && last_beacon
.at(pending_map
.active_gid
) < cutoff
) {
548 const std::string old_active_name
= pending_map
.active_name
;
551 dout(4) << "Dropping active" << pending_map
.active_gid
<< dendl
;
552 if (promote_standby()) {
553 dout(4) << "Promoted standby " << pending_map
.active_gid
<< dendl
;
554 mon
->clog
->info() << "Manager daemon " << old_active_name
555 << " is unresponsive, replacing it with standby"
556 << " daemon " << pending_map
.active_name
;
558 dout(4) << "Active is laggy but have no standbys to replace it" << dendl
;
559 mon
->clog
->warn() << "Manager daemon " << old_active_name
560 << " is unresponsive. No standby daemons available.";
562 } else if (pending_map
.active_gid
== 0) {
563 if (promote_standby()) {
564 dout(4) << "Promoted standby " << pending_map
.active_gid
<< dendl
;
565 mon
->clog
->info() << "Activating manager daemon "
566 << pending_map
.active_name
;
571 if (!pending_map
.available
&&
572 !ever_had_active_mgr
&&
573 should_warn_about_mgr_down() != HEALTH_OK
) {
574 dout(10) << " exceeded mon_mgr_mkfs_grace " << g_conf
->mon_mgr_mkfs_grace
575 << " seconds" << dendl
;
584 void MgrMonitor::on_restart()
586 // Clear out the leader-specific state.
591 bool MgrMonitor::promote_standby()
593 assert(pending_map
.active_gid
== 0);
594 if (pending_map
.standbys
.size()) {
595 // Promote a replacement (arbitrary choice of standby)
596 auto replacement_gid
= pending_map
.standbys
.begin()->first
;
597 pending_map
.active_gid
= replacement_gid
;
598 pending_map
.active_name
= pending_map
.standbys
.at(replacement_gid
).name
;
599 pending_map
.available
= false;
600 pending_map
.active_addr
= entity_addr_t();
602 drop_standby(replacement_gid
, false);
610 void MgrMonitor::drop_active()
612 if (last_beacon
.count(pending_map
.active_gid
) > 0) {
613 last_beacon
.erase(pending_map
.active_gid
);
616 pending_metadata_rm
.insert(pending_map
.active_name
);
617 pending_metadata
.erase(pending_map
.active_name
);
618 pending_map
.active_name
= "";
619 pending_map
.active_gid
= 0;
620 pending_map
.available
= false;
621 pending_map
.active_addr
= entity_addr_t();
623 // So that when new active mgr subscribes to mgrdigest, it will
624 // get an immediate response instead of waiting for next timer
628 void MgrMonitor::drop_standby(uint64_t gid
, bool drop_meta
)
631 pending_metadata_rm
.insert(pending_map
.standbys
[gid
].name
);
632 pending_metadata
.erase(pending_map
.standbys
[gid
].name
);
634 pending_map
.standbys
.erase(gid
);
635 if (last_beacon
.count(gid
) > 0) {
636 last_beacon
.erase(gid
);
640 bool MgrMonitor::preprocess_command(MonOpRequestRef op
)
642 MMonCommand
*m
= static_cast<MMonCommand
*>(op
->get_req());
643 std::stringstream ss
;
646 std::map
<std::string
, cmd_vartype
> cmdmap
;
647 if (!cmdmap_from_json(m
->cmd
, &cmdmap
, ss
)) {
648 string rs
= ss
.str();
649 mon
->reply_command(op
, -EINVAL
, rs
, rdata
, get_last_committed());
653 MonSession
*session
= m
->get_session();
655 mon
->reply_command(op
, -EACCES
, "access denied", rdata
,
656 get_last_committed());
661 cmd_getval(g_ceph_context
, cmdmap
, "format", format
, string("json-pretty"));
662 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
));
665 cmd_getval(g_ceph_context
, cmdmap
, "prefix", prefix
);
668 if (prefix
== "mgr dump") {
670 cmd_getval(g_ceph_context
, cmdmap
, "epoch", epoch
, (int64_t)map
.get_epoch());
671 if (epoch
== (int64_t)map
.get_epoch()) {
672 f
->dump_object("mgrmap", map
);
675 int err
= get_version(epoch
, bl
);
676 if (err
== -ENOENT
) {
678 ss
<< "there is no map for epoch " << epoch
;
684 f
->dump_object("mgrmap", m
);
687 } else if (prefix
== "mgr module ls") {
688 f
->open_array_section("modules");
689 for (auto& p
: map
.modules
) {
690 f
->dump_string("module", p
);
694 } else if (prefix
== "mgr metadata") {
696 cmd_getval(g_ceph_context
, cmdmap
, "id", name
);
697 if (name
.size() > 0 && !map
.have_name(name
)) {
698 ss
<< "mgr." << name
<< " does not exist";
703 cmd_getval(g_ceph_context
, cmdmap
, "format", format
);
704 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
, "json-pretty", "json-pretty"));
706 f
->open_object_section("mgr_metadata");
707 f
->dump_string("id", name
);
708 r
= dump_metadata(name
, f
.get(), &ss
);
714 f
->open_array_section("mgr_metadata");
715 for (auto& i
: map
.get_all_names()) {
716 f
->open_object_section("mgr");
717 f
->dump_string("id", i
);
718 r
= dump_metadata(i
, f
.get(), NULL
);
719 if (r
== -EINVAL
|| r
== -ENOENT
) {
720 // Drop error, continue to get other daemons' metadata
721 dout(4) << "No metadata for mgr." << i
<< dendl
;
732 } else if (prefix
== "mgr versions") {
734 f
.reset(Formatter::create("json-pretty"));
735 count_metadata("ceph_version", f
.get());
738 } else if (prefix
== "mgr count-metadata") {
740 f
.reset(Formatter::create("json-pretty"));
742 cmd_getval(g_ceph_context
, cmdmap
, "property", field
);
743 count_metadata(field
, f
.get());
753 mon
->reply_command(op
, r
, rs
, rdata
, get_last_committed());
757 bool MgrMonitor::prepare_command(MonOpRequestRef op
)
759 MMonCommand
*m
= static_cast<MMonCommand
*>(op
->get_req());
761 std::stringstream ss
;
764 std::map
<std::string
, cmd_vartype
> cmdmap
;
765 if (!cmdmap_from_json(m
->cmd
, &cmdmap
, ss
)) {
766 string rs
= ss
.str();
767 mon
->reply_command(op
, -EINVAL
, rs
, rdata
, get_last_committed());
771 MonSession
*session
= m
->get_session();
773 mon
->reply_command(op
, -EACCES
, "access denied", rdata
, get_last_committed());
778 cmd_getval(g_ceph_context
, cmdmap
, "format", format
, string("plain"));
779 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
));
782 cmd_getval(g_ceph_context
, cmdmap
, "prefix", prefix
);
786 if (prefix
== "mgr fail") {
788 cmd_getval(g_ceph_context
, cmdmap
, "who", who
);
791 uint64_t gid
= strict_strtol(who
.c_str(), 10, &err
);
792 bool changed
= false;
794 // Does not parse as a gid, treat it as a name
795 if (pending_map
.active_name
== who
) {
800 for (const auto &i
: pending_map
.standbys
) {
801 if (i
.second
.name
== who
) {
810 ss
<< "Daemon not found '" << who
<< "', already failed?";
814 if (pending_map
.active_gid
== gid
) {
817 } else if (pending_map
.standbys
.count(gid
) > 0) {
821 ss
<< "Daemon not found '" << gid
<< "', already failed?";
825 if (changed
&& pending_map
.active_gid
== 0) {
828 } else if (prefix
== "mgr module enable") {
830 cmd_getval(g_ceph_context
, cmdmap
, "module", module
);
831 if (module
.empty()) {
836 cmd_getval(g_ceph_context
, cmdmap
, "force", force
);
837 if (!pending_map
.all_support_module(module
) &&
838 force
!= "--force") {
839 ss
<< "all mgr daemons do not support module '" << module
<< "', pass "
840 << "--force to force enablement";
844 pending_map
.modules
.insert(module
);
845 } else if (prefix
== "mgr module disable") {
847 cmd_getval(g_ceph_context
, cmdmap
, "module", module
);
848 if (module
.empty()) {
852 pending_map
.modules
.erase(module
);
854 ss
<< "Command '" << prefix
<< "' not implemented!";
859 dout(4) << __func__
<< " done, r=" << r
<< dendl
;
860 /* Compose response */
865 // success.. delay reply
866 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, r
, rs
,
867 get_last_committed() + 1));
871 mon
->reply_command(op
, r
, rs
, rdata
, get_last_committed());
876 void MgrMonitor::init()
878 if (digest_event
== nullptr) {
879 send_digests(); // To get it to schedule its own event
883 void MgrMonitor::on_shutdown()
888 int MgrMonitor::load_metadata(const string
& name
, std::map
<string
, string
>& m
,
892 int r
= mon
->store
->get(MGR_METADATA_PREFIX
, name
, bl
);
896 bufferlist::iterator p
= bl
.begin();
899 catch (buffer::error
& e
) {
901 *err
<< "mgr." << name
<< " metadata is corrupt";
907 void MgrMonitor::count_metadata(const string
& field
, std::map
<string
,int> *out
)
909 std::set
<string
> ls
= map
.get_all_names();
910 for (auto& name
: ls
) {
911 std::map
<string
,string
> meta
;
912 load_metadata(name
, meta
, nullptr);
913 auto p
= meta
.find(field
);
914 if (p
== meta
.end()) {
922 void MgrMonitor::count_metadata(const string
& field
, Formatter
*f
)
924 std::map
<string
,int> by_val
;
925 count_metadata(field
, &by_val
);
926 f
->open_object_section(field
.c_str());
927 for (auto& p
: by_val
) {
928 f
->dump_int(p
.first
.c_str(), p
.second
);
933 int MgrMonitor::dump_metadata(const string
& name
, Formatter
*f
, ostream
*err
)
935 std::map
<string
,string
> m
;
936 if (int r
= load_metadata(name
, m
, err
))
939 f
->dump_string(p
.first
.c_str(), p
.second
);
944 const std::vector
<MonCommand
> &MgrMonitor::get_command_descs() const
946 if (command_descs
.empty()) {
947 // must have just upgraded; fallback to static commands
950 return command_descs
;