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) 2004-2006 Sage Weil <sage@newdream.net>
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.
15 #ifndef CEPH_MOSDPGPEERNOTIFY_H
16 #define CEPH_MOSDPGPEERNOTIFY_H
18 #include "msg/Message.h"
20 #include "osd/osd_types.h"
23 * PGNotify - notify primary of my PGs and versions.
26 class MOSDPGNotify : public Message {
28 static const int HEAD_VERSION = 6;
29 static const int COMPAT_VERSION = 2;
32 /// query_epoch is the epoch of the query being responded to, or
33 /// the current epoch if this is not being sent in response to a
34 /// query. This allows the recipient to disregard responses to old
36 vector<pair<pg_notify_t,PastIntervals> > pg_list; // pgid -> version
39 version_t get_epoch() const { return epoch; }
40 const vector<pair<pg_notify_t,PastIntervals> >& get_pg_list() const {
45 : Message(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION) {
46 set_priority(CEPH_MSG_PRIO_HIGH);
48 MOSDPGNotify(epoch_t e, vector<pair<pg_notify_t,PastIntervals> >& l)
49 : Message(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION),
52 set_priority(CEPH_MSG_PRIO_HIGH);
55 ~MOSDPGNotify() override {}
58 const char *get_type_name() const override { return "PGnot"; }
60 void encode_payload(uint64_t features) override {
61 if (HAVE_FEATURE(features, SERVER_LUMINOUS)) {
62 header.version = HEAD_VERSION;
64 // for jewel+kraken compat only
67 // Use query_epoch for first entry for backwards compatibility
68 epoch_t query_epoch = epoch;
70 query_epoch = pg_list.begin()->first.query_epoch;
72 ::encode(epoch, payload);
74 // v2 was vector<pg_info_t>
75 __u32 n = pg_list.size();
77 for (auto p = pg_list.begin();
80 ::encode(p->first.info, payload);
82 ::encode(query_epoch, payload);
84 // v3 needs the PastIntervals for each record
85 for (auto p = pg_list.begin();
88 p->second.encode_classic(payload);
91 // v4 needs epoch_sent, query_epoch
92 for (vector<pair<pg_notify_t,PastIntervals> >::iterator p = pg_list.begin();
95 ::encode(pair<epoch_t, epoch_t>(
96 p->first.epoch_sent, p->first.query_epoch),
100 for (vector<pair<pg_notify_t, PastIntervals> >::iterator p = pg_list.begin();
103 ::encode(p->first.from, payload);
104 ::encode(p->first.to, payload);
109 ::encode(epoch, payload);
110 ::encode(pg_list, payload);
113 void decode_payload() override {
114 bufferlist::iterator p = payload.begin();
115 if (header.version < 6) {
116 // for kraken+jewel compat only
120 // decode pg_info_t portion of the vector
124 for (unsigned i=0; i<n; i++) {
125 ::decode(pg_list[i].first.info, p);
128 ::decode(query_epoch, p);
130 if (header.version >= 3) {
131 // get the PastIntervals portion
132 for (unsigned i=0; i<n; i++) {
133 pg_list[i].second.decode_classic(p);
137 // v3 needs epoch_sent, query_epoch
138 for (auto i = pg_list.begin();
141 if (header.version >= 4) {
142 pair<epoch_t, epoch_t> dec;
144 i->first.epoch_sent = dec.first;
145 i->first.query_epoch = dec.second;
147 i->first.epoch_sent = epoch;
148 i->first.query_epoch = query_epoch;
152 // v5 needs from and to
153 if (header.version >= 5) {
154 for (auto i = pg_list.begin();
157 ::decode(i->first.from, p);
158 ::decode(i->first.to, p);
165 ::decode(pg_list, p);
167 void print(ostream& out) const override {
169 for (auto i = pg_list.begin();
172 if (i != pg_list.begin())
174 out << i->first << "=" << i->second;
176 out << " epoch " << epoch