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());
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
);
609 void MgrMonitor::drop_active()
611 if (last_beacon
.count(pending_map
.active_gid
) > 0) {
612 last_beacon
.erase(pending_map
.active_gid
);
615 pending_metadata_rm
.insert(pending_map
.active_name
);
616 pending_metadata
.erase(pending_map
.active_name
);
617 pending_map
.active_name
= "";
618 pending_map
.active_gid
= 0;
619 pending_map
.available
= false;
620 pending_map
.active_addr
= entity_addr_t();
622 // So that when new active mgr subscribes to mgrdigest, it will
623 // get an immediate response instead of waiting for next timer
627 void MgrMonitor::drop_standby(uint64_t gid
)
629 pending_metadata_rm
.insert(pending_map
.standbys
[gid
].name
);
630 pending_metadata
.erase(pending_map
.standbys
[gid
].name
);
631 pending_map
.standbys
.erase(gid
);
632 if (last_beacon
.count(gid
) > 0) {
633 last_beacon
.erase(gid
);
637 bool MgrMonitor::preprocess_command(MonOpRequestRef op
)
639 MMonCommand
*m
= static_cast<MMonCommand
*>(op
->get_req());
640 std::stringstream ss
;
643 std::map
<std::string
, cmd_vartype
> cmdmap
;
644 if (!cmdmap_from_json(m
->cmd
, &cmdmap
, ss
)) {
645 string rs
= ss
.str();
646 mon
->reply_command(op
, -EINVAL
, rs
, rdata
, get_last_committed());
650 MonSession
*session
= m
->get_session();
652 mon
->reply_command(op
, -EACCES
, "access denied", rdata
,
653 get_last_committed());
658 cmd_getval(g_ceph_context
, cmdmap
, "format", format
, string("json-pretty"));
659 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
));
662 cmd_getval(g_ceph_context
, cmdmap
, "prefix", prefix
);
665 if (prefix
== "mgr dump") {
667 cmd_getval(g_ceph_context
, cmdmap
, "epoch", epoch
, (int64_t)map
.get_epoch());
668 if (epoch
== (int64_t)map
.get_epoch()) {
669 f
->dump_object("mgrmap", map
);
672 int err
= get_version(epoch
, bl
);
673 if (err
== -ENOENT
) {
675 ss
<< "there is no map for epoch " << epoch
;
681 f
->dump_object("mgrmap", m
);
684 } else if (prefix
== "mgr module ls") {
685 f
->open_array_section("modules");
686 for (auto& p
: map
.modules
) {
687 f
->dump_string("module", p
);
691 } else if (prefix
== "mgr metadata") {
693 cmd_getval(g_ceph_context
, cmdmap
, "id", name
);
694 if (name
.size() > 0 && !map
.have_name(name
)) {
695 ss
<< "mgr." << name
<< " does not exist";
700 cmd_getval(g_ceph_context
, cmdmap
, "format", format
);
701 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
, "json-pretty", "json-pretty"));
703 f
->open_object_section("mgr_metadata");
704 f
->dump_string("id", name
);
705 r
= dump_metadata(name
, f
.get(), &ss
);
711 f
->open_array_section("mgr_metadata");
712 for (auto& i
: map
.get_all_names()) {
713 f
->open_object_section("mgr");
714 f
->dump_string("id", i
);
715 r
= dump_metadata(i
, f
.get(), NULL
);
716 if (r
== -EINVAL
|| r
== -ENOENT
) {
717 // Drop error, continue to get other daemons' metadata
718 dout(4) << "No metadata for mgr." << i
<< dendl
;
729 } else if (prefix
== "mgr versions") {
731 f
.reset(Formatter::create("json-pretty"));
732 count_metadata("ceph_version", f
.get());
735 } else if (prefix
== "mgr count-metadata") {
737 f
.reset(Formatter::create("json-pretty"));
739 cmd_getval(g_ceph_context
, cmdmap
, "property", field
);
740 count_metadata(field
, f
.get());
750 mon
->reply_command(op
, r
, rs
, rdata
, get_last_committed());
754 bool MgrMonitor::prepare_command(MonOpRequestRef op
)
756 MMonCommand
*m
= static_cast<MMonCommand
*>(op
->get_req());
758 std::stringstream ss
;
761 std::map
<std::string
, cmd_vartype
> cmdmap
;
762 if (!cmdmap_from_json(m
->cmd
, &cmdmap
, ss
)) {
763 string rs
= ss
.str();
764 mon
->reply_command(op
, -EINVAL
, rs
, rdata
, get_last_committed());
768 MonSession
*session
= m
->get_session();
770 mon
->reply_command(op
, -EACCES
, "access denied", rdata
, get_last_committed());
775 cmd_getval(g_ceph_context
, cmdmap
, "format", format
, string("plain"));
776 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
));
779 cmd_getval(g_ceph_context
, cmdmap
, "prefix", prefix
);
783 if (prefix
== "mgr fail") {
785 cmd_getval(g_ceph_context
, cmdmap
, "who", who
);
788 uint64_t gid
= strict_strtol(who
.c_str(), 10, &err
);
789 bool changed
= false;
791 // Does not parse as a gid, treat it as a name
792 if (pending_map
.active_name
== who
) {
797 for (const auto &i
: pending_map
.standbys
) {
798 if (i
.second
.name
== who
) {
807 ss
<< "Daemon not found '" << who
<< "', already failed?";
811 if (pending_map
.active_gid
== gid
) {
814 } else if (pending_map
.standbys
.count(gid
) > 0) {
818 ss
<< "Daemon not found '" << gid
<< "', already failed?";
822 if (changed
&& pending_map
.active_gid
== 0) {
825 } else if (prefix
== "mgr module enable") {
827 cmd_getval(g_ceph_context
, cmdmap
, "module", module
);
828 if (module
.empty()) {
833 cmd_getval(g_ceph_context
, cmdmap
, "force", force
);
834 if (!pending_map
.all_support_module(module
) &&
835 force
!= "--force") {
836 ss
<< "all mgr daemons do not support module '" << module
<< "', pass "
837 << "--force to force enablement";
841 pending_map
.modules
.insert(module
);
842 } else if (prefix
== "mgr module disable") {
844 cmd_getval(g_ceph_context
, cmdmap
, "module", module
);
845 if (module
.empty()) {
849 pending_map
.modules
.erase(module
);
851 ss
<< "Command '" << prefix
<< "' not implemented!";
856 dout(4) << __func__
<< " done, r=" << r
<< dendl
;
857 /* Compose response */
862 // success.. delay reply
863 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, r
, rs
,
864 get_last_committed() + 1));
868 mon
->reply_command(op
, r
, rs
, rdata
, get_last_committed());
873 void MgrMonitor::init()
875 if (digest_event
== nullptr) {
876 send_digests(); // To get it to schedule its own event
880 void MgrMonitor::on_shutdown()
885 int MgrMonitor::load_metadata(const string
& name
, std::map
<string
, string
>& m
,
889 int r
= mon
->store
->get(MGR_METADATA_PREFIX
, name
, bl
);
893 bufferlist::iterator p
= bl
.begin();
896 catch (buffer::error
& e
) {
898 *err
<< "mgr." << name
<< " metadata is corrupt";
904 void MgrMonitor::count_metadata(const string
& field
, std::map
<string
,int> *out
)
906 std::set
<string
> ls
= map
.get_all_names();
907 for (auto& name
: ls
) {
908 std::map
<string
,string
> meta
;
909 load_metadata(name
, meta
, nullptr);
910 auto p
= meta
.find(field
);
911 if (p
== meta
.end()) {
919 void MgrMonitor::count_metadata(const string
& field
, Formatter
*f
)
921 std::map
<string
,int> by_val
;
922 count_metadata(field
, &by_val
);
923 f
->open_object_section(field
.c_str());
924 for (auto& p
: by_val
) {
925 f
->dump_int(p
.first
.c_str(), p
.second
);
930 int MgrMonitor::dump_metadata(const string
& name
, Formatter
*f
, ostream
*err
)
932 std::map
<string
,string
> m
;
933 if (int r
= load_metadata(name
, m
, err
))
936 f
->dump_string(p
.first
.c_str(), p
.second
);