]>
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 { | |
61 | if (!HAVE_FEATURE(features, SERVER_LUMINOUS)) { | |
62 | // for jewel+kraken compat only | |
63 | header.version = 5; | |
64 | ||
65 | // Use query_epoch for first entry for backwards compatibility | |
66 | epoch_t query_epoch = epoch; | |
67 | if (pg_list.size()) | |
68 | query_epoch = pg_list.begin()->first.query_epoch; | |
69 | ||
70 | ::encode(epoch, payload); | |
71 | ||
72 | // v2 was vector<pg_info_t> | |
73 | __u32 n = pg_list.size(); | |
74 | ::encode(n, payload); | |
75 | for (auto p = pg_list.begin(); | |
76 | p != pg_list.end(); | |
77 | p++) | |
78 | ::encode(p->first.info, payload); | |
79 | ||
80 | ::encode(query_epoch, payload); | |
81 | ||
82 | // v3 needs the PastIntervals for each record | |
83 | for (auto p = pg_list.begin(); | |
84 | p != pg_list.end(); | |
85 | p++) { | |
86 | p->second.encode_classic(payload); | |
87 | } | |
88 | ||
89 | // v4 needs epoch_sent, query_epoch | |
90 | for (vector<pair<pg_notify_t,PastIntervals> >::iterator p = pg_list.begin(); | |
91 | p != pg_list.end(); | |
92 | p++) | |
93 | ::encode(pair<epoch_t, epoch_t>( | |
94 | p->first.epoch_sent, p->first.query_epoch), | |
95 | payload); | |
96 | ||
97 | // v5 needs from, to | |
98 | for (vector<pair<pg_notify_t, PastIntervals> >::iterator p = pg_list.begin(); | |
99 | p != pg_list.end(); | |
100 | ++p) { | |
101 | ::encode(p->first.from, payload); | |
102 | ::encode(p->first.to, payload); | |
103 | } | |
104 | return; | |
105 | } | |
106 | ||
107 | ::encode(epoch, payload); | |
108 | ::encode(pg_list, payload); | |
109 | } | |
110 | ||
111 | void decode_payload() override { | |
112 | bufferlist::iterator p = payload.begin(); | |
113 | if (header.version < 6) { | |
114 | // for kraken+jewel compat only | |
115 | epoch_t query_epoch; | |
116 | ::decode(epoch, p); | |
117 | ||
118 | // decode pg_info_t portion of the vector | |
119 | __u32 n; | |
120 | ::decode(n, p); | |
121 | pg_list.resize(n); | |
122 | for (unsigned i=0; i<n; i++) { | |
123 | ::decode(pg_list[i].first.info, p); | |
124 | } | |
125 | ||
126 | ::decode(query_epoch, p); | |
127 | ||
128 | if (header.version >= 3) { | |
129 | // get the PastIntervals portion | |
130 | for (unsigned i=0; i<n; i++) { | |
131 | pg_list[i].second.decode_classic(p); | |
132 | } | |
133 | } | |
134 | ||
135 | // v3 needs epoch_sent, query_epoch | |
136 | for (auto i = pg_list.begin(); | |
137 | i != pg_list.end(); | |
138 | i++) { | |
139 | if (header.version >= 4) { | |
140 | pair<epoch_t, epoch_t> dec; | |
141 | ::decode(dec, p); | |
142 | i->first.epoch_sent = dec.first; | |
143 | i->first.query_epoch = dec.second; | |
144 | } else { | |
145 | i->first.epoch_sent = epoch; | |
146 | i->first.query_epoch = query_epoch; | |
147 | } | |
148 | } | |
149 | ||
150 | // v5 needs from and to | |
151 | if (header.version >= 5) { | |
152 | for (auto i = pg_list.begin(); | |
153 | i != pg_list.end(); | |
154 | i++) { | |
155 | ::decode(i->first.from, p); | |
156 | ::decode(i->first.to, p); | |
157 | } | |
158 | } | |
159 | return; | |
160 | } | |
161 | ||
162 | ::decode(epoch, p); | |
163 | ::decode(pg_list, p); | |
164 | } | |
165 | void print(ostream& out) const override { | |
166 | out << "pg_notify("; | |
167 | for (auto i = pg_list.begin(); | |
168 | i != pg_list.end(); | |
169 | ++i) { | |
170 | if (i != pg_list.begin()) | |
171 | out << " "; | |
172 | out << i->first << "=" << i->second; | |
173 | } | |
174 | out << " epoch " << epoch | |
175 | << ")"; | |
176 | } | |
177 | }; | |
178 | ||
179 | #endif |