]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * | |
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. | |
12 | * | |
13 | */ | |
14 | ||
15 | #ifndef CEPH_MOSDPGPEERNOTIFY_H | |
16 | #define CEPH_MOSDPGPEERNOTIFY_H | |
17 | ||
18 | #include "msg/Message.h" | |
19 | ||
20 | #include "osd/osd_types.h" | |
21 | ||
22 | /* | |
23 | * PGNotify - notify primary of my PGs and versions. | |
24 | */ | |
25 | ||
26 | class MOSDPGNotify : public Message { | |
27 | ||
28 | static const int HEAD_VERSION = 6; | |
29 | static const int COMPAT_VERSION = 2; | |
30 | ||
31 | epoch_t epoch; | |
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 | |
35 | /// queries. | |
36 | vector<pair<pg_notify_t,PastIntervals> > pg_list; // pgid -> version | |
37 | ||
38 | public: | |
39 | version_t get_epoch() const { return epoch; } | |
40 | const vector<pair<pg_notify_t,PastIntervals> >& get_pg_list() const { | |
41 | return pg_list; | |
42 | } | |
43 | ||
44 | MOSDPGNotify() | |
45 | : Message(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION) { | |
46 | set_priority(CEPH_MSG_PRIO_HIGH); | |
47 | } | |
48 | MOSDPGNotify(epoch_t e, vector<pair<pg_notify_t,PastIntervals> >& l) | |
49 | : Message(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION), | |
50 | epoch(e) { | |
51 | pg_list.swap(l); | |
52 | set_priority(CEPH_MSG_PRIO_HIGH); | |
53 | } | |
54 | private: | |
55 | ~MOSDPGNotify() override {} | |
56 | ||
57 | public: | |
58 | const char *get_type_name() const override { return "PGnot"; } | |
59 | ||
60 | void encode_payload(uint64_t features) override { | |
c07f9fc5 FG |
61 | if (HAVE_FEATURE(features, SERVER_LUMINOUS)) { |
62 | header.version = HEAD_VERSION; | |
63 | } else { | |
7c673cae FG |
64 | // for jewel+kraken compat only |
65 | header.version = 5; | |
66 | ||
67 | // Use query_epoch for first entry for backwards compatibility | |
68 | epoch_t query_epoch = epoch; | |
69 | if (pg_list.size()) | |
70 | query_epoch = pg_list.begin()->first.query_epoch; | |
71 | ||
72 | ::encode(epoch, payload); | |
73 | ||
74 | // v2 was vector<pg_info_t> | |
75 | __u32 n = pg_list.size(); | |
76 | ::encode(n, payload); | |
77 | for (auto p = pg_list.begin(); | |
78 | p != pg_list.end(); | |
79 | p++) | |
80 | ::encode(p->first.info, payload); | |
81 | ||
82 | ::encode(query_epoch, payload); | |
83 | ||
84 | // v3 needs the PastIntervals for each record | |
85 | for (auto p = pg_list.begin(); | |
86 | p != pg_list.end(); | |
87 | p++) { | |
88 | p->second.encode_classic(payload); | |
89 | } | |
90 | ||
91 | // v4 needs epoch_sent, query_epoch | |
92 | for (vector<pair<pg_notify_t,PastIntervals> >::iterator p = pg_list.begin(); | |
93 | p != pg_list.end(); | |
94 | p++) | |
95 | ::encode(pair<epoch_t, epoch_t>( | |
96 | p->first.epoch_sent, p->first.query_epoch), | |
97 | payload); | |
98 | ||
99 | // v5 needs from, to | |
100 | for (vector<pair<pg_notify_t, PastIntervals> >::iterator p = pg_list.begin(); | |
101 | p != pg_list.end(); | |
102 | ++p) { | |
103 | ::encode(p->first.from, payload); | |
104 | ::encode(p->first.to, payload); | |
105 | } | |
106 | return; | |
107 | } | |
108 | ||
109 | ::encode(epoch, payload); | |
110 | ::encode(pg_list, payload); | |
111 | } | |
112 | ||
113 | void decode_payload() override { | |
114 | bufferlist::iterator p = payload.begin(); | |
115 | if (header.version < 6) { | |
116 | // for kraken+jewel compat only | |
117 | epoch_t query_epoch; | |
118 | ::decode(epoch, p); | |
119 | ||
120 | // decode pg_info_t portion of the vector | |
121 | __u32 n; | |
122 | ::decode(n, p); | |
123 | pg_list.resize(n); | |
124 | for (unsigned i=0; i<n; i++) { | |
125 | ::decode(pg_list[i].first.info, p); | |
126 | } | |
127 | ||
128 | ::decode(query_epoch, p); | |
129 | ||
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); | |
134 | } | |
135 | } | |
136 | ||
137 | // v3 needs epoch_sent, query_epoch | |
138 | for (auto i = pg_list.begin(); | |
139 | i != pg_list.end(); | |
140 | i++) { | |
141 | if (header.version >= 4) { | |
142 | pair<epoch_t, epoch_t> dec; | |
143 | ::decode(dec, p); | |
144 | i->first.epoch_sent = dec.first; | |
145 | i->first.query_epoch = dec.second; | |
146 | } else { | |
147 | i->first.epoch_sent = epoch; | |
148 | i->first.query_epoch = query_epoch; | |
149 | } | |
150 | } | |
151 | ||
152 | // v5 needs from and to | |
153 | if (header.version >= 5) { | |
154 | for (auto i = pg_list.begin(); | |
155 | i != pg_list.end(); | |
156 | i++) { | |
157 | ::decode(i->first.from, p); | |
158 | ::decode(i->first.to, p); | |
159 | } | |
160 | } | |
161 | return; | |
162 | } | |
163 | ||
164 | ::decode(epoch, p); | |
165 | ::decode(pg_list, p); | |
166 | } | |
167 | void print(ostream& out) const override { | |
168 | out << "pg_notify("; | |
169 | for (auto i = pg_list.begin(); | |
170 | i != pg_list.end(); | |
171 | ++i) { | |
172 | if (i != pg_list.begin()) | |
173 | out << " "; | |
174 | out << i->first << "=" << i->second; | |
175 | } | |
176 | out << " epoch " << epoch | |
177 | << ")"; | |
178 | } | |
179 | }; | |
180 | ||
181 | #endif |