]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: persist ServiceMap
authorSage Weil <sage@redhat.com>
Mon, 26 Jun 2017 17:20:58 +0000 (13:20 -0400)
committerSage Weil <sage@redhat.com>
Sun, 9 Jul 2017 02:30:28 +0000 (22:30 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/messages/MMonMgrReport.h
src/messages/MServiceMap.h [new file with mode: 0644]
src/mon/MgrStatMonitor.cc
src/mon/MgrStatMonitor.h
src/mon/Monitor.cc
src/msg/Message.cc
src/msg/Message.h

index bf91519eb5c2e8f23b4efc2e41e4be73baf90b9e..8f3a8fe9115402ca8184ddfc07e3f8cba3622a12 100644 (file)
@@ -37,6 +37,7 @@ class MMonMgrReport : public PaxosServiceMessage {
 public:
   // PGMapDigest is in data payload
   list<pair<health_status_t,std::string>> health_summary, health_detail;
+  bufferlist service_map_bl;  // encoded ServiceMap
 
   MMonMgrReport()
     : PaxosServiceMessage(MSG_MON_MGR_REPORT, 0, HEAD_VERSION, COMPAT_VERSION)
@@ -55,12 +56,14 @@ public:
     paxos_encode();
     ::encode(health_summary, payload);
     ::encode(health_detail, payload);
+    ::encode(service_map_bl, payload);
   }
   void decode_payload() override {
     bufferlist::iterator p = payload.begin();
     paxos_decode(p);
     ::decode(health_summary, p);
     ::decode(health_detail, p);
+    ::decode(service_map_bl, p);
   }
 };
 
diff --git a/src/messages/MServiceMap.h b/src/messages/MServiceMap.h
new file mode 100644 (file)
index 0000000..b7dd913
--- /dev/null
@@ -0,0 +1,34 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include "msg/Message.h"
+#include "mgr/ServiceMap.h"
+
+class MServiceMap : public Message {
+public:
+  ServiceMap service_map;
+
+  MServiceMap() : Message(MSG_SERVICE_MAP) { }
+  explicit MServiceMap(const ServiceMap& sm)
+    : Message(MSG_SERVICE_MAP),
+      service_map(sm) {
+  }
+private:
+  ~MServiceMap() override {}
+
+public:
+  const char *get_type_name() const override { return "service_map"; }
+  void print(ostream& out) const override {
+    out << "service_map(e" << service_map.epoch << " "
+       << service_map.services.size() << " svc)";
+  }
+  void encode_payload(uint64_t features) override {
+    ::encode(service_map, payload, features);
+  }
+  void decode_payload() override {
+    bufferlist::iterator p = payload.begin();
+    ::decode(service_map, p);
+  }
+};
index 658b7001d6e2c39a11dd4915bcc35fb9093fe1f8..ab0d4623b877f49aa8d387caec47044df9d849fc 100644 (file)
@@ -10,6 +10,7 @@
 #include "messages/MMonMgrReport.h"
 #include "messages/MStatfs.h"
 #include "messages/MStatfsReply.h"
+#include "messages/MServiceMap.h"
 
 class MgrPGStatService : public MonPGStatService {
   PGMapDigest& digest;
@@ -72,6 +73,8 @@ void MgrStatMonitor::create_initial()
 {
   dout(10) << dendl;
   version = 0;
+  service_map.epoch = 1;
+  ::encode(service_map, pending_service_map_bl, CEPH_FEATURES_ALL);
 }
 
 void MgrStatMonitor::update_from_paxos(bool *need_bootstrap)
@@ -86,7 +89,11 @@ void MgrStatMonitor::update_from_paxos(bool *need_bootstrap)
     ::decode(digest, p);
     ::decode(health_summary, p);
     ::decode(health_detail, p);
+    ::decode(service_map, p);
+    dout(10) << __func__ << " v" << version
+            << " service_map e" << service_map.epoch << dendl;
   }
+  check_subs();
 }
 
 void MgrStatMonitor::create_pending()
@@ -95,6 +102,8 @@ void MgrStatMonitor::create_pending()
   pending_digest = digest;
   pending_health_summary = health_summary;
   pending_health_detail = health_detail;
+  pending_service_map_bl.clear();
+  ::encode(service_map, pending_service_map_bl, mon->get_quorum_con_features());
 }
 
 void MgrStatMonitor::encode_pending(MonitorDBStore::TransactionRef t)
@@ -110,6 +119,8 @@ void MgrStatMonitor::encode_pending(MonitorDBStore::TransactionRef t)
   ::encode(pending_digest, bl, mon->get_quorum_con_features());
   ::encode(pending_health_summary, bl);
   ::encode(pending_health_detail, bl);
+  assert(pending_service_map_bl.length());
+  bl.append(pending_service_map_bl);
   put_version(t, version, bl);
   put_last_committed(t, version);
 }
@@ -194,6 +205,9 @@ bool MgrStatMonitor::prepare_report(MonOpRequestRef op)
   dout(10) << __func__ << " " << pending_digest << dendl;
   pending_health_summary.swap(m->health_summary);
   pending_health_detail.swap(m->health_detail);
+  if (m->service_map_bl.length()) {
+    pending_service_map_bl.swap(m->service_map_bl);
+  }
   return true;
 }
 
@@ -264,3 +278,40 @@ bool MgrStatMonitor::preprocess_statfs(MonOpRequestRef op)
   mon->send_reply(op, reply);
   return true;
 }
+
+void MgrStatMonitor::check_sub(Subscription *sub)
+{
+  const auto epoch = mon->monmap->get_epoch();
+  dout(10) << __func__
+          << " next " << sub->next
+          << " have " << epoch << dendl;
+  if (sub->next <= service_map.epoch) {
+    auto m = new MServiceMap(service_map);
+    sub->session->con->send_message(m);
+    if (sub->onetime) {
+      mon->with_session_map([this, sub](MonSessionMap& session_map) {
+         session_map.remove_sub(sub);
+       });
+    } else {
+      sub->next = epoch + 1;
+    }
+  }
+}
+
+void MgrStatMonitor::check_subs()
+{
+  dout(10) << __func__ << dendl;
+  if (!service_map.epoch) {
+    return;
+  }
+  auto subs = mon->session_map.subs.find("servicemap");
+  if (subs == mon->session_map.subs.end()) {
+    return;
+  }
+  auto p = subs->second->begin();
+  while (!p.end()) {
+    auto sub = *p;
+    ++p;
+    check_sub(sub);
+  }
+}
index 7ecbc9d377f5d53d6528109bba305f343790ee07..bd96ec8376e6ae8979936d672eddd09b42f23b75 100644 (file)
@@ -6,6 +6,7 @@
 #include "include/Context.h"
 #include "PaxosService.h"
 #include "mon/PGMap.h"
+#include "mgr/ServiceMap.h"
 
 class MonPGStatService;
 class MgrPGStatService;
@@ -16,11 +17,13 @@ class MgrStatMonitor : public PaxosService {
   PGMapDigest digest;
   list<pair<health_status_t,string>> health_summary;
   list<pair<health_status_t,string>> health_detail;
+  ServiceMap service_map;
 
   // pending commit
   PGMapDigest pending_digest;
   list<pair<health_status_t,string>> pending_health_summary;
   list<pair<health_status_t,string>> pending_health_detail;
+  bufferlist pending_service_map_bl;
 
   std::unique_ptr<MgrPGStatService> pgservice;
 
@@ -66,6 +69,9 @@ public:
   void print_summary(Formatter *f, std::ostream *ss) const;
 
   MonPGStatService *get_pg_stat_service();
+  const ServiceMap& get_service_map() {
+    return service_map;
+  }
 
   friend class C_Updated;
 };
index 9c936b1c940013d5b3149c79af46dd22355bdedc..5a22db7a8e338db383564fa61c4638fab3ef69b5 100644 (file)
@@ -4619,6 +4619,8 @@ void Monitor::handle_subscribe(MonOpRequestRef op)
       logmon()->check_sub(s->sub_map[p->first]);
     } else if (p->first == "mgrmap" || p->first == "mgrdigest") {
       mgrmon()->check_sub(s->sub_map[p->first]);
+    } else if (p->first == "servicemap") {
+      mgrstatmon()->check_sub(s->sub_map[p->first]);
     }
   }
 
index 8232ba39c438a341ae12175ca47fbe9d2712c79a..4860889989fe9c16719fe91d8fd84fe4cd22cc11 100644 (file)
@@ -169,6 +169,7 @@ using namespace std;
 #include "messages/MMgrOpen.h"
 #include "messages/MMgrConfigure.h"
 #include "messages/MMonMgrReport.h"
+#include "messages/MServiceMap.h"
 
 #include "messages/MLock.h"
 
@@ -751,6 +752,10 @@ Message *decode_message(CephContext *cct, int crcflags,
     m = new MMonMgrReport();
     break;
 
+  case MSG_SERVICE_MAP:
+    m = new MServiceMap();
+    break;
+
   case MSG_MGR_MAP:
     m = new MMgrMap();
     break;
index b7220e2de28aa0584958059a7f27369231a50c84..611d691df992c474bb67b311c553f7929e43b8ad 100644 (file)
 #define MSG_MGR_DIGEST               0x705
 // *** cephmgr -> ceph-mon
 #define MSG_MON_MGR_REPORT        0x706
+#define MSG_SERVICE_MAP           0x707
 
 // ======================================================