From e4258ce04b55238af7e9421d5273298a6d1bd633 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 11 Feb 2012 14:29:52 -0800 Subject: [PATCH] mon: move quorum_status into helper Signed-off-by: Sage Weil --- src/mon/Monitor.cc | 42 ++++++++++++++++++++++++------------------ src/mon/Monitor.h | 1 + 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index bce1abb1d18..176212ec625 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -778,6 +778,29 @@ bool Monitor::_allowed_command(MonSession *s, const vector& cmd) return false; } +void Monitor::_quorum_status(ostream& ss) +{ + if (!is_leader() && !is_peon()) { + return; + } + + JSONFormatter jf(true); + jf.open_object_section("quorum_status"); + jf.dump_int("election_epoch", get_epoch()); + + jf.open_array_section("quorum"); + for (set::iterator p = quorum.begin(); p != quorum.end(); ++p) + jf.dump_int("mon", *p); + jf.close_section(); + + jf.open_object_section("monmap"); + monmap->dump(&jf); + jf.close_section(); + + jf.close_section(); + jf.flush(ss); +} + void Monitor::_mon_status(ostream& ss) { JSONFormatter jf(true); @@ -903,31 +926,14 @@ void Monitor::handle_command(MMonCommand *m) return; } if (m->cmd[0] == "quorum_status") { - // make sure our map is readable and up to date if (!is_leader() && !is_peon()) { dout(10) << " waiting for qorum" << dendl; waitfor_quorum.push_back(new C_RetryMessage(this, m)); return; } - - JSONFormatter jf(true); - jf.open_object_section("quorum_status"); - jf.dump_int("election_epoch", get_epoch()); - - jf.open_array_section("quorum"); - for (set::iterator p = quorum.begin(); p != quorum.end(); ++p) - jf.dump_int("mon", *p); - jf.close_section(); - - jf.open_object_section("monmap"); - monmap->dump(&jf); - jf.close_section(); - - jf.close_section(); - stringstream ss; - jf.flush(ss); + _quorum_status(ss); rs = ss.str(); r = 0; } diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index ad92e96ef7f..96b1acaa03a 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -240,6 +240,7 @@ public: void handle_mon_get_map(MMonGetMap *m); bool _allowed_command(MonSession *s, const vector& cmd); void _mon_status(ostream& ss); + void _quorum_status(ostream& ss); void handle_command(class MMonCommand *m); void handle_observe(MMonObserve *m); void handle_route(MRoute *m);