]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/messages/MOSDPGNotify.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / messages / MOSDPGNotify.h
index a73bf05692a4dad1e5aa11e0fa02b4746ddd979b..a3b237c1a8b05b6b46c767cd6f160d88b9da7fc0 100644 (file)
  * PGNotify - notify primary of my PGs and versions.
  */
 
-class MOSDPGNotify : public Message {
-
-  static const int HEAD_VERSION = 6;
-  static const int COMPAT_VERSION = 2;
+class MOSDPGNotify final : public Message {
+private:
+  static constexpr int HEAD_VERSION = 7;
+  static constexpr int COMPAT_VERSION = 6;
 
   epoch_t epoch = 0;
   /// query_epoch is the epoch of the query being responded to, or
   /// the current epoch if this is not being sent in response to a
   /// query. This allows the recipient to disregard responses to old
   /// queries.
-  vector<pair<pg_notify_t,PastIntervals> > pg_list;   // pgid -> version
+  using pg_list_t = std::vector<pg_notify_t>;
+  pg_list_t pg_list;
 
  public:
   version_t get_epoch() const { return epoch; }
-  const vector<pair<pg_notify_t,PastIntervals> >& get_pg_list() const {
+  const pg_list_t& get_pg_list() const {
     return pg_list;
   }
 
   MOSDPGNotify()
-    : Message(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION) { 
-    set_priority(CEPH_MSG_PRIO_HIGH);
-  }
-  MOSDPGNotify(epoch_t e, vector<pair<pg_notify_t,PastIntervals> >& l)
-    : Message(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION),
-      epoch(e) {
-    pg_list.swap(l);
+    : MOSDPGNotify(0, {})
+  {}
+  MOSDPGNotify(epoch_t e, pg_list_t&& l)
+    : Message{MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION},
+      epoch(e),
+      pg_list(std::move(l)) {
     set_priority(CEPH_MSG_PRIO_HIGH);
   }
 private:
-  ~MOSDPGNotify() override {}
+  ~MOSDPGNotify() final {}
 
 public:  
-  const char *get_type_name() const override { return "PGnot"; }
+  std::string_view get_type_name() const override { return "PGnot"; }
 
   void encode_payload(uint64_t features) override {
-    if (HAVE_FEATURE(features, SERVER_LUMINOUS)) {
-      header.version = HEAD_VERSION;
-    } else {
-      // for jewel+kraken compat only
-      header.version = 5;
-
-      // Use query_epoch for first entry for backwards compatibility
-      epoch_t query_epoch = epoch;
-      if (pg_list.size())
-       query_epoch = pg_list.begin()->first.query_epoch;
-    
-      ::encode(epoch, payload);
-
-      // v2 was vector<pg_info_t>
-      __u32 n = pg_list.size();
-      ::encode(n, payload);
-      for (auto p = pg_list.begin();
-          p != pg_list.end();
-          p++)
-       ::encode(p->first.info, payload);
-
-      ::encode(query_epoch, payload);
-
-      // v3 needs the PastIntervals for each record
-      for (auto p = pg_list.begin();
-          p != pg_list.end();
-          p++) {
-       p->second.encode_classic(payload);
-      }
-
-      // v4 needs epoch_sent, query_epoch
-      for (vector<pair<pg_notify_t,PastIntervals> >::iterator p = pg_list.begin();
-          p != pg_list.end();
-          p++)
-       ::encode(pair<epoch_t, epoch_t>(
-                  p->first.epoch_sent, p->first.query_epoch),
-                payload);
-
-      // v5 needs from, to
-      for (vector<pair<pg_notify_t, PastIntervals> >::iterator p = pg_list.begin();
-          p != pg_list.end();
-          ++p) {
-       ::encode(p->first.from, payload);
-       ::encode(p->first.to, payload);
+    using ceph::encode;
+    header.version = HEAD_VERSION;
+    encode(epoch, payload);
+    if (!HAVE_FEATURE(features, SERVER_OCTOPUS)) {
+      // pretend to be vector<pair<pg_notify_t,PastIntervals>>
+      header.version = 6;
+      encode((uint32_t)pg_list.size(), payload);
+      for (auto& i : pg_list) {
+       encode(i, payload);   // this embeds a dup (ignored) PastIntervals
+       encode(i.past_intervals, payload);
       }
       return;
     }
-
-    ::encode(epoch, payload);
-    ::encode(pg_list, payload);
+    encode(pg_list, payload);
   }
 
   void decode_payload() override {
-    bufferlist::iterator p = payload.begin();
-    if (header.version < 6) {
-      // for kraken+jewel compat only
-      epoch_t query_epoch;
-      ::decode(epoch, p);
-
-      // decode pg_info_t portion of the vector
-      __u32 n;
-      ::decode(n, p);
-      pg_list.resize(n);
-      for (unsigned i=0; i<n; i++) {
-       ::decode(pg_list[i].first.info, p);
-      }
-
-      ::decode(query_epoch, p);
-
-      if (header.version >= 3) {
-       // get the PastIntervals portion
-       for (unsigned i=0; i<n; i++) {
-         pg_list[i].second.decode_classic(p);
-       }
-      }
-
-      // v3 needs epoch_sent, query_epoch
-      for (auto i = pg_list.begin();
-          i != pg_list.end();
-          i++) {
-       if (header.version >= 4) {
-         pair<epoch_t, epoch_t> dec;
-         ::decode(dec, p);
-         i->first.epoch_sent = dec.first;
-         i->first.query_epoch = dec.second;
-       } else {
-         i->first.epoch_sent = epoch;
-         i->first.query_epoch = query_epoch;
-       }
-      }
-
-      // v5 needs from and to
-      if (header.version >= 5) {
-       for (auto i = pg_list.begin();
-            i != pg_list.end();
-            i++) {
-         ::decode(i->first.from, p);
-         ::decode(i->first.to, p);
-       }
+    auto p = payload.cbegin();
+    using ceph::decode;
+    decode(epoch, p);
+    if (header.version == 6) {
+      // decode legacy vector<pair<pg_notify_t,PastIntervals>>
+      uint32_t num;
+      decode(num, p);
+      pg_list.resize(num);
+      for (unsigned i = 0; i < num; ++i) {
+       decode(pg_list[i], p);
+       decode(pg_list[i].past_intervals, p);
       }
       return;
     }
-
-    ::decode(epoch, p);
-    ::decode(pg_list, p);
+    decode(pg_list, p);
   }
-  void print(ostream& out) const override {
+  void print(std::ostream& out) const override {
     out << "pg_notify(";
     for (auto i = pg_list.begin();
          i != pg_list.end();
          ++i) {
       if (i != pg_list.begin())
        out << " ";
-      out << i->first << "=" << i->second;
+      out << *i;
     }
     out << " epoch " << epoch
        << ")";
   }
+private:
+  template<class T, typename... Args>
+  friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
 };
 
 #endif