]>
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) 2011 New Dream Network | |
7 | * Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com> | |
8 | * | |
9 | * Author: Loic Dachary <loic@dachary.org> | |
10 | * | |
11 | * This is free software; you can redistribute it and/or | |
12 | * modify it under the terms of the GNU Lesser General Public | |
13 | * License version 2.1, as published by the Free Software | |
14 | * Foundation. See file COPYING. | |
15 | * | |
16 | */ | |
17 | ||
18 | #include <boost/assign/list_of.hpp> | |
19 | ||
20 | #include "osd_types.h" | |
21 | #include "include/ceph_features.h" | |
22 | extern "C" { | |
23 | #include "crush/hash.h" | |
24 | } | |
25 | #include "PG.h" | |
26 | #include "OSDMap.h" | |
27 | #include "PGBackend.h" | |
28 | ||
29 | const char *ceph_osd_flag_name(unsigned flag) | |
30 | { | |
31 | switch (flag) { | |
32 | case CEPH_OSD_FLAG_ACK: return "ack"; | |
33 | case CEPH_OSD_FLAG_ONNVRAM: return "onnvram"; | |
34 | case CEPH_OSD_FLAG_ONDISK: return "ondisk"; | |
35 | case CEPH_OSD_FLAG_RETRY: return "retry"; | |
36 | case CEPH_OSD_FLAG_READ: return "read"; | |
37 | case CEPH_OSD_FLAG_WRITE: return "write"; | |
38 | case CEPH_OSD_FLAG_ORDERSNAP: return "ordersnap"; | |
39 | case CEPH_OSD_FLAG_PEERSTAT_OLD: return "peerstat_old"; | |
40 | case CEPH_OSD_FLAG_BALANCE_READS: return "balance_reads"; | |
41 | case CEPH_OSD_FLAG_PARALLELEXEC: return "parallelexec"; | |
42 | case CEPH_OSD_FLAG_PGOP: return "pgop"; | |
43 | case CEPH_OSD_FLAG_EXEC: return "exec"; | |
44 | case CEPH_OSD_FLAG_EXEC_PUBLIC: return "exec_public"; | |
45 | case CEPH_OSD_FLAG_LOCALIZE_READS: return "localize_reads"; | |
46 | case CEPH_OSD_FLAG_RWORDERED: return "rwordered"; | |
47 | case CEPH_OSD_FLAG_IGNORE_CACHE: return "ignore_cache"; | |
48 | case CEPH_OSD_FLAG_SKIPRWLOCKS: return "skiprwlocks"; | |
49 | case CEPH_OSD_FLAG_IGNORE_OVERLAY: return "ignore_overlay"; | |
50 | case CEPH_OSD_FLAG_FLUSH: return "flush"; | |
51 | case CEPH_OSD_FLAG_MAP_SNAP_CLONE: return "map_snap_clone"; | |
52 | case CEPH_OSD_FLAG_ENFORCE_SNAPC: return "enforce_snapc"; | |
53 | case CEPH_OSD_FLAG_REDIRECTED: return "redirected"; | |
54 | case CEPH_OSD_FLAG_KNOWN_REDIR: return "known_if_redirected"; | |
55 | case CEPH_OSD_FLAG_FULL_TRY: return "full_try"; | |
56 | case CEPH_OSD_FLAG_FULL_FORCE: return "full_force"; | |
224ce89b | 57 | case CEPH_OSD_FLAG_IGNORE_REDIRECT: return "ignore_redirect"; |
7c673cae FG |
58 | default: return "???"; |
59 | } | |
60 | } | |
61 | ||
62 | string ceph_osd_flag_string(unsigned flags) | |
63 | { | |
64 | string s; | |
65 | for (unsigned i=0; i<32; ++i) { | |
66 | if (flags & (1u<<i)) { | |
67 | if (s.length()) | |
68 | s += "+"; | |
69 | s += ceph_osd_flag_name(1u << i); | |
70 | } | |
71 | } | |
72 | if (s.length()) | |
73 | return s; | |
74 | return string("-"); | |
75 | } | |
76 | ||
77 | const char * ceph_osd_op_flag_name(unsigned flag) | |
78 | { | |
79 | const char *name; | |
80 | ||
81 | switch(flag) { | |
82 | case CEPH_OSD_OP_FLAG_EXCL: | |
83 | name = "excl"; | |
84 | break; | |
85 | case CEPH_OSD_OP_FLAG_FAILOK: | |
86 | name = "failok"; | |
87 | break; | |
88 | case CEPH_OSD_OP_FLAG_FADVISE_RANDOM: | |
89 | name = "fadvise_random"; | |
90 | break; | |
91 | case CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL: | |
92 | name = "fadvise_sequential"; | |
93 | break; | |
94 | case CEPH_OSD_OP_FLAG_FADVISE_WILLNEED: | |
95 | name = "favise_willneed"; | |
96 | break; | |
97 | case CEPH_OSD_OP_FLAG_FADVISE_DONTNEED: | |
98 | name = "fadvise_dontneed"; | |
99 | break; | |
100 | case CEPH_OSD_OP_FLAG_FADVISE_NOCACHE: | |
101 | name = "fadvise_nocache"; | |
102 | break; | |
103 | default: | |
104 | name = "???"; | |
105 | }; | |
106 | ||
107 | return name; | |
108 | } | |
109 | ||
110 | string ceph_osd_op_flag_string(unsigned flags) | |
111 | { | |
112 | string s; | |
113 | for (unsigned i=0; i<32; ++i) { | |
114 | if (flags & (1u<<i)) { | |
115 | if (s.length()) | |
116 | s += "+"; | |
117 | s += ceph_osd_op_flag_name(1u << i); | |
118 | } | |
119 | } | |
120 | if (s.length()) | |
121 | return s; | |
122 | return string("-"); | |
123 | } | |
124 | ||
125 | string ceph_osd_alloc_hint_flag_string(unsigned flags) | |
126 | { | |
127 | string s; | |
128 | for (unsigned i=0; i<32; ++i) { | |
129 | if (flags & (1u<<i)) { | |
130 | if (s.length()) | |
131 | s += "+"; | |
132 | s += ceph_osd_alloc_hint_flag_name(1u << i); | |
133 | } | |
134 | } | |
135 | if (s.length()) | |
136 | return s; | |
137 | return string("-"); | |
138 | } | |
139 | ||
140 | void pg_shard_t::encode(bufferlist &bl) const | |
141 | { | |
142 | ENCODE_START(1, 1, bl); | |
143 | ::encode(osd, bl); | |
144 | ::encode(shard, bl); | |
145 | ENCODE_FINISH(bl); | |
146 | } | |
147 | void pg_shard_t::decode(bufferlist::iterator &bl) | |
148 | { | |
149 | DECODE_START(1, bl); | |
150 | ::decode(osd, bl); | |
151 | ::decode(shard, bl); | |
152 | DECODE_FINISH(bl); | |
153 | } | |
154 | ||
155 | ostream &operator<<(ostream &lhs, const pg_shard_t &rhs) | |
156 | { | |
157 | if (rhs.is_undefined()) | |
158 | return lhs << "?"; | |
159 | if (rhs.shard == shard_id_t::NO_SHARD) | |
b32b8144 FG |
160 | return lhs << rhs.get_osd(); |
161 | return lhs << rhs.get_osd() << '(' << (unsigned)(rhs.shard) << ')'; | |
7c673cae FG |
162 | } |
163 | ||
164 | // -- osd_reqid_t -- | |
165 | void osd_reqid_t::dump(Formatter *f) const | |
166 | { | |
167 | f->dump_stream("name") << name; | |
168 | f->dump_int("inc", inc); | |
169 | f->dump_unsigned("tid", tid); | |
170 | } | |
171 | ||
172 | void osd_reqid_t::generate_test_instances(list<osd_reqid_t*>& o) | |
173 | { | |
174 | o.push_back(new osd_reqid_t); | |
175 | o.push_back(new osd_reqid_t(entity_name_t::CLIENT(123), 1, 45678)); | |
176 | } | |
177 | ||
178 | // -- object_locator_t -- | |
179 | ||
180 | void object_locator_t::encode(bufferlist& bl) const | |
181 | { | |
182 | // verify that nobody's corrupted the locator | |
183 | assert(hash == -1 || key.empty()); | |
184 | __u8 encode_compat = 3; | |
185 | ENCODE_START(6, encode_compat, bl); | |
186 | ::encode(pool, bl); | |
187 | int32_t preferred = -1; // tell old code there is no preferred osd (-1). | |
188 | ::encode(preferred, bl); | |
189 | ::encode(key, bl); | |
190 | ::encode(nspace, bl); | |
191 | ::encode(hash, bl); | |
192 | if (hash != -1) | |
193 | encode_compat = MAX(encode_compat, 6); // need to interpret the hash | |
194 | ENCODE_FINISH_NEW_COMPAT(bl, encode_compat); | |
195 | } | |
196 | ||
197 | void object_locator_t::decode(bufferlist::iterator& p) | |
198 | { | |
199 | DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, p); | |
200 | if (struct_v < 2) { | |
201 | int32_t op; | |
202 | ::decode(op, p); | |
203 | pool = op; | |
204 | int16_t pref; | |
205 | ::decode(pref, p); | |
206 | } else { | |
207 | ::decode(pool, p); | |
208 | int32_t preferred; | |
209 | ::decode(preferred, p); | |
210 | } | |
211 | ::decode(key, p); | |
212 | if (struct_v >= 5) | |
213 | ::decode(nspace, p); | |
214 | if (struct_v >= 6) | |
215 | ::decode(hash, p); | |
216 | else | |
217 | hash = -1; | |
218 | DECODE_FINISH(p); | |
219 | // verify that nobody's corrupted the locator | |
220 | assert(hash == -1 || key.empty()); | |
221 | } | |
222 | ||
223 | void object_locator_t::dump(Formatter *f) const | |
224 | { | |
225 | f->dump_int("pool", pool); | |
226 | f->dump_string("key", key); | |
227 | f->dump_string("namespace", nspace); | |
228 | f->dump_int("hash", hash); | |
229 | } | |
230 | ||
231 | void object_locator_t::generate_test_instances(list<object_locator_t*>& o) | |
232 | { | |
233 | o.push_back(new object_locator_t); | |
234 | o.push_back(new object_locator_t(123)); | |
235 | o.push_back(new object_locator_t(123, 876)); | |
236 | o.push_back(new object_locator_t(1, "n2")); | |
237 | o.push_back(new object_locator_t(1234, "", "key")); | |
238 | o.push_back(new object_locator_t(12, "n1", "key2")); | |
239 | } | |
240 | ||
241 | // -- request_redirect_t -- | |
242 | void request_redirect_t::encode(bufferlist& bl) const | |
243 | { | |
244 | ENCODE_START(1, 1, bl); | |
245 | ::encode(redirect_locator, bl); | |
246 | ::encode(redirect_object, bl); | |
247 | ::encode(osd_instructions, bl); | |
248 | ENCODE_FINISH(bl); | |
249 | } | |
250 | ||
251 | void request_redirect_t::decode(bufferlist::iterator& bl) | |
252 | { | |
253 | DECODE_START(1, bl); | |
254 | ::decode(redirect_locator, bl); | |
255 | ::decode(redirect_object, bl); | |
256 | ::decode(osd_instructions, bl); | |
257 | DECODE_FINISH(bl); | |
258 | } | |
259 | ||
260 | void request_redirect_t::dump(Formatter *f) const | |
261 | { | |
262 | f->dump_string("object", redirect_object); | |
263 | f->open_object_section("locator"); | |
264 | redirect_locator.dump(f); | |
265 | f->close_section(); // locator | |
266 | } | |
267 | ||
268 | void request_redirect_t::generate_test_instances(list<request_redirect_t*>& o) | |
269 | { | |
270 | object_locator_t loc(1, "redir_obj"); | |
271 | o.push_back(new request_redirect_t()); | |
272 | o.push_back(new request_redirect_t(loc, 0)); | |
273 | o.push_back(new request_redirect_t(loc, "redir_obj")); | |
274 | o.push_back(new request_redirect_t(loc)); | |
275 | } | |
276 | ||
277 | void objectstore_perf_stat_t::dump(Formatter *f) const | |
278 | { | |
279 | f->dump_unsigned("commit_latency_ms", os_commit_latency); | |
280 | f->dump_unsigned("apply_latency_ms", os_apply_latency); | |
281 | } | |
282 | ||
283 | void objectstore_perf_stat_t::encode(bufferlist &bl) const | |
284 | { | |
285 | ENCODE_START(1, 1, bl); | |
286 | ::encode(os_commit_latency, bl); | |
287 | ::encode(os_apply_latency, bl); | |
288 | ENCODE_FINISH(bl); | |
289 | } | |
290 | ||
291 | void objectstore_perf_stat_t::decode(bufferlist::iterator &bl) | |
292 | { | |
293 | DECODE_START(1, bl); | |
294 | ::decode(os_commit_latency, bl); | |
295 | ::decode(os_apply_latency, bl); | |
296 | DECODE_FINISH(bl); | |
297 | } | |
298 | ||
299 | void objectstore_perf_stat_t::generate_test_instances(std::list<objectstore_perf_stat_t*>& o) | |
300 | { | |
301 | o.push_back(new objectstore_perf_stat_t()); | |
302 | o.push_back(new objectstore_perf_stat_t()); | |
303 | o.back()->os_commit_latency = 20; | |
304 | o.back()->os_apply_latency = 30; | |
305 | } | |
306 | ||
307 | // -- osd_stat_t -- | |
308 | void osd_stat_t::dump(Formatter *f) const | |
309 | { | |
31f18b77 FG |
310 | f->dump_unsigned("up_from", up_from); |
311 | f->dump_unsigned("seq", seq); | |
35e4c445 | 312 | f->dump_unsigned("num_pgs", num_pgs); |
7c673cae FG |
313 | f->dump_unsigned("kb", kb); |
314 | f->dump_unsigned("kb_used", kb_used); | |
315 | f->dump_unsigned("kb_avail", kb_avail); | |
316 | f->open_array_section("hb_peers"); | |
317 | for (auto p : hb_peers) | |
318 | f->dump_int("osd", p); | |
319 | f->close_section(); | |
320 | f->dump_int("snap_trim_queue_len", snap_trim_queue_len); | |
321 | f->dump_int("num_snap_trimming", num_snap_trimming); | |
322 | f->open_object_section("op_queue_age_hist"); | |
323 | op_queue_age_hist.dump(f); | |
324 | f->close_section(); | |
325 | f->open_object_section("perf_stat"); | |
326 | os_perf_stat.dump(f); | |
327 | f->close_section(); | |
328 | } | |
329 | ||
330 | void osd_stat_t::encode(bufferlist &bl) const | |
331 | { | |
35e4c445 | 332 | ENCODE_START(7, 2, bl); |
7c673cae FG |
333 | ::encode(kb, bl); |
334 | ::encode(kb_used, bl); | |
335 | ::encode(kb_avail, bl); | |
336 | ::encode(snap_trim_queue_len, bl); | |
337 | ::encode(num_snap_trimming, bl); | |
338 | ::encode(hb_peers, bl); | |
339 | ::encode((uint32_t)0, bl); | |
340 | ::encode(op_queue_age_hist, bl); | |
341 | ::encode(os_perf_stat, bl); | |
31f18b77 FG |
342 | ::encode(up_from, bl); |
343 | ::encode(seq, bl); | |
35e4c445 | 344 | ::encode(num_pgs, bl); |
7c673cae FG |
345 | ENCODE_FINISH(bl); |
346 | } | |
347 | ||
348 | void osd_stat_t::decode(bufferlist::iterator &bl) | |
349 | { | |
31f18b77 | 350 | DECODE_START_LEGACY_COMPAT_LEN(6, 2, 2, bl); |
7c673cae FG |
351 | ::decode(kb, bl); |
352 | ::decode(kb_used, bl); | |
353 | ::decode(kb_avail, bl); | |
354 | ::decode(snap_trim_queue_len, bl); | |
355 | ::decode(num_snap_trimming, bl); | |
356 | ::decode(hb_peers, bl); | |
357 | vector<int> num_hb_out; | |
358 | ::decode(num_hb_out, bl); | |
359 | if (struct_v >= 3) | |
360 | ::decode(op_queue_age_hist, bl); | |
361 | if (struct_v >= 4) | |
362 | ::decode(os_perf_stat, bl); | |
31f18b77 FG |
363 | if (struct_v >= 6) { |
364 | ::decode(up_from, bl); | |
365 | ::decode(seq, bl); | |
366 | } | |
35e4c445 FG |
367 | if (struct_v >= 7) { |
368 | ::decode(num_pgs, bl); | |
369 | } | |
7c673cae FG |
370 | DECODE_FINISH(bl); |
371 | } | |
372 | ||
373 | void osd_stat_t::generate_test_instances(std::list<osd_stat_t*>& o) | |
374 | { | |
375 | o.push_back(new osd_stat_t); | |
376 | ||
377 | o.push_back(new osd_stat_t); | |
378 | o.back()->kb = 1; | |
379 | o.back()->kb_used = 2; | |
380 | o.back()->kb_avail = 3; | |
381 | o.back()->hb_peers.push_back(7); | |
382 | o.back()->snap_trim_queue_len = 8; | |
383 | o.back()->num_snap_trimming = 99; | |
384 | } | |
385 | ||
386 | // -- pg_t -- | |
387 | ||
388 | int pg_t::print(char *o, int maxlen) const | |
389 | { | |
390 | if (preferred() >= 0) | |
391 | return snprintf(o, maxlen, "%llu.%xp%d", (unsigned long long)pool(), ps(), preferred()); | |
392 | else | |
393 | return snprintf(o, maxlen, "%llu.%x", (unsigned long long)pool(), ps()); | |
394 | } | |
395 | ||
396 | bool pg_t::parse(const char *s) | |
397 | { | |
398 | uint64_t ppool; | |
399 | uint32_t pseed; | |
400 | int32_t pref; | |
401 | int r = sscanf(s, "%llu.%xp%d", (long long unsigned *)&ppool, &pseed, &pref); | |
402 | if (r < 2) | |
403 | return false; | |
404 | m_pool = ppool; | |
405 | m_seed = pseed; | |
406 | if (r == 3) | |
407 | m_preferred = pref; | |
408 | else | |
409 | m_preferred = -1; | |
410 | return true; | |
411 | } | |
412 | ||
413 | bool spg_t::parse(const char *s) | |
414 | { | |
415 | pgid.set_preferred(-1); | |
416 | shard = shard_id_t::NO_SHARD; | |
417 | uint64_t ppool; | |
418 | uint32_t pseed; | |
419 | int32_t pref; | |
420 | uint32_t pshard; | |
421 | int r = sscanf(s, "%llu.%x", (long long unsigned *)&ppool, &pseed); | |
422 | if (r < 2) | |
423 | return false; | |
424 | pgid.set_pool(ppool); | |
425 | pgid.set_ps(pseed); | |
426 | ||
427 | const char *p = strchr(s, 'p'); | |
428 | if (p) { | |
429 | r = sscanf(p, "p%d", &pref); | |
430 | if (r == 1) { | |
431 | pgid.set_preferred(pref); | |
432 | } else { | |
433 | return false; | |
434 | } | |
435 | } | |
436 | ||
437 | p = strchr(s, 's'); | |
438 | if (p) { | |
439 | r = sscanf(p, "s%d", &pshard); | |
440 | if (r == 1) { | |
441 | shard = shard_id_t(pshard); | |
442 | } else { | |
443 | return false; | |
444 | } | |
445 | } | |
446 | return true; | |
447 | } | |
448 | ||
449 | char *spg_t::calc_name(char *buf, const char *suffix_backwords) const | |
450 | { | |
451 | while (*suffix_backwords) | |
452 | *--buf = *suffix_backwords++; | |
453 | ||
454 | if (!is_no_shard()) { | |
455 | buf = ritoa<uint8_t, 10>((uint8_t)shard.id, buf); | |
456 | *--buf = 's'; | |
457 | } | |
458 | ||
459 | return pgid.calc_name(buf, ""); | |
460 | } | |
461 | ||
462 | ostream& operator<<(ostream& out, const spg_t &pg) | |
463 | { | |
464 | char buf[spg_t::calc_name_buf_size]; | |
465 | buf[spg_t::calc_name_buf_size - 1] = '\0'; | |
466 | out << pg.calc_name(buf + spg_t::calc_name_buf_size - 1, ""); | |
467 | return out; | |
468 | } | |
469 | ||
470 | pg_t pg_t::get_ancestor(unsigned old_pg_num) const | |
471 | { | |
472 | int old_bits = cbits(old_pg_num); | |
473 | int old_mask = (1 << old_bits) - 1; | |
474 | pg_t ret = *this; | |
475 | ret.m_seed = ceph_stable_mod(m_seed, old_pg_num, old_mask); | |
476 | return ret; | |
477 | } | |
478 | ||
479 | bool pg_t::is_split(unsigned old_pg_num, unsigned new_pg_num, set<pg_t> *children) const | |
480 | { | |
481 | assert(m_seed < old_pg_num); | |
482 | if (new_pg_num <= old_pg_num) | |
483 | return false; | |
484 | ||
485 | bool split = false; | |
486 | if (true) { | |
487 | unsigned old_bits = cbits(old_pg_num); | |
488 | unsigned old_mask = (1 << old_bits) - 1; | |
489 | for (unsigned n = 1; ; n++) { | |
490 | unsigned next_bit = (n << (old_bits-1)); | |
491 | unsigned s = next_bit | m_seed; | |
492 | ||
493 | if (s < old_pg_num || s == m_seed) | |
494 | continue; | |
495 | if (s >= new_pg_num) | |
496 | break; | |
497 | if ((unsigned)ceph_stable_mod(s, old_pg_num, old_mask) == m_seed) { | |
498 | split = true; | |
499 | if (children) | |
500 | children->insert(pg_t(s, m_pool, m_preferred)); | |
501 | } | |
502 | } | |
503 | } | |
504 | if (false) { | |
505 | // brute force | |
506 | int old_bits = cbits(old_pg_num); | |
507 | int old_mask = (1 << old_bits) - 1; | |
508 | for (unsigned x = old_pg_num; x < new_pg_num; ++x) { | |
509 | unsigned o = ceph_stable_mod(x, old_pg_num, old_mask); | |
510 | if (o == m_seed) { | |
511 | split = true; | |
512 | children->insert(pg_t(x, m_pool, m_preferred)); | |
513 | } | |
514 | } | |
515 | } | |
516 | return split; | |
517 | } | |
518 | ||
519 | unsigned pg_t::get_split_bits(unsigned pg_num) const { | |
520 | if (pg_num == 1) | |
521 | return 0; | |
522 | assert(pg_num > 1); | |
523 | ||
524 | // Find unique p such that pg_num \in [2^(p-1), 2^p) | |
525 | unsigned p = cbits(pg_num); | |
526 | assert(p); // silence coverity #751330 | |
527 | ||
528 | if ((m_seed % (1<<(p-1))) < (pg_num % (1<<(p-1)))) | |
529 | return p; | |
530 | else | |
531 | return p - 1; | |
532 | } | |
533 | ||
534 | pg_t pg_t::get_parent() const | |
535 | { | |
536 | unsigned bits = cbits(m_seed); | |
537 | assert(bits); | |
538 | pg_t retval = *this; | |
539 | retval.m_seed &= ~((~0)<<(bits - 1)); | |
540 | return retval; | |
541 | } | |
542 | ||
543 | hobject_t pg_t::get_hobj_start() const | |
544 | { | |
545 | return hobject_t(object_t(), string(), CEPH_NOSNAP, m_seed, m_pool, | |
546 | string()); | |
547 | } | |
548 | ||
549 | hobject_t pg_t::get_hobj_end(unsigned pg_num) const | |
550 | { | |
551 | // note: this assumes a bitwise sort; with the legacy nibblewise | |
552 | // sort a PG did not always cover a single contiguous range of the | |
553 | // (bit-reversed) hash range. | |
554 | unsigned bits = get_split_bits(pg_num); | |
555 | uint64_t rev_start = hobject_t::_reverse_bits(m_seed); | |
556 | uint64_t rev_end = (rev_start | (0xffffffff >> bits)) + 1; | |
557 | if (rev_end >= 0x100000000) { | |
558 | assert(rev_end == 0x100000000); | |
559 | return hobject_t::get_max(); | |
560 | } else { | |
561 | return hobject_t(object_t(), string(), CEPH_NOSNAP, | |
562 | hobject_t::_reverse_bits(rev_end), m_pool, | |
563 | string()); | |
564 | } | |
565 | } | |
566 | ||
567 | void pg_t::dump(Formatter *f) const | |
568 | { | |
569 | f->dump_unsigned("pool", m_pool); | |
570 | f->dump_unsigned("seed", m_seed); | |
571 | f->dump_int("preferred_osd", m_preferred); | |
572 | } | |
573 | ||
574 | void pg_t::generate_test_instances(list<pg_t*>& o) | |
575 | { | |
576 | o.push_back(new pg_t); | |
577 | o.push_back(new pg_t(1, 2, -1)); | |
578 | o.push_back(new pg_t(13123, 3, -1)); | |
579 | o.push_back(new pg_t(131223, 4, 23)); | |
580 | } | |
581 | ||
582 | char *pg_t::calc_name(char *buf, const char *suffix_backwords) const | |
583 | { | |
584 | while (*suffix_backwords) | |
585 | *--buf = *suffix_backwords++; | |
586 | ||
587 | if (m_preferred >= 0) | |
588 | *--buf ='p'; | |
589 | ||
590 | buf = ritoa<uint32_t, 16>(m_seed, buf); | |
591 | ||
592 | *--buf = '.'; | |
593 | ||
594 | return ritoa<uint64_t, 10>(m_pool, buf); | |
595 | } | |
596 | ||
597 | ostream& operator<<(ostream& out, const pg_t &pg) | |
598 | { | |
599 | char buf[pg_t::calc_name_buf_size]; | |
600 | buf[pg_t::calc_name_buf_size - 1] = '\0'; | |
601 | out << pg.calc_name(buf + pg_t::calc_name_buf_size - 1, ""); | |
602 | return out; | |
603 | } | |
604 | ||
605 | ||
606 | // -- coll_t -- | |
607 | ||
608 | void coll_t::calc_str() | |
609 | { | |
610 | switch (type) { | |
611 | case TYPE_META: | |
612 | strcpy(_str_buff, "meta"); | |
613 | _str = _str_buff; | |
614 | break; | |
615 | case TYPE_PG: | |
616 | _str_buff[spg_t::calc_name_buf_size - 1] = '\0'; | |
617 | _str = pgid.calc_name(_str_buff + spg_t::calc_name_buf_size - 1, "daeh_"); | |
618 | break; | |
619 | case TYPE_PG_TEMP: | |
620 | _str_buff[spg_t::calc_name_buf_size - 1] = '\0'; | |
621 | _str = pgid.calc_name(_str_buff + spg_t::calc_name_buf_size - 1, "PMET_"); | |
622 | break; | |
623 | default: | |
624 | assert(0 == "unknown collection type"); | |
625 | } | |
626 | } | |
627 | ||
628 | bool coll_t::parse(const std::string& s) | |
629 | { | |
630 | if (s == "meta") { | |
631 | type = TYPE_META; | |
632 | pgid = spg_t(); | |
633 | removal_seq = 0; | |
634 | calc_str(); | |
635 | assert(s == _str); | |
636 | return true; | |
637 | } | |
638 | if (s.find("_head") == s.length() - 5 && | |
639 | pgid.parse(s.substr(0, s.length() - 5))) { | |
640 | type = TYPE_PG; | |
641 | removal_seq = 0; | |
642 | calc_str(); | |
643 | assert(s == _str); | |
644 | return true; | |
645 | } | |
646 | if (s.find("_TEMP") == s.length() - 5 && | |
647 | pgid.parse(s.substr(0, s.length() - 5))) { | |
648 | type = TYPE_PG_TEMP; | |
649 | removal_seq = 0; | |
650 | calc_str(); | |
651 | assert(s == _str); | |
652 | return true; | |
653 | } | |
654 | return false; | |
655 | } | |
656 | ||
657 | void coll_t::encode(bufferlist& bl) const | |
658 | { | |
659 | // when changing this, remember to update encoded_size() too. | |
660 | if (is_temp()) { | |
661 | // can't express this as v2... | |
662 | __u8 struct_v = 3; | |
663 | ::encode(struct_v, bl); | |
664 | ::encode(to_str(), bl); | |
665 | } else { | |
666 | __u8 struct_v = 2; | |
667 | ::encode(struct_v, bl); | |
668 | ::encode((__u8)type, bl); | |
669 | ::encode(pgid, bl); | |
670 | snapid_t snap = CEPH_NOSNAP; | |
671 | ::encode(snap, bl); | |
672 | } | |
673 | } | |
674 | ||
675 | size_t coll_t::encoded_size() const | |
676 | { | |
677 | size_t r = sizeof(__u8); | |
678 | if (is_temp()) { | |
679 | // v3 | |
680 | r += sizeof(__u32); | |
681 | if (_str) { | |
682 | r += strlen(_str); | |
683 | } | |
684 | } else { | |
685 | // v2 | |
686 | // 1. type | |
687 | r += sizeof(__u8); | |
688 | // 2. pgid | |
689 | // - encoding header | |
690 | r += sizeof(ceph_le32) + 2 * sizeof(__u8); | |
691 | // - pg_t | |
692 | r += sizeof(__u8) + sizeof(uint64_t) + 2 * sizeof(uint32_t); | |
693 | // - shard_id_t | |
694 | r += sizeof(int8_t); | |
695 | // 3. snapid_t | |
696 | r += sizeof(uint64_t); | |
697 | } | |
698 | ||
699 | return r; | |
700 | } | |
701 | ||
702 | void coll_t::decode(bufferlist::iterator& bl) | |
703 | { | |
704 | __u8 struct_v; | |
705 | ::decode(struct_v, bl); | |
706 | switch (struct_v) { | |
707 | case 1: | |
708 | { | |
709 | snapid_t snap; | |
710 | ::decode(pgid, bl); | |
711 | ::decode(snap, bl); | |
712 | ||
713 | // infer the type | |
714 | if (pgid == spg_t() && snap == 0) { | |
715 | type = TYPE_META; | |
716 | } else { | |
717 | type = TYPE_PG; | |
718 | } | |
719 | removal_seq = 0; | |
720 | } | |
721 | break; | |
722 | ||
723 | case 2: | |
724 | { | |
725 | __u8 _type; | |
726 | snapid_t snap; | |
727 | ::decode(_type, bl); | |
728 | ::decode(pgid, bl); | |
729 | ::decode(snap, bl); | |
730 | type = (type_t)_type; | |
731 | removal_seq = 0; | |
732 | } | |
733 | break; | |
734 | ||
735 | case 3: | |
736 | { | |
737 | string str; | |
738 | ::decode(str, bl); | |
739 | bool ok = parse(str); | |
740 | if (!ok) | |
741 | throw std::domain_error(std::string("unable to parse pg ") + str); | |
742 | } | |
743 | break; | |
744 | ||
745 | default: | |
746 | { | |
747 | ostringstream oss; | |
748 | oss << "coll_t::decode(): don't know how to decode version " | |
749 | << struct_v; | |
750 | throw std::domain_error(oss.str()); | |
751 | } | |
752 | } | |
753 | } | |
754 | ||
755 | void coll_t::dump(Formatter *f) const | |
756 | { | |
757 | f->dump_unsigned("type_id", (unsigned)type); | |
758 | if (type != TYPE_META) | |
759 | f->dump_stream("pgid") << pgid; | |
760 | f->dump_string("name", to_str()); | |
761 | } | |
762 | ||
763 | void coll_t::generate_test_instances(list<coll_t*>& o) | |
764 | { | |
765 | o.push_back(new coll_t()); | |
766 | o.push_back(new coll_t(spg_t(pg_t(1, 0), shard_id_t::NO_SHARD))); | |
767 | o.push_back(new coll_t(o.back()->get_temp())); | |
768 | o.push_back(new coll_t(spg_t(pg_t(3, 2), shard_id_t(12)))); | |
769 | o.push_back(new coll_t(o.back()->get_temp())); | |
770 | o.push_back(new coll_t()); | |
771 | } | |
772 | ||
773 | // --- | |
774 | ||
775 | std::string pg_vector_string(const vector<int32_t> &a) | |
776 | { | |
777 | ostringstream oss; | |
778 | oss << "["; | |
779 | for (vector<int32_t>::const_iterator i = a.begin(); i != a.end(); ++i) { | |
780 | if (i != a.begin()) | |
781 | oss << ","; | |
782 | if (*i != CRUSH_ITEM_NONE) | |
783 | oss << *i; | |
784 | else | |
785 | oss << "NONE"; | |
786 | } | |
787 | oss << "]"; | |
788 | return oss.str(); | |
789 | } | |
790 | ||
791 | std::string pg_state_string(int state) | |
792 | { | |
793 | ostringstream oss; | |
794 | if (state & PG_STATE_STALE) | |
795 | oss << "stale+"; | |
796 | if (state & PG_STATE_CREATING) | |
797 | oss << "creating+"; | |
798 | if (state & PG_STATE_ACTIVE) | |
799 | oss << "active+"; | |
800 | if (state & PG_STATE_ACTIVATING) | |
801 | oss << "activating+"; | |
802 | if (state & PG_STATE_CLEAN) | |
803 | oss << "clean+"; | |
804 | if (state & PG_STATE_RECOVERY_WAIT) | |
805 | oss << "recovery_wait+"; | |
806 | if (state & PG_STATE_RECOVERY_TOOFULL) | |
807 | oss << "recovery_toofull+"; | |
808 | if (state & PG_STATE_RECOVERING) | |
809 | oss << "recovering+"; | |
c07f9fc5 FG |
810 | if (state & PG_STATE_FORCED_RECOVERY) |
811 | oss << "forced_recovery+"; | |
7c673cae FG |
812 | if (state & PG_STATE_DOWN) |
813 | oss << "down+"; | |
b32b8144 FG |
814 | if (state & PG_STATE_RECOVERY_UNFOUND) |
815 | oss << "recovery_unfound+"; | |
816 | if (state & PG_STATE_BACKFILL_UNFOUND) | |
817 | oss << "backfill_unfound+"; | |
7c673cae FG |
818 | if (state & PG_STATE_UNDERSIZED) |
819 | oss << "undersized+"; | |
820 | if (state & PG_STATE_DEGRADED) | |
821 | oss << "degraded+"; | |
822 | if (state & PG_STATE_REMAPPED) | |
823 | oss << "remapped+"; | |
824 | if (state & PG_STATE_SCRUBBING) | |
825 | oss << "scrubbing+"; | |
826 | if (state & PG_STATE_DEEP_SCRUB) | |
827 | oss << "deep+"; | |
828 | if (state & PG_STATE_INCONSISTENT) | |
829 | oss << "inconsistent+"; | |
830 | if (state & PG_STATE_PEERING) | |
831 | oss << "peering+"; | |
832 | if (state & PG_STATE_REPAIR) | |
833 | oss << "repair+"; | |
3efd9988 | 834 | if (state & PG_STATE_BACKFILL_WAIT) |
7c673cae | 835 | oss << "backfill_wait+"; |
3efd9988 | 836 | if (state & PG_STATE_BACKFILLING) |
7c673cae | 837 | oss << "backfilling+"; |
c07f9fc5 FG |
838 | if (state & PG_STATE_FORCED_BACKFILL) |
839 | oss << "forced_backfill+"; | |
7c673cae FG |
840 | if (state & PG_STATE_BACKFILL_TOOFULL) |
841 | oss << "backfill_toofull+"; | |
842 | if (state & PG_STATE_INCOMPLETE) | |
843 | oss << "incomplete+"; | |
844 | if (state & PG_STATE_PEERED) | |
845 | oss << "peered+"; | |
846 | if (state & PG_STATE_SNAPTRIM) | |
847 | oss << "snaptrim+"; | |
848 | if (state & PG_STATE_SNAPTRIM_WAIT) | |
849 | oss << "snaptrim_wait+"; | |
224ce89b WB |
850 | if (state & PG_STATE_SNAPTRIM_ERROR) |
851 | oss << "snaptrim_error+"; | |
7c673cae FG |
852 | string ret(oss.str()); |
853 | if (ret.length() > 0) | |
854 | ret.resize(ret.length() - 1); | |
855 | else | |
31f18b77 | 856 | ret = "unknown"; |
7c673cae FG |
857 | return ret; |
858 | } | |
859 | ||
3efd9988 | 860 | boost::optional<uint64_t> pg_string_state(const std::string& state) |
7c673cae | 861 | { |
3efd9988 | 862 | boost::optional<uint64_t> type; |
7c673cae FG |
863 | if (state == "active") |
864 | type = PG_STATE_ACTIVE; | |
865 | else if (state == "clean") | |
866 | type = PG_STATE_CLEAN; | |
867 | else if (state == "down") | |
868 | type = PG_STATE_DOWN; | |
b32b8144 FG |
869 | else if (state == "recovery_unfound") |
870 | type = PG_STATE_RECOVERY_UNFOUND; | |
871 | else if (state == "backfill_unfound") | |
872 | type = PG_STATE_BACKFILL_UNFOUND; | |
7c673cae FG |
873 | else if (state == "scrubbing") |
874 | type = PG_STATE_SCRUBBING; | |
875 | else if (state == "degraded") | |
876 | type = PG_STATE_DEGRADED; | |
877 | else if (state == "inconsistent") | |
878 | type = PG_STATE_INCONSISTENT; | |
879 | else if (state == "peering") | |
880 | type = PG_STATE_PEERING; | |
881 | else if (state == "repair") | |
882 | type = PG_STATE_REPAIR; | |
883 | else if (state == "recovering") | |
884 | type = PG_STATE_RECOVERING; | |
c07f9fc5 FG |
885 | else if (state == "forced_recovery") |
886 | type = PG_STATE_FORCED_RECOVERY; | |
7c673cae FG |
887 | else if (state == "backfill_wait") |
888 | type = PG_STATE_BACKFILL_WAIT; | |
889 | else if (state == "incomplete") | |
890 | type = PG_STATE_INCOMPLETE; | |
891 | else if (state == "stale") | |
892 | type = PG_STATE_STALE; | |
893 | else if (state == "remapped") | |
894 | type = PG_STATE_REMAPPED; | |
94b18763 | 895 | else if (state == "deep") |
7c673cae | 896 | type = PG_STATE_DEEP_SCRUB; |
3efd9988 FG |
897 | else if (state == "backfilling") |
898 | type = PG_STATE_BACKFILLING; | |
c07f9fc5 FG |
899 | else if (state == "forced_backfill") |
900 | type = PG_STATE_FORCED_BACKFILL; | |
7c673cae FG |
901 | else if (state == "backfill_toofull") |
902 | type = PG_STATE_BACKFILL_TOOFULL; | |
903 | else if (state == "recovery_wait") | |
904 | type = PG_STATE_RECOVERY_WAIT; | |
905 | else if (state == "recovery_toofull") | |
906 | type = PG_STATE_RECOVERY_TOOFULL; | |
907 | else if (state == "undersized") | |
908 | type = PG_STATE_UNDERSIZED; | |
909 | else if (state == "activating") | |
910 | type = PG_STATE_ACTIVATING; | |
911 | else if (state == "peered") | |
912 | type = PG_STATE_PEERED; | |
913 | else if (state == "snaptrim") | |
914 | type = PG_STATE_SNAPTRIM; | |
915 | else if (state == "snaptrim_wait") | |
916 | type = PG_STATE_SNAPTRIM_WAIT; | |
224ce89b WB |
917 | else if (state == "snaptrim_error") |
918 | type = PG_STATE_SNAPTRIM_ERROR; | |
7c673cae | 919 | else |
3efd9988 | 920 | type = boost::none; |
7c673cae FG |
921 | return type; |
922 | } | |
923 | ||
924 | // -- eversion_t -- | |
925 | string eversion_t::get_key_name() const | |
926 | { | |
927 | char key[32]; | |
928 | // Below is equivalent of sprintf("%010u.%020llu"); | |
929 | key[31] = 0; | |
930 | ritoa<uint64_t, 10, 20>(version, key + 31); | |
931 | key[10] = '.'; | |
932 | ritoa<uint32_t, 10, 10>(epoch, key + 10); | |
933 | return string(key); | |
934 | } | |
935 | ||
936 | ||
937 | // -- pool_snap_info_t -- | |
938 | void pool_snap_info_t::dump(Formatter *f) const | |
939 | { | |
940 | f->dump_unsigned("snapid", snapid); | |
941 | f->dump_stream("stamp") << stamp; | |
942 | f->dump_string("name", name); | |
943 | } | |
944 | ||
945 | void pool_snap_info_t::encode(bufferlist& bl, uint64_t features) const | |
946 | { | |
947 | if ((features & CEPH_FEATURE_PGPOOL3) == 0) { | |
948 | __u8 struct_v = 1; | |
949 | ::encode(struct_v, bl); | |
950 | ::encode(snapid, bl); | |
951 | ::encode(stamp, bl); | |
952 | ::encode(name, bl); | |
953 | return; | |
954 | } | |
955 | ENCODE_START(2, 2, bl); | |
956 | ::encode(snapid, bl); | |
957 | ::encode(stamp, bl); | |
958 | ::encode(name, bl); | |
959 | ENCODE_FINISH(bl); | |
960 | } | |
961 | ||
962 | void pool_snap_info_t::decode(bufferlist::iterator& bl) | |
963 | { | |
964 | DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); | |
965 | ::decode(snapid, bl); | |
966 | ::decode(stamp, bl); | |
967 | ::decode(name, bl); | |
968 | DECODE_FINISH(bl); | |
969 | } | |
970 | ||
971 | void pool_snap_info_t::generate_test_instances(list<pool_snap_info_t*>& o) | |
972 | { | |
973 | o.push_back(new pool_snap_info_t); | |
974 | o.push_back(new pool_snap_info_t); | |
975 | o.back()->snapid = 1; | |
976 | o.back()->stamp = utime_t(1, 2); | |
977 | o.back()->name = "foo"; | |
978 | } | |
979 | ||
980 | // -- pool_opts_t -- | |
981 | ||
982 | typedef std::map<std::string, pool_opts_t::opt_desc_t> opt_mapping_t; | |
983 | static opt_mapping_t opt_mapping = boost::assign::map_list_of | |
984 | ("scrub_min_interval", pool_opts_t::opt_desc_t( | |
985 | pool_opts_t::SCRUB_MIN_INTERVAL, pool_opts_t::DOUBLE)) | |
986 | ("scrub_max_interval", pool_opts_t::opt_desc_t( | |
987 | pool_opts_t::SCRUB_MAX_INTERVAL, pool_opts_t::DOUBLE)) | |
988 | ("deep_scrub_interval", pool_opts_t::opt_desc_t( | |
989 | pool_opts_t::DEEP_SCRUB_INTERVAL, pool_opts_t::DOUBLE)) | |
990 | ("recovery_priority", pool_opts_t::opt_desc_t( | |
991 | pool_opts_t::RECOVERY_PRIORITY, pool_opts_t::INT)) | |
992 | ("recovery_op_priority", pool_opts_t::opt_desc_t( | |
993 | pool_opts_t::RECOVERY_OP_PRIORITY, pool_opts_t::INT)) | |
994 | ("scrub_priority", pool_opts_t::opt_desc_t( | |
995 | pool_opts_t::SCRUB_PRIORITY, pool_opts_t::INT)) | |
996 | ("compression_mode", pool_opts_t::opt_desc_t( | |
997 | pool_opts_t::COMPRESSION_MODE, pool_opts_t::STR)) | |
998 | ("compression_algorithm", pool_opts_t::opt_desc_t( | |
999 | pool_opts_t::COMPRESSION_ALGORITHM, pool_opts_t::STR)) | |
1000 | ("compression_required_ratio", pool_opts_t::opt_desc_t( | |
1001 | pool_opts_t::COMPRESSION_REQUIRED_RATIO, pool_opts_t::DOUBLE)) | |
1002 | ("compression_max_blob_size", pool_opts_t::opt_desc_t( | |
1003 | pool_opts_t::COMPRESSION_MAX_BLOB_SIZE, pool_opts_t::INT)) | |
1004 | ("compression_min_blob_size", pool_opts_t::opt_desc_t( | |
1005 | pool_opts_t::COMPRESSION_MIN_BLOB_SIZE, pool_opts_t::INT)) | |
1006 | ("csum_type", pool_opts_t::opt_desc_t( | |
1007 | pool_opts_t::CSUM_TYPE, pool_opts_t::INT)) | |
1008 | ("csum_max_block", pool_opts_t::opt_desc_t( | |
1009 | pool_opts_t::CSUM_MAX_BLOCK, pool_opts_t::INT)) | |
1010 | ("csum_min_block", pool_opts_t::opt_desc_t( | |
1011 | pool_opts_t::CSUM_MIN_BLOCK, pool_opts_t::INT)); | |
1012 | ||
1013 | bool pool_opts_t::is_opt_name(const std::string& name) { | |
224ce89b | 1014 | return opt_mapping.count(name); |
7c673cae FG |
1015 | } |
1016 | ||
1017 | pool_opts_t::opt_desc_t pool_opts_t::get_opt_desc(const std::string& name) { | |
1018 | opt_mapping_t::iterator i = opt_mapping.find(name); | |
1019 | assert(i != opt_mapping.end()); | |
1020 | return i->second; | |
1021 | } | |
1022 | ||
1023 | bool pool_opts_t::is_set(pool_opts_t::key_t key) const { | |
224ce89b | 1024 | return opts.count(key); |
7c673cae FG |
1025 | } |
1026 | ||
1027 | const pool_opts_t::value_t& pool_opts_t::get(pool_opts_t::key_t key) const { | |
1028 | opts_t::const_iterator i = opts.find(key); | |
1029 | assert(i != opts.end()); | |
1030 | return i->second; | |
1031 | } | |
1032 | ||
1033 | bool pool_opts_t::unset(pool_opts_t::key_t key) { | |
1034 | return opts.erase(key) > 0; | |
1035 | } | |
1036 | ||
1037 | class pool_opts_dumper_t : public boost::static_visitor<> | |
1038 | { | |
1039 | public: | |
1040 | pool_opts_dumper_t(const std::string& name_, Formatter* f_) : | |
1041 | name(name_.c_str()), f(f_) {} | |
1042 | ||
1043 | void operator()(std::string s) const { | |
1044 | f->dump_string(name, s); | |
1045 | } | |
1046 | void operator()(int i) const { | |
1047 | f->dump_int(name, i); | |
1048 | } | |
1049 | void operator()(double d) const { | |
1050 | f->dump_float(name, d); | |
1051 | } | |
1052 | ||
1053 | private: | |
1054 | const char* name; | |
1055 | Formatter* f; | |
1056 | }; | |
1057 | ||
1058 | void pool_opts_t::dump(const std::string& name, Formatter* f) const | |
1059 | { | |
1060 | const opt_desc_t& desc = get_opt_desc(name); | |
1061 | opts_t::const_iterator i = opts.find(desc.key); | |
1062 | if (i == opts.end()) { | |
1063 | return; | |
1064 | } | |
1065 | boost::apply_visitor(pool_opts_dumper_t(name, f), i->second); | |
1066 | } | |
1067 | ||
1068 | void pool_opts_t::dump(Formatter* f) const | |
1069 | { | |
1070 | for (opt_mapping_t::iterator i = opt_mapping.begin(); i != opt_mapping.end(); | |
1071 | ++i) { | |
1072 | const std::string& name = i->first; | |
1073 | const opt_desc_t& desc = i->second; | |
1074 | opts_t::const_iterator j = opts.find(desc.key); | |
1075 | if (j == opts.end()) { | |
1076 | continue; | |
1077 | } | |
1078 | boost::apply_visitor(pool_opts_dumper_t(name, f), j->second); | |
1079 | } | |
1080 | } | |
1081 | ||
1082 | class pool_opts_encoder_t : public boost::static_visitor<> | |
1083 | { | |
1084 | public: | |
1085 | explicit pool_opts_encoder_t(bufferlist& bl_) : bl(bl_) {} | |
1086 | ||
1087 | void operator()(std::string s) const { | |
1088 | ::encode(static_cast<int32_t>(pool_opts_t::STR), bl); | |
1089 | ::encode(s, bl); | |
1090 | } | |
1091 | void operator()(int i) const { | |
1092 | ::encode(static_cast<int32_t>(pool_opts_t::INT), bl); | |
1093 | ::encode(i, bl); | |
1094 | } | |
1095 | void operator()(double d) const { | |
1096 | ::encode(static_cast<int32_t>(pool_opts_t::DOUBLE), bl); | |
1097 | ::encode(d, bl); | |
1098 | } | |
1099 | ||
1100 | private: | |
1101 | bufferlist& bl; | |
1102 | }; | |
1103 | ||
1104 | void pool_opts_t::encode(bufferlist& bl) const { | |
1105 | ENCODE_START(1, 1, bl); | |
1106 | uint32_t n = static_cast<uint32_t>(opts.size()); | |
1107 | ::encode(n, bl); | |
1108 | for (opts_t::const_iterator i = opts.begin(); i != opts.end(); ++i) { | |
1109 | ::encode(static_cast<int32_t>(i->first), bl); | |
1110 | boost::apply_visitor(pool_opts_encoder_t(bl), i->second); | |
1111 | } | |
1112 | ENCODE_FINISH(bl); | |
1113 | } | |
1114 | ||
1115 | void pool_opts_t::decode(bufferlist::iterator& bl) { | |
1116 | DECODE_START(1, bl); | |
1117 | __u32 n; | |
1118 | ::decode(n, bl); | |
1119 | opts.clear(); | |
1120 | while (n--) { | |
1121 | int32_t k, t; | |
1122 | ::decode(k, bl); | |
1123 | ::decode(t, bl); | |
1124 | if (t == STR) { | |
1125 | std::string s; | |
1126 | ::decode(s, bl); | |
1127 | opts[static_cast<key_t>(k)] = s; | |
1128 | } else if (t == INT) { | |
1129 | int i; | |
1130 | ::decode(i, bl); | |
1131 | opts[static_cast<key_t>(k)] = i; | |
1132 | } else if (t == DOUBLE) { | |
1133 | double d; | |
1134 | ::decode(d, bl); | |
1135 | opts[static_cast<key_t>(k)] = d; | |
1136 | } else { | |
1137 | assert(!"invalid type"); | |
1138 | } | |
1139 | } | |
1140 | DECODE_FINISH(bl); | |
1141 | } | |
1142 | ||
1143 | ostream& operator<<(ostream& out, const pool_opts_t& opts) | |
1144 | { | |
1145 | for (opt_mapping_t::iterator i = opt_mapping.begin(); i != opt_mapping.end(); | |
1146 | ++i) { | |
1147 | const std::string& name = i->first; | |
1148 | const pool_opts_t::opt_desc_t& desc = i->second; | |
1149 | pool_opts_t::opts_t::const_iterator j = opts.opts.find(desc.key); | |
1150 | if (j == opts.opts.end()) { | |
1151 | continue; | |
1152 | } | |
1153 | out << " " << name << " " << j->second; | |
1154 | } | |
1155 | return out; | |
1156 | } | |
1157 | ||
1158 | // -- pg_pool_t -- | |
1159 | ||
c07f9fc5 FG |
1160 | const char *pg_pool_t::APPLICATION_NAME_CEPHFS("cephfs"); |
1161 | const char *pg_pool_t::APPLICATION_NAME_RBD("rbd"); | |
1162 | const char *pg_pool_t::APPLICATION_NAME_RGW("rgw"); | |
1163 | ||
7c673cae FG |
1164 | void pg_pool_t::dump(Formatter *f) const |
1165 | { | |
1166 | f->dump_unsigned("flags", get_flags()); | |
1167 | f->dump_string("flags_names", get_flags_string()); | |
1168 | f->dump_int("type", get_type()); | |
1169 | f->dump_int("size", get_size()); | |
1170 | f->dump_int("min_size", get_min_size()); | |
31f18b77 | 1171 | f->dump_int("crush_rule", get_crush_rule()); |
7c673cae FG |
1172 | f->dump_int("object_hash", get_object_hash()); |
1173 | f->dump_unsigned("pg_num", get_pg_num()); | |
1174 | f->dump_unsigned("pg_placement_num", get_pgp_num()); | |
1175 | f->dump_unsigned("crash_replay_interval", get_crash_replay_interval()); | |
1176 | f->dump_stream("last_change") << get_last_change(); | |
1177 | f->dump_stream("last_force_op_resend") << get_last_force_op_resend(); | |
1178 | f->dump_stream("last_force_op_resend_preluminous") | |
1179 | << get_last_force_op_resend_preluminous(); | |
1180 | f->dump_unsigned("auid", get_auid()); | |
1181 | f->dump_string("snap_mode", is_pool_snaps_mode() ? "pool" : "selfmanaged"); | |
1182 | f->dump_unsigned("snap_seq", get_snap_seq()); | |
1183 | f->dump_unsigned("snap_epoch", get_snap_epoch()); | |
1184 | f->open_array_section("pool_snaps"); | |
1185 | for (map<snapid_t, pool_snap_info_t>::const_iterator p = snaps.begin(); p != snaps.end(); ++p) { | |
1186 | f->open_object_section("pool_snap_info"); | |
1187 | p->second.dump(f); | |
1188 | f->close_section(); | |
1189 | } | |
1190 | f->close_section(); | |
1191 | f->dump_stream("removed_snaps") << removed_snaps; | |
1192 | f->dump_unsigned("quota_max_bytes", quota_max_bytes); | |
1193 | f->dump_unsigned("quota_max_objects", quota_max_objects); | |
1194 | f->open_array_section("tiers"); | |
1195 | for (set<uint64_t>::const_iterator p = tiers.begin(); p != tiers.end(); ++p) | |
1196 | f->dump_unsigned("pool_id", *p); | |
1197 | f->close_section(); | |
1198 | f->dump_int("tier_of", tier_of); | |
1199 | f->dump_int("read_tier", read_tier); | |
1200 | f->dump_int("write_tier", write_tier); | |
1201 | f->dump_string("cache_mode", get_cache_mode_name()); | |
1202 | f->dump_unsigned("target_max_bytes", target_max_bytes); | |
1203 | f->dump_unsigned("target_max_objects", target_max_objects); | |
1204 | f->dump_unsigned("cache_target_dirty_ratio_micro", | |
1205 | cache_target_dirty_ratio_micro); | |
1206 | f->dump_unsigned("cache_target_dirty_high_ratio_micro", | |
1207 | cache_target_dirty_high_ratio_micro); | |
1208 | f->dump_unsigned("cache_target_full_ratio_micro", | |
1209 | cache_target_full_ratio_micro); | |
1210 | f->dump_unsigned("cache_min_flush_age", cache_min_flush_age); | |
1211 | f->dump_unsigned("cache_min_evict_age", cache_min_evict_age); | |
1212 | f->dump_string("erasure_code_profile", erasure_code_profile); | |
1213 | f->open_object_section("hit_set_params"); | |
1214 | hit_set_params.dump(f); | |
1215 | f->close_section(); // hit_set_params | |
1216 | f->dump_unsigned("hit_set_period", hit_set_period); | |
1217 | f->dump_unsigned("hit_set_count", hit_set_count); | |
1218 | f->dump_bool("use_gmt_hitset", use_gmt_hitset); | |
1219 | f->dump_unsigned("min_read_recency_for_promote", min_read_recency_for_promote); | |
1220 | f->dump_unsigned("min_write_recency_for_promote", min_write_recency_for_promote); | |
1221 | f->dump_unsigned("hit_set_grade_decay_rate", hit_set_grade_decay_rate); | |
1222 | f->dump_unsigned("hit_set_search_last_n", hit_set_search_last_n); | |
1223 | f->open_array_section("grade_table"); | |
1224 | for (unsigned i = 0; i < hit_set_count; ++i) | |
1225 | f->dump_unsigned("value", get_grade(i)); | |
1226 | f->close_section(); | |
1227 | f->dump_unsigned("stripe_width", get_stripe_width()); | |
1228 | f->dump_unsigned("expected_num_objects", expected_num_objects); | |
1229 | f->dump_bool("fast_read", fast_read); | |
1230 | f->open_object_section("options"); | |
1231 | opts.dump(f); | |
1232 | f->close_section(); // options | |
c07f9fc5 FG |
1233 | f->open_object_section("application_metadata"); |
1234 | for (auto &app_pair : application_metadata) { | |
1235 | f->open_object_section(app_pair.first.c_str()); | |
1236 | for (auto &kv_pair : app_pair.second) { | |
1237 | f->dump_string(kv_pair.first.c_str(), kv_pair.second); | |
1238 | } | |
1239 | f->close_section(); // application | |
1240 | } | |
1241 | f->close_section(); // application_metadata | |
7c673cae FG |
1242 | } |
1243 | ||
1244 | void pg_pool_t::convert_to_pg_shards(const vector<int> &from, set<pg_shard_t>* to) const { | |
1245 | for (size_t i = 0; i < from.size(); ++i) { | |
1246 | if (from[i] != CRUSH_ITEM_NONE) { | |
1247 | to->insert( | |
1248 | pg_shard_t( | |
1249 | from[i], | |
1250 | ec_pool() ? shard_id_t(i) : shard_id_t::NO_SHARD)); | |
1251 | } | |
1252 | } | |
1253 | } | |
1254 | ||
1255 | void pg_pool_t::calc_pg_masks() | |
1256 | { | |
1257 | pg_num_mask = (1 << cbits(pg_num-1)) - 1; | |
1258 | pgp_num_mask = (1 << cbits(pgp_num-1)) - 1; | |
1259 | } | |
1260 | ||
1261 | unsigned pg_pool_t::get_pg_num_divisor(pg_t pgid) const | |
1262 | { | |
1263 | if (pg_num == pg_num_mask + 1) | |
1264 | return pg_num; // power-of-2 split | |
1265 | unsigned mask = pg_num_mask >> 1; | |
1266 | if ((pgid.ps() & mask) < (pg_num & mask)) | |
1267 | return pg_num_mask + 1; // smaller bin size (already split) | |
1268 | else | |
1269 | return (pg_num_mask + 1) >> 1; // bigger bin (not yet split) | |
1270 | } | |
1271 | ||
1272 | /* | |
1273 | * we have two snap modes: | |
1274 | * - pool global snaps | |
1275 | * - snap existence/non-existence defined by snaps[] and snap_seq | |
1276 | * - user managed snaps | |
1277 | * - removal governed by removed_snaps | |
1278 | * | |
1279 | * we know which mode we're using based on whether removed_snaps is empty. | |
1280 | */ | |
1281 | bool pg_pool_t::is_pool_snaps_mode() const | |
1282 | { | |
1283 | return removed_snaps.empty() && get_snap_seq() > 0; | |
1284 | } | |
1285 | ||
1286 | bool pg_pool_t::is_unmanaged_snaps_mode() const | |
1287 | { | |
1288 | return removed_snaps.size() && get_snap_seq() > 0; | |
1289 | } | |
1290 | ||
1291 | bool pg_pool_t::is_removed_snap(snapid_t s) const | |
1292 | { | |
1293 | if (is_pool_snaps_mode()) | |
1294 | return s <= get_snap_seq() && snaps.count(s) == 0; | |
1295 | else | |
1296 | return removed_snaps.contains(s); | |
1297 | } | |
1298 | ||
1299 | /* | |
1300 | * build set of known-removed sets from either pool snaps or | |
1301 | * explicit removed_snaps set. | |
1302 | */ | |
1303 | void pg_pool_t::build_removed_snaps(interval_set<snapid_t>& rs) const | |
1304 | { | |
1305 | if (is_pool_snaps_mode()) { | |
1306 | rs.clear(); | |
1307 | for (snapid_t s = 1; s <= get_snap_seq(); s = s + 1) | |
1308 | if (snaps.count(s) == 0) | |
1309 | rs.insert(s); | |
1310 | } else { | |
1311 | rs = removed_snaps; | |
1312 | } | |
1313 | } | |
1314 | ||
1315 | snapid_t pg_pool_t::snap_exists(const char *s) const | |
1316 | { | |
1317 | for (map<snapid_t,pool_snap_info_t>::const_iterator p = snaps.begin(); | |
1318 | p != snaps.end(); | |
1319 | ++p) | |
1320 | if (p->second.name == s) | |
1321 | return p->second.snapid; | |
1322 | return 0; | |
1323 | } | |
1324 | ||
1325 | void pg_pool_t::add_snap(const char *n, utime_t stamp) | |
1326 | { | |
1327 | assert(!is_unmanaged_snaps_mode()); | |
1328 | snapid_t s = get_snap_seq() + 1; | |
1329 | snap_seq = s; | |
1330 | snaps[s].snapid = s; | |
1331 | snaps[s].name = n; | |
1332 | snaps[s].stamp = stamp; | |
1333 | } | |
1334 | ||
1335 | void pg_pool_t::add_unmanaged_snap(uint64_t& snapid) | |
1336 | { | |
1337 | if (removed_snaps.empty()) { | |
1338 | assert(!is_pool_snaps_mode()); | |
1339 | removed_snaps.insert(snapid_t(1)); | |
1340 | snap_seq = 1; | |
1341 | } | |
1342 | snapid = snap_seq = snap_seq + 1; | |
1343 | } | |
1344 | ||
1345 | void pg_pool_t::remove_snap(snapid_t s) | |
1346 | { | |
1347 | assert(snaps.count(s)); | |
1348 | snaps.erase(s); | |
1349 | snap_seq = snap_seq + 1; | |
1350 | } | |
1351 | ||
1352 | void pg_pool_t::remove_unmanaged_snap(snapid_t s) | |
1353 | { | |
1354 | assert(is_unmanaged_snaps_mode()); | |
1355 | removed_snaps.insert(s); | |
1356 | snap_seq = snap_seq + 1; | |
1357 | removed_snaps.insert(get_snap_seq()); | |
1358 | } | |
1359 | ||
1360 | SnapContext pg_pool_t::get_snap_context() const | |
1361 | { | |
1362 | vector<snapid_t> s(snaps.size()); | |
1363 | unsigned i = 0; | |
1364 | for (map<snapid_t, pool_snap_info_t>::const_reverse_iterator p = snaps.rbegin(); | |
1365 | p != snaps.rend(); | |
1366 | ++p) | |
1367 | s[i++] = p->first; | |
1368 | return SnapContext(get_snap_seq(), s); | |
1369 | } | |
1370 | ||
1371 | uint32_t pg_pool_t::hash_key(const string& key, const string& ns) const | |
1372 | { | |
1373 | if (ns.empty()) | |
1374 | return ceph_str_hash(object_hash, key.data(), key.length()); | |
1375 | int nsl = ns.length(); | |
1376 | int len = key.length() + nsl + 1; | |
1377 | char buf[len]; | |
1378 | memcpy(&buf[0], ns.data(), nsl); | |
1379 | buf[nsl] = '\037'; | |
1380 | memcpy(&buf[nsl+1], key.data(), key.length()); | |
1381 | return ceph_str_hash(object_hash, &buf[0], len); | |
1382 | } | |
1383 | ||
1384 | uint32_t pg_pool_t::raw_hash_to_pg(uint32_t v) const | |
1385 | { | |
1386 | return ceph_stable_mod(v, pg_num, pg_num_mask); | |
1387 | } | |
1388 | ||
1389 | /* | |
1390 | * map a raw pg (with full precision ps) into an actual pg, for storage | |
1391 | */ | |
1392 | pg_t pg_pool_t::raw_pg_to_pg(pg_t pg) const | |
1393 | { | |
1394 | pg.set_ps(ceph_stable_mod(pg.ps(), pg_num, pg_num_mask)); | |
1395 | return pg; | |
1396 | } | |
1397 | ||
1398 | /* | |
1399 | * map raw pg (full precision ps) into a placement seed. include | |
1400 | * pool id in that value so that different pools don't use the same | |
1401 | * seeds. | |
1402 | */ | |
1403 | ps_t pg_pool_t::raw_pg_to_pps(pg_t pg) const | |
1404 | { | |
1405 | if (flags & FLAG_HASHPSPOOL) { | |
1406 | // Hash the pool id so that pool PGs do not overlap. | |
1407 | return | |
1408 | crush_hash32_2(CRUSH_HASH_RJENKINS1, | |
1409 | ceph_stable_mod(pg.ps(), pgp_num, pgp_num_mask), | |
1410 | pg.pool()); | |
1411 | } else { | |
1412 | // Legacy behavior; add ps and pool together. This is not a great | |
1413 | // idea because the PGs from each pool will essentially overlap on | |
1414 | // top of each other: 0.5 == 1.4 == 2.3 == ... | |
1415 | return | |
1416 | ceph_stable_mod(pg.ps(), pgp_num, pgp_num_mask) + | |
1417 | pg.pool(); | |
1418 | } | |
1419 | } | |
1420 | ||
1421 | uint32_t pg_pool_t::get_random_pg_position(pg_t pg, uint32_t seed) const | |
1422 | { | |
1423 | uint32_t r = crush_hash32_2(CRUSH_HASH_RJENKINS1, seed, 123); | |
1424 | if (pg_num == pg_num_mask + 1) { | |
1425 | r &= ~pg_num_mask; | |
1426 | } else { | |
1427 | unsigned smaller_mask = pg_num_mask >> 1; | |
1428 | if ((pg.ps() & smaller_mask) < (pg_num & smaller_mask)) { | |
1429 | r &= ~pg_num_mask; | |
1430 | } else { | |
1431 | r &= ~smaller_mask; | |
1432 | } | |
1433 | } | |
1434 | r |= pg.ps(); | |
1435 | return r; | |
1436 | } | |
1437 | ||
1438 | void pg_pool_t::encode(bufferlist& bl, uint64_t features) const | |
1439 | { | |
1440 | if ((features & CEPH_FEATURE_PGPOOL3) == 0) { | |
1441 | // this encoding matches the old struct ceph_pg_pool | |
1442 | __u8 struct_v = 2; | |
1443 | ::encode(struct_v, bl); | |
1444 | ::encode(type, bl); | |
1445 | ::encode(size, bl); | |
31f18b77 | 1446 | ::encode(crush_rule, bl); |
7c673cae FG |
1447 | ::encode(object_hash, bl); |
1448 | ::encode(pg_num, bl); | |
1449 | ::encode(pgp_num, bl); | |
1450 | __u32 lpg_num = 0, lpgp_num = 0; // tell old code that there are no localized pgs. | |
1451 | ::encode(lpg_num, bl); | |
1452 | ::encode(lpgp_num, bl); | |
1453 | ::encode(last_change, bl); | |
1454 | ::encode(snap_seq, bl); | |
1455 | ::encode(snap_epoch, bl); | |
1456 | ||
1457 | __u32 n = snaps.size(); | |
1458 | ::encode(n, bl); | |
1459 | n = removed_snaps.num_intervals(); | |
1460 | ::encode(n, bl); | |
1461 | ||
1462 | ::encode(auid, bl); | |
1463 | ||
1464 | ::encode_nohead(snaps, bl, features); | |
1465 | ::encode_nohead(removed_snaps, bl); | |
1466 | return; | |
1467 | } | |
1468 | ||
1469 | if ((features & CEPH_FEATURE_OSDENC) == 0) { | |
1470 | __u8 struct_v = 4; | |
1471 | ::encode(struct_v, bl); | |
1472 | ::encode(type, bl); | |
1473 | ::encode(size, bl); | |
31f18b77 | 1474 | ::encode(crush_rule, bl); |
7c673cae FG |
1475 | ::encode(object_hash, bl); |
1476 | ::encode(pg_num, bl); | |
1477 | ::encode(pgp_num, bl); | |
1478 | __u32 lpg_num = 0, lpgp_num = 0; // tell old code that there are no localized pgs. | |
1479 | ::encode(lpg_num, bl); | |
1480 | ::encode(lpgp_num, bl); | |
1481 | ::encode(last_change, bl); | |
1482 | ::encode(snap_seq, bl); | |
1483 | ::encode(snap_epoch, bl); | |
1484 | ::encode(snaps, bl, features); | |
1485 | ::encode(removed_snaps, bl); | |
1486 | ::encode(auid, bl); | |
1487 | ::encode(flags, bl); | |
1488 | ::encode(crash_replay_interval, bl); | |
1489 | return; | |
1490 | } | |
1491 | ||
1492 | if ((features & CEPH_FEATURE_OSD_POOLRESEND) == 0) { | |
1493 | // we simply added last_force_op_resend here, which is a fully | |
1494 | // backward compatible change. however, encoding the same map | |
1495 | // differently between monitors triggers scrub noise (even though | |
1496 | // they are decodable without the feature), so let's be pendantic | |
1497 | // about it. | |
1498 | ENCODE_START(14, 5, bl); | |
1499 | ::encode(type, bl); | |
1500 | ::encode(size, bl); | |
31f18b77 | 1501 | ::encode(crush_rule, bl); |
7c673cae FG |
1502 | ::encode(object_hash, bl); |
1503 | ::encode(pg_num, bl); | |
1504 | ::encode(pgp_num, bl); | |
1505 | __u32 lpg_num = 0, lpgp_num = 0; // tell old code that there are no localized pgs. | |
1506 | ::encode(lpg_num, bl); | |
1507 | ::encode(lpgp_num, bl); | |
1508 | ::encode(last_change, bl); | |
1509 | ::encode(snap_seq, bl); | |
1510 | ::encode(snap_epoch, bl); | |
1511 | ::encode(snaps, bl, features); | |
1512 | ::encode(removed_snaps, bl); | |
1513 | ::encode(auid, bl); | |
1514 | ::encode(flags, bl); | |
1515 | ::encode(crash_replay_interval, bl); | |
1516 | ::encode(min_size, bl); | |
1517 | ::encode(quota_max_bytes, bl); | |
1518 | ::encode(quota_max_objects, bl); | |
1519 | ::encode(tiers, bl); | |
1520 | ::encode(tier_of, bl); | |
1521 | __u8 c = cache_mode; | |
1522 | ::encode(c, bl); | |
1523 | ::encode(read_tier, bl); | |
1524 | ::encode(write_tier, bl); | |
1525 | ::encode(properties, bl); | |
1526 | ::encode(hit_set_params, bl); | |
1527 | ::encode(hit_set_period, bl); | |
1528 | ::encode(hit_set_count, bl); | |
1529 | ::encode(stripe_width, bl); | |
1530 | ::encode(target_max_bytes, bl); | |
1531 | ::encode(target_max_objects, bl); | |
1532 | ::encode(cache_target_dirty_ratio_micro, bl); | |
1533 | ::encode(cache_target_full_ratio_micro, bl); | |
1534 | ::encode(cache_min_flush_age, bl); | |
1535 | ::encode(cache_min_evict_age, bl); | |
1536 | ::encode(erasure_code_profile, bl); | |
1537 | ENCODE_FINISH(bl); | |
1538 | return; | |
1539 | } | |
1540 | ||
c07f9fc5 | 1541 | uint8_t v = 26; |
7c673cae FG |
1542 | if (!(features & CEPH_FEATURE_NEW_OSDOP_ENCODING)) { |
1543 | // this was the first post-hammer thing we added; if it's missing, encode | |
1544 | // like hammer. | |
1545 | v = 21; | |
94b18763 | 1546 | } else if (!HAVE_FEATURE(features, SERVER_LUMINOUS)) { |
7c673cae FG |
1547 | v = 24; |
1548 | } | |
1549 | ||
1550 | ENCODE_START(v, 5, bl); | |
1551 | ::encode(type, bl); | |
1552 | ::encode(size, bl); | |
31f18b77 | 1553 | ::encode(crush_rule, bl); |
7c673cae FG |
1554 | ::encode(object_hash, bl); |
1555 | ::encode(pg_num, bl); | |
1556 | ::encode(pgp_num, bl); | |
1557 | __u32 lpg_num = 0, lpgp_num = 0; // tell old code that there are no localized pgs. | |
1558 | ::encode(lpg_num, bl); | |
1559 | ::encode(lpgp_num, bl); | |
1560 | ::encode(last_change, bl); | |
1561 | ::encode(snap_seq, bl); | |
1562 | ::encode(snap_epoch, bl); | |
1563 | ::encode(snaps, bl, features); | |
1564 | ::encode(removed_snaps, bl); | |
1565 | ::encode(auid, bl); | |
1566 | ::encode(flags, bl); | |
1567 | ::encode(crash_replay_interval, bl); | |
1568 | ::encode(min_size, bl); | |
1569 | ::encode(quota_max_bytes, bl); | |
1570 | ::encode(quota_max_objects, bl); | |
1571 | ::encode(tiers, bl); | |
1572 | ::encode(tier_of, bl); | |
1573 | __u8 c = cache_mode; | |
1574 | ::encode(c, bl); | |
1575 | ::encode(read_tier, bl); | |
1576 | ::encode(write_tier, bl); | |
1577 | ::encode(properties, bl); | |
1578 | ::encode(hit_set_params, bl); | |
1579 | ::encode(hit_set_period, bl); | |
1580 | ::encode(hit_set_count, bl); | |
1581 | ::encode(stripe_width, bl); | |
1582 | ::encode(target_max_bytes, bl); | |
1583 | ::encode(target_max_objects, bl); | |
1584 | ::encode(cache_target_dirty_ratio_micro, bl); | |
1585 | ::encode(cache_target_full_ratio_micro, bl); | |
1586 | ::encode(cache_min_flush_age, bl); | |
1587 | ::encode(cache_min_evict_age, bl); | |
1588 | ::encode(erasure_code_profile, bl); | |
1589 | ::encode(last_force_op_resend_preluminous, bl); | |
1590 | ::encode(min_read_recency_for_promote, bl); | |
1591 | ::encode(expected_num_objects, bl); | |
1592 | if (v >= 19) { | |
1593 | ::encode(cache_target_dirty_high_ratio_micro, bl); | |
1594 | } | |
1595 | if (v >= 20) { | |
1596 | ::encode(min_write_recency_for_promote, bl); | |
1597 | } | |
1598 | if (v >= 21) { | |
1599 | ::encode(use_gmt_hitset, bl); | |
1600 | } | |
1601 | if (v >= 22) { | |
1602 | ::encode(fast_read, bl); | |
1603 | } | |
1604 | if (v >= 23) { | |
1605 | ::encode(hit_set_grade_decay_rate, bl); | |
1606 | ::encode(hit_set_search_last_n, bl); | |
1607 | } | |
1608 | if (v >= 24) { | |
1609 | ::encode(opts, bl); | |
1610 | } | |
1611 | if (v >= 25) { | |
1612 | ::encode(last_force_op_resend, bl); | |
1613 | } | |
c07f9fc5 FG |
1614 | if (v >= 26) { |
1615 | ::encode(application_metadata, bl); | |
1616 | } | |
7c673cae FG |
1617 | ENCODE_FINISH(bl); |
1618 | } | |
1619 | ||
1620 | void pg_pool_t::decode(bufferlist::iterator& bl) | |
1621 | { | |
c07f9fc5 | 1622 | DECODE_START_LEGACY_COMPAT_LEN(26, 5, 5, bl); |
7c673cae FG |
1623 | ::decode(type, bl); |
1624 | ::decode(size, bl); | |
31f18b77 | 1625 | ::decode(crush_rule, bl); |
7c673cae FG |
1626 | ::decode(object_hash, bl); |
1627 | ::decode(pg_num, bl); | |
1628 | ::decode(pgp_num, bl); | |
1629 | { | |
1630 | __u32 lpg_num, lpgp_num; | |
1631 | ::decode(lpg_num, bl); | |
1632 | ::decode(lpgp_num, bl); | |
1633 | } | |
1634 | ::decode(last_change, bl); | |
1635 | ::decode(snap_seq, bl); | |
1636 | ::decode(snap_epoch, bl); | |
1637 | ||
1638 | if (struct_v >= 3) { | |
1639 | ::decode(snaps, bl); | |
1640 | ::decode(removed_snaps, bl); | |
1641 | ::decode(auid, bl); | |
1642 | } else { | |
1643 | __u32 n, m; | |
1644 | ::decode(n, bl); | |
1645 | ::decode(m, bl); | |
1646 | ::decode(auid, bl); | |
1647 | ::decode_nohead(n, snaps, bl); | |
1648 | ::decode_nohead(m, removed_snaps, bl); | |
1649 | } | |
1650 | ||
1651 | if (struct_v >= 4) { | |
1652 | ::decode(flags, bl); | |
1653 | ::decode(crash_replay_interval, bl); | |
1654 | } else { | |
1655 | flags = 0; | |
1656 | ||
1657 | // if this looks like the 'data' pool, set the | |
1658 | // crash_replay_interval appropriately. unfortunately, we can't | |
1659 | // be precise here. this should be good enough to preserve replay | |
1660 | // on the data pool for the majority of cluster upgrades, though. | |
31f18b77 | 1661 | if (crush_rule == 0 && auid == 0) |
7c673cae FG |
1662 | crash_replay_interval = 60; |
1663 | else | |
1664 | crash_replay_interval = 0; | |
1665 | } | |
1666 | if (struct_v >= 7) { | |
1667 | ::decode(min_size, bl); | |
1668 | } else { | |
1669 | min_size = size - size/2; | |
1670 | } | |
1671 | if (struct_v >= 8) { | |
1672 | ::decode(quota_max_bytes, bl); | |
1673 | ::decode(quota_max_objects, bl); | |
1674 | } | |
1675 | if (struct_v >= 9) { | |
1676 | ::decode(tiers, bl); | |
1677 | ::decode(tier_of, bl); | |
1678 | __u8 v; | |
1679 | ::decode(v, bl); | |
1680 | cache_mode = (cache_mode_t)v; | |
1681 | ::decode(read_tier, bl); | |
1682 | ::decode(write_tier, bl); | |
1683 | } | |
1684 | if (struct_v >= 10) { | |
1685 | ::decode(properties, bl); | |
1686 | } | |
1687 | if (struct_v >= 11) { | |
1688 | ::decode(hit_set_params, bl); | |
1689 | ::decode(hit_set_period, bl); | |
1690 | ::decode(hit_set_count, bl); | |
1691 | } else { | |
1692 | pg_pool_t def; | |
1693 | hit_set_period = def.hit_set_period; | |
1694 | hit_set_count = def.hit_set_count; | |
1695 | } | |
1696 | if (struct_v >= 12) { | |
1697 | ::decode(stripe_width, bl); | |
1698 | } else { | |
1699 | set_stripe_width(0); | |
1700 | } | |
1701 | if (struct_v >= 13) { | |
1702 | ::decode(target_max_bytes, bl); | |
1703 | ::decode(target_max_objects, bl); | |
1704 | ::decode(cache_target_dirty_ratio_micro, bl); | |
1705 | ::decode(cache_target_full_ratio_micro, bl); | |
1706 | ::decode(cache_min_flush_age, bl); | |
1707 | ::decode(cache_min_evict_age, bl); | |
1708 | } else { | |
1709 | target_max_bytes = 0; | |
1710 | target_max_objects = 0; | |
1711 | cache_target_dirty_ratio_micro = 0; | |
1712 | cache_target_full_ratio_micro = 0; | |
1713 | cache_min_flush_age = 0; | |
1714 | cache_min_evict_age = 0; | |
1715 | } | |
1716 | if (struct_v >= 14) { | |
1717 | ::decode(erasure_code_profile, bl); | |
1718 | } | |
1719 | if (struct_v >= 15) { | |
1720 | ::decode(last_force_op_resend_preluminous, bl); | |
1721 | } else { | |
1722 | last_force_op_resend_preluminous = 0; | |
1723 | } | |
1724 | if (struct_v >= 16) { | |
1725 | ::decode(min_read_recency_for_promote, bl); | |
1726 | } else { | |
1727 | min_read_recency_for_promote = 1; | |
1728 | } | |
1729 | if (struct_v >= 17) { | |
1730 | ::decode(expected_num_objects, bl); | |
1731 | } else { | |
1732 | expected_num_objects = 0; | |
1733 | } | |
1734 | if (struct_v >= 19) { | |
1735 | ::decode(cache_target_dirty_high_ratio_micro, bl); | |
1736 | } else { | |
1737 | cache_target_dirty_high_ratio_micro = cache_target_dirty_ratio_micro; | |
1738 | } | |
1739 | if (struct_v >= 20) { | |
1740 | ::decode(min_write_recency_for_promote, bl); | |
1741 | } else { | |
1742 | min_write_recency_for_promote = 1; | |
1743 | } | |
1744 | if (struct_v >= 21) { | |
1745 | ::decode(use_gmt_hitset, bl); | |
1746 | } else { | |
1747 | use_gmt_hitset = false; | |
1748 | } | |
1749 | if (struct_v >= 22) { | |
1750 | ::decode(fast_read, bl); | |
1751 | } else { | |
1752 | fast_read = false; | |
1753 | } | |
1754 | if (struct_v >= 23) { | |
1755 | ::decode(hit_set_grade_decay_rate, bl); | |
1756 | ::decode(hit_set_search_last_n, bl); | |
1757 | } else { | |
1758 | hit_set_grade_decay_rate = 0; | |
1759 | hit_set_search_last_n = 1; | |
1760 | } | |
1761 | if (struct_v >= 24) { | |
1762 | ::decode(opts, bl); | |
1763 | } | |
1764 | if (struct_v >= 25) { | |
1765 | ::decode(last_force_op_resend, bl); | |
1766 | } else { | |
1767 | last_force_op_resend = last_force_op_resend_preluminous; | |
1768 | } | |
c07f9fc5 FG |
1769 | if (struct_v >= 26) { |
1770 | ::decode(application_metadata, bl); | |
1771 | } | |
7c673cae FG |
1772 | DECODE_FINISH(bl); |
1773 | calc_pg_masks(); | |
1774 | calc_grade_table(); | |
1775 | } | |
1776 | ||
1777 | void pg_pool_t::generate_test_instances(list<pg_pool_t*>& o) | |
1778 | { | |
1779 | pg_pool_t a; | |
1780 | o.push_back(new pg_pool_t(a)); | |
1781 | ||
1782 | a.type = TYPE_REPLICATED; | |
1783 | a.size = 2; | |
31f18b77 | 1784 | a.crush_rule = 3; |
7c673cae FG |
1785 | a.object_hash = 4; |
1786 | a.pg_num = 6; | |
1787 | a.pgp_num = 5; | |
1788 | a.last_change = 9; | |
1789 | a.last_force_op_resend = 123823; | |
1790 | a.last_force_op_resend_preluminous = 123824; | |
1791 | a.snap_seq = 10; | |
1792 | a.snap_epoch = 11; | |
1793 | a.auid = 12; | |
1794 | a.crash_replay_interval = 13; | |
1795 | a.quota_max_bytes = 473; | |
1796 | a.quota_max_objects = 474; | |
1797 | o.push_back(new pg_pool_t(a)); | |
1798 | ||
1799 | a.snaps[3].name = "asdf"; | |
1800 | a.snaps[3].snapid = 3; | |
1801 | a.snaps[3].stamp = utime_t(123, 4); | |
1802 | a.snaps[6].name = "qwer"; | |
1803 | a.snaps[6].snapid = 6; | |
1804 | a.snaps[6].stamp = utime_t(23423, 4); | |
1805 | o.push_back(new pg_pool_t(a)); | |
1806 | ||
1807 | a.removed_snaps.insert(2); // not quite valid to combine with snaps! | |
1808 | a.quota_max_bytes = 2473; | |
1809 | a.quota_max_objects = 4374; | |
1810 | a.tiers.insert(0); | |
1811 | a.tiers.insert(1); | |
1812 | a.tier_of = 2; | |
1813 | a.cache_mode = CACHEMODE_WRITEBACK; | |
1814 | a.read_tier = 1; | |
1815 | a.write_tier = 1; | |
1816 | a.hit_set_params = HitSet::Params(new BloomHitSet::Params); | |
1817 | a.hit_set_period = 3600; | |
1818 | a.hit_set_count = 8; | |
1819 | a.min_read_recency_for_promote = 1; | |
1820 | a.min_write_recency_for_promote = 1; | |
1821 | a.hit_set_grade_decay_rate = 50; | |
1822 | a.hit_set_search_last_n = 1; | |
1823 | a.calc_grade_table(); | |
1824 | a.set_stripe_width(12345); | |
1825 | a.target_max_bytes = 1238132132; | |
1826 | a.target_max_objects = 1232132; | |
1827 | a.cache_target_dirty_ratio_micro = 187232; | |
1828 | a.cache_target_dirty_high_ratio_micro = 309856; | |
1829 | a.cache_target_full_ratio_micro = 987222; | |
1830 | a.cache_min_flush_age = 231; | |
1831 | a.cache_min_evict_age = 2321; | |
1832 | a.erasure_code_profile = "profile in osdmap"; | |
1833 | a.expected_num_objects = 123456; | |
1834 | a.fast_read = false; | |
c07f9fc5 | 1835 | a.application_metadata = {{"rbd", {{"key", "value"}}}}; |
7c673cae FG |
1836 | o.push_back(new pg_pool_t(a)); |
1837 | } | |
1838 | ||
1839 | ostream& operator<<(ostream& out, const pg_pool_t& p) | |
1840 | { | |
1841 | out << p.get_type_name() | |
1842 | << " size " << p.get_size() | |
1843 | << " min_size " << p.get_min_size() | |
31f18b77 | 1844 | << " crush_rule " << p.get_crush_rule() |
7c673cae FG |
1845 | << " object_hash " << p.get_object_hash_name() |
1846 | << " pg_num " << p.get_pg_num() | |
1847 | << " pgp_num " << p.get_pgp_num() | |
1848 | << " last_change " << p.get_last_change(); | |
1849 | if (p.get_last_force_op_resend() || | |
1850 | p.get_last_force_op_resend_preluminous()) | |
1851 | out << " lfor " << p.get_last_force_op_resend() << "/" | |
1852 | << p.get_last_force_op_resend_preluminous(); | |
1853 | if (p.get_auid()) | |
1854 | out << " owner " << p.get_auid(); | |
1855 | if (p.flags) | |
1856 | out << " flags " << p.get_flags_string(); | |
1857 | if (p.crash_replay_interval) | |
1858 | out << " crash_replay_interval " << p.crash_replay_interval; | |
1859 | if (p.quota_max_bytes) | |
1860 | out << " max_bytes " << p.quota_max_bytes; | |
1861 | if (p.quota_max_objects) | |
1862 | out << " max_objects " << p.quota_max_objects; | |
1863 | if (!p.tiers.empty()) | |
1864 | out << " tiers " << p.tiers; | |
1865 | if (p.is_tier()) | |
1866 | out << " tier_of " << p.tier_of; | |
1867 | if (p.has_read_tier()) | |
1868 | out << " read_tier " << p.read_tier; | |
1869 | if (p.has_write_tier()) | |
1870 | out << " write_tier " << p.write_tier; | |
1871 | if (p.cache_mode) | |
1872 | out << " cache_mode " << p.get_cache_mode_name(); | |
1873 | if (p.target_max_bytes) | |
1874 | out << " target_bytes " << p.target_max_bytes; | |
1875 | if (p.target_max_objects) | |
1876 | out << " target_objects " << p.target_max_objects; | |
1877 | if (p.hit_set_params.get_type() != HitSet::TYPE_NONE) { | |
1878 | out << " hit_set " << p.hit_set_params | |
1879 | << " " << p.hit_set_period << "s" | |
1880 | << " x" << p.hit_set_count << " decay_rate " | |
1881 | << p.hit_set_grade_decay_rate | |
1882 | << " search_last_n " << p.hit_set_search_last_n; | |
1883 | } | |
1884 | if (p.min_read_recency_for_promote) | |
1885 | out << " min_read_recency_for_promote " << p.min_read_recency_for_promote; | |
1886 | if (p.min_write_recency_for_promote) | |
1887 | out << " min_write_recency_for_promote " << p.min_write_recency_for_promote; | |
1888 | out << " stripe_width " << p.get_stripe_width(); | |
1889 | if (p.expected_num_objects) | |
1890 | out << " expected_num_objects " << p.expected_num_objects; | |
1891 | if (p.fast_read) | |
1892 | out << " fast_read " << p.fast_read; | |
1893 | out << p.opts; | |
c07f9fc5 FG |
1894 | if (!p.application_metadata.empty()) { |
1895 | out << " application "; | |
1896 | for (auto it = p.application_metadata.begin(); | |
1897 | it != p.application_metadata.end(); ++it) { | |
1898 | if (it != p.application_metadata.begin()) | |
1899 | out << ","; | |
1900 | out << it->first; | |
1901 | } | |
1902 | } | |
7c673cae FG |
1903 | return out; |
1904 | } | |
1905 | ||
1906 | ||
1907 | // -- object_stat_sum_t -- | |
1908 | ||
1909 | void object_stat_sum_t::dump(Formatter *f) const | |
1910 | { | |
1911 | f->dump_int("num_bytes", num_bytes); | |
1912 | f->dump_int("num_objects", num_objects); | |
1913 | f->dump_int("num_object_clones", num_object_clones); | |
1914 | f->dump_int("num_object_copies", num_object_copies); | |
1915 | f->dump_int("num_objects_missing_on_primary", num_objects_missing_on_primary); | |
1916 | f->dump_int("num_objects_missing", num_objects_missing); | |
1917 | f->dump_int("num_objects_degraded", num_objects_degraded); | |
1918 | f->dump_int("num_objects_misplaced", num_objects_misplaced); | |
1919 | f->dump_int("num_objects_unfound", num_objects_unfound); | |
1920 | f->dump_int("num_objects_dirty", num_objects_dirty); | |
1921 | f->dump_int("num_whiteouts", num_whiteouts); | |
1922 | f->dump_int("num_read", num_rd); | |
1923 | f->dump_int("num_read_kb", num_rd_kb); | |
1924 | f->dump_int("num_write", num_wr); | |
1925 | f->dump_int("num_write_kb", num_wr_kb); | |
1926 | f->dump_int("num_scrub_errors", num_scrub_errors); | |
1927 | f->dump_int("num_shallow_scrub_errors", num_shallow_scrub_errors); | |
1928 | f->dump_int("num_deep_scrub_errors", num_deep_scrub_errors); | |
1929 | f->dump_int("num_objects_recovered", num_objects_recovered); | |
1930 | f->dump_int("num_bytes_recovered", num_bytes_recovered); | |
1931 | f->dump_int("num_keys_recovered", num_keys_recovered); | |
1932 | f->dump_int("num_objects_omap", num_objects_omap); | |
1933 | f->dump_int("num_objects_hit_set_archive", num_objects_hit_set_archive); | |
1934 | f->dump_int("num_bytes_hit_set_archive", num_bytes_hit_set_archive); | |
1935 | f->dump_int("num_flush", num_flush); | |
1936 | f->dump_int("num_flush_kb", num_flush_kb); | |
1937 | f->dump_int("num_evict", num_evict); | |
1938 | f->dump_int("num_evict_kb", num_evict_kb); | |
1939 | f->dump_int("num_promote", num_promote); | |
1940 | f->dump_int("num_flush_mode_high", num_flush_mode_high); | |
1941 | f->dump_int("num_flush_mode_low", num_flush_mode_low); | |
1942 | f->dump_int("num_evict_mode_some", num_evict_mode_some); | |
1943 | f->dump_int("num_evict_mode_full", num_evict_mode_full); | |
1944 | f->dump_int("num_objects_pinned", num_objects_pinned); | |
1945 | f->dump_int("num_legacy_snapsets", num_legacy_snapsets); | |
1946 | } | |
1947 | ||
1948 | void object_stat_sum_t::encode(bufferlist& bl) const | |
1949 | { | |
1950 | ENCODE_START(16, 14, bl); | |
1951 | #if defined(CEPH_LITTLE_ENDIAN) | |
1952 | bl.append((char *)(&num_bytes), sizeof(object_stat_sum_t)); | |
1953 | #else | |
1954 | ::encode(num_bytes, bl); | |
1955 | ::encode(num_objects, bl); | |
1956 | ::encode(num_object_clones, bl); | |
1957 | ::encode(num_object_copies, bl); | |
1958 | ::encode(num_objects_missing_on_primary, bl); | |
1959 | ::encode(num_objects_degraded, bl); | |
1960 | ::encode(num_objects_unfound, bl); | |
1961 | ::encode(num_rd, bl); | |
1962 | ::encode(num_rd_kb, bl); | |
1963 | ::encode(num_wr, bl); | |
1964 | ::encode(num_wr_kb, bl); | |
1965 | ::encode(num_scrub_errors, bl); | |
1966 | ::encode(num_objects_recovered, bl); | |
1967 | ::encode(num_bytes_recovered, bl); | |
1968 | ::encode(num_keys_recovered, bl); | |
1969 | ::encode(num_shallow_scrub_errors, bl); | |
1970 | ::encode(num_deep_scrub_errors, bl); | |
1971 | ::encode(num_objects_dirty, bl); | |
1972 | ::encode(num_whiteouts, bl); | |
1973 | ::encode(num_objects_omap, bl); | |
1974 | ::encode(num_objects_hit_set_archive, bl); | |
1975 | ::encode(num_objects_misplaced, bl); | |
1976 | ::encode(num_bytes_hit_set_archive, bl); | |
1977 | ::encode(num_flush, bl); | |
1978 | ::encode(num_flush_kb, bl); | |
1979 | ::encode(num_evict, bl); | |
1980 | ::encode(num_evict_kb, bl); | |
1981 | ::encode(num_promote, bl); | |
1982 | ::encode(num_flush_mode_high, bl); | |
1983 | ::encode(num_flush_mode_low, bl); | |
1984 | ::encode(num_evict_mode_some, bl); | |
1985 | ::encode(num_evict_mode_full, bl); | |
1986 | ::encode(num_objects_pinned, bl); | |
1987 | ::encode(num_objects_missing, bl); | |
1988 | ::encode(num_legacy_snapsets, bl); | |
1989 | #endif | |
1990 | ENCODE_FINISH(bl); | |
1991 | } | |
1992 | ||
1993 | void object_stat_sum_t::decode(bufferlist::iterator& bl) | |
1994 | { | |
1995 | bool decode_finish = false; | |
1996 | DECODE_START(16, bl); | |
1997 | #if defined(CEPH_LITTLE_ENDIAN) | |
1998 | if (struct_v >= 16) { | |
1999 | bl.copy(sizeof(object_stat_sum_t), (char*)(&num_bytes)); | |
2000 | decode_finish = true; | |
2001 | } | |
2002 | #endif | |
2003 | if (!decode_finish) { | |
2004 | ::decode(num_bytes, bl); | |
2005 | ::decode(num_objects, bl); | |
2006 | ::decode(num_object_clones, bl); | |
2007 | ::decode(num_object_copies, bl); | |
2008 | ::decode(num_objects_missing_on_primary, bl); | |
2009 | ::decode(num_objects_degraded, bl); | |
2010 | ::decode(num_objects_unfound, bl); | |
2011 | ::decode(num_rd, bl); | |
2012 | ::decode(num_rd_kb, bl); | |
2013 | ::decode(num_wr, bl); | |
2014 | ::decode(num_wr_kb, bl); | |
2015 | ::decode(num_scrub_errors, bl); | |
2016 | ::decode(num_objects_recovered, bl); | |
2017 | ::decode(num_bytes_recovered, bl); | |
2018 | ::decode(num_keys_recovered, bl); | |
2019 | ::decode(num_shallow_scrub_errors, bl); | |
2020 | ::decode(num_deep_scrub_errors, bl); | |
2021 | ::decode(num_objects_dirty, bl); | |
2022 | ::decode(num_whiteouts, bl); | |
2023 | ::decode(num_objects_omap, bl); | |
2024 | ::decode(num_objects_hit_set_archive, bl); | |
2025 | ::decode(num_objects_misplaced, bl); | |
2026 | ::decode(num_bytes_hit_set_archive, bl); | |
2027 | ::decode(num_flush, bl); | |
2028 | ::decode(num_flush_kb, bl); | |
2029 | ::decode(num_evict, bl); | |
2030 | ::decode(num_evict_kb, bl); | |
2031 | ::decode(num_promote, bl); | |
2032 | ::decode(num_flush_mode_high, bl); | |
2033 | ::decode(num_flush_mode_low, bl); | |
2034 | ::decode(num_evict_mode_some, bl); | |
2035 | ::decode(num_evict_mode_full, bl); | |
2036 | ::decode(num_objects_pinned, bl); | |
2037 | ::decode(num_objects_missing, bl); | |
2038 | if (struct_v >= 16) { | |
2039 | ::decode(num_legacy_snapsets, bl); | |
2040 | } else { | |
2041 | num_legacy_snapsets = num_object_clones; // upper bound | |
2042 | } | |
2043 | } | |
2044 | DECODE_FINISH(bl); | |
2045 | } | |
2046 | ||
2047 | void object_stat_sum_t::generate_test_instances(list<object_stat_sum_t*>& o) | |
2048 | { | |
2049 | object_stat_sum_t a; | |
2050 | ||
2051 | a.num_bytes = 1; | |
2052 | a.num_objects = 3; | |
2053 | a.num_object_clones = 4; | |
2054 | a.num_object_copies = 5; | |
2055 | a.num_objects_missing_on_primary = 6; | |
2056 | a.num_objects_missing = 123; | |
2057 | a.num_objects_degraded = 7; | |
2058 | a.num_objects_unfound = 8; | |
2059 | a.num_rd = 9; a.num_rd_kb = 10; | |
2060 | a.num_wr = 11; a.num_wr_kb = 12; | |
2061 | a.num_objects_recovered = 14; | |
2062 | a.num_bytes_recovered = 15; | |
2063 | a.num_keys_recovered = 16; | |
2064 | a.num_deep_scrub_errors = 17; | |
2065 | a.num_shallow_scrub_errors = 18; | |
2066 | a.num_scrub_errors = a.num_deep_scrub_errors + a.num_shallow_scrub_errors; | |
2067 | a.num_objects_dirty = 21; | |
2068 | a.num_whiteouts = 22; | |
2069 | a.num_objects_misplaced = 1232; | |
2070 | a.num_objects_hit_set_archive = 2; | |
2071 | a.num_bytes_hit_set_archive = 27; | |
2072 | a.num_flush = 5; | |
2073 | a.num_flush_kb = 6; | |
2074 | a.num_evict = 7; | |
2075 | a.num_evict_kb = 8; | |
2076 | a.num_promote = 9; | |
2077 | a.num_flush_mode_high = 0; | |
2078 | a.num_flush_mode_low = 1; | |
2079 | a.num_evict_mode_some = 1; | |
2080 | a.num_evict_mode_full = 0; | |
2081 | a.num_objects_pinned = 20; | |
2082 | o.push_back(new object_stat_sum_t(a)); | |
2083 | } | |
2084 | ||
2085 | void object_stat_sum_t::add(const object_stat_sum_t& o) | |
2086 | { | |
2087 | num_bytes += o.num_bytes; | |
2088 | num_objects += o.num_objects; | |
2089 | num_object_clones += o.num_object_clones; | |
2090 | num_object_copies += o.num_object_copies; | |
2091 | num_objects_missing_on_primary += o.num_objects_missing_on_primary; | |
2092 | num_objects_missing += o.num_objects_missing; | |
2093 | num_objects_degraded += o.num_objects_degraded; | |
2094 | num_objects_misplaced += o.num_objects_misplaced; | |
2095 | num_rd += o.num_rd; | |
2096 | num_rd_kb += o.num_rd_kb; | |
2097 | num_wr += o.num_wr; | |
2098 | num_wr_kb += o.num_wr_kb; | |
2099 | num_objects_unfound += o.num_objects_unfound; | |
2100 | num_scrub_errors += o.num_scrub_errors; | |
2101 | num_shallow_scrub_errors += o.num_shallow_scrub_errors; | |
2102 | num_deep_scrub_errors += o.num_deep_scrub_errors; | |
2103 | num_objects_recovered += o.num_objects_recovered; | |
2104 | num_bytes_recovered += o.num_bytes_recovered; | |
2105 | num_keys_recovered += o.num_keys_recovered; | |
2106 | num_objects_dirty += o.num_objects_dirty; | |
2107 | num_whiteouts += o.num_whiteouts; | |
2108 | num_objects_omap += o.num_objects_omap; | |
2109 | num_objects_hit_set_archive += o.num_objects_hit_set_archive; | |
2110 | num_bytes_hit_set_archive += o.num_bytes_hit_set_archive; | |
2111 | num_flush += o.num_flush; | |
2112 | num_flush_kb += o.num_flush_kb; | |
2113 | num_evict += o.num_evict; | |
2114 | num_evict_kb += o.num_evict_kb; | |
2115 | num_promote += o.num_promote; | |
2116 | num_flush_mode_high += o.num_flush_mode_high; | |
2117 | num_flush_mode_low += o.num_flush_mode_low; | |
2118 | num_evict_mode_some += o.num_evict_mode_some; | |
2119 | num_evict_mode_full += o.num_evict_mode_full; | |
2120 | num_objects_pinned += o.num_objects_pinned; | |
2121 | num_legacy_snapsets += o.num_legacy_snapsets; | |
2122 | } | |
2123 | ||
2124 | void object_stat_sum_t::sub(const object_stat_sum_t& o) | |
2125 | { | |
2126 | num_bytes -= o.num_bytes; | |
2127 | num_objects -= o.num_objects; | |
2128 | num_object_clones -= o.num_object_clones; | |
2129 | num_object_copies -= o.num_object_copies; | |
2130 | num_objects_missing_on_primary -= o.num_objects_missing_on_primary; | |
2131 | num_objects_missing -= o.num_objects_missing; | |
2132 | num_objects_degraded -= o.num_objects_degraded; | |
2133 | num_objects_misplaced -= o.num_objects_misplaced; | |
2134 | num_rd -= o.num_rd; | |
2135 | num_rd_kb -= o.num_rd_kb; | |
2136 | num_wr -= o.num_wr; | |
2137 | num_wr_kb -= o.num_wr_kb; | |
2138 | num_objects_unfound -= o.num_objects_unfound; | |
2139 | num_scrub_errors -= o.num_scrub_errors; | |
2140 | num_shallow_scrub_errors -= o.num_shallow_scrub_errors; | |
2141 | num_deep_scrub_errors -= o.num_deep_scrub_errors; | |
2142 | num_objects_recovered -= o.num_objects_recovered; | |
2143 | num_bytes_recovered -= o.num_bytes_recovered; | |
2144 | num_keys_recovered -= o.num_keys_recovered; | |
2145 | num_objects_dirty -= o.num_objects_dirty; | |
2146 | num_whiteouts -= o.num_whiteouts; | |
2147 | num_objects_omap -= o.num_objects_omap; | |
2148 | num_objects_hit_set_archive -= o.num_objects_hit_set_archive; | |
2149 | num_bytes_hit_set_archive -= o.num_bytes_hit_set_archive; | |
2150 | num_flush -= o.num_flush; | |
2151 | num_flush_kb -= o.num_flush_kb; | |
2152 | num_evict -= o.num_evict; | |
2153 | num_evict_kb -= o.num_evict_kb; | |
2154 | num_promote -= o.num_promote; | |
2155 | num_flush_mode_high -= o.num_flush_mode_high; | |
2156 | num_flush_mode_low -= o.num_flush_mode_low; | |
2157 | num_evict_mode_some -= o.num_evict_mode_some; | |
2158 | num_evict_mode_full -= o.num_evict_mode_full; | |
2159 | num_objects_pinned -= o.num_objects_pinned; | |
2160 | num_legacy_snapsets -= o.num_legacy_snapsets; | |
2161 | } | |
2162 | ||
2163 | bool operator==(const object_stat_sum_t& l, const object_stat_sum_t& r) | |
2164 | { | |
2165 | return | |
2166 | l.num_bytes == r.num_bytes && | |
2167 | l.num_objects == r.num_objects && | |
2168 | l.num_object_clones == r.num_object_clones && | |
2169 | l.num_object_copies == r.num_object_copies && | |
2170 | l.num_objects_missing_on_primary == r.num_objects_missing_on_primary && | |
2171 | l.num_objects_missing == r.num_objects_missing && | |
2172 | l.num_objects_degraded == r.num_objects_degraded && | |
2173 | l.num_objects_misplaced == r.num_objects_misplaced && | |
2174 | l.num_objects_unfound == r.num_objects_unfound && | |
2175 | l.num_rd == r.num_rd && | |
2176 | l.num_rd_kb == r.num_rd_kb && | |
2177 | l.num_wr == r.num_wr && | |
2178 | l.num_wr_kb == r.num_wr_kb && | |
2179 | l.num_scrub_errors == r.num_scrub_errors && | |
2180 | l.num_shallow_scrub_errors == r.num_shallow_scrub_errors && | |
2181 | l.num_deep_scrub_errors == r.num_deep_scrub_errors && | |
2182 | l.num_objects_recovered == r.num_objects_recovered && | |
2183 | l.num_bytes_recovered == r.num_bytes_recovered && | |
2184 | l.num_keys_recovered == r.num_keys_recovered && | |
2185 | l.num_objects_dirty == r.num_objects_dirty && | |
2186 | l.num_whiteouts == r.num_whiteouts && | |
2187 | l.num_objects_omap == r.num_objects_omap && | |
2188 | l.num_objects_hit_set_archive == r.num_objects_hit_set_archive && | |
2189 | l.num_bytes_hit_set_archive == r.num_bytes_hit_set_archive && | |
2190 | l.num_flush == r.num_flush && | |
2191 | l.num_flush_kb == r.num_flush_kb && | |
2192 | l.num_evict == r.num_evict && | |
2193 | l.num_evict_kb == r.num_evict_kb && | |
2194 | l.num_promote == r.num_promote && | |
2195 | l.num_flush_mode_high == r.num_flush_mode_high && | |
2196 | l.num_flush_mode_low == r.num_flush_mode_low && | |
2197 | l.num_evict_mode_some == r.num_evict_mode_some && | |
2198 | l.num_evict_mode_full == r.num_evict_mode_full && | |
2199 | l.num_objects_pinned == r.num_objects_pinned && | |
2200 | l.num_legacy_snapsets == r.num_legacy_snapsets; | |
2201 | } | |
2202 | ||
2203 | // -- object_stat_collection_t -- | |
2204 | ||
2205 | void object_stat_collection_t::dump(Formatter *f) const | |
2206 | { | |
2207 | f->open_object_section("stat_sum"); | |
2208 | sum.dump(f); | |
2209 | f->close_section(); | |
2210 | } | |
2211 | ||
2212 | void object_stat_collection_t::encode(bufferlist& bl) const | |
2213 | { | |
2214 | ENCODE_START(2, 2, bl); | |
2215 | ::encode(sum, bl); | |
2216 | ::encode((__u32)0, bl); | |
2217 | ENCODE_FINISH(bl); | |
2218 | } | |
2219 | ||
2220 | void object_stat_collection_t::decode(bufferlist::iterator& bl) | |
2221 | { | |
2222 | DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); | |
2223 | ::decode(sum, bl); | |
2224 | { | |
2225 | map<string,object_stat_sum_t> cat_sum; | |
2226 | ::decode(cat_sum, bl); | |
2227 | } | |
2228 | DECODE_FINISH(bl); | |
2229 | } | |
2230 | ||
2231 | void object_stat_collection_t::generate_test_instances(list<object_stat_collection_t*>& o) | |
2232 | { | |
2233 | object_stat_collection_t a; | |
2234 | o.push_back(new object_stat_collection_t(a)); | |
2235 | list<object_stat_sum_t*> l; | |
2236 | object_stat_sum_t::generate_test_instances(l); | |
2237 | for (list<object_stat_sum_t*>::iterator p = l.begin(); p != l.end(); ++p) { | |
2238 | a.add(**p); | |
2239 | o.push_back(new object_stat_collection_t(a)); | |
2240 | } | |
2241 | } | |
2242 | ||
2243 | ||
2244 | // -- pg_stat_t -- | |
2245 | ||
2246 | bool pg_stat_t::is_acting_osd(int32_t osd, bool primary) const | |
2247 | { | |
2248 | if (primary && osd == acting_primary) { | |
2249 | return true; | |
2250 | } else if (!primary) { | |
2251 | for(vector<int32_t>::const_iterator it = acting.begin(); | |
2252 | it != acting.end(); ++it) | |
2253 | { | |
2254 | if (*it == osd) | |
2255 | return true; | |
2256 | } | |
2257 | } | |
2258 | return false; | |
2259 | } | |
2260 | ||
2261 | void pg_stat_t::dump(Formatter *f) const | |
2262 | { | |
2263 | f->dump_stream("version") << version; | |
2264 | f->dump_stream("reported_seq") << reported_seq; | |
2265 | f->dump_stream("reported_epoch") << reported_epoch; | |
2266 | f->dump_string("state", pg_state_string(state)); | |
2267 | f->dump_stream("last_fresh") << last_fresh; | |
2268 | f->dump_stream("last_change") << last_change; | |
2269 | f->dump_stream("last_active") << last_active; | |
2270 | f->dump_stream("last_peered") << last_peered; | |
2271 | f->dump_stream("last_clean") << last_clean; | |
2272 | f->dump_stream("last_became_active") << last_became_active; | |
2273 | f->dump_stream("last_became_peered") << last_became_peered; | |
2274 | f->dump_stream("last_unstale") << last_unstale; | |
2275 | f->dump_stream("last_undegraded") << last_undegraded; | |
2276 | f->dump_stream("last_fullsized") << last_fullsized; | |
2277 | f->dump_unsigned("mapping_epoch", mapping_epoch); | |
2278 | f->dump_stream("log_start") << log_start; | |
2279 | f->dump_stream("ondisk_log_start") << ondisk_log_start; | |
2280 | f->dump_unsigned("created", created); | |
2281 | f->dump_unsigned("last_epoch_clean", last_epoch_clean); | |
2282 | f->dump_stream("parent") << parent; | |
2283 | f->dump_unsigned("parent_split_bits", parent_split_bits); | |
2284 | f->dump_stream("last_scrub") << last_scrub; | |
2285 | f->dump_stream("last_scrub_stamp") << last_scrub_stamp; | |
2286 | f->dump_stream("last_deep_scrub") << last_deep_scrub; | |
2287 | f->dump_stream("last_deep_scrub_stamp") << last_deep_scrub_stamp; | |
2288 | f->dump_stream("last_clean_scrub_stamp") << last_clean_scrub_stamp; | |
2289 | f->dump_int("log_size", log_size); | |
2290 | f->dump_int("ondisk_log_size", ondisk_log_size); | |
2291 | f->dump_bool("stats_invalid", stats_invalid); | |
2292 | f->dump_bool("dirty_stats_invalid", dirty_stats_invalid); | |
2293 | f->dump_bool("omap_stats_invalid", omap_stats_invalid); | |
2294 | f->dump_bool("hitset_stats_invalid", hitset_stats_invalid); | |
2295 | f->dump_bool("hitset_bytes_stats_invalid", hitset_bytes_stats_invalid); | |
2296 | f->dump_bool("pin_stats_invalid", pin_stats_invalid); | |
b32b8144 | 2297 | f->dump_unsigned("snaptrimq_len", snaptrimq_len); |
7c673cae FG |
2298 | stats.dump(f); |
2299 | f->open_array_section("up"); | |
2300 | for (vector<int32_t>::const_iterator p = up.begin(); p != up.end(); ++p) | |
2301 | f->dump_int("osd", *p); | |
2302 | f->close_section(); | |
2303 | f->open_array_section("acting"); | |
2304 | for (vector<int32_t>::const_iterator p = acting.begin(); p != acting.end(); ++p) | |
2305 | f->dump_int("osd", *p); | |
2306 | f->close_section(); | |
2307 | f->open_array_section("blocked_by"); | |
2308 | for (vector<int32_t>::const_iterator p = blocked_by.begin(); | |
2309 | p != blocked_by.end(); ++p) | |
2310 | f->dump_int("osd", *p); | |
2311 | f->close_section(); | |
2312 | f->dump_int("up_primary", up_primary); | |
2313 | f->dump_int("acting_primary", acting_primary); | |
2314 | } | |
2315 | ||
2316 | void pg_stat_t::dump_brief(Formatter *f) const | |
2317 | { | |
2318 | f->dump_string("state", pg_state_string(state)); | |
2319 | f->open_array_section("up"); | |
2320 | for (vector<int32_t>::const_iterator p = up.begin(); p != up.end(); ++p) | |
2321 | f->dump_int("osd", *p); | |
2322 | f->close_section(); | |
2323 | f->open_array_section("acting"); | |
2324 | for (vector<int32_t>::const_iterator p = acting.begin(); p != acting.end(); ++p) | |
2325 | f->dump_int("osd", *p); | |
2326 | f->close_section(); | |
2327 | f->dump_int("up_primary", up_primary); | |
2328 | f->dump_int("acting_primary", acting_primary); | |
2329 | } | |
2330 | ||
2331 | void pg_stat_t::encode(bufferlist &bl) const | |
2332 | { | |
b32b8144 | 2333 | ENCODE_START(23, 22, bl); |
7c673cae FG |
2334 | ::encode(version, bl); |
2335 | ::encode(reported_seq, bl); | |
2336 | ::encode(reported_epoch, bl); | |
2337 | ::encode(state, bl); | |
2338 | ::encode(log_start, bl); | |
2339 | ::encode(ondisk_log_start, bl); | |
2340 | ::encode(created, bl); | |
2341 | ::encode(last_epoch_clean, bl); | |
2342 | ::encode(parent, bl); | |
2343 | ::encode(parent_split_bits, bl); | |
2344 | ::encode(last_scrub, bl); | |
2345 | ::encode(last_scrub_stamp, bl); | |
2346 | ::encode(stats, bl); | |
2347 | ::encode(log_size, bl); | |
2348 | ::encode(ondisk_log_size, bl); | |
2349 | ::encode(up, bl); | |
2350 | ::encode(acting, bl); | |
2351 | ::encode(last_fresh, bl); | |
2352 | ::encode(last_change, bl); | |
2353 | ::encode(last_active, bl); | |
2354 | ::encode(last_clean, bl); | |
2355 | ::encode(last_unstale, bl); | |
2356 | ::encode(mapping_epoch, bl); | |
2357 | ::encode(last_deep_scrub, bl); | |
2358 | ::encode(last_deep_scrub_stamp, bl); | |
2359 | ::encode(stats_invalid, bl); | |
2360 | ::encode(last_clean_scrub_stamp, bl); | |
2361 | ::encode(last_became_active, bl); | |
2362 | ::encode(dirty_stats_invalid, bl); | |
2363 | ::encode(up_primary, bl); | |
2364 | ::encode(acting_primary, bl); | |
2365 | ::encode(omap_stats_invalid, bl); | |
2366 | ::encode(hitset_stats_invalid, bl); | |
2367 | ::encode(blocked_by, bl); | |
2368 | ::encode(last_undegraded, bl); | |
2369 | ::encode(last_fullsized, bl); | |
2370 | ::encode(hitset_bytes_stats_invalid, bl); | |
2371 | ::encode(last_peered, bl); | |
2372 | ::encode(last_became_peered, bl); | |
2373 | ::encode(pin_stats_invalid, bl); | |
b32b8144 | 2374 | ::encode(snaptrimq_len, bl); |
7c673cae FG |
2375 | ENCODE_FINISH(bl); |
2376 | } | |
2377 | ||
2378 | void pg_stat_t::decode(bufferlist::iterator &bl) | |
2379 | { | |
2380 | bool tmp; | |
2381 | DECODE_START(22, bl); | |
2382 | ::decode(version, bl); | |
2383 | ::decode(reported_seq, bl); | |
2384 | ::decode(reported_epoch, bl); | |
2385 | ::decode(state, bl); | |
2386 | ::decode(log_start, bl); | |
2387 | ::decode(ondisk_log_start, bl); | |
2388 | ::decode(created, bl); | |
2389 | ::decode(last_epoch_clean, bl); | |
2390 | ::decode(parent, bl); | |
2391 | ::decode(parent_split_bits, bl); | |
2392 | ::decode(last_scrub, bl); | |
2393 | ::decode(last_scrub_stamp, bl); | |
2394 | ::decode(stats, bl); | |
2395 | ::decode(log_size, bl); | |
2396 | ::decode(ondisk_log_size, bl); | |
2397 | ::decode(up, bl); | |
2398 | ::decode(acting, bl); | |
2399 | ::decode(last_fresh, bl); | |
2400 | ::decode(last_change, bl); | |
2401 | ::decode(last_active, bl); | |
2402 | ::decode(last_clean, bl); | |
2403 | ::decode(last_unstale, bl); | |
2404 | ::decode(mapping_epoch, bl); | |
2405 | ::decode(last_deep_scrub, bl); | |
2406 | ::decode(last_deep_scrub_stamp, bl); | |
2407 | ::decode(tmp, bl); | |
2408 | stats_invalid = tmp; | |
2409 | ::decode(last_clean_scrub_stamp, bl); | |
2410 | ::decode(last_became_active, bl); | |
2411 | ::decode(tmp, bl); | |
2412 | dirty_stats_invalid = tmp; | |
2413 | ::decode(up_primary, bl); | |
2414 | ::decode(acting_primary, bl); | |
2415 | ::decode(tmp, bl); | |
2416 | omap_stats_invalid = tmp; | |
2417 | ::decode(tmp, bl); | |
2418 | hitset_stats_invalid = tmp; | |
2419 | ::decode(blocked_by, bl); | |
2420 | ::decode(last_undegraded, bl); | |
2421 | ::decode(last_fullsized, bl); | |
2422 | ::decode(tmp, bl); | |
2423 | hitset_bytes_stats_invalid = tmp; | |
2424 | ::decode(last_peered, bl); | |
2425 | ::decode(last_became_peered, bl); | |
2426 | ::decode(tmp, bl); | |
2427 | pin_stats_invalid = tmp; | |
b32b8144 FG |
2428 | if (struct_v >= 23) { |
2429 | ::decode(snaptrimq_len, bl); | |
2430 | } | |
7c673cae FG |
2431 | DECODE_FINISH(bl); |
2432 | } | |
2433 | ||
2434 | void pg_stat_t::generate_test_instances(list<pg_stat_t*>& o) | |
2435 | { | |
2436 | pg_stat_t a; | |
2437 | o.push_back(new pg_stat_t(a)); | |
2438 | ||
2439 | a.version = eversion_t(1, 3); | |
2440 | a.reported_epoch = 1; | |
2441 | a.reported_seq = 2; | |
2442 | a.state = 123; | |
2443 | a.mapping_epoch = 998; | |
2444 | a.last_fresh = utime_t(1002, 1); | |
2445 | a.last_change = utime_t(1002, 2); | |
2446 | a.last_active = utime_t(1002, 3); | |
2447 | a.last_clean = utime_t(1002, 4); | |
2448 | a.last_unstale = utime_t(1002, 5); | |
2449 | a.last_undegraded = utime_t(1002, 7); | |
2450 | a.last_fullsized = utime_t(1002, 8); | |
2451 | a.log_start = eversion_t(1, 4); | |
2452 | a.ondisk_log_start = eversion_t(1, 5); | |
2453 | a.created = 6; | |
2454 | a.last_epoch_clean = 7; | |
2455 | a.parent = pg_t(1, 2, 3); | |
2456 | a.parent_split_bits = 12; | |
2457 | a.last_scrub = eversion_t(9, 10); | |
2458 | a.last_scrub_stamp = utime_t(11, 12); | |
2459 | a.last_deep_scrub = eversion_t(13, 14); | |
2460 | a.last_deep_scrub_stamp = utime_t(15, 16); | |
2461 | a.last_clean_scrub_stamp = utime_t(17, 18); | |
b32b8144 | 2462 | a.snaptrimq_len = 1048576; |
7c673cae FG |
2463 | list<object_stat_collection_t*> l; |
2464 | object_stat_collection_t::generate_test_instances(l); | |
2465 | a.stats = *l.back(); | |
2466 | a.log_size = 99; | |
2467 | a.ondisk_log_size = 88; | |
2468 | a.up.push_back(123); | |
2469 | a.up_primary = 123; | |
2470 | a.acting.push_back(456); | |
2471 | a.acting_primary = 456; | |
2472 | o.push_back(new pg_stat_t(a)); | |
2473 | ||
2474 | a.up.push_back(124); | |
2475 | a.up_primary = 124; | |
2476 | a.acting.push_back(124); | |
2477 | a.acting_primary = 124; | |
2478 | a.blocked_by.push_back(155); | |
2479 | a.blocked_by.push_back(156); | |
2480 | o.push_back(new pg_stat_t(a)); | |
2481 | } | |
2482 | ||
2483 | bool operator==(const pg_stat_t& l, const pg_stat_t& r) | |
2484 | { | |
2485 | return | |
2486 | l.version == r.version && | |
2487 | l.reported_seq == r.reported_seq && | |
2488 | l.reported_epoch == r.reported_epoch && | |
2489 | l.state == r.state && | |
2490 | l.last_fresh == r.last_fresh && | |
2491 | l.last_change == r.last_change && | |
2492 | l.last_active == r.last_active && | |
2493 | l.last_peered == r.last_peered && | |
2494 | l.last_clean == r.last_clean && | |
2495 | l.last_unstale == r.last_unstale && | |
2496 | l.last_undegraded == r.last_undegraded && | |
2497 | l.last_fullsized == r.last_fullsized && | |
2498 | l.log_start == r.log_start && | |
2499 | l.ondisk_log_start == r.ondisk_log_start && | |
2500 | l.created == r.created && | |
2501 | l.last_epoch_clean == r.last_epoch_clean && | |
2502 | l.parent == r.parent && | |
2503 | l.parent_split_bits == r.parent_split_bits && | |
2504 | l.last_scrub == r.last_scrub && | |
2505 | l.last_deep_scrub == r.last_deep_scrub && | |
2506 | l.last_scrub_stamp == r.last_scrub_stamp && | |
2507 | l.last_deep_scrub_stamp == r.last_deep_scrub_stamp && | |
2508 | l.last_clean_scrub_stamp == r.last_clean_scrub_stamp && | |
2509 | l.stats == r.stats && | |
2510 | l.stats_invalid == r.stats_invalid && | |
2511 | l.log_size == r.log_size && | |
2512 | l.ondisk_log_size == r.ondisk_log_size && | |
2513 | l.up == r.up && | |
2514 | l.acting == r.acting && | |
2515 | l.mapping_epoch == r.mapping_epoch && | |
2516 | l.blocked_by == r.blocked_by && | |
2517 | l.last_became_active == r.last_became_active && | |
2518 | l.last_became_peered == r.last_became_peered && | |
2519 | l.dirty_stats_invalid == r.dirty_stats_invalid && | |
2520 | l.omap_stats_invalid == r.omap_stats_invalid && | |
2521 | l.hitset_stats_invalid == r.hitset_stats_invalid && | |
2522 | l.hitset_bytes_stats_invalid == r.hitset_bytes_stats_invalid && | |
2523 | l.up_primary == r.up_primary && | |
2524 | l.acting_primary == r.acting_primary && | |
b32b8144 FG |
2525 | l.pin_stats_invalid == r.pin_stats_invalid && |
2526 | l.snaptrimq_len == r.snaptrimq_len; | |
7c673cae FG |
2527 | } |
2528 | ||
2529 | // -- pool_stat_t -- | |
2530 | ||
2531 | void pool_stat_t::dump(Formatter *f) const | |
2532 | { | |
2533 | stats.dump(f); | |
2534 | f->dump_int("log_size", log_size); | |
2535 | f->dump_int("ondisk_log_size", ondisk_log_size); | |
2536 | f->dump_int("up", up); | |
2537 | f->dump_int("acting", acting); | |
2538 | } | |
2539 | ||
2540 | void pool_stat_t::encode(bufferlist &bl, uint64_t features) const | |
2541 | { | |
2542 | if ((features & CEPH_FEATURE_OSDENC) == 0) { | |
2543 | __u8 v = 4; | |
2544 | ::encode(v, bl); | |
2545 | ::encode(stats, bl); | |
2546 | ::encode(log_size, bl); | |
2547 | ::encode(ondisk_log_size, bl); | |
2548 | return; | |
2549 | } | |
2550 | ||
2551 | ENCODE_START(6, 5, bl); | |
2552 | ::encode(stats, bl); | |
2553 | ::encode(log_size, bl); | |
2554 | ::encode(ondisk_log_size, bl); | |
2555 | ::encode(up, bl); | |
2556 | ::encode(acting, bl); | |
2557 | ENCODE_FINISH(bl); | |
2558 | } | |
2559 | ||
2560 | void pool_stat_t::decode(bufferlist::iterator &bl) | |
2561 | { | |
2562 | DECODE_START_LEGACY_COMPAT_LEN(6, 5, 5, bl); | |
2563 | if (struct_v >= 4) { | |
2564 | ::decode(stats, bl); | |
2565 | ::decode(log_size, bl); | |
2566 | ::decode(ondisk_log_size, bl); | |
2567 | if (struct_v >= 6) { | |
2568 | ::decode(up, bl); | |
2569 | ::decode(acting, bl); | |
2570 | } else { | |
2571 | up = 0; | |
2572 | acting = 0; | |
2573 | } | |
2574 | } else { | |
2575 | ::decode(stats.sum.num_bytes, bl); | |
2576 | uint64_t num_kb; | |
2577 | ::decode(num_kb, bl); | |
2578 | ::decode(stats.sum.num_objects, bl); | |
2579 | ::decode(stats.sum.num_object_clones, bl); | |
2580 | ::decode(stats.sum.num_object_copies, bl); | |
2581 | ::decode(stats.sum.num_objects_missing_on_primary, bl); | |
2582 | ::decode(stats.sum.num_objects_degraded, bl); | |
2583 | ::decode(log_size, bl); | |
2584 | ::decode(ondisk_log_size, bl); | |
2585 | if (struct_v >= 2) { | |
2586 | ::decode(stats.sum.num_rd, bl); | |
2587 | ::decode(stats.sum.num_rd_kb, bl); | |
2588 | ::decode(stats.sum.num_wr, bl); | |
2589 | ::decode(stats.sum.num_wr_kb, bl); | |
2590 | } | |
2591 | if (struct_v >= 3) { | |
2592 | ::decode(stats.sum.num_objects_unfound, bl); | |
2593 | } | |
2594 | } | |
2595 | DECODE_FINISH(bl); | |
2596 | } | |
2597 | ||
2598 | void pool_stat_t::generate_test_instances(list<pool_stat_t*>& o) | |
2599 | { | |
2600 | pool_stat_t a; | |
2601 | o.push_back(new pool_stat_t(a)); | |
2602 | ||
2603 | list<object_stat_collection_t*> l; | |
2604 | object_stat_collection_t::generate_test_instances(l); | |
2605 | a.stats = *l.back(); | |
2606 | a.log_size = 123; | |
2607 | a.ondisk_log_size = 456; | |
2608 | a.acting = 3; | |
2609 | a.up = 4; | |
2610 | o.push_back(new pool_stat_t(a)); | |
2611 | } | |
2612 | ||
2613 | ||
2614 | // -- pg_history_t -- | |
2615 | ||
2616 | void pg_history_t::encode(bufferlist &bl) const | |
2617 | { | |
31f18b77 | 2618 | ENCODE_START(9, 4, bl); |
7c673cae FG |
2619 | ::encode(epoch_created, bl); |
2620 | ::encode(last_epoch_started, bl); | |
2621 | ::encode(last_epoch_clean, bl); | |
2622 | ::encode(last_epoch_split, bl); | |
2623 | ::encode(same_interval_since, bl); | |
2624 | ::encode(same_up_since, bl); | |
2625 | ::encode(same_primary_since, bl); | |
2626 | ::encode(last_scrub, bl); | |
2627 | ::encode(last_scrub_stamp, bl); | |
2628 | ::encode(last_deep_scrub, bl); | |
2629 | ::encode(last_deep_scrub_stamp, bl); | |
2630 | ::encode(last_clean_scrub_stamp, bl); | |
2631 | ::encode(last_epoch_marked_full, bl); | |
2632 | ::encode(last_interval_started, bl); | |
2633 | ::encode(last_interval_clean, bl); | |
31f18b77 | 2634 | ::encode(epoch_pool_created, bl); |
7c673cae FG |
2635 | ENCODE_FINISH(bl); |
2636 | } | |
2637 | ||
2638 | void pg_history_t::decode(bufferlist::iterator &bl) | |
2639 | { | |
31f18b77 | 2640 | DECODE_START_LEGACY_COMPAT_LEN(9, 4, 4, bl); |
7c673cae FG |
2641 | ::decode(epoch_created, bl); |
2642 | ::decode(last_epoch_started, bl); | |
2643 | if (struct_v >= 3) | |
2644 | ::decode(last_epoch_clean, bl); | |
2645 | else | |
2646 | last_epoch_clean = last_epoch_started; // careful, it's a lie! | |
2647 | ::decode(last_epoch_split, bl); | |
2648 | ::decode(same_interval_since, bl); | |
2649 | ::decode(same_up_since, bl); | |
2650 | ::decode(same_primary_since, bl); | |
2651 | if (struct_v >= 2) { | |
2652 | ::decode(last_scrub, bl); | |
2653 | ::decode(last_scrub_stamp, bl); | |
2654 | } | |
2655 | if (struct_v >= 5) { | |
2656 | ::decode(last_deep_scrub, bl); | |
2657 | ::decode(last_deep_scrub_stamp, bl); | |
2658 | } | |
2659 | if (struct_v >= 6) { | |
2660 | ::decode(last_clean_scrub_stamp, bl); | |
2661 | } | |
2662 | if (struct_v >= 7) { | |
2663 | ::decode(last_epoch_marked_full, bl); | |
2664 | } | |
2665 | if (struct_v >= 8) { | |
2666 | ::decode(last_interval_started, bl); | |
2667 | ::decode(last_interval_clean, bl); | |
2668 | } else { | |
2669 | if (last_epoch_started >= same_interval_since) { | |
2670 | last_interval_started = same_interval_since; | |
2671 | } else { | |
2672 | last_interval_started = last_epoch_started; // best guess | |
2673 | } | |
2674 | if (last_epoch_clean >= same_interval_since) { | |
2675 | last_interval_clean = same_interval_since; | |
2676 | } else { | |
2677 | last_interval_clean = last_epoch_clean; // best guess | |
2678 | } | |
2679 | } | |
31f18b77 FG |
2680 | if (struct_v >= 9) { |
2681 | ::decode(epoch_pool_created, bl); | |
2682 | } else { | |
2683 | epoch_pool_created = epoch_created; | |
2684 | } | |
7c673cae FG |
2685 | DECODE_FINISH(bl); |
2686 | } | |
2687 | ||
2688 | void pg_history_t::dump(Formatter *f) const | |
2689 | { | |
2690 | f->dump_int("epoch_created", epoch_created); | |
31f18b77 | 2691 | f->dump_int("epoch_pool_created", epoch_pool_created); |
7c673cae FG |
2692 | f->dump_int("last_epoch_started", last_epoch_started); |
2693 | f->dump_int("last_interval_started", last_interval_started); | |
2694 | f->dump_int("last_epoch_clean", last_epoch_clean); | |
2695 | f->dump_int("last_interval_clean", last_interval_clean); | |
2696 | f->dump_int("last_epoch_split", last_epoch_split); | |
2697 | f->dump_int("last_epoch_marked_full", last_epoch_marked_full); | |
2698 | f->dump_int("same_up_since", same_up_since); | |
2699 | f->dump_int("same_interval_since", same_interval_since); | |
2700 | f->dump_int("same_primary_since", same_primary_since); | |
2701 | f->dump_stream("last_scrub") << last_scrub; | |
2702 | f->dump_stream("last_scrub_stamp") << last_scrub_stamp; | |
2703 | f->dump_stream("last_deep_scrub") << last_deep_scrub; | |
2704 | f->dump_stream("last_deep_scrub_stamp") << last_deep_scrub_stamp; | |
2705 | f->dump_stream("last_clean_scrub_stamp") << last_clean_scrub_stamp; | |
2706 | } | |
2707 | ||
2708 | void pg_history_t::generate_test_instances(list<pg_history_t*>& o) | |
2709 | { | |
2710 | o.push_back(new pg_history_t); | |
2711 | o.push_back(new pg_history_t); | |
2712 | o.back()->epoch_created = 1; | |
31f18b77 | 2713 | o.back()->epoch_pool_created = 1; |
7c673cae FG |
2714 | o.back()->last_epoch_started = 2; |
2715 | o.back()->last_interval_started = 2; | |
2716 | o.back()->last_epoch_clean = 3; | |
2717 | o.back()->last_interval_clean = 2; | |
2718 | o.back()->last_epoch_split = 4; | |
2719 | o.back()->same_up_since = 5; | |
2720 | o.back()->same_interval_since = 6; | |
2721 | o.back()->same_primary_since = 7; | |
2722 | o.back()->last_scrub = eversion_t(8, 9); | |
2723 | o.back()->last_scrub_stamp = utime_t(10, 11); | |
2724 | o.back()->last_deep_scrub = eversion_t(12, 13); | |
2725 | o.back()->last_deep_scrub_stamp = utime_t(14, 15); | |
2726 | o.back()->last_clean_scrub_stamp = utime_t(16, 17); | |
2727 | o.back()->last_epoch_marked_full = 18; | |
2728 | } | |
2729 | ||
2730 | ||
2731 | // -- pg_info_t -- | |
2732 | ||
2733 | void pg_info_t::encode(bufferlist &bl) const | |
2734 | { | |
2735 | ENCODE_START(32, 26, bl); | |
2736 | ::encode(pgid.pgid, bl); | |
2737 | ::encode(last_update, bl); | |
2738 | ::encode(last_complete, bl); | |
2739 | ::encode(log_tail, bl); | |
2740 | if (last_backfill_bitwise && !last_backfill.is_max()) { | |
2741 | ::encode(hobject_t(), bl); | |
2742 | } else { | |
2743 | ::encode(last_backfill, bl); | |
2744 | } | |
2745 | ::encode(stats, bl); | |
2746 | history.encode(bl); | |
2747 | ::encode(purged_snaps, bl); | |
2748 | ::encode(last_epoch_started, bl); | |
2749 | ::encode(last_user_version, bl); | |
2750 | ::encode(hit_set, bl); | |
2751 | ::encode(pgid.shard, bl); | |
2752 | ::encode(last_backfill, bl); | |
2753 | ::encode(last_backfill_bitwise, bl); | |
2754 | ::encode(last_interval_started, bl); | |
2755 | ENCODE_FINISH(bl); | |
2756 | } | |
2757 | ||
2758 | void pg_info_t::decode(bufferlist::iterator &bl) | |
2759 | { | |
2760 | DECODE_START(32, bl); | |
2761 | ::decode(pgid.pgid, bl); | |
2762 | ::decode(last_update, bl); | |
2763 | ::decode(last_complete, bl); | |
2764 | ::decode(log_tail, bl); | |
2765 | { | |
2766 | hobject_t old_last_backfill; | |
2767 | ::decode(old_last_backfill, bl); | |
2768 | } | |
2769 | ::decode(stats, bl); | |
2770 | history.decode(bl); | |
2771 | ::decode(purged_snaps, bl); | |
2772 | ::decode(last_epoch_started, bl); | |
2773 | ::decode(last_user_version, bl); | |
2774 | ::decode(hit_set, bl); | |
2775 | ::decode(pgid.shard, bl); | |
2776 | ::decode(last_backfill, bl); | |
2777 | ::decode(last_backfill_bitwise, bl); | |
2778 | if (struct_v >= 32) { | |
2779 | ::decode(last_interval_started, bl); | |
2780 | } else { | |
2781 | last_interval_started = last_epoch_started; | |
2782 | } | |
2783 | DECODE_FINISH(bl); | |
2784 | } | |
2785 | ||
2786 | // -- pg_info_t -- | |
2787 | ||
2788 | void pg_info_t::dump(Formatter *f) const | |
2789 | { | |
2790 | f->dump_stream("pgid") << pgid; | |
2791 | f->dump_stream("last_update") << last_update; | |
2792 | f->dump_stream("last_complete") << last_complete; | |
2793 | f->dump_stream("log_tail") << log_tail; | |
2794 | f->dump_int("last_user_version", last_user_version); | |
2795 | f->dump_stream("last_backfill") << last_backfill; | |
2796 | f->dump_int("last_backfill_bitwise", (int)last_backfill_bitwise); | |
2797 | f->open_array_section("purged_snaps"); | |
2798 | for (interval_set<snapid_t>::const_iterator i=purged_snaps.begin(); | |
2799 | i != purged_snaps.end(); | |
2800 | ++i) { | |
2801 | f->open_object_section("purged_snap_interval"); | |
2802 | f->dump_stream("start") << i.get_start(); | |
2803 | f->dump_stream("length") << i.get_len(); | |
2804 | f->close_section(); | |
2805 | } | |
2806 | f->close_section(); | |
2807 | f->open_object_section("history"); | |
2808 | history.dump(f); | |
2809 | f->close_section(); | |
2810 | f->open_object_section("stats"); | |
2811 | stats.dump(f); | |
2812 | f->close_section(); | |
2813 | ||
2814 | f->dump_int("empty", is_empty()); | |
2815 | f->dump_int("dne", dne()); | |
2816 | f->dump_int("incomplete", is_incomplete()); | |
2817 | f->dump_int("last_epoch_started", last_epoch_started); | |
2818 | ||
2819 | f->open_object_section("hit_set_history"); | |
2820 | hit_set.dump(f); | |
2821 | f->close_section(); | |
2822 | } | |
2823 | ||
2824 | void pg_info_t::generate_test_instances(list<pg_info_t*>& o) | |
2825 | { | |
2826 | o.push_back(new pg_info_t); | |
2827 | o.push_back(new pg_info_t); | |
2828 | list<pg_history_t*> h; | |
2829 | pg_history_t::generate_test_instances(h); | |
2830 | o.back()->history = *h.back(); | |
2831 | o.back()->pgid = spg_t(pg_t(1, 2, -1), shard_id_t::NO_SHARD); | |
2832 | o.back()->last_update = eversion_t(3, 4); | |
2833 | o.back()->last_complete = eversion_t(5, 6); | |
2834 | o.back()->last_user_version = 2; | |
2835 | o.back()->log_tail = eversion_t(7, 8); | |
2836 | o.back()->last_backfill = hobject_t(object_t("objname"), "key", 123, 456, -1, ""); | |
2837 | o.back()->last_backfill_bitwise = true; | |
2838 | { | |
2839 | list<pg_stat_t*> s; | |
2840 | pg_stat_t::generate_test_instances(s); | |
2841 | o.back()->stats = *s.back(); | |
2842 | } | |
2843 | { | |
2844 | list<pg_hit_set_history_t*> s; | |
2845 | pg_hit_set_history_t::generate_test_instances(s); | |
2846 | o.back()->hit_set = *s.back(); | |
2847 | } | |
2848 | } | |
2849 | ||
2850 | // -- pg_notify_t -- | |
2851 | void pg_notify_t::encode(bufferlist &bl) const | |
2852 | { | |
2853 | ENCODE_START(2, 2, bl); | |
2854 | ::encode(query_epoch, bl); | |
2855 | ::encode(epoch_sent, bl); | |
2856 | ::encode(info, bl); | |
2857 | ::encode(to, bl); | |
2858 | ::encode(from, bl); | |
2859 | ENCODE_FINISH(bl); | |
2860 | } | |
2861 | ||
2862 | void pg_notify_t::decode(bufferlist::iterator &bl) | |
2863 | { | |
2864 | DECODE_START(2, bl); | |
2865 | ::decode(query_epoch, bl); | |
2866 | ::decode(epoch_sent, bl); | |
2867 | ::decode(info, bl); | |
2868 | ::decode(to, bl); | |
2869 | ::decode(from, bl); | |
2870 | DECODE_FINISH(bl); | |
2871 | } | |
2872 | ||
2873 | void pg_notify_t::dump(Formatter *f) const | |
2874 | { | |
2875 | f->dump_int("from", from); | |
2876 | f->dump_int("to", to); | |
2877 | f->dump_unsigned("query_epoch", query_epoch); | |
2878 | f->dump_unsigned("epoch_sent", epoch_sent); | |
2879 | { | |
2880 | f->open_object_section("info"); | |
2881 | info.dump(f); | |
2882 | f->close_section(); | |
2883 | } | |
2884 | } | |
2885 | ||
2886 | void pg_notify_t::generate_test_instances(list<pg_notify_t*>& o) | |
2887 | { | |
2888 | o.push_back(new pg_notify_t(shard_id_t(3), shard_id_t::NO_SHARD, 1, 1, pg_info_t())); | |
2889 | o.push_back(new pg_notify_t(shard_id_t(0), shard_id_t(0), 3, 10, pg_info_t())); | |
2890 | } | |
2891 | ||
2892 | ostream &operator<<(ostream &lhs, const pg_notify_t ¬ify) | |
2893 | { | |
2894 | lhs << "(query:" << notify.query_epoch | |
2895 | << " sent:" << notify.epoch_sent | |
2896 | << " " << notify.info; | |
2897 | if (notify.from != shard_id_t::NO_SHARD || | |
2898 | notify.to != shard_id_t::NO_SHARD) | |
2899 | lhs << " " << (unsigned)notify.from | |
2900 | << "->" << (unsigned)notify.to; | |
2901 | return lhs << ")"; | |
2902 | } | |
2903 | ||
2904 | // -- pg_interval_t -- | |
2905 | ||
2906 | void PastIntervals::pg_interval_t::encode(bufferlist& bl) const | |
2907 | { | |
2908 | ENCODE_START(4, 2, bl); | |
2909 | ::encode(first, bl); | |
2910 | ::encode(last, bl); | |
2911 | ::encode(up, bl); | |
2912 | ::encode(acting, bl); | |
2913 | ::encode(maybe_went_rw, bl); | |
2914 | ::encode(primary, bl); | |
2915 | ::encode(up_primary, bl); | |
2916 | ENCODE_FINISH(bl); | |
2917 | } | |
2918 | ||
2919 | void PastIntervals::pg_interval_t::decode(bufferlist::iterator& bl) | |
2920 | { | |
2921 | DECODE_START_LEGACY_COMPAT_LEN(4, 2, 2, bl); | |
2922 | ::decode(first, bl); | |
2923 | ::decode(last, bl); | |
2924 | ::decode(up, bl); | |
2925 | ::decode(acting, bl); | |
2926 | ::decode(maybe_went_rw, bl); | |
2927 | if (struct_v >= 3) { | |
2928 | ::decode(primary, bl); | |
2929 | } else { | |
2930 | if (acting.size()) | |
2931 | primary = acting[0]; | |
2932 | } | |
2933 | if (struct_v >= 4) { | |
2934 | ::decode(up_primary, bl); | |
2935 | } else { | |
2936 | if (up.size()) | |
2937 | up_primary = up[0]; | |
2938 | } | |
2939 | DECODE_FINISH(bl); | |
2940 | } | |
2941 | ||
2942 | void PastIntervals::pg_interval_t::dump(Formatter *f) const | |
2943 | { | |
2944 | f->dump_unsigned("first", first); | |
2945 | f->dump_unsigned("last", last); | |
2946 | f->dump_int("maybe_went_rw", maybe_went_rw ? 1 : 0); | |
2947 | f->open_array_section("up"); | |
2948 | for (vector<int>::const_iterator p = up.begin(); p != up.end(); ++p) | |
2949 | f->dump_int("osd", *p); | |
2950 | f->close_section(); | |
2951 | f->open_array_section("acting"); | |
2952 | for (vector<int>::const_iterator p = acting.begin(); p != acting.end(); ++p) | |
2953 | f->dump_int("osd", *p); | |
2954 | f->close_section(); | |
2955 | f->dump_int("primary", primary); | |
2956 | f->dump_int("up_primary", up_primary); | |
2957 | } | |
2958 | ||
2959 | void PastIntervals::pg_interval_t::generate_test_instances(list<pg_interval_t*>& o) | |
2960 | { | |
2961 | o.push_back(new pg_interval_t); | |
2962 | o.push_back(new pg_interval_t); | |
2963 | o.back()->up.push_back(1); | |
2964 | o.back()->acting.push_back(2); | |
2965 | o.back()->acting.push_back(3); | |
2966 | o.back()->first = 4; | |
2967 | o.back()->last = 5; | |
2968 | o.back()->maybe_went_rw = true; | |
2969 | } | |
2970 | ||
2971 | WRITE_CLASS_ENCODER(PastIntervals::pg_interval_t) | |
2972 | ||
2973 | class pi_simple_rep : public PastIntervals::interval_rep { | |
2974 | map<epoch_t, PastIntervals::pg_interval_t> interval_map; | |
2975 | ||
2976 | pi_simple_rep( | |
2977 | bool ec_pool, | |
2978 | std::list<PastIntervals::pg_interval_t> &&intervals) { | |
2979 | for (auto &&i: intervals) | |
2980 | add_interval(ec_pool, i); | |
2981 | } | |
2982 | ||
2983 | public: | |
2984 | pi_simple_rep() = default; | |
2985 | pi_simple_rep(const pi_simple_rep &) = default; | |
2986 | pi_simple_rep(pi_simple_rep &&) = default; | |
2987 | pi_simple_rep &operator=(pi_simple_rep &&) = default; | |
2988 | pi_simple_rep &operator=(const pi_simple_rep &) = default; | |
2989 | ||
2990 | size_t size() const override { return interval_map.size(); } | |
2991 | bool empty() const override { return interval_map.empty(); } | |
2992 | void clear() override { interval_map.clear(); } | |
2993 | pair<epoch_t, epoch_t> get_bounds() const override { | |
2994 | auto iter = interval_map.begin(); | |
2995 | if (iter != interval_map.end()) { | |
2996 | auto riter = interval_map.rbegin(); | |
2997 | return make_pair( | |
2998 | iter->second.first, | |
2999 | riter->second.last + 1); | |
3000 | } else { | |
3001 | return make_pair(0, 0); | |
3002 | } | |
3003 | } | |
3004 | set<pg_shard_t> get_all_participants( | |
3005 | bool ec_pool) const override { | |
3006 | set<pg_shard_t> all_participants; | |
3007 | ||
3008 | // We need to decide who might have unfound objects that we need | |
3009 | auto p = interval_map.rbegin(); | |
3010 | auto end = interval_map.rend(); | |
3011 | for (; p != end; ++p) { | |
3012 | const PastIntervals::pg_interval_t &interval(p->second); | |
3013 | // If nothing changed, we don't care about this interval. | |
3014 | if (!interval.maybe_went_rw) | |
3015 | continue; | |
3016 | ||
3017 | int i = 0; | |
3018 | std::vector<int>::const_iterator a = interval.acting.begin(); | |
3019 | std::vector<int>::const_iterator a_end = interval.acting.end(); | |
3020 | for (; a != a_end; ++a, ++i) { | |
3021 | pg_shard_t shard(*a, ec_pool ? shard_id_t(i) : shard_id_t::NO_SHARD); | |
3022 | if (*a != CRUSH_ITEM_NONE) | |
3023 | all_participants.insert(shard); | |
3024 | } | |
3025 | } | |
3026 | return all_participants; | |
3027 | } | |
3028 | void add_interval( | |
3029 | bool ec_pool, | |
3030 | const PastIntervals::pg_interval_t &interval) override { | |
3031 | interval_map[interval.first] = interval; | |
3032 | } | |
3033 | unique_ptr<PastIntervals::interval_rep> clone() const override { | |
3034 | return unique_ptr<PastIntervals::interval_rep>(new pi_simple_rep(*this)); | |
3035 | } | |
3036 | ostream &print(ostream &out) const override { | |
3037 | return out << interval_map; | |
3038 | } | |
3039 | void encode(bufferlist &bl) const override { | |
3040 | ::encode(interval_map, bl); | |
3041 | } | |
3042 | void decode(bufferlist::iterator &bl) override { | |
3043 | ::decode(interval_map, bl); | |
3044 | } | |
3045 | void dump(Formatter *f) const override { | |
3046 | f->open_array_section("PastIntervals::compat_rep"); | |
3047 | for (auto &&i: interval_map) { | |
3048 | f->open_object_section("pg_interval_t"); | |
3049 | f->dump_int("epoch", i.first); | |
3050 | f->open_object_section("interval"); | |
3051 | i.second.dump(f); | |
3052 | f->close_section(); | |
3053 | f->close_section(); | |
3054 | } | |
3055 | f->close_section(); | |
3056 | } | |
3057 | bool is_classic() const override { | |
3058 | return true; | |
3059 | } | |
3060 | static void generate_test_instances(list<pi_simple_rep*> &o) { | |
3061 | using ival = PastIntervals::pg_interval_t; | |
3062 | using ivallst = std::list<ival>; | |
3063 | o.push_back( | |
3064 | new pi_simple_rep( | |
3065 | true, ivallst | |
3066 | { ival{{0, 1, 2}, {0, 1, 2}, 10, 20, true, 0, 0} | |
3067 | , ival{{ 1, 2}, { 1, 2}, 21, 30, true, 1, 1} | |
3068 | , ival{{ 2}, { 2}, 31, 35, false, 2, 2} | |
3069 | , ival{{0, 2}, {0, 2}, 36, 50, true, 0, 0} | |
3070 | })); | |
3071 | o.push_back( | |
3072 | new pi_simple_rep( | |
3073 | false, ivallst | |
3074 | { ival{{0, 1, 2}, {0, 1, 2}, 10, 20, true, 0, 0} | |
3075 | , ival{{ 1, 2}, { 1, 2}, 20, 30, true, 1, 1} | |
3076 | , ival{{ 2}, { 2}, 31, 35, false, 2, 2} | |
3077 | , ival{{0, 2}, {0, 2}, 36, 50, true, 0, 0} | |
3078 | })); | |
3079 | o.push_back( | |
3080 | new pi_simple_rep( | |
3081 | true, ivallst | |
3082 | { ival{{2, 1, 0}, {2, 1, 0}, 10, 20, true, 1, 1} | |
3083 | , ival{{ 0, 2}, { 0, 2}, 21, 30, true, 0, 0} | |
3084 | , ival{{ 0, 2}, {2, 0}, 31, 35, true, 2, 2} | |
3085 | , ival{{ 0, 2}, { 0, 2}, 36, 50, true, 0, 0} | |
3086 | })); | |
3087 | return; | |
3088 | } | |
3089 | void iterate_mayberw_back_to( | |
3090 | bool ec_pool, | |
3091 | epoch_t les, | |
3092 | std::function<void(epoch_t, const set<pg_shard_t> &)> &&f) const override { | |
3093 | for (auto i = interval_map.rbegin(); i != interval_map.rend(); ++i) { | |
3094 | if (!i->second.maybe_went_rw) | |
3095 | continue; | |
3096 | if (i->second.last < les) | |
3097 | break; | |
3098 | set<pg_shard_t> actingset; | |
3099 | for (unsigned j = 0; j < i->second.acting.size(); ++j) { | |
3100 | if (i->second.acting[j] == CRUSH_ITEM_NONE) | |
3101 | continue; | |
3102 | actingset.insert( | |
3103 | pg_shard_t( | |
3104 | i->second.acting[j], | |
3105 | ec_pool ? shard_id_t(j) : shard_id_t::NO_SHARD)); | |
3106 | } | |
3107 | f(i->second.first, actingset); | |
3108 | } | |
3109 | } | |
3110 | ||
3111 | bool has_full_intervals() const override { return true; } | |
3112 | void iterate_all_intervals( | |
3113 | std::function<void(const PastIntervals::pg_interval_t &)> &&f | |
3114 | ) const override { | |
3115 | for (auto &&i: interval_map) { | |
3116 | f(i.second); | |
3117 | } | |
3118 | } | |
3119 | virtual ~pi_simple_rep() override {} | |
3120 | }; | |
3121 | ||
3122 | /** | |
3123 | * pi_compact_rep | |
3124 | * | |
3125 | * PastIntervals only needs to be able to answer two questions: | |
3126 | * 1) Where should the primary look for unfound objects? | |
3127 | * 2) List a set of subsets of the OSDs such that contacting at least | |
3128 | * one from each subset guarrantees we speak to at least one witness | |
3129 | * of any completed write. | |
3130 | * | |
3131 | * Crucially, 2) does not require keeping *all* past intervals. Certainly, | |
3132 | * we don't need to keep any where maybe_went_rw would be false. We also | |
3133 | * needn't keep two intervals where the actingset in one is a subset | |
3134 | * of the other (only need to keep the smaller of the two sets). In order | |
3135 | * to accurately trim the set of intervals as last_epoch_started changes | |
3136 | * without rebuilding the set from scratch, we'll retain the larger set | |
3137 | * if it in an older interval. | |
3138 | */ | |
3139 | struct compact_interval_t { | |
3140 | epoch_t first; | |
3141 | epoch_t last; | |
3142 | set<pg_shard_t> acting; | |
3143 | bool supersedes(const compact_interval_t &other) { | |
3144 | for (auto &&i: acting) { | |
3145 | if (!other.acting.count(i)) | |
3146 | return false; | |
3147 | } | |
3148 | return true; | |
3149 | } | |
3150 | void dump(Formatter *f) const { | |
3151 | f->open_object_section("compact_interval_t"); | |
3152 | f->dump_stream("first") << first; | |
3153 | f->dump_stream("last") << last; | |
3154 | f->dump_stream("acting") << acting; | |
3155 | f->close_section(); | |
3156 | } | |
3157 | void encode(bufferlist &bl) const { | |
3158 | ENCODE_START(1, 1, bl); | |
3159 | ::encode(first, bl); | |
3160 | ::encode(last, bl); | |
3161 | ::encode(acting, bl); | |
3162 | ENCODE_FINISH(bl); | |
3163 | } | |
3164 | void decode(bufferlist::iterator &bl) { | |
3165 | DECODE_START(1, bl); | |
3166 | ::decode(first, bl); | |
3167 | ::decode(last, bl); | |
3168 | ::decode(acting, bl); | |
3169 | DECODE_FINISH(bl); | |
3170 | } | |
3171 | static void generate_test_instances(list<compact_interval_t*> & o) { | |
3172 | /* Not going to be used, we'll generate pi_compact_rep directly */ | |
3173 | } | |
3174 | }; | |
3175 | ostream &operator<<(ostream &o, const compact_interval_t &rhs) | |
3176 | { | |
3177 | return o << "([" << rhs.first << "," << rhs.last | |
3178 | << "] acting " << rhs.acting << ")"; | |
3179 | } | |
3180 | WRITE_CLASS_ENCODER(compact_interval_t) | |
3181 | ||
3182 | class pi_compact_rep : public PastIntervals::interval_rep { | |
3183 | epoch_t first = 0; | |
3184 | epoch_t last = 0; // inclusive | |
3185 | set<pg_shard_t> all_participants; | |
3186 | list<compact_interval_t> intervals; | |
3187 | pi_compact_rep( | |
3188 | bool ec_pool, | |
3189 | std::list<PastIntervals::pg_interval_t> &&intervals) { | |
3190 | for (auto &&i: intervals) | |
3191 | add_interval(ec_pool, i); | |
3192 | } | |
3193 | public: | |
3194 | pi_compact_rep() = default; | |
3195 | pi_compact_rep(const pi_compact_rep &) = default; | |
3196 | pi_compact_rep(pi_compact_rep &&) = default; | |
3197 | pi_compact_rep &operator=(const pi_compact_rep &) = default; | |
3198 | pi_compact_rep &operator=(pi_compact_rep &&) = default; | |
3199 | ||
3200 | size_t size() const override { return intervals.size(); } | |
3201 | bool empty() const override { | |
3202 | return first > last || (first == 0 && last == 0); | |
3203 | } | |
3204 | void clear() override { | |
3205 | *this = pi_compact_rep(); | |
3206 | } | |
3207 | pair<epoch_t, epoch_t> get_bounds() const override { | |
3208 | return make_pair(first, last + 1); | |
3209 | } | |
3210 | set<pg_shard_t> get_all_participants( | |
3211 | bool ec_pool) const override { | |
3212 | return all_participants; | |
3213 | } | |
3214 | void add_interval( | |
3215 | bool ec_pool, const PastIntervals::pg_interval_t &interval) override { | |
3216 | if (first == 0) | |
3217 | first = interval.first; | |
3218 | assert(interval.last > last); | |
3219 | last = interval.last; | |
3220 | set<pg_shard_t> acting; | |
3221 | for (unsigned i = 0; i < interval.acting.size(); ++i) { | |
3222 | if (interval.acting[i] == CRUSH_ITEM_NONE) | |
3223 | continue; | |
3224 | acting.insert( | |
3225 | pg_shard_t( | |
3226 | interval.acting[i], | |
3227 | ec_pool ? shard_id_t(i) : shard_id_t::NO_SHARD)); | |
3228 | } | |
3229 | all_participants.insert(acting.begin(), acting.end()); | |
3230 | if (!interval.maybe_went_rw) | |
3231 | return; | |
3232 | intervals.push_back( | |
3233 | compact_interval_t{interval.first, interval.last, acting}); | |
3234 | auto plast = intervals.end(); | |
3235 | --plast; | |
3236 | for (auto cur = intervals.begin(); cur != plast; ) { | |
3237 | if (plast->supersedes(*cur)) { | |
3238 | intervals.erase(cur++); | |
3239 | } else { | |
3240 | ++cur; | |
3241 | } | |
3242 | } | |
3243 | } | |
3244 | unique_ptr<PastIntervals::interval_rep> clone() const override { | |
3245 | return unique_ptr<PastIntervals::interval_rep>(new pi_compact_rep(*this)); | |
3246 | } | |
3247 | ostream &print(ostream &out) const override { | |
3248 | return out << "([" << first << "," << last | |
3249 | << "] intervals=" << intervals << ")"; | |
3250 | } | |
3251 | void encode(bufferlist &bl) const override { | |
3252 | ENCODE_START(1, 1, bl); | |
3253 | ::encode(first, bl); | |
3254 | ::encode(last, bl); | |
3255 | ::encode(all_participants, bl); | |
3256 | ::encode(intervals, bl); | |
3257 | ENCODE_FINISH(bl); | |
3258 | } | |
3259 | void decode(bufferlist::iterator &bl) override { | |
3260 | DECODE_START(1, bl); | |
3261 | ::decode(first, bl); | |
3262 | ::decode(last, bl); | |
3263 | ::decode(all_participants, bl); | |
3264 | ::decode(intervals, bl); | |
3265 | DECODE_FINISH(bl); | |
3266 | } | |
3267 | void dump(Formatter *f) const override { | |
3268 | f->open_object_section("PastIntervals::compact_rep"); | |
3269 | f->dump_stream("first") << first; | |
3270 | f->dump_stream("last") << last; | |
3271 | f->open_array_section("all_participants"); | |
3272 | for (auto& i : all_participants) { | |
3273 | f->dump_object("pg_shard", i); | |
3274 | } | |
3275 | f->close_section(); | |
3276 | f->open_array_section("intervals"); | |
3277 | for (auto &&i: intervals) { | |
3278 | i.dump(f); | |
3279 | } | |
3280 | f->close_section(); | |
3281 | f->close_section(); | |
3282 | } | |
3283 | bool is_classic() const override { | |
3284 | return false; | |
3285 | } | |
3286 | static void generate_test_instances(list<pi_compact_rep*> &o) { | |
3287 | using ival = PastIntervals::pg_interval_t; | |
3288 | using ivallst = std::list<ival>; | |
3289 | o.push_back( | |
3290 | new pi_compact_rep( | |
3291 | true, ivallst | |
3292 | { ival{{0, 1, 2}, {0, 1, 2}, 10, 20, true, 0, 0} | |
3293 | , ival{{ 1, 2}, { 1, 2}, 21, 30, true, 1, 1} | |
3294 | , ival{{ 2}, { 2}, 31, 35, false, 2, 2} | |
3295 | , ival{{0, 2}, {0, 2}, 36, 50, true, 0, 0} | |
3296 | })); | |
3297 | o.push_back( | |
3298 | new pi_compact_rep( | |
3299 | false, ivallst | |
3300 | { ival{{0, 1, 2}, {0, 1, 2}, 10, 20, true, 0, 0} | |
3301 | , ival{{ 1, 2}, { 1, 2}, 21, 30, true, 1, 1} | |
3302 | , ival{{ 2}, { 2}, 31, 35, false, 2, 2} | |
3303 | , ival{{0, 2}, {0, 2}, 36, 50, true, 0, 0} | |
3304 | })); | |
3305 | o.push_back( | |
3306 | new pi_compact_rep( | |
3307 | true, ivallst | |
3308 | { ival{{2, 1, 0}, {2, 1, 0}, 10, 20, true, 1, 1} | |
3309 | , ival{{ 0, 2}, { 0, 2}, 21, 30, true, 0, 0} | |
3310 | , ival{{ 0, 2}, {2, 0}, 31, 35, true, 2, 2} | |
3311 | , ival{{ 0, 2}, { 0, 2}, 36, 50, true, 0, 0} | |
3312 | })); | |
3313 | } | |
3314 | void iterate_mayberw_back_to( | |
3315 | bool ec_pool, | |
3316 | epoch_t les, | |
3317 | std::function<void(epoch_t, const set<pg_shard_t> &)> &&f) const override { | |
3318 | for (auto i = intervals.rbegin(); i != intervals.rend(); ++i) { | |
3319 | if (i->last < les) | |
3320 | break; | |
3321 | f(i->first, i->acting); | |
3322 | } | |
3323 | } | |
3324 | virtual ~pi_compact_rep() override {} | |
3325 | }; | |
3326 | WRITE_CLASS_ENCODER(pi_compact_rep) | |
3327 | ||
3328 | PastIntervals::PastIntervals(const PastIntervals &rhs) | |
3329 | : past_intervals(rhs.past_intervals ? | |
3330 | rhs.past_intervals->clone() : | |
3331 | nullptr) {} | |
3332 | ||
3333 | PastIntervals &PastIntervals::operator=(const PastIntervals &rhs) | |
3334 | { | |
3335 | PastIntervals other(rhs); | |
31f18b77 | 3336 | swap(other); |
7c673cae FG |
3337 | return *this; |
3338 | } | |
3339 | ||
3340 | ostream& operator<<(ostream& out, const PastIntervals &i) | |
3341 | { | |
3342 | if (i.past_intervals) { | |
3343 | return i.past_intervals->print(out); | |
3344 | } else { | |
3345 | return out << "(empty)"; | |
3346 | } | |
3347 | } | |
3348 | ||
3349 | ostream& operator<<(ostream& out, const PastIntervals::PriorSet &i) | |
3350 | { | |
3351 | return out << "PriorSet(" | |
3352 | << "ec_pool: " << i.ec_pool | |
3353 | << ", probe: " << i.probe | |
3354 | << ", down: " << i.down | |
3355 | << ", blocked_by: " << i.blocked_by | |
3356 | << ", pg_down: " << i.pg_down | |
3357 | << ")"; | |
3358 | } | |
3359 | ||
3360 | void PastIntervals::decode(bufferlist::iterator &bl) | |
3361 | { | |
3362 | DECODE_START(1, bl); | |
3363 | __u8 type = 0; | |
3364 | ::decode(type, bl); | |
3365 | switch (type) { | |
3366 | case 0: | |
3367 | break; | |
3368 | case 1: | |
3369 | past_intervals.reset(new pi_simple_rep); | |
3370 | past_intervals->decode(bl); | |
3371 | break; | |
3372 | case 2: | |
3373 | past_intervals.reset(new pi_compact_rep); | |
3374 | past_intervals->decode(bl); | |
3375 | break; | |
3376 | } | |
3377 | DECODE_FINISH(bl); | |
3378 | } | |
3379 | ||
3380 | void PastIntervals::decode_classic(bufferlist::iterator &bl) | |
3381 | { | |
3382 | past_intervals.reset(new pi_simple_rep); | |
3383 | past_intervals->decode(bl); | |
3384 | } | |
3385 | ||
3386 | void PastIntervals::generate_test_instances(list<PastIntervals*> &o) | |
3387 | { | |
3388 | { | |
3389 | list<pi_simple_rep *> simple; | |
3390 | pi_simple_rep::generate_test_instances(simple); | |
3391 | for (auto &&i: simple) { | |
3392 | // takes ownership of contents | |
3393 | o.push_back(new PastIntervals(i)); | |
3394 | } | |
3395 | } | |
3396 | { | |
3397 | list<pi_compact_rep *> compact; | |
3398 | pi_compact_rep::generate_test_instances(compact); | |
3399 | for (auto &&i: compact) { | |
3400 | // takes ownership of contents | |
3401 | o.push_back(new PastIntervals(i)); | |
3402 | } | |
3403 | } | |
3404 | return; | |
3405 | } | |
3406 | ||
3407 | void PastIntervals::update_type(bool ec_pool, bool compact) | |
3408 | { | |
3409 | if (!compact) { | |
3410 | if (!past_intervals) { | |
3411 | past_intervals.reset(new pi_simple_rep); | |
3412 | } else { | |
3413 | // we never convert from compact back to classic | |
3414 | assert(is_classic()); | |
3415 | } | |
3416 | } else { | |
3417 | if (!past_intervals) { | |
3418 | past_intervals.reset(new pi_compact_rep); | |
3419 | } else if (is_classic()) { | |
3420 | auto old = std::move(past_intervals); | |
3421 | past_intervals.reset(new pi_compact_rep); | |
3422 | assert(old->has_full_intervals()); | |
3423 | old->iterate_all_intervals([&](const pg_interval_t &i) { | |
3424 | past_intervals->add_interval(ec_pool, i); | |
3425 | }); | |
3426 | } | |
3427 | } | |
3428 | } | |
3429 | ||
3430 | void PastIntervals::update_type_from_map(bool ec_pool, const OSDMap &osdmap) | |
3431 | { | |
31f18b77 | 3432 | update_type(ec_pool, osdmap.require_osd_release >= CEPH_RELEASE_LUMINOUS); |
7c673cae FG |
3433 | } |
3434 | ||
3435 | bool PastIntervals::is_new_interval( | |
3436 | int old_acting_primary, | |
3437 | int new_acting_primary, | |
3438 | const vector<int> &old_acting, | |
3439 | const vector<int> &new_acting, | |
3440 | int old_up_primary, | |
3441 | int new_up_primary, | |
3442 | const vector<int> &old_up, | |
3443 | const vector<int> &new_up, | |
3444 | int old_size, | |
3445 | int new_size, | |
3446 | int old_min_size, | |
3447 | int new_min_size, | |
3448 | unsigned old_pg_num, | |
3449 | unsigned new_pg_num, | |
3450 | bool old_sort_bitwise, | |
3451 | bool new_sort_bitwise, | |
c07f9fc5 FG |
3452 | bool old_recovery_deletes, |
3453 | bool new_recovery_deletes, | |
7c673cae FG |
3454 | pg_t pgid) { |
3455 | return old_acting_primary != new_acting_primary || | |
3456 | new_acting != old_acting || | |
3457 | old_up_primary != new_up_primary || | |
3458 | new_up != old_up || | |
3459 | old_min_size != new_min_size || | |
3460 | old_size != new_size || | |
3461 | pgid.is_split(old_pg_num, new_pg_num, 0) || | |
c07f9fc5 FG |
3462 | old_sort_bitwise != new_sort_bitwise || |
3463 | old_recovery_deletes != new_recovery_deletes; | |
7c673cae FG |
3464 | } |
3465 | ||
3466 | bool PastIntervals::is_new_interval( | |
3467 | int old_acting_primary, | |
3468 | int new_acting_primary, | |
3469 | const vector<int> &old_acting, | |
3470 | const vector<int> &new_acting, | |
3471 | int old_up_primary, | |
3472 | int new_up_primary, | |
3473 | const vector<int> &old_up, | |
3474 | const vector<int> &new_up, | |
3475 | OSDMapRef osdmap, | |
3476 | OSDMapRef lastmap, | |
3477 | pg_t pgid) { | |
3478 | return !(lastmap->get_pools().count(pgid.pool())) || | |
3479 | is_new_interval(old_acting_primary, | |
3480 | new_acting_primary, | |
3481 | old_acting, | |
3482 | new_acting, | |
3483 | old_up_primary, | |
3484 | new_up_primary, | |
3485 | old_up, | |
3486 | new_up, | |
3487 | lastmap->get_pools().find(pgid.pool())->second.size, | |
3488 | osdmap->get_pools().find(pgid.pool())->second.size, | |
3489 | lastmap->get_pools().find(pgid.pool())->second.min_size, | |
3490 | osdmap->get_pools().find(pgid.pool())->second.min_size, | |
3491 | lastmap->get_pg_num(pgid.pool()), | |
3492 | osdmap->get_pg_num(pgid.pool()), | |
3493 | lastmap->test_flag(CEPH_OSDMAP_SORTBITWISE), | |
3494 | osdmap->test_flag(CEPH_OSDMAP_SORTBITWISE), | |
c07f9fc5 FG |
3495 | lastmap->test_flag(CEPH_OSDMAP_RECOVERY_DELETES), |
3496 | osdmap->test_flag(CEPH_OSDMAP_RECOVERY_DELETES), | |
7c673cae FG |
3497 | pgid); |
3498 | } | |
3499 | ||
3500 | bool PastIntervals::check_new_interval( | |
3501 | int old_acting_primary, | |
3502 | int new_acting_primary, | |
3503 | const vector<int> &old_acting, | |
3504 | const vector<int> &new_acting, | |
3505 | int old_up_primary, | |
3506 | int new_up_primary, | |
3507 | const vector<int> &old_up, | |
3508 | const vector<int> &new_up, | |
3509 | epoch_t same_interval_since, | |
3510 | epoch_t last_epoch_clean, | |
3511 | OSDMapRef osdmap, | |
3512 | OSDMapRef lastmap, | |
3513 | pg_t pgid, | |
3514 | IsPGRecoverablePredicate *could_have_gone_active, | |
3515 | PastIntervals *past_intervals, | |
3516 | std::ostream *out) | |
3517 | { | |
3518 | /* | |
3519 | * We have to be careful to gracefully deal with situations like | |
3520 | * so. Say we have a power outage or something that takes out both | |
3521 | * OSDs, but the monitor doesn't mark them down in the same epoch. | |
3522 | * The history may look like | |
3523 | * | |
3524 | * 1: A B | |
3525 | * 2: B | |
3526 | * 3: let's say B dies for good, too (say, from the power spike) | |
3527 | * 4: A | |
3528 | * | |
3529 | * which makes it look like B may have applied updates to the PG | |
3530 | * that we need in order to proceed. This sucks... | |
3531 | * | |
3532 | * To minimize the risk of this happening, we CANNOT go active if | |
3533 | * _any_ OSDs in the prior set are down until we send an MOSDAlive | |
3534 | * to the monitor such that the OSDMap sets osd_up_thru to an epoch. | |
3535 | * Then, we have something like | |
3536 | * | |
3537 | * 1: A B | |
3538 | * 2: B up_thru[B]=0 | |
3539 | * 3: | |
3540 | * 4: A | |
3541 | * | |
3542 | * -> we can ignore B, bc it couldn't have gone active (up_thru still 0). | |
3543 | * | |
3544 | * or, | |
3545 | * | |
3546 | * 1: A B | |
3547 | * 2: B up_thru[B]=0 | |
3548 | * 3: B up_thru[B]=2 | |
3549 | * 4: | |
3550 | * 5: A | |
3551 | * | |
3552 | * -> we must wait for B, bc it was alive through 2, and could have | |
3553 | * written to the pg. | |
3554 | * | |
3555 | * If B is really dead, then an administrator will need to manually | |
3556 | * intervene by marking the OSD as "lost." | |
3557 | */ | |
3558 | ||
3559 | // remember past interval | |
3560 | // NOTE: a change in the up set primary triggers an interval | |
3561 | // change, even though the interval members in the pg_interval_t | |
3562 | // do not change. | |
3563 | assert(past_intervals); | |
3564 | assert(past_intervals->past_intervals); | |
3565 | if (is_new_interval( | |
3566 | old_acting_primary, | |
3567 | new_acting_primary, | |
3568 | old_acting, | |
3569 | new_acting, | |
3570 | old_up_primary, | |
3571 | new_up_primary, | |
3572 | old_up, | |
3573 | new_up, | |
3574 | osdmap, | |
3575 | lastmap, | |
3576 | pgid)) { | |
3577 | pg_interval_t i; | |
3578 | i.first = same_interval_since; | |
3579 | i.last = osdmap->get_epoch() - 1; | |
3580 | assert(i.first <= i.last); | |
3581 | i.acting = old_acting; | |
3582 | i.up = old_up; | |
3583 | i.primary = old_acting_primary; | |
3584 | i.up_primary = old_up_primary; | |
3585 | ||
3586 | unsigned num_acting = 0; | |
3587 | for (vector<int>::const_iterator p = i.acting.begin(); p != i.acting.end(); | |
3588 | ++p) | |
3589 | if (*p != CRUSH_ITEM_NONE) | |
3590 | ++num_acting; | |
3591 | ||
3592 | assert(lastmap->get_pools().count(pgid.pool())); | |
3593 | const pg_pool_t& old_pg_pool = lastmap->get_pools().find(pgid.pool())->second; | |
3594 | set<pg_shard_t> old_acting_shards; | |
3595 | old_pg_pool.convert_to_pg_shards(old_acting, &old_acting_shards); | |
3596 | ||
3597 | if (num_acting && | |
3598 | i.primary != -1 && | |
3599 | num_acting >= old_pg_pool.min_size && | |
3600 | (*could_have_gone_active)(old_acting_shards)) { | |
3601 | if (out) | |
3602 | *out << __func__ << " " << i | |
3603 | << ": not rw," | |
3604 | << " up_thru " << lastmap->get_up_thru(i.primary) | |
3605 | << " up_from " << lastmap->get_up_from(i.primary) | |
3606 | << " last_epoch_clean " << last_epoch_clean | |
3607 | << std::endl; | |
3608 | if (lastmap->get_up_thru(i.primary) >= i.first && | |
3609 | lastmap->get_up_from(i.primary) <= i.first) { | |
3610 | i.maybe_went_rw = true; | |
3611 | if (out) | |
3612 | *out << __func__ << " " << i | |
3613 | << " : primary up " << lastmap->get_up_from(i.primary) | |
3614 | << "-" << lastmap->get_up_thru(i.primary) | |
3615 | << " includes interval" | |
3616 | << std::endl; | |
3617 | } else if (last_epoch_clean >= i.first && | |
3618 | last_epoch_clean <= i.last) { | |
3619 | // If the last_epoch_clean is included in this interval, then | |
3620 | // the pg must have been rw (for recovery to have completed). | |
3621 | // This is important because we won't know the _real_ | |
3622 | // first_epoch because we stop at last_epoch_clean, and we | |
3623 | // don't want the oldest interval to randomly have | |
3624 | // maybe_went_rw false depending on the relative up_thru vs | |
3625 | // last_epoch_clean timing. | |
3626 | i.maybe_went_rw = true; | |
3627 | if (out) | |
3628 | *out << __func__ << " " << i | |
3629 | << " : includes last_epoch_clean " << last_epoch_clean | |
3630 | << " and presumed to have been rw" | |
3631 | << std::endl; | |
3632 | } else { | |
3633 | i.maybe_went_rw = false; | |
3634 | if (out) | |
3635 | *out << __func__ << " " << i | |
3636 | << " : primary up " << lastmap->get_up_from(i.primary) | |
3637 | << "-" << lastmap->get_up_thru(i.primary) | |
3638 | << " does not include interval" | |
3639 | << std::endl; | |
3640 | } | |
3641 | } else { | |
3642 | i.maybe_went_rw = false; | |
3643 | if (out) | |
3644 | *out << __func__ << " " << i << " : acting set is too small" << std::endl; | |
3645 | } | |
3646 | past_intervals->past_intervals->add_interval(old_pg_pool.ec_pool(), i); | |
3647 | return true; | |
3648 | } else { | |
3649 | return false; | |
3650 | } | |
3651 | } | |
3652 | ||
3653 | ||
3654 | // true if the given map affects the prior set | |
3655 | bool PastIntervals::PriorSet::affected_by_map( | |
3656 | const OSDMap &osdmap, | |
3657 | const DoutPrefixProvider *dpp) const | |
3658 | { | |
3659 | for (set<pg_shard_t>::iterator p = probe.begin(); | |
3660 | p != probe.end(); | |
3661 | ++p) { | |
3662 | int o = p->osd; | |
3663 | ||
3664 | // did someone in the prior set go down? | |
3665 | if (osdmap.is_down(o) && down.count(o) == 0) { | |
3666 | ldpp_dout(dpp, 10) << "affected_by_map osd." << o << " now down" << dendl; | |
3667 | return true; | |
3668 | } | |
3669 | ||
3670 | // did a down osd in cur get (re)marked as lost? | |
3671 | map<int, epoch_t>::const_iterator r = blocked_by.find(o); | |
3672 | if (r != blocked_by.end()) { | |
3673 | if (!osdmap.exists(o)) { | |
3674 | ldpp_dout(dpp, 10) << "affected_by_map osd." << o << " no longer exists" << dendl; | |
3675 | return true; | |
3676 | } | |
3677 | if (osdmap.get_info(o).lost_at != r->second) { | |
3678 | ldpp_dout(dpp, 10) << "affected_by_map osd." << o << " (re)marked as lost" << dendl; | |
3679 | return true; | |
3680 | } | |
3681 | } | |
3682 | } | |
3683 | ||
3684 | // did someone in the prior down set go up? | |
3685 | for (set<int>::const_iterator p = down.begin(); | |
3686 | p != down.end(); | |
3687 | ++p) { | |
3688 | int o = *p; | |
3689 | ||
3690 | if (osdmap.is_up(o)) { | |
3691 | ldpp_dout(dpp, 10) << "affected_by_map osd." << o << " now up" << dendl; | |
3692 | return true; | |
3693 | } | |
3694 | ||
3695 | // did someone in the prior set get lost or destroyed? | |
3696 | if (!osdmap.exists(o)) { | |
3697 | ldpp_dout(dpp, 10) << "affected_by_map osd." << o << " no longer exists" << dendl; | |
3698 | return true; | |
3699 | } | |
3700 | // did a down osd in down get (re)marked as lost? | |
3701 | map<int, epoch_t>::const_iterator r = blocked_by.find(o); | |
3702 | if (r != blocked_by.end()) { | |
3703 | if (osdmap.get_info(o).lost_at != r->second) { | |
3704 | ldpp_dout(dpp, 10) << "affected_by_map osd." << o << " (re)marked as lost" << dendl; | |
3705 | return true; | |
3706 | } | |
3707 | } | |
3708 | } | |
3709 | ||
3710 | return false; | |
3711 | } | |
3712 | ||
3713 | ostream& operator<<(ostream& out, const PastIntervals::pg_interval_t& i) | |
3714 | { | |
3715 | out << "interval(" << i.first << "-" << i.last | |
3716 | << " up " << i.up << "(" << i.up_primary << ")" | |
3717 | << " acting " << i.acting << "(" << i.primary << ")"; | |
3718 | if (i.maybe_went_rw) | |
3719 | out << " maybe_went_rw"; | |
3720 | out << ")"; | |
3721 | return out; | |
3722 | } | |
3723 | ||
3724 | ||
3725 | ||
3726 | // -- pg_query_t -- | |
3727 | ||
3728 | void pg_query_t::encode(bufferlist &bl, uint64_t features) const { | |
3729 | ENCODE_START(3, 3, bl); | |
3730 | ::encode(type, bl); | |
3731 | ::encode(since, bl); | |
3732 | history.encode(bl); | |
3733 | ::encode(epoch_sent, bl); | |
3734 | ::encode(to, bl); | |
3735 | ::encode(from, bl); | |
3736 | ENCODE_FINISH(bl); | |
3737 | } | |
3738 | ||
3739 | void pg_query_t::decode(bufferlist::iterator &bl) { | |
3740 | DECODE_START(3, bl); | |
3741 | ::decode(type, bl); | |
3742 | ::decode(since, bl); | |
3743 | history.decode(bl); | |
3744 | ::decode(epoch_sent, bl); | |
3745 | ::decode(to, bl); | |
3746 | ::decode(from, bl); | |
3747 | DECODE_FINISH(bl); | |
3748 | } | |
3749 | ||
3750 | void pg_query_t::dump(Formatter *f) const | |
3751 | { | |
3752 | f->dump_int("from", from); | |
3753 | f->dump_int("to", to); | |
3754 | f->dump_string("type", get_type_name()); | |
3755 | f->dump_stream("since") << since; | |
3756 | f->dump_stream("epoch_sent") << epoch_sent; | |
3757 | f->open_object_section("history"); | |
3758 | history.dump(f); | |
3759 | f->close_section(); | |
3760 | } | |
3761 | void pg_query_t::generate_test_instances(list<pg_query_t*>& o) | |
3762 | { | |
3763 | o.push_back(new pg_query_t()); | |
3764 | list<pg_history_t*> h; | |
3765 | pg_history_t::generate_test_instances(h); | |
3766 | o.push_back(new pg_query_t(pg_query_t::INFO, shard_id_t(1), shard_id_t(2), *h.back(), 4)); | |
3767 | o.push_back(new pg_query_t(pg_query_t::MISSING, shard_id_t(2), shard_id_t(3), *h.back(), 4)); | |
3768 | o.push_back(new pg_query_t(pg_query_t::LOG, shard_id_t(0), shard_id_t(0), | |
3769 | eversion_t(4, 5), *h.back(), 4)); | |
3770 | o.push_back(new pg_query_t(pg_query_t::FULLLOG, | |
3771 | shard_id_t::NO_SHARD, shard_id_t::NO_SHARD, | |
3772 | *h.back(), 5)); | |
3773 | } | |
3774 | ||
3775 | // -- ObjectModDesc -- | |
3776 | void ObjectModDesc::visit(Visitor *visitor) const | |
3777 | { | |
3778 | bufferlist::iterator bp = bl.begin(); | |
3779 | try { | |
3780 | while (!bp.end()) { | |
3781 | DECODE_START(max_required_version, bp); | |
3782 | uint8_t code; | |
3783 | ::decode(code, bp); | |
3784 | switch (code) { | |
3785 | case APPEND: { | |
3786 | uint64_t size; | |
3787 | ::decode(size, bp); | |
3788 | visitor->append(size); | |
3789 | break; | |
3790 | } | |
3791 | case SETATTRS: { | |
3792 | map<string, boost::optional<bufferlist> > attrs; | |
3793 | ::decode(attrs, bp); | |
3794 | visitor->setattrs(attrs); | |
3795 | break; | |
3796 | } | |
3797 | case DELETE: { | |
3798 | version_t old_version; | |
3799 | ::decode(old_version, bp); | |
3800 | visitor->rmobject(old_version); | |
3801 | break; | |
3802 | } | |
3803 | case CREATE: { | |
3804 | visitor->create(); | |
3805 | break; | |
3806 | } | |
3807 | case UPDATE_SNAPS: { | |
3808 | set<snapid_t> snaps; | |
3809 | ::decode(snaps, bp); | |
3810 | visitor->update_snaps(snaps); | |
3811 | break; | |
3812 | } | |
3813 | case TRY_DELETE: { | |
3814 | version_t old_version; | |
3815 | ::decode(old_version, bp); | |
3816 | visitor->try_rmobject(old_version); | |
3817 | break; | |
3818 | } | |
3819 | case ROLLBACK_EXTENTS: { | |
3820 | vector<pair<uint64_t, uint64_t> > extents; | |
3821 | version_t gen; | |
3822 | ::decode(gen, bp); | |
3823 | ::decode(extents, bp); | |
3824 | visitor->rollback_extents(gen,extents); | |
3825 | break; | |
3826 | } | |
3827 | default: | |
3828 | assert(0 == "Invalid rollback code"); | |
3829 | } | |
3830 | DECODE_FINISH(bp); | |
3831 | } | |
3832 | } catch (...) { | |
3833 | assert(0 == "Invalid encoding"); | |
3834 | } | |
3835 | } | |
3836 | ||
3837 | struct DumpVisitor : public ObjectModDesc::Visitor { | |
3838 | Formatter *f; | |
3839 | explicit DumpVisitor(Formatter *f) : f(f) {} | |
3840 | void append(uint64_t old_size) override { | |
3841 | f->open_object_section("op"); | |
3842 | f->dump_string("code", "APPEND"); | |
3843 | f->dump_unsigned("old_size", old_size); | |
3844 | f->close_section(); | |
3845 | } | |
3846 | void setattrs(map<string, boost::optional<bufferlist> > &attrs) override { | |
3847 | f->open_object_section("op"); | |
3848 | f->dump_string("code", "SETATTRS"); | |
3849 | f->open_array_section("attrs"); | |
3850 | for (map<string, boost::optional<bufferlist> >::iterator i = attrs.begin(); | |
3851 | i != attrs.end(); | |
3852 | ++i) { | |
3853 | f->dump_string("attr_name", i->first); | |
3854 | } | |
3855 | f->close_section(); | |
3856 | f->close_section(); | |
3857 | } | |
3858 | void rmobject(version_t old_version) override { | |
3859 | f->open_object_section("op"); | |
3860 | f->dump_string("code", "RMOBJECT"); | |
3861 | f->dump_unsigned("old_version", old_version); | |
3862 | f->close_section(); | |
3863 | } | |
3864 | void try_rmobject(version_t old_version) override { | |
3865 | f->open_object_section("op"); | |
3866 | f->dump_string("code", "TRY_RMOBJECT"); | |
3867 | f->dump_unsigned("old_version", old_version); | |
3868 | f->close_section(); | |
3869 | } | |
3870 | void create() override { | |
3871 | f->open_object_section("op"); | |
3872 | f->dump_string("code", "CREATE"); | |
3873 | f->close_section(); | |
3874 | } | |
3875 | void update_snaps(const set<snapid_t> &snaps) override { | |
3876 | f->open_object_section("op"); | |
3877 | f->dump_string("code", "UPDATE_SNAPS"); | |
3878 | f->dump_stream("snaps") << snaps; | |
3879 | f->close_section(); | |
3880 | } | |
3881 | void rollback_extents( | |
3882 | version_t gen, | |
3883 | const vector<pair<uint64_t, uint64_t> > &extents) override { | |
3884 | f->open_object_section("op"); | |
3885 | f->dump_string("code", "ROLLBACK_EXTENTS"); | |
3886 | f->dump_unsigned("gen", gen); | |
3887 | f->dump_stream("snaps") << extents; | |
3888 | f->close_section(); | |
3889 | } | |
3890 | }; | |
3891 | ||
3892 | void ObjectModDesc::dump(Formatter *f) const | |
3893 | { | |
3894 | f->open_object_section("object_mod_desc"); | |
3895 | f->dump_bool("can_local_rollback", can_local_rollback); | |
3896 | f->dump_bool("rollback_info_completed", rollback_info_completed); | |
3897 | { | |
3898 | f->open_array_section("ops"); | |
3899 | DumpVisitor vis(f); | |
3900 | visit(&vis); | |
3901 | f->close_section(); | |
3902 | } | |
3903 | f->close_section(); | |
3904 | } | |
3905 | ||
3906 | void ObjectModDesc::generate_test_instances(list<ObjectModDesc*>& o) | |
3907 | { | |
3908 | map<string, boost::optional<bufferlist> > attrs; | |
3909 | attrs[OI_ATTR]; | |
3910 | attrs[SS_ATTR]; | |
3911 | attrs["asdf"]; | |
3912 | o.push_back(new ObjectModDesc()); | |
3913 | o.back()->append(100); | |
3914 | o.back()->setattrs(attrs); | |
3915 | o.push_back(new ObjectModDesc()); | |
3916 | o.back()->rmobject(1001); | |
3917 | o.push_back(new ObjectModDesc()); | |
3918 | o.back()->create(); | |
3919 | o.back()->setattrs(attrs); | |
3920 | o.push_back(new ObjectModDesc()); | |
3921 | o.back()->create(); | |
3922 | o.back()->setattrs(attrs); | |
3923 | o.back()->mark_unrollbackable(); | |
3924 | o.back()->append(1000); | |
3925 | } | |
3926 | ||
3927 | void ObjectModDesc::encode(bufferlist &_bl) const | |
3928 | { | |
3929 | ENCODE_START(max_required_version, max_required_version, _bl); | |
3930 | ::encode(can_local_rollback, _bl); | |
3931 | ::encode(rollback_info_completed, _bl); | |
3932 | ::encode(bl, _bl); | |
3933 | ENCODE_FINISH(_bl); | |
3934 | } | |
3935 | void ObjectModDesc::decode(bufferlist::iterator &_bl) | |
3936 | { | |
3937 | DECODE_START(2, _bl); | |
3938 | max_required_version = struct_v; | |
3939 | ::decode(can_local_rollback, _bl); | |
3940 | ::decode(rollback_info_completed, _bl); | |
3941 | ::decode(bl, _bl); | |
3942 | // ensure bl does not pin a larger buffer in memory | |
3943 | bl.rebuild(); | |
31f18b77 | 3944 | bl.reassign_to_mempool(mempool::mempool_osd_pglog); |
7c673cae FG |
3945 | DECODE_FINISH(_bl); |
3946 | } | |
3947 | ||
3948 | // -- pg_log_entry_t -- | |
3949 | ||
3950 | string pg_log_entry_t::get_key_name() const | |
3951 | { | |
3952 | return version.get_key_name(); | |
3953 | } | |
3954 | ||
3955 | void pg_log_entry_t::encode_with_checksum(bufferlist& bl) const | |
3956 | { | |
3957 | bufferlist ebl(sizeof(*this)*2); | |
3958 | encode(ebl); | |
3959 | __u32 crc = ebl.crc32c(0); | |
3960 | ::encode(ebl, bl); | |
3961 | ::encode(crc, bl); | |
3962 | } | |
3963 | ||
3964 | void pg_log_entry_t::decode_with_checksum(bufferlist::iterator& p) | |
3965 | { | |
3966 | bufferlist bl; | |
3967 | ::decode(bl, p); | |
3968 | __u32 crc; | |
3969 | ::decode(crc, p); | |
3970 | if (crc != bl.crc32c(0)) | |
3971 | throw buffer::malformed_input("bad checksum on pg_log_entry_t"); | |
3972 | bufferlist::iterator q = bl.begin(); | |
3973 | decode(q); | |
3974 | } | |
3975 | ||
3976 | void pg_log_entry_t::encode(bufferlist &bl) const | |
3977 | { | |
3978 | ENCODE_START(11, 4, bl); | |
3979 | ::encode(op, bl); | |
3980 | ::encode(soid, bl); | |
3981 | ::encode(version, bl); | |
3982 | ||
3983 | /** | |
3984 | * Added with reverting_to: | |
3985 | * Previous code used prior_version to encode | |
3986 | * what we now call reverting_to. This will | |
3987 | * allow older code to decode reverting_to | |
3988 | * into prior_version as expected. | |
3989 | */ | |
3990 | if (op == LOST_REVERT) | |
3991 | ::encode(reverting_to, bl); | |
3992 | else | |
3993 | ::encode(prior_version, bl); | |
3994 | ||
3995 | ::encode(reqid, bl); | |
3996 | ::encode(mtime, bl); | |
3997 | if (op == LOST_REVERT) | |
3998 | ::encode(prior_version, bl); | |
3999 | ::encode(snaps, bl); | |
4000 | ::encode(user_version, bl); | |
4001 | ::encode(mod_desc, bl); | |
4002 | ::encode(extra_reqids, bl); | |
4003 | if (op == ERROR) | |
4004 | ::encode(return_code, bl); | |
4005 | ENCODE_FINISH(bl); | |
4006 | } | |
4007 | ||
4008 | void pg_log_entry_t::decode(bufferlist::iterator &bl) | |
4009 | { | |
4010 | DECODE_START_LEGACY_COMPAT_LEN(11, 4, 4, bl); | |
4011 | ::decode(op, bl); | |
4012 | if (struct_v < 2) { | |
4013 | sobject_t old_soid; | |
4014 | ::decode(old_soid, bl); | |
4015 | soid.oid = old_soid.oid; | |
4016 | soid.snap = old_soid.snap; | |
4017 | invalid_hash = true; | |
4018 | } else { | |
4019 | ::decode(soid, bl); | |
4020 | } | |
4021 | if (struct_v < 3) | |
4022 | invalid_hash = true; | |
4023 | ::decode(version, bl); | |
4024 | ||
4025 | if (struct_v >= 6 && op == LOST_REVERT) | |
4026 | ::decode(reverting_to, bl); | |
4027 | else | |
4028 | ::decode(prior_version, bl); | |
4029 | ||
4030 | ::decode(reqid, bl); | |
4031 | ||
4032 | ::decode(mtime, bl); | |
4033 | if (struct_v < 5) | |
4034 | invalid_pool = true; | |
4035 | ||
4036 | if (op == LOST_REVERT) { | |
4037 | if (struct_v >= 6) { | |
4038 | ::decode(prior_version, bl); | |
4039 | } else { | |
4040 | reverting_to = prior_version; | |
4041 | } | |
4042 | } | |
4043 | if (struct_v >= 7 || // for v >= 7, this is for all ops. | |
4044 | op == CLONE) { // for v < 7, it's only present for CLONE. | |
4045 | ::decode(snaps, bl); | |
4046 | // ensure snaps does not pin a larger buffer in memory | |
4047 | snaps.rebuild(); | |
31f18b77 | 4048 | snaps.reassign_to_mempool(mempool::mempool_osd_pglog); |
7c673cae FG |
4049 | } |
4050 | ||
4051 | if (struct_v >= 8) | |
4052 | ::decode(user_version, bl); | |
4053 | else | |
4054 | user_version = version.version; | |
4055 | ||
4056 | if (struct_v >= 9) | |
4057 | ::decode(mod_desc, bl); | |
4058 | else | |
4059 | mod_desc.mark_unrollbackable(); | |
4060 | if (struct_v >= 10) | |
4061 | ::decode(extra_reqids, bl); | |
4062 | if (struct_v >= 11 && op == ERROR) | |
4063 | ::decode(return_code, bl); | |
4064 | DECODE_FINISH(bl); | |
4065 | } | |
4066 | ||
4067 | void pg_log_entry_t::dump(Formatter *f) const | |
4068 | { | |
4069 | f->dump_string("op", get_op_name()); | |
4070 | f->dump_stream("object") << soid; | |
4071 | f->dump_stream("version") << version; | |
4072 | f->dump_stream("prior_version") << prior_version; | |
4073 | f->dump_stream("reqid") << reqid; | |
4074 | f->open_array_section("extra_reqids"); | |
31f18b77 | 4075 | for (auto p = extra_reqids.begin(); |
7c673cae FG |
4076 | p != extra_reqids.end(); |
4077 | ++p) { | |
4078 | f->open_object_section("extra_reqid"); | |
4079 | f->dump_stream("reqid") << p->first; | |
4080 | f->dump_stream("user_version") << p->second; | |
4081 | f->close_section(); | |
4082 | } | |
4083 | f->close_section(); | |
4084 | f->dump_stream("mtime") << mtime; | |
4085 | f->dump_int("return_code", return_code); | |
4086 | if (snaps.length() > 0) { | |
4087 | vector<snapid_t> v; | |
4088 | bufferlist c = snaps; | |
4089 | bufferlist::iterator p = c.begin(); | |
4090 | try { | |
4091 | ::decode(v, p); | |
4092 | } catch (...) { | |
4093 | v.clear(); | |
4094 | } | |
4095 | f->open_object_section("snaps"); | |
4096 | for (vector<snapid_t>::iterator p = v.begin(); p != v.end(); ++p) | |
4097 | f->dump_unsigned("snap", *p); | |
4098 | f->close_section(); | |
4099 | } | |
4100 | { | |
4101 | f->open_object_section("mod_desc"); | |
4102 | mod_desc.dump(f); | |
4103 | f->close_section(); | |
4104 | } | |
4105 | } | |
4106 | ||
4107 | void pg_log_entry_t::generate_test_instances(list<pg_log_entry_t*>& o) | |
4108 | { | |
4109 | o.push_back(new pg_log_entry_t()); | |
4110 | hobject_t oid(object_t("objname"), "key", 123, 456, 0, ""); | |
4111 | o.push_back(new pg_log_entry_t(MODIFY, oid, eversion_t(1,2), eversion_t(3,4), | |
4112 | 1, osd_reqid_t(entity_name_t::CLIENT(777), 8, 999), | |
4113 | utime_t(8,9), 0)); | |
4114 | o.push_back(new pg_log_entry_t(ERROR, oid, eversion_t(1,2), eversion_t(3,4), | |
4115 | 1, osd_reqid_t(entity_name_t::CLIENT(777), 8, 999), | |
4116 | utime_t(8,9), -ENOENT)); | |
4117 | } | |
4118 | ||
4119 | ostream& operator<<(ostream& out, const pg_log_entry_t& e) | |
4120 | { | |
4121 | out << e.version << " (" << e.prior_version << ") " | |
4122 | << std::left << std::setw(8) << e.get_op_name() << ' ' | |
4123 | << e.soid << " by " << e.reqid << " " << e.mtime | |
4124 | << " " << e.return_code; | |
4125 | if (e.snaps.length()) { | |
4126 | vector<snapid_t> snaps; | |
4127 | bufferlist c = e.snaps; | |
4128 | bufferlist::iterator p = c.begin(); | |
4129 | try { | |
4130 | ::decode(snaps, p); | |
4131 | } catch (...) { | |
4132 | snaps.clear(); | |
4133 | } | |
4134 | out << " snaps " << snaps; | |
4135 | } | |
4136 | return out; | |
4137 | } | |
4138 | ||
c07f9fc5 FG |
4139 | // -- pg_log_dup_t -- |
4140 | ||
4141 | string pg_log_dup_t::get_key_name() const | |
4142 | { | |
4143 | return "dup_" + version.get_key_name(); | |
4144 | } | |
4145 | ||
4146 | void pg_log_dup_t::encode(bufferlist &bl) const | |
4147 | { | |
4148 | ENCODE_START(1, 1, bl); | |
4149 | ::encode(reqid, bl); | |
4150 | ::encode(version, bl); | |
4151 | ::encode(user_version, bl); | |
4152 | ::encode(return_code, bl); | |
4153 | ENCODE_FINISH(bl); | |
4154 | } | |
4155 | ||
4156 | void pg_log_dup_t::decode(bufferlist::iterator &bl) | |
4157 | { | |
4158 | DECODE_START(1, bl); | |
4159 | ::decode(reqid, bl); | |
4160 | ::decode(version, bl); | |
4161 | ::decode(user_version, bl); | |
4162 | ::decode(return_code, bl); | |
4163 | DECODE_FINISH(bl); | |
4164 | } | |
4165 | ||
4166 | void pg_log_dup_t::dump(Formatter *f) const | |
4167 | { | |
4168 | f->dump_stream("reqid") << reqid; | |
4169 | f->dump_stream("version") << version; | |
4170 | f->dump_stream("user_version") << user_version; | |
4171 | f->dump_stream("return_code") << return_code; | |
4172 | } | |
4173 | ||
4174 | void pg_log_dup_t::generate_test_instances(list<pg_log_dup_t*>& o) | |
4175 | { | |
4176 | o.push_back(new pg_log_dup_t()); | |
4177 | o.push_back(new pg_log_dup_t(eversion_t(1,2), | |
4178 | 1, | |
4179 | osd_reqid_t(entity_name_t::CLIENT(777), 8, 999), | |
4180 | 0)); | |
4181 | o.push_back(new pg_log_dup_t(eversion_t(1,2), | |
4182 | 2, | |
4183 | osd_reqid_t(entity_name_t::CLIENT(777), 8, 999), | |
4184 | -ENOENT)); | |
4185 | } | |
4186 | ||
4187 | ||
4188 | std::ostream& operator<<(std::ostream& out, const pg_log_dup_t& e) { | |
4189 | return out << "log_dup(reqid=" << e.reqid << | |
4190 | " v=" << e.version << " uv=" << e.user_version << | |
4191 | " rc=" << e.return_code << ")"; | |
4192 | } | |
4193 | ||
7c673cae FG |
4194 | |
4195 | // -- pg_log_t -- | |
4196 | ||
4197 | // out: pg_log_t that only has entries that apply to import_pgid using curmap | |
4198 | // reject: Entries rejected from "in" are in the reject.log. Other fields not set. | |
4199 | void pg_log_t::filter_log(spg_t import_pgid, const OSDMap &curmap, | |
4200 | const string &hit_set_namespace, const pg_log_t &in, | |
4201 | pg_log_t &out, pg_log_t &reject) | |
4202 | { | |
4203 | out = in; | |
4204 | out.log.clear(); | |
4205 | reject.log.clear(); | |
4206 | ||
4207 | for (list<pg_log_entry_t>::const_iterator i = in.log.begin(); | |
4208 | i != in.log.end(); ++i) { | |
4209 | ||
4210 | // Reject pg log entries for temporary objects | |
4211 | if (i->soid.is_temp()) { | |
4212 | reject.log.push_back(*i); | |
4213 | continue; | |
4214 | } | |
4215 | ||
4216 | if (i->soid.nspace != hit_set_namespace) { | |
4217 | object_t oid = i->soid.oid; | |
4218 | object_locator_t loc(i->soid); | |
4219 | pg_t raw_pgid = curmap.object_locator_to_pg(oid, loc); | |
4220 | pg_t pgid = curmap.raw_pg_to_pg(raw_pgid); | |
4221 | ||
4222 | if (import_pgid.pgid == pgid) { | |
4223 | out.log.push_back(*i); | |
4224 | } else { | |
4225 | reject.log.push_back(*i); | |
4226 | } | |
4227 | } else { | |
4228 | out.log.push_back(*i); | |
4229 | } | |
4230 | } | |
4231 | } | |
4232 | ||
4233 | void pg_log_t::encode(bufferlist& bl) const | |
4234 | { | |
c07f9fc5 | 4235 | ENCODE_START(7, 3, bl); |
7c673cae FG |
4236 | ::encode(head, bl); |
4237 | ::encode(tail, bl); | |
4238 | ::encode(log, bl); | |
4239 | ::encode(can_rollback_to, bl); | |
4240 | ::encode(rollback_info_trimmed_to, bl); | |
c07f9fc5 | 4241 | ::encode(dups, bl); |
7c673cae FG |
4242 | ENCODE_FINISH(bl); |
4243 | } | |
4244 | ||
4245 | void pg_log_t::decode(bufferlist::iterator &bl, int64_t pool) | |
4246 | { | |
c07f9fc5 | 4247 | DECODE_START_LEGACY_COMPAT_LEN(7, 3, 3, bl); |
7c673cae FG |
4248 | ::decode(head, bl); |
4249 | ::decode(tail, bl); | |
4250 | if (struct_v < 2) { | |
4251 | bool backlog; | |
4252 | ::decode(backlog, bl); | |
4253 | } | |
4254 | ::decode(log, bl); | |
4255 | if (struct_v >= 5) | |
4256 | ::decode(can_rollback_to, bl); | |
4257 | ||
4258 | if (struct_v >= 6) | |
4259 | ::decode(rollback_info_trimmed_to, bl); | |
4260 | else | |
4261 | rollback_info_trimmed_to = tail; | |
c07f9fc5 FG |
4262 | |
4263 | if (struct_v >= 7) | |
4264 | ::decode(dups, bl); | |
4265 | ||
7c673cae FG |
4266 | DECODE_FINISH(bl); |
4267 | ||
4268 | // handle hobject_t format change | |
4269 | if (struct_v < 4) { | |
4270 | for (list<pg_log_entry_t>::iterator i = log.begin(); | |
4271 | i != log.end(); | |
4272 | ++i) { | |
4273 | if (!i->soid.is_max() && i->soid.pool == -1) | |
4274 | i->soid.pool = pool; | |
4275 | } | |
4276 | } | |
4277 | } | |
4278 | ||
4279 | void pg_log_t::dump(Formatter *f) const | |
4280 | { | |
4281 | f->dump_stream("head") << head; | |
4282 | f->dump_stream("tail") << tail; | |
4283 | f->open_array_section("log"); | |
4284 | for (list<pg_log_entry_t>::const_iterator p = log.begin(); p != log.end(); ++p) { | |
4285 | f->open_object_section("entry"); | |
4286 | p->dump(f); | |
4287 | f->close_section(); | |
4288 | } | |
4289 | f->close_section(); | |
c07f9fc5 FG |
4290 | f->open_array_section("dups"); |
4291 | for (const auto& entry : dups) { | |
4292 | f->open_object_section("entry"); | |
4293 | entry.dump(f); | |
4294 | f->close_section(); | |
4295 | } | |
4296 | f->close_section(); | |
7c673cae FG |
4297 | } |
4298 | ||
4299 | void pg_log_t::generate_test_instances(list<pg_log_t*>& o) | |
4300 | { | |
4301 | o.push_back(new pg_log_t); | |
4302 | ||
4303 | // this is nonsensical: | |
4304 | o.push_back(new pg_log_t); | |
4305 | o.back()->head = eversion_t(1,2); | |
4306 | o.back()->tail = eversion_t(3,4); | |
4307 | list<pg_log_entry_t*> e; | |
4308 | pg_log_entry_t::generate_test_instances(e); | |
4309 | for (list<pg_log_entry_t*>::iterator p = e.begin(); p != e.end(); ++p) | |
4310 | o.back()->log.push_back(**p); | |
4311 | } | |
4312 | ||
4313 | void pg_log_t::copy_after(const pg_log_t &other, eversion_t v) | |
4314 | { | |
4315 | can_rollback_to = other.can_rollback_to; | |
4316 | head = other.head; | |
4317 | tail = other.tail; | |
4318 | for (list<pg_log_entry_t>::const_reverse_iterator i = other.log.rbegin(); | |
4319 | i != other.log.rend(); | |
4320 | ++i) { | |
4321 | assert(i->version > other.tail); | |
4322 | if (i->version <= v) { | |
4323 | // make tail accurate. | |
4324 | tail = i->version; | |
4325 | break; | |
4326 | } | |
4327 | log.push_front(*i); | |
4328 | } | |
4329 | } | |
4330 | ||
4331 | void pg_log_t::copy_range(const pg_log_t &other, eversion_t from, eversion_t to) | |
4332 | { | |
4333 | can_rollback_to = other.can_rollback_to; | |
4334 | list<pg_log_entry_t>::const_reverse_iterator i = other.log.rbegin(); | |
4335 | assert(i != other.log.rend()); | |
4336 | while (i->version > to) { | |
4337 | ++i; | |
4338 | assert(i != other.log.rend()); | |
4339 | } | |
4340 | assert(i->version == to); | |
4341 | head = to; | |
4342 | for ( ; i != other.log.rend(); ++i) { | |
4343 | if (i->version <= from) { | |
4344 | tail = i->version; | |
4345 | break; | |
4346 | } | |
4347 | log.push_front(*i); | |
4348 | } | |
4349 | } | |
4350 | ||
4351 | void pg_log_t::copy_up_to(const pg_log_t &other, int max) | |
4352 | { | |
4353 | can_rollback_to = other.can_rollback_to; | |
4354 | int n = 0; | |
4355 | head = other.head; | |
4356 | tail = other.tail; | |
4357 | for (list<pg_log_entry_t>::const_reverse_iterator i = other.log.rbegin(); | |
4358 | i != other.log.rend(); | |
4359 | ++i) { | |
4360 | if (n++ >= max) { | |
4361 | tail = i->version; | |
4362 | break; | |
4363 | } | |
4364 | log.push_front(*i); | |
4365 | } | |
4366 | } | |
4367 | ||
c07f9fc5 | 4368 | ostream& pg_log_t::print(ostream& out) const |
7c673cae FG |
4369 | { |
4370 | out << *this << std::endl; | |
4371 | for (list<pg_log_entry_t>::const_iterator p = log.begin(); | |
4372 | p != log.end(); | |
c07f9fc5 | 4373 | ++p) |
7c673cae | 4374 | out << *p << std::endl; |
c07f9fc5 FG |
4375 | for (const auto& entry : dups) { |
4376 | out << " dup entry: " << entry << std::endl; | |
4377 | } | |
7c673cae FG |
4378 | return out; |
4379 | } | |
4380 | ||
4381 | // -- pg_missing_t -- | |
4382 | ||
4383 | ostream& operator<<(ostream& out, const pg_missing_item& i) | |
4384 | { | |
4385 | out << i.need; | |
4386 | if (i.have != eversion_t()) | |
4387 | out << "(" << i.have << ")"; | |
c07f9fc5 | 4388 | out << " flags = " << i.flag_str(); |
7c673cae FG |
4389 | return out; |
4390 | } | |
4391 | ||
4392 | // -- object_copy_cursor_t -- | |
4393 | ||
4394 | void object_copy_cursor_t::encode(bufferlist& bl) const | |
4395 | { | |
4396 | ENCODE_START(1, 1, bl); | |
4397 | ::encode(attr_complete, bl); | |
4398 | ::encode(data_offset, bl); | |
4399 | ::encode(data_complete, bl); | |
4400 | ::encode(omap_offset, bl); | |
4401 | ::encode(omap_complete, bl); | |
4402 | ENCODE_FINISH(bl); | |
4403 | } | |
4404 | ||
4405 | void object_copy_cursor_t::decode(bufferlist::iterator &bl) | |
4406 | { | |
4407 | DECODE_START(1, bl); | |
4408 | ::decode(attr_complete, bl); | |
4409 | ::decode(data_offset, bl); | |
4410 | ::decode(data_complete, bl); | |
4411 | ::decode(omap_offset, bl); | |
4412 | ::decode(omap_complete, bl); | |
4413 | DECODE_FINISH(bl); | |
4414 | } | |
4415 | ||
4416 | void object_copy_cursor_t::dump(Formatter *f) const | |
4417 | { | |
4418 | f->dump_unsigned("attr_complete", (int)attr_complete); | |
4419 | f->dump_unsigned("data_offset", data_offset); | |
4420 | f->dump_unsigned("data_complete", (int)data_complete); | |
4421 | f->dump_string("omap_offset", omap_offset); | |
4422 | f->dump_unsigned("omap_complete", (int)omap_complete); | |
4423 | } | |
4424 | ||
4425 | void object_copy_cursor_t::generate_test_instances(list<object_copy_cursor_t*>& o) | |
4426 | { | |
4427 | o.push_back(new object_copy_cursor_t); | |
4428 | o.push_back(new object_copy_cursor_t); | |
4429 | o.back()->attr_complete = true; | |
4430 | o.back()->data_offset = 123; | |
4431 | o.push_back(new object_copy_cursor_t); | |
4432 | o.back()->attr_complete = true; | |
4433 | o.back()->data_complete = true; | |
4434 | o.back()->omap_offset = "foo"; | |
4435 | o.push_back(new object_copy_cursor_t); | |
4436 | o.back()->attr_complete = true; | |
4437 | o.back()->data_complete = true; | |
4438 | o.back()->omap_complete = true; | |
4439 | } | |
4440 | ||
4441 | // -- object_copy_data_t -- | |
4442 | ||
4443 | void object_copy_data_t::encode(bufferlist& bl, uint64_t features) const | |
4444 | { | |
4445 | ENCODE_START(7, 5, bl); | |
4446 | ::encode(size, bl); | |
4447 | ::encode(mtime, bl); | |
4448 | ::encode(attrs, bl); | |
4449 | ::encode(data, bl); | |
4450 | ::encode(omap_data, bl); | |
4451 | ::encode(cursor, bl); | |
4452 | ::encode(omap_header, bl); | |
4453 | ::encode(snaps, bl); | |
4454 | ::encode(snap_seq, bl); | |
4455 | ::encode(flags, bl); | |
4456 | ::encode(data_digest, bl); | |
4457 | ::encode(omap_digest, bl); | |
4458 | ::encode(reqids, bl); | |
4459 | ::encode(truncate_seq, bl); | |
4460 | ::encode(truncate_size, bl); | |
4461 | ENCODE_FINISH(bl); | |
4462 | } | |
4463 | ||
4464 | void object_copy_data_t::decode(bufferlist::iterator& bl) | |
4465 | { | |
4466 | DECODE_START(7, bl); | |
4467 | if (struct_v < 5) { | |
4468 | // old | |
4469 | ::decode(size, bl); | |
4470 | ::decode(mtime, bl); | |
4471 | { | |
4472 | string category; | |
4473 | ::decode(category, bl); // no longer used | |
4474 | } | |
4475 | ::decode(attrs, bl); | |
4476 | ::decode(data, bl); | |
4477 | { | |
4478 | map<string,bufferlist> omap; | |
4479 | ::decode(omap, bl); | |
4480 | omap_data.clear(); | |
4481 | if (!omap.empty()) | |
4482 | ::encode(omap, omap_data); | |
4483 | } | |
4484 | ::decode(cursor, bl); | |
4485 | if (struct_v >= 2) | |
4486 | ::decode(omap_header, bl); | |
4487 | if (struct_v >= 3) { | |
4488 | ::decode(snaps, bl); | |
4489 | ::decode(snap_seq, bl); | |
4490 | } else { | |
4491 | snaps.clear(); | |
4492 | snap_seq = 0; | |
4493 | } | |
4494 | if (struct_v >= 4) { | |
4495 | ::decode(flags, bl); | |
4496 | ::decode(data_digest, bl); | |
4497 | ::decode(omap_digest, bl); | |
4498 | } | |
4499 | } else { | |
4500 | // current | |
4501 | ::decode(size, bl); | |
4502 | ::decode(mtime, bl); | |
4503 | ::decode(attrs, bl); | |
4504 | ::decode(data, bl); | |
4505 | ::decode(omap_data, bl); | |
4506 | ::decode(cursor, bl); | |
4507 | ::decode(omap_header, bl); | |
4508 | ::decode(snaps, bl); | |
4509 | ::decode(snap_seq, bl); | |
4510 | if (struct_v >= 4) { | |
4511 | ::decode(flags, bl); | |
4512 | ::decode(data_digest, bl); | |
4513 | ::decode(omap_digest, bl); | |
4514 | } | |
4515 | if (struct_v >= 6) { | |
4516 | ::decode(reqids, bl); | |
4517 | } | |
4518 | if (struct_v >= 7) { | |
4519 | ::decode(truncate_seq, bl); | |
4520 | ::decode(truncate_size, bl); | |
4521 | } | |
4522 | } | |
4523 | DECODE_FINISH(bl); | |
4524 | } | |
4525 | ||
4526 | void object_copy_data_t::generate_test_instances(list<object_copy_data_t*>& o) | |
4527 | { | |
4528 | o.push_back(new object_copy_data_t()); | |
4529 | ||
4530 | list<object_copy_cursor_t*> cursors; | |
4531 | object_copy_cursor_t::generate_test_instances(cursors); | |
4532 | list<object_copy_cursor_t*>::iterator ci = cursors.begin(); | |
4533 | o.back()->cursor = **(ci++); | |
4534 | ||
4535 | o.push_back(new object_copy_data_t()); | |
4536 | o.back()->cursor = **(ci++); | |
4537 | ||
4538 | o.push_back(new object_copy_data_t()); | |
4539 | o.back()->size = 1234; | |
4540 | o.back()->mtime.set_from_double(1234); | |
4541 | bufferptr bp("there", 5); | |
4542 | bufferlist bl; | |
4543 | bl.push_back(bp); | |
4544 | o.back()->attrs["hello"] = bl; | |
4545 | bufferptr bp2("not", 3); | |
4546 | bufferlist bl2; | |
4547 | bl2.push_back(bp2); | |
4548 | map<string,bufferlist> omap; | |
4549 | omap["why"] = bl2; | |
4550 | ::encode(omap, o.back()->omap_data); | |
4551 | bufferptr databp("iamsomedatatocontain", 20); | |
4552 | o.back()->data.push_back(databp); | |
4553 | o.back()->omap_header.append("this is an omap header"); | |
4554 | o.back()->snaps.push_back(123); | |
4555 | o.back()->reqids.push_back(make_pair(osd_reqid_t(), version_t())); | |
4556 | } | |
4557 | ||
4558 | void object_copy_data_t::dump(Formatter *f) const | |
4559 | { | |
4560 | f->open_object_section("cursor"); | |
4561 | cursor.dump(f); | |
4562 | f->close_section(); // cursor | |
4563 | f->dump_int("size", size); | |
4564 | f->dump_stream("mtime") << mtime; | |
4565 | /* we should really print out the attrs here, but bufferlist | |
4566 | const-correctness prevents that */ | |
4567 | f->dump_int("attrs_size", attrs.size()); | |
4568 | f->dump_int("flags", flags); | |
4569 | f->dump_unsigned("data_digest", data_digest); | |
4570 | f->dump_unsigned("omap_digest", omap_digest); | |
4571 | f->dump_int("omap_data_length", omap_data.length()); | |
4572 | f->dump_int("omap_header_length", omap_header.length()); | |
4573 | f->dump_int("data_length", data.length()); | |
4574 | f->open_array_section("snaps"); | |
4575 | for (vector<snapid_t>::const_iterator p = snaps.begin(); | |
4576 | p != snaps.end(); ++p) | |
4577 | f->dump_unsigned("snap", *p); | |
4578 | f->close_section(); | |
4579 | f->open_array_section("reqids"); | |
31f18b77 | 4580 | for (auto p = reqids.begin(); |
7c673cae FG |
4581 | p != reqids.end(); |
4582 | ++p) { | |
4583 | f->open_object_section("extra_reqid"); | |
4584 | f->dump_stream("reqid") << p->first; | |
4585 | f->dump_stream("user_version") << p->second; | |
4586 | f->close_section(); | |
4587 | } | |
4588 | f->close_section(); | |
4589 | } | |
4590 | ||
4591 | // -- pg_create_t -- | |
4592 | ||
4593 | void pg_create_t::encode(bufferlist &bl) const | |
4594 | { | |
4595 | ENCODE_START(1, 1, bl); | |
4596 | ::encode(created, bl); | |
4597 | ::encode(parent, bl); | |
4598 | ::encode(split_bits, bl); | |
4599 | ENCODE_FINISH(bl); | |
4600 | } | |
4601 | ||
4602 | void pg_create_t::decode(bufferlist::iterator &bl) | |
4603 | { | |
4604 | DECODE_START(1, bl); | |
4605 | ::decode(created, bl); | |
4606 | ::decode(parent, bl); | |
4607 | ::decode(split_bits, bl); | |
4608 | DECODE_FINISH(bl); | |
4609 | } | |
4610 | ||
4611 | void pg_create_t::dump(Formatter *f) const | |
4612 | { | |
4613 | f->dump_unsigned("created", created); | |
4614 | f->dump_stream("parent") << parent; | |
4615 | f->dump_int("split_bits", split_bits); | |
4616 | } | |
4617 | ||
4618 | void pg_create_t::generate_test_instances(list<pg_create_t*>& o) | |
4619 | { | |
4620 | o.push_back(new pg_create_t); | |
4621 | o.push_back(new pg_create_t(1, pg_t(3, 4, -1), 2)); | |
4622 | } | |
4623 | ||
4624 | ||
4625 | // -- pg_hit_set_info_t -- | |
4626 | ||
4627 | void pg_hit_set_info_t::encode(bufferlist& bl) const | |
4628 | { | |
4629 | ENCODE_START(2, 1, bl); | |
4630 | ::encode(begin, bl); | |
4631 | ::encode(end, bl); | |
4632 | ::encode(version, bl); | |
4633 | ::encode(using_gmt, bl); | |
4634 | ENCODE_FINISH(bl); | |
4635 | } | |
4636 | ||
4637 | void pg_hit_set_info_t::decode(bufferlist::iterator& p) | |
4638 | { | |
4639 | DECODE_START(2, p); | |
4640 | ::decode(begin, p); | |
4641 | ::decode(end, p); | |
4642 | ::decode(version, p); | |
4643 | if (struct_v >= 2) { | |
4644 | ::decode(using_gmt, p); | |
4645 | } else { | |
4646 | using_gmt = false; | |
4647 | } | |
4648 | DECODE_FINISH(p); | |
4649 | } | |
4650 | ||
4651 | void pg_hit_set_info_t::dump(Formatter *f) const | |
4652 | { | |
4653 | f->dump_stream("begin") << begin; | |
4654 | f->dump_stream("end") << end; | |
4655 | f->dump_stream("version") << version; | |
4656 | f->dump_stream("using_gmt") << using_gmt; | |
4657 | } | |
4658 | ||
4659 | void pg_hit_set_info_t::generate_test_instances(list<pg_hit_set_info_t*>& ls) | |
4660 | { | |
4661 | ls.push_back(new pg_hit_set_info_t); | |
4662 | ls.push_back(new pg_hit_set_info_t); | |
4663 | ls.back()->begin = utime_t(1, 2); | |
4664 | ls.back()->end = utime_t(3, 4); | |
4665 | } | |
4666 | ||
4667 | ||
4668 | // -- pg_hit_set_history_t -- | |
4669 | ||
4670 | void pg_hit_set_history_t::encode(bufferlist& bl) const | |
4671 | { | |
4672 | ENCODE_START(1, 1, bl); | |
4673 | ::encode(current_last_update, bl); | |
4674 | { | |
4675 | utime_t dummy_stamp; | |
4676 | ::encode(dummy_stamp, bl); | |
4677 | } | |
4678 | { | |
4679 | pg_hit_set_info_t dummy_info; | |
4680 | ::encode(dummy_info, bl); | |
4681 | } | |
4682 | ::encode(history, bl); | |
4683 | ENCODE_FINISH(bl); | |
4684 | } | |
4685 | ||
4686 | void pg_hit_set_history_t::decode(bufferlist::iterator& p) | |
4687 | { | |
4688 | DECODE_START(1, p); | |
4689 | ::decode(current_last_update, p); | |
4690 | { | |
4691 | utime_t dummy_stamp; | |
4692 | ::decode(dummy_stamp, p); | |
4693 | } | |
4694 | { | |
4695 | pg_hit_set_info_t dummy_info; | |
4696 | ::decode(dummy_info, p); | |
4697 | } | |
4698 | ::decode(history, p); | |
4699 | DECODE_FINISH(p); | |
4700 | } | |
4701 | ||
4702 | void pg_hit_set_history_t::dump(Formatter *f) const | |
4703 | { | |
4704 | f->dump_stream("current_last_update") << current_last_update; | |
4705 | f->open_array_section("history"); | |
4706 | for (list<pg_hit_set_info_t>::const_iterator p = history.begin(); | |
4707 | p != history.end(); ++p) { | |
4708 | f->open_object_section("info"); | |
4709 | p->dump(f); | |
4710 | f->close_section(); | |
4711 | } | |
4712 | f->close_section(); | |
4713 | } | |
4714 | ||
4715 | void pg_hit_set_history_t::generate_test_instances(list<pg_hit_set_history_t*>& ls) | |
4716 | { | |
4717 | ls.push_back(new pg_hit_set_history_t); | |
4718 | ls.push_back(new pg_hit_set_history_t); | |
4719 | ls.back()->current_last_update = eversion_t(1, 2); | |
4720 | ls.back()->history.push_back(pg_hit_set_info_t()); | |
4721 | } | |
4722 | ||
4723 | // -- osd_peer_stat_t -- | |
4724 | ||
4725 | void osd_peer_stat_t::encode(bufferlist& bl) const | |
4726 | { | |
4727 | ENCODE_START(1, 1, bl); | |
4728 | ::encode(stamp, bl); | |
4729 | ENCODE_FINISH(bl); | |
4730 | } | |
4731 | ||
4732 | void osd_peer_stat_t::decode(bufferlist::iterator& bl) | |
4733 | { | |
4734 | DECODE_START(1, bl); | |
4735 | ::decode(stamp, bl); | |
4736 | DECODE_FINISH(bl); | |
4737 | } | |
4738 | ||
4739 | void osd_peer_stat_t::dump(Formatter *f) const | |
4740 | { | |
4741 | f->dump_stream("stamp") << stamp; | |
4742 | } | |
4743 | ||
4744 | void osd_peer_stat_t::generate_test_instances(list<osd_peer_stat_t*>& o) | |
4745 | { | |
4746 | o.push_back(new osd_peer_stat_t); | |
4747 | o.push_back(new osd_peer_stat_t); | |
4748 | o.back()->stamp = utime_t(1, 2); | |
4749 | } | |
4750 | ||
4751 | ostream& operator<<(ostream& out, const osd_peer_stat_t &stat) | |
4752 | { | |
4753 | return out << "stat(" << stat.stamp << ")"; | |
4754 | } | |
4755 | ||
4756 | ||
4757 | // -- OSDSuperblock -- | |
4758 | ||
4759 | void OSDSuperblock::encode(bufferlist &bl) const | |
4760 | { | |
4761 | ENCODE_START(8, 5, bl); | |
4762 | ::encode(cluster_fsid, bl); | |
4763 | ::encode(whoami, bl); | |
4764 | ::encode(current_epoch, bl); | |
4765 | ::encode(oldest_map, bl); | |
4766 | ::encode(newest_map, bl); | |
4767 | ::encode(weight, bl); | |
4768 | compat_features.encode(bl); | |
4769 | ::encode(clean_thru, bl); | |
4770 | ::encode(mounted, bl); | |
4771 | ::encode(osd_fsid, bl); | |
4772 | ::encode((epoch_t)0, bl); // epoch_t last_epoch_marked_full | |
4773 | ::encode((uint32_t)0, bl); // map<int64_t,epoch_t> pool_last_epoch_marked_full | |
4774 | ENCODE_FINISH(bl); | |
4775 | } | |
4776 | ||
4777 | void OSDSuperblock::decode(bufferlist::iterator &bl) | |
4778 | { | |
4779 | DECODE_START_LEGACY_COMPAT_LEN(8, 5, 5, bl); | |
4780 | if (struct_v < 3) { | |
4781 | string magic; | |
4782 | ::decode(magic, bl); | |
4783 | } | |
4784 | ::decode(cluster_fsid, bl); | |
4785 | ::decode(whoami, bl); | |
4786 | ::decode(current_epoch, bl); | |
4787 | ::decode(oldest_map, bl); | |
4788 | ::decode(newest_map, bl); | |
4789 | ::decode(weight, bl); | |
4790 | if (struct_v >= 2) { | |
4791 | compat_features.decode(bl); | |
4792 | } else { //upgrade it! | |
4793 | compat_features.incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_BASE); | |
4794 | } | |
4795 | ::decode(clean_thru, bl); | |
4796 | ::decode(mounted, bl); | |
4797 | if (struct_v >= 4) | |
4798 | ::decode(osd_fsid, bl); | |
4799 | if (struct_v >= 6) { | |
4800 | epoch_t last_map_marked_full; | |
4801 | ::decode(last_map_marked_full, bl); | |
4802 | } | |
4803 | if (struct_v >= 7) { | |
4804 | map<int64_t,epoch_t> pool_last_map_marked_full; | |
4805 | ::decode(pool_last_map_marked_full, bl); | |
4806 | } | |
4807 | DECODE_FINISH(bl); | |
4808 | } | |
4809 | ||
4810 | void OSDSuperblock::dump(Formatter *f) const | |
4811 | { | |
4812 | f->dump_stream("cluster_fsid") << cluster_fsid; | |
4813 | f->dump_stream("osd_fsid") << osd_fsid; | |
4814 | f->dump_int("whoami", whoami); | |
4815 | f->dump_int("current_epoch", current_epoch); | |
4816 | f->dump_int("oldest_map", oldest_map); | |
4817 | f->dump_int("newest_map", newest_map); | |
4818 | f->dump_float("weight", weight); | |
4819 | f->open_object_section("compat"); | |
4820 | compat_features.dump(f); | |
4821 | f->close_section(); | |
4822 | f->dump_int("clean_thru", clean_thru); | |
4823 | f->dump_int("last_epoch_mounted", mounted); | |
4824 | } | |
4825 | ||
4826 | void OSDSuperblock::generate_test_instances(list<OSDSuperblock*>& o) | |
4827 | { | |
4828 | OSDSuperblock z; | |
4829 | o.push_back(new OSDSuperblock(z)); | |
4830 | memset(&z.cluster_fsid, 1, sizeof(z.cluster_fsid)); | |
4831 | memset(&z.osd_fsid, 2, sizeof(z.osd_fsid)); | |
4832 | z.whoami = 3; | |
4833 | z.current_epoch = 4; | |
4834 | z.oldest_map = 5; | |
4835 | z.newest_map = 9; | |
4836 | z.mounted = 8; | |
4837 | z.clean_thru = 7; | |
4838 | o.push_back(new OSDSuperblock(z)); | |
4839 | o.push_back(new OSDSuperblock(z)); | |
4840 | } | |
4841 | ||
4842 | // -- SnapSet -- | |
4843 | ||
4844 | void SnapSet::encode(bufferlist& bl) const | |
4845 | { | |
4846 | ENCODE_START(3, 2, bl); | |
4847 | ::encode(seq, bl); | |
4848 | ::encode(head_exists, bl); | |
4849 | ::encode(snaps, bl); | |
4850 | ::encode(clones, bl); | |
4851 | ::encode(clone_overlap, bl); | |
4852 | ::encode(clone_size, bl); | |
4853 | ::encode(clone_snaps, bl); | |
4854 | ENCODE_FINISH(bl); | |
4855 | } | |
4856 | ||
4857 | void SnapSet::decode(bufferlist::iterator& bl) | |
4858 | { | |
4859 | DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); | |
4860 | ::decode(seq, bl); | |
4861 | ::decode(head_exists, bl); | |
4862 | ::decode(snaps, bl); | |
4863 | ::decode(clones, bl); | |
4864 | ::decode(clone_overlap, bl); | |
4865 | ::decode(clone_size, bl); | |
4866 | if (struct_v >= 3) { | |
4867 | ::decode(clone_snaps, bl); | |
4868 | } else { | |
4869 | clone_snaps.clear(); | |
4870 | } | |
4871 | DECODE_FINISH(bl); | |
4872 | } | |
4873 | ||
4874 | void SnapSet::dump(Formatter *f) const | |
4875 | { | |
4876 | SnapContext sc(seq, snaps); | |
4877 | f->open_object_section("snap_context"); | |
4878 | sc.dump(f); | |
4879 | f->close_section(); | |
4880 | f->dump_int("head_exists", head_exists); | |
4881 | f->open_array_section("clones"); | |
4882 | for (vector<snapid_t>::const_iterator p = clones.begin(); p != clones.end(); ++p) { | |
4883 | f->open_object_section("clone"); | |
4884 | f->dump_unsigned("snap", *p); | |
94b18763 FG |
4885 | auto cs = clone_size.find(*p); |
4886 | if (cs != clone_size.end()) | |
4887 | f->dump_unsigned("size", cs->second); | |
4888 | else | |
4889 | f->dump_string("size", "????"); | |
4890 | auto co = clone_overlap.find(*p); | |
4891 | if (co != clone_overlap.end()) | |
4892 | f->dump_stream("overlap") << co->second; | |
4893 | else | |
4894 | f->dump_stream("overlap") << "????"; | |
7c673cae FG |
4895 | auto q = clone_snaps.find(*p); |
4896 | if (q != clone_snaps.end()) { | |
4897 | f->open_array_section("snaps"); | |
4898 | for (auto s : q->second) { | |
4899 | f->dump_unsigned("snap", s); | |
4900 | } | |
4901 | f->close_section(); | |
4902 | } | |
4903 | f->close_section(); | |
4904 | } | |
4905 | f->close_section(); | |
4906 | } | |
4907 | ||
4908 | void SnapSet::generate_test_instances(list<SnapSet*>& o) | |
4909 | { | |
4910 | o.push_back(new SnapSet); | |
4911 | o.push_back(new SnapSet); | |
4912 | o.back()->head_exists = true; | |
4913 | o.back()->seq = 123; | |
4914 | o.back()->snaps.push_back(123); | |
4915 | o.back()->snaps.push_back(12); | |
4916 | o.push_back(new SnapSet); | |
4917 | o.back()->head_exists = true; | |
4918 | o.back()->seq = 123; | |
4919 | o.back()->snaps.push_back(123); | |
4920 | o.back()->snaps.push_back(12); | |
4921 | o.back()->clones.push_back(12); | |
4922 | o.back()->clone_size[12] = 12345; | |
4923 | o.back()->clone_overlap[12]; | |
4924 | o.back()->clone_snaps[12] = {12, 10, 8}; | |
4925 | } | |
4926 | ||
4927 | ostream& operator<<(ostream& out, const SnapSet& cs) | |
4928 | { | |
4929 | if (cs.is_legacy()) { | |
4930 | out << cs.seq << "=" << cs.snaps << ":" | |
4931 | << cs.clones | |
4932 | << (cs.head_exists ? "+head":""); | |
4933 | if (!cs.clone_snaps.empty()) { | |
4934 | out << "+stray_clone_snaps=" << cs.clone_snaps; | |
4935 | } | |
4936 | return out; | |
4937 | } else { | |
4938 | return out << cs.seq << "=" << cs.snaps << ":" | |
4939 | << cs.clone_snaps; | |
4940 | } | |
4941 | } | |
4942 | ||
4943 | void SnapSet::from_snap_set(const librados::snap_set_t& ss, bool legacy) | |
4944 | { | |
4945 | // NOTE: our reconstruction of snaps (and the snapc) is not strictly | |
4946 | // correct: it will not include snaps that still logically exist | |
4947 | // but for which there was no clone that is defined. For all | |
4948 | // practical purposes this doesn't matter, since we only use that | |
4949 | // information to clone on the OSD, and we have already moved | |
4950 | // forward past that part of the object history. | |
4951 | ||
4952 | seq = ss.seq; | |
4953 | set<snapid_t> _snaps; | |
4954 | set<snapid_t> _clones; | |
4955 | head_exists = false; | |
4956 | for (vector<librados::clone_info_t>::const_iterator p = ss.clones.begin(); | |
4957 | p != ss.clones.end(); | |
4958 | ++p) { | |
4959 | if (p->cloneid == librados::SNAP_HEAD) { | |
4960 | head_exists = true; | |
4961 | } else { | |
4962 | _clones.insert(p->cloneid); | |
4963 | _snaps.insert(p->snaps.begin(), p->snaps.end()); | |
4964 | clone_size[p->cloneid] = p->size; | |
4965 | clone_overlap[p->cloneid]; // the entry must exist, even if it's empty. | |
4966 | for (vector<pair<uint64_t, uint64_t> >::const_iterator q = | |
4967 | p->overlap.begin(); q != p->overlap.end(); ++q) | |
4968 | clone_overlap[p->cloneid].insert(q->first, q->second); | |
4969 | if (!legacy) { | |
4970 | // p->snaps is ascending; clone_snaps is descending | |
4971 | vector<snapid_t>& v = clone_snaps[p->cloneid]; | |
4972 | for (auto q = p->snaps.rbegin(); q != p->snaps.rend(); ++q) { | |
4973 | v.push_back(*q); | |
4974 | } | |
4975 | } | |
4976 | } | |
4977 | } | |
4978 | ||
4979 | // ascending | |
4980 | clones.clear(); | |
4981 | clones.reserve(_clones.size()); | |
4982 | for (set<snapid_t>::iterator p = _clones.begin(); p != _clones.end(); ++p) | |
4983 | clones.push_back(*p); | |
4984 | ||
4985 | // descending | |
4986 | snaps.clear(); | |
4987 | snaps.reserve(_snaps.size()); | |
4988 | for (set<snapid_t>::reverse_iterator p = _snaps.rbegin(); | |
4989 | p != _snaps.rend(); ++p) | |
4990 | snaps.push_back(*p); | |
4991 | } | |
4992 | ||
4993 | uint64_t SnapSet::get_clone_bytes(snapid_t clone) const | |
4994 | { | |
4995 | assert(clone_size.count(clone)); | |
4996 | uint64_t size = clone_size.find(clone)->second; | |
4997 | assert(clone_overlap.count(clone)); | |
4998 | const interval_set<uint64_t> &overlap = clone_overlap.find(clone)->second; | |
4999 | for (interval_set<uint64_t>::const_iterator i = overlap.begin(); | |
5000 | i != overlap.end(); | |
5001 | ++i) { | |
5002 | assert(size >= i.get_len()); | |
5003 | size -= i.get_len(); | |
5004 | } | |
5005 | return size; | |
5006 | } | |
5007 | ||
5008 | void SnapSet::filter(const pg_pool_t &pinfo) | |
5009 | { | |
5010 | vector<snapid_t> oldsnaps; | |
5011 | oldsnaps.swap(snaps); | |
5012 | for (vector<snapid_t>::const_iterator i = oldsnaps.begin(); | |
5013 | i != oldsnaps.end(); | |
5014 | ++i) { | |
5015 | if (!pinfo.is_removed_snap(*i)) | |
5016 | snaps.push_back(*i); | |
5017 | } | |
5018 | } | |
5019 | ||
5020 | SnapSet SnapSet::get_filtered(const pg_pool_t &pinfo) const | |
5021 | { | |
5022 | SnapSet ss = *this; | |
5023 | ss.filter(pinfo); | |
5024 | return ss; | |
5025 | } | |
5026 | ||
5027 | // -- watch_info_t -- | |
5028 | ||
5029 | void watch_info_t::encode(bufferlist& bl, uint64_t features) const | |
5030 | { | |
5031 | ENCODE_START(4, 3, bl); | |
5032 | ::encode(cookie, bl); | |
5033 | ::encode(timeout_seconds, bl); | |
5034 | ::encode(addr, bl, features); | |
5035 | ENCODE_FINISH(bl); | |
5036 | } | |
5037 | ||
5038 | void watch_info_t::decode(bufferlist::iterator& bl) | |
5039 | { | |
5040 | DECODE_START_LEGACY_COMPAT_LEN(4, 3, 3, bl); | |
5041 | ::decode(cookie, bl); | |
5042 | if (struct_v < 2) { | |
5043 | uint64_t ver; | |
5044 | ::decode(ver, bl); | |
5045 | } | |
5046 | ::decode(timeout_seconds, bl); | |
5047 | if (struct_v >= 4) { | |
5048 | ::decode(addr, bl); | |
5049 | } | |
5050 | DECODE_FINISH(bl); | |
5051 | } | |
5052 | ||
5053 | void watch_info_t::dump(Formatter *f) const | |
5054 | { | |
5055 | f->dump_unsigned("cookie", cookie); | |
5056 | f->dump_unsigned("timeout_seconds", timeout_seconds); | |
5057 | f->open_object_section("addr"); | |
5058 | addr.dump(f); | |
5059 | f->close_section(); | |
5060 | } | |
5061 | ||
5062 | void watch_info_t::generate_test_instances(list<watch_info_t*>& o) | |
5063 | { | |
5064 | o.push_back(new watch_info_t); | |
5065 | o.push_back(new watch_info_t); | |
5066 | o.back()->cookie = 123; | |
5067 | o.back()->timeout_seconds = 99; | |
5068 | entity_addr_t ea; | |
5069 | ea.set_type(entity_addr_t::TYPE_LEGACY); | |
5070 | ea.set_nonce(1); | |
5071 | ea.set_family(AF_INET); | |
5072 | ea.set_in4_quad(0, 127); | |
5073 | ea.set_in4_quad(1, 0); | |
5074 | ea.set_in4_quad(2, 1); | |
5075 | ea.set_in4_quad(3, 2); | |
5076 | ea.set_port(2); | |
5077 | o.back()->addr = ea; | |
5078 | } | |
5079 | ||
31f18b77 FG |
5080 | // -- object_manifest_t -- |
5081 | ||
5082 | void object_manifest_t::encode(bufferlist& bl) const | |
5083 | { | |
5084 | ENCODE_START(1, 1, bl); | |
5085 | ::encode(type, bl); | |
5086 | switch (type) { | |
5087 | case TYPE_NONE: break; | |
5088 | case TYPE_REDIRECT: | |
5089 | ::encode(redirect_target, bl); | |
5090 | break; | |
5091 | default: | |
5092 | ceph_abort(); | |
5093 | } | |
5094 | ENCODE_FINISH(bl); | |
5095 | } | |
5096 | ||
5097 | void object_manifest_t::decode(bufferlist::iterator& bl) | |
5098 | { | |
5099 | DECODE_START(1, bl); | |
5100 | ::decode(type, bl); | |
5101 | switch (type) { | |
5102 | case TYPE_NONE: break; | |
5103 | case TYPE_REDIRECT: | |
5104 | ::decode(redirect_target, bl); | |
5105 | break; | |
5106 | default: | |
5107 | ceph_abort(); | |
5108 | } | |
5109 | DECODE_FINISH(bl); | |
5110 | } | |
5111 | ||
5112 | void object_manifest_t::dump(Formatter *f) const | |
5113 | { | |
5114 | f->dump_unsigned("type", type); | |
5115 | f->open_object_section("redirect_target"); | |
5116 | redirect_target.dump(f); | |
5117 | f->close_section(); | |
5118 | } | |
5119 | ||
5120 | void object_manifest_t::generate_test_instances(list<object_manifest_t*>& o) | |
5121 | { | |
5122 | o.push_back(new object_manifest_t()); | |
5123 | o.back()->type = TYPE_REDIRECT; | |
5124 | } | |
5125 | ||
5126 | ostream& operator<<(ostream& out, const object_manifest_t& om) | |
5127 | { | |
5128 | return out << "type:" << om.type << " redirect_target:" << om.redirect_target; | |
5129 | } | |
7c673cae FG |
5130 | |
5131 | // -- object_info_t -- | |
5132 | ||
5133 | void object_info_t::copy_user_bits(const object_info_t& other) | |
5134 | { | |
5135 | // these bits are copied from head->clone. | |
5136 | size = other.size; | |
5137 | mtime = other.mtime; | |
5138 | local_mtime = other.local_mtime; | |
5139 | last_reqid = other.last_reqid; | |
5140 | truncate_seq = other.truncate_seq; | |
5141 | truncate_size = other.truncate_size; | |
5142 | flags = other.flags; | |
5143 | user_version = other.user_version; | |
5144 | data_digest = other.data_digest; | |
5145 | omap_digest = other.omap_digest; | |
5146 | } | |
5147 | ||
5148 | ps_t object_info_t::legacy_object_locator_to_ps(const object_t &oid, | |
5149 | const object_locator_t &loc) { | |
5150 | ps_t ps; | |
5151 | if (loc.key.length()) | |
5152 | // Hack, we don't have the osd map, so we don't really know the hash... | |
5153 | ps = ceph_str_hash(CEPH_STR_HASH_RJENKINS, loc.key.c_str(), | |
5154 | loc.key.length()); | |
5155 | else | |
5156 | ps = ceph_str_hash(CEPH_STR_HASH_RJENKINS, oid.name.c_str(), | |
5157 | oid.name.length()); | |
5158 | return ps; | |
5159 | } | |
5160 | ||
5161 | void object_info_t::encode(bufferlist& bl, uint64_t features) const | |
5162 | { | |
5163 | object_locator_t myoloc(soid); | |
5164 | map<entity_name_t, watch_info_t> old_watchers; | |
5165 | for (map<pair<uint64_t, entity_name_t>, watch_info_t>::const_iterator i = | |
5166 | watchers.begin(); | |
5167 | i != watchers.end(); | |
5168 | ++i) { | |
5169 | old_watchers.insert(make_pair(i->first.second, i->second)); | |
5170 | } | |
31f18b77 | 5171 | ENCODE_START(17, 8, bl); |
7c673cae FG |
5172 | ::encode(soid, bl); |
5173 | ::encode(myoloc, bl); //Retained for compatibility | |
5174 | ::encode((__u32)0, bl); // was category, no longer used | |
5175 | ::encode(version, bl); | |
5176 | ::encode(prior_version, bl); | |
5177 | ::encode(last_reqid, bl); | |
5178 | ::encode(size, bl); | |
5179 | ::encode(mtime, bl); | |
5180 | if (soid.snap == CEPH_NOSNAP) | |
5181 | ::encode(osd_reqid_t(), bl); // used to be wrlock_by | |
5182 | else | |
5183 | ::encode(legacy_snaps, bl); | |
5184 | ::encode(truncate_seq, bl); | |
5185 | ::encode(truncate_size, bl); | |
5186 | ::encode(is_lost(), bl); | |
5187 | ::encode(old_watchers, bl, features); | |
5188 | /* shenanigans to avoid breaking backwards compatibility in the disk format. | |
5189 | * When we can, switch this out for simply putting the version_t on disk. */ | |
5190 | eversion_t user_eversion(0, user_version); | |
5191 | ::encode(user_eversion, bl); | |
5192 | ::encode(test_flag(FLAG_USES_TMAP), bl); | |
5193 | ::encode(watchers, bl, features); | |
5194 | __u32 _flags = flags; | |
5195 | ::encode(_flags, bl); | |
5196 | ::encode(local_mtime, bl); | |
5197 | ::encode(data_digest, bl); | |
5198 | ::encode(omap_digest, bl); | |
5199 | ::encode(expected_object_size, bl); | |
5200 | ::encode(expected_write_size, bl); | |
5201 | ::encode(alloc_hint_flags, bl); | |
31f18b77 FG |
5202 | if (has_manifest()) { |
5203 | ::encode(manifest, bl); | |
5204 | } | |
7c673cae FG |
5205 | ENCODE_FINISH(bl); |
5206 | } | |
5207 | ||
5208 | void object_info_t::decode(bufferlist::iterator& bl) | |
5209 | { | |
5210 | object_locator_t myoloc; | |
31f18b77 | 5211 | DECODE_START_LEGACY_COMPAT_LEN(17, 8, 8, bl); |
7c673cae FG |
5212 | map<entity_name_t, watch_info_t> old_watchers; |
5213 | ::decode(soid, bl); | |
5214 | ::decode(myoloc, bl); | |
5215 | { | |
5216 | string category; | |
5217 | ::decode(category, bl); // no longer used | |
5218 | } | |
5219 | ::decode(version, bl); | |
5220 | ::decode(prior_version, bl); | |
5221 | ::decode(last_reqid, bl); | |
5222 | ::decode(size, bl); | |
5223 | ::decode(mtime, bl); | |
5224 | if (soid.snap == CEPH_NOSNAP) { | |
5225 | osd_reqid_t wrlock_by; | |
5226 | ::decode(wrlock_by, bl); | |
5227 | } else { | |
5228 | ::decode(legacy_snaps, bl); | |
5229 | } | |
5230 | ::decode(truncate_seq, bl); | |
5231 | ::decode(truncate_size, bl); | |
5232 | ||
5233 | // if this is struct_v >= 13, we will overwrite this | |
5234 | // below since this field is just here for backwards | |
5235 | // compatibility | |
5236 | __u8 lo; | |
5237 | ::decode(lo, bl); | |
5238 | flags = (flag_t)lo; | |
5239 | ||
5240 | ::decode(old_watchers, bl); | |
5241 | eversion_t user_eversion; | |
5242 | ::decode(user_eversion, bl); | |
5243 | user_version = user_eversion.version; | |
5244 | ||
5245 | if (struct_v >= 9) { | |
5246 | bool uses_tmap = false; | |
5247 | ::decode(uses_tmap, bl); | |
5248 | if (uses_tmap) | |
5249 | set_flag(FLAG_USES_TMAP); | |
5250 | } else { | |
5251 | set_flag(FLAG_USES_TMAP); | |
5252 | } | |
5253 | if (struct_v < 10) | |
5254 | soid.pool = myoloc.pool; | |
5255 | if (struct_v >= 11) { | |
5256 | ::decode(watchers, bl); | |
5257 | } else { | |
5258 | for (map<entity_name_t, watch_info_t>::iterator i = old_watchers.begin(); | |
5259 | i != old_watchers.end(); | |
5260 | ++i) { | |
5261 | watchers.insert( | |
5262 | make_pair( | |
5263 | make_pair(i->second.cookie, i->first), i->second)); | |
5264 | } | |
5265 | } | |
5266 | if (struct_v >= 13) { | |
5267 | __u32 _flags; | |
5268 | ::decode(_flags, bl); | |
5269 | flags = (flag_t)_flags; | |
5270 | } | |
5271 | if (struct_v >= 14) { | |
5272 | ::decode(local_mtime, bl); | |
5273 | } else { | |
5274 | local_mtime = utime_t(); | |
5275 | } | |
5276 | if (struct_v >= 15) { | |
5277 | ::decode(data_digest, bl); | |
5278 | ::decode(omap_digest, bl); | |
5279 | } else { | |
5280 | data_digest = omap_digest = -1; | |
5281 | clear_flag(FLAG_DATA_DIGEST); | |
5282 | clear_flag(FLAG_OMAP_DIGEST); | |
5283 | } | |
5284 | if (struct_v >= 16) { | |
5285 | ::decode(expected_object_size, bl); | |
5286 | ::decode(expected_write_size, bl); | |
5287 | ::decode(alloc_hint_flags, bl); | |
5288 | } else { | |
5289 | expected_object_size = 0; | |
5290 | expected_write_size = 0; | |
5291 | alloc_hint_flags = 0; | |
5292 | } | |
31f18b77 FG |
5293 | if (struct_v >= 17) { |
5294 | if (has_manifest()) { | |
5295 | ::decode(manifest, bl); | |
5296 | } | |
5297 | } | |
7c673cae FG |
5298 | DECODE_FINISH(bl); |
5299 | } | |
5300 | ||
5301 | void object_info_t::dump(Formatter *f) const | |
5302 | { | |
5303 | f->open_object_section("oid"); | |
5304 | soid.dump(f); | |
5305 | f->close_section(); | |
5306 | f->dump_stream("version") << version; | |
5307 | f->dump_stream("prior_version") << prior_version; | |
5308 | f->dump_stream("last_reqid") << last_reqid; | |
5309 | f->dump_unsigned("user_version", user_version); | |
5310 | f->dump_unsigned("size", size); | |
5311 | f->dump_stream("mtime") << mtime; | |
5312 | f->dump_stream("local_mtime") << local_mtime; | |
5313 | f->dump_unsigned("lost", (int)is_lost()); | |
94b18763 FG |
5314 | vector<string> sv = get_flag_vector(flags); |
5315 | f->open_array_section("flags"); | |
5316 | for (auto str: sv) | |
5317 | f->dump_string("flags", str); | |
5318 | f->close_section(); | |
7c673cae FG |
5319 | f->open_array_section("legacy_snaps"); |
5320 | for (auto s : legacy_snaps) { | |
5321 | f->dump_unsigned("snap", s); | |
5322 | } | |
5323 | f->close_section(); | |
5324 | f->dump_unsigned("truncate_seq", truncate_seq); | |
5325 | f->dump_unsigned("truncate_size", truncate_size); | |
94b18763 FG |
5326 | f->dump_format("data_digest", "0x%08x", data_digest); |
5327 | f->dump_format("omap_digest", "0x%08x", omap_digest); | |
7c673cae FG |
5328 | f->dump_unsigned("expected_object_size", expected_object_size); |
5329 | f->dump_unsigned("expected_write_size", expected_write_size); | |
5330 | f->dump_unsigned("alloc_hint_flags", alloc_hint_flags); | |
31f18b77 | 5331 | f->dump_object("manifest", manifest); |
7c673cae FG |
5332 | f->open_object_section("watchers"); |
5333 | for (map<pair<uint64_t, entity_name_t>,watch_info_t>::const_iterator p = | |
5334 | watchers.begin(); p != watchers.end(); ++p) { | |
5335 | stringstream ss; | |
5336 | ss << p->first.second; | |
5337 | f->open_object_section(ss.str().c_str()); | |
5338 | p->second.dump(f); | |
5339 | f->close_section(); | |
5340 | } | |
5341 | f->close_section(); | |
5342 | } | |
5343 | ||
5344 | void object_info_t::generate_test_instances(list<object_info_t*>& o) | |
5345 | { | |
5346 | o.push_back(new object_info_t()); | |
5347 | ||
5348 | // fixme | |
5349 | } | |
5350 | ||
5351 | ||
5352 | ostream& operator<<(ostream& out, const object_info_t& oi) | |
5353 | { | |
5354 | out << oi.soid << "(" << oi.version | |
5355 | << " " << oi.last_reqid; | |
5356 | if (oi.soid.snap != CEPH_NOSNAP && !oi.legacy_snaps.empty()) | |
5357 | out << " " << oi.legacy_snaps; | |
5358 | if (oi.flags) | |
5359 | out << " " << oi.get_flag_string(); | |
5360 | out << " s " << oi.size; | |
5361 | out << " uv " << oi.user_version; | |
5362 | if (oi.is_data_digest()) | |
5363 | out << " dd " << std::hex << oi.data_digest << std::dec; | |
5364 | if (oi.is_omap_digest()) | |
5365 | out << " od " << std::hex << oi.omap_digest << std::dec; | |
5366 | out << " alloc_hint [" << oi.expected_object_size | |
5367 | << " " << oi.expected_write_size | |
5368 | << " " << oi.alloc_hint_flags << "]"; | |
31f18b77 FG |
5369 | if (oi.has_manifest()) |
5370 | out << " " << oi.manifest; | |
7c673cae FG |
5371 | |
5372 | out << ")"; | |
5373 | return out; | |
5374 | } | |
5375 | ||
5376 | // -- ObjectRecovery -- | |
5377 | void ObjectRecoveryProgress::encode(bufferlist &bl) const | |
5378 | { | |
5379 | ENCODE_START(1, 1, bl); | |
5380 | ::encode(first, bl); | |
5381 | ::encode(data_complete, bl); | |
5382 | ::encode(data_recovered_to, bl); | |
5383 | ::encode(omap_recovered_to, bl); | |
5384 | ::encode(omap_complete, bl); | |
5385 | ENCODE_FINISH(bl); | |
5386 | } | |
5387 | ||
5388 | void ObjectRecoveryProgress::decode(bufferlist::iterator &bl) | |
5389 | { | |
5390 | DECODE_START(1, bl); | |
5391 | ::decode(first, bl); | |
5392 | ::decode(data_complete, bl); | |
5393 | ::decode(data_recovered_to, bl); | |
5394 | ::decode(omap_recovered_to, bl); | |
5395 | ::decode(omap_complete, bl); | |
5396 | DECODE_FINISH(bl); | |
5397 | } | |
5398 | ||
5399 | ostream &operator<<(ostream &out, const ObjectRecoveryProgress &prog) | |
5400 | { | |
5401 | return prog.print(out); | |
5402 | } | |
5403 | ||
5404 | void ObjectRecoveryProgress::generate_test_instances( | |
5405 | list<ObjectRecoveryProgress*>& o) | |
5406 | { | |
5407 | o.push_back(new ObjectRecoveryProgress); | |
5408 | o.back()->first = false; | |
5409 | o.back()->data_complete = true; | |
5410 | o.back()->omap_complete = true; | |
5411 | o.back()->data_recovered_to = 100; | |
5412 | ||
5413 | o.push_back(new ObjectRecoveryProgress); | |
5414 | o.back()->first = true; | |
5415 | o.back()->data_complete = false; | |
5416 | o.back()->omap_complete = false; | |
5417 | o.back()->data_recovered_to = 0; | |
5418 | } | |
5419 | ||
5420 | ostream &ObjectRecoveryProgress::print(ostream &out) const | |
5421 | { | |
5422 | return out << "ObjectRecoveryProgress(" | |
5423 | << ( first ? "" : "!" ) << "first, " | |
5424 | << "data_recovered_to:" << data_recovered_to | |
5425 | << ", data_complete:" << ( data_complete ? "true" : "false" ) | |
5426 | << ", omap_recovered_to:" << omap_recovered_to | |
5427 | << ", omap_complete:" << ( omap_complete ? "true" : "false" ) | |
224ce89b | 5428 | << ", error:" << ( error ? "true" : "false" ) |
7c673cae FG |
5429 | << ")"; |
5430 | } | |
5431 | ||
5432 | void ObjectRecoveryProgress::dump(Formatter *f) const | |
5433 | { | |
5434 | f->dump_int("first?", first); | |
5435 | f->dump_int("data_complete?", data_complete); | |
5436 | f->dump_unsigned("data_recovered_to", data_recovered_to); | |
5437 | f->dump_int("omap_complete?", omap_complete); | |
5438 | f->dump_string("omap_recovered_to", omap_recovered_to); | |
5439 | } | |
5440 | ||
5441 | void ObjectRecoveryInfo::encode(bufferlist &bl, uint64_t features) const | |
5442 | { | |
5443 | ENCODE_START(2, 1, bl); | |
5444 | ::encode(soid, bl); | |
5445 | ::encode(version, bl); | |
5446 | ::encode(size, bl); | |
5447 | ::encode(oi, bl, features); | |
5448 | ::encode(ss, bl); | |
5449 | ::encode(copy_subset, bl); | |
5450 | ::encode(clone_subset, bl); | |
5451 | ENCODE_FINISH(bl); | |
5452 | } | |
5453 | ||
5454 | void ObjectRecoveryInfo::decode(bufferlist::iterator &bl, | |
5455 | int64_t pool) | |
5456 | { | |
5457 | DECODE_START(2, bl); | |
5458 | ::decode(soid, bl); | |
5459 | ::decode(version, bl); | |
5460 | ::decode(size, bl); | |
5461 | ::decode(oi, bl); | |
5462 | ::decode(ss, bl); | |
5463 | ::decode(copy_subset, bl); | |
5464 | ::decode(clone_subset, bl); | |
5465 | DECODE_FINISH(bl); | |
5466 | ||
5467 | if (struct_v < 2) { | |
5468 | if (!soid.is_max() && soid.pool == -1) | |
5469 | soid.pool = pool; | |
5470 | map<hobject_t, interval_set<uint64_t>> tmp; | |
5471 | tmp.swap(clone_subset); | |
5472 | for (map<hobject_t, interval_set<uint64_t>>::iterator i = tmp.begin(); | |
5473 | i != tmp.end(); | |
5474 | ++i) { | |
5475 | hobject_t first(i->first); | |
5476 | if (!first.is_max() && first.pool == -1) | |
5477 | first.pool = pool; | |
5478 | clone_subset[first].swap(i->second); | |
5479 | } | |
5480 | } | |
5481 | } | |
5482 | ||
5483 | void ObjectRecoveryInfo::generate_test_instances( | |
5484 | list<ObjectRecoveryInfo*>& o) | |
5485 | { | |
5486 | o.push_back(new ObjectRecoveryInfo); | |
5487 | o.back()->soid = hobject_t(sobject_t("key", CEPH_NOSNAP)); | |
5488 | o.back()->version = eversion_t(0,0); | |
5489 | o.back()->size = 100; | |
5490 | } | |
5491 | ||
5492 | ||
5493 | void ObjectRecoveryInfo::dump(Formatter *f) const | |
5494 | { | |
5495 | f->dump_stream("object") << soid; | |
5496 | f->dump_stream("at_version") << version; | |
5497 | f->dump_stream("size") << size; | |
5498 | { | |
5499 | f->open_object_section("object_info"); | |
5500 | oi.dump(f); | |
5501 | f->close_section(); | |
5502 | } | |
5503 | { | |
5504 | f->open_object_section("snapset"); | |
5505 | ss.dump(f); | |
5506 | f->close_section(); | |
5507 | } | |
5508 | f->dump_stream("copy_subset") << copy_subset; | |
5509 | f->dump_stream("clone_subset") << clone_subset; | |
5510 | } | |
5511 | ||
5512 | ostream& operator<<(ostream& out, const ObjectRecoveryInfo &inf) | |
5513 | { | |
5514 | return inf.print(out); | |
5515 | } | |
5516 | ||
5517 | ostream &ObjectRecoveryInfo::print(ostream &out) const | |
5518 | { | |
5519 | return out << "ObjectRecoveryInfo(" | |
5520 | << soid << "@" << version | |
5521 | << ", size: " << size | |
5522 | << ", copy_subset: " << copy_subset | |
5523 | << ", clone_subset: " << clone_subset | |
5524 | << ", snapset: " << ss | |
5525 | << ")"; | |
5526 | } | |
5527 | ||
5528 | // -- PushReplyOp -- | |
5529 | void PushReplyOp::generate_test_instances(list<PushReplyOp*> &o) | |
5530 | { | |
5531 | o.push_back(new PushReplyOp); | |
5532 | o.push_back(new PushReplyOp); | |
5533 | o.back()->soid = hobject_t(sobject_t("asdf", 2)); | |
5534 | o.push_back(new PushReplyOp); | |
5535 | o.back()->soid = hobject_t(sobject_t("asdf", CEPH_NOSNAP)); | |
5536 | } | |
5537 | ||
5538 | void PushReplyOp::encode(bufferlist &bl) const | |
5539 | { | |
5540 | ENCODE_START(1, 1, bl); | |
5541 | ::encode(soid, bl); | |
5542 | ENCODE_FINISH(bl); | |
5543 | } | |
5544 | ||
5545 | void PushReplyOp::decode(bufferlist::iterator &bl) | |
5546 | { | |
5547 | DECODE_START(1, bl); | |
5548 | ::decode(soid, bl); | |
5549 | DECODE_FINISH(bl); | |
5550 | } | |
5551 | ||
5552 | void PushReplyOp::dump(Formatter *f) const | |
5553 | { | |
5554 | f->dump_stream("soid") << soid; | |
5555 | } | |
5556 | ||
5557 | ostream &PushReplyOp::print(ostream &out) const | |
5558 | { | |
5559 | return out | |
5560 | << "PushReplyOp(" << soid | |
5561 | << ")"; | |
5562 | } | |
5563 | ||
5564 | ostream& operator<<(ostream& out, const PushReplyOp &op) | |
5565 | { | |
5566 | return op.print(out); | |
5567 | } | |
5568 | ||
5569 | uint64_t PushReplyOp::cost(CephContext *cct) const | |
5570 | { | |
5571 | ||
5572 | return cct->_conf->osd_push_per_object_cost + | |
5573 | cct->_conf->osd_recovery_max_chunk; | |
5574 | } | |
5575 | ||
5576 | // -- PullOp -- | |
5577 | void PullOp::generate_test_instances(list<PullOp*> &o) | |
5578 | { | |
5579 | o.push_back(new PullOp); | |
5580 | o.push_back(new PullOp); | |
5581 | o.back()->soid = hobject_t(sobject_t("asdf", 2)); | |
5582 | o.back()->recovery_info.version = eversion_t(3, 10); | |
5583 | o.push_back(new PullOp); | |
5584 | o.back()->soid = hobject_t(sobject_t("asdf", CEPH_NOSNAP)); | |
5585 | o.back()->recovery_info.version = eversion_t(0, 0); | |
5586 | } | |
5587 | ||
5588 | void PullOp::encode(bufferlist &bl, uint64_t features) const | |
5589 | { | |
5590 | ENCODE_START(1, 1, bl); | |
5591 | ::encode(soid, bl); | |
5592 | ::encode(recovery_info, bl, features); | |
5593 | ::encode(recovery_progress, bl); | |
5594 | ENCODE_FINISH(bl); | |
5595 | } | |
5596 | ||
5597 | void PullOp::decode(bufferlist::iterator &bl) | |
5598 | { | |
5599 | DECODE_START(1, bl); | |
5600 | ::decode(soid, bl); | |
5601 | ::decode(recovery_info, bl); | |
5602 | ::decode(recovery_progress, bl); | |
5603 | DECODE_FINISH(bl); | |
5604 | } | |
5605 | ||
5606 | void PullOp::dump(Formatter *f) const | |
5607 | { | |
5608 | f->dump_stream("soid") << soid; | |
5609 | { | |
5610 | f->open_object_section("recovery_info"); | |
5611 | recovery_info.dump(f); | |
5612 | f->close_section(); | |
5613 | } | |
5614 | { | |
5615 | f->open_object_section("recovery_progress"); | |
5616 | recovery_progress.dump(f); | |
5617 | f->close_section(); | |
5618 | } | |
5619 | } | |
5620 | ||
5621 | ostream &PullOp::print(ostream &out) const | |
5622 | { | |
5623 | return out | |
5624 | << "PullOp(" << soid | |
5625 | << ", recovery_info: " << recovery_info | |
5626 | << ", recovery_progress: " << recovery_progress | |
5627 | << ")"; | |
5628 | } | |
5629 | ||
5630 | ostream& operator<<(ostream& out, const PullOp &op) | |
5631 | { | |
5632 | return op.print(out); | |
5633 | } | |
5634 | ||
5635 | uint64_t PullOp::cost(CephContext *cct) const | |
5636 | { | |
5637 | return cct->_conf->osd_push_per_object_cost + | |
5638 | cct->_conf->osd_recovery_max_chunk; | |
5639 | } | |
5640 | ||
5641 | // -- PushOp -- | |
5642 | void PushOp::generate_test_instances(list<PushOp*> &o) | |
5643 | { | |
5644 | o.push_back(new PushOp); | |
5645 | o.push_back(new PushOp); | |
5646 | o.back()->soid = hobject_t(sobject_t("asdf", 2)); | |
5647 | o.back()->version = eversion_t(3, 10); | |
5648 | o.push_back(new PushOp); | |
5649 | o.back()->soid = hobject_t(sobject_t("asdf", CEPH_NOSNAP)); | |
5650 | o.back()->version = eversion_t(0, 0); | |
5651 | } | |
5652 | ||
5653 | void PushOp::encode(bufferlist &bl, uint64_t features) const | |
5654 | { | |
5655 | ENCODE_START(1, 1, bl); | |
5656 | ::encode(soid, bl); | |
5657 | ::encode(version, bl); | |
5658 | ::encode(data, bl); | |
5659 | ::encode(data_included, bl); | |
5660 | ::encode(omap_header, bl); | |
5661 | ::encode(omap_entries, bl); | |
5662 | ::encode(attrset, bl); | |
5663 | ::encode(recovery_info, bl, features); | |
5664 | ::encode(after_progress, bl); | |
5665 | ::encode(before_progress, bl); | |
5666 | ENCODE_FINISH(bl); | |
5667 | } | |
5668 | ||
5669 | void PushOp::decode(bufferlist::iterator &bl) | |
5670 | { | |
5671 | DECODE_START(1, bl); | |
5672 | ::decode(soid, bl); | |
5673 | ::decode(version, bl); | |
5674 | ::decode(data, bl); | |
5675 | ::decode(data_included, bl); | |
5676 | ::decode(omap_header, bl); | |
5677 | ::decode(omap_entries, bl); | |
5678 | ::decode(attrset, bl); | |
5679 | ::decode(recovery_info, bl); | |
5680 | ::decode(after_progress, bl); | |
5681 | ::decode(before_progress, bl); | |
5682 | DECODE_FINISH(bl); | |
5683 | } | |
5684 | ||
5685 | void PushOp::dump(Formatter *f) const | |
5686 | { | |
5687 | f->dump_stream("soid") << soid; | |
5688 | f->dump_stream("version") << version; | |
5689 | f->dump_int("data_len", data.length()); | |
5690 | f->dump_stream("data_included") << data_included; | |
5691 | f->dump_int("omap_header_len", omap_header.length()); | |
5692 | f->dump_int("omap_entries_len", omap_entries.size()); | |
5693 | f->dump_int("attrset_len", attrset.size()); | |
5694 | { | |
5695 | f->open_object_section("recovery_info"); | |
5696 | recovery_info.dump(f); | |
5697 | f->close_section(); | |
5698 | } | |
5699 | { | |
5700 | f->open_object_section("after_progress"); | |
5701 | after_progress.dump(f); | |
5702 | f->close_section(); | |
5703 | } | |
5704 | { | |
5705 | f->open_object_section("before_progress"); | |
5706 | before_progress.dump(f); | |
5707 | f->close_section(); | |
5708 | } | |
5709 | } | |
5710 | ||
5711 | ostream &PushOp::print(ostream &out) const | |
5712 | { | |
5713 | return out | |
5714 | << "PushOp(" << soid | |
5715 | << ", version: " << version | |
5716 | << ", data_included: " << data_included | |
5717 | << ", data_size: " << data.length() | |
5718 | << ", omap_header_size: " << omap_header.length() | |
5719 | << ", omap_entries_size: " << omap_entries.size() | |
5720 | << ", attrset_size: " << attrset.size() | |
5721 | << ", recovery_info: " << recovery_info | |
5722 | << ", after_progress: " << after_progress | |
5723 | << ", before_progress: " << before_progress | |
5724 | << ")"; | |
5725 | } | |
5726 | ||
5727 | ostream& operator<<(ostream& out, const PushOp &op) | |
5728 | { | |
5729 | return op.print(out); | |
5730 | } | |
5731 | ||
5732 | uint64_t PushOp::cost(CephContext *cct) const | |
5733 | { | |
5734 | uint64_t cost = data_included.size(); | |
5735 | for (map<string, bufferlist>::const_iterator i = | |
5736 | omap_entries.begin(); | |
5737 | i != omap_entries.end(); | |
5738 | ++i) { | |
5739 | cost += i->second.length(); | |
5740 | } | |
5741 | cost += cct->_conf->osd_push_per_object_cost; | |
5742 | return cost; | |
5743 | } | |
5744 | ||
5745 | // -- ScrubMap -- | |
5746 | ||
5747 | void ScrubMap::merge_incr(const ScrubMap &l) | |
5748 | { | |
5749 | assert(valid_through == l.incr_since); | |
5750 | valid_through = l.valid_through; | |
5751 | ||
5752 | for (map<hobject_t,object>::const_iterator p = l.objects.begin(); | |
5753 | p != l.objects.end(); | |
5754 | ++p){ | |
5755 | if (p->second.negative) { | |
5756 | map<hobject_t,object>::iterator q = objects.find(p->first); | |
5757 | if (q != objects.end()) { | |
5758 | objects.erase(q); | |
5759 | } | |
5760 | } else { | |
5761 | objects[p->first] = p->second; | |
5762 | } | |
5763 | } | |
5764 | } | |
5765 | ||
5766 | void ScrubMap::encode(bufferlist& bl) const | |
5767 | { | |
5768 | ENCODE_START(3, 2, bl); | |
5769 | ::encode(objects, bl); | |
5770 | ::encode((__u32)0, bl); // used to be attrs; now deprecated | |
5771 | bufferlist old_logbl; // not used | |
5772 | ::encode(old_logbl, bl); | |
5773 | ::encode(valid_through, bl); | |
5774 | ::encode(incr_since, bl); | |
5775 | ENCODE_FINISH(bl); | |
5776 | } | |
5777 | ||
5778 | void ScrubMap::decode(bufferlist::iterator& bl, int64_t pool) | |
5779 | { | |
5780 | DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); | |
5781 | ::decode(objects, bl); | |
5782 | { | |
5783 | map<string,string> attrs; // deprecated | |
5784 | ::decode(attrs, bl); | |
5785 | } | |
5786 | bufferlist old_logbl; // not used | |
5787 | ::decode(old_logbl, bl); | |
5788 | ::decode(valid_through, bl); | |
5789 | ::decode(incr_since, bl); | |
5790 | DECODE_FINISH(bl); | |
5791 | ||
5792 | // handle hobject_t upgrade | |
5793 | if (struct_v < 3) { | |
5794 | map<hobject_t, object> tmp; | |
5795 | tmp.swap(objects); | |
5796 | for (map<hobject_t, object>::iterator i = tmp.begin(); | |
5797 | i != tmp.end(); | |
5798 | ++i) { | |
5799 | hobject_t first(i->first); | |
5800 | if (!first.is_max() && first.pool == -1) | |
5801 | first.pool = pool; | |
5802 | objects[first] = i->second; | |
5803 | } | |
5804 | } | |
5805 | } | |
5806 | ||
5807 | void ScrubMap::dump(Formatter *f) const | |
5808 | { | |
5809 | f->dump_stream("valid_through") << valid_through; | |
5810 | f->dump_stream("incremental_since") << incr_since; | |
5811 | f->open_array_section("objects"); | |
5812 | for (map<hobject_t,object>::const_iterator p = objects.begin(); p != objects.end(); ++p) { | |
5813 | f->open_object_section("object"); | |
5814 | f->dump_string("name", p->first.oid.name); | |
5815 | f->dump_unsigned("hash", p->first.get_hash()); | |
5816 | f->dump_string("key", p->first.get_key()); | |
5817 | f->dump_int("snapid", p->first.snap); | |
5818 | p->second.dump(f); | |
5819 | f->close_section(); | |
5820 | } | |
5821 | f->close_section(); | |
5822 | } | |
5823 | ||
5824 | void ScrubMap::generate_test_instances(list<ScrubMap*>& o) | |
5825 | { | |
5826 | o.push_back(new ScrubMap); | |
5827 | o.push_back(new ScrubMap); | |
5828 | o.back()->valid_through = eversion_t(1, 2); | |
5829 | o.back()->incr_since = eversion_t(3, 4); | |
5830 | list<object*> obj; | |
5831 | object::generate_test_instances(obj); | |
5832 | o.back()->objects[hobject_t(object_t("foo"), "fookey", 123, 456, 0, "")] = *obj.back(); | |
5833 | obj.pop_back(); | |
5834 | o.back()->objects[hobject_t(object_t("bar"), string(), 123, 456, 0, "")] = *obj.back(); | |
5835 | } | |
5836 | ||
5837 | // -- ScrubMap::object -- | |
5838 | ||
5839 | void ScrubMap::object::encode(bufferlist& bl) const | |
5840 | { | |
5841 | bool compat_read_error = read_error || ec_hash_mismatch || ec_size_mismatch; | |
5842 | ENCODE_START(8, 7, bl); | |
5843 | ::encode(size, bl); | |
5844 | ::encode(negative, bl); | |
5845 | ::encode(attrs, bl); | |
5846 | ::encode(digest, bl); | |
5847 | ::encode(digest_present, bl); | |
5848 | ::encode((uint32_t)0, bl); // obsolete nlinks | |
5849 | ::encode((uint32_t)0, bl); // snapcolls | |
5850 | ::encode(omap_digest, bl); | |
5851 | ::encode(omap_digest_present, bl); | |
5852 | ::encode(compat_read_error, bl); | |
5853 | ::encode(stat_error, bl); | |
5854 | ::encode(read_error, bl); | |
5855 | ::encode(ec_hash_mismatch, bl); | |
5856 | ::encode(ec_size_mismatch, bl); | |
5857 | ENCODE_FINISH(bl); | |
5858 | } | |
5859 | ||
5860 | void ScrubMap::object::decode(bufferlist::iterator& bl) | |
5861 | { | |
5862 | DECODE_START(8, bl); | |
5863 | ::decode(size, bl); | |
5864 | bool tmp, compat_read_error = false; | |
5865 | ::decode(tmp, bl); | |
5866 | negative = tmp; | |
5867 | ::decode(attrs, bl); | |
5868 | ::decode(digest, bl); | |
5869 | ::decode(tmp, bl); | |
5870 | digest_present = tmp; | |
5871 | { | |
5872 | uint32_t nlinks; | |
5873 | ::decode(nlinks, bl); | |
5874 | set<snapid_t> snapcolls; | |
5875 | ::decode(snapcolls, bl); | |
5876 | } | |
5877 | ::decode(omap_digest, bl); | |
5878 | ::decode(tmp, bl); | |
5879 | omap_digest_present = tmp; | |
5880 | ::decode(compat_read_error, bl); | |
5881 | ::decode(tmp, bl); | |
5882 | stat_error = tmp; | |
5883 | if (struct_v >= 8) { | |
5884 | ::decode(tmp, bl); | |
5885 | read_error = tmp; | |
5886 | ::decode(tmp, bl); | |
5887 | ec_hash_mismatch = tmp; | |
5888 | ::decode(tmp, bl); | |
5889 | ec_size_mismatch = tmp; | |
5890 | } | |
5891 | // If older encoder found a read_error, set read_error | |
5892 | if (compat_read_error && !read_error && !ec_hash_mismatch && !ec_size_mismatch) | |
5893 | read_error = true; | |
5894 | DECODE_FINISH(bl); | |
5895 | } | |
5896 | ||
5897 | void ScrubMap::object::dump(Formatter *f) const | |
5898 | { | |
5899 | f->dump_int("size", size); | |
5900 | f->dump_int("negative", negative); | |
5901 | f->open_array_section("attrs"); | |
5902 | for (map<string,bufferptr>::const_iterator p = attrs.begin(); p != attrs.end(); ++p) { | |
5903 | f->open_object_section("attr"); | |
5904 | f->dump_string("name", p->first); | |
5905 | f->dump_int("length", p->second.length()); | |
5906 | f->close_section(); | |
5907 | } | |
5908 | f->close_section(); | |
5909 | } | |
5910 | ||
5911 | void ScrubMap::object::generate_test_instances(list<object*>& o) | |
5912 | { | |
5913 | o.push_back(new object); | |
5914 | o.push_back(new object); | |
5915 | o.back()->negative = true; | |
5916 | o.push_back(new object); | |
5917 | o.back()->size = 123; | |
5918 | o.back()->attrs["foo"] = buffer::copy("foo", 3); | |
5919 | o.back()->attrs["bar"] = buffer::copy("barval", 6); | |
5920 | } | |
5921 | ||
5922 | // -- OSDOp -- | |
5923 | ||
5924 | ostream& operator<<(ostream& out, const OSDOp& op) | |
5925 | { | |
5926 | out << ceph_osd_op_name(op.op.op); | |
5927 | if (ceph_osd_op_type_data(op.op.op)) { | |
5928 | // data extent | |
5929 | switch (op.op.op) { | |
5930 | case CEPH_OSD_OP_ASSERT_VER: | |
5931 | out << " v" << op.op.assert_ver.ver; | |
5932 | break; | |
5933 | case CEPH_OSD_OP_TRUNCATE: | |
5934 | out << " " << op.op.extent.offset; | |
5935 | break; | |
5936 | case CEPH_OSD_OP_MASKTRUNC: | |
5937 | case CEPH_OSD_OP_TRIMTRUNC: | |
5938 | out << " " << op.op.extent.truncate_seq << "@" | |
5939 | << (int64_t)op.op.extent.truncate_size; | |
5940 | break; | |
5941 | case CEPH_OSD_OP_ROLLBACK: | |
5942 | out << " " << snapid_t(op.op.snap.snapid); | |
5943 | break; | |
5944 | case CEPH_OSD_OP_WATCH: | |
5945 | out << " " << ceph_osd_watch_op_name(op.op.watch.op) | |
5946 | << " cookie " << op.op.watch.cookie; | |
5947 | if (op.op.watch.gen) | |
5948 | out << " gen " << op.op.watch.gen; | |
5949 | break; | |
5950 | case CEPH_OSD_OP_NOTIFY: | |
5951 | case CEPH_OSD_OP_NOTIFY_ACK: | |
5952 | out << " cookie " << op.op.notify.cookie; | |
5953 | break; | |
5954 | case CEPH_OSD_OP_COPY_GET: | |
5955 | out << " max " << op.op.copy_get.max; | |
5956 | break; | |
5957 | case CEPH_OSD_OP_COPY_FROM: | |
5958 | out << " ver " << op.op.copy_from.src_version; | |
5959 | break; | |
5960 | case CEPH_OSD_OP_SETALLOCHINT: | |
5961 | out << " object_size " << op.op.alloc_hint.expected_object_size | |
5962 | << " write_size " << op.op.alloc_hint.expected_write_size; | |
5963 | break; | |
5964 | case CEPH_OSD_OP_READ: | |
5965 | case CEPH_OSD_OP_SPARSE_READ: | |
5966 | case CEPH_OSD_OP_SYNC_READ: | |
5967 | case CEPH_OSD_OP_WRITE: | |
5968 | case CEPH_OSD_OP_WRITEFULL: | |
5969 | case CEPH_OSD_OP_ZERO: | |
5970 | case CEPH_OSD_OP_APPEND: | |
5971 | case CEPH_OSD_OP_MAPEXT: | |
5972 | out << " " << op.op.extent.offset << "~" << op.op.extent.length; | |
5973 | if (op.op.extent.truncate_seq) | |
5974 | out << " [" << op.op.extent.truncate_seq << "@" | |
5975 | << (int64_t)op.op.extent.truncate_size << "]"; | |
5976 | if (op.op.flags) | |
5977 | out << " [" << ceph_osd_op_flag_string(op.op.flags) << "]"; | |
5978 | default: | |
5979 | // don't show any arg info | |
5980 | break; | |
5981 | } | |
5982 | } else if (ceph_osd_op_type_attr(op.op.op)) { | |
5983 | // xattr name | |
5984 | if (op.op.xattr.name_len && op.indata.length()) { | |
5985 | out << " "; | |
5986 | op.indata.write(0, op.op.xattr.name_len, out); | |
5987 | } | |
5988 | if (op.op.xattr.value_len) | |
5989 | out << " (" << op.op.xattr.value_len << ")"; | |
5990 | if (op.op.op == CEPH_OSD_OP_CMPXATTR) | |
5991 | out << " op " << (int)op.op.xattr.cmp_op | |
5992 | << " mode " << (int)op.op.xattr.cmp_mode; | |
5993 | } else if (ceph_osd_op_type_exec(op.op.op)) { | |
5994 | // class.method | |
5995 | if (op.op.cls.class_len && op.indata.length()) { | |
5996 | out << " "; | |
5997 | op.indata.write(0, op.op.cls.class_len, out); | |
5998 | out << "."; | |
5999 | op.indata.write(op.op.cls.class_len, op.op.cls.method_len, out); | |
6000 | } | |
6001 | } else if (ceph_osd_op_type_pg(op.op.op)) { | |
6002 | switch (op.op.op) { | |
6003 | case CEPH_OSD_OP_PGLS: | |
6004 | case CEPH_OSD_OP_PGLS_FILTER: | |
6005 | case CEPH_OSD_OP_PGNLS: | |
6006 | case CEPH_OSD_OP_PGNLS_FILTER: | |
6007 | out << " start_epoch " << op.op.pgls.start_epoch; | |
6008 | break; | |
6009 | case CEPH_OSD_OP_PG_HITSET_LS: | |
6010 | break; | |
6011 | case CEPH_OSD_OP_PG_HITSET_GET: | |
6012 | out << " " << utime_t(op.op.hit_set_get.stamp); | |
6013 | break; | |
6014 | case CEPH_OSD_OP_SCRUBLS: | |
6015 | break; | |
6016 | } | |
6017 | } | |
6018 | return out; | |
6019 | } | |
6020 | ||
6021 | ||
6022 | void OSDOp::split_osd_op_vector_in_data(vector<OSDOp>& ops, bufferlist& in) | |
6023 | { | |
6024 | bufferlist::iterator datap = in.begin(); | |
6025 | for (unsigned i = 0; i < ops.size(); i++) { | |
6026 | if (ops[i].op.payload_len) { | |
6027 | datap.copy(ops[i].op.payload_len, ops[i].indata); | |
6028 | } | |
6029 | } | |
6030 | } | |
6031 | ||
6032 | void OSDOp::merge_osd_op_vector_in_data(vector<OSDOp>& ops, bufferlist& out) | |
6033 | { | |
6034 | for (unsigned i = 0; i < ops.size(); i++) { | |
6035 | if (ops[i].indata.length()) { | |
6036 | ops[i].op.payload_len = ops[i].indata.length(); | |
6037 | out.append(ops[i].indata); | |
6038 | } | |
6039 | } | |
6040 | } | |
6041 | ||
6042 | void OSDOp::split_osd_op_vector_out_data(vector<OSDOp>& ops, bufferlist& in) | |
6043 | { | |
6044 | bufferlist::iterator datap = in.begin(); | |
6045 | for (unsigned i = 0; i < ops.size(); i++) { | |
6046 | if (ops[i].op.payload_len) { | |
6047 | datap.copy(ops[i].op.payload_len, ops[i].outdata); | |
6048 | } | |
6049 | } | |
6050 | } | |
6051 | ||
6052 | void OSDOp::merge_osd_op_vector_out_data(vector<OSDOp>& ops, bufferlist& out) | |
6053 | { | |
6054 | for (unsigned i = 0; i < ops.size(); i++) { | |
6055 | if (ops[i].outdata.length()) { | |
6056 | ops[i].op.payload_len = ops[i].outdata.length(); | |
6057 | out.append(ops[i].outdata); | |
6058 | } | |
6059 | } | |
6060 | } | |
6061 | ||
6062 | bool store_statfs_t::operator==(const store_statfs_t& other) const | |
6063 | { | |
6064 | return total == other.total | |
6065 | && available == other.available | |
6066 | && allocated == other.allocated | |
6067 | && stored == other.stored | |
6068 | && compressed == other.compressed | |
6069 | && compressed_allocated == other.compressed_allocated | |
6070 | && compressed_original == other.compressed_original; | |
6071 | } | |
6072 | ||
6073 | void store_statfs_t::dump(Formatter *f) const | |
6074 | { | |
6075 | f->dump_int("total", total); | |
6076 | f->dump_int("available", available); | |
6077 | f->dump_int("allocated", allocated); | |
6078 | f->dump_int("stored", stored); | |
6079 | f->dump_int("compressed", compressed); | |
6080 | f->dump_int("compressed_allocated", compressed_allocated); | |
6081 | f->dump_int("compressed_original", compressed_original); | |
6082 | } | |
6083 | ||
6084 | ostream& operator<<(ostream& out, const store_statfs_t &s) | |
6085 | { | |
6086 | out << std::hex | |
6087 | << "store_statfs(0x" << s.available | |
6088 | << "/0x" << s.total | |
6089 | << ", stored 0x" << s.stored | |
6090 | << "/0x" << s.allocated | |
6091 | << ", compress 0x" << s.compressed | |
6092 | << "/0x" << s.compressed_allocated | |
6093 | << "/0x" << s.compressed_original | |
6094 | << std::dec | |
6095 | << ")"; | |
6096 | return out; | |
6097 | } | |
224ce89b WB |
6098 | |
6099 | void OSDOp::clear_data(vector<OSDOp>& ops) | |
6100 | { | |
6101 | for (unsigned i = 0; i < ops.size(); i++) { | |
6102 | OSDOp& op = ops[i]; | |
6103 | op.outdata.clear(); | |
6104 | if (ceph_osd_op_type_attr(op.op.op) && | |
6105 | op.op.xattr.name_len && | |
6106 | op.indata.length() >= op.op.xattr.name_len) { | |
6107 | bufferptr bp(op.op.xattr.name_len); | |
6108 | bufferlist bl; | |
6109 | bl.append(bp); | |
6110 | bl.copy_in(0, op.op.xattr.name_len, op.indata); | |
6111 | op.indata.claim(bl); | |
6112 | } else if (ceph_osd_op_type_exec(op.op.op) && | |
6113 | op.op.cls.class_len && | |
6114 | op.indata.length() > | |
6115 | (op.op.cls.class_len + op.op.cls.method_len)) { | |
6116 | __u8 len = op.op.cls.class_len + op.op.cls.method_len; | |
6117 | bufferptr bp(len); | |
6118 | bufferlist bl; | |
6119 | bl.append(bp); | |
6120 | bl.copy_in(0, len, op.indata); | |
6121 | op.indata.claim(bl); | |
6122 | } else { | |
6123 | op.indata.clear(); | |
6124 | } | |
6125 | } | |
6126 | } |