]> git.proxmox.com Git - ceph.git/blob - ceph/src/osd/osd_types.h
9d9a142b0f3ff27b1fc795f4d00bbcf18d618529
[ceph.git] / ceph / src / osd / osd_types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 * 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 #ifndef CEPH_OSD_TYPES_H
19 #define CEPH_OSD_TYPES_H
20
21 #include <sstream>
22 #include <stdio.h>
23 #include <memory>
24 #include <boost/scoped_ptr.hpp>
25 #include <boost/optional/optional_io.hpp>
26 #include <boost/variant.hpp>
27
28 #include "include/rados/rados_types.hpp"
29 #include "include/mempool.h"
30
31 #include "msg/msg_types.h"
32 #include "include/types.h"
33 #include "include/utime.h"
34 #include "include/CompatSet.h"
35 #include "common/histogram.h"
36 #include "include/interval_set.h"
37 #include "include/inline_memory.h"
38 #include "common/Formatter.h"
39 #include "common/bloom_filter.hpp"
40 #include "common/hobject.h"
41 #include "common/snap_types.h"
42 #include "HitSet.h"
43 #include "Watch.h"
44 #include "include/cmp.h"
45 #include "librados/ListObjectImpl.h"
46 #include "compressor/Compressor.h"
47 #include <atomic>
48
49 #define CEPH_OSD_ONDISK_MAGIC "ceph osd volume v026"
50
51 #define CEPH_OSD_FEATURE_INCOMPAT_BASE CompatSet::Feature(1, "initial feature set(~v.18)")
52 #define CEPH_OSD_FEATURE_INCOMPAT_PGINFO CompatSet::Feature(2, "pginfo object")
53 #define CEPH_OSD_FEATURE_INCOMPAT_OLOC CompatSet::Feature(3, "object locator")
54 #define CEPH_OSD_FEATURE_INCOMPAT_LEC CompatSet::Feature(4, "last_epoch_clean")
55 #define CEPH_OSD_FEATURE_INCOMPAT_CATEGORIES CompatSet::Feature(5, "categories")
56 #define CEPH_OSD_FEATURE_INCOMPAT_HOBJECTPOOL CompatSet::Feature(6, "hobjectpool")
57 #define CEPH_OSD_FEATURE_INCOMPAT_BIGINFO CompatSet::Feature(7, "biginfo")
58 #define CEPH_OSD_FEATURE_INCOMPAT_LEVELDBINFO CompatSet::Feature(8, "leveldbinfo")
59 #define CEPH_OSD_FEATURE_INCOMPAT_LEVELDBLOG CompatSet::Feature(9, "leveldblog")
60 #define CEPH_OSD_FEATURE_INCOMPAT_SNAPMAPPER CompatSet::Feature(10, "snapmapper")
61 #define CEPH_OSD_FEATURE_INCOMPAT_SHARDS CompatSet::Feature(11, "sharded objects")
62 #define CEPH_OSD_FEATURE_INCOMPAT_HINTS CompatSet::Feature(12, "transaction hints")
63 #define CEPH_OSD_FEATURE_INCOMPAT_PGMETA CompatSet::Feature(13, "pg meta object")
64 #define CEPH_OSD_FEATURE_INCOMPAT_MISSING CompatSet::Feature(14, "explicit missing set")
65 #define CEPH_OSD_FEATURE_INCOMPAT_FASTINFO CompatSet::Feature(15, "fastinfo pg attr")
66 #define CEPH_OSD_FEATURE_INCOMPAT_RECOVERY_DELETES CompatSet::Feature(16, "deletes in missing set")
67
68
69 /// min recovery priority for MBackfillReserve
70 #define OSD_RECOVERY_PRIORITY_MIN 0
71
72 /// base backfill priority for MBackfillReserve
73 #define OSD_BACKFILL_PRIORITY_BASE 100
74
75 /// base backfill priority for MBackfillReserve (degraded PG)
76 #define OSD_BACKFILL_DEGRADED_PRIORITY_BASE 140
77
78 /// base recovery priority for MBackfillReserve
79 #define OSD_RECOVERY_PRIORITY_BASE 180
80
81 /// base backfill priority for MBackfillReserve (inactive PG)
82 #define OSD_BACKFILL_INACTIVE_PRIORITY_BASE 220
83
84 /// max manually/automatically set recovery priority for MBackfillReserve
85 #define OSD_RECOVERY_PRIORITY_MAX 254
86
87 /// max recovery priority for MBackfillReserve, only when forced manually
88 #define OSD_RECOVERY_PRIORITY_FORCED 255
89
90
91 typedef hobject_t collection_list_handle_t;
92
93 /// convert a single CPEH_OSD_FLAG_* to a string
94 const char *ceph_osd_flag_name(unsigned flag);
95 /// convert a single CEPH_OSD_OF_FLAG_* to a string
96 const char *ceph_osd_op_flag_name(unsigned flag);
97
98 /// convert CEPH_OSD_FLAG_* op flags to a string
99 string ceph_osd_flag_string(unsigned flags);
100 /// conver CEPH_OSD_OP_FLAG_* op flags to a string
101 string ceph_osd_op_flag_string(unsigned flags);
102 /// conver CEPH_OSD_ALLOC_HINT_FLAG_* op flags to a string
103 string ceph_osd_alloc_hint_flag_string(unsigned flags);
104
105
106 /**
107 * osd request identifier
108 *
109 * caller name + incarnation# + tid to unique identify this request.
110 */
111 struct osd_reqid_t {
112 entity_name_t name; // who
113 ceph_tid_t tid;
114 int32_t inc; // incarnation
115
116 osd_reqid_t()
117 : tid(0), inc(0)
118 {}
119 osd_reqid_t(const osd_reqid_t& other)
120 : name(other.name), tid(other.tid), inc(other.inc)
121 {}
122 osd_reqid_t(const entity_name_t& a, int i, ceph_tid_t t)
123 : name(a), tid(t), inc(i)
124 {}
125
126 DENC(osd_reqid_t, v, p) {
127 DENC_START(2, 2, p);
128 denc(v.name, p);
129 denc(v.tid, p);
130 denc(v.inc, p);
131 DENC_FINISH(p);
132 }
133 void dump(Formatter *f) const;
134 static void generate_test_instances(list<osd_reqid_t*>& o);
135 };
136 WRITE_CLASS_DENC(osd_reqid_t)
137
138
139
140 struct pg_shard_t {
141 int32_t osd;
142 shard_id_t shard;
143 pg_shard_t() : osd(-1), shard(shard_id_t::NO_SHARD) {}
144 explicit pg_shard_t(int osd) : osd(osd), shard(shard_id_t::NO_SHARD) {}
145 pg_shard_t(int osd, shard_id_t shard) : osd(osd), shard(shard) {}
146 bool is_undefined() const {
147 return osd == -1;
148 }
149 void encode(bufferlist &bl) const;
150 void decode(bufferlist::iterator &bl);
151 void dump(Formatter *f) const {
152 f->dump_unsigned("osd", osd);
153 if (shard != shard_id_t::NO_SHARD) {
154 f->dump_unsigned("shard", shard);
155 }
156 }
157 };
158 WRITE_CLASS_ENCODER(pg_shard_t)
159 WRITE_EQ_OPERATORS_2(pg_shard_t, osd, shard)
160 WRITE_CMP_OPERATORS_2(pg_shard_t, osd, shard)
161 ostream &operator<<(ostream &lhs, const pg_shard_t &rhs);
162
163 class IsPGRecoverablePredicate {
164 public:
165 /**
166 * have encodes the shards available
167 */
168 virtual bool operator()(const set<pg_shard_t> &have) const = 0;
169 virtual ~IsPGRecoverablePredicate() {}
170 };
171
172 class IsPGReadablePredicate {
173 public:
174 /**
175 * have encodes the shards available
176 */
177 virtual bool operator()(const set<pg_shard_t> &have) const = 0;
178 virtual ~IsPGReadablePredicate() {}
179 };
180
181 inline ostream& operator<<(ostream& out, const osd_reqid_t& r) {
182 return out << r.name << "." << r.inc << ":" << r.tid;
183 }
184
185 inline bool operator==(const osd_reqid_t& l, const osd_reqid_t& r) {
186 return (l.name == r.name) && (l.inc == r.inc) && (l.tid == r.tid);
187 }
188 inline bool operator!=(const osd_reqid_t& l, const osd_reqid_t& r) {
189 return (l.name != r.name) || (l.inc != r.inc) || (l.tid != r.tid);
190 }
191 inline bool operator<(const osd_reqid_t& l, const osd_reqid_t& r) {
192 return (l.name < r.name) || (l.inc < r.inc) ||
193 (l.name == r.name && l.inc == r.inc && l.tid < r.tid);
194 }
195 inline bool operator<=(const osd_reqid_t& l, const osd_reqid_t& r) {
196 return (l.name < r.name) || (l.inc < r.inc) ||
197 (l.name == r.name && l.inc == r.inc && l.tid <= r.tid);
198 }
199 inline bool operator>(const osd_reqid_t& l, const osd_reqid_t& r) { return !(l <= r); }
200 inline bool operator>=(const osd_reqid_t& l, const osd_reqid_t& r) { return !(l < r); }
201
202 namespace std {
203 template<> struct hash<osd_reqid_t> {
204 size_t operator()(const osd_reqid_t &r) const {
205 static hash<uint64_t> H;
206 return H(r.name.num() ^ r.tid ^ r.inc);
207 }
208 };
209 } // namespace std
210
211
212 // -----
213
214 // a locator constrains the placement of an object. mainly, which pool
215 // does it go in.
216 struct object_locator_t {
217 // You specify either the hash or the key -- not both
218 int64_t pool; ///< pool id
219 string key; ///< key string (if non-empty)
220 string nspace; ///< namespace
221 int64_t hash; ///< hash position (if >= 0)
222
223 explicit object_locator_t()
224 : pool(-1), hash(-1) {}
225 explicit object_locator_t(int64_t po)
226 : pool(po), hash(-1) {}
227 explicit object_locator_t(int64_t po, int64_t ps)
228 : pool(po), hash(ps) {}
229 explicit object_locator_t(int64_t po, string ns)
230 : pool(po), nspace(ns), hash(-1) {}
231 explicit object_locator_t(int64_t po, string ns, int64_t ps)
232 : pool(po), nspace(ns), hash(ps) {}
233 explicit object_locator_t(int64_t po, string ns, string s)
234 : pool(po), key(s), nspace(ns), hash(-1) {}
235 explicit object_locator_t(const hobject_t& soid)
236 : pool(soid.pool), key(soid.get_key()), nspace(soid.nspace), hash(-1) {}
237
238 int64_t get_pool() const {
239 return pool;
240 }
241
242 void clear() {
243 pool = -1;
244 key = "";
245 nspace = "";
246 hash = -1;
247 }
248
249 bool empty() const {
250 return pool == -1;
251 }
252
253 void encode(bufferlist& bl) const;
254 void decode(bufferlist::iterator& p);
255 void dump(Formatter *f) const;
256 static void generate_test_instances(list<object_locator_t*>& o);
257 };
258 WRITE_CLASS_ENCODER(object_locator_t)
259
260 inline bool operator==(const object_locator_t& l, const object_locator_t& r) {
261 return l.pool == r.pool && l.key == r.key && l.nspace == r.nspace && l.hash == r.hash;
262 }
263 inline bool operator!=(const object_locator_t& l, const object_locator_t& r) {
264 return !(l == r);
265 }
266
267 inline ostream& operator<<(ostream& out, const object_locator_t& loc)
268 {
269 out << "@" << loc.pool;
270 if (loc.nspace.length())
271 out << ";" << loc.nspace;
272 if (loc.key.length())
273 out << ":" << loc.key;
274 return out;
275 }
276
277 struct request_redirect_t {
278 private:
279 object_locator_t redirect_locator; ///< this is authoritative
280 string redirect_object; ///< If non-empty, the request goes to this object name
281 bufferlist osd_instructions; ///< a bufferlist for the OSDs, passed but not interpreted by clients
282
283 friend ostream& operator<<(ostream& out, const request_redirect_t& redir);
284 public:
285
286 request_redirect_t() {}
287 explicit request_redirect_t(const object_locator_t& orig, int64_t rpool) :
288 redirect_locator(orig) { redirect_locator.pool = rpool; }
289 explicit request_redirect_t(const object_locator_t& rloc) :
290 redirect_locator(rloc) {}
291 explicit request_redirect_t(const object_locator_t& orig,
292 const string& robj) :
293 redirect_locator(orig), redirect_object(robj) {}
294
295 void set_instructions(const bufferlist& bl) { osd_instructions = bl; }
296 const bufferlist& get_instructions() { return osd_instructions; }
297
298 bool empty() const { return redirect_locator.empty() &&
299 redirect_object.empty(); }
300
301 void combine_with_locator(object_locator_t& orig, string& obj) const {
302 orig = redirect_locator;
303 if (!redirect_object.empty())
304 obj = redirect_object;
305 }
306
307 void encode(bufferlist& bl) const;
308 void decode(bufferlist::iterator& bl);
309 void dump(Formatter *f) const;
310 static void generate_test_instances(list<request_redirect_t*>& o);
311 };
312 WRITE_CLASS_ENCODER(request_redirect_t)
313
314 inline ostream& operator<<(ostream& out, const request_redirect_t& redir) {
315 out << "object " << redir.redirect_object << ", locator{" << redir.redirect_locator << "}";
316 return out;
317 }
318
319 // Internal OSD op flags - set by the OSD based on the op types
320 enum {
321 CEPH_OSD_RMW_FLAG_READ = (1 << 1),
322 CEPH_OSD_RMW_FLAG_WRITE = (1 << 2),
323 CEPH_OSD_RMW_FLAG_CLASS_READ = (1 << 3),
324 CEPH_OSD_RMW_FLAG_CLASS_WRITE = (1 << 4),
325 CEPH_OSD_RMW_FLAG_PGOP = (1 << 5),
326 CEPH_OSD_RMW_FLAG_CACHE = (1 << 6),
327 CEPH_OSD_RMW_FLAG_FORCE_PROMOTE = (1 << 7),
328 CEPH_OSD_RMW_FLAG_SKIP_HANDLE_CACHE = (1 << 8),
329 CEPH_OSD_RMW_FLAG_SKIP_PROMOTE = (1 << 9),
330 CEPH_OSD_RMW_FLAG_RWORDERED = (1 << 10),
331 };
332
333
334 // pg stuff
335
336 #define OSD_SUPERBLOCK_GOBJECT ghobject_t(hobject_t(sobject_t(object_t("osd_superblock"), 0)))
337
338 // placement seed (a hash value)
339 typedef uint32_t ps_t;
340
341 // old (v1) pg_t encoding (wrap old struct ceph_pg)
342 struct old_pg_t {
343 ceph_pg v;
344 void encode(bufferlist& bl) const {
345 ::encode_raw(v, bl);
346 }
347 void decode(bufferlist::iterator& bl) {
348 ::decode_raw(v, bl);
349 }
350 };
351 WRITE_CLASS_ENCODER(old_pg_t)
352
353 // placement group id
354 struct pg_t {
355 uint64_t m_pool;
356 uint32_t m_seed;
357 int32_t m_preferred;
358
359 pg_t() : m_pool(0), m_seed(0), m_preferred(-1) {}
360 pg_t(ps_t seed, uint64_t pool, int pref=-1) :
361 m_pool(pool), m_seed(seed), m_preferred(pref) {}
362 // cppcheck-suppress noExplicitConstructor
363 pg_t(const ceph_pg& cpg) :
364 m_pool(cpg.pool), m_seed(cpg.ps), m_preferred((__s16)cpg.preferred) {}
365
366 // cppcheck-suppress noExplicitConstructor
367 pg_t(const old_pg_t& opg) {
368 *this = opg.v;
369 }
370
371 old_pg_t get_old_pg() const {
372 old_pg_t o;
373 assert(m_pool < 0xffffffffull);
374 o.v.pool = m_pool;
375 o.v.ps = m_seed;
376 o.v.preferred = (__s16)m_preferred;
377 return o;
378 }
379
380 ps_t ps() const {
381 return m_seed;
382 }
383 uint64_t pool() const {
384 return m_pool;
385 }
386 int32_t preferred() const {
387 return m_preferred;
388 }
389
390 static const uint8_t calc_name_buf_size = 36; // max length for max values len("18446744073709551615.ffffffff") + future suffix len("_head") + '\0'
391 char *calc_name(char *buf, const char *suffix_backwords) const;
392
393 void set_ps(ps_t p) {
394 m_seed = p;
395 }
396 void set_pool(uint64_t p) {
397 m_pool = p;
398 }
399 void set_preferred(int32_t osd) {
400 m_preferred = osd;
401 }
402
403 pg_t get_parent() const;
404 pg_t get_ancestor(unsigned old_pg_num) const;
405
406 int print(char *o, int maxlen) const;
407 bool parse(const char *s);
408
409 bool is_split(unsigned old_pg_num, unsigned new_pg_num, set<pg_t> *pchildren) const;
410
411 /**
412 * Returns b such that for all object o:
413 * ~((~0)<<b) & o.hash) == 0 iff o is in the pg for *this
414 */
415 unsigned get_split_bits(unsigned pg_num) const;
416
417 bool contains(int bits, const ghobject_t& oid) {
418 return oid.match(bits, ps());
419 }
420 bool contains(int bits, const hobject_t& oid) {
421 return oid.match(bits, ps());
422 }
423
424 hobject_t get_hobj_start() const;
425 hobject_t get_hobj_end(unsigned pg_num) const;
426
427 void encode(bufferlist& bl) const {
428 __u8 v = 1;
429 ::encode(v, bl);
430 ::encode(m_pool, bl);
431 ::encode(m_seed, bl);
432 ::encode(m_preferred, bl);
433 }
434 void decode(bufferlist::iterator& bl) {
435 __u8 v;
436 ::decode(v, bl);
437 ::decode(m_pool, bl);
438 ::decode(m_seed, bl);
439 ::decode(m_preferred, bl);
440 }
441 void decode_old(bufferlist::iterator& bl) {
442 old_pg_t opg;
443 ::decode(opg, bl);
444 *this = opg;
445 }
446 void dump(Formatter *f) const;
447 static void generate_test_instances(list<pg_t*>& o);
448 };
449 WRITE_CLASS_ENCODER(pg_t)
450
451 inline bool operator<(const pg_t& l, const pg_t& r) {
452 return l.pool() < r.pool() ||
453 (l.pool() == r.pool() && (l.preferred() < r.preferred() ||
454 (l.preferred() == r.preferred() && (l.ps() < r.ps()))));
455 }
456 inline bool operator<=(const pg_t& l, const pg_t& r) {
457 return l.pool() < r.pool() ||
458 (l.pool() == r.pool() && (l.preferred() < r.preferred() ||
459 (l.preferred() == r.preferred() && (l.ps() <= r.ps()))));
460 }
461 inline bool operator==(const pg_t& l, const pg_t& r) {
462 return l.pool() == r.pool() &&
463 l.preferred() == r.preferred() &&
464 l.ps() == r.ps();
465 }
466 inline bool operator!=(const pg_t& l, const pg_t& r) {
467 return l.pool() != r.pool() ||
468 l.preferred() != r.preferred() ||
469 l.ps() != r.ps();
470 }
471 inline bool operator>(const pg_t& l, const pg_t& r) {
472 return l.pool() > r.pool() ||
473 (l.pool() == r.pool() && (l.preferred() > r.preferred() ||
474 (l.preferred() == r.preferred() && (l.ps() > r.ps()))));
475 }
476 inline bool operator>=(const pg_t& l, const pg_t& r) {
477 return l.pool() > r.pool() ||
478 (l.pool() == r.pool() && (l.preferred() > r.preferred() ||
479 (l.preferred() == r.preferred() && (l.ps() >= r.ps()))));
480 }
481
482 ostream& operator<<(ostream& out, const pg_t &pg);
483
484 namespace std {
485 template<> struct hash< pg_t >
486 {
487 size_t operator()( const pg_t& x ) const
488 {
489 static hash<uint32_t> H;
490 return H((x.pool() & 0xffffffff) ^ (x.pool() >> 32) ^ x.ps() ^ x.preferred());
491 }
492 };
493 } // namespace std
494
495 struct spg_t {
496 pg_t pgid;
497 shard_id_t shard;
498 spg_t() : shard(shard_id_t::NO_SHARD) {}
499 spg_t(pg_t pgid, shard_id_t shard) : pgid(pgid), shard(shard) {}
500 explicit spg_t(pg_t pgid) : pgid(pgid), shard(shard_id_t::NO_SHARD) {}
501 unsigned get_split_bits(unsigned pg_num) const {
502 return pgid.get_split_bits(pg_num);
503 }
504 spg_t get_parent() const {
505 return spg_t(pgid.get_parent(), shard);
506 }
507 ps_t ps() const {
508 return pgid.ps();
509 }
510 uint64_t pool() const {
511 return pgid.pool();
512 }
513 int32_t preferred() const {
514 return pgid.preferred();
515 }
516
517 static const uint8_t calc_name_buf_size = pg_t::calc_name_buf_size + 4; // 36 + len('s') + len("255");
518 char *calc_name(char *buf, const char *suffix_backwords) const;
519
520 bool parse(const char *s);
521 bool parse(const std::string& s) {
522 return parse(s.c_str());
523 }
524 bool is_split(unsigned old_pg_num, unsigned new_pg_num,
525 set<spg_t> *pchildren) const {
526 set<pg_t> _children;
527 set<pg_t> *children = pchildren ? &_children : NULL;
528 bool is_split = pgid.is_split(old_pg_num, new_pg_num, children);
529 if (pchildren && is_split) {
530 for (set<pg_t>::iterator i = _children.begin();
531 i != _children.end();
532 ++i) {
533 pchildren->insert(spg_t(*i, shard));
534 }
535 }
536 return is_split;
537 }
538 bool is_no_shard() const {
539 return shard == shard_id_t::NO_SHARD;
540 }
541
542 ghobject_t make_pgmeta_oid() const {
543 return ghobject_t::make_pgmeta(pgid.pool(), pgid.ps(), shard);
544 }
545
546 void encode(bufferlist &bl) const {
547 ENCODE_START(1, 1, bl);
548 ::encode(pgid, bl);
549 ::encode(shard, bl);
550 ENCODE_FINISH(bl);
551 }
552 void decode(bufferlist::iterator &bl) {
553 DECODE_START(1, bl);
554 ::decode(pgid, bl);
555 ::decode(shard, bl);
556 DECODE_FINISH(bl);
557 }
558
559 ghobject_t make_temp_ghobject(const string& name) const {
560 return ghobject_t(
561 hobject_t(object_t(name), "", CEPH_NOSNAP,
562 pgid.ps(),
563 hobject_t::POOL_TEMP_START - pgid.pool(), ""),
564 ghobject_t::NO_GEN,
565 shard);
566 }
567
568 unsigned hash_to_shard(unsigned num_shards) const {
569 return ps() % num_shards;
570 }
571 };
572 WRITE_CLASS_ENCODER(spg_t)
573 WRITE_EQ_OPERATORS_2(spg_t, pgid, shard)
574 WRITE_CMP_OPERATORS_2(spg_t, pgid, shard)
575
576 namespace std {
577 template<> struct hash< spg_t >
578 {
579 size_t operator()( const spg_t& x ) const
580 {
581 static hash<uint32_t> H;
582 return H(hash<pg_t>()(x.pgid) ^ x.shard);
583 }
584 };
585 } // namespace std
586
587 ostream& operator<<(ostream& out, const spg_t &pg);
588
589 // ----------------------
590
591 class coll_t {
592 enum type_t {
593 TYPE_META = 0,
594 TYPE_LEGACY_TEMP = 1, /* no longer used */
595 TYPE_PG = 2,
596 TYPE_PG_TEMP = 3,
597 };
598 type_t type;
599 spg_t pgid;
600 uint64_t removal_seq; // note: deprecated, not encoded
601
602 char _str_buff[spg_t::calc_name_buf_size];
603 char *_str;
604
605 void calc_str();
606
607 coll_t(type_t t, spg_t p, uint64_t r)
608 : type(t), pgid(p), removal_seq(r) {
609 calc_str();
610 }
611
612 public:
613 coll_t() : type(TYPE_META), removal_seq(0)
614 {
615 calc_str();
616 }
617
618 coll_t(const coll_t& other)
619 : type(other.type), pgid(other.pgid), removal_seq(other.removal_seq) {
620 calc_str();
621 }
622
623 explicit coll_t(spg_t pgid)
624 : type(TYPE_PG), pgid(pgid), removal_seq(0)
625 {
626 calc_str();
627 }
628
629 coll_t& operator=(const coll_t& rhs)
630 {
631 this->type = rhs.type;
632 this->pgid = rhs.pgid;
633 this->removal_seq = rhs.removal_seq;
634 this->calc_str();
635 return *this;
636 }
637
638 // named constructors
639 static coll_t meta() {
640 return coll_t();
641 }
642 static coll_t pg(spg_t p) {
643 return coll_t(p);
644 }
645
646 const std::string to_str() const {
647 return string(_str);
648 }
649 const char *c_str() const {
650 return _str;
651 }
652
653 bool parse(const std::string& s);
654
655 int operator<(const coll_t &rhs) const {
656 return type < rhs.type ||
657 (type == rhs.type && pgid < rhs.pgid);
658 }
659
660 bool is_meta() const {
661 return type == TYPE_META;
662 }
663 bool is_pg_prefix(spg_t *pgid_) const {
664 if (type == TYPE_PG || type == TYPE_PG_TEMP) {
665 *pgid_ = pgid;
666 return true;
667 }
668 return false;
669 }
670 bool is_pg() const {
671 return type == TYPE_PG;
672 }
673 bool is_pg(spg_t *pgid_) const {
674 if (type == TYPE_PG) {
675 *pgid_ = pgid;
676 return true;
677 }
678 return false;
679 }
680 bool is_temp() const {
681 return type == TYPE_PG_TEMP;
682 }
683 bool is_temp(spg_t *pgid_) const {
684 if (type == TYPE_PG_TEMP) {
685 *pgid_ = pgid;
686 return true;
687 }
688 return false;
689 }
690
691 void encode(bufferlist& bl) const;
692 void decode(bufferlist::iterator& bl);
693 size_t encoded_size() const;
694
695 inline bool operator==(const coll_t& rhs) const {
696 // only compare type if meta
697 if (type != rhs.type)
698 return false;
699 if (type == TYPE_META)
700 return true;
701 return type == rhs.type && pgid == rhs.pgid;
702 }
703 inline bool operator!=(const coll_t& rhs) const {
704 return !(*this == rhs);
705 }
706
707 // get a TEMP collection that corresponds to the current collection,
708 // which we presume is a pg collection.
709 coll_t get_temp() const {
710 assert(type == TYPE_PG);
711 return coll_t(TYPE_PG_TEMP, pgid, 0);
712 }
713
714 ghobject_t get_min_hobj() const {
715 ghobject_t o;
716 switch (type) {
717 case TYPE_PG:
718 o.hobj.pool = pgid.pool();
719 o.set_shard(pgid.shard);
720 break;
721 case TYPE_META:
722 o.hobj.pool = -1;
723 break;
724 default:
725 break;
726 }
727 return o;
728 }
729
730 unsigned hash_to_shard(unsigned num_shards) const {
731 if (type == TYPE_PG)
732 return pgid.hash_to_shard(num_shards);
733 return 0; // whatever.
734 }
735
736 void dump(Formatter *f) const;
737 static void generate_test_instances(list<coll_t*>& o);
738 };
739
740 WRITE_CLASS_ENCODER(coll_t)
741
742 inline ostream& operator<<(ostream& out, const coll_t& c) {
743 out << c.to_str();
744 return out;
745 }
746
747 namespace std {
748 template<> struct hash<coll_t> {
749 size_t operator()(const coll_t &c) const {
750 size_t h = 0;
751 string str(c.to_str());
752 std::string::const_iterator end(str.end());
753 for (std::string::const_iterator s = str.begin(); s != end; ++s) {
754 h += *s;
755 h += (h << 10);
756 h ^= (h >> 6);
757 }
758 h += (h << 3);
759 h ^= (h >> 11);
760 h += (h << 15);
761 return h;
762 }
763 };
764 } // namespace std
765
766 inline ostream& operator<<(ostream& out, const ceph_object_layout &ol)
767 {
768 out << pg_t(ol.ol_pgid);
769 int su = ol.ol_stripe_unit;
770 if (su)
771 out << ".su=" << su;
772 return out;
773 }
774
775
776
777 // compound rados version type
778 /* WARNING: If add member in eversion_t, please make sure the encode/decode function
779 * work well. For little-endian machine, we should make sure there is no padding
780 * in 32-bit machine and 64-bit machine.
781 */
782 class eversion_t {
783 public:
784 version_t version;
785 epoch_t epoch;
786 __u32 __pad;
787 eversion_t() : version(0), epoch(0), __pad(0) {}
788 eversion_t(epoch_t e, version_t v) : version(v), epoch(e), __pad(0) {}
789
790 // cppcheck-suppress noExplicitConstructor
791 eversion_t(const ceph_eversion& ce) :
792 version(ce.version),
793 epoch(ce.epoch),
794 __pad(0) { }
795
796 explicit eversion_t(bufferlist& bl) : __pad(0) { decode(bl); }
797
798 static eversion_t max() {
799 eversion_t max;
800 max.version -= 1;
801 max.epoch -= 1;
802 return max;
803 }
804
805 operator ceph_eversion() {
806 ceph_eversion c;
807 c.epoch = epoch;
808 c.version = version;
809 return c;
810 }
811
812 string get_key_name() const;
813
814 void encode(bufferlist &bl) const {
815 #if defined(CEPH_LITTLE_ENDIAN)
816 bl.append((char *)this, sizeof(version_t) + sizeof(epoch_t));
817 #else
818 ::encode(version, bl);
819 ::encode(epoch, bl);
820 #endif
821 }
822 void decode(bufferlist::iterator &bl) {
823 #if defined(CEPH_LITTLE_ENDIAN)
824 bl.copy(sizeof(version_t) + sizeof(epoch_t), (char *)this);
825 #else
826 ::decode(version, bl);
827 ::decode(epoch, bl);
828 #endif
829 }
830 void decode(bufferlist& bl) {
831 bufferlist::iterator p = bl.begin();
832 decode(p);
833 }
834 };
835 WRITE_CLASS_ENCODER(eversion_t)
836
837 inline bool operator==(const eversion_t& l, const eversion_t& r) {
838 return (l.epoch == r.epoch) && (l.version == r.version);
839 }
840 inline bool operator!=(const eversion_t& l, const eversion_t& r) {
841 return (l.epoch != r.epoch) || (l.version != r.version);
842 }
843 inline bool operator<(const eversion_t& l, const eversion_t& r) {
844 return (l.epoch == r.epoch) ? (l.version < r.version):(l.epoch < r.epoch);
845 }
846 inline bool operator<=(const eversion_t& l, const eversion_t& r) {
847 return (l.epoch == r.epoch) ? (l.version <= r.version):(l.epoch <= r.epoch);
848 }
849 inline bool operator>(const eversion_t& l, const eversion_t& r) {
850 return (l.epoch == r.epoch) ? (l.version > r.version):(l.epoch > r.epoch);
851 }
852 inline bool operator>=(const eversion_t& l, const eversion_t& r) {
853 return (l.epoch == r.epoch) ? (l.version >= r.version):(l.epoch >= r.epoch);
854 }
855 inline ostream& operator<<(ostream& out, const eversion_t& e) {
856 return out << e.epoch << "'" << e.version;
857 }
858
859 /**
860 * objectstore_perf_stat_t
861 *
862 * current perf information about the osd
863 */
864 struct objectstore_perf_stat_t {
865 // cur_op_latency is in ms since double add/sub are not associative
866 uint32_t os_commit_latency;
867 uint32_t os_apply_latency;
868
869 objectstore_perf_stat_t() :
870 os_commit_latency(0), os_apply_latency(0) {}
871
872 bool operator==(const objectstore_perf_stat_t &r) const {
873 return os_commit_latency == r.os_commit_latency &&
874 os_apply_latency == r.os_apply_latency;
875 }
876
877 void add(const objectstore_perf_stat_t &o) {
878 os_commit_latency += o.os_commit_latency;
879 os_apply_latency += o.os_apply_latency;
880 }
881 void sub(const objectstore_perf_stat_t &o) {
882 os_commit_latency -= o.os_commit_latency;
883 os_apply_latency -= o.os_apply_latency;
884 }
885 void dump(Formatter *f) const;
886 void encode(bufferlist &bl) const;
887 void decode(bufferlist::iterator &bl);
888 static void generate_test_instances(std::list<objectstore_perf_stat_t*>& o);
889 };
890 WRITE_CLASS_ENCODER(objectstore_perf_stat_t)
891
892 /** osd_stat
893 * aggregate stats for an osd
894 */
895 struct osd_stat_t {
896 int64_t kb, kb_used, kb_avail;
897 vector<int> hb_peers;
898 int32_t snap_trim_queue_len, num_snap_trimming;
899
900 pow2_hist_t op_queue_age_hist;
901
902 objectstore_perf_stat_t os_perf_stat;
903
904 epoch_t up_from = 0;
905 uint64_t seq = 0;
906
907 uint32_t num_pgs = 0;
908
909 osd_stat_t() : kb(0), kb_used(0), kb_avail(0),
910 snap_trim_queue_len(0), num_snap_trimming(0) {}
911
912 void add(const osd_stat_t& o) {
913 kb += o.kb;
914 kb_used += o.kb_used;
915 kb_avail += o.kb_avail;
916 snap_trim_queue_len += o.snap_trim_queue_len;
917 num_snap_trimming += o.num_snap_trimming;
918 op_queue_age_hist.add(o.op_queue_age_hist);
919 os_perf_stat.add(o.os_perf_stat);
920 num_pgs += o.num_pgs;
921 }
922 void sub(const osd_stat_t& o) {
923 kb -= o.kb;
924 kb_used -= o.kb_used;
925 kb_avail -= o.kb_avail;
926 snap_trim_queue_len -= o.snap_trim_queue_len;
927 num_snap_trimming -= o.num_snap_trimming;
928 op_queue_age_hist.sub(o.op_queue_age_hist);
929 os_perf_stat.sub(o.os_perf_stat);
930 num_pgs -= o.num_pgs;
931 }
932
933 void dump(Formatter *f) const;
934 void encode(bufferlist &bl) const;
935 void decode(bufferlist::iterator &bl);
936 static void generate_test_instances(std::list<osd_stat_t*>& o);
937 };
938 WRITE_CLASS_ENCODER(osd_stat_t)
939
940 inline bool operator==(const osd_stat_t& l, const osd_stat_t& r) {
941 return l.kb == r.kb &&
942 l.kb_used == r.kb_used &&
943 l.kb_avail == r.kb_avail &&
944 l.snap_trim_queue_len == r.snap_trim_queue_len &&
945 l.num_snap_trimming == r.num_snap_trimming &&
946 l.hb_peers == r.hb_peers &&
947 l.op_queue_age_hist == r.op_queue_age_hist &&
948 l.os_perf_stat == r.os_perf_stat &&
949 l.num_pgs == r.num_pgs;
950 }
951 inline bool operator!=(const osd_stat_t& l, const osd_stat_t& r) {
952 return !(l == r);
953 }
954
955
956
957 inline ostream& operator<<(ostream& out, const osd_stat_t& s) {
958 return out << "osd_stat(" << kb_t(s.kb_used) << " used, "
959 << kb_t(s.kb_avail) << " avail, "
960 << kb_t(s.kb) << " total, "
961 << "peers " << s.hb_peers
962 << " op hist " << s.op_queue_age_hist.h
963 << ")";
964 }
965
966
967 /*
968 * pg states
969 */
970 #define PG_STATE_CREATING (1<<0) // creating
971 #define PG_STATE_ACTIVE (1<<1) // i am active. (primary: replicas too)
972 #define PG_STATE_CLEAN (1<<2) // peers are complete, clean of stray replicas.
973 #define PG_STATE_DOWN (1<<4) // a needed replica is down, PG offline
974 //#define PG_STATE_REPLAY (1<<5) // crashed, waiting for replay
975 //#define PG_STATE_STRAY (1<<6) // i must notify the primary i exist.
976 //#define PG_STATE_SPLITTING (1<<7) // i am splitting
977 #define PG_STATE_SCRUBBING (1<<8) // scrubbing
978 //#define PG_STATE_SCRUBQ (1<<9) // queued for scrub
979 #define PG_STATE_DEGRADED (1<<10) // pg contains objects with reduced redundancy
980 #define PG_STATE_INCONSISTENT (1<<11) // pg replicas are inconsistent (but shouldn't be)
981 #define PG_STATE_PEERING (1<<12) // pg is (re)peering
982 #define PG_STATE_REPAIR (1<<13) // pg should repair on next scrub
983 #define PG_STATE_RECOVERING (1<<14) // pg is recovering/migrating objects
984 #define PG_STATE_BACKFILL_WAIT (1<<15) // [active] reserving backfill
985 #define PG_STATE_INCOMPLETE (1<<16) // incomplete content, peering failed.
986 #define PG_STATE_STALE (1<<17) // our state for this pg is stale, unknown.
987 #define PG_STATE_REMAPPED (1<<18) // pg is explicitly remapped to different OSDs than CRUSH
988 #define PG_STATE_DEEP_SCRUB (1<<19) // deep scrub: check CRC32 on files
989 #define PG_STATE_BACKFILL (1<<20) // [active] backfilling pg content
990 #define PG_STATE_BACKFILL_TOOFULL (1<<21) // backfill can't proceed: too full
991 #define PG_STATE_RECOVERY_WAIT (1<<22) // waiting for recovery reservations
992 #define PG_STATE_UNDERSIZED (1<<23) // pg acting < pool size
993 #define PG_STATE_ACTIVATING (1<<24) // pg is peered but not yet active
994 #define PG_STATE_PEERED (1<<25) // peered, cannot go active, can recover
995 #define PG_STATE_SNAPTRIM (1<<26) // trimming snaps
996 #define PG_STATE_SNAPTRIM_WAIT (1<<27) // queued to trim snaps
997 #define PG_STATE_RECOVERY_TOOFULL (1<<28) // recovery can't proceed: too full
998 #define PG_STATE_SNAPTRIM_ERROR (1<<29) // error stopped trimming snaps
999 #define PG_STATE_FORCED_RECOVERY (1<<30) // force recovery of this pg before any other
1000 #define PG_STATE_FORCED_BACKFILL (1<<31) // force backfill of this pg before any other
1001
1002 std::string pg_state_string(int state);
1003 std::string pg_vector_string(const vector<int32_t> &a);
1004 int pg_string_state(const std::string& state);
1005
1006
1007 /*
1008 * pool_snap_info_t
1009 *
1010 * attributes for a single pool snapshot.
1011 */
1012 struct pool_snap_info_t {
1013 snapid_t snapid;
1014 utime_t stamp;
1015 string name;
1016
1017 void dump(Formatter *f) const;
1018 void encode(bufferlist& bl, uint64_t features) const;
1019 void decode(bufferlist::iterator& bl);
1020 static void generate_test_instances(list<pool_snap_info_t*>& o);
1021 };
1022 WRITE_CLASS_ENCODER_FEATURES(pool_snap_info_t)
1023
1024 inline ostream& operator<<(ostream& out, const pool_snap_info_t& si) {
1025 return out << si.snapid << '(' << si.name << ' ' << si.stamp << ')';
1026 }
1027
1028
1029 /*
1030 * pool_opts_t
1031 *
1032 * pool options.
1033 */
1034
1035 class pool_opts_t {
1036 public:
1037 enum key_t {
1038 SCRUB_MIN_INTERVAL,
1039 SCRUB_MAX_INTERVAL,
1040 DEEP_SCRUB_INTERVAL,
1041 RECOVERY_PRIORITY,
1042 RECOVERY_OP_PRIORITY,
1043 SCRUB_PRIORITY,
1044 COMPRESSION_MODE,
1045 COMPRESSION_ALGORITHM,
1046 COMPRESSION_REQUIRED_RATIO,
1047 COMPRESSION_MAX_BLOB_SIZE,
1048 COMPRESSION_MIN_BLOB_SIZE,
1049 CSUM_TYPE,
1050 CSUM_MAX_BLOCK,
1051 CSUM_MIN_BLOCK,
1052 };
1053
1054 enum type_t {
1055 STR,
1056 INT,
1057 DOUBLE,
1058 };
1059
1060 struct opt_desc_t {
1061 key_t key;
1062 type_t type;
1063
1064 opt_desc_t(key_t k, type_t t) : key(k), type(t) {}
1065
1066 bool operator==(const opt_desc_t& rhs) const {
1067 return key == rhs.key && type == rhs.type;
1068 }
1069 };
1070
1071 typedef boost::variant<std::string,int,double> value_t;
1072
1073 static bool is_opt_name(const std::string& name);
1074 static opt_desc_t get_opt_desc(const std::string& name);
1075
1076 pool_opts_t() : opts() {}
1077
1078 bool is_set(key_t key) const;
1079
1080 template<typename T>
1081 void set(key_t key, const T &val) {
1082 value_t value = val;
1083 opts[key] = value;
1084 }
1085
1086 template<typename T>
1087 bool get(key_t key, T *val) const {
1088 opts_t::const_iterator i = opts.find(key);
1089 if (i == opts.end()) {
1090 return false;
1091 }
1092 *val = boost::get<T>(i->second);
1093 return true;
1094 }
1095
1096 const value_t& get(key_t key) const;
1097
1098 bool unset(key_t key);
1099
1100 void dump(const std::string& name, Formatter *f) const;
1101
1102 void dump(Formatter *f) const;
1103 void encode(bufferlist &bl) const;
1104 void decode(bufferlist::iterator &bl);
1105
1106 private:
1107 typedef std::map<key_t, value_t> opts_t;
1108 opts_t opts;
1109
1110 friend ostream& operator<<(ostream& out, const pool_opts_t& opts);
1111 };
1112 WRITE_CLASS_ENCODER(pool_opts_t)
1113
1114 /*
1115 * pg_pool
1116 */
1117 struct pg_pool_t {
1118 static const char *APPLICATION_NAME_CEPHFS;
1119 static const char *APPLICATION_NAME_RBD;
1120 static const char *APPLICATION_NAME_RGW;
1121
1122 enum {
1123 TYPE_REPLICATED = 1, // replication
1124 //TYPE_RAID4 = 2, // raid4 (never implemented)
1125 TYPE_ERASURE = 3, // erasure-coded
1126 };
1127 static const char *get_type_name(int t) {
1128 switch (t) {
1129 case TYPE_REPLICATED: return "replicated";
1130 //case TYPE_RAID4: return "raid4";
1131 case TYPE_ERASURE: return "erasure";
1132 default: return "???";
1133 }
1134 }
1135 const char *get_type_name() const {
1136 return get_type_name(type);
1137 }
1138
1139 enum {
1140 FLAG_HASHPSPOOL = 1<<0, // hash pg seed and pool together (instead of adding)
1141 FLAG_FULL = 1<<1, // pool is full
1142 FLAG_EC_OVERWRITES = 1<<2, // enables overwrites, once enabled, cannot be disabled
1143 FLAG_INCOMPLETE_CLONES = 1<<3, // may have incomplete clones (bc we are/were an overlay)
1144 FLAG_NODELETE = 1<<4, // pool can't be deleted
1145 FLAG_NOPGCHANGE = 1<<5, // pool's pg and pgp num can't be changed
1146 FLAG_NOSIZECHANGE = 1<<6, // pool's size and min size can't be changed
1147 FLAG_WRITE_FADVISE_DONTNEED = 1<<7, // write mode with LIBRADOS_OP_FLAG_FADVISE_DONTNEED
1148 FLAG_NOSCRUB = 1<<8, // block periodic scrub
1149 FLAG_NODEEP_SCRUB = 1<<9, // block periodic deep-scrub
1150 };
1151
1152 static const char *get_flag_name(int f) {
1153 switch (f) {
1154 case FLAG_HASHPSPOOL: return "hashpspool";
1155 case FLAG_FULL: return "full";
1156 case FLAG_EC_OVERWRITES: return "ec_overwrites";
1157 case FLAG_INCOMPLETE_CLONES: return "incomplete_clones";
1158 case FLAG_NODELETE: return "nodelete";
1159 case FLAG_NOPGCHANGE: return "nopgchange";
1160 case FLAG_NOSIZECHANGE: return "nosizechange";
1161 case FLAG_WRITE_FADVISE_DONTNEED: return "write_fadvise_dontneed";
1162 case FLAG_NOSCRUB: return "noscrub";
1163 case FLAG_NODEEP_SCRUB: return "nodeep-scrub";
1164 default: return "???";
1165 }
1166 }
1167 static string get_flags_string(uint64_t f) {
1168 string s;
1169 for (unsigned n=0; f && n<64; ++n) {
1170 if (f & (1ull << n)) {
1171 if (s.length())
1172 s += ",";
1173 s += get_flag_name(1ull << n);
1174 }
1175 }
1176 return s;
1177 }
1178 string get_flags_string() const {
1179 return get_flags_string(flags);
1180 }
1181 static uint64_t get_flag_by_name(const string& name) {
1182 if (name == "hashpspool")
1183 return FLAG_HASHPSPOOL;
1184 if (name == "full")
1185 return FLAG_FULL;
1186 if (name == "ec_overwrites")
1187 return FLAG_EC_OVERWRITES;
1188 if (name == "incomplete_clones")
1189 return FLAG_INCOMPLETE_CLONES;
1190 if (name == "nodelete")
1191 return FLAG_NODELETE;
1192 if (name == "nopgchange")
1193 return FLAG_NOPGCHANGE;
1194 if (name == "nosizechange")
1195 return FLAG_NOSIZECHANGE;
1196 if (name == "write_fadvise_dontneed")
1197 return FLAG_WRITE_FADVISE_DONTNEED;
1198 if (name == "noscrub")
1199 return FLAG_NOSCRUB;
1200 if (name == "nodeep-scrub")
1201 return FLAG_NODEEP_SCRUB;
1202 return 0;
1203 }
1204
1205 /// converts the acting/up vector to a set of pg shards
1206 void convert_to_pg_shards(const vector<int> &from, set<pg_shard_t>* to) const;
1207
1208 typedef enum {
1209 CACHEMODE_NONE = 0, ///< no caching
1210 CACHEMODE_WRITEBACK = 1, ///< write to cache, flush later
1211 CACHEMODE_FORWARD = 2, ///< forward if not in cache
1212 CACHEMODE_READONLY = 3, ///< handle reads, forward writes [not strongly consistent]
1213 CACHEMODE_READFORWARD = 4, ///< forward reads, write to cache flush later
1214 CACHEMODE_READPROXY = 5, ///< proxy reads, write to cache flush later
1215 CACHEMODE_PROXY = 6, ///< proxy if not in cache
1216 } cache_mode_t;
1217 static const char *get_cache_mode_name(cache_mode_t m) {
1218 switch (m) {
1219 case CACHEMODE_NONE: return "none";
1220 case CACHEMODE_WRITEBACK: return "writeback";
1221 case CACHEMODE_FORWARD: return "forward";
1222 case CACHEMODE_READONLY: return "readonly";
1223 case CACHEMODE_READFORWARD: return "readforward";
1224 case CACHEMODE_READPROXY: return "readproxy";
1225 case CACHEMODE_PROXY: return "proxy";
1226 default: return "unknown";
1227 }
1228 }
1229 static cache_mode_t get_cache_mode_from_str(const string& s) {
1230 if (s == "none")
1231 return CACHEMODE_NONE;
1232 if (s == "writeback")
1233 return CACHEMODE_WRITEBACK;
1234 if (s == "forward")
1235 return CACHEMODE_FORWARD;
1236 if (s == "readonly")
1237 return CACHEMODE_READONLY;
1238 if (s == "readforward")
1239 return CACHEMODE_READFORWARD;
1240 if (s == "readproxy")
1241 return CACHEMODE_READPROXY;
1242 if (s == "proxy")
1243 return CACHEMODE_PROXY;
1244 return (cache_mode_t)-1;
1245 }
1246 const char *get_cache_mode_name() const {
1247 return get_cache_mode_name(cache_mode);
1248 }
1249 bool cache_mode_requires_hit_set() const {
1250 switch (cache_mode) {
1251 case CACHEMODE_NONE:
1252 case CACHEMODE_FORWARD:
1253 case CACHEMODE_READONLY:
1254 case CACHEMODE_PROXY:
1255 return false;
1256 case CACHEMODE_WRITEBACK:
1257 case CACHEMODE_READFORWARD:
1258 case CACHEMODE_READPROXY:
1259 return true;
1260 default:
1261 assert(0 == "implement me");
1262 }
1263 }
1264
1265 uint64_t flags; ///< FLAG_*
1266 __u8 type; ///< TYPE_*
1267 __u8 size, min_size; ///< number of osds in each pg
1268 __u8 crush_rule; ///< crush placement rule
1269 __u8 object_hash; ///< hash mapping object name to ps
1270 private:
1271 __u32 pg_num, pgp_num; ///< number of pgs
1272
1273
1274 public:
1275 map<string,string> properties; ///< OBSOLETE
1276 string erasure_code_profile; ///< name of the erasure code profile in OSDMap
1277 epoch_t last_change; ///< most recent epoch changed, exclusing snapshot changes
1278 epoch_t last_force_op_resend; ///< last epoch that forced clients to resend
1279 /// last epoch that forced clients to resend (pre-luminous clients only)
1280 epoch_t last_force_op_resend_preluminous;
1281 snapid_t snap_seq; ///< seq for per-pool snapshot
1282 epoch_t snap_epoch; ///< osdmap epoch of last snap
1283 uint64_t auid; ///< who owns the pg
1284 __u32 crash_replay_interval; ///< seconds to allow clients to replay ACKed but unCOMMITted requests
1285
1286 uint64_t quota_max_bytes; ///< maximum number of bytes for this pool
1287 uint64_t quota_max_objects; ///< maximum number of objects for this pool
1288
1289 /*
1290 * Pool snaps (global to this pool). These define a SnapContext for
1291 * the pool, unless the client manually specifies an alternate
1292 * context.
1293 */
1294 map<snapid_t, pool_snap_info_t> snaps;
1295 /*
1296 * Alternatively, if we are defining non-pool snaps (e.g. via the
1297 * Ceph MDS), we must track @removed_snaps (since @snaps is not
1298 * used). Snaps and removed_snaps are to be used exclusive of each
1299 * other!
1300 */
1301 interval_set<snapid_t> removed_snaps;
1302
1303 unsigned pg_num_mask, pgp_num_mask;
1304
1305 set<uint64_t> tiers; ///< pools that are tiers of us
1306 int64_t tier_of; ///< pool for which we are a tier
1307 // Note that write wins for read+write ops
1308 int64_t read_tier; ///< pool/tier for objecter to direct reads to
1309 int64_t write_tier; ///< pool/tier for objecter to direct writes to
1310 cache_mode_t cache_mode; ///< cache pool mode
1311
1312 bool is_tier() const { return tier_of >= 0; }
1313 bool has_tiers() const { return !tiers.empty(); }
1314 void clear_tier() {
1315 tier_of = -1;
1316 clear_read_tier();
1317 clear_write_tier();
1318 clear_tier_tunables();
1319 }
1320 bool has_read_tier() const { return read_tier >= 0; }
1321 void clear_read_tier() { read_tier = -1; }
1322 bool has_write_tier() const { return write_tier >= 0; }
1323 void clear_write_tier() { write_tier = -1; }
1324 void clear_tier_tunables() {
1325 if (cache_mode != CACHEMODE_NONE)
1326 flags |= FLAG_INCOMPLETE_CLONES;
1327 cache_mode = CACHEMODE_NONE;
1328
1329 target_max_bytes = 0;
1330 target_max_objects = 0;
1331 cache_target_dirty_ratio_micro = 0;
1332 cache_target_dirty_high_ratio_micro = 0;
1333 cache_target_full_ratio_micro = 0;
1334 hit_set_params = HitSet::Params();
1335 hit_set_period = 0;
1336 hit_set_count = 0;
1337 hit_set_grade_decay_rate = 0;
1338 hit_set_search_last_n = 0;
1339 grade_table.resize(0);
1340 }
1341
1342 uint64_t target_max_bytes; ///< tiering: target max pool size
1343 uint64_t target_max_objects; ///< tiering: target max pool size
1344
1345 uint32_t cache_target_dirty_ratio_micro; ///< cache: fraction of target to leave dirty
1346 uint32_t cache_target_dirty_high_ratio_micro; ///<cache: fraction of target to flush with high speed
1347 uint32_t cache_target_full_ratio_micro; ///< cache: fraction of target to fill before we evict in earnest
1348
1349 uint32_t cache_min_flush_age; ///< minimum age (seconds) before we can flush
1350 uint32_t cache_min_evict_age; ///< minimum age (seconds) before we can evict
1351
1352 HitSet::Params hit_set_params; ///< The HitSet params to use on this pool
1353 uint32_t hit_set_period; ///< periodicity of HitSet segments (seconds)
1354 uint32_t hit_set_count; ///< number of periods to retain
1355 bool use_gmt_hitset; ///< use gmt to name the hitset archive object
1356 uint32_t min_read_recency_for_promote; ///< minimum number of HitSet to check before promote on read
1357 uint32_t min_write_recency_for_promote; ///< minimum number of HitSet to check before promote on write
1358 uint32_t hit_set_grade_decay_rate; ///< current hit_set has highest priority on objects
1359 ///temperature count,the follow hit_set's priority decay
1360 ///by this params than pre hit_set
1361 uint32_t hit_set_search_last_n; ///<accumulate atmost N hit_sets for temperature
1362
1363 uint32_t stripe_width; ///< erasure coded stripe size in bytes
1364
1365 uint64_t expected_num_objects; ///< expected number of objects on this pool, a value of 0 indicates
1366 ///< user does not specify any expected value
1367 bool fast_read; ///< whether turn on fast read on the pool or not
1368
1369 pool_opts_t opts; ///< options
1370
1371 /// application -> key/value metadata
1372 map<string, std::map<string, string>> application_metadata;
1373
1374 private:
1375 vector<uint32_t> grade_table;
1376
1377 public:
1378 uint32_t get_grade(unsigned i) const {
1379 if (grade_table.size() <= i)
1380 return 0;
1381 return grade_table[i];
1382 }
1383 void calc_grade_table() {
1384 unsigned v = 1000000;
1385 grade_table.resize(hit_set_count);
1386 for (unsigned i = 0; i < hit_set_count; i++) {
1387 v = v * (1 - (hit_set_grade_decay_rate / 100.0));
1388 grade_table[i] = v;
1389 }
1390 }
1391
1392 pg_pool_t()
1393 : flags(0), type(0), size(0), min_size(0),
1394 crush_rule(0), object_hash(0),
1395 pg_num(0), pgp_num(0),
1396 last_change(0),
1397 last_force_op_resend(0),
1398 last_force_op_resend_preluminous(0),
1399 snap_seq(0), snap_epoch(0),
1400 auid(0),
1401 crash_replay_interval(0),
1402 quota_max_bytes(0), quota_max_objects(0),
1403 pg_num_mask(0), pgp_num_mask(0),
1404 tier_of(-1), read_tier(-1), write_tier(-1),
1405 cache_mode(CACHEMODE_NONE),
1406 target_max_bytes(0), target_max_objects(0),
1407 cache_target_dirty_ratio_micro(0),
1408 cache_target_dirty_high_ratio_micro(0),
1409 cache_target_full_ratio_micro(0),
1410 cache_min_flush_age(0),
1411 cache_min_evict_age(0),
1412 hit_set_params(),
1413 hit_set_period(0),
1414 hit_set_count(0),
1415 use_gmt_hitset(true),
1416 min_read_recency_for_promote(0),
1417 min_write_recency_for_promote(0),
1418 hit_set_grade_decay_rate(0),
1419 hit_set_search_last_n(0),
1420 stripe_width(0),
1421 expected_num_objects(0),
1422 fast_read(false),
1423 opts()
1424 { }
1425
1426 void dump(Formatter *f) const;
1427
1428 uint64_t get_flags() const { return flags; }
1429 bool has_flag(uint64_t f) const { return flags & f; }
1430 void set_flag(uint64_t f) { flags |= f; }
1431 void unset_flag(uint64_t f) { flags &= ~f; }
1432
1433 bool ec_pool() const {
1434 return type == TYPE_ERASURE;
1435 }
1436 bool require_rollback() const {
1437 return ec_pool();
1438 }
1439
1440 /// true if incomplete clones may be present
1441 bool allow_incomplete_clones() const {
1442 return cache_mode != CACHEMODE_NONE || has_flag(FLAG_INCOMPLETE_CLONES);
1443 }
1444
1445 unsigned get_type() const { return type; }
1446 unsigned get_size() const { return size; }
1447 unsigned get_min_size() const { return min_size; }
1448 int get_crush_rule() const { return crush_rule; }
1449 int get_object_hash() const { return object_hash; }
1450 const char *get_object_hash_name() const {
1451 return ceph_str_hash_name(get_object_hash());
1452 }
1453 epoch_t get_last_change() const { return last_change; }
1454 epoch_t get_last_force_op_resend() const { return last_force_op_resend; }
1455 epoch_t get_last_force_op_resend_preluminous() const {
1456 return last_force_op_resend_preluminous;
1457 }
1458 epoch_t get_snap_epoch() const { return snap_epoch; }
1459 snapid_t get_snap_seq() const { return snap_seq; }
1460 uint64_t get_auid() const { return auid; }
1461 unsigned get_crash_replay_interval() const { return crash_replay_interval; }
1462
1463 void set_snap_seq(snapid_t s) { snap_seq = s; }
1464 void set_snap_epoch(epoch_t e) { snap_epoch = e; }
1465
1466 void set_stripe_width(uint32_t s) { stripe_width = s; }
1467 uint32_t get_stripe_width() const { return stripe_width; }
1468
1469 bool is_replicated() const { return get_type() == TYPE_REPLICATED; }
1470 bool is_erasure() const { return get_type() == TYPE_ERASURE; }
1471
1472 bool supports_omap() const {
1473 return !(get_type() == TYPE_ERASURE);
1474 }
1475
1476 bool requires_aligned_append() const {
1477 return is_erasure() && !has_flag(FLAG_EC_OVERWRITES);
1478 }
1479 uint64_t required_alignment() const { return stripe_width; }
1480
1481 bool allows_ecoverwrites() const {
1482 return has_flag(FLAG_EC_OVERWRITES);
1483 }
1484
1485 bool can_shift_osds() const {
1486 switch (get_type()) {
1487 case TYPE_REPLICATED:
1488 return true;
1489 case TYPE_ERASURE:
1490 return false;
1491 default:
1492 assert(0 == "unhandled pool type");
1493 }
1494 }
1495
1496 unsigned get_pg_num() const { return pg_num; }
1497 unsigned get_pgp_num() const { return pgp_num; }
1498
1499 unsigned get_pg_num_mask() const { return pg_num_mask; }
1500 unsigned get_pgp_num_mask() const { return pgp_num_mask; }
1501
1502 // if pg_num is not a multiple of two, pgs are not equally sized.
1503 // return, for a given pg, the fraction (denominator) of the total
1504 // pool size that it represents.
1505 unsigned get_pg_num_divisor(pg_t pgid) const;
1506
1507 void set_pg_num(int p) {
1508 pg_num = p;
1509 calc_pg_masks();
1510 }
1511 void set_pgp_num(int p) {
1512 pgp_num = p;
1513 calc_pg_masks();
1514 }
1515
1516 void set_quota_max_bytes(uint64_t m) {
1517 quota_max_bytes = m;
1518 }
1519 uint64_t get_quota_max_bytes() {
1520 return quota_max_bytes;
1521 }
1522
1523 void set_quota_max_objects(uint64_t m) {
1524 quota_max_objects = m;
1525 }
1526 uint64_t get_quota_max_objects() {
1527 return quota_max_objects;
1528 }
1529
1530 void set_last_force_op_resend(uint64_t t) {
1531 last_force_op_resend = t;
1532 last_force_op_resend_preluminous = t;
1533 }
1534
1535 void calc_pg_masks();
1536
1537 /*
1538 * we have two snap modes:
1539 * - pool global snaps
1540 * - snap existence/non-existence defined by snaps[] and snap_seq
1541 * - user managed snaps
1542 * - removal governed by removed_snaps
1543 *
1544 * we know which mode we're using based on whether removed_snaps is empty.
1545 * If nothing has been created, both functions report false.
1546 */
1547 bool is_pool_snaps_mode() const;
1548 bool is_unmanaged_snaps_mode() const;
1549 bool is_removed_snap(snapid_t s) const;
1550
1551 /*
1552 * build set of known-removed sets from either pool snaps or
1553 * explicit removed_snaps set.
1554 */
1555 void build_removed_snaps(interval_set<snapid_t>& rs) const;
1556 snapid_t snap_exists(const char *s) const;
1557 void add_snap(const char *n, utime_t stamp);
1558 void add_unmanaged_snap(uint64_t& snapid);
1559 void remove_snap(snapid_t s);
1560 void remove_unmanaged_snap(snapid_t s);
1561
1562 SnapContext get_snap_context() const;
1563
1564 /// hash a object name+namespace key to a hash position
1565 uint32_t hash_key(const string& key, const string& ns) const;
1566
1567 /// round a hash position down to a pg num
1568 uint32_t raw_hash_to_pg(uint32_t v) const;
1569
1570 /*
1571 * map a raw pg (with full precision ps) into an actual pg, for storage
1572 */
1573 pg_t raw_pg_to_pg(pg_t pg) const;
1574
1575 /*
1576 * map raw pg (full precision ps) into a placement seed. include
1577 * pool id in that value so that different pools don't use the same
1578 * seeds.
1579 */
1580 ps_t raw_pg_to_pps(pg_t pg) const;
1581
1582 /// choose a random hash position within a pg
1583 uint32_t get_random_pg_position(pg_t pgid, uint32_t seed) const;
1584
1585 void encode(bufferlist& bl, uint64_t features) const;
1586 void decode(bufferlist::iterator& bl);
1587
1588 static void generate_test_instances(list<pg_pool_t*>& o);
1589 };
1590 WRITE_CLASS_ENCODER_FEATURES(pg_pool_t)
1591
1592 ostream& operator<<(ostream& out, const pg_pool_t& p);
1593
1594
1595 /**
1596 * a summation of object stats
1597 *
1598 * This is just a container for object stats; we don't know what for.
1599 *
1600 * If you add members in object_stat_sum_t, you should make sure there are
1601 * not padding among these members.
1602 * You should also modify the padding_check function.
1603
1604 */
1605 struct object_stat_sum_t {
1606 /**************************************************************************
1607 * WARNING: be sure to update operator==, floor, and split when
1608 * adding/removing fields!
1609 **************************************************************************/
1610 int64_t num_bytes; // in bytes
1611 int64_t num_objects;
1612 int64_t num_object_clones;
1613 int64_t num_object_copies; // num_objects * num_replicas
1614 int64_t num_objects_missing_on_primary;
1615 int64_t num_objects_degraded;
1616 int64_t num_objects_unfound;
1617 int64_t num_rd;
1618 int64_t num_rd_kb;
1619 int64_t num_wr;
1620 int64_t num_wr_kb;
1621 int64_t num_scrub_errors; // total deep and shallow scrub errors
1622 int64_t num_objects_recovered;
1623 int64_t num_bytes_recovered;
1624 int64_t num_keys_recovered;
1625 int64_t num_shallow_scrub_errors;
1626 int64_t num_deep_scrub_errors;
1627 int64_t num_objects_dirty;
1628 int64_t num_whiteouts;
1629 int64_t num_objects_omap;
1630 int64_t num_objects_hit_set_archive;
1631 int64_t num_objects_misplaced;
1632 int64_t num_bytes_hit_set_archive;
1633 int64_t num_flush;
1634 int64_t num_flush_kb;
1635 int64_t num_evict;
1636 int64_t num_evict_kb;
1637 int64_t num_promote;
1638 int32_t num_flush_mode_high; // 1 when in high flush mode, otherwise 0
1639 int32_t num_flush_mode_low; // 1 when in low flush mode, otherwise 0
1640 int32_t num_evict_mode_some; // 1 when in evict some mode, otherwise 0
1641 int32_t num_evict_mode_full; // 1 when in evict full mode, otherwise 0
1642 int64_t num_objects_pinned;
1643 int64_t num_objects_missing;
1644 int64_t num_legacy_snapsets; ///< upper bound on pre-luminous-style SnapSets
1645
1646 object_stat_sum_t()
1647 : num_bytes(0),
1648 num_objects(0), num_object_clones(0), num_object_copies(0),
1649 num_objects_missing_on_primary(0), num_objects_degraded(0),
1650 num_objects_unfound(0),
1651 num_rd(0), num_rd_kb(0), num_wr(0), num_wr_kb(0),
1652 num_scrub_errors(0),
1653 num_objects_recovered(0),
1654 num_bytes_recovered(0),
1655 num_keys_recovered(0),
1656 num_shallow_scrub_errors(0),
1657 num_deep_scrub_errors(0),
1658 num_objects_dirty(0),
1659 num_whiteouts(0),
1660 num_objects_omap(0),
1661 num_objects_hit_set_archive(0),
1662 num_objects_misplaced(0),
1663 num_bytes_hit_set_archive(0),
1664 num_flush(0),
1665 num_flush_kb(0),
1666 num_evict(0),
1667 num_evict_kb(0),
1668 num_promote(0),
1669 num_flush_mode_high(0), num_flush_mode_low(0),
1670 num_evict_mode_some(0), num_evict_mode_full(0),
1671 num_objects_pinned(0),
1672 num_objects_missing(0),
1673 num_legacy_snapsets(0)
1674 {}
1675
1676 void floor(int64_t f) {
1677 #define FLOOR(x) if (x < f) x = f
1678 FLOOR(num_bytes);
1679 FLOOR(num_objects);
1680 FLOOR(num_object_clones);
1681 FLOOR(num_object_copies);
1682 FLOOR(num_objects_missing_on_primary);
1683 FLOOR(num_objects_missing);
1684 FLOOR(num_objects_degraded);
1685 FLOOR(num_objects_misplaced);
1686 FLOOR(num_objects_unfound);
1687 FLOOR(num_rd);
1688 FLOOR(num_rd_kb);
1689 FLOOR(num_wr);
1690 FLOOR(num_wr_kb);
1691 FLOOR(num_scrub_errors);
1692 FLOOR(num_shallow_scrub_errors);
1693 FLOOR(num_deep_scrub_errors);
1694 FLOOR(num_objects_recovered);
1695 FLOOR(num_bytes_recovered);
1696 FLOOR(num_keys_recovered);
1697 FLOOR(num_objects_dirty);
1698 FLOOR(num_whiteouts);
1699 FLOOR(num_objects_omap);
1700 FLOOR(num_objects_hit_set_archive);
1701 FLOOR(num_bytes_hit_set_archive);
1702 FLOOR(num_flush);
1703 FLOOR(num_flush_kb);
1704 FLOOR(num_evict);
1705 FLOOR(num_evict_kb);
1706 FLOOR(num_promote);
1707 FLOOR(num_flush_mode_high);
1708 FLOOR(num_flush_mode_low);
1709 FLOOR(num_evict_mode_some);
1710 FLOOR(num_evict_mode_full);
1711 FLOOR(num_objects_pinned);
1712 FLOOR(num_legacy_snapsets);
1713 #undef FLOOR
1714 }
1715
1716 void split(vector<object_stat_sum_t> &out) const {
1717 #define SPLIT(PARAM) \
1718 for (unsigned i = 0; i < out.size(); ++i) { \
1719 out[i].PARAM = PARAM / out.size(); \
1720 if (i < (PARAM % out.size())) { \
1721 out[i].PARAM++; \
1722 } \
1723 }
1724 #define SPLIT_PRESERVE_NONZERO(PARAM) \
1725 for (unsigned i = 0; i < out.size(); ++i) { \
1726 if (PARAM) \
1727 out[i].PARAM = 1 + PARAM / out.size(); \
1728 else \
1729 out[i].PARAM = 0; \
1730 }
1731
1732 SPLIT(num_bytes);
1733 SPLIT(num_objects);
1734 SPLIT(num_object_clones);
1735 SPLIT(num_object_copies);
1736 SPLIT(num_objects_missing_on_primary);
1737 SPLIT(num_objects_missing);
1738 SPLIT(num_objects_degraded);
1739 SPLIT(num_objects_misplaced);
1740 SPLIT(num_objects_unfound);
1741 SPLIT(num_rd);
1742 SPLIT(num_rd_kb);
1743 SPLIT(num_wr);
1744 SPLIT(num_wr_kb);
1745 SPLIT(num_scrub_errors);
1746 SPLIT(num_shallow_scrub_errors);
1747 SPLIT(num_deep_scrub_errors);
1748 SPLIT(num_objects_recovered);
1749 SPLIT(num_bytes_recovered);
1750 SPLIT(num_keys_recovered);
1751 SPLIT(num_objects_dirty);
1752 SPLIT(num_whiteouts);
1753 SPLIT(num_objects_omap);
1754 SPLIT(num_objects_hit_set_archive);
1755 SPLIT(num_bytes_hit_set_archive);
1756 SPLIT(num_flush);
1757 SPLIT(num_flush_kb);
1758 SPLIT(num_evict);
1759 SPLIT(num_evict_kb);
1760 SPLIT(num_promote);
1761 SPLIT(num_flush_mode_high);
1762 SPLIT(num_flush_mode_low);
1763 SPLIT(num_evict_mode_some);
1764 SPLIT(num_evict_mode_full);
1765 SPLIT(num_objects_pinned);
1766 SPLIT_PRESERVE_NONZERO(num_legacy_snapsets);
1767 #undef SPLIT
1768 #undef SPLIT_PRESERVE_NONZERO
1769 }
1770
1771 void clear() {
1772 memset(this, 0, sizeof(*this));
1773 }
1774
1775 void calc_copies(int nrep) {
1776 num_object_copies = nrep * num_objects;
1777 }
1778
1779 bool is_zero() const {
1780 return mem_is_zero((char*)this, sizeof(*this));
1781 }
1782
1783 void add(const object_stat_sum_t& o);
1784 void sub(const object_stat_sum_t& o);
1785
1786 void dump(Formatter *f) const;
1787 void padding_check() {
1788 static_assert(
1789 sizeof(object_stat_sum_t) ==
1790 sizeof(num_bytes) +
1791 sizeof(num_objects) +
1792 sizeof(num_object_clones) +
1793 sizeof(num_object_copies) +
1794 sizeof(num_objects_missing_on_primary) +
1795 sizeof(num_objects_degraded) +
1796 sizeof(num_objects_unfound) +
1797 sizeof(num_rd) +
1798 sizeof(num_rd_kb) +
1799 sizeof(num_wr) +
1800 sizeof(num_wr_kb) +
1801 sizeof(num_scrub_errors) +
1802 sizeof(num_objects_recovered) +
1803 sizeof(num_bytes_recovered) +
1804 sizeof(num_keys_recovered) +
1805 sizeof(num_shallow_scrub_errors) +
1806 sizeof(num_deep_scrub_errors) +
1807 sizeof(num_objects_dirty) +
1808 sizeof(num_whiteouts) +
1809 sizeof(num_objects_omap) +
1810 sizeof(num_objects_hit_set_archive) +
1811 sizeof(num_objects_misplaced) +
1812 sizeof(num_bytes_hit_set_archive) +
1813 sizeof(num_flush) +
1814 sizeof(num_flush_kb) +
1815 sizeof(num_evict) +
1816 sizeof(num_evict_kb) +
1817 sizeof(num_promote) +
1818 sizeof(num_flush_mode_high) +
1819 sizeof(num_flush_mode_low) +
1820 sizeof(num_evict_mode_some) +
1821 sizeof(num_evict_mode_full) +
1822 sizeof(num_objects_pinned) +
1823 sizeof(num_objects_missing) +
1824 sizeof(num_legacy_snapsets)
1825 ,
1826 "object_stat_sum_t have padding");
1827 }
1828 void encode(bufferlist& bl) const;
1829 void decode(bufferlist::iterator& bl);
1830 static void generate_test_instances(list<object_stat_sum_t*>& o);
1831 };
1832 WRITE_CLASS_ENCODER(object_stat_sum_t)
1833
1834 bool operator==(const object_stat_sum_t& l, const object_stat_sum_t& r);
1835
1836 /**
1837 * a collection of object stat sums
1838 *
1839 * This is a collection of stat sums over different categories.
1840 */
1841 struct object_stat_collection_t {
1842 /**************************************************************************
1843 * WARNING: be sure to update the operator== when adding/removing fields! *
1844 **************************************************************************/
1845 object_stat_sum_t sum;
1846
1847 void calc_copies(int nrep) {
1848 sum.calc_copies(nrep);
1849 }
1850
1851 void dump(Formatter *f) const;
1852 void encode(bufferlist& bl) const;
1853 void decode(bufferlist::iterator& bl);
1854 static void generate_test_instances(list<object_stat_collection_t*>& o);
1855
1856 bool is_zero() const {
1857 return sum.is_zero();
1858 }
1859
1860 void clear() {
1861 sum.clear();
1862 }
1863
1864 void floor(int64_t f) {
1865 sum.floor(f);
1866 }
1867
1868 void add(const object_stat_sum_t& o) {
1869 sum.add(o);
1870 }
1871
1872 void add(const object_stat_collection_t& o) {
1873 sum.add(o.sum);
1874 }
1875 void sub(const object_stat_collection_t& o) {
1876 sum.sub(o.sum);
1877 }
1878 };
1879 WRITE_CLASS_ENCODER(object_stat_collection_t)
1880
1881 inline bool operator==(const object_stat_collection_t& l,
1882 const object_stat_collection_t& r) {
1883 return l.sum == r.sum;
1884 }
1885
1886
1887 /** pg_stat
1888 * aggregate stats for a single PG.
1889 */
1890 struct pg_stat_t {
1891 /**************************************************************************
1892 * WARNING: be sure to update the operator== when adding/removing fields! *
1893 **************************************************************************/
1894 eversion_t version;
1895 version_t reported_seq; // sequence number
1896 epoch_t reported_epoch; // epoch of this report
1897 __u32 state;
1898 utime_t last_fresh; // last reported
1899 utime_t last_change; // new state != previous state
1900 utime_t last_active; // state & PG_STATE_ACTIVE
1901 utime_t last_peered; // state & PG_STATE_ACTIVE || state & PG_STATE_PEERED
1902 utime_t last_clean; // state & PG_STATE_CLEAN
1903 utime_t last_unstale; // (state & PG_STATE_STALE) == 0
1904 utime_t last_undegraded; // (state & PG_STATE_DEGRADED) == 0
1905 utime_t last_fullsized; // (state & PG_STATE_UNDERSIZED) == 0
1906
1907 eversion_t log_start; // (log_start,version]
1908 eversion_t ondisk_log_start; // there may be more on disk
1909
1910 epoch_t created;
1911 epoch_t last_epoch_clean;
1912 pg_t parent;
1913 __u32 parent_split_bits;
1914
1915 eversion_t last_scrub;
1916 eversion_t last_deep_scrub;
1917 utime_t last_scrub_stamp;
1918 utime_t last_deep_scrub_stamp;
1919 utime_t last_clean_scrub_stamp;
1920
1921 object_stat_collection_t stats;
1922
1923 int64_t log_size;
1924 int64_t ondisk_log_size; // >= active_log_size
1925
1926 vector<int32_t> up, acting;
1927 epoch_t mapping_epoch;
1928
1929 vector<int32_t> blocked_by; ///< osds on which the pg is blocked
1930
1931 utime_t last_became_active;
1932 utime_t last_became_peered;
1933
1934 /// up, acting primaries
1935 int32_t up_primary;
1936 int32_t acting_primary;
1937
1938 bool stats_invalid:1;
1939 /// true if num_objects_dirty is not accurate (because it was not
1940 /// maintained starting from pool creation)
1941 bool dirty_stats_invalid:1;
1942 bool omap_stats_invalid:1;
1943 bool hitset_stats_invalid:1;
1944 bool hitset_bytes_stats_invalid:1;
1945 bool pin_stats_invalid:1;
1946
1947 pg_stat_t()
1948 : reported_seq(0),
1949 reported_epoch(0),
1950 state(0),
1951 created(0), last_epoch_clean(0),
1952 parent_split_bits(0),
1953 log_size(0), ondisk_log_size(0),
1954 mapping_epoch(0),
1955 up_primary(-1),
1956 acting_primary(-1),
1957 stats_invalid(false),
1958 dirty_stats_invalid(false),
1959 omap_stats_invalid(false),
1960 hitset_stats_invalid(false),
1961 hitset_bytes_stats_invalid(false),
1962 pin_stats_invalid(false)
1963 { }
1964
1965 epoch_t get_effective_last_epoch_clean() const {
1966 if (state & PG_STATE_CLEAN) {
1967 // we are clean as of this report, and should thus take the
1968 // reported epoch
1969 return reported_epoch;
1970 } else {
1971 return last_epoch_clean;
1972 }
1973 }
1974
1975 pair<epoch_t, version_t> get_version_pair() const {
1976 return make_pair(reported_epoch, reported_seq);
1977 }
1978
1979 void floor(int64_t f) {
1980 stats.floor(f);
1981 if (log_size < f)
1982 log_size = f;
1983 if (ondisk_log_size < f)
1984 ondisk_log_size = f;
1985 }
1986
1987 void add(const pg_stat_t& o) {
1988 stats.add(o.stats);
1989 log_size += o.log_size;
1990 ondisk_log_size += o.ondisk_log_size;
1991 }
1992 void sub(const pg_stat_t& o) {
1993 stats.sub(o.stats);
1994 log_size -= o.log_size;
1995 ondisk_log_size -= o.ondisk_log_size;
1996 }
1997
1998 bool is_acting_osd(int32_t osd, bool primary) const;
1999 void dump(Formatter *f) const;
2000 void dump_brief(Formatter *f) const;
2001 void encode(bufferlist &bl) const;
2002 void decode(bufferlist::iterator &bl);
2003 static void generate_test_instances(list<pg_stat_t*>& o);
2004 };
2005 WRITE_CLASS_ENCODER(pg_stat_t)
2006
2007 bool operator==(const pg_stat_t& l, const pg_stat_t& r);
2008
2009 /*
2010 * summation over an entire pool
2011 */
2012 struct pool_stat_t {
2013 object_stat_collection_t stats;
2014 int64_t log_size;
2015 int64_t ondisk_log_size; // >= active_log_size
2016 int32_t up; ///< number of up replicas or shards
2017 int32_t acting; ///< number of acting replicas or shards
2018
2019 pool_stat_t() : log_size(0), ondisk_log_size(0), up(0), acting(0)
2020 { }
2021
2022 void floor(int64_t f) {
2023 stats.floor(f);
2024 if (log_size < f)
2025 log_size = f;
2026 if (ondisk_log_size < f)
2027 ondisk_log_size = f;
2028 if (up < f)
2029 up = f;
2030 if (acting < f)
2031 acting = f;
2032 }
2033
2034 void add(const pg_stat_t& o) {
2035 stats.add(o.stats);
2036 log_size += o.log_size;
2037 ondisk_log_size += o.ondisk_log_size;
2038 up += o.up.size();
2039 acting += o.acting.size();
2040 }
2041 void sub(const pg_stat_t& o) {
2042 stats.sub(o.stats);
2043 log_size -= o.log_size;
2044 ondisk_log_size -= o.ondisk_log_size;
2045 up -= o.up.size();
2046 acting -= o.acting.size();
2047 }
2048
2049 bool is_zero() const {
2050 return (stats.is_zero() &&
2051 log_size == 0 &&
2052 ondisk_log_size == 0 &&
2053 up == 0 &&
2054 acting == 0);
2055 }
2056
2057 void dump(Formatter *f) const;
2058 void encode(bufferlist &bl, uint64_t features) const;
2059 void decode(bufferlist::iterator &bl);
2060 static void generate_test_instances(list<pool_stat_t*>& o);
2061 };
2062 WRITE_CLASS_ENCODER_FEATURES(pool_stat_t)
2063
2064
2065 // -----------------------------------------
2066
2067 /**
2068 * pg_hit_set_info_t - information about a single recorded HitSet
2069 *
2070 * Track basic metadata about a HitSet, like the nubmer of insertions
2071 * and the time range it covers.
2072 */
2073 struct pg_hit_set_info_t {
2074 utime_t begin, end; ///< time interval
2075 eversion_t version; ///< version this HitSet object was written
2076 bool using_gmt; ///< use gmt for creating the hit_set archive object name
2077
2078 friend bool operator==(const pg_hit_set_info_t& l,
2079 const pg_hit_set_info_t& r) {
2080 return
2081 l.begin == r.begin &&
2082 l.end == r.end &&
2083 l.version == r.version &&
2084 l.using_gmt == r.using_gmt;
2085 }
2086
2087 explicit pg_hit_set_info_t(bool using_gmt = true)
2088 : using_gmt(using_gmt) {}
2089
2090 void encode(bufferlist &bl) const;
2091 void decode(bufferlist::iterator &bl);
2092 void dump(Formatter *f) const;
2093 static void generate_test_instances(list<pg_hit_set_info_t*>& o);
2094 };
2095 WRITE_CLASS_ENCODER(pg_hit_set_info_t)
2096
2097 /**
2098 * pg_hit_set_history_t - information about a history of hitsets
2099 *
2100 * Include information about the currently accumulating hit set as well
2101 * as archived/historical ones.
2102 */
2103 struct pg_hit_set_history_t {
2104 eversion_t current_last_update; ///< last version inserted into current set
2105 list<pg_hit_set_info_t> history; ///< archived sets, sorted oldest -> newest
2106
2107 friend bool operator==(const pg_hit_set_history_t& l,
2108 const pg_hit_set_history_t& r) {
2109 return
2110 l.current_last_update == r.current_last_update &&
2111 l.history == r.history;
2112 }
2113
2114 void encode(bufferlist &bl) const;
2115 void decode(bufferlist::iterator &bl);
2116 void dump(Formatter *f) const;
2117 static void generate_test_instances(list<pg_hit_set_history_t*>& o);
2118 };
2119 WRITE_CLASS_ENCODER(pg_hit_set_history_t)
2120
2121
2122 // -----------------------------------------
2123
2124 /**
2125 * pg_history_t - information about recent pg peering/mapping history
2126 *
2127 * This is aggressively shared between OSDs to bound the amount of past
2128 * history they need to worry about.
2129 */
2130 struct pg_history_t {
2131 epoch_t epoch_created; // epoch in which *pg* was created (pool or pg)
2132 epoch_t epoch_pool_created; // epoch in which *pool* was created
2133 // (note: may be pg creation epoch for
2134 // pre-luminous clusters)
2135 epoch_t last_epoch_started; // lower bound on last epoch started (anywhere, not necessarily locally)
2136 epoch_t last_interval_started; // first epoch of last_epoch_started interval
2137 epoch_t last_epoch_clean; // lower bound on last epoch the PG was completely clean.
2138 epoch_t last_interval_clean; // first epoch of last_epoch_clean interval
2139 epoch_t last_epoch_split; // as parent or child
2140 epoch_t last_epoch_marked_full; // pool or cluster
2141
2142 /**
2143 * In the event of a map discontinuity, same_*_since may reflect the first
2144 * map the osd has seen in the new map sequence rather than the actual start
2145 * of the interval. This is ok since a discontinuity at epoch e means there
2146 * must have been a clean interval between e and now and that we cannot be
2147 * in the active set during the interval containing e.
2148 */
2149 epoch_t same_up_since; // same acting set since
2150 epoch_t same_interval_since; // same acting AND up set since
2151 epoch_t same_primary_since; // same primary at least back through this epoch.
2152
2153 eversion_t last_scrub;
2154 eversion_t last_deep_scrub;
2155 utime_t last_scrub_stamp;
2156 utime_t last_deep_scrub_stamp;
2157 utime_t last_clean_scrub_stamp;
2158
2159 friend bool operator==(const pg_history_t& l, const pg_history_t& r) {
2160 return
2161 l.epoch_created == r.epoch_created &&
2162 l.epoch_pool_created == r.epoch_pool_created &&
2163 l.last_epoch_started == r.last_epoch_started &&
2164 l.last_interval_started == r.last_interval_started &&
2165 l.last_epoch_clean == r.last_epoch_clean &&
2166 l.last_interval_clean == r.last_interval_clean &&
2167 l.last_epoch_split == r.last_epoch_split &&
2168 l.last_epoch_marked_full == r.last_epoch_marked_full &&
2169 l.same_up_since == r.same_up_since &&
2170 l.same_interval_since == r.same_interval_since &&
2171 l.same_primary_since == r.same_primary_since &&
2172 l.last_scrub == r.last_scrub &&
2173 l.last_deep_scrub == r.last_deep_scrub &&
2174 l.last_scrub_stamp == r.last_scrub_stamp &&
2175 l.last_deep_scrub_stamp == r.last_deep_scrub_stamp &&
2176 l.last_clean_scrub_stamp == r.last_clean_scrub_stamp;
2177 }
2178
2179 pg_history_t()
2180 : epoch_created(0),
2181 epoch_pool_created(0),
2182 last_epoch_started(0),
2183 last_interval_started(0),
2184 last_epoch_clean(0),
2185 last_interval_clean(0),
2186 last_epoch_split(0),
2187 last_epoch_marked_full(0),
2188 same_up_since(0), same_interval_since(0), same_primary_since(0) {}
2189
2190 bool merge(const pg_history_t &other) {
2191 // Here, we only update the fields which cannot be calculated from the OSDmap.
2192 bool modified = false;
2193 if (epoch_created < other.epoch_created) {
2194 epoch_created = other.epoch_created;
2195 modified = true;
2196 }
2197 if (epoch_pool_created < other.epoch_pool_created) {
2198 // FIXME: for jewel compat only; this should either be 0 or always the
2199 // same value across all pg instances.
2200 epoch_pool_created = other.epoch_pool_created;
2201 modified = true;
2202 }
2203 if (last_epoch_started < other.last_epoch_started) {
2204 last_epoch_started = other.last_epoch_started;
2205 modified = true;
2206 }
2207 if (last_interval_started < other.last_interval_started) {
2208 last_interval_started = other.last_interval_started;
2209 modified = true;
2210 }
2211 if (last_epoch_clean < other.last_epoch_clean) {
2212 last_epoch_clean = other.last_epoch_clean;
2213 modified = true;
2214 }
2215 if (last_interval_clean < other.last_interval_clean) {
2216 last_interval_clean = other.last_interval_clean;
2217 modified = true;
2218 }
2219 if (last_epoch_split < other.last_epoch_split) {
2220 last_epoch_split = other.last_epoch_split;
2221 modified = true;
2222 }
2223 if (last_epoch_marked_full < other.last_epoch_marked_full) {
2224 last_epoch_marked_full = other.last_epoch_marked_full;
2225 modified = true;
2226 }
2227 if (other.last_scrub > last_scrub) {
2228 last_scrub = other.last_scrub;
2229 modified = true;
2230 }
2231 if (other.last_scrub_stamp > last_scrub_stamp) {
2232 last_scrub_stamp = other.last_scrub_stamp;
2233 modified = true;
2234 }
2235 if (other.last_deep_scrub > last_deep_scrub) {
2236 last_deep_scrub = other.last_deep_scrub;
2237 modified = true;
2238 }
2239 if (other.last_deep_scrub_stamp > last_deep_scrub_stamp) {
2240 last_deep_scrub_stamp = other.last_deep_scrub_stamp;
2241 modified = true;
2242 }
2243 if (other.last_clean_scrub_stamp > last_clean_scrub_stamp) {
2244 last_clean_scrub_stamp = other.last_clean_scrub_stamp;
2245 modified = true;
2246 }
2247 return modified;
2248 }
2249
2250 void encode(bufferlist& bl) const;
2251 void decode(bufferlist::iterator& p);
2252 void dump(Formatter *f) const;
2253 static void generate_test_instances(list<pg_history_t*>& o);
2254 };
2255 WRITE_CLASS_ENCODER(pg_history_t)
2256
2257 inline ostream& operator<<(ostream& out, const pg_history_t& h) {
2258 return out << "ec=" << h.epoch_created << "/" << h.epoch_pool_created
2259 << " lis/c " << h.last_interval_started
2260 << "/" << h.last_interval_clean
2261 << " les/c/f " << h.last_epoch_started << "/" << h.last_epoch_clean
2262 << "/" << h.last_epoch_marked_full
2263 << " " << h.same_up_since
2264 << "/" << h.same_interval_since
2265 << "/" << h.same_primary_since;
2266 }
2267
2268
2269 /**
2270 * pg_info_t - summary of PG statistics.
2271 *
2272 * some notes:
2273 * - last_complete implies we have all objects that existed as of that
2274 * stamp, OR a newer object, OR have already applied a later delete.
2275 * - if last_complete >= log.bottom, then we know pg contents thru log.head.
2276 * otherwise, we have no idea what the pg is supposed to contain.
2277 */
2278 struct pg_info_t {
2279 spg_t pgid;
2280 eversion_t last_update; ///< last object version applied to store.
2281 eversion_t last_complete; ///< last version pg was complete through.
2282 epoch_t last_epoch_started; ///< last epoch at which this pg started on this osd
2283 epoch_t last_interval_started; ///< first epoch of last_epoch_started interval
2284
2285 version_t last_user_version; ///< last user object version applied to store
2286
2287 eversion_t log_tail; ///< oldest log entry.
2288
2289 hobject_t last_backfill; ///< objects >= this and < last_complete may be missing
2290 bool last_backfill_bitwise; ///< true if last_backfill reflects a bitwise (vs nibblewise) sort
2291
2292 interval_set<snapid_t> purged_snaps;
2293
2294 pg_stat_t stats;
2295
2296 pg_history_t history;
2297 pg_hit_set_history_t hit_set;
2298
2299 friend bool operator==(const pg_info_t& l, const pg_info_t& r) {
2300 return
2301 l.pgid == r.pgid &&
2302 l.last_update == r.last_update &&
2303 l.last_complete == r.last_complete &&
2304 l.last_epoch_started == r.last_epoch_started &&
2305 l.last_interval_started == r.last_interval_started &&
2306 l.last_user_version == r.last_user_version &&
2307 l.log_tail == r.log_tail &&
2308 l.last_backfill == r.last_backfill &&
2309 l.last_backfill_bitwise == r.last_backfill_bitwise &&
2310 l.purged_snaps == r.purged_snaps &&
2311 l.stats == r.stats &&
2312 l.history == r.history &&
2313 l.hit_set == r.hit_set;
2314 }
2315
2316 pg_info_t()
2317 : last_epoch_started(0),
2318 last_interval_started(0),
2319 last_user_version(0),
2320 last_backfill(hobject_t::get_max()),
2321 last_backfill_bitwise(false)
2322 { }
2323 // cppcheck-suppress noExplicitConstructor
2324 pg_info_t(spg_t p)
2325 : pgid(p),
2326 last_epoch_started(0),
2327 last_interval_started(0),
2328 last_user_version(0),
2329 last_backfill(hobject_t::get_max()),
2330 last_backfill_bitwise(false)
2331 { }
2332
2333 void set_last_backfill(hobject_t pos) {
2334 last_backfill = pos;
2335 last_backfill_bitwise = true;
2336 }
2337
2338 bool is_empty() const { return last_update.version == 0; }
2339 bool dne() const { return history.epoch_created == 0; }
2340
2341 bool is_incomplete() const { return !last_backfill.is_max(); }
2342
2343 void encode(bufferlist& bl) const;
2344 void decode(bufferlist::iterator& p);
2345 void dump(Formatter *f) const;
2346 bool overlaps_with(const pg_info_t &oinfo) const {
2347 return last_update > oinfo.log_tail ?
2348 oinfo.last_update >= log_tail :
2349 last_update >= oinfo.log_tail;
2350 }
2351 static void generate_test_instances(list<pg_info_t*>& o);
2352 };
2353 WRITE_CLASS_ENCODER(pg_info_t)
2354
2355 inline ostream& operator<<(ostream& out, const pg_info_t& pgi)
2356 {
2357 out << pgi.pgid << "(";
2358 if (pgi.dne())
2359 out << " DNE";
2360 if (pgi.is_empty())
2361 out << " empty";
2362 else {
2363 out << " v " << pgi.last_update;
2364 if (pgi.last_complete != pgi.last_update)
2365 out << " lc " << pgi.last_complete;
2366 out << " (" << pgi.log_tail << "," << pgi.last_update << "]";
2367 }
2368 if (pgi.is_incomplete())
2369 out << " lb " << pgi.last_backfill
2370 << (pgi.last_backfill_bitwise ? " (bitwise)" : " (NIBBLEWISE)");
2371 //out << " c " << pgi.epoch_created;
2372 out << " local-lis/les=" << pgi.last_interval_started
2373 << "/" << pgi.last_epoch_started;
2374 out << " n=" << pgi.stats.stats.sum.num_objects;
2375 out << " " << pgi.history
2376 << ")";
2377 return out;
2378 }
2379
2380 /**
2381 * pg_fast_info_t - common pg_info_t fields
2382 *
2383 * These are the fields of pg_info_t (and children) that are updated for
2384 * most IO operations.
2385 *
2386 * ** WARNING **
2387 * Because we rely on these fields to be applied to the normal
2388 * info struct, adding a new field here that is not also new in info
2389 * means that we must set an incompat OSD feature bit!
2390 */
2391 struct pg_fast_info_t {
2392 eversion_t last_update;
2393 eversion_t last_complete;
2394 version_t last_user_version;
2395 struct { // pg_stat_t stats
2396 eversion_t version;
2397 version_t reported_seq;
2398 utime_t last_fresh;
2399 utime_t last_active;
2400 utime_t last_peered;
2401 utime_t last_clean;
2402 utime_t last_unstale;
2403 utime_t last_undegraded;
2404 utime_t last_fullsized;
2405 int64_t log_size; // (also ondisk_log_size, which has the same value)
2406 struct { // object_stat_collection_t stats;
2407 struct { // objct_stat_sum_t sum
2408 int64_t num_bytes; // in bytes
2409 int64_t num_objects;
2410 int64_t num_object_copies;
2411 int64_t num_rd;
2412 int64_t num_rd_kb;
2413 int64_t num_wr;
2414 int64_t num_wr_kb;
2415 int64_t num_objects_dirty;
2416 } sum;
2417 } stats;
2418 } stats;
2419
2420 void populate_from(const pg_info_t& info) {
2421 last_update = info.last_update;
2422 last_complete = info.last_complete;
2423 last_user_version = info.last_user_version;
2424 stats.version = info.stats.version;
2425 stats.reported_seq = info.stats.reported_seq;
2426 stats.last_fresh = info.stats.last_fresh;
2427 stats.last_active = info.stats.last_active;
2428 stats.last_peered = info.stats.last_peered;
2429 stats.last_clean = info.stats.last_clean;
2430 stats.last_unstale = info.stats.last_unstale;
2431 stats.last_undegraded = info.stats.last_undegraded;
2432 stats.last_fullsized = info.stats.last_fullsized;
2433 stats.log_size = info.stats.log_size;
2434 stats.stats.sum.num_bytes = info.stats.stats.sum.num_bytes;
2435 stats.stats.sum.num_objects = info.stats.stats.sum.num_objects;
2436 stats.stats.sum.num_object_copies = info.stats.stats.sum.num_object_copies;
2437 stats.stats.sum.num_rd = info.stats.stats.sum.num_rd;
2438 stats.stats.sum.num_rd_kb = info.stats.stats.sum.num_rd_kb;
2439 stats.stats.sum.num_wr = info.stats.stats.sum.num_wr;
2440 stats.stats.sum.num_wr_kb = info.stats.stats.sum.num_wr_kb;
2441 stats.stats.sum.num_objects_dirty = info.stats.stats.sum.num_objects_dirty;
2442 }
2443
2444 bool try_apply_to(pg_info_t* info) {
2445 if (last_update <= info->last_update)
2446 return false;
2447 info->last_update = last_update;
2448 info->last_complete = last_complete;
2449 info->last_user_version = last_user_version;
2450 info->stats.version = stats.version;
2451 info->stats.reported_seq = stats.reported_seq;
2452 info->stats.last_fresh = stats.last_fresh;
2453 info->stats.last_active = stats.last_active;
2454 info->stats.last_peered = stats.last_peered;
2455 info->stats.last_clean = stats.last_clean;
2456 info->stats.last_unstale = stats.last_unstale;
2457 info->stats.last_undegraded = stats.last_undegraded;
2458 info->stats.last_fullsized = stats.last_fullsized;
2459 info->stats.log_size = stats.log_size;
2460 info->stats.ondisk_log_size = stats.log_size;
2461 info->stats.stats.sum.num_bytes = stats.stats.sum.num_bytes;
2462 info->stats.stats.sum.num_objects = stats.stats.sum.num_objects;
2463 info->stats.stats.sum.num_object_copies = stats.stats.sum.num_object_copies;
2464 info->stats.stats.sum.num_rd = stats.stats.sum.num_rd;
2465 info->stats.stats.sum.num_rd_kb = stats.stats.sum.num_rd_kb;
2466 info->stats.stats.sum.num_wr = stats.stats.sum.num_wr;
2467 info->stats.stats.sum.num_wr_kb = stats.stats.sum.num_wr_kb;
2468 info->stats.stats.sum.num_objects_dirty = stats.stats.sum.num_objects_dirty;
2469 return true;
2470 }
2471
2472 void encode(bufferlist& bl) const {
2473 ENCODE_START(1, 1, bl);
2474 ::encode(last_update, bl);
2475 ::encode(last_complete, bl);
2476 ::encode(last_user_version, bl);
2477 ::encode(stats.version, bl);
2478 ::encode(stats.reported_seq, bl);
2479 ::encode(stats.last_fresh, bl);
2480 ::encode(stats.last_active, bl);
2481 ::encode(stats.last_peered, bl);
2482 ::encode(stats.last_clean, bl);
2483 ::encode(stats.last_unstale, bl);
2484 ::encode(stats.last_undegraded, bl);
2485 ::encode(stats.last_fullsized, bl);
2486 ::encode(stats.log_size, bl);
2487 ::encode(stats.stats.sum.num_bytes, bl);
2488 ::encode(stats.stats.sum.num_objects, bl);
2489 ::encode(stats.stats.sum.num_object_copies, bl);
2490 ::encode(stats.stats.sum.num_rd, bl);
2491 ::encode(stats.stats.sum.num_rd_kb, bl);
2492 ::encode(stats.stats.sum.num_wr, bl);
2493 ::encode(stats.stats.sum.num_wr_kb, bl);
2494 ::encode(stats.stats.sum.num_objects_dirty, bl);
2495 ENCODE_FINISH(bl);
2496 }
2497 void decode(bufferlist::iterator& p) {
2498 DECODE_START(1, p);
2499 ::decode(last_update, p);
2500 ::decode(last_complete, p);
2501 ::decode(last_user_version, p);
2502 ::decode(stats.version, p);
2503 ::decode(stats.reported_seq, p);
2504 ::decode(stats.last_fresh, p);
2505 ::decode(stats.last_active, p);
2506 ::decode(stats.last_peered, p);
2507 ::decode(stats.last_clean, p);
2508 ::decode(stats.last_unstale, p);
2509 ::decode(stats.last_undegraded, p);
2510 ::decode(stats.last_fullsized, p);
2511 ::decode(stats.log_size, p);
2512 ::decode(stats.stats.sum.num_bytes, p);
2513 ::decode(stats.stats.sum.num_objects, p);
2514 ::decode(stats.stats.sum.num_object_copies, p);
2515 ::decode(stats.stats.sum.num_rd, p);
2516 ::decode(stats.stats.sum.num_rd_kb, p);
2517 ::decode(stats.stats.sum.num_wr, p);
2518 ::decode(stats.stats.sum.num_wr_kb, p);
2519 ::decode(stats.stats.sum.num_objects_dirty, p);
2520 DECODE_FINISH(p);
2521 }
2522 };
2523 WRITE_CLASS_ENCODER(pg_fast_info_t)
2524
2525
2526 struct pg_notify_t {
2527 epoch_t query_epoch;
2528 epoch_t epoch_sent;
2529 pg_info_t info;
2530 shard_id_t to;
2531 shard_id_t from;
2532 pg_notify_t() :
2533 query_epoch(0), epoch_sent(0), to(shard_id_t::NO_SHARD),
2534 from(shard_id_t::NO_SHARD) {}
2535 pg_notify_t(
2536 shard_id_t to,
2537 shard_id_t from,
2538 epoch_t query_epoch,
2539 epoch_t epoch_sent,
2540 const pg_info_t &info)
2541 : query_epoch(query_epoch),
2542 epoch_sent(epoch_sent),
2543 info(info), to(to), from(from) {
2544 assert(from == info.pgid.shard);
2545 }
2546 void encode(bufferlist &bl) const;
2547 void decode(bufferlist::iterator &p);
2548 void dump(Formatter *f) const;
2549 static void generate_test_instances(list<pg_notify_t*> &o);
2550 };
2551 WRITE_CLASS_ENCODER(pg_notify_t)
2552 ostream &operator<<(ostream &lhs, const pg_notify_t &notify);
2553
2554
2555 class OSDMap;
2556 /**
2557 * PastIntervals -- information needed to determine the PriorSet and
2558 * the might_have_unfound set
2559 */
2560 class PastIntervals {
2561 public:
2562 struct pg_interval_t {
2563 vector<int32_t> up, acting;
2564 epoch_t first, last;
2565 bool maybe_went_rw;
2566 int32_t primary;
2567 int32_t up_primary;
2568
2569 pg_interval_t()
2570 : first(0), last(0),
2571 maybe_went_rw(false),
2572 primary(-1),
2573 up_primary(-1)
2574 {}
2575
2576 pg_interval_t(
2577 vector<int32_t> &&up,
2578 vector<int32_t> &&acting,
2579 epoch_t first,
2580 epoch_t last,
2581 bool maybe_went_rw,
2582 int32_t primary,
2583 int32_t up_primary)
2584 : up(up), acting(acting), first(first), last(last),
2585 maybe_went_rw(maybe_went_rw), primary(primary), up_primary(up_primary)
2586 {}
2587
2588 void encode(bufferlist& bl) const;
2589 void decode(bufferlist::iterator& bl);
2590 void dump(Formatter *f) const;
2591 static void generate_test_instances(list<pg_interval_t*>& o);
2592 };
2593
2594 PastIntervals() = default;
2595 PastIntervals(bool ec_pool, const OSDMap &osdmap) : PastIntervals() {
2596 update_type_from_map(ec_pool, osdmap);
2597 }
2598 PastIntervals(bool ec_pool, bool compact) : PastIntervals() {
2599 update_type(ec_pool, compact);
2600 }
2601 PastIntervals(PastIntervals &&rhs) = default;
2602 PastIntervals &operator=(PastIntervals &&rhs) = default;
2603
2604 PastIntervals(const PastIntervals &rhs);
2605 PastIntervals &operator=(const PastIntervals &rhs);
2606
2607 class interval_rep {
2608 public:
2609 virtual size_t size() const = 0;
2610 virtual bool empty() const = 0;
2611 virtual void clear() = 0;
2612 virtual pair<epoch_t, epoch_t> get_bounds() const = 0;
2613 virtual set<pg_shard_t> get_all_participants(
2614 bool ec_pool) const = 0;
2615 virtual void add_interval(bool ec_pool, const pg_interval_t &interval) = 0;
2616 virtual unique_ptr<interval_rep> clone() const = 0;
2617 virtual ostream &print(ostream &out) const = 0;
2618 virtual void encode(bufferlist &bl) const = 0;
2619 virtual void decode(bufferlist::iterator &bl) = 0;
2620 virtual void dump(Formatter *f) const = 0;
2621 virtual bool is_classic() const = 0;
2622 virtual void iterate_mayberw_back_to(
2623 bool ec_pool,
2624 epoch_t les,
2625 std::function<void(epoch_t, const set<pg_shard_t> &)> &&f) const = 0;
2626
2627 virtual bool has_full_intervals() const { return false; }
2628 virtual void iterate_all_intervals(
2629 std::function<void(const pg_interval_t &)> &&f) const {
2630 assert(!has_full_intervals());
2631 assert(0 == "not valid for this implementation");
2632 }
2633
2634 virtual ~interval_rep() {}
2635 };
2636 friend class pi_simple_rep;
2637 friend class pi_compact_rep;
2638 private:
2639
2640 unique_ptr<interval_rep> past_intervals;
2641
2642 PastIntervals(interval_rep *rep) : past_intervals(rep) {}
2643
2644 public:
2645 void add_interval(bool ec_pool, const pg_interval_t &interval) {
2646 assert(past_intervals);
2647 return past_intervals->add_interval(ec_pool, interval);
2648 }
2649
2650 bool is_classic() const {
2651 assert(past_intervals);
2652 return past_intervals->is_classic();
2653 }
2654
2655 void encode(bufferlist &bl) const {
2656 ENCODE_START(1, 1, bl);
2657 if (past_intervals) {
2658 __u8 type = is_classic() ? 1 : 2;
2659 ::encode(type, bl);
2660 past_intervals->encode(bl);
2661 } else {
2662 ::encode((__u8)0, bl);
2663 }
2664 ENCODE_FINISH(bl);
2665 }
2666 void encode_classic(bufferlist &bl) const {
2667 if (past_intervals) {
2668 assert(past_intervals->is_classic());
2669 past_intervals->encode(bl);
2670 } else {
2671 // it's a map<>
2672 ::encode((uint32_t)0, bl);
2673 }
2674 }
2675
2676 void decode(bufferlist::iterator &bl);
2677 void decode_classic(bufferlist::iterator &bl);
2678
2679 void dump(Formatter *f) const {
2680 assert(past_intervals);
2681 past_intervals->dump(f);
2682 }
2683 static void generate_test_instances(list<PastIntervals *> & o);
2684
2685 /**
2686 * Determines whether there is an interval change
2687 */
2688 static bool is_new_interval(
2689 int old_acting_primary,
2690 int new_acting_primary,
2691 const vector<int> &old_acting,
2692 const vector<int> &new_acting,
2693 int old_up_primary,
2694 int new_up_primary,
2695 const vector<int> &old_up,
2696 const vector<int> &new_up,
2697 int old_size,
2698 int new_size,
2699 int old_min_size,
2700 int new_min_size,
2701 unsigned old_pg_num,
2702 unsigned new_pg_num,
2703 bool old_sort_bitwise,
2704 bool new_sort_bitwise,
2705 bool old_recovery_deletes,
2706 bool new_recovery_deletes,
2707 pg_t pgid
2708 );
2709
2710 /**
2711 * Determines whether there is an interval change
2712 */
2713 static bool is_new_interval(
2714 int old_acting_primary, ///< [in] primary as of lastmap
2715 int new_acting_primary, ///< [in] primary as of lastmap
2716 const vector<int> &old_acting, ///< [in] acting as of lastmap
2717 const vector<int> &new_acting, ///< [in] acting as of osdmap
2718 int old_up_primary, ///< [in] up primary of lastmap
2719 int new_up_primary, ///< [in] up primary of osdmap
2720 const vector<int> &old_up, ///< [in] up as of lastmap
2721 const vector<int> &new_up, ///< [in] up as of osdmap
2722 ceph::shared_ptr<const OSDMap> osdmap, ///< [in] current map
2723 ceph::shared_ptr<const OSDMap> lastmap, ///< [in] last map
2724 pg_t pgid ///< [in] pgid for pg
2725 );
2726
2727 /**
2728 * Integrates a new map into *past_intervals, returns true
2729 * if an interval was closed out.
2730 */
2731 static bool check_new_interval(
2732 int old_acting_primary, ///< [in] primary as of lastmap
2733 int new_acting_primary, ///< [in] primary as of osdmap
2734 const vector<int> &old_acting, ///< [in] acting as of lastmap
2735 const vector<int> &new_acting, ///< [in] acting as of osdmap
2736 int old_up_primary, ///< [in] up primary of lastmap
2737 int new_up_primary, ///< [in] up primary of osdmap
2738 const vector<int> &old_up, ///< [in] up as of lastmap
2739 const vector<int> &new_up, ///< [in] up as of osdmap
2740 epoch_t same_interval_since, ///< [in] as of osdmap
2741 epoch_t last_epoch_clean, ///< [in] current
2742 ceph::shared_ptr<const OSDMap> osdmap, ///< [in] current map
2743 ceph::shared_ptr<const OSDMap> lastmap, ///< [in] last map
2744 pg_t pgid, ///< [in] pgid for pg
2745 IsPGRecoverablePredicate *could_have_gone_active, /// [in] predicate whether the pg can be active
2746 PastIntervals *past_intervals, ///< [out] intervals
2747 ostream *out = 0 ///< [out] debug ostream
2748 );
2749
2750 friend ostream& operator<<(ostream& out, const PastIntervals &i);
2751
2752 template <typename F>
2753 void iterate_mayberw_back_to(
2754 bool ec_pool,
2755 epoch_t les,
2756 F &&f) const {
2757 assert(past_intervals);
2758 past_intervals->iterate_mayberw_back_to(ec_pool, les, std::forward<F>(f));
2759 }
2760 void clear() {
2761 assert(past_intervals);
2762 past_intervals->clear();
2763 }
2764
2765 /**
2766 * Should return a value which gives an indication of the amount
2767 * of state contained
2768 */
2769 size_t size() const {
2770 assert(past_intervals);
2771 return past_intervals->size();
2772 }
2773
2774 bool empty() const {
2775 assert(past_intervals);
2776 return past_intervals->empty();
2777 }
2778
2779 void swap(PastIntervals &other) {
2780 using std::swap;
2781 swap(other.past_intervals, past_intervals);
2782 }
2783
2784 /**
2785 * Return all shards which have been in the acting set back to the
2786 * latest epoch to which we have trimmed except for pg_whoami
2787 */
2788 set<pg_shard_t> get_might_have_unfound(
2789 pg_shard_t pg_whoami,
2790 bool ec_pool) const {
2791 assert(past_intervals);
2792 auto ret = past_intervals->get_all_participants(ec_pool);
2793 ret.erase(pg_whoami);
2794 return ret;
2795 }
2796
2797 /**
2798 * Return all shards which we might want to talk to for peering
2799 */
2800 set<pg_shard_t> get_all_probe(
2801 bool ec_pool) const {
2802 assert(past_intervals);
2803 return past_intervals->get_all_participants(ec_pool);
2804 }
2805
2806 /* Return the set of epochs [start, end) represented by the
2807 * past_interval set.
2808 */
2809 pair<epoch_t, epoch_t> get_bounds() const {
2810 assert(past_intervals);
2811 return past_intervals->get_bounds();
2812 }
2813
2814 enum osd_state_t {
2815 UP,
2816 DOWN,
2817 DNE,
2818 LOST
2819 };
2820 struct PriorSet {
2821 bool ec_pool = false;
2822 set<pg_shard_t> probe; /// current+prior OSDs we need to probe.
2823 set<int> down; /// down osds that would normally be in @a probe and might be interesting.
2824 map<int, epoch_t> blocked_by; /// current lost_at values for any OSDs in cur set for which (re)marking them lost would affect cur set
2825
2826 bool pg_down = false; /// some down osds are included in @a cur; the DOWN pg state bit should be set.
2827 unique_ptr<IsPGRecoverablePredicate> pcontdec;
2828
2829 PriorSet() = default;
2830 PriorSet(PriorSet &&) = default;
2831 PriorSet &operator=(PriorSet &&) = default;
2832
2833 PriorSet &operator=(const PriorSet &) = delete;
2834 PriorSet(const PriorSet &) = delete;
2835
2836 bool operator==(const PriorSet &rhs) const {
2837 return (ec_pool == rhs.ec_pool) &&
2838 (probe == rhs.probe) &&
2839 (down == rhs.down) &&
2840 (blocked_by == rhs.blocked_by) &&
2841 (pg_down == rhs.pg_down);
2842 }
2843
2844 bool affected_by_map(
2845 const OSDMap &osdmap,
2846 const DoutPrefixProvider *dpp) const;
2847
2848 // For verifying tests
2849 PriorSet(
2850 bool ec_pool,
2851 set<pg_shard_t> probe,
2852 set<int> down,
2853 map<int, epoch_t> blocked_by,
2854 bool pg_down,
2855 IsPGRecoverablePredicate *pcontdec)
2856 : ec_pool(ec_pool), probe(probe), down(down), blocked_by(blocked_by),
2857 pg_down(pg_down), pcontdec(pcontdec) {}
2858
2859 private:
2860 template <typename F>
2861 PriorSet(
2862 const PastIntervals &past_intervals,
2863 bool ec_pool,
2864 epoch_t last_epoch_started,
2865 IsPGRecoverablePredicate *c,
2866 F f,
2867 const vector<int> &up,
2868 const vector<int> &acting,
2869 const DoutPrefixProvider *dpp);
2870
2871 friend class PastIntervals;
2872 };
2873
2874 void update_type(bool ec_pool, bool compact);
2875 void update_type_from_map(bool ec_pool, const OSDMap &osdmap);
2876
2877 template <typename... Args>
2878 PriorSet get_prior_set(Args&&... args) const {
2879 return PriorSet(*this, std::forward<Args>(args)...);
2880 }
2881 };
2882 WRITE_CLASS_ENCODER(PastIntervals)
2883
2884 ostream& operator<<(ostream& out, const PastIntervals::pg_interval_t& i);
2885 ostream& operator<<(ostream& out, const PastIntervals &i);
2886 ostream& operator<<(ostream& out, const PastIntervals::PriorSet &i);
2887
2888 template <typename F>
2889 PastIntervals::PriorSet::PriorSet(
2890 const PastIntervals &past_intervals,
2891 bool ec_pool,
2892 epoch_t last_epoch_started,
2893 IsPGRecoverablePredicate *c,
2894 F f,
2895 const vector<int> &up,
2896 const vector<int> &acting,
2897 const DoutPrefixProvider *dpp)
2898 : ec_pool(ec_pool), pg_down(false), pcontdec(c)
2899 {
2900 /*
2901 * We have to be careful to gracefully deal with situations like
2902 * so. Say we have a power outage or something that takes out both
2903 * OSDs, but the monitor doesn't mark them down in the same epoch.
2904 * The history may look like
2905 *
2906 * 1: A B
2907 * 2: B
2908 * 3: let's say B dies for good, too (say, from the power spike)
2909 * 4: A
2910 *
2911 * which makes it look like B may have applied updates to the PG
2912 * that we need in order to proceed. This sucks...
2913 *
2914 * To minimize the risk of this happening, we CANNOT go active if
2915 * _any_ OSDs in the prior set are down until we send an MOSDAlive
2916 * to the monitor such that the OSDMap sets osd_up_thru to an epoch.
2917 * Then, we have something like
2918 *
2919 * 1: A B
2920 * 2: B up_thru[B]=0
2921 * 3:
2922 * 4: A
2923 *
2924 * -> we can ignore B, bc it couldn't have gone active (alive_thru
2925 * still 0).
2926 *
2927 * or,
2928 *
2929 * 1: A B
2930 * 2: B up_thru[B]=0
2931 * 3: B up_thru[B]=2
2932 * 4:
2933 * 5: A
2934 *
2935 * -> we must wait for B, bc it was alive through 2, and could have
2936 * written to the pg.
2937 *
2938 * If B is really dead, then an administrator will need to manually
2939 * intervene by marking the OSD as "lost."
2940 */
2941
2942 // Include current acting and up nodes... not because they may
2943 // contain old data (this interval hasn't gone active, obviously),
2944 // but because we want their pg_info to inform choose_acting(), and
2945 // so that we know what they do/do not have explicitly before
2946 // sending them any new info/logs/whatever.
2947 for (unsigned i = 0; i < acting.size(); i++) {
2948 if (acting[i] != 0x7fffffff /* CRUSH_ITEM_NONE, can't import crush.h here */)
2949 probe.insert(pg_shard_t(acting[i], ec_pool ? shard_id_t(i) : shard_id_t::NO_SHARD));
2950 }
2951 // It may be possible to exclude the up nodes, but let's keep them in
2952 // there for now.
2953 for (unsigned i = 0; i < up.size(); i++) {
2954 if (up[i] != 0x7fffffff /* CRUSH_ITEM_NONE, can't import crush.h here */)
2955 probe.insert(pg_shard_t(up[i], ec_pool ? shard_id_t(i) : shard_id_t::NO_SHARD));
2956 }
2957
2958 set<pg_shard_t> all_probe = past_intervals.get_all_probe(ec_pool);
2959 ldpp_dout(dpp, 10) << "build_prior all_probe " << all_probe << dendl;
2960 for (auto &&i: all_probe) {
2961 switch (f(0, i.osd, nullptr)) {
2962 case UP: {
2963 probe.insert(i);
2964 break;
2965 }
2966 case DNE:
2967 case LOST:
2968 case DOWN: {
2969 down.insert(i.osd);
2970 break;
2971 }
2972 }
2973 }
2974
2975 past_intervals.iterate_mayberw_back_to(
2976 ec_pool,
2977 last_epoch_started,
2978 [&](epoch_t start, const set<pg_shard_t> &acting) {
2979 ldpp_dout(dpp, 10) << "build_prior maybe_rw interval:" << start
2980 << ", acting: " << acting << dendl;
2981
2982 // look at candidate osds during this interval. each falls into
2983 // one of three categories: up, down (but potentially
2984 // interesting), or lost (down, but we won't wait for it).
2985 set<pg_shard_t> up_now;
2986 map<int, epoch_t> candidate_blocked_by;
2987 // any candidates down now (that might have useful data)
2988 bool any_down_now = false;
2989
2990 // consider ACTING osds
2991 for (auto &&so: acting) {
2992 epoch_t lost_at = 0;
2993 switch (f(start, so.osd, &lost_at)) {
2994 case UP: {
2995 // include past acting osds if they are up.
2996 up_now.insert(so);
2997 break;
2998 }
2999 case DNE: {
3000 ldpp_dout(dpp, 10) << "build_prior prior osd." << so.osd
3001 << " no longer exists" << dendl;
3002 break;
3003 }
3004 case LOST: {
3005 ldpp_dout(dpp, 10) << "build_prior prior osd." << so.osd
3006 << " is down, but lost_at " << lost_at << dendl;
3007 up_now.insert(so);
3008 break;
3009 }
3010 case DOWN: {
3011 ldpp_dout(dpp, 10) << "build_prior prior osd." << so.osd
3012 << " is down" << dendl;
3013 candidate_blocked_by[so.osd] = lost_at;
3014 any_down_now = true;
3015 break;
3016 }
3017 }
3018 }
3019
3020 // if not enough osds survived this interval, and we may have gone rw,
3021 // then we need to wait for one of those osds to recover to
3022 // ensure that we haven't lost any information.
3023 if (!(*pcontdec)(up_now) && any_down_now) {
3024 // fixme: how do we identify a "clean" shutdown anyway?
3025 ldpp_dout(dpp, 10) << "build_prior possibly went active+rw,"
3026 << " insufficient up; including down osds" << dendl;
3027 assert(!candidate_blocked_by.empty());
3028 pg_down = true;
3029 blocked_by.insert(
3030 candidate_blocked_by.begin(),
3031 candidate_blocked_by.end());
3032 }
3033 });
3034
3035 ldpp_dout(dpp, 10) << "build_prior final: probe " << probe
3036 << " down " << down
3037 << " blocked_by " << blocked_by
3038 << (pg_down ? " pg_down":"")
3039 << dendl;
3040 }
3041
3042 /**
3043 * pg_query_t - used to ask a peer for information about a pg.
3044 *
3045 * note: if version=0, type=LOG, then we just provide our full log.
3046 */
3047 struct pg_query_t {
3048 enum {
3049 INFO = 0,
3050 LOG = 1,
3051 MISSING = 4,
3052 FULLLOG = 5,
3053 };
3054 const char *get_type_name() const {
3055 switch (type) {
3056 case INFO: return "info";
3057 case LOG: return "log";
3058 case MISSING: return "missing";
3059 case FULLLOG: return "fulllog";
3060 default: return "???";
3061 }
3062 }
3063
3064 __s32 type;
3065 eversion_t since;
3066 pg_history_t history;
3067 epoch_t epoch_sent;
3068 shard_id_t to;
3069 shard_id_t from;
3070
3071 pg_query_t() : type(-1), epoch_sent(0), to(shard_id_t::NO_SHARD),
3072 from(shard_id_t::NO_SHARD) {}
3073 pg_query_t(
3074 int t,
3075 shard_id_t to,
3076 shard_id_t from,
3077 const pg_history_t& h,
3078 epoch_t epoch_sent)
3079 : type(t),
3080 history(h),
3081 epoch_sent(epoch_sent),
3082 to(to), from(from) {
3083 assert(t != LOG);
3084 }
3085 pg_query_t(
3086 int t,
3087 shard_id_t to,
3088 shard_id_t from,
3089 eversion_t s,
3090 const pg_history_t& h,
3091 epoch_t epoch_sent)
3092 : type(t), since(s), history(h),
3093 epoch_sent(epoch_sent), to(to), from(from) {
3094 assert(t == LOG);
3095 }
3096
3097 void encode(bufferlist &bl, uint64_t features) const;
3098 void decode(bufferlist::iterator &bl);
3099
3100 void dump(Formatter *f) const;
3101 static void generate_test_instances(list<pg_query_t*>& o);
3102 };
3103 WRITE_CLASS_ENCODER_FEATURES(pg_query_t)
3104
3105 inline ostream& operator<<(ostream& out, const pg_query_t& q) {
3106 out << "query(" << q.get_type_name() << " " << q.since;
3107 if (q.type == pg_query_t::LOG)
3108 out << " " << q.history;
3109 out << ")";
3110 return out;
3111 }
3112
3113 class PGBackend;
3114 class ObjectModDesc {
3115 bool can_local_rollback;
3116 bool rollback_info_completed;
3117
3118 // version required to decode, reflected in encode/decode version
3119 __u8 max_required_version = 1;
3120 public:
3121 class Visitor {
3122 public:
3123 virtual void append(uint64_t old_offset) {}
3124 virtual void setattrs(map<string, boost::optional<bufferlist> > &attrs) {}
3125 virtual void rmobject(version_t old_version) {}
3126 /**
3127 * Used to support the unfound_lost_delete log event: if the stashed
3128 * version exists, we unstash it, otherwise, we do nothing. This way
3129 * each replica rolls back to whatever state it had prior to the attempt
3130 * at mark unfound lost delete
3131 */
3132 virtual void try_rmobject(version_t old_version) {
3133 rmobject(old_version);
3134 }
3135 virtual void create() {}
3136 virtual void update_snaps(const set<snapid_t> &old_snaps) {}
3137 virtual void rollback_extents(
3138 version_t gen,
3139 const vector<pair<uint64_t, uint64_t> > &extents) {}
3140 virtual ~Visitor() {}
3141 };
3142 void visit(Visitor *visitor) const;
3143 mutable bufferlist bl;
3144 enum ModID {
3145 APPEND = 1,
3146 SETATTRS = 2,
3147 DELETE = 3,
3148 CREATE = 4,
3149 UPDATE_SNAPS = 5,
3150 TRY_DELETE = 6,
3151 ROLLBACK_EXTENTS = 7
3152 };
3153 ObjectModDesc() : can_local_rollback(true), rollback_info_completed(false) {
3154 bl.reassign_to_mempool(mempool::mempool_osd_pglog);
3155 }
3156 void claim(ObjectModDesc &other) {
3157 bl.clear();
3158 bl.claim(other.bl);
3159 can_local_rollback = other.can_local_rollback;
3160 rollback_info_completed = other.rollback_info_completed;
3161 }
3162 void claim_append(ObjectModDesc &other) {
3163 if (!can_local_rollback || rollback_info_completed)
3164 return;
3165 if (!other.can_local_rollback) {
3166 mark_unrollbackable();
3167 return;
3168 }
3169 bl.claim_append(other.bl);
3170 rollback_info_completed = other.rollback_info_completed;
3171 }
3172 void swap(ObjectModDesc &other) {
3173 bl.swap(other.bl);
3174
3175 using std::swap;
3176 swap(other.can_local_rollback, can_local_rollback);
3177 swap(other.rollback_info_completed, rollback_info_completed);
3178 swap(other.max_required_version, max_required_version);
3179 }
3180 void append_id(ModID id) {
3181 uint8_t _id(id);
3182 ::encode(_id, bl);
3183 }
3184 void append(uint64_t old_size) {
3185 if (!can_local_rollback || rollback_info_completed)
3186 return;
3187 ENCODE_START(1, 1, bl);
3188 append_id(APPEND);
3189 ::encode(old_size, bl);
3190 ENCODE_FINISH(bl);
3191 }
3192 void setattrs(map<string, boost::optional<bufferlist> > &old_attrs) {
3193 if (!can_local_rollback || rollback_info_completed)
3194 return;
3195 ENCODE_START(1, 1, bl);
3196 append_id(SETATTRS);
3197 ::encode(old_attrs, bl);
3198 ENCODE_FINISH(bl);
3199 }
3200 bool rmobject(version_t deletion_version) {
3201 if (!can_local_rollback || rollback_info_completed)
3202 return false;
3203 ENCODE_START(1, 1, bl);
3204 append_id(DELETE);
3205 ::encode(deletion_version, bl);
3206 ENCODE_FINISH(bl);
3207 rollback_info_completed = true;
3208 return true;
3209 }
3210 bool try_rmobject(version_t deletion_version) {
3211 if (!can_local_rollback || rollback_info_completed)
3212 return false;
3213 ENCODE_START(1, 1, bl);
3214 append_id(TRY_DELETE);
3215 ::encode(deletion_version, bl);
3216 ENCODE_FINISH(bl);
3217 rollback_info_completed = true;
3218 return true;
3219 }
3220 void create() {
3221 if (!can_local_rollback || rollback_info_completed)
3222 return;
3223 rollback_info_completed = true;
3224 ENCODE_START(1, 1, bl);
3225 append_id(CREATE);
3226 ENCODE_FINISH(bl);
3227 }
3228 void update_snaps(const set<snapid_t> &old_snaps) {
3229 if (!can_local_rollback || rollback_info_completed)
3230 return;
3231 ENCODE_START(1, 1, bl);
3232 append_id(UPDATE_SNAPS);
3233 ::encode(old_snaps, bl);
3234 ENCODE_FINISH(bl);
3235 }
3236 void rollback_extents(
3237 version_t gen, const vector<pair<uint64_t, uint64_t> > &extents) {
3238 assert(can_local_rollback);
3239 assert(!rollback_info_completed);
3240 if (max_required_version < 2)
3241 max_required_version = 2;
3242 ENCODE_START(2, 2, bl);
3243 append_id(ROLLBACK_EXTENTS);
3244 ::encode(gen, bl);
3245 ::encode(extents, bl);
3246 ENCODE_FINISH(bl);
3247 }
3248
3249 // cannot be rolled back
3250 void mark_unrollbackable() {
3251 can_local_rollback = false;
3252 bl.clear();
3253 }
3254 bool can_rollback() const {
3255 return can_local_rollback;
3256 }
3257 bool empty() const {
3258 return can_local_rollback && (bl.length() == 0);
3259 }
3260
3261 bool requires_kraken() const {
3262 return max_required_version >= 2;
3263 }
3264
3265 /**
3266 * Create fresh copy of bl bytes to avoid keeping large buffers around
3267 * in the case that bl contains ptrs which point into a much larger
3268 * message buffer
3269 */
3270 void trim_bl() const {
3271 if (bl.length() > 0)
3272 bl.rebuild();
3273 }
3274 void encode(bufferlist &bl) const;
3275 void decode(bufferlist::iterator &bl);
3276 void dump(Formatter *f) const;
3277 static void generate_test_instances(list<ObjectModDesc*>& o);
3278 };
3279 WRITE_CLASS_ENCODER(ObjectModDesc)
3280
3281
3282 /**
3283 * pg_log_entry_t - single entry/event in pg log
3284 *
3285 */
3286 struct pg_log_entry_t {
3287 enum {
3288 MODIFY = 1, // some unspecified modification (but not *all* modifications)
3289 CLONE = 2, // cloned object from head
3290 DELETE = 3, // deleted object
3291 BACKLOG = 4, // event invented by generate_backlog [deprecated]
3292 LOST_REVERT = 5, // lost new version, revert to an older version.
3293 LOST_DELETE = 6, // lost new version, revert to no object (deleted).
3294 LOST_MARK = 7, // lost new version, now EIO
3295 PROMOTE = 8, // promoted object from another tier
3296 CLEAN = 9, // mark an object clean
3297 ERROR = 10, // write that returned an error
3298 };
3299 static const char *get_op_name(int op) {
3300 switch (op) {
3301 case MODIFY:
3302 return "modify";
3303 case PROMOTE:
3304 return "promote";
3305 case CLONE:
3306 return "clone";
3307 case DELETE:
3308 return "delete";
3309 case BACKLOG:
3310 return "backlog";
3311 case LOST_REVERT:
3312 return "l_revert";
3313 case LOST_DELETE:
3314 return "l_delete";
3315 case LOST_MARK:
3316 return "l_mark";
3317 case CLEAN:
3318 return "clean";
3319 case ERROR:
3320 return "error";
3321 default:
3322 return "unknown";
3323 }
3324 }
3325 const char *get_op_name() const {
3326 return get_op_name(op);
3327 }
3328
3329 // describes state for a locally-rollbackable entry
3330 ObjectModDesc mod_desc;
3331 bufferlist snaps; // only for clone entries
3332 hobject_t soid;
3333 osd_reqid_t reqid; // caller+tid to uniquely identify request
3334 mempool::osd_pglog::vector<pair<osd_reqid_t, version_t> > extra_reqids;
3335 eversion_t version, prior_version, reverting_to;
3336 version_t user_version; // the user version for this entry
3337 utime_t mtime; // this is the _user_ mtime, mind you
3338 int32_t return_code; // only stored for ERRORs for dup detection
3339
3340 __s32 op;
3341 bool invalid_hash; // only when decoding sobject_t based entries
3342 bool invalid_pool; // only when decoding pool-less hobject based entries
3343
3344 pg_log_entry_t()
3345 : user_version(0), return_code(0), op(0),
3346 invalid_hash(false), invalid_pool(false) {
3347 snaps.reassign_to_mempool(mempool::mempool_osd_pglog);
3348 }
3349 pg_log_entry_t(int _op, const hobject_t& _soid,
3350 const eversion_t& v, const eversion_t& pv,
3351 version_t uv,
3352 const osd_reqid_t& rid, const utime_t& mt,
3353 int return_code)
3354 : soid(_soid), reqid(rid), version(v), prior_version(pv), user_version(uv),
3355 mtime(mt), return_code(return_code), op(_op),
3356 invalid_hash(false), invalid_pool(false) {
3357 snaps.reassign_to_mempool(mempool::mempool_osd_pglog);
3358 }
3359
3360 bool is_clone() const { return op == CLONE; }
3361 bool is_modify() const { return op == MODIFY; }
3362 bool is_promote() const { return op == PROMOTE; }
3363 bool is_clean() const { return op == CLEAN; }
3364 bool is_backlog() const { return op == BACKLOG; }
3365 bool is_lost_revert() const { return op == LOST_REVERT; }
3366 bool is_lost_delete() const { return op == LOST_DELETE; }
3367 bool is_lost_mark() const { return op == LOST_MARK; }
3368 bool is_error() const { return op == ERROR; }
3369
3370 bool is_update() const {
3371 return
3372 is_clone() || is_modify() || is_promote() || is_clean() ||
3373 is_backlog() || is_lost_revert() || is_lost_mark();
3374 }
3375 bool is_delete() const {
3376 return op == DELETE || op == LOST_DELETE;
3377 }
3378
3379 bool can_rollback() const {
3380 return mod_desc.can_rollback();
3381 }
3382
3383 void mark_unrollbackable() {
3384 mod_desc.mark_unrollbackable();
3385 }
3386
3387 bool requires_kraken() const {
3388 return mod_desc.requires_kraken();
3389 }
3390
3391 // Errors are only used for dup detection, whereas
3392 // the index by objects is used by recovery, copy_get,
3393 // and other facilities that don't expect or need to
3394 // be aware of error entries.
3395 bool object_is_indexed() const {
3396 return !is_error();
3397 }
3398
3399 bool reqid_is_indexed() const {
3400 return reqid != osd_reqid_t() &&
3401 (op == MODIFY || op == DELETE || op == ERROR);
3402 }
3403
3404 string get_key_name() const;
3405 void encode_with_checksum(bufferlist& bl) const;
3406 void decode_with_checksum(bufferlist::iterator& p);
3407
3408 void encode(bufferlist &bl) const;
3409 void decode(bufferlist::iterator &bl);
3410 void dump(Formatter *f) const;
3411 static void generate_test_instances(list<pg_log_entry_t*>& o);
3412
3413 };
3414 WRITE_CLASS_ENCODER(pg_log_entry_t)
3415
3416 ostream& operator<<(ostream& out, const pg_log_entry_t& e);
3417
3418 struct pg_log_dup_t {
3419 osd_reqid_t reqid; // caller+tid to uniquely identify request
3420 eversion_t version;
3421 version_t user_version; // the user version for this entry
3422 int32_t return_code; // only stored for ERRORs for dup detection
3423
3424 pg_log_dup_t()
3425 : user_version(0), return_code(0)
3426 {}
3427 explicit pg_log_dup_t(const pg_log_entry_t& entry)
3428 : reqid(entry.reqid), version(entry.version),
3429 user_version(entry.user_version), return_code(entry.return_code)
3430 {}
3431 pg_log_dup_t(const eversion_t& v, version_t uv,
3432 const osd_reqid_t& rid, int return_code)
3433 : reqid(rid), version(v), user_version(uv),
3434 return_code(return_code)
3435 {}
3436
3437 string get_key_name() const;
3438 void encode(bufferlist &bl) const;
3439 void decode(bufferlist::iterator &bl);
3440 void dump(Formatter *f) const;
3441 static void generate_test_instances(list<pg_log_dup_t*>& o);
3442
3443 friend std::ostream& operator<<(std::ostream& out, const pg_log_dup_t& e);
3444 };
3445 WRITE_CLASS_ENCODER(pg_log_dup_t)
3446
3447 std::ostream& operator<<(std::ostream& out, const pg_log_dup_t& e);
3448
3449 /**
3450 * pg_log_t - incremental log of recent pg changes.
3451 *
3452 * serves as a recovery queue for recent changes.
3453 */
3454 struct pg_log_t {
3455 /*
3456 * head - newest entry (update|delete)
3457 * tail - entry previous to oldest (update|delete) for which we have
3458 * complete negative information.
3459 * i.e. we can infer pg contents for any store whose last_update >= tail.
3460 */
3461 eversion_t head; // newest entry
3462 eversion_t tail; // version prior to oldest
3463
3464 protected:
3465 // We can rollback rollback-able entries > can_rollback_to
3466 eversion_t can_rollback_to;
3467
3468 // always <= can_rollback_to, indicates how far stashed rollback
3469 // data can be found
3470 eversion_t rollback_info_trimmed_to;
3471
3472 public:
3473 // the actual log
3474 mempool::osd_pglog::list<pg_log_entry_t> log;
3475
3476 // entries just for dup op detection ordered oldest to newest
3477 mempool::osd_pglog::list<pg_log_dup_t> dups;
3478
3479 pg_log_t() = default;
3480 pg_log_t(const eversion_t &last_update,
3481 const eversion_t &log_tail,
3482 const eversion_t &can_rollback_to,
3483 const eversion_t &rollback_info_trimmed_to,
3484 mempool::osd_pglog::list<pg_log_entry_t> &&entries,
3485 mempool::osd_pglog::list<pg_log_dup_t> &&dup_entries)
3486 : head(last_update), tail(log_tail), can_rollback_to(can_rollback_to),
3487 rollback_info_trimmed_to(rollback_info_trimmed_to),
3488 log(std::move(entries)), dups(std::move(dup_entries)) {}
3489 pg_log_t(const eversion_t &last_update,
3490 const eversion_t &log_tail,
3491 const eversion_t &can_rollback_to,
3492 const eversion_t &rollback_info_trimmed_to,
3493 const std::list<pg_log_entry_t> &entries,
3494 const std::list<pg_log_dup_t> &dup_entries)
3495 : head(last_update), tail(log_tail), can_rollback_to(can_rollback_to),
3496 rollback_info_trimmed_to(rollback_info_trimmed_to) {
3497 for (auto &&entry: entries) {
3498 log.push_back(entry);
3499 }
3500 for (auto &&entry: dup_entries) {
3501 dups.push_back(entry);
3502 }
3503 }
3504
3505 void clear() {
3506 eversion_t z;
3507 rollback_info_trimmed_to = can_rollback_to = head = tail = z;
3508 log.clear();
3509 dups.clear();
3510 }
3511
3512 eversion_t get_rollback_info_trimmed_to() const {
3513 return rollback_info_trimmed_to;
3514 }
3515 eversion_t get_can_rollback_to() const {
3516 return can_rollback_to;
3517 }
3518
3519
3520 pg_log_t split_out_child(pg_t child_pgid, unsigned split_bits) {
3521 mempool::osd_pglog::list<pg_log_entry_t> oldlog, childlog;
3522 oldlog.swap(log);
3523
3524 eversion_t old_tail;
3525 unsigned mask = ~((~0)<<split_bits);
3526 for (auto i = oldlog.begin();
3527 i != oldlog.end();
3528 ) {
3529 if ((i->soid.get_hash() & mask) == child_pgid.m_seed) {
3530 childlog.push_back(*i);
3531 } else {
3532 log.push_back(*i);
3533 }
3534 oldlog.erase(i++);
3535 }
3536
3537 // osd_reqid is unique, so it doesn't matter if there are extra
3538 // dup entries in each pg. To avoid storing oid with the dup
3539 // entries, just copy the whole list.
3540 auto childdups(dups);
3541
3542 return pg_log_t(
3543 head,
3544 tail,
3545 can_rollback_to,
3546 rollback_info_trimmed_to,
3547 std::move(childlog),
3548 std::move(childdups));
3549 }
3550
3551 mempool::osd_pglog::list<pg_log_entry_t> rewind_from_head(eversion_t newhead) {
3552 assert(newhead >= tail);
3553
3554 mempool::osd_pglog::list<pg_log_entry_t>::iterator p = log.end();
3555 mempool::osd_pglog::list<pg_log_entry_t> divergent;
3556 while (true) {
3557 if (p == log.begin()) {
3558 // yikes, the whole thing is divergent!
3559 using std::swap;
3560 swap(divergent, log);
3561 break;
3562 }
3563 --p;
3564 if (p->version.version <= newhead.version) {
3565 /*
3566 * look at eversion.version here. we want to avoid a situation like:
3567 * our log: 100'10 (0'0) m 10000004d3a.00000000/head by client4225.1:18529
3568 * new log: 122'10 (0'0) m 10000004d3a.00000000/head by client4225.1:18529
3569 * lower_bound = 100'9
3570 * i.e, same request, different version. If the eversion.version is > the
3571 * lower_bound, we it is divergent.
3572 */
3573 ++p;
3574 divergent.splice(divergent.begin(), log, p, log.end());
3575 break;
3576 }
3577 assert(p->version > newhead);
3578 }
3579 head = newhead;
3580
3581 if (can_rollback_to > newhead)
3582 can_rollback_to = newhead;
3583
3584 if (rollback_info_trimmed_to > newhead)
3585 rollback_info_trimmed_to = newhead;
3586
3587 return divergent;
3588 }
3589
3590 bool empty() const {
3591 return log.empty();
3592 }
3593
3594 bool null() const {
3595 return head.version == 0 && head.epoch == 0;
3596 }
3597
3598 size_t approx_size() const {
3599 return head.version - tail.version;
3600 }
3601
3602 static void filter_log(spg_t import_pgid, const OSDMap &curmap,
3603 const string &hit_set_namespace, const pg_log_t &in,
3604 pg_log_t &out, pg_log_t &reject);
3605
3606 /**
3607 * copy entries from the tail of another pg_log_t
3608 *
3609 * @param other pg_log_t to copy from
3610 * @param from copy entries after this version
3611 */
3612 void copy_after(const pg_log_t &other, eversion_t from);
3613
3614 /**
3615 * copy a range of entries from another pg_log_t
3616 *
3617 * @param other pg_log_t to copy from
3618 * @param from copy entries after this version
3619 * @param to up to and including this version
3620 */
3621 void copy_range(const pg_log_t &other, eversion_t from, eversion_t to);
3622
3623 /**
3624 * copy up to N entries
3625 *
3626 * @param other source log
3627 * @param max max number of entries to copy
3628 */
3629 void copy_up_to(const pg_log_t &other, int max);
3630
3631 ostream& print(ostream& out) const;
3632
3633 void encode(bufferlist &bl) const;
3634 void decode(bufferlist::iterator &bl, int64_t pool = -1);
3635 void dump(Formatter *f) const;
3636 static void generate_test_instances(list<pg_log_t*>& o);
3637 };
3638 WRITE_CLASS_ENCODER(pg_log_t)
3639
3640 inline ostream& operator<<(ostream& out, const pg_log_t& log)
3641 {
3642 out << "log((" << log.tail << "," << log.head << "], crt="
3643 << log.get_can_rollback_to() << ")";
3644 return out;
3645 }
3646
3647
3648 /**
3649 * pg_missing_t - summary of missing objects.
3650 *
3651 * kept in memory, as a supplement to pg_log_t
3652 * also used to pass missing info in messages.
3653 */
3654 struct pg_missing_item {
3655 eversion_t need, have;
3656 enum missing_flags_t {
3657 FLAG_NONE = 0,
3658 FLAG_DELETE = 1,
3659 } flags;
3660 pg_missing_item() : flags(FLAG_NONE) {}
3661 explicit pg_missing_item(eversion_t n) : need(n), flags(FLAG_NONE) {} // have no old version
3662 pg_missing_item(eversion_t n, eversion_t h, bool is_delete=false) : need(n), have(h) {
3663 set_delete(is_delete);
3664 }
3665
3666 void encode(bufferlist& bl, uint64_t features) const {
3667 if (HAVE_FEATURE(features, OSD_RECOVERY_DELETES)) {
3668 // encoding a zeroed eversion_t to differentiate between this and
3669 // legacy unversioned encoding - a need value of 0'0 is not
3670 // possible. This can be replaced with the legacy encoding
3671 // macros post-luminous.
3672 eversion_t e;
3673 ::encode(e, bl);
3674 ::encode(need, bl);
3675 ::encode(have, bl);
3676 ::encode(static_cast<uint8_t>(flags), bl);
3677 } else {
3678 // legacy unversioned encoding
3679 ::encode(need, bl);
3680 ::encode(have, bl);
3681 }
3682 }
3683 void decode(bufferlist::iterator& bl) {
3684 eversion_t e;
3685 ::decode(e, bl);
3686 if (e != eversion_t()) {
3687 // legacy encoding, this is the need value
3688 need = e;
3689 ::decode(have, bl);
3690 } else {
3691 ::decode(need, bl);
3692 ::decode(have, bl);
3693 uint8_t f;
3694 ::decode(f, bl);
3695 flags = static_cast<missing_flags_t>(f);
3696 }
3697 }
3698
3699 void set_delete(bool is_delete) {
3700 flags = is_delete ? FLAG_DELETE : FLAG_NONE;
3701 }
3702
3703 bool is_delete() const {
3704 return (flags & FLAG_DELETE) == FLAG_DELETE;
3705 }
3706
3707 string flag_str() const {
3708 if (flags == FLAG_NONE) {
3709 return "none";
3710 } else {
3711 return "delete";
3712 }
3713 }
3714
3715 void dump(Formatter *f) const {
3716 f->dump_stream("need") << need;
3717 f->dump_stream("have") << have;
3718 f->dump_stream("flags") << flag_str();
3719 }
3720 static void generate_test_instances(list<pg_missing_item*>& o) {
3721 o.push_back(new pg_missing_item);
3722 o.push_back(new pg_missing_item);
3723 o.back()->need = eversion_t(1, 2);
3724 o.back()->have = eversion_t(1, 1);
3725 o.push_back(new pg_missing_item);
3726 o.back()->need = eversion_t(3, 5);
3727 o.back()->have = eversion_t(3, 4);
3728 o.back()->flags = FLAG_DELETE;
3729 }
3730 bool operator==(const pg_missing_item &rhs) const {
3731 return need == rhs.need && have == rhs.have && flags == rhs.flags;
3732 }
3733 bool operator!=(const pg_missing_item &rhs) const {
3734 return !(*this == rhs);
3735 }
3736 };
3737 WRITE_CLASS_ENCODER_FEATURES(pg_missing_item)
3738 ostream& operator<<(ostream& out, const pg_missing_item &item);
3739
3740 class pg_missing_const_i {
3741 public:
3742 virtual const map<hobject_t, pg_missing_item> &
3743 get_items() const = 0;
3744 virtual const map<version_t, hobject_t> &get_rmissing() const = 0;
3745 virtual bool get_may_include_deletes() const = 0;
3746 virtual unsigned int num_missing() const = 0;
3747 virtual bool have_missing() const = 0;
3748 virtual bool is_missing(const hobject_t& oid, pg_missing_item *out = nullptr) const = 0;
3749 virtual bool is_missing(const hobject_t& oid, eversion_t v) const = 0;
3750 virtual eversion_t have_old(const hobject_t& oid) const = 0;
3751 virtual ~pg_missing_const_i() {}
3752 };
3753
3754
3755 template <bool Track>
3756 class ChangeTracker {
3757 public:
3758 void changed(const hobject_t &obj) {}
3759 template <typename F>
3760 void get_changed(F &&f) const {}
3761 void flush() {}
3762 bool is_clean() const {
3763 return true;
3764 }
3765 };
3766 template <>
3767 class ChangeTracker<true> {
3768 set<hobject_t> _changed;
3769 public:
3770 void changed(const hobject_t &obj) {
3771 _changed.insert(obj);
3772 }
3773 template <typename F>
3774 void get_changed(F &&f) const {
3775 for (auto const &i: _changed) {
3776 f(i);
3777 }
3778 }
3779 void flush() {
3780 _changed.clear();
3781 }
3782 bool is_clean() const {
3783 return _changed.empty();
3784 }
3785 };
3786
3787 template <bool TrackChanges>
3788 class pg_missing_set : public pg_missing_const_i {
3789 using item = pg_missing_item;
3790 map<hobject_t, item> missing; // oid -> (need v, have v)
3791 map<version_t, hobject_t> rmissing; // v -> oid
3792 ChangeTracker<TrackChanges> tracker;
3793
3794 public:
3795 pg_missing_set() = default;
3796
3797 template <typename missing_type>
3798 pg_missing_set(const missing_type &m) {
3799 missing = m.get_items();
3800 rmissing = m.get_rmissing();
3801 may_include_deletes = m.get_may_include_deletes();
3802 for (auto &&i: missing)
3803 tracker.changed(i.first);
3804 }
3805
3806 bool may_include_deletes = false;
3807
3808 const map<hobject_t, item> &get_items() const override {
3809 return missing;
3810 }
3811 const map<version_t, hobject_t> &get_rmissing() const override {
3812 return rmissing;
3813 }
3814 bool get_may_include_deletes() const override {
3815 return may_include_deletes;
3816 }
3817 unsigned int num_missing() const override {
3818 return missing.size();
3819 }
3820 bool have_missing() const override {
3821 return !missing.empty();
3822 }
3823 bool is_missing(const hobject_t& oid, pg_missing_item *out = nullptr) const override {
3824 auto iter = missing.find(oid);
3825 if (iter == missing.end())
3826 return false;
3827 if (out)
3828 *out = iter->second;
3829 return true;
3830 }
3831 bool is_missing(const hobject_t& oid, eversion_t v) const override {
3832 map<hobject_t, item>::const_iterator m =
3833 missing.find(oid);
3834 if (m == missing.end())
3835 return false;
3836 const item &item(m->second);
3837 if (item.need > v)
3838 return false;
3839 return true;
3840 }
3841 eversion_t have_old(const hobject_t& oid) const override {
3842 map<hobject_t, item>::const_iterator m =
3843 missing.find(oid);
3844 if (m == missing.end())
3845 return eversion_t();
3846 const item &item(m->second);
3847 return item.have;
3848 }
3849
3850 void claim(pg_missing_set& o) {
3851 static_assert(!TrackChanges, "Can't use claim with TrackChanges");
3852 missing.swap(o.missing);
3853 rmissing.swap(o.rmissing);
3854 }
3855
3856 /*
3857 * this needs to be called in log order as we extend the log. it
3858 * assumes missing is accurate up through the previous log entry.
3859 */
3860 void add_next_event(const pg_log_entry_t& e) {
3861 map<hobject_t, item>::iterator missing_it;
3862 missing_it = missing.find(e.soid);
3863 bool is_missing_divergent_item = missing_it != missing.end();
3864 if (e.prior_version == eversion_t() || e.is_clone()) {
3865 // new object.
3866 if (is_missing_divergent_item) { // use iterator
3867 rmissing.erase((missing_it->second).need.version);
3868 missing_it->second = item(e.version, eversion_t(), e.is_delete()); // .have = nil
3869 } else // create new element in missing map
3870 missing[e.soid] = item(e.version, eversion_t(), e.is_delete()); // .have = nil
3871 } else if (is_missing_divergent_item) {
3872 // already missing (prior).
3873 rmissing.erase((missing_it->second).need.version);
3874 (missing_it->second).need = e.version; // leave .have unchanged.
3875 missing_it->second.set_delete(e.is_delete());
3876 } else if (e.is_backlog()) {
3877 // May not have prior version
3878 assert(0 == "these don't exist anymore");
3879 } else {
3880 // not missing, we must have prior_version (if any)
3881 assert(!is_missing_divergent_item);
3882 missing[e.soid] = item(e.version, e.prior_version, e.is_delete());
3883 }
3884 rmissing[e.version.version] = e.soid;
3885 tracker.changed(e.soid);
3886 }
3887
3888 void revise_need(hobject_t oid, eversion_t need, bool is_delete) {
3889 if (missing.count(oid)) {
3890 rmissing.erase(missing[oid].need.version);
3891 missing[oid].need = need; // no not adjust .have
3892 missing[oid].set_delete(is_delete);
3893 } else {
3894 missing[oid] = item(need, eversion_t(), is_delete);
3895 }
3896 rmissing[need.version] = oid;
3897
3898 tracker.changed(oid);
3899 }
3900
3901 void revise_have(hobject_t oid, eversion_t have) {
3902 if (missing.count(oid)) {
3903 tracker.changed(oid);
3904 missing[oid].have = have;
3905 }
3906 }
3907
3908 void add(const hobject_t& oid, eversion_t need, eversion_t have,
3909 bool is_delete) {
3910 missing[oid] = item(need, have, is_delete);
3911 rmissing[need.version] = oid;
3912 tracker.changed(oid);
3913 }
3914
3915 void rm(const hobject_t& oid, eversion_t v) {
3916 std::map<hobject_t, item>::iterator p = missing.find(oid);
3917 if (p != missing.end() && p->second.need <= v)
3918 rm(p);
3919 }
3920
3921 void rm(std::map<hobject_t, item>::const_iterator m) {
3922 tracker.changed(m->first);
3923 rmissing.erase(m->second.need.version);
3924 missing.erase(m);
3925 }
3926
3927 void got(const hobject_t& oid, eversion_t v) {
3928 std::map<hobject_t, item>::iterator p = missing.find(oid);
3929 assert(p != missing.end());
3930 assert(p->second.need <= v || p->second.is_delete());
3931 got(p);
3932 }
3933
3934 void got(std::map<hobject_t, item>::const_iterator m) {
3935 tracker.changed(m->first);
3936 rmissing.erase(m->second.need.version);
3937 missing.erase(m);
3938 }
3939
3940 void split_into(
3941 pg_t child_pgid,
3942 unsigned split_bits,
3943 pg_missing_set *omissing) {
3944 omissing->may_include_deletes = may_include_deletes;
3945 unsigned mask = ~((~0)<<split_bits);
3946 for (map<hobject_t, item>::iterator i = missing.begin();
3947 i != missing.end();
3948 ) {
3949 if ((i->first.get_hash() & mask) == child_pgid.m_seed) {
3950 omissing->add(i->first, i->second.need, i->second.have,
3951 i->second.is_delete());
3952 rm(i++);
3953 } else {
3954 ++i;
3955 }
3956 }
3957 }
3958
3959 void clear() {
3960 for (auto const &i: missing)
3961 tracker.changed(i.first);
3962 missing.clear();
3963 rmissing.clear();
3964 }
3965
3966 void encode(bufferlist &bl) const {
3967 ENCODE_START(4, 2, bl);
3968 ::encode(missing, bl, may_include_deletes ? CEPH_FEATURE_OSD_RECOVERY_DELETES : 0);
3969 ::encode(may_include_deletes, bl);
3970 ENCODE_FINISH(bl);
3971 }
3972 void decode(bufferlist::iterator &bl, int64_t pool = -1) {
3973 for (auto const &i: missing)
3974 tracker.changed(i.first);
3975 DECODE_START_LEGACY_COMPAT_LEN(4, 2, 2, bl);
3976 ::decode(missing, bl);
3977 if (struct_v >= 4) {
3978 ::decode(may_include_deletes, bl);
3979 }
3980 DECODE_FINISH(bl);
3981
3982 if (struct_v < 3) {
3983 // Handle hobject_t upgrade
3984 map<hobject_t, item> tmp;
3985 for (map<hobject_t, item>::iterator i =
3986 missing.begin();
3987 i != missing.end();
3988 ) {
3989 if (!i->first.is_max() && i->first.pool == -1) {
3990 hobject_t to_insert(i->first);
3991 to_insert.pool = pool;
3992 tmp[to_insert] = i->second;
3993 missing.erase(i++);
3994 } else {
3995 ++i;
3996 }
3997 }
3998 missing.insert(tmp.begin(), tmp.end());
3999 }
4000
4001 for (map<hobject_t,item>::iterator it =
4002 missing.begin();
4003 it != missing.end();
4004 ++it)
4005 rmissing[it->second.need.version] = it->first;
4006 for (auto const &i: missing)
4007 tracker.changed(i.first);
4008 }
4009 void dump(Formatter *f) const {
4010 f->open_array_section("missing");
4011 for (map<hobject_t,item>::const_iterator p =
4012 missing.begin(); p != missing.end(); ++p) {
4013 f->open_object_section("item");
4014 f->dump_stream("object") << p->first;
4015 p->second.dump(f);
4016 f->close_section();
4017 }
4018 f->close_section();
4019 f->dump_bool("may_include_deletes", may_include_deletes);
4020 }
4021 template <typename F>
4022 void filter_objects(F &&f) {
4023 for (auto i = missing.begin(); i != missing.end();) {
4024 if (f(i->first)) {
4025 rm(i++);
4026 } else {
4027 ++i;
4028 }
4029 }
4030 }
4031 static void generate_test_instances(list<pg_missing_set*>& o) {
4032 o.push_back(new pg_missing_set);
4033 o.push_back(new pg_missing_set);
4034 o.back()->add(
4035 hobject_t(object_t("foo"), "foo", 123, 456, 0, ""),
4036 eversion_t(5, 6), eversion_t(5, 1), false);
4037 o.push_back(new pg_missing_set);
4038 o.back()->add(
4039 hobject_t(object_t("foo"), "foo", 123, 456, 0, ""),
4040 eversion_t(5, 6), eversion_t(5, 1), true);
4041 o.back()->may_include_deletes = true;
4042 }
4043 template <typename F>
4044 void get_changed(F &&f) const {
4045 tracker.get_changed(f);
4046 }
4047 void flush() {
4048 tracker.flush();
4049 }
4050 bool is_clean() const {
4051 return tracker.is_clean();
4052 }
4053 template <typename missing_t>
4054 bool debug_verify_from_init(
4055 const missing_t &init_missing,
4056 ostream *oss) const {
4057 if (!TrackChanges)
4058 return true;
4059 auto check_missing(init_missing.get_items());
4060 tracker.get_changed([&](const hobject_t &hoid) {
4061 check_missing.erase(hoid);
4062 if (missing.count(hoid)) {
4063 check_missing.insert(*(missing.find(hoid)));
4064 }
4065 });
4066 bool ok = true;
4067 if (check_missing.size() != missing.size()) {
4068 if (oss) {
4069 *oss << "Size mismatch, check: " << check_missing.size()
4070 << ", actual: " << missing.size() << "\n";
4071 }
4072 ok = false;
4073 }
4074 for (auto &i: missing) {
4075 if (!check_missing.count(i.first)) {
4076 if (oss)
4077 *oss << "check_missing missing " << i.first << "\n";
4078 ok = false;
4079 } else if (check_missing[i.first] != i.second) {
4080 if (oss)
4081 *oss << "check_missing missing item mismatch on " << i.first
4082 << ", check: " << check_missing[i.first]
4083 << ", actual: " << i.second << "\n";
4084 ok = false;
4085 }
4086 }
4087 if (oss && !ok) {
4088 *oss << "check_missing: " << check_missing << "\n";
4089 set<hobject_t> changed;
4090 tracker.get_changed([&](const hobject_t &hoid) { changed.insert(hoid); });
4091 *oss << "changed: " << changed << "\n";
4092 }
4093 return ok;
4094 }
4095 };
4096 template <bool TrackChanges>
4097 void encode(
4098 const pg_missing_set<TrackChanges> &c, bufferlist &bl, uint64_t features=0) {
4099 ENCODE_DUMP_PRE();
4100 c.encode(bl);
4101 ENCODE_DUMP_POST(cl);
4102 }
4103 template <bool TrackChanges>
4104 void decode(pg_missing_set<TrackChanges> &c, bufferlist::iterator &p) {
4105 c.decode(p);
4106 }
4107 template <bool TrackChanges>
4108 ostream& operator<<(ostream& out, const pg_missing_set<TrackChanges> &missing)
4109 {
4110 out << "missing(" << missing.num_missing()
4111 << " may_include_deletes = " << missing.may_include_deletes;
4112 //if (missing.num_lost()) out << ", " << missing.num_lost() << " lost";
4113 out << ")";
4114 return out;
4115 }
4116
4117 using pg_missing_t = pg_missing_set<false>;
4118 using pg_missing_tracker_t = pg_missing_set<true>;
4119
4120
4121 /**
4122 * pg list objects response format
4123 *
4124 */
4125 struct pg_nls_response_t {
4126 collection_list_handle_t handle;
4127 list<librados::ListObjectImpl> entries;
4128
4129 void encode(bufferlist& bl) const {
4130 ENCODE_START(1, 1, bl);
4131 ::encode(handle, bl);
4132 __u32 n = (__u32)entries.size();
4133 ::encode(n, bl);
4134 for (list<librados::ListObjectImpl>::const_iterator i = entries.begin(); i != entries.end(); ++i) {
4135 ::encode(i->nspace, bl);
4136 ::encode(i->oid, bl);
4137 ::encode(i->locator, bl);
4138 }
4139 ENCODE_FINISH(bl);
4140 }
4141 void decode(bufferlist::iterator& bl) {
4142 DECODE_START(1, bl);
4143 ::decode(handle, bl);
4144 __u32 n;
4145 ::decode(n, bl);
4146 entries.clear();
4147 while (n--) {
4148 librados::ListObjectImpl i;
4149 ::decode(i.nspace, bl);
4150 ::decode(i.oid, bl);
4151 ::decode(i.locator, bl);
4152 entries.push_back(i);
4153 }
4154 DECODE_FINISH(bl);
4155 }
4156 void dump(Formatter *f) const {
4157 f->dump_stream("handle") << handle;
4158 f->open_array_section("entries");
4159 for (list<librados::ListObjectImpl>::const_iterator p = entries.begin(); p != entries.end(); ++p) {
4160 f->open_object_section("object");
4161 f->dump_string("namespace", p->nspace);
4162 f->dump_string("object", p->oid);
4163 f->dump_string("key", p->locator);
4164 f->close_section();
4165 }
4166 f->close_section();
4167 }
4168 static void generate_test_instances(list<pg_nls_response_t*>& o) {
4169 o.push_back(new pg_nls_response_t);
4170 o.push_back(new pg_nls_response_t);
4171 o.back()->handle = hobject_t(object_t("hi"), "key", 1, 2, -1, "");
4172 o.back()->entries.push_back(librados::ListObjectImpl("", "one", ""));
4173 o.back()->entries.push_back(librados::ListObjectImpl("", "two", "twokey"));
4174 o.back()->entries.push_back(librados::ListObjectImpl("", "three", ""));
4175 o.push_back(new pg_nls_response_t);
4176 o.back()->handle = hobject_t(object_t("hi"), "key", 3, 4, -1, "");
4177 o.back()->entries.push_back(librados::ListObjectImpl("n1", "n1one", ""));
4178 o.back()->entries.push_back(librados::ListObjectImpl("n1", "n1two", "n1twokey"));
4179 o.back()->entries.push_back(librados::ListObjectImpl("n1", "n1three", ""));
4180 o.push_back(new pg_nls_response_t);
4181 o.back()->handle = hobject_t(object_t("hi"), "key", 5, 6, -1, "");
4182 o.back()->entries.push_back(librados::ListObjectImpl("", "one", ""));
4183 o.back()->entries.push_back(librados::ListObjectImpl("", "two", "twokey"));
4184 o.back()->entries.push_back(librados::ListObjectImpl("", "three", ""));
4185 o.back()->entries.push_back(librados::ListObjectImpl("n1", "n1one", ""));
4186 o.back()->entries.push_back(librados::ListObjectImpl("n1", "n1two", "n1twokey"));
4187 o.back()->entries.push_back(librados::ListObjectImpl("n1", "n1three", ""));
4188 }
4189 };
4190
4191 WRITE_CLASS_ENCODER(pg_nls_response_t)
4192
4193 // For backwards compatibility with older OSD requests
4194 struct pg_ls_response_t {
4195 collection_list_handle_t handle;
4196 list<pair<object_t, string> > entries;
4197
4198 void encode(bufferlist& bl) const {
4199 __u8 v = 1;
4200 ::encode(v, bl);
4201 ::encode(handle, bl);
4202 ::encode(entries, bl);
4203 }
4204 void decode(bufferlist::iterator& bl) {
4205 __u8 v;
4206 ::decode(v, bl);
4207 assert(v == 1);
4208 ::decode(handle, bl);
4209 ::decode(entries, bl);
4210 }
4211 void dump(Formatter *f) const {
4212 f->dump_stream("handle") << handle;
4213 f->open_array_section("entries");
4214 for (list<pair<object_t, string> >::const_iterator p = entries.begin(); p != entries.end(); ++p) {
4215 f->open_object_section("object");
4216 f->dump_stream("object") << p->first;
4217 f->dump_string("key", p->second);
4218 f->close_section();
4219 }
4220 f->close_section();
4221 }
4222 static void generate_test_instances(list<pg_ls_response_t*>& o) {
4223 o.push_back(new pg_ls_response_t);
4224 o.push_back(new pg_ls_response_t);
4225 o.back()->handle = hobject_t(object_t("hi"), "key", 1, 2, -1, "");
4226 o.back()->entries.push_back(make_pair(object_t("one"), string()));
4227 o.back()->entries.push_back(make_pair(object_t("two"), string("twokey")));
4228 }
4229 };
4230
4231 WRITE_CLASS_ENCODER(pg_ls_response_t)
4232
4233 /**
4234 * object_copy_cursor_t
4235 */
4236 struct object_copy_cursor_t {
4237 uint64_t data_offset;
4238 string omap_offset;
4239 bool attr_complete;
4240 bool data_complete;
4241 bool omap_complete;
4242
4243 object_copy_cursor_t()
4244 : data_offset(0),
4245 attr_complete(false),
4246 data_complete(false),
4247 omap_complete(false)
4248 {}
4249
4250 bool is_initial() const {
4251 return !attr_complete && data_offset == 0 && omap_offset.empty();
4252 }
4253 bool is_complete() const {
4254 return attr_complete && data_complete && omap_complete;
4255 }
4256
4257 static void generate_test_instances(list<object_copy_cursor_t*>& o);
4258 void encode(bufferlist& bl) const;
4259 void decode(bufferlist::iterator &bl);
4260 void dump(Formatter *f) const;
4261 };
4262 WRITE_CLASS_ENCODER(object_copy_cursor_t)
4263
4264 /**
4265 * object_copy_data_t
4266 *
4267 * Return data from a copy request. The semantics are a little strange
4268 * as a result of the encoding's heritage.
4269 *
4270 * In particular, the sender unconditionally fills in the cursor (from what
4271 * it receives and sends), the size, and the mtime, but is responsible for
4272 * figuring out whether it should put any data in the attrs, data, or
4273 * omap members (corresponding to xattrs, object data, and the omap entries)
4274 * based on external data (the client includes a max amount to return with
4275 * the copy request). The client then looks into the attrs, data, and/or omap
4276 * based on the contents of the cursor.
4277 */
4278 struct object_copy_data_t {
4279 enum {
4280 FLAG_DATA_DIGEST = 1<<0,
4281 FLAG_OMAP_DIGEST = 1<<1,
4282 };
4283 object_copy_cursor_t cursor;
4284 uint64_t size;
4285 utime_t mtime;
4286 uint32_t data_digest, omap_digest;
4287 uint32_t flags;
4288 map<string, bufferlist> attrs;
4289 bufferlist data;
4290 bufferlist omap_header;
4291 bufferlist omap_data;
4292
4293 /// which snaps we are defined for (if a snap and not the head)
4294 vector<snapid_t> snaps;
4295 ///< latest snap seq for the object (if head)
4296 snapid_t snap_seq;
4297
4298 ///< recent reqids on this object
4299 mempool::osd_pglog::vector<pair<osd_reqid_t, version_t> > reqids;
4300
4301 uint64_t truncate_seq;
4302 uint64_t truncate_size;
4303
4304 public:
4305 object_copy_data_t() :
4306 size((uint64_t)-1), data_digest(-1),
4307 omap_digest(-1), flags(0),
4308 truncate_seq(0),
4309 truncate_size(0) {}
4310
4311 static void generate_test_instances(list<object_copy_data_t*>& o);
4312 void encode(bufferlist& bl, uint64_t features) const;
4313 void decode(bufferlist::iterator& bl);
4314 void dump(Formatter *f) const;
4315 };
4316 WRITE_CLASS_ENCODER_FEATURES(object_copy_data_t)
4317
4318 /**
4319 * pg creation info
4320 */
4321 struct pg_create_t {
4322 epoch_t created; // epoch pg created
4323 pg_t parent; // split from parent (if != pg_t())
4324 __s32 split_bits;
4325
4326 pg_create_t()
4327 : created(0), split_bits(0) {}
4328 pg_create_t(unsigned c, pg_t p, int s)
4329 : created(c), parent(p), split_bits(s) {}
4330
4331 void encode(bufferlist &bl) const;
4332 void decode(bufferlist::iterator &bl);
4333 void dump(Formatter *f) const;
4334 static void generate_test_instances(list<pg_create_t*>& o);
4335 };
4336 WRITE_CLASS_ENCODER(pg_create_t)
4337
4338 // -----------------------------------------
4339
4340 struct osd_peer_stat_t {
4341 utime_t stamp;
4342
4343 osd_peer_stat_t() { }
4344
4345 void encode(bufferlist &bl) const;
4346 void decode(bufferlist::iterator &bl);
4347 void dump(Formatter *f) const;
4348 static void generate_test_instances(list<osd_peer_stat_t*>& o);
4349 };
4350 WRITE_CLASS_ENCODER(osd_peer_stat_t)
4351
4352 ostream& operator<<(ostream& out, const osd_peer_stat_t &stat);
4353
4354
4355 // -----------------------------------------
4356
4357 class ObjectExtent {
4358 /**
4359 * ObjectExtents are used for specifying IO behavior against RADOS
4360 * objects when one is using the ObjectCacher.
4361 *
4362 * To use this in a real system, *every member* must be filled
4363 * out correctly. In particular, make sure to initialize the
4364 * oloc correctly, as its default values are deliberate poison
4365 * and will cause internal ObjectCacher asserts.
4366 *
4367 * Similarly, your buffer_extents vector *must* specify a total
4368 * size equal to your length. If the buffer_extents inadvertently
4369 * contain less space than the length member specifies, you
4370 * will get unintelligible asserts deep in the ObjectCacher.
4371 *
4372 * If you are trying to do testing and don't care about actual
4373 * RADOS function, the simplest thing to do is to initialize
4374 * the ObjectExtent (truncate_size can be 0), create a single entry
4375 * in buffer_extents matching the length, and set oloc.pool to 0.
4376 */
4377 public:
4378 object_t oid; // object id
4379 uint64_t objectno;
4380 uint64_t offset; // in object
4381 uint64_t length; // in object
4382 uint64_t truncate_size; // in object
4383
4384 object_locator_t oloc; // object locator (pool etc)
4385
4386 vector<pair<uint64_t,uint64_t> > buffer_extents; // off -> len. extents in buffer being mapped (may be fragmented bc of striping!)
4387
4388 ObjectExtent() : objectno(0), offset(0), length(0), truncate_size(0) {}
4389 ObjectExtent(object_t o, uint64_t ono, uint64_t off, uint64_t l, uint64_t ts) :
4390 oid(o), objectno(ono), offset(off), length(l), truncate_size(ts) { }
4391 };
4392
4393 inline ostream& operator<<(ostream& out, const ObjectExtent &ex)
4394 {
4395 return out << "extent("
4396 << ex.oid << " (" << ex.objectno << ") in " << ex.oloc
4397 << " " << ex.offset << "~" << ex.length
4398 << " -> " << ex.buffer_extents
4399 << ")";
4400 }
4401
4402
4403 // ---------------------------------------
4404
4405 class OSDSuperblock {
4406 public:
4407 uuid_d cluster_fsid, osd_fsid;
4408 int32_t whoami; // my role in this fs.
4409 epoch_t current_epoch; // most recent epoch
4410 epoch_t oldest_map, newest_map; // oldest/newest maps we have.
4411 double weight;
4412
4413 CompatSet compat_features;
4414
4415 // last interval over which i mounted and was then active
4416 epoch_t mounted; // last epoch i mounted
4417 epoch_t clean_thru; // epoch i was active and clean thru
4418
4419 OSDSuperblock() :
4420 whoami(-1),
4421 current_epoch(0), oldest_map(0), newest_map(0), weight(0),
4422 mounted(0), clean_thru(0) {
4423 }
4424
4425 void encode(bufferlist &bl) const;
4426 void decode(bufferlist::iterator &bl);
4427 void dump(Formatter *f) const;
4428 static void generate_test_instances(list<OSDSuperblock*>& o);
4429 };
4430 WRITE_CLASS_ENCODER(OSDSuperblock)
4431
4432 inline ostream& operator<<(ostream& out, const OSDSuperblock& sb)
4433 {
4434 return out << "sb(" << sb.cluster_fsid
4435 << " osd." << sb.whoami
4436 << " " << sb.osd_fsid
4437 << " e" << sb.current_epoch
4438 << " [" << sb.oldest_map << "," << sb.newest_map << "]"
4439 << " lci=[" << sb.mounted << "," << sb.clean_thru << "]"
4440 << ")";
4441 }
4442
4443
4444 // -------
4445
4446
4447
4448
4449
4450
4451 /*
4452 * attached to object head. describes most recent snap context, and
4453 * set of existing clones.
4454 */
4455 struct SnapSet {
4456 snapid_t seq;
4457 bool head_exists;
4458 vector<snapid_t> snaps; // descending
4459 vector<snapid_t> clones; // ascending
4460 map<snapid_t, interval_set<uint64_t> > clone_overlap; // overlap w/ next newest
4461 map<snapid_t, uint64_t> clone_size;
4462 map<snapid_t, vector<snapid_t>> clone_snaps; // descending
4463
4464 SnapSet() : seq(0), head_exists(false) {}
4465 explicit SnapSet(bufferlist& bl) {
4466 bufferlist::iterator p = bl.begin();
4467 decode(p);
4468 }
4469
4470 bool is_legacy() const {
4471 return clone_snaps.size() < clones.size() || !head_exists;
4472 }
4473
4474 /// populate SnapSet from a librados::snap_set_t
4475 void from_snap_set(const librados::snap_set_t& ss, bool legacy);
4476
4477 /// get space accounted to clone
4478 uint64_t get_clone_bytes(snapid_t clone) const;
4479
4480 void encode(bufferlist& bl) const;
4481 void decode(bufferlist::iterator& bl);
4482 void dump(Formatter *f) const;
4483 static void generate_test_instances(list<SnapSet*>& o);
4484
4485 SnapContext get_ssc_as_of(snapid_t as_of) const {
4486 SnapContext out;
4487 out.seq = as_of;
4488 for (vector<snapid_t>::const_iterator i = snaps.begin();
4489 i != snaps.end();
4490 ++i) {
4491 if (*i <= as_of)
4492 out.snaps.push_back(*i);
4493 }
4494 return out;
4495 }
4496
4497 // return min element of snaps > after, return max if no such element
4498 snapid_t get_first_snap_after(snapid_t after, snapid_t max) const {
4499 for (vector<snapid_t>::const_reverse_iterator i = snaps.rbegin();
4500 i != snaps.rend();
4501 ++i) {
4502 if (*i > after)
4503 return *i;
4504 }
4505 return max;
4506 }
4507
4508 SnapSet get_filtered(const pg_pool_t &pinfo) const;
4509 void filter(const pg_pool_t &pinfo);
4510 };
4511 WRITE_CLASS_ENCODER(SnapSet)
4512
4513 ostream& operator<<(ostream& out, const SnapSet& cs);
4514
4515
4516
4517 #define OI_ATTR "_"
4518 #define SS_ATTR "snapset"
4519
4520 struct watch_info_t {
4521 uint64_t cookie;
4522 uint32_t timeout_seconds;
4523 entity_addr_t addr;
4524
4525 watch_info_t() : cookie(0), timeout_seconds(0) { }
4526 watch_info_t(uint64_t c, uint32_t t, const entity_addr_t& a) : cookie(c), timeout_seconds(t), addr(a) {}
4527
4528 void encode(bufferlist& bl, uint64_t features) const;
4529 void decode(bufferlist::iterator& bl);
4530 void dump(Formatter *f) const;
4531 static void generate_test_instances(list<watch_info_t*>& o);
4532 };
4533 WRITE_CLASS_ENCODER_FEATURES(watch_info_t)
4534
4535 static inline bool operator==(const watch_info_t& l, const watch_info_t& r) {
4536 return l.cookie == r.cookie && l.timeout_seconds == r.timeout_seconds
4537 && l.addr == r.addr;
4538 }
4539
4540 static inline ostream& operator<<(ostream& out, const watch_info_t& w) {
4541 return out << "watch(cookie " << w.cookie << " " << w.timeout_seconds << "s"
4542 << " " << w.addr << ")";
4543 }
4544
4545 struct notify_info_t {
4546 uint64_t cookie;
4547 uint64_t notify_id;
4548 uint32_t timeout;
4549 bufferlist bl;
4550 };
4551
4552 static inline ostream& operator<<(ostream& out, const notify_info_t& n) {
4553 return out << "notify(cookie " << n.cookie
4554 << " notify" << n.notify_id
4555 << " " << n.timeout << "s)";
4556 }
4557
4558 struct object_info_t;
4559 struct object_manifest_t {
4560 enum {
4561 TYPE_NONE = 0,
4562 TYPE_REDIRECT = 1, // start with this
4563 TYPE_CHUNKED = 2, // do this later
4564 };
4565 uint8_t type; // redirect, chunked, ...
4566 hobject_t redirect_target;
4567
4568 object_manifest_t() : type(0) { }
4569 object_manifest_t(uint8_t type, const hobject_t& redirect_target)
4570 : type(type), redirect_target(redirect_target) { }
4571
4572 bool is_empty() const {
4573 return type == TYPE_NONE;
4574 }
4575 bool is_redirect() const {
4576 return type == TYPE_REDIRECT;
4577 }
4578 bool is_chunked() const {
4579 return type == TYPE_CHUNKED;
4580 }
4581 static const char *get_type_name(uint8_t m) {
4582 switch (m) {
4583 case TYPE_NONE: return "none";
4584 case TYPE_REDIRECT: return "redirect";
4585 case TYPE_CHUNKED: return "chunked";
4586 default: return "unknown";
4587 }
4588 }
4589 const char *get_type_name() const {
4590 return get_type_name(type);
4591 }
4592 static void generate_test_instances(list<object_manifest_t*>& o);
4593 void encode(bufferlist &bl) const;
4594 void decode(bufferlist::iterator &bl);
4595 void dump(Formatter *f) const;
4596 friend ostream& operator<<(ostream& out, const object_info_t& oi);
4597 };
4598 WRITE_CLASS_ENCODER(object_manifest_t)
4599 ostream& operator<<(ostream& out, const object_manifest_t& oi);
4600
4601 struct object_info_t {
4602 hobject_t soid;
4603 eversion_t version, prior_version;
4604 version_t user_version;
4605 osd_reqid_t last_reqid;
4606
4607 uint64_t size;
4608 utime_t mtime;
4609 utime_t local_mtime; // local mtime
4610
4611 // note: these are currently encoded into a total 16 bits; see
4612 // encode()/decode() for the weirdness.
4613 typedef enum {
4614 FLAG_LOST = 1<<0,
4615 FLAG_WHITEOUT = 1<<1, // object logically does not exist
4616 FLAG_DIRTY = 1<<2, // object has been modified since last flushed or undirtied
4617 FLAG_OMAP = 1 << 3, // has (or may have) some/any omap data
4618 FLAG_DATA_DIGEST = 1 << 4, // has data crc
4619 FLAG_OMAP_DIGEST = 1 << 5, // has omap crc
4620 FLAG_CACHE_PIN = 1 << 6, // pin the object in cache tier
4621 FLAG_MANIFEST = 1 << 7, // has manifest
4622 // ...
4623 FLAG_USES_TMAP = 1<<8, // deprecated; no longer used.
4624 } flag_t;
4625
4626 flag_t flags;
4627
4628 static string get_flag_string(flag_t flags) {
4629 string s;
4630 if (flags & FLAG_LOST)
4631 s += "|lost";
4632 if (flags & FLAG_WHITEOUT)
4633 s += "|whiteout";
4634 if (flags & FLAG_DIRTY)
4635 s += "|dirty";
4636 if (flags & FLAG_USES_TMAP)
4637 s += "|uses_tmap";
4638 if (flags & FLAG_OMAP)
4639 s += "|omap";
4640 if (flags & FLAG_DATA_DIGEST)
4641 s += "|data_digest";
4642 if (flags & FLAG_OMAP_DIGEST)
4643 s += "|omap_digest";
4644 if (flags & FLAG_CACHE_PIN)
4645 s += "|cache_pin";
4646 if (flags & FLAG_MANIFEST)
4647 s += "|manifest";
4648 if (s.length())
4649 return s.substr(1);
4650 return s;
4651 }
4652 string get_flag_string() const {
4653 return get_flag_string(flags);
4654 }
4655
4656 /// [clone] descending. pre-luminous; moved to SnapSet
4657 vector<snapid_t> legacy_snaps;
4658
4659 uint64_t truncate_seq, truncate_size;
4660
4661 map<pair<uint64_t, entity_name_t>, watch_info_t> watchers;
4662
4663 // opportunistic checksums; may or may not be present
4664 __u32 data_digest; ///< data crc32c
4665 __u32 omap_digest; ///< omap crc32c
4666
4667 // alloc hint attribute
4668 uint64_t expected_object_size, expected_write_size;
4669 uint32_t alloc_hint_flags;
4670
4671 struct object_manifest_t manifest;
4672
4673 void copy_user_bits(const object_info_t& other);
4674
4675 static ps_t legacy_object_locator_to_ps(const object_t &oid,
4676 const object_locator_t &loc);
4677
4678 bool test_flag(flag_t f) const {
4679 return (flags & f) == f;
4680 }
4681 void set_flag(flag_t f) {
4682 flags = (flag_t)(flags | f);
4683 }
4684 void clear_flag(flag_t f) {
4685 flags = (flag_t)(flags & ~f);
4686 }
4687 bool is_lost() const {
4688 return test_flag(FLAG_LOST);
4689 }
4690 bool is_whiteout() const {
4691 return test_flag(FLAG_WHITEOUT);
4692 }
4693 bool is_dirty() const {
4694 return test_flag(FLAG_DIRTY);
4695 }
4696 bool is_omap() const {
4697 return test_flag(FLAG_OMAP);
4698 }
4699 bool is_data_digest() const {
4700 return test_flag(FLAG_DATA_DIGEST);
4701 }
4702 bool is_omap_digest() const {
4703 return test_flag(FLAG_OMAP_DIGEST);
4704 }
4705 bool is_cache_pinned() const {
4706 return test_flag(FLAG_CACHE_PIN);
4707 }
4708 bool has_manifest() const {
4709 return test_flag(FLAG_MANIFEST);
4710 }
4711
4712 void set_data_digest(__u32 d) {
4713 set_flag(FLAG_DATA_DIGEST);
4714 data_digest = d;
4715 }
4716 void set_omap_digest(__u32 d) {
4717 set_flag(FLAG_OMAP_DIGEST);
4718 omap_digest = d;
4719 }
4720 void clear_data_digest() {
4721 clear_flag(FLAG_DATA_DIGEST);
4722 data_digest = -1;
4723 }
4724 void clear_omap_digest() {
4725 clear_flag(FLAG_OMAP_DIGEST);
4726 omap_digest = -1;
4727 }
4728 void new_object() {
4729 set_data_digest(-1);
4730 set_omap_digest(-1);
4731 }
4732
4733 void encode(bufferlist& bl, uint64_t features) const;
4734 void decode(bufferlist::iterator& bl);
4735 void decode(bufferlist& bl) {
4736 bufferlist::iterator p = bl.begin();
4737 decode(p);
4738 }
4739 void dump(Formatter *f) const;
4740 static void generate_test_instances(list<object_info_t*>& o);
4741
4742 explicit object_info_t()
4743 : user_version(0), size(0), flags((flag_t)0),
4744 truncate_seq(0), truncate_size(0),
4745 data_digest(-1), omap_digest(-1),
4746 expected_object_size(0), expected_write_size(0),
4747 alloc_hint_flags(0)
4748 {}
4749
4750 explicit object_info_t(const hobject_t& s)
4751 : soid(s),
4752 user_version(0), size(0), flags((flag_t)0),
4753 truncate_seq(0), truncate_size(0),
4754 data_digest(-1), omap_digest(-1),
4755 expected_object_size(0), expected_write_size(0),
4756 alloc_hint_flags(0)
4757 {}
4758
4759 explicit object_info_t(bufferlist& bl) {
4760 decode(bl);
4761 }
4762 };
4763 WRITE_CLASS_ENCODER_FEATURES(object_info_t)
4764
4765 ostream& operator<<(ostream& out, const object_info_t& oi);
4766
4767
4768
4769 // Object recovery
4770 struct ObjectRecoveryInfo {
4771 hobject_t soid;
4772 eversion_t version;
4773 uint64_t size;
4774 object_info_t oi;
4775 SnapSet ss; // only populated if soid is_snap()
4776 interval_set<uint64_t> copy_subset;
4777 map<hobject_t, interval_set<uint64_t>> clone_subset;
4778
4779 ObjectRecoveryInfo() : size(0) { }
4780
4781 static void generate_test_instances(list<ObjectRecoveryInfo*>& o);
4782 void encode(bufferlist &bl, uint64_t features) const;
4783 void decode(bufferlist::iterator &bl, int64_t pool = -1);
4784 ostream &print(ostream &out) const;
4785 void dump(Formatter *f) const;
4786 };
4787 WRITE_CLASS_ENCODER_FEATURES(ObjectRecoveryInfo)
4788 ostream& operator<<(ostream& out, const ObjectRecoveryInfo &inf);
4789
4790 struct ObjectRecoveryProgress {
4791 uint64_t data_recovered_to;
4792 string omap_recovered_to;
4793 bool first;
4794 bool data_complete;
4795 bool omap_complete;
4796 bool error = false;
4797
4798 ObjectRecoveryProgress()
4799 : data_recovered_to(0),
4800 first(true),
4801 data_complete(false), omap_complete(false) { }
4802
4803 bool is_complete(const ObjectRecoveryInfo& info) const {
4804 return (data_recovered_to >= (
4805 info.copy_subset.empty() ?
4806 0 : info.copy_subset.range_end())) &&
4807 omap_complete;
4808 }
4809
4810 static void generate_test_instances(list<ObjectRecoveryProgress*>& o);
4811 void encode(bufferlist &bl) const;
4812 void decode(bufferlist::iterator &bl);
4813 ostream &print(ostream &out) const;
4814 void dump(Formatter *f) const;
4815 };
4816 WRITE_CLASS_ENCODER(ObjectRecoveryProgress)
4817 ostream& operator<<(ostream& out, const ObjectRecoveryProgress &prog);
4818
4819 struct PushReplyOp {
4820 hobject_t soid;
4821
4822 static void generate_test_instances(list<PushReplyOp*>& o);
4823 void encode(bufferlist &bl) const;
4824 void decode(bufferlist::iterator &bl);
4825 ostream &print(ostream &out) const;
4826 void dump(Formatter *f) const;
4827
4828 uint64_t cost(CephContext *cct) const;
4829 };
4830 WRITE_CLASS_ENCODER(PushReplyOp)
4831 ostream& operator<<(ostream& out, const PushReplyOp &op);
4832
4833 struct PullOp {
4834 hobject_t soid;
4835
4836 ObjectRecoveryInfo recovery_info;
4837 ObjectRecoveryProgress recovery_progress;
4838
4839 static void generate_test_instances(list<PullOp*>& o);
4840 void encode(bufferlist &bl, uint64_t features) const;
4841 void decode(bufferlist::iterator &bl);
4842 ostream &print(ostream &out) const;
4843 void dump(Formatter *f) const;
4844
4845 uint64_t cost(CephContext *cct) const;
4846 };
4847 WRITE_CLASS_ENCODER_FEATURES(PullOp)
4848 ostream& operator<<(ostream& out, const PullOp &op);
4849
4850 struct PushOp {
4851 hobject_t soid;
4852 eversion_t version;
4853 bufferlist data;
4854 interval_set<uint64_t> data_included;
4855 bufferlist omap_header;
4856 map<string, bufferlist> omap_entries;
4857 map<string, bufferlist> attrset;
4858
4859 ObjectRecoveryInfo recovery_info;
4860 ObjectRecoveryProgress before_progress;
4861 ObjectRecoveryProgress after_progress;
4862
4863 static void generate_test_instances(list<PushOp*>& o);
4864 void encode(bufferlist &bl, uint64_t features) const;
4865 void decode(bufferlist::iterator &bl);
4866 ostream &print(ostream &out) const;
4867 void dump(Formatter *f) const;
4868
4869 uint64_t cost(CephContext *cct) const;
4870 };
4871 WRITE_CLASS_ENCODER_FEATURES(PushOp)
4872 ostream& operator<<(ostream& out, const PushOp &op);
4873
4874
4875 /*
4876 * summarize pg contents for purposes of a scrub
4877 */
4878 struct ScrubMap {
4879 struct object {
4880 map<string,bufferptr> attrs;
4881 uint64_t size;
4882 __u32 omap_digest; ///< omap crc32c
4883 __u32 digest; ///< data crc32c
4884 bool negative:1;
4885 bool digest_present:1;
4886 bool omap_digest_present:1;
4887 bool read_error:1;
4888 bool stat_error:1;
4889 bool ec_hash_mismatch:1;
4890 bool ec_size_mismatch:1;
4891
4892 object() :
4893 // Init invalid size so it won't match if we get a stat EIO error
4894 size(-1), omap_digest(0), digest(0),
4895 negative(false), digest_present(false), omap_digest_present(false),
4896 read_error(false), stat_error(false), ec_hash_mismatch(false), ec_size_mismatch(false) {}
4897
4898 void encode(bufferlist& bl) const;
4899 void decode(bufferlist::iterator& bl);
4900 void dump(Formatter *f) const;
4901 static void generate_test_instances(list<object*>& o);
4902 };
4903 WRITE_CLASS_ENCODER(object)
4904
4905 map<hobject_t,object> objects;
4906 eversion_t valid_through;
4907 eversion_t incr_since;
4908
4909 void merge_incr(const ScrubMap &l);
4910 void insert(const ScrubMap &r) {
4911 objects.insert(r.objects.begin(), r.objects.end());
4912 }
4913 void swap(ScrubMap &r) {
4914 using std::swap;
4915 swap(objects, r.objects);
4916 swap(valid_through, r.valid_through);
4917 swap(incr_since, r.incr_since);
4918 }
4919
4920 void encode(bufferlist& bl) const;
4921 void decode(bufferlist::iterator& bl, int64_t pool=-1);
4922 void dump(Formatter *f) const;
4923 static void generate_test_instances(list<ScrubMap*>& o);
4924 };
4925 WRITE_CLASS_ENCODER(ScrubMap::object)
4926 WRITE_CLASS_ENCODER(ScrubMap)
4927
4928 struct OSDOp {
4929 ceph_osd_op op;
4930 sobject_t soid;
4931
4932 bufferlist indata, outdata;
4933 errorcode32_t rval;
4934
4935 OSDOp() : rval(0) {
4936 memset(&op, 0, sizeof(ceph_osd_op));
4937 }
4938
4939 /**
4940 * split a bufferlist into constituent indata members of a vector of OSDOps
4941 *
4942 * @param ops [out] vector of OSDOps
4943 * @param in [in] combined data buffer
4944 */
4945 static void split_osd_op_vector_in_data(vector<OSDOp>& ops, bufferlist& in);
4946
4947 /**
4948 * merge indata members of a vector of OSDOp into a single bufferlist
4949 *
4950 * Notably this also encodes certain other OSDOp data into the data
4951 * buffer, including the sobject_t soid.
4952 *
4953 * @param ops [in] vector of OSDOps
4954 * @param out [out] combined data buffer
4955 */
4956 static void merge_osd_op_vector_in_data(vector<OSDOp>& ops, bufferlist& out);
4957
4958 /**
4959 * split a bufferlist into constituent outdata members of a vector of OSDOps
4960 *
4961 * @param ops [out] vector of OSDOps
4962 * @param in [in] combined data buffer
4963 */
4964 static void split_osd_op_vector_out_data(vector<OSDOp>& ops, bufferlist& in);
4965
4966 /**
4967 * merge outdata members of a vector of OSDOps into a single bufferlist
4968 *
4969 * @param ops [in] vector of OSDOps
4970 * @param out [out] combined data buffer
4971 */
4972 static void merge_osd_op_vector_out_data(vector<OSDOp>& ops, bufferlist& out);
4973
4974 /**
4975 * Clear data as much as possible, leave minimal data for historical op dump
4976 *
4977 * @param ops [in] vector of OSDOps
4978 */
4979 static void clear_data(vector<OSDOp>& ops);
4980 };
4981
4982 ostream& operator<<(ostream& out, const OSDOp& op);
4983
4984 struct watch_item_t {
4985 entity_name_t name;
4986 uint64_t cookie;
4987 uint32_t timeout_seconds;
4988 entity_addr_t addr;
4989
4990 watch_item_t() : cookie(0), timeout_seconds(0) { }
4991 watch_item_t(entity_name_t name, uint64_t cookie, uint32_t timeout,
4992 const entity_addr_t& addr)
4993 : name(name), cookie(cookie), timeout_seconds(timeout),
4994 addr(addr) { }
4995
4996 void encode(bufferlist &bl, uint64_t features) const {
4997 ENCODE_START(2, 1, bl);
4998 ::encode(name, bl);
4999 ::encode(cookie, bl);
5000 ::encode(timeout_seconds, bl);
5001 ::encode(addr, bl, features);
5002 ENCODE_FINISH(bl);
5003 }
5004 void decode(bufferlist::iterator &bl) {
5005 DECODE_START(2, bl);
5006 ::decode(name, bl);
5007 ::decode(cookie, bl);
5008 ::decode(timeout_seconds, bl);
5009 if (struct_v >= 2) {
5010 ::decode(addr, bl);
5011 }
5012 DECODE_FINISH(bl);
5013 }
5014 };
5015 WRITE_CLASS_ENCODER_FEATURES(watch_item_t)
5016
5017 struct obj_watch_item_t {
5018 hobject_t obj;
5019 watch_item_t wi;
5020 };
5021
5022 /**
5023 * obj list watch response format
5024 *
5025 */
5026 struct obj_list_watch_response_t {
5027 list<watch_item_t> entries;
5028
5029 void encode(bufferlist& bl, uint64_t features) const {
5030 ENCODE_START(1, 1, bl);
5031 ::encode(entries, bl, features);
5032 ENCODE_FINISH(bl);
5033 }
5034 void decode(bufferlist::iterator& bl) {
5035 DECODE_START(1, bl);
5036 ::decode(entries, bl);
5037 DECODE_FINISH(bl);
5038 }
5039 void dump(Formatter *f) const {
5040 f->open_array_section("entries");
5041 for (list<watch_item_t>::const_iterator p = entries.begin(); p != entries.end(); ++p) {
5042 f->open_object_section("watch");
5043 f->dump_stream("watcher") << p->name;
5044 f->dump_int("cookie", p->cookie);
5045 f->dump_int("timeout", p->timeout_seconds);
5046 f->open_object_section("addr");
5047 p->addr.dump(f);
5048 f->close_section();
5049 f->close_section();
5050 }
5051 f->close_section();
5052 }
5053 static void generate_test_instances(list<obj_list_watch_response_t*>& o) {
5054 entity_addr_t ea;
5055 o.push_back(new obj_list_watch_response_t);
5056 o.push_back(new obj_list_watch_response_t);
5057 ea.set_type(entity_addr_t::TYPE_LEGACY);
5058 ea.set_nonce(1000);
5059 ea.set_family(AF_INET);
5060 ea.set_in4_quad(0, 127);
5061 ea.set_in4_quad(1, 0);
5062 ea.set_in4_quad(2, 0);
5063 ea.set_in4_quad(3, 1);
5064 ea.set_port(1024);
5065 o.back()->entries.push_back(watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT, 1), 10, 30, ea));
5066 ea.set_nonce(1001);
5067 ea.set_in4_quad(3, 2);
5068 ea.set_port(1025);
5069 o.back()->entries.push_back(watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT, 2), 20, 60, ea));
5070 }
5071 };
5072 WRITE_CLASS_ENCODER_FEATURES(obj_list_watch_response_t)
5073
5074 struct clone_info {
5075 snapid_t cloneid;
5076 vector<snapid_t> snaps; // ascending
5077 vector< pair<uint64_t,uint64_t> > overlap;
5078 uint64_t size;
5079
5080 clone_info() : cloneid(CEPH_NOSNAP), size(0) {}
5081
5082 void encode(bufferlist& bl) const {
5083 ENCODE_START(1, 1, bl);
5084 ::encode(cloneid, bl);
5085 ::encode(snaps, bl);
5086 ::encode(overlap, bl);
5087 ::encode(size, bl);
5088 ENCODE_FINISH(bl);
5089 }
5090 void decode(bufferlist::iterator& bl) {
5091 DECODE_START(1, bl);
5092 ::decode(cloneid, bl);
5093 ::decode(snaps, bl);
5094 ::decode(overlap, bl);
5095 ::decode(size, bl);
5096 DECODE_FINISH(bl);
5097 }
5098 void dump(Formatter *f) const {
5099 if (cloneid == CEPH_NOSNAP)
5100 f->dump_string("cloneid", "HEAD");
5101 else
5102 f->dump_unsigned("cloneid", cloneid.val);
5103 f->open_array_section("snapshots");
5104 for (vector<snapid_t>::const_iterator p = snaps.begin(); p != snaps.end(); ++p) {
5105 f->open_object_section("snap");
5106 f->dump_unsigned("id", p->val);
5107 f->close_section();
5108 }
5109 f->close_section();
5110 f->open_array_section("overlaps");
5111 for (vector< pair<uint64_t,uint64_t> >::const_iterator q = overlap.begin();
5112 q != overlap.end(); ++q) {
5113 f->open_object_section("overlap");
5114 f->dump_unsigned("offset", q->first);
5115 f->dump_unsigned("length", q->second);
5116 f->close_section();
5117 }
5118 f->close_section();
5119 f->dump_unsigned("size", size);
5120 }
5121 static void generate_test_instances(list<clone_info*>& o) {
5122 o.push_back(new clone_info);
5123 o.push_back(new clone_info);
5124 o.back()->cloneid = 1;
5125 o.back()->snaps.push_back(1);
5126 o.back()->overlap.push_back(pair<uint64_t,uint64_t>(0,4096));
5127 o.back()->overlap.push_back(pair<uint64_t,uint64_t>(8192,4096));
5128 o.back()->size = 16384;
5129 o.push_back(new clone_info);
5130 o.back()->cloneid = CEPH_NOSNAP;
5131 o.back()->size = 32768;
5132 }
5133 };
5134 WRITE_CLASS_ENCODER(clone_info)
5135
5136 /**
5137 * obj list snaps response format
5138 *
5139 */
5140 struct obj_list_snap_response_t {
5141 vector<clone_info> clones; // ascending
5142 snapid_t seq;
5143
5144 void encode(bufferlist& bl) const {
5145 ENCODE_START(2, 1, bl);
5146 ::encode(clones, bl);
5147 ::encode(seq, bl);
5148 ENCODE_FINISH(bl);
5149 }
5150 void decode(bufferlist::iterator& bl) {
5151 DECODE_START(2, bl);
5152 ::decode(clones, bl);
5153 if (struct_v >= 2)
5154 ::decode(seq, bl);
5155 else
5156 seq = CEPH_NOSNAP;
5157 DECODE_FINISH(bl);
5158 }
5159 void dump(Formatter *f) const {
5160 f->open_array_section("clones");
5161 for (vector<clone_info>::const_iterator p = clones.begin(); p != clones.end(); ++p) {
5162 f->open_object_section("clone");
5163 p->dump(f);
5164 f->close_section();
5165 }
5166 f->dump_unsigned("seq", seq);
5167 f->close_section();
5168 }
5169 static void generate_test_instances(list<obj_list_snap_response_t*>& o) {
5170 o.push_back(new obj_list_snap_response_t);
5171 o.push_back(new obj_list_snap_response_t);
5172 clone_info cl;
5173 cl.cloneid = 1;
5174 cl.snaps.push_back(1);
5175 cl.overlap.push_back(pair<uint64_t,uint64_t>(0,4096));
5176 cl.overlap.push_back(pair<uint64_t,uint64_t>(8192,4096));
5177 cl.size = 16384;
5178 o.back()->clones.push_back(cl);
5179 cl.cloneid = CEPH_NOSNAP;
5180 cl.snaps.clear();
5181 cl.overlap.clear();
5182 cl.size = 32768;
5183 o.back()->clones.push_back(cl);
5184 o.back()->seq = 123;
5185 }
5186 };
5187
5188 WRITE_CLASS_ENCODER(obj_list_snap_response_t)
5189
5190 // PromoteCounter
5191
5192 struct PromoteCounter {
5193 std::atomic_ullong attempts{0};
5194 std::atomic_ullong objects{0};
5195 std::atomic_ullong bytes{0};
5196
5197 void attempt() {
5198 attempts++;
5199 }
5200
5201 void finish(uint64_t size) {
5202 objects++;
5203 bytes += size;
5204 }
5205
5206 void sample_and_attenuate(uint64_t *a, uint64_t *o, uint64_t *b) {
5207 *a = attempts;
5208 *o = objects;
5209 *b = bytes;
5210 attempts = *a / 2;
5211 objects = *o / 2;
5212 bytes = *b / 2;
5213 }
5214 };
5215
5216 /** store_statfs_t
5217 * ObjectStore full statfs information
5218 */
5219 struct store_statfs_t
5220 {
5221 uint64_t total = 0; // Total bytes
5222 uint64_t available = 0; // Free bytes available
5223
5224 int64_t allocated = 0; // Bytes allocated by the store
5225 int64_t stored = 0; // Bytes actually stored by the user
5226 int64_t compressed = 0; // Bytes stored after compression
5227 int64_t compressed_allocated = 0; // Bytes allocated for compressed data
5228 int64_t compressed_original = 0; // Bytes that were successfully compressed
5229
5230 void reset() {
5231 *this = store_statfs_t();
5232 }
5233 bool operator ==(const store_statfs_t& other) const;
5234 void dump(Formatter *f) const;
5235 };
5236 ostream &operator<<(ostream &lhs, const store_statfs_t &rhs);
5237
5238 #endif