1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 * Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
9 * Author: Loic Dachary <loic@dachary.org>
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.
18 #ifndef CEPH_OSD_TYPES_H
19 #define CEPH_OSD_TYPES_H
24 #include <boost/scoped_ptr.hpp>
25 #include <boost/optional/optional_io.hpp>
26 #include <boost/variant.hpp>
28 #include "include/rados/rados_types.hpp"
29 #include "include/mempool.h"
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"
44 #include "include/cmp.h"
45 #include "librados/ListObjectImpl.h"
46 #include "compressor/Compressor.h"
49 #define CEPH_OSD_ONDISK_MAGIC "ceph osd volume v026"
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")
69 /// min recovery priority for MBackfillReserve
70 #define OSD_RECOVERY_PRIORITY_MIN 0
72 /// base backfill priority for MBackfillReserve
73 #define OSD_BACKFILL_PRIORITY_BASE 100
75 /// base backfill priority for MBackfillReserve (degraded PG)
76 #define OSD_BACKFILL_DEGRADED_PRIORITY_BASE 140
78 /// base recovery priority for MBackfillReserve
79 #define OSD_RECOVERY_PRIORITY_BASE 180
81 /// base backfill priority for MBackfillReserve (inactive PG)
82 #define OSD_BACKFILL_INACTIVE_PRIORITY_BASE 220
84 /// max manually/automatically set recovery priority for MBackfillReserve
85 #define OSD_RECOVERY_PRIORITY_MAX 254
87 /// max recovery priority for MBackfillReserve, only when forced manually
88 #define OSD_RECOVERY_PRIORITY_FORCED 255
91 typedef hobject_t collection_list_handle_t
;
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
);
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
);
107 * osd request identifier
109 * caller name + incarnation# + tid to unique identify this request.
112 entity_name_t name
; // who
114 int32_t inc
; // incarnation
119 osd_reqid_t(const osd_reqid_t
& other
)
120 : name(other
.name
), tid(other
.tid
), inc(other
.inc
)
122 osd_reqid_t(const entity_name_t
& a
, int i
, ceph_tid_t t
)
123 : name(a
), tid(t
), inc(i
)
126 DENC(osd_reqid_t
, v
, p
) {
133 void dump(Formatter
*f
) const;
134 static void generate_test_instances(list
<osd_reqid_t
*>& o
);
136 WRITE_CLASS_DENC(osd_reqid_t
)
141 static const int32_t NO_OSD
= 0x7fffffff;
144 pg_shard_t() : osd(-1), shard(shard_id_t::NO_SHARD
) {}
145 explicit pg_shard_t(int osd
) : osd(osd
), shard(shard_id_t::NO_SHARD
) {}
146 pg_shard_t(int osd
, shard_id_t shard
) : osd(osd
), shard(shard
) {}
147 bool is_undefined() const {
150 string
get_osd() const { return (osd
== NO_OSD
? "NONE" : to_string(osd
)); }
151 void encode(bufferlist
&bl
) const;
152 void decode(bufferlist::iterator
&bl
);
153 void dump(Formatter
*f
) const {
154 f
->dump_unsigned("osd", osd
);
155 if (shard
!= shard_id_t::NO_SHARD
) {
156 f
->dump_unsigned("shard", shard
);
160 WRITE_CLASS_ENCODER(pg_shard_t
)
161 WRITE_EQ_OPERATORS_2(pg_shard_t
, osd
, shard
)
162 WRITE_CMP_OPERATORS_2(pg_shard_t
, osd
, shard
)
163 ostream
&operator<<(ostream
&lhs
, const pg_shard_t
&rhs
);
165 class IsPGRecoverablePredicate
{
168 * have encodes the shards available
170 virtual bool operator()(const set
<pg_shard_t
> &have
) const = 0;
171 virtual ~IsPGRecoverablePredicate() {}
174 class IsPGReadablePredicate
{
177 * have encodes the shards available
179 virtual bool operator()(const set
<pg_shard_t
> &have
) const = 0;
180 virtual ~IsPGReadablePredicate() {}
183 inline ostream
& operator<<(ostream
& out
, const osd_reqid_t
& r
) {
184 return out
<< r
.name
<< "." << r
.inc
<< ":" << r
.tid
;
187 inline bool operator==(const osd_reqid_t
& l
, const osd_reqid_t
& r
) {
188 return (l
.name
== r
.name
) && (l
.inc
== r
.inc
) && (l
.tid
== r
.tid
);
190 inline bool operator!=(const osd_reqid_t
& l
, const osd_reqid_t
& r
) {
191 return (l
.name
!= r
.name
) || (l
.inc
!= r
.inc
) || (l
.tid
!= r
.tid
);
193 inline bool operator<(const osd_reqid_t
& l
, const osd_reqid_t
& r
) {
194 return (l
.name
< r
.name
) || (l
.inc
< r
.inc
) ||
195 (l
.name
== r
.name
&& l
.inc
== r
.inc
&& l
.tid
< r
.tid
);
197 inline bool operator<=(const osd_reqid_t
& l
, const osd_reqid_t
& r
) {
198 return (l
.name
< r
.name
) || (l
.inc
< r
.inc
) ||
199 (l
.name
== r
.name
&& l
.inc
== r
.inc
&& l
.tid
<= r
.tid
);
201 inline bool operator>(const osd_reqid_t
& l
, const osd_reqid_t
& r
) { return !(l
<= r
); }
202 inline bool operator>=(const osd_reqid_t
& l
, const osd_reqid_t
& r
) { return !(l
< r
); }
205 template<> struct hash
<osd_reqid_t
> {
206 size_t operator()(const osd_reqid_t
&r
) const {
207 static hash
<uint64_t> H
;
208 return H(r
.name
.num() ^ r
.tid
^ r
.inc
);
216 // a locator constrains the placement of an object. mainly, which pool
218 struct object_locator_t
{
219 // You specify either the hash or the key -- not both
220 int64_t pool
; ///< pool id
221 string key
; ///< key string (if non-empty)
222 string nspace
; ///< namespace
223 int64_t hash
; ///< hash position (if >= 0)
225 explicit object_locator_t()
226 : pool(-1), hash(-1) {}
227 explicit object_locator_t(int64_t po
)
228 : pool(po
), hash(-1) {}
229 explicit object_locator_t(int64_t po
, int64_t ps
)
230 : pool(po
), hash(ps
) {}
231 explicit object_locator_t(int64_t po
, string ns
)
232 : pool(po
), nspace(ns
), hash(-1) {}
233 explicit object_locator_t(int64_t po
, string ns
, int64_t ps
)
234 : pool(po
), nspace(ns
), hash(ps
) {}
235 explicit object_locator_t(int64_t po
, string ns
, string s
)
236 : pool(po
), key(s
), nspace(ns
), hash(-1) {}
237 explicit object_locator_t(const hobject_t
& soid
)
238 : pool(soid
.pool
), key(soid
.get_key()), nspace(soid
.nspace
), hash(-1) {}
240 int64_t get_pool() const {
255 void encode(bufferlist
& bl
) const;
256 void decode(bufferlist::iterator
& p
);
257 void dump(Formatter
*f
) const;
258 static void generate_test_instances(list
<object_locator_t
*>& o
);
260 WRITE_CLASS_ENCODER(object_locator_t
)
262 inline bool operator==(const object_locator_t
& l
, const object_locator_t
& r
) {
263 return l
.pool
== r
.pool
&& l
.key
== r
.key
&& l
.nspace
== r
.nspace
&& l
.hash
== r
.hash
;
265 inline bool operator!=(const object_locator_t
& l
, const object_locator_t
& r
) {
269 inline ostream
& operator<<(ostream
& out
, const object_locator_t
& loc
)
271 out
<< "@" << loc
.pool
;
272 if (loc
.nspace
.length())
273 out
<< ";" << loc
.nspace
;
274 if (loc
.key
.length())
275 out
<< ":" << loc
.key
;
279 struct request_redirect_t
{
281 object_locator_t redirect_locator
; ///< this is authoritative
282 string redirect_object
; ///< If non-empty, the request goes to this object name
283 bufferlist osd_instructions
; ///< a bufferlist for the OSDs, passed but not interpreted by clients
285 friend ostream
& operator<<(ostream
& out
, const request_redirect_t
& redir
);
288 request_redirect_t() {}
289 explicit request_redirect_t(const object_locator_t
& orig
, int64_t rpool
) :
290 redirect_locator(orig
) { redirect_locator
.pool
= rpool
; }
291 explicit request_redirect_t(const object_locator_t
& rloc
) :
292 redirect_locator(rloc
) {}
293 explicit request_redirect_t(const object_locator_t
& orig
,
294 const string
& robj
) :
295 redirect_locator(orig
), redirect_object(robj
) {}
297 void set_instructions(const bufferlist
& bl
) { osd_instructions
= bl
; }
298 const bufferlist
& get_instructions() { return osd_instructions
; }
300 bool empty() const { return redirect_locator
.empty() &&
301 redirect_object
.empty(); }
303 void combine_with_locator(object_locator_t
& orig
, string
& obj
) const {
304 orig
= redirect_locator
;
305 if (!redirect_object
.empty())
306 obj
= redirect_object
;
309 void encode(bufferlist
& bl
) const;
310 void decode(bufferlist::iterator
& bl
);
311 void dump(Formatter
*f
) const;
312 static void generate_test_instances(list
<request_redirect_t
*>& o
);
314 WRITE_CLASS_ENCODER(request_redirect_t
)
316 inline ostream
& operator<<(ostream
& out
, const request_redirect_t
& redir
) {
317 out
<< "object " << redir
.redirect_object
<< ", locator{" << redir
.redirect_locator
<< "}";
321 // Internal OSD op flags - set by the OSD based on the op types
323 CEPH_OSD_RMW_FLAG_READ
= (1 << 1),
324 CEPH_OSD_RMW_FLAG_WRITE
= (1 << 2),
325 CEPH_OSD_RMW_FLAG_CLASS_READ
= (1 << 3),
326 CEPH_OSD_RMW_FLAG_CLASS_WRITE
= (1 << 4),
327 CEPH_OSD_RMW_FLAG_PGOP
= (1 << 5),
328 CEPH_OSD_RMW_FLAG_CACHE
= (1 << 6),
329 CEPH_OSD_RMW_FLAG_FORCE_PROMOTE
= (1 << 7),
330 CEPH_OSD_RMW_FLAG_SKIP_HANDLE_CACHE
= (1 << 8),
331 CEPH_OSD_RMW_FLAG_SKIP_PROMOTE
= (1 << 9),
332 CEPH_OSD_RMW_FLAG_RWORDERED
= (1 << 10),
338 #define OSD_SUPERBLOCK_GOBJECT ghobject_t(hobject_t(sobject_t(object_t("osd_superblock"), 0)))
340 // placement seed (a hash value)
341 typedef uint32_t ps_t
;
343 // old (v1) pg_t encoding (wrap old struct ceph_pg)
346 void encode(bufferlist
& bl
) const {
349 void decode(bufferlist::iterator
& bl
) {
353 WRITE_CLASS_ENCODER(old_pg_t
)
355 // placement group id
361 pg_t() : m_pool(0), m_seed(0), m_preferred(-1) {}
362 pg_t(ps_t seed
, uint64_t pool
, int pref
=-1) :
363 m_pool(pool
), m_seed(seed
), m_preferred(pref
) {}
364 // cppcheck-suppress noExplicitConstructor
365 pg_t(const ceph_pg
& cpg
) :
366 m_pool(cpg
.pool
), m_seed(cpg
.ps
), m_preferred((__s16
)cpg
.preferred
) {}
368 // cppcheck-suppress noExplicitConstructor
369 pg_t(const old_pg_t
& opg
) {
373 old_pg_t
get_old_pg() const {
375 assert(m_pool
< 0xffffffffull
);
378 o
.v
.preferred
= (__s16
)m_preferred
;
385 uint64_t pool() const {
388 int32_t preferred() const {
392 static const uint8_t calc_name_buf_size
= 36; // max length for max values len("18446744073709551615.ffffffff") + future suffix len("_head") + '\0'
393 char *calc_name(char *buf
, const char *suffix_backwords
) const;
395 void set_ps(ps_t p
) {
398 void set_pool(uint64_t p
) {
401 void set_preferred(int32_t osd
) {
405 pg_t
get_parent() const;
406 pg_t
get_ancestor(unsigned old_pg_num
) const;
408 int print(char *o
, int maxlen
) const;
409 bool parse(const char *s
);
411 bool is_split(unsigned old_pg_num
, unsigned new_pg_num
, set
<pg_t
> *pchildren
) const;
414 * Returns b such that for all object o:
415 * ~((~0)<<b) & o.hash) == 0 iff o is in the pg for *this
417 unsigned get_split_bits(unsigned pg_num
) const;
419 bool contains(int bits
, const ghobject_t
& oid
) {
420 return oid
.match(bits
, ps());
422 bool contains(int bits
, const hobject_t
& oid
) {
423 return oid
.match(bits
, ps());
426 hobject_t
get_hobj_start() const;
427 hobject_t
get_hobj_end(unsigned pg_num
) const;
429 void encode(bufferlist
& bl
) const {
432 ::encode(m_pool
, bl
);
433 ::encode(m_seed
, bl
);
434 ::encode(m_preferred
, bl
);
436 void decode(bufferlist::iterator
& bl
) {
439 ::decode(m_pool
, bl
);
440 ::decode(m_seed
, bl
);
441 ::decode(m_preferred
, bl
);
443 void decode_old(bufferlist::iterator
& bl
) {
448 void dump(Formatter
*f
) const;
449 static void generate_test_instances(list
<pg_t
*>& o
);
451 WRITE_CLASS_ENCODER(pg_t
)
453 inline bool operator<(const pg_t
& l
, const pg_t
& r
) {
454 return l
.pool() < r
.pool() ||
455 (l
.pool() == r
.pool() && (l
.preferred() < r
.preferred() ||
456 (l
.preferred() == r
.preferred() && (l
.ps() < r
.ps()))));
458 inline bool operator<=(const pg_t
& l
, const pg_t
& r
) {
459 return l
.pool() < r
.pool() ||
460 (l
.pool() == r
.pool() && (l
.preferred() < r
.preferred() ||
461 (l
.preferred() == r
.preferred() && (l
.ps() <= r
.ps()))));
463 inline bool operator==(const pg_t
& l
, const pg_t
& r
) {
464 return l
.pool() == r
.pool() &&
465 l
.preferred() == r
.preferred() &&
468 inline bool operator!=(const pg_t
& l
, const pg_t
& r
) {
469 return l
.pool() != r
.pool() ||
470 l
.preferred() != r
.preferred() ||
473 inline bool operator>(const pg_t
& l
, const pg_t
& r
) {
474 return l
.pool() > r
.pool() ||
475 (l
.pool() == r
.pool() && (l
.preferred() > r
.preferred() ||
476 (l
.preferred() == r
.preferred() && (l
.ps() > r
.ps()))));
478 inline bool operator>=(const pg_t
& l
, const pg_t
& r
) {
479 return l
.pool() > r
.pool() ||
480 (l
.pool() == r
.pool() && (l
.preferred() > r
.preferred() ||
481 (l
.preferred() == r
.preferred() && (l
.ps() >= r
.ps()))));
484 ostream
& operator<<(ostream
& out
, const pg_t
&pg
);
487 template<> struct hash
< pg_t
>
489 size_t operator()( const pg_t
& x
) const
491 static hash
<uint32_t> H
;
492 return H((x
.pool() & 0xffffffff) ^ (x
.pool() >> 32) ^ x
.ps() ^ x
.preferred());
500 spg_t() : shard(shard_id_t::NO_SHARD
) {}
501 spg_t(pg_t pgid
, shard_id_t shard
) : pgid(pgid
), shard(shard
) {}
502 explicit spg_t(pg_t pgid
) : pgid(pgid
), shard(shard_id_t::NO_SHARD
) {}
503 unsigned get_split_bits(unsigned pg_num
) const {
504 return pgid
.get_split_bits(pg_num
);
506 spg_t
get_parent() const {
507 return spg_t(pgid
.get_parent(), shard
);
512 uint64_t pool() const {
515 int32_t preferred() const {
516 return pgid
.preferred();
519 static const uint8_t calc_name_buf_size
= pg_t::calc_name_buf_size
+ 4; // 36 + len('s') + len("255");
520 char *calc_name(char *buf
, const char *suffix_backwords
) const;
522 bool parse(const char *s
);
523 bool parse(const std::string
& s
) {
524 return parse(s
.c_str());
526 bool is_split(unsigned old_pg_num
, unsigned new_pg_num
,
527 set
<spg_t
> *pchildren
) const {
529 set
<pg_t
> *children
= pchildren
? &_children
: NULL
;
530 bool is_split
= pgid
.is_split(old_pg_num
, new_pg_num
, children
);
531 if (pchildren
&& is_split
) {
532 for (set
<pg_t
>::iterator i
= _children
.begin();
533 i
!= _children
.end();
535 pchildren
->insert(spg_t(*i
, shard
));
540 bool is_no_shard() const {
541 return shard
== shard_id_t::NO_SHARD
;
544 ghobject_t
make_pgmeta_oid() const {
545 return ghobject_t::make_pgmeta(pgid
.pool(), pgid
.ps(), shard
);
548 void encode(bufferlist
&bl
) const {
549 ENCODE_START(1, 1, bl
);
554 void decode(bufferlist::iterator
&bl
) {
561 ghobject_t
make_temp_ghobject(const string
& name
) const {
563 hobject_t(object_t(name
), "", CEPH_NOSNAP
,
565 hobject_t::POOL_TEMP_START
- pgid
.pool(), ""),
570 unsigned hash_to_shard(unsigned num_shards
) const {
571 return ps() % num_shards
;
574 WRITE_CLASS_ENCODER(spg_t
)
575 WRITE_EQ_OPERATORS_2(spg_t
, pgid
, shard
)
576 WRITE_CMP_OPERATORS_2(spg_t
, pgid
, shard
)
579 template<> struct hash
< spg_t
>
581 size_t operator()( const spg_t
& x
) const
583 static hash
<uint32_t> H
;
584 return H(hash
<pg_t
>()(x
.pgid
) ^ x
.shard
);
589 ostream
& operator<<(ostream
& out
, const spg_t
&pg
);
591 // ----------------------
596 TYPE_LEGACY_TEMP
= 1, /* no longer used */
602 uint64_t removal_seq
; // note: deprecated, not encoded
604 char _str_buff
[spg_t::calc_name_buf_size
];
609 coll_t(type_t t
, spg_t p
, uint64_t r
)
610 : type(t
), pgid(p
), removal_seq(r
) {
615 coll_t() : type(TYPE_META
), removal_seq(0)
620 coll_t(const coll_t
& other
)
621 : type(other
.type
), pgid(other
.pgid
), removal_seq(other
.removal_seq
) {
625 explicit coll_t(spg_t pgid
)
626 : type(TYPE_PG
), pgid(pgid
), removal_seq(0)
631 coll_t
& operator=(const coll_t
& rhs
)
633 this->type
= rhs
.type
;
634 this->pgid
= rhs
.pgid
;
635 this->removal_seq
= rhs
.removal_seq
;
640 // named constructors
641 static coll_t
meta() {
644 static coll_t
pg(spg_t p
) {
648 const std::string
to_str() const {
651 const char *c_str() const {
655 bool parse(const std::string
& s
);
657 int operator<(const coll_t
&rhs
) const {
658 return type
< rhs
.type
||
659 (type
== rhs
.type
&& pgid
< rhs
.pgid
);
662 bool is_meta() const {
663 return type
== TYPE_META
;
665 bool is_pg_prefix(spg_t
*pgid_
) const {
666 if (type
== TYPE_PG
|| type
== TYPE_PG_TEMP
) {
673 return type
== TYPE_PG
;
675 bool is_pg(spg_t
*pgid_
) const {
676 if (type
== TYPE_PG
) {
682 bool is_temp() const {
683 return type
== TYPE_PG_TEMP
;
685 bool is_temp(spg_t
*pgid_
) const {
686 if (type
== TYPE_PG_TEMP
) {
693 void encode(bufferlist
& bl
) const;
694 void decode(bufferlist::iterator
& bl
);
695 size_t encoded_size() const;
697 inline bool operator==(const coll_t
& rhs
) const {
698 // only compare type if meta
699 if (type
!= rhs
.type
)
701 if (type
== TYPE_META
)
703 return type
== rhs
.type
&& pgid
== rhs
.pgid
;
705 inline bool operator!=(const coll_t
& rhs
) const {
706 return !(*this == rhs
);
709 // get a TEMP collection that corresponds to the current collection,
710 // which we presume is a pg collection.
711 coll_t
get_temp() const {
712 assert(type
== TYPE_PG
);
713 return coll_t(TYPE_PG_TEMP
, pgid
, 0);
716 ghobject_t
get_min_hobj() const {
720 o
.hobj
.pool
= pgid
.pool();
721 o
.set_shard(pgid
.shard
);
732 unsigned hash_to_shard(unsigned num_shards
) const {
734 return pgid
.hash_to_shard(num_shards
);
735 return 0; // whatever.
738 void dump(Formatter
*f
) const;
739 static void generate_test_instances(list
<coll_t
*>& o
);
742 WRITE_CLASS_ENCODER(coll_t
)
744 inline ostream
& operator<<(ostream
& out
, const coll_t
& c
) {
750 template<> struct hash
<coll_t
> {
751 size_t operator()(const coll_t
&c
) const {
753 string
str(c
.to_str());
754 std::string::const_iterator
end(str
.end());
755 for (std::string::const_iterator s
= str
.begin(); s
!= end
; ++s
) {
768 inline ostream
& operator<<(ostream
& out
, const ceph_object_layout
&ol
)
770 out
<< pg_t(ol
.ol_pgid
);
771 int su
= ol
.ol_stripe_unit
;
779 // compound rados version type
780 /* WARNING: If add member in eversion_t, please make sure the encode/decode function
781 * work well. For little-endian machine, we should make sure there is no padding
782 * in 32-bit machine and 64-bit machine.
789 eversion_t() : version(0), epoch(0), __pad(0) {}
790 eversion_t(epoch_t e
, version_t v
) : version(v
), epoch(e
), __pad(0) {}
792 // cppcheck-suppress noExplicitConstructor
793 eversion_t(const ceph_eversion
& ce
) :
798 explicit eversion_t(bufferlist
& bl
) : __pad(0) { decode(bl
); }
800 static eversion_t
max() {
807 operator ceph_eversion() {
814 string
get_key_name() const;
816 void encode(bufferlist
&bl
) const {
817 #if defined(CEPH_LITTLE_ENDIAN)
818 bl
.append((char *)this, sizeof(version_t
) + sizeof(epoch_t
));
820 ::encode(version
, bl
);
824 void decode(bufferlist::iterator
&bl
) {
825 #if defined(CEPH_LITTLE_ENDIAN)
826 bl
.copy(sizeof(version_t
) + sizeof(epoch_t
), (char *)this);
828 ::decode(version
, bl
);
832 void decode(bufferlist
& bl
) {
833 bufferlist::iterator p
= bl
.begin();
837 WRITE_CLASS_ENCODER(eversion_t
)
839 inline bool operator==(const eversion_t
& l
, const eversion_t
& r
) {
840 return (l
.epoch
== r
.epoch
) && (l
.version
== r
.version
);
842 inline bool operator!=(const eversion_t
& l
, const eversion_t
& r
) {
843 return (l
.epoch
!= r
.epoch
) || (l
.version
!= r
.version
);
845 inline bool operator<(const eversion_t
& l
, const eversion_t
& r
) {
846 return (l
.epoch
== r
.epoch
) ? (l
.version
< r
.version
):(l
.epoch
< r
.epoch
);
848 inline bool operator<=(const eversion_t
& l
, const eversion_t
& r
) {
849 return (l
.epoch
== r
.epoch
) ? (l
.version
<= r
.version
):(l
.epoch
<= r
.epoch
);
851 inline bool operator>(const eversion_t
& l
, const eversion_t
& r
) {
852 return (l
.epoch
== r
.epoch
) ? (l
.version
> r
.version
):(l
.epoch
> r
.epoch
);
854 inline bool operator>=(const eversion_t
& l
, const eversion_t
& r
) {
855 return (l
.epoch
== r
.epoch
) ? (l
.version
>= r
.version
):(l
.epoch
>= r
.epoch
);
857 inline ostream
& operator<<(ostream
& out
, const eversion_t
& e
) {
858 return out
<< e
.epoch
<< "'" << e
.version
;
862 * objectstore_perf_stat_t
864 * current perf information about the osd
866 struct objectstore_perf_stat_t
{
867 // cur_op_latency is in ms since double add/sub are not associative
868 uint32_t os_commit_latency
;
869 uint32_t os_apply_latency
;
871 objectstore_perf_stat_t() :
872 os_commit_latency(0), os_apply_latency(0) {}
874 bool operator==(const objectstore_perf_stat_t
&r
) const {
875 return os_commit_latency
== r
.os_commit_latency
&&
876 os_apply_latency
== r
.os_apply_latency
;
879 void add(const objectstore_perf_stat_t
&o
) {
880 os_commit_latency
+= o
.os_commit_latency
;
881 os_apply_latency
+= o
.os_apply_latency
;
883 void sub(const objectstore_perf_stat_t
&o
) {
884 os_commit_latency
-= o
.os_commit_latency
;
885 os_apply_latency
-= o
.os_apply_latency
;
887 void dump(Formatter
*f
) const;
888 void encode(bufferlist
&bl
) const;
889 void decode(bufferlist::iterator
&bl
);
890 static void generate_test_instances(std::list
<objectstore_perf_stat_t
*>& o
);
892 WRITE_CLASS_ENCODER(objectstore_perf_stat_t
)
895 * aggregate stats for an osd
898 int64_t kb
, kb_used
, kb_avail
;
899 vector
<int> hb_peers
;
900 int32_t snap_trim_queue_len
, num_snap_trimming
;
902 pow2_hist_t op_queue_age_hist
;
904 objectstore_perf_stat_t os_perf_stat
;
909 uint32_t num_pgs
= 0;
911 osd_stat_t() : kb(0), kb_used(0), kb_avail(0),
912 snap_trim_queue_len(0), num_snap_trimming(0) {}
914 void add(const osd_stat_t
& o
) {
916 kb_used
+= o
.kb_used
;
917 kb_avail
+= o
.kb_avail
;
918 snap_trim_queue_len
+= o
.snap_trim_queue_len
;
919 num_snap_trimming
+= o
.num_snap_trimming
;
920 op_queue_age_hist
.add(o
.op_queue_age_hist
);
921 os_perf_stat
.add(o
.os_perf_stat
);
922 num_pgs
+= o
.num_pgs
;
924 void sub(const osd_stat_t
& o
) {
926 kb_used
-= o
.kb_used
;
927 kb_avail
-= o
.kb_avail
;
928 snap_trim_queue_len
-= o
.snap_trim_queue_len
;
929 num_snap_trimming
-= o
.num_snap_trimming
;
930 op_queue_age_hist
.sub(o
.op_queue_age_hist
);
931 os_perf_stat
.sub(o
.os_perf_stat
);
932 num_pgs
-= o
.num_pgs
;
935 void dump(Formatter
*f
) const;
936 void encode(bufferlist
&bl
) const;
937 void decode(bufferlist::iterator
&bl
);
938 static void generate_test_instances(std::list
<osd_stat_t
*>& o
);
940 WRITE_CLASS_ENCODER(osd_stat_t
)
942 inline bool operator==(const osd_stat_t
& l
, const osd_stat_t
& r
) {
943 return l
.kb
== r
.kb
&&
944 l
.kb_used
== r
.kb_used
&&
945 l
.kb_avail
== r
.kb_avail
&&
946 l
.snap_trim_queue_len
== r
.snap_trim_queue_len
&&
947 l
.num_snap_trimming
== r
.num_snap_trimming
&&
948 l
.hb_peers
== r
.hb_peers
&&
949 l
.op_queue_age_hist
== r
.op_queue_age_hist
&&
950 l
.os_perf_stat
== r
.os_perf_stat
&&
951 l
.num_pgs
== r
.num_pgs
;
953 inline bool operator!=(const osd_stat_t
& l
, const osd_stat_t
& r
) {
959 inline ostream
& operator<<(ostream
& out
, const osd_stat_t
& s
) {
960 return out
<< "osd_stat(" << kb_t(s
.kb_used
) << " used, "
961 << kb_t(s
.kb_avail
) << " avail, "
962 << kb_t(s
.kb
) << " total, "
963 << "peers " << s
.hb_peers
964 << " op hist " << s
.op_queue_age_hist
.h
972 #define PG_STATE_CREATING (1<<0) // creating
973 #define PG_STATE_ACTIVE (1<<1) // i am active. (primary: replicas too)
974 #define PG_STATE_CLEAN (1<<2) // peers are complete, clean of stray replicas.
975 #define PG_STATE_DOWN (1<<4) // a needed replica is down, PG offline
976 #define PG_STATE_RECOVERY_UNFOUND (1<<5) // recovery stopped due to unfound
977 #define PG_STATE_BACKFILL_UNFOUND (1<<6) // backfill stopped due to unfound
978 //#define PG_STATE_SPLITTING (1<<7) // i am splitting
979 #define PG_STATE_SCRUBBING (1<<8) // scrubbing
980 //#define PG_STATE_SCRUBQ (1<<9) // queued for scrub
981 #define PG_STATE_DEGRADED (1<<10) // pg contains objects with reduced redundancy
982 #define PG_STATE_INCONSISTENT (1<<11) // pg replicas are inconsistent (but shouldn't be)
983 #define PG_STATE_PEERING (1<<12) // pg is (re)peering
984 #define PG_STATE_REPAIR (1<<13) // pg should repair on next scrub
985 #define PG_STATE_RECOVERING (1<<14) // pg is recovering/migrating objects
986 #define PG_STATE_BACKFILL_WAIT (1<<15) // [active] reserving backfill
987 #define PG_STATE_INCOMPLETE (1<<16) // incomplete content, peering failed.
988 #define PG_STATE_STALE (1<<17) // our state for this pg is stale, unknown.
989 #define PG_STATE_REMAPPED (1<<18) // pg is explicitly remapped to different OSDs than CRUSH
990 #define PG_STATE_DEEP_SCRUB (1<<19) // deep scrub: check CRC32 on files
991 #define PG_STATE_BACKFILLING (1<<20) // [active] backfilling pg content
992 #define PG_STATE_BACKFILL_TOOFULL (1<<21) // backfill can't proceed: too full
993 #define PG_STATE_RECOVERY_WAIT (1<<22) // waiting for recovery reservations
994 #define PG_STATE_UNDERSIZED (1<<23) // pg acting < pool size
995 #define PG_STATE_ACTIVATING (1<<24) // pg is peered but not yet active
996 #define PG_STATE_PEERED (1<<25) // peered, cannot go active, can recover
997 #define PG_STATE_SNAPTRIM (1<<26) // trimming snaps
998 #define PG_STATE_SNAPTRIM_WAIT (1<<27) // queued to trim snaps
999 #define PG_STATE_RECOVERY_TOOFULL (1<<28) // recovery can't proceed: too full
1000 #define PG_STATE_SNAPTRIM_ERROR (1<<29) // error stopped trimming snaps
1001 #define PG_STATE_FORCED_RECOVERY (1<<30) // force recovery of this pg before any other
1002 #define PG_STATE_FORCED_BACKFILL (1<<31) // force backfill of this pg before any other
1004 std::string
pg_state_string(int state
);
1005 std::string
pg_vector_string(const vector
<int32_t> &a
);
1006 boost::optional
<uint64_t> pg_string_state(const std::string
& state
);
1012 * attributes for a single pool snapshot.
1014 struct pool_snap_info_t
{
1019 void dump(Formatter
*f
) const;
1020 void encode(bufferlist
& bl
, uint64_t features
) const;
1021 void decode(bufferlist::iterator
& bl
);
1022 static void generate_test_instances(list
<pool_snap_info_t
*>& o
);
1024 WRITE_CLASS_ENCODER_FEATURES(pool_snap_info_t
)
1026 inline ostream
& operator<<(ostream
& out
, const pool_snap_info_t
& si
) {
1027 return out
<< si
.snapid
<< '(' << si
.name
<< ' ' << si
.stamp
<< ')';
1042 DEEP_SCRUB_INTERVAL
,
1044 RECOVERY_OP_PRIORITY
,
1047 COMPRESSION_ALGORITHM
,
1048 COMPRESSION_REQUIRED_RATIO
,
1049 COMPRESSION_MAX_BLOB_SIZE
,
1050 COMPRESSION_MIN_BLOB_SIZE
,
1066 opt_desc_t(key_t k
, type_t t
) : key(k
), type(t
) {}
1068 bool operator==(const opt_desc_t
& rhs
) const {
1069 return key
== rhs
.key
&& type
== rhs
.type
;
1073 typedef boost::variant
<std::string
,int,double> value_t
;
1075 static bool is_opt_name(const std::string
& name
);
1076 static opt_desc_t
get_opt_desc(const std::string
& name
);
1078 pool_opts_t() : opts() {}
1080 bool is_set(key_t key
) const;
1082 template<typename T
>
1083 void set(key_t key
, const T
&val
) {
1084 value_t value
= val
;
1088 template<typename T
>
1089 bool get(key_t key
, T
*val
) const {
1090 opts_t::const_iterator i
= opts
.find(key
);
1091 if (i
== opts
.end()) {
1094 *val
= boost::get
<T
>(i
->second
);
1098 const value_t
& get(key_t key
) const;
1100 bool unset(key_t key
);
1102 void dump(const std::string
& name
, Formatter
*f
) const;
1104 void dump(Formatter
*f
) const;
1105 void encode(bufferlist
&bl
) const;
1106 void decode(bufferlist::iterator
&bl
);
1109 typedef std::map
<key_t
, value_t
> opts_t
;
1112 friend ostream
& operator<<(ostream
& out
, const pool_opts_t
& opts
);
1114 WRITE_CLASS_ENCODER(pool_opts_t
)
1120 static const char *APPLICATION_NAME_CEPHFS
;
1121 static const char *APPLICATION_NAME_RBD
;
1122 static const char *APPLICATION_NAME_RGW
;
1125 TYPE_REPLICATED
= 1, // replication
1126 //TYPE_RAID4 = 2, // raid4 (never implemented)
1127 TYPE_ERASURE
= 3, // erasure-coded
1129 static const char *get_type_name(int t
) {
1131 case TYPE_REPLICATED
: return "replicated";
1132 //case TYPE_RAID4: return "raid4";
1133 case TYPE_ERASURE
: return "erasure";
1134 default: return "???";
1137 const char *get_type_name() const {
1138 return get_type_name(type
);
1142 FLAG_HASHPSPOOL
= 1<<0, // hash pg seed and pool together (instead of adding)
1143 FLAG_FULL
= 1<<1, // pool is full
1144 FLAG_EC_OVERWRITES
= 1<<2, // enables overwrites, once enabled, cannot be disabled
1145 FLAG_INCOMPLETE_CLONES
= 1<<3, // may have incomplete clones (bc we are/were an overlay)
1146 FLAG_NODELETE
= 1<<4, // pool can't be deleted
1147 FLAG_NOPGCHANGE
= 1<<5, // pool's pg and pgp num can't be changed
1148 FLAG_NOSIZECHANGE
= 1<<6, // pool's size and min size can't be changed
1149 FLAG_WRITE_FADVISE_DONTNEED
= 1<<7, // write mode with LIBRADOS_OP_FLAG_FADVISE_DONTNEED
1150 FLAG_NOSCRUB
= 1<<8, // block periodic scrub
1151 FLAG_NODEEP_SCRUB
= 1<<9, // block periodic deep-scrub
1152 FLAG_FULL_NO_QUOTA
= 1<<10, // pool is currently running out of quota, will set FLAG_FULL too
1153 FLAG_NEARFULL
= 1<<11, // pool is nearfull
1154 FLAG_BACKFILLFULL
= 1<<12, // pool is backfillfull
1157 static const char *get_flag_name(int f
) {
1159 case FLAG_HASHPSPOOL
: return "hashpspool";
1160 case FLAG_FULL
: return "full";
1161 case FLAG_EC_OVERWRITES
: return "ec_overwrites";
1162 case FLAG_INCOMPLETE_CLONES
: return "incomplete_clones";
1163 case FLAG_NODELETE
: return "nodelete";
1164 case FLAG_NOPGCHANGE
: return "nopgchange";
1165 case FLAG_NOSIZECHANGE
: return "nosizechange";
1166 case FLAG_WRITE_FADVISE_DONTNEED
: return "write_fadvise_dontneed";
1167 case FLAG_NOSCRUB
: return "noscrub";
1168 case FLAG_NODEEP_SCRUB
: return "nodeep-scrub";
1169 case FLAG_FULL_NO_QUOTA
: return "full_no_quota";
1170 case FLAG_NEARFULL
: return "nearfull";
1171 case FLAG_BACKFILLFULL
: return "backfillfull";
1172 default: return "???";
1175 static string
get_flags_string(uint64_t f
) {
1177 for (unsigned n
=0; f
&& n
<64; ++n
) {
1178 if (f
& (1ull << n
)) {
1181 s
+= get_flag_name(1ull << n
);
1186 string
get_flags_string() const {
1187 return get_flags_string(flags
);
1189 static uint64_t get_flag_by_name(const string
& name
) {
1190 if (name
== "hashpspool")
1191 return FLAG_HASHPSPOOL
;
1194 if (name
== "ec_overwrites")
1195 return FLAG_EC_OVERWRITES
;
1196 if (name
== "incomplete_clones")
1197 return FLAG_INCOMPLETE_CLONES
;
1198 if (name
== "nodelete")
1199 return FLAG_NODELETE
;
1200 if (name
== "nopgchange")
1201 return FLAG_NOPGCHANGE
;
1202 if (name
== "nosizechange")
1203 return FLAG_NOSIZECHANGE
;
1204 if (name
== "write_fadvise_dontneed")
1205 return FLAG_WRITE_FADVISE_DONTNEED
;
1206 if (name
== "noscrub")
1207 return FLAG_NOSCRUB
;
1208 if (name
== "nodeep-scrub")
1209 return FLAG_NODEEP_SCRUB
;
1210 if (name
== "full_no_quota")
1211 return FLAG_FULL_NO_QUOTA
;
1212 if (name
== "nearfull")
1213 return FLAG_NEARFULL
;
1214 if (name
== "backfillfull")
1215 return FLAG_BACKFILLFULL
;
1219 /// converts the acting/up vector to a set of pg shards
1220 void convert_to_pg_shards(const vector
<int> &from
, set
<pg_shard_t
>* to
) const;
1223 CACHEMODE_NONE
= 0, ///< no caching
1224 CACHEMODE_WRITEBACK
= 1, ///< write to cache, flush later
1225 CACHEMODE_FORWARD
= 2, ///< forward if not in cache
1226 CACHEMODE_READONLY
= 3, ///< handle reads, forward writes [not strongly consistent]
1227 CACHEMODE_READFORWARD
= 4, ///< forward reads, write to cache flush later
1228 CACHEMODE_READPROXY
= 5, ///< proxy reads, write to cache flush later
1229 CACHEMODE_PROXY
= 6, ///< proxy if not in cache
1231 static const char *get_cache_mode_name(cache_mode_t m
) {
1233 case CACHEMODE_NONE
: return "none";
1234 case CACHEMODE_WRITEBACK
: return "writeback";
1235 case CACHEMODE_FORWARD
: return "forward";
1236 case CACHEMODE_READONLY
: return "readonly";
1237 case CACHEMODE_READFORWARD
: return "readforward";
1238 case CACHEMODE_READPROXY
: return "readproxy";
1239 case CACHEMODE_PROXY
: return "proxy";
1240 default: return "unknown";
1243 static cache_mode_t
get_cache_mode_from_str(const string
& s
) {
1245 return CACHEMODE_NONE
;
1246 if (s
== "writeback")
1247 return CACHEMODE_WRITEBACK
;
1249 return CACHEMODE_FORWARD
;
1250 if (s
== "readonly")
1251 return CACHEMODE_READONLY
;
1252 if (s
== "readforward")
1253 return CACHEMODE_READFORWARD
;
1254 if (s
== "readproxy")
1255 return CACHEMODE_READPROXY
;
1257 return CACHEMODE_PROXY
;
1258 return (cache_mode_t
)-1;
1260 const char *get_cache_mode_name() const {
1261 return get_cache_mode_name(cache_mode
);
1263 bool cache_mode_requires_hit_set() const {
1264 switch (cache_mode
) {
1265 case CACHEMODE_NONE
:
1266 case CACHEMODE_FORWARD
:
1267 case CACHEMODE_READONLY
:
1268 case CACHEMODE_PROXY
:
1270 case CACHEMODE_WRITEBACK
:
1271 case CACHEMODE_READFORWARD
:
1272 case CACHEMODE_READPROXY
:
1275 assert(0 == "implement me");
1279 uint64_t flags
; ///< FLAG_*
1280 __u8 type
; ///< TYPE_*
1281 __u8 size
, min_size
; ///< number of osds in each pg
1282 __u8 crush_rule
; ///< crush placement rule
1283 __u8 object_hash
; ///< hash mapping object name to ps
1285 __u32 pg_num
, pgp_num
; ///< number of pgs
1289 map
<string
,string
> properties
; ///< OBSOLETE
1290 string erasure_code_profile
; ///< name of the erasure code profile in OSDMap
1291 epoch_t last_change
; ///< most recent epoch changed, exclusing snapshot changes
1292 epoch_t last_force_op_resend
; ///< last epoch that forced clients to resend
1293 /// last epoch that forced clients to resend (pre-luminous clients only)
1294 epoch_t last_force_op_resend_preluminous
;
1295 snapid_t snap_seq
; ///< seq for per-pool snapshot
1296 epoch_t snap_epoch
; ///< osdmap epoch of last snap
1297 uint64_t auid
; ///< who owns the pg
1298 __u32 crash_replay_interval
; ///< seconds to allow clients to replay ACKed but unCOMMITted requests
1300 uint64_t quota_max_bytes
; ///< maximum number of bytes for this pool
1301 uint64_t quota_max_objects
; ///< maximum number of objects for this pool
1304 * Pool snaps (global to this pool). These define a SnapContext for
1305 * the pool, unless the client manually specifies an alternate
1308 map
<snapid_t
, pool_snap_info_t
> snaps
;
1310 * Alternatively, if we are defining non-pool snaps (e.g. via the
1311 * Ceph MDS), we must track @removed_snaps (since @snaps is not
1312 * used). Snaps and removed_snaps are to be used exclusive of each
1315 interval_set
<snapid_t
> removed_snaps
;
1317 unsigned pg_num_mask
, pgp_num_mask
;
1319 set
<uint64_t> tiers
; ///< pools that are tiers of us
1320 int64_t tier_of
; ///< pool for which we are a tier
1321 // Note that write wins for read+write ops
1322 int64_t read_tier
; ///< pool/tier for objecter to direct reads to
1323 int64_t write_tier
; ///< pool/tier for objecter to direct writes to
1324 cache_mode_t cache_mode
; ///< cache pool mode
1326 bool is_tier() const { return tier_of
>= 0; }
1327 bool has_tiers() const { return !tiers
.empty(); }
1332 clear_tier_tunables();
1334 bool has_read_tier() const { return read_tier
>= 0; }
1335 void clear_read_tier() { read_tier
= -1; }
1336 bool has_write_tier() const { return write_tier
>= 0; }
1337 void clear_write_tier() { write_tier
= -1; }
1338 void clear_tier_tunables() {
1339 if (cache_mode
!= CACHEMODE_NONE
)
1340 flags
|= FLAG_INCOMPLETE_CLONES
;
1341 cache_mode
= CACHEMODE_NONE
;
1343 target_max_bytes
= 0;
1344 target_max_objects
= 0;
1345 cache_target_dirty_ratio_micro
= 0;
1346 cache_target_dirty_high_ratio_micro
= 0;
1347 cache_target_full_ratio_micro
= 0;
1348 hit_set_params
= HitSet::Params();
1351 hit_set_grade_decay_rate
= 0;
1352 hit_set_search_last_n
= 0;
1353 grade_table
.resize(0);
1356 uint64_t target_max_bytes
; ///< tiering: target max pool size
1357 uint64_t target_max_objects
; ///< tiering: target max pool size
1359 uint32_t cache_target_dirty_ratio_micro
; ///< cache: fraction of target to leave dirty
1360 uint32_t cache_target_dirty_high_ratio_micro
; ///<cache: fraction of target to flush with high speed
1361 uint32_t cache_target_full_ratio_micro
; ///< cache: fraction of target to fill before we evict in earnest
1363 uint32_t cache_min_flush_age
; ///< minimum age (seconds) before we can flush
1364 uint32_t cache_min_evict_age
; ///< minimum age (seconds) before we can evict
1366 HitSet::Params hit_set_params
; ///< The HitSet params to use on this pool
1367 uint32_t hit_set_period
; ///< periodicity of HitSet segments (seconds)
1368 uint32_t hit_set_count
; ///< number of periods to retain
1369 bool use_gmt_hitset
; ///< use gmt to name the hitset archive object
1370 uint32_t min_read_recency_for_promote
; ///< minimum number of HitSet to check before promote on read
1371 uint32_t min_write_recency_for_promote
; ///< minimum number of HitSet to check before promote on write
1372 uint32_t hit_set_grade_decay_rate
; ///< current hit_set has highest priority on objects
1373 ///temperature count,the follow hit_set's priority decay
1374 ///by this params than pre hit_set
1375 uint32_t hit_set_search_last_n
; ///<accumulate atmost N hit_sets for temperature
1377 uint32_t stripe_width
; ///< erasure coded stripe size in bytes
1379 uint64_t expected_num_objects
; ///< expected number of objects on this pool, a value of 0 indicates
1380 ///< user does not specify any expected value
1381 bool fast_read
; ///< whether turn on fast read on the pool or not
1383 pool_opts_t opts
; ///< options
1385 /// application -> key/value metadata
1386 map
<string
, std::map
<string
, string
>> application_metadata
;
1389 vector
<uint32_t> grade_table
;
1392 uint32_t get_grade(unsigned i
) const {
1393 if (grade_table
.size() <= i
)
1395 return grade_table
[i
];
1397 void calc_grade_table() {
1398 unsigned v
= 1000000;
1399 grade_table
.resize(hit_set_count
);
1400 for (unsigned i
= 0; i
< hit_set_count
; i
++) {
1401 v
= v
* (1 - (hit_set_grade_decay_rate
/ 100.0));
1407 : flags(0), type(0), size(0), min_size(0),
1408 crush_rule(0), object_hash(0),
1409 pg_num(0), pgp_num(0),
1411 last_force_op_resend(0),
1412 last_force_op_resend_preluminous(0),
1413 snap_seq(0), snap_epoch(0),
1415 crash_replay_interval(0),
1416 quota_max_bytes(0), quota_max_objects(0),
1417 pg_num_mask(0), pgp_num_mask(0),
1418 tier_of(-1), read_tier(-1), write_tier(-1),
1419 cache_mode(CACHEMODE_NONE
),
1420 target_max_bytes(0), target_max_objects(0),
1421 cache_target_dirty_ratio_micro(0),
1422 cache_target_dirty_high_ratio_micro(0),
1423 cache_target_full_ratio_micro(0),
1424 cache_min_flush_age(0),
1425 cache_min_evict_age(0),
1429 use_gmt_hitset(true),
1430 min_read_recency_for_promote(0),
1431 min_write_recency_for_promote(0),
1432 hit_set_grade_decay_rate(0),
1433 hit_set_search_last_n(0),
1435 expected_num_objects(0),
1440 void dump(Formatter
*f
) const;
1442 uint64_t get_flags() const { return flags
; }
1443 bool has_flag(uint64_t f
) const { return flags
& f
; }
1444 void set_flag(uint64_t f
) { flags
|= f
; }
1445 void unset_flag(uint64_t f
) { flags
&= ~f
; }
1447 bool ec_pool() const {
1448 return type
== TYPE_ERASURE
;
1450 bool require_rollback() const {
1454 /// true if incomplete clones may be present
1455 bool allow_incomplete_clones() const {
1456 return cache_mode
!= CACHEMODE_NONE
|| has_flag(FLAG_INCOMPLETE_CLONES
);
1459 unsigned get_type() const { return type
; }
1460 unsigned get_size() const { return size
; }
1461 unsigned get_min_size() const { return min_size
; }
1462 int get_crush_rule() const { return crush_rule
; }
1463 int get_object_hash() const { return object_hash
; }
1464 const char *get_object_hash_name() const {
1465 return ceph_str_hash_name(get_object_hash());
1467 epoch_t
get_last_change() const { return last_change
; }
1468 epoch_t
get_last_force_op_resend() const { return last_force_op_resend
; }
1469 epoch_t
get_last_force_op_resend_preluminous() const {
1470 return last_force_op_resend_preluminous
;
1472 epoch_t
get_snap_epoch() const { return snap_epoch
; }
1473 snapid_t
get_snap_seq() const { return snap_seq
; }
1474 uint64_t get_auid() const { return auid
; }
1475 unsigned get_crash_replay_interval() const { return crash_replay_interval
; }
1477 void set_snap_seq(snapid_t s
) { snap_seq
= s
; }
1478 void set_snap_epoch(epoch_t e
) { snap_epoch
= e
; }
1480 void set_stripe_width(uint32_t s
) { stripe_width
= s
; }
1481 uint32_t get_stripe_width() const { return stripe_width
; }
1483 bool is_replicated() const { return get_type() == TYPE_REPLICATED
; }
1484 bool is_erasure() const { return get_type() == TYPE_ERASURE
; }
1486 bool supports_omap() const {
1487 return !(get_type() == TYPE_ERASURE
);
1490 bool requires_aligned_append() const {
1491 return is_erasure() && !has_flag(FLAG_EC_OVERWRITES
);
1493 uint64_t required_alignment() const { return stripe_width
; }
1495 bool allows_ecoverwrites() const {
1496 return has_flag(FLAG_EC_OVERWRITES
);
1499 bool can_shift_osds() const {
1500 switch (get_type()) {
1501 case TYPE_REPLICATED
:
1506 assert(0 == "unhandled pool type");
1510 unsigned get_pg_num() const { return pg_num
; }
1511 unsigned get_pgp_num() const { return pgp_num
; }
1513 unsigned get_pg_num_mask() const { return pg_num_mask
; }
1514 unsigned get_pgp_num_mask() const { return pgp_num_mask
; }
1516 // if pg_num is not a multiple of two, pgs are not equally sized.
1517 // return, for a given pg, the fraction (denominator) of the total
1518 // pool size that it represents.
1519 unsigned get_pg_num_divisor(pg_t pgid
) const;
1521 void set_pg_num(int p
) {
1525 void set_pgp_num(int p
) {
1530 void set_quota_max_bytes(uint64_t m
) {
1531 quota_max_bytes
= m
;
1533 uint64_t get_quota_max_bytes() {
1534 return quota_max_bytes
;
1537 void set_quota_max_objects(uint64_t m
) {
1538 quota_max_objects
= m
;
1540 uint64_t get_quota_max_objects() {
1541 return quota_max_objects
;
1544 void set_last_force_op_resend(uint64_t t
) {
1545 last_force_op_resend
= t
;
1546 last_force_op_resend_preluminous
= t
;
1549 void calc_pg_masks();
1552 * we have two snap modes:
1553 * - pool global snaps
1554 * - snap existence/non-existence defined by snaps[] and snap_seq
1555 * - user managed snaps
1556 * - removal governed by removed_snaps
1558 * we know which mode we're using based on whether removed_snaps is empty.
1559 * If nothing has been created, both functions report false.
1561 bool is_pool_snaps_mode() const;
1562 bool is_unmanaged_snaps_mode() const;
1563 bool is_removed_snap(snapid_t s
) const;
1566 * build set of known-removed sets from either pool snaps or
1567 * explicit removed_snaps set.
1569 void build_removed_snaps(interval_set
<snapid_t
>& rs
) const;
1570 snapid_t
snap_exists(const char *s
) const;
1571 void add_snap(const char *n
, utime_t stamp
);
1572 void add_unmanaged_snap(uint64_t& snapid
);
1573 void remove_snap(snapid_t s
);
1574 void remove_unmanaged_snap(snapid_t s
);
1576 SnapContext
get_snap_context() const;
1578 /// hash a object name+namespace key to a hash position
1579 uint32_t hash_key(const string
& key
, const string
& ns
) const;
1581 /// round a hash position down to a pg num
1582 uint32_t raw_hash_to_pg(uint32_t v
) const;
1585 * map a raw pg (with full precision ps) into an actual pg, for storage
1587 pg_t
raw_pg_to_pg(pg_t pg
) const;
1590 * map raw pg (full precision ps) into a placement seed. include
1591 * pool id in that value so that different pools don't use the same
1594 ps_t
raw_pg_to_pps(pg_t pg
) const;
1596 /// choose a random hash position within a pg
1597 uint32_t get_random_pg_position(pg_t pgid
, uint32_t seed
) const;
1599 void encode(bufferlist
& bl
, uint64_t features
) const;
1600 void decode(bufferlist::iterator
& bl
);
1602 static void generate_test_instances(list
<pg_pool_t
*>& o
);
1604 WRITE_CLASS_ENCODER_FEATURES(pg_pool_t
)
1606 ostream
& operator<<(ostream
& out
, const pg_pool_t
& p
);
1610 * a summation of object stats
1612 * This is just a container for object stats; we don't know what for.
1614 * If you add members in object_stat_sum_t, you should make sure there are
1615 * not padding among these members.
1616 * You should also modify the padding_check function.
1619 struct object_stat_sum_t
{
1620 /**************************************************************************
1621 * WARNING: be sure to update operator==, floor, and split when
1622 * adding/removing fields!
1623 **************************************************************************/
1624 int64_t num_bytes
; // in bytes
1625 int64_t num_objects
;
1626 int64_t num_object_clones
;
1627 int64_t num_object_copies
; // num_objects * num_replicas
1628 int64_t num_objects_missing_on_primary
;
1629 int64_t num_objects_degraded
;
1630 int64_t num_objects_unfound
;
1635 int64_t num_scrub_errors
; // total deep and shallow scrub errors
1636 int64_t num_objects_recovered
;
1637 int64_t num_bytes_recovered
;
1638 int64_t num_keys_recovered
;
1639 int64_t num_shallow_scrub_errors
;
1640 int64_t num_deep_scrub_errors
;
1641 int64_t num_objects_dirty
;
1642 int64_t num_whiteouts
;
1643 int64_t num_objects_omap
;
1644 int64_t num_objects_hit_set_archive
;
1645 int64_t num_objects_misplaced
;
1646 int64_t num_bytes_hit_set_archive
;
1648 int64_t num_flush_kb
;
1650 int64_t num_evict_kb
;
1651 int64_t num_promote
;
1652 int32_t num_flush_mode_high
; // 1 when in high flush mode, otherwise 0
1653 int32_t num_flush_mode_low
; // 1 when in low flush mode, otherwise 0
1654 int32_t num_evict_mode_some
; // 1 when in evict some mode, otherwise 0
1655 int32_t num_evict_mode_full
; // 1 when in evict full mode, otherwise 0
1656 int64_t num_objects_pinned
;
1657 int64_t num_objects_missing
;
1658 int64_t num_legacy_snapsets
; ///< upper bound on pre-luminous-style SnapSets
1662 num_objects(0), num_object_clones(0), num_object_copies(0),
1663 num_objects_missing_on_primary(0), num_objects_degraded(0),
1664 num_objects_unfound(0),
1665 num_rd(0), num_rd_kb(0), num_wr(0), num_wr_kb(0),
1666 num_scrub_errors(0),
1667 num_objects_recovered(0),
1668 num_bytes_recovered(0),
1669 num_keys_recovered(0),
1670 num_shallow_scrub_errors(0),
1671 num_deep_scrub_errors(0),
1672 num_objects_dirty(0),
1674 num_objects_omap(0),
1675 num_objects_hit_set_archive(0),
1676 num_objects_misplaced(0),
1677 num_bytes_hit_set_archive(0),
1683 num_flush_mode_high(0), num_flush_mode_low(0),
1684 num_evict_mode_some(0), num_evict_mode_full(0),
1685 num_objects_pinned(0),
1686 num_objects_missing(0),
1687 num_legacy_snapsets(0)
1690 void floor(int64_t f
) {
1691 #define FLOOR(x) if (x < f) x = f
1694 FLOOR(num_object_clones
);
1695 FLOOR(num_object_copies
);
1696 FLOOR(num_objects_missing_on_primary
);
1697 FLOOR(num_objects_missing
);
1698 FLOOR(num_objects_degraded
);
1699 FLOOR(num_objects_misplaced
);
1700 FLOOR(num_objects_unfound
);
1705 FLOOR(num_scrub_errors
);
1706 FLOOR(num_shallow_scrub_errors
);
1707 FLOOR(num_deep_scrub_errors
);
1708 FLOOR(num_objects_recovered
);
1709 FLOOR(num_bytes_recovered
);
1710 FLOOR(num_keys_recovered
);
1711 FLOOR(num_objects_dirty
);
1712 FLOOR(num_whiteouts
);
1713 FLOOR(num_objects_omap
);
1714 FLOOR(num_objects_hit_set_archive
);
1715 FLOOR(num_bytes_hit_set_archive
);
1717 FLOOR(num_flush_kb
);
1719 FLOOR(num_evict_kb
);
1721 FLOOR(num_flush_mode_high
);
1722 FLOOR(num_flush_mode_low
);
1723 FLOOR(num_evict_mode_some
);
1724 FLOOR(num_evict_mode_full
);
1725 FLOOR(num_objects_pinned
);
1726 FLOOR(num_legacy_snapsets
);
1730 void split(vector
<object_stat_sum_t
> &out
) const {
1731 #define SPLIT(PARAM) \
1732 for (unsigned i = 0; i < out.size(); ++i) { \
1733 out[i].PARAM = PARAM / out.size(); \
1734 if (i < (PARAM % out.size())) { \
1738 #define SPLIT_PRESERVE_NONZERO(PARAM) \
1739 for (unsigned i = 0; i < out.size(); ++i) { \
1741 out[i].PARAM = 1 + PARAM / out.size(); \
1748 SPLIT(num_object_clones
);
1749 SPLIT(num_object_copies
);
1750 SPLIT(num_objects_missing_on_primary
);
1751 SPLIT(num_objects_missing
);
1752 SPLIT(num_objects_degraded
);
1753 SPLIT(num_objects_misplaced
);
1754 SPLIT(num_objects_unfound
);
1759 SPLIT(num_scrub_errors
);
1760 SPLIT(num_shallow_scrub_errors
);
1761 SPLIT(num_deep_scrub_errors
);
1762 SPLIT(num_objects_recovered
);
1763 SPLIT(num_bytes_recovered
);
1764 SPLIT(num_keys_recovered
);
1765 SPLIT(num_objects_dirty
);
1766 SPLIT(num_whiteouts
);
1767 SPLIT(num_objects_omap
);
1768 SPLIT(num_objects_hit_set_archive
);
1769 SPLIT(num_bytes_hit_set_archive
);
1771 SPLIT(num_flush_kb
);
1773 SPLIT(num_evict_kb
);
1775 SPLIT(num_flush_mode_high
);
1776 SPLIT(num_flush_mode_low
);
1777 SPLIT(num_evict_mode_some
);
1778 SPLIT(num_evict_mode_full
);
1779 SPLIT(num_objects_pinned
);
1780 SPLIT_PRESERVE_NONZERO(num_legacy_snapsets
);
1782 #undef SPLIT_PRESERVE_NONZERO
1786 memset(this, 0, sizeof(*this));
1789 void calc_copies(int nrep
) {
1790 num_object_copies
= nrep
* num_objects
;
1793 bool is_zero() const {
1794 return mem_is_zero((char*)this, sizeof(*this));
1797 void add(const object_stat_sum_t
& o
);
1798 void sub(const object_stat_sum_t
& o
);
1800 void dump(Formatter
*f
) const;
1801 void padding_check() {
1803 sizeof(object_stat_sum_t
) ==
1805 sizeof(num_objects
) +
1806 sizeof(num_object_clones
) +
1807 sizeof(num_object_copies
) +
1808 sizeof(num_objects_missing_on_primary
) +
1809 sizeof(num_objects_degraded
) +
1810 sizeof(num_objects_unfound
) +
1815 sizeof(num_scrub_errors
) +
1816 sizeof(num_objects_recovered
) +
1817 sizeof(num_bytes_recovered
) +
1818 sizeof(num_keys_recovered
) +
1819 sizeof(num_shallow_scrub_errors
) +
1820 sizeof(num_deep_scrub_errors
) +
1821 sizeof(num_objects_dirty
) +
1822 sizeof(num_whiteouts
) +
1823 sizeof(num_objects_omap
) +
1824 sizeof(num_objects_hit_set_archive
) +
1825 sizeof(num_objects_misplaced
) +
1826 sizeof(num_bytes_hit_set_archive
) +
1828 sizeof(num_flush_kb
) +
1830 sizeof(num_evict_kb
) +
1831 sizeof(num_promote
) +
1832 sizeof(num_flush_mode_high
) +
1833 sizeof(num_flush_mode_low
) +
1834 sizeof(num_evict_mode_some
) +
1835 sizeof(num_evict_mode_full
) +
1836 sizeof(num_objects_pinned
) +
1837 sizeof(num_objects_missing
) +
1838 sizeof(num_legacy_snapsets
)
1840 "object_stat_sum_t have padding");
1842 void encode(bufferlist
& bl
) const;
1843 void decode(bufferlist::iterator
& bl
);
1844 static void generate_test_instances(list
<object_stat_sum_t
*>& o
);
1846 WRITE_CLASS_ENCODER(object_stat_sum_t
)
1848 bool operator==(const object_stat_sum_t
& l
, const object_stat_sum_t
& r
);
1851 * a collection of object stat sums
1853 * This is a collection of stat sums over different categories.
1855 struct object_stat_collection_t
{
1856 /**************************************************************************
1857 * WARNING: be sure to update the operator== when adding/removing fields! *
1858 **************************************************************************/
1859 object_stat_sum_t sum
;
1861 void calc_copies(int nrep
) {
1862 sum
.calc_copies(nrep
);
1865 void dump(Formatter
*f
) const;
1866 void encode(bufferlist
& bl
) const;
1867 void decode(bufferlist::iterator
& bl
);
1868 static void generate_test_instances(list
<object_stat_collection_t
*>& o
);
1870 bool is_zero() const {
1871 return sum
.is_zero();
1878 void floor(int64_t f
) {
1882 void add(const object_stat_sum_t
& o
) {
1886 void add(const object_stat_collection_t
& o
) {
1889 void sub(const object_stat_collection_t
& o
) {
1893 WRITE_CLASS_ENCODER(object_stat_collection_t
)
1895 inline bool operator==(const object_stat_collection_t
& l
,
1896 const object_stat_collection_t
& r
) {
1897 return l
.sum
== r
.sum
;
1902 * aggregate stats for a single PG.
1905 /**************************************************************************
1906 * WARNING: be sure to update the operator== when adding/removing fields! *
1907 **************************************************************************/
1909 version_t reported_seq
; // sequence number
1910 epoch_t reported_epoch
; // epoch of this report
1912 utime_t last_fresh
; // last reported
1913 utime_t last_change
; // new state != previous state
1914 utime_t last_active
; // state & PG_STATE_ACTIVE
1915 utime_t last_peered
; // state & PG_STATE_ACTIVE || state & PG_STATE_PEERED
1916 utime_t last_clean
; // state & PG_STATE_CLEAN
1917 utime_t last_unstale
; // (state & PG_STATE_STALE) == 0
1918 utime_t last_undegraded
; // (state & PG_STATE_DEGRADED) == 0
1919 utime_t last_fullsized
; // (state & PG_STATE_UNDERSIZED) == 0
1921 eversion_t log_start
; // (log_start,version]
1922 eversion_t ondisk_log_start
; // there may be more on disk
1925 epoch_t last_epoch_clean
;
1927 __u32 parent_split_bits
;
1929 eversion_t last_scrub
;
1930 eversion_t last_deep_scrub
;
1931 utime_t last_scrub_stamp
;
1932 utime_t last_deep_scrub_stamp
;
1933 utime_t last_clean_scrub_stamp
;
1935 object_stat_collection_t stats
;
1938 int64_t ondisk_log_size
; // >= active_log_size
1940 vector
<int32_t> up
, acting
;
1941 epoch_t mapping_epoch
;
1943 vector
<int32_t> blocked_by
; ///< osds on which the pg is blocked
1945 utime_t last_became_active
;
1946 utime_t last_became_peered
;
1948 /// up, acting primaries
1950 int32_t acting_primary
;
1952 // snaptrimq.size() is 64bit, but let's be serious - anything over 50k is
1953 // absurd already, so cap it to 2^32 and save 4 bytes at the same time
1954 uint32_t snaptrimq_len
;
1956 bool stats_invalid
:1;
1957 /// true if num_objects_dirty is not accurate (because it was not
1958 /// maintained starting from pool creation)
1959 bool dirty_stats_invalid
:1;
1960 bool omap_stats_invalid
:1;
1961 bool hitset_stats_invalid
:1;
1962 bool hitset_bytes_stats_invalid
:1;
1963 bool pin_stats_invalid
:1;
1969 created(0), last_epoch_clean(0),
1970 parent_split_bits(0),
1971 log_size(0), ondisk_log_size(0),
1976 stats_invalid(false),
1977 dirty_stats_invalid(false),
1978 omap_stats_invalid(false),
1979 hitset_stats_invalid(false),
1980 hitset_bytes_stats_invalid(false),
1981 pin_stats_invalid(false)
1984 epoch_t
get_effective_last_epoch_clean() const {
1985 if (state
& PG_STATE_CLEAN
) {
1986 // we are clean as of this report, and should thus take the
1988 return reported_epoch
;
1990 return last_epoch_clean
;
1994 pair
<epoch_t
, version_t
> get_version_pair() const {
1995 return make_pair(reported_epoch
, reported_seq
);
1998 void floor(int64_t f
) {
2002 if (ondisk_log_size
< f
)
2003 ondisk_log_size
= f
;
2004 if (snaptrimq_len
< f
)
2008 void add(const pg_stat_t
& o
) {
2010 log_size
+= o
.log_size
;
2011 ondisk_log_size
+= o
.ondisk_log_size
;
2012 if (((uint64_t)snaptrimq_len
+ (uint64_t)o
.snaptrimq_len
) > (uint64_t)(1 << 31)) {
2013 snaptrimq_len
= 1 << 31;
2015 snaptrimq_len
+= o
.snaptrimq_len
;
2018 void sub(const pg_stat_t
& o
) {
2020 log_size
-= o
.log_size
;
2021 ondisk_log_size
-= o
.ondisk_log_size
;
2022 if (o
.snaptrimq_len
< snaptrimq_len
) {
2023 snaptrimq_len
-= o
.snaptrimq_len
;
2029 bool is_acting_osd(int32_t osd
, bool primary
) const;
2030 void dump(Formatter
*f
) const;
2031 void dump_brief(Formatter
*f
) const;
2032 void encode(bufferlist
&bl
) const;
2033 void decode(bufferlist::iterator
&bl
);
2034 static void generate_test_instances(list
<pg_stat_t
*>& o
);
2036 WRITE_CLASS_ENCODER(pg_stat_t
)
2038 bool operator==(const pg_stat_t
& l
, const pg_stat_t
& r
);
2041 * summation over an entire pool
2043 struct pool_stat_t
{
2044 object_stat_collection_t stats
;
2046 int64_t ondisk_log_size
; // >= active_log_size
2047 int32_t up
; ///< number of up replicas or shards
2048 int32_t acting
; ///< number of acting replicas or shards
2050 pool_stat_t() : log_size(0), ondisk_log_size(0), up(0), acting(0)
2053 void floor(int64_t f
) {
2057 if (ondisk_log_size
< f
)
2058 ondisk_log_size
= f
;
2065 void add(const pg_stat_t
& o
) {
2067 log_size
+= o
.log_size
;
2068 ondisk_log_size
+= o
.ondisk_log_size
;
2070 acting
+= o
.acting
.size();
2072 void sub(const pg_stat_t
& o
) {
2074 log_size
-= o
.log_size
;
2075 ondisk_log_size
-= o
.ondisk_log_size
;
2077 acting
-= o
.acting
.size();
2080 bool is_zero() const {
2081 return (stats
.is_zero() &&
2083 ondisk_log_size
== 0 &&
2088 void dump(Formatter
*f
) const;
2089 void encode(bufferlist
&bl
, uint64_t features
) const;
2090 void decode(bufferlist::iterator
&bl
);
2091 static void generate_test_instances(list
<pool_stat_t
*>& o
);
2093 WRITE_CLASS_ENCODER_FEATURES(pool_stat_t
)
2096 // -----------------------------------------
2099 * pg_hit_set_info_t - information about a single recorded HitSet
2101 * Track basic metadata about a HitSet, like the nubmer of insertions
2102 * and the time range it covers.
2104 struct pg_hit_set_info_t
{
2105 utime_t begin
, end
; ///< time interval
2106 eversion_t version
; ///< version this HitSet object was written
2107 bool using_gmt
; ///< use gmt for creating the hit_set archive object name
2109 friend bool operator==(const pg_hit_set_info_t
& l
,
2110 const pg_hit_set_info_t
& r
) {
2112 l
.begin
== r
.begin
&&
2114 l
.version
== r
.version
&&
2115 l
.using_gmt
== r
.using_gmt
;
2118 explicit pg_hit_set_info_t(bool using_gmt
= true)
2119 : using_gmt(using_gmt
) {}
2121 void encode(bufferlist
&bl
) const;
2122 void decode(bufferlist::iterator
&bl
);
2123 void dump(Formatter
*f
) const;
2124 static void generate_test_instances(list
<pg_hit_set_info_t
*>& o
);
2126 WRITE_CLASS_ENCODER(pg_hit_set_info_t
)
2129 * pg_hit_set_history_t - information about a history of hitsets
2131 * Include information about the currently accumulating hit set as well
2132 * as archived/historical ones.
2134 struct pg_hit_set_history_t
{
2135 eversion_t current_last_update
; ///< last version inserted into current set
2136 list
<pg_hit_set_info_t
> history
; ///< archived sets, sorted oldest -> newest
2138 friend bool operator==(const pg_hit_set_history_t
& l
,
2139 const pg_hit_set_history_t
& r
) {
2141 l
.current_last_update
== r
.current_last_update
&&
2142 l
.history
== r
.history
;
2145 void encode(bufferlist
&bl
) const;
2146 void decode(bufferlist::iterator
&bl
);
2147 void dump(Formatter
*f
) const;
2148 static void generate_test_instances(list
<pg_hit_set_history_t
*>& o
);
2150 WRITE_CLASS_ENCODER(pg_hit_set_history_t
)
2153 // -----------------------------------------
2156 * pg_history_t - information about recent pg peering/mapping history
2158 * This is aggressively shared between OSDs to bound the amount of past
2159 * history they need to worry about.
2161 struct pg_history_t
{
2162 epoch_t epoch_created
; // epoch in which *pg* was created (pool or pg)
2163 epoch_t epoch_pool_created
; // epoch in which *pool* was created
2164 // (note: may be pg creation epoch for
2165 // pre-luminous clusters)
2166 epoch_t last_epoch_started
; // lower bound on last epoch started (anywhere, not necessarily locally)
2167 epoch_t last_interval_started
; // first epoch of last_epoch_started interval
2168 epoch_t last_epoch_clean
; // lower bound on last epoch the PG was completely clean.
2169 epoch_t last_interval_clean
; // first epoch of last_epoch_clean interval
2170 epoch_t last_epoch_split
; // as parent or child
2171 epoch_t last_epoch_marked_full
; // pool or cluster
2174 * In the event of a map discontinuity, same_*_since may reflect the first
2175 * map the osd has seen in the new map sequence rather than the actual start
2176 * of the interval. This is ok since a discontinuity at epoch e means there
2177 * must have been a clean interval between e and now and that we cannot be
2178 * in the active set during the interval containing e.
2180 epoch_t same_up_since
; // same acting set since
2181 epoch_t same_interval_since
; // same acting AND up set since
2182 epoch_t same_primary_since
; // same primary at least back through this epoch.
2184 eversion_t last_scrub
;
2185 eversion_t last_deep_scrub
;
2186 utime_t last_scrub_stamp
;
2187 utime_t last_deep_scrub_stamp
;
2188 utime_t last_clean_scrub_stamp
;
2190 friend bool operator==(const pg_history_t
& l
, const pg_history_t
& r
) {
2192 l
.epoch_created
== r
.epoch_created
&&
2193 l
.epoch_pool_created
== r
.epoch_pool_created
&&
2194 l
.last_epoch_started
== r
.last_epoch_started
&&
2195 l
.last_interval_started
== r
.last_interval_started
&&
2196 l
.last_epoch_clean
== r
.last_epoch_clean
&&
2197 l
.last_interval_clean
== r
.last_interval_clean
&&
2198 l
.last_epoch_split
== r
.last_epoch_split
&&
2199 l
.last_epoch_marked_full
== r
.last_epoch_marked_full
&&
2200 l
.same_up_since
== r
.same_up_since
&&
2201 l
.same_interval_since
== r
.same_interval_since
&&
2202 l
.same_primary_since
== r
.same_primary_since
&&
2203 l
.last_scrub
== r
.last_scrub
&&
2204 l
.last_deep_scrub
== r
.last_deep_scrub
&&
2205 l
.last_scrub_stamp
== r
.last_scrub_stamp
&&
2206 l
.last_deep_scrub_stamp
== r
.last_deep_scrub_stamp
&&
2207 l
.last_clean_scrub_stamp
== r
.last_clean_scrub_stamp
;
2212 epoch_pool_created(0),
2213 last_epoch_started(0),
2214 last_interval_started(0),
2215 last_epoch_clean(0),
2216 last_interval_clean(0),
2217 last_epoch_split(0),
2218 last_epoch_marked_full(0),
2219 same_up_since(0), same_interval_since(0), same_primary_since(0) {}
2221 bool merge(const pg_history_t
&other
) {
2222 // Here, we only update the fields which cannot be calculated from the OSDmap.
2223 bool modified
= false;
2224 if (epoch_created
< other
.epoch_created
) {
2225 epoch_created
= other
.epoch_created
;
2228 if (epoch_pool_created
< other
.epoch_pool_created
) {
2229 // FIXME: for jewel compat only; this should either be 0 or always the
2230 // same value across all pg instances.
2231 epoch_pool_created
= other
.epoch_pool_created
;
2234 if (last_epoch_started
< other
.last_epoch_started
) {
2235 last_epoch_started
= other
.last_epoch_started
;
2238 if (last_interval_started
< other
.last_interval_started
) {
2239 last_interval_started
= other
.last_interval_started
;
2242 if (last_epoch_clean
< other
.last_epoch_clean
) {
2243 last_epoch_clean
= other
.last_epoch_clean
;
2246 if (last_interval_clean
< other
.last_interval_clean
) {
2247 last_interval_clean
= other
.last_interval_clean
;
2250 if (last_epoch_split
< other
.last_epoch_split
) {
2251 last_epoch_split
= other
.last_epoch_split
;
2254 if (last_epoch_marked_full
< other
.last_epoch_marked_full
) {
2255 last_epoch_marked_full
= other
.last_epoch_marked_full
;
2258 if (other
.last_scrub
> last_scrub
) {
2259 last_scrub
= other
.last_scrub
;
2262 if (other
.last_scrub_stamp
> last_scrub_stamp
) {
2263 last_scrub_stamp
= other
.last_scrub_stamp
;
2266 if (other
.last_deep_scrub
> last_deep_scrub
) {
2267 last_deep_scrub
= other
.last_deep_scrub
;
2270 if (other
.last_deep_scrub_stamp
> last_deep_scrub_stamp
) {
2271 last_deep_scrub_stamp
= other
.last_deep_scrub_stamp
;
2274 if (other
.last_clean_scrub_stamp
> last_clean_scrub_stamp
) {
2275 last_clean_scrub_stamp
= other
.last_clean_scrub_stamp
;
2281 void encode(bufferlist
& bl
) const;
2282 void decode(bufferlist::iterator
& p
);
2283 void dump(Formatter
*f
) const;
2284 static void generate_test_instances(list
<pg_history_t
*>& o
);
2286 WRITE_CLASS_ENCODER(pg_history_t
)
2288 inline ostream
& operator<<(ostream
& out
, const pg_history_t
& h
) {
2289 return out
<< "ec=" << h
.epoch_created
<< "/" << h
.epoch_pool_created
2290 << " lis/c " << h
.last_interval_started
2291 << "/" << h
.last_interval_clean
2292 << " les/c/f " << h
.last_epoch_started
<< "/" << h
.last_epoch_clean
2293 << "/" << h
.last_epoch_marked_full
2294 << " " << h
.same_up_since
2295 << "/" << h
.same_interval_since
2296 << "/" << h
.same_primary_since
;
2301 * pg_info_t - summary of PG statistics.
2304 * - last_complete implies we have all objects that existed as of that
2305 * stamp, OR a newer object, OR have already applied a later delete.
2306 * - if last_complete >= log.bottom, then we know pg contents thru log.head.
2307 * otherwise, we have no idea what the pg is supposed to contain.
2311 eversion_t last_update
; ///< last object version applied to store.
2312 eversion_t last_complete
; ///< last version pg was complete through.
2313 epoch_t last_epoch_started
; ///< last epoch at which this pg started on this osd
2314 epoch_t last_interval_started
; ///< first epoch of last_epoch_started interval
2316 version_t last_user_version
; ///< last user object version applied to store
2318 eversion_t log_tail
; ///< oldest log entry.
2320 hobject_t last_backfill
; ///< objects >= this and < last_complete may be missing
2321 bool last_backfill_bitwise
; ///< true if last_backfill reflects a bitwise (vs nibblewise) sort
2323 interval_set
<snapid_t
> purged_snaps
;
2327 pg_history_t history
;
2328 pg_hit_set_history_t hit_set
;
2330 friend bool operator==(const pg_info_t
& l
, const pg_info_t
& r
) {
2333 l
.last_update
== r
.last_update
&&
2334 l
.last_complete
== r
.last_complete
&&
2335 l
.last_epoch_started
== r
.last_epoch_started
&&
2336 l
.last_interval_started
== r
.last_interval_started
&&
2337 l
.last_user_version
== r
.last_user_version
&&
2338 l
.log_tail
== r
.log_tail
&&
2339 l
.last_backfill
== r
.last_backfill
&&
2340 l
.last_backfill_bitwise
== r
.last_backfill_bitwise
&&
2341 l
.purged_snaps
== r
.purged_snaps
&&
2342 l
.stats
== r
.stats
&&
2343 l
.history
== r
.history
&&
2344 l
.hit_set
== r
.hit_set
;
2348 : last_epoch_started(0),
2349 last_interval_started(0),
2350 last_user_version(0),
2351 last_backfill(hobject_t::get_max()),
2352 last_backfill_bitwise(false)
2354 // cppcheck-suppress noExplicitConstructor
2357 last_epoch_started(0),
2358 last_interval_started(0),
2359 last_user_version(0),
2360 last_backfill(hobject_t::get_max()),
2361 last_backfill_bitwise(false)
2364 void set_last_backfill(hobject_t pos
) {
2365 last_backfill
= pos
;
2366 last_backfill_bitwise
= true;
2369 bool is_empty() const { return last_update
.version
== 0; }
2370 bool dne() const { return history
.epoch_created
== 0; }
2372 bool is_incomplete() const { return !last_backfill
.is_max(); }
2374 void encode(bufferlist
& bl
) const;
2375 void decode(bufferlist::iterator
& p
);
2376 void dump(Formatter
*f
) const;
2377 bool overlaps_with(const pg_info_t
&oinfo
) const {
2378 return last_update
> oinfo
.log_tail
?
2379 oinfo
.last_update
>= log_tail
:
2380 last_update
>= oinfo
.log_tail
;
2382 static void generate_test_instances(list
<pg_info_t
*>& o
);
2384 WRITE_CLASS_ENCODER(pg_info_t
)
2386 inline ostream
& operator<<(ostream
& out
, const pg_info_t
& pgi
)
2388 out
<< pgi
.pgid
<< "(";
2394 out
<< " v " << pgi
.last_update
;
2395 if (pgi
.last_complete
!= pgi
.last_update
)
2396 out
<< " lc " << pgi
.last_complete
;
2397 out
<< " (" << pgi
.log_tail
<< "," << pgi
.last_update
<< "]";
2399 if (pgi
.is_incomplete())
2400 out
<< " lb " << pgi
.last_backfill
2401 << (pgi
.last_backfill_bitwise
? " (bitwise)" : " (NIBBLEWISE)");
2402 //out << " c " << pgi.epoch_created;
2403 out
<< " local-lis/les=" << pgi
.last_interval_started
2404 << "/" << pgi
.last_epoch_started
;
2405 out
<< " n=" << pgi
.stats
.stats
.sum
.num_objects
;
2406 out
<< " " << pgi
.history
2412 * pg_fast_info_t - common pg_info_t fields
2414 * These are the fields of pg_info_t (and children) that are updated for
2415 * most IO operations.
2418 * Because we rely on these fields to be applied to the normal
2419 * info struct, adding a new field here that is not also new in info
2420 * means that we must set an incompat OSD feature bit!
2422 struct pg_fast_info_t
{
2423 eversion_t last_update
;
2424 eversion_t last_complete
;
2425 version_t last_user_version
;
2426 struct { // pg_stat_t stats
2428 version_t reported_seq
;
2430 utime_t last_active
;
2431 utime_t last_peered
;
2433 utime_t last_unstale
;
2434 utime_t last_undegraded
;
2435 utime_t last_fullsized
;
2436 int64_t log_size
; // (also ondisk_log_size, which has the same value)
2437 struct { // object_stat_collection_t stats;
2438 struct { // objct_stat_sum_t sum
2439 int64_t num_bytes
; // in bytes
2440 int64_t num_objects
;
2441 int64_t num_object_copies
;
2446 int64_t num_objects_dirty
;
2451 void populate_from(const pg_info_t
& info
) {
2452 last_update
= info
.last_update
;
2453 last_complete
= info
.last_complete
;
2454 last_user_version
= info
.last_user_version
;
2455 stats
.version
= info
.stats
.version
;
2456 stats
.reported_seq
= info
.stats
.reported_seq
;
2457 stats
.last_fresh
= info
.stats
.last_fresh
;
2458 stats
.last_active
= info
.stats
.last_active
;
2459 stats
.last_peered
= info
.stats
.last_peered
;
2460 stats
.last_clean
= info
.stats
.last_clean
;
2461 stats
.last_unstale
= info
.stats
.last_unstale
;
2462 stats
.last_undegraded
= info
.stats
.last_undegraded
;
2463 stats
.last_fullsized
= info
.stats
.last_fullsized
;
2464 stats
.log_size
= info
.stats
.log_size
;
2465 stats
.stats
.sum
.num_bytes
= info
.stats
.stats
.sum
.num_bytes
;
2466 stats
.stats
.sum
.num_objects
= info
.stats
.stats
.sum
.num_objects
;
2467 stats
.stats
.sum
.num_object_copies
= info
.stats
.stats
.sum
.num_object_copies
;
2468 stats
.stats
.sum
.num_rd
= info
.stats
.stats
.sum
.num_rd
;
2469 stats
.stats
.sum
.num_rd_kb
= info
.stats
.stats
.sum
.num_rd_kb
;
2470 stats
.stats
.sum
.num_wr
= info
.stats
.stats
.sum
.num_wr
;
2471 stats
.stats
.sum
.num_wr_kb
= info
.stats
.stats
.sum
.num_wr_kb
;
2472 stats
.stats
.sum
.num_objects_dirty
= info
.stats
.stats
.sum
.num_objects_dirty
;
2475 bool try_apply_to(pg_info_t
* info
) {
2476 if (last_update
<= info
->last_update
)
2478 info
->last_update
= last_update
;
2479 info
->last_complete
= last_complete
;
2480 info
->last_user_version
= last_user_version
;
2481 info
->stats
.version
= stats
.version
;
2482 info
->stats
.reported_seq
= stats
.reported_seq
;
2483 info
->stats
.last_fresh
= stats
.last_fresh
;
2484 info
->stats
.last_active
= stats
.last_active
;
2485 info
->stats
.last_peered
= stats
.last_peered
;
2486 info
->stats
.last_clean
= stats
.last_clean
;
2487 info
->stats
.last_unstale
= stats
.last_unstale
;
2488 info
->stats
.last_undegraded
= stats
.last_undegraded
;
2489 info
->stats
.last_fullsized
= stats
.last_fullsized
;
2490 info
->stats
.log_size
= stats
.log_size
;
2491 info
->stats
.ondisk_log_size
= stats
.log_size
;
2492 info
->stats
.stats
.sum
.num_bytes
= stats
.stats
.sum
.num_bytes
;
2493 info
->stats
.stats
.sum
.num_objects
= stats
.stats
.sum
.num_objects
;
2494 info
->stats
.stats
.sum
.num_object_copies
= stats
.stats
.sum
.num_object_copies
;
2495 info
->stats
.stats
.sum
.num_rd
= stats
.stats
.sum
.num_rd
;
2496 info
->stats
.stats
.sum
.num_rd_kb
= stats
.stats
.sum
.num_rd_kb
;
2497 info
->stats
.stats
.sum
.num_wr
= stats
.stats
.sum
.num_wr
;
2498 info
->stats
.stats
.sum
.num_wr_kb
= stats
.stats
.sum
.num_wr_kb
;
2499 info
->stats
.stats
.sum
.num_objects_dirty
= stats
.stats
.sum
.num_objects_dirty
;
2503 void encode(bufferlist
& bl
) const {
2504 ENCODE_START(1, 1, bl
);
2505 ::encode(last_update
, bl
);
2506 ::encode(last_complete
, bl
);
2507 ::encode(last_user_version
, bl
);
2508 ::encode(stats
.version
, bl
);
2509 ::encode(stats
.reported_seq
, bl
);
2510 ::encode(stats
.last_fresh
, bl
);
2511 ::encode(stats
.last_active
, bl
);
2512 ::encode(stats
.last_peered
, bl
);
2513 ::encode(stats
.last_clean
, bl
);
2514 ::encode(stats
.last_unstale
, bl
);
2515 ::encode(stats
.last_undegraded
, bl
);
2516 ::encode(stats
.last_fullsized
, bl
);
2517 ::encode(stats
.log_size
, bl
);
2518 ::encode(stats
.stats
.sum
.num_bytes
, bl
);
2519 ::encode(stats
.stats
.sum
.num_objects
, bl
);
2520 ::encode(stats
.stats
.sum
.num_object_copies
, bl
);
2521 ::encode(stats
.stats
.sum
.num_rd
, bl
);
2522 ::encode(stats
.stats
.sum
.num_rd_kb
, bl
);
2523 ::encode(stats
.stats
.sum
.num_wr
, bl
);
2524 ::encode(stats
.stats
.sum
.num_wr_kb
, bl
);
2525 ::encode(stats
.stats
.sum
.num_objects_dirty
, bl
);
2528 void decode(bufferlist::iterator
& p
) {
2530 ::decode(last_update
, p
);
2531 ::decode(last_complete
, p
);
2532 ::decode(last_user_version
, p
);
2533 ::decode(stats
.version
, p
);
2534 ::decode(stats
.reported_seq
, p
);
2535 ::decode(stats
.last_fresh
, p
);
2536 ::decode(stats
.last_active
, p
);
2537 ::decode(stats
.last_peered
, p
);
2538 ::decode(stats
.last_clean
, p
);
2539 ::decode(stats
.last_unstale
, p
);
2540 ::decode(stats
.last_undegraded
, p
);
2541 ::decode(stats
.last_fullsized
, p
);
2542 ::decode(stats
.log_size
, p
);
2543 ::decode(stats
.stats
.sum
.num_bytes
, p
);
2544 ::decode(stats
.stats
.sum
.num_objects
, p
);
2545 ::decode(stats
.stats
.sum
.num_object_copies
, p
);
2546 ::decode(stats
.stats
.sum
.num_rd
, p
);
2547 ::decode(stats
.stats
.sum
.num_rd_kb
, p
);
2548 ::decode(stats
.stats
.sum
.num_wr
, p
);
2549 ::decode(stats
.stats
.sum
.num_wr_kb
, p
);
2550 ::decode(stats
.stats
.sum
.num_objects_dirty
, p
);
2554 WRITE_CLASS_ENCODER(pg_fast_info_t
)
2557 struct pg_notify_t
{
2558 epoch_t query_epoch
;
2564 query_epoch(0), epoch_sent(0), to(shard_id_t::NO_SHARD
),
2565 from(shard_id_t::NO_SHARD
) {}
2569 epoch_t query_epoch
,
2571 const pg_info_t
&info
)
2572 : query_epoch(query_epoch
),
2573 epoch_sent(epoch_sent
),
2574 info(info
), to(to
), from(from
) {
2575 assert(from
== info
.pgid
.shard
);
2577 void encode(bufferlist
&bl
) const;
2578 void decode(bufferlist::iterator
&p
);
2579 void dump(Formatter
*f
) const;
2580 static void generate_test_instances(list
<pg_notify_t
*> &o
);
2582 WRITE_CLASS_ENCODER(pg_notify_t
)
2583 ostream
&operator<<(ostream
&lhs
, const pg_notify_t
¬ify
);
2588 * PastIntervals -- information needed to determine the PriorSet and
2589 * the might_have_unfound set
2591 class PastIntervals
{
2593 struct pg_interval_t
{
2594 vector
<int32_t> up
, acting
;
2595 epoch_t first
, last
;
2601 : first(0), last(0),
2602 maybe_went_rw(false),
2608 vector
<int32_t> &&up
,
2609 vector
<int32_t> &&acting
,
2615 : up(up
), acting(acting
), first(first
), last(last
),
2616 maybe_went_rw(maybe_went_rw
), primary(primary
), up_primary(up_primary
)
2619 void encode(bufferlist
& bl
) const;
2620 void decode(bufferlist::iterator
& bl
);
2621 void dump(Formatter
*f
) const;
2622 static void generate_test_instances(list
<pg_interval_t
*>& o
);
2625 PastIntervals() = default;
2626 PastIntervals(bool ec_pool
, const OSDMap
&osdmap
) : PastIntervals() {
2627 update_type_from_map(ec_pool
, osdmap
);
2629 PastIntervals(bool ec_pool
, bool compact
) : PastIntervals() {
2630 update_type(ec_pool
, compact
);
2632 PastIntervals(PastIntervals
&&rhs
) = default;
2633 PastIntervals
&operator=(PastIntervals
&&rhs
) = default;
2635 PastIntervals(const PastIntervals
&rhs
);
2636 PastIntervals
&operator=(const PastIntervals
&rhs
);
2638 class interval_rep
{
2640 virtual size_t size() const = 0;
2641 virtual bool empty() const = 0;
2642 virtual void clear() = 0;
2643 virtual pair
<epoch_t
, epoch_t
> get_bounds() const = 0;
2644 virtual set
<pg_shard_t
> get_all_participants(
2645 bool ec_pool
) const = 0;
2646 virtual void add_interval(bool ec_pool
, const pg_interval_t
&interval
) = 0;
2647 virtual unique_ptr
<interval_rep
> clone() const = 0;
2648 virtual ostream
&print(ostream
&out
) const = 0;
2649 virtual void encode(bufferlist
&bl
) const = 0;
2650 virtual void decode(bufferlist::iterator
&bl
) = 0;
2651 virtual void dump(Formatter
*f
) const = 0;
2652 virtual bool is_classic() const = 0;
2653 virtual void iterate_mayberw_back_to(
2656 std::function
<void(epoch_t
, const set
<pg_shard_t
> &)> &&f
) const = 0;
2658 virtual bool has_full_intervals() const { return false; }
2659 virtual void iterate_all_intervals(
2660 std::function
<void(const pg_interval_t
&)> &&f
) const {
2661 assert(!has_full_intervals());
2662 assert(0 == "not valid for this implementation");
2665 virtual ~interval_rep() {}
2667 friend class pi_simple_rep
;
2668 friend class pi_compact_rep
;
2671 unique_ptr
<interval_rep
> past_intervals
;
2673 PastIntervals(interval_rep
*rep
) : past_intervals(rep
) {}
2676 void add_interval(bool ec_pool
, const pg_interval_t
&interval
) {
2677 assert(past_intervals
);
2678 return past_intervals
->add_interval(ec_pool
, interval
);
2681 bool is_classic() const {
2682 assert(past_intervals
);
2683 return past_intervals
->is_classic();
2686 void encode(bufferlist
&bl
) const {
2687 ENCODE_START(1, 1, bl
);
2688 if (past_intervals
) {
2689 __u8 type
= is_classic() ? 1 : 2;
2691 past_intervals
->encode(bl
);
2693 ::encode((__u8
)0, bl
);
2697 void encode_classic(bufferlist
&bl
) const {
2698 if (past_intervals
) {
2699 assert(past_intervals
->is_classic());
2700 past_intervals
->encode(bl
);
2703 ::encode((uint32_t)0, bl
);
2707 void decode(bufferlist::iterator
&bl
);
2708 void decode_classic(bufferlist::iterator
&bl
);
2710 void dump(Formatter
*f
) const {
2711 assert(past_intervals
);
2712 past_intervals
->dump(f
);
2714 static void generate_test_instances(list
<PastIntervals
*> & o
);
2717 * Determines whether there is an interval change
2719 static bool is_new_interval(
2720 int old_acting_primary
,
2721 int new_acting_primary
,
2722 const vector
<int> &old_acting
,
2723 const vector
<int> &new_acting
,
2726 const vector
<int> &old_up
,
2727 const vector
<int> &new_up
,
2732 unsigned old_pg_num
,
2733 unsigned new_pg_num
,
2734 bool old_sort_bitwise
,
2735 bool new_sort_bitwise
,
2736 bool old_recovery_deletes
,
2737 bool new_recovery_deletes
,
2742 * Determines whether there is an interval change
2744 static bool is_new_interval(
2745 int old_acting_primary
, ///< [in] primary as of lastmap
2746 int new_acting_primary
, ///< [in] primary as of lastmap
2747 const vector
<int> &old_acting
, ///< [in] acting as of lastmap
2748 const vector
<int> &new_acting
, ///< [in] acting as of osdmap
2749 int old_up_primary
, ///< [in] up primary of lastmap
2750 int new_up_primary
, ///< [in] up primary of osdmap
2751 const vector
<int> &old_up
, ///< [in] up as of lastmap
2752 const vector
<int> &new_up
, ///< [in] up as of osdmap
2753 ceph::shared_ptr
<const OSDMap
> osdmap
, ///< [in] current map
2754 ceph::shared_ptr
<const OSDMap
> lastmap
, ///< [in] last map
2755 pg_t pgid
///< [in] pgid for pg
2759 * Integrates a new map into *past_intervals, returns true
2760 * if an interval was closed out.
2762 static bool check_new_interval(
2763 int old_acting_primary
, ///< [in] primary as of lastmap
2764 int new_acting_primary
, ///< [in] primary as of osdmap
2765 const vector
<int> &old_acting
, ///< [in] acting as of lastmap
2766 const vector
<int> &new_acting
, ///< [in] acting as of osdmap
2767 int old_up_primary
, ///< [in] up primary of lastmap
2768 int new_up_primary
, ///< [in] up primary of osdmap
2769 const vector
<int> &old_up
, ///< [in] up as of lastmap
2770 const vector
<int> &new_up
, ///< [in] up as of osdmap
2771 epoch_t same_interval_since
, ///< [in] as of osdmap
2772 epoch_t last_epoch_clean
, ///< [in] current
2773 ceph::shared_ptr
<const OSDMap
> osdmap
, ///< [in] current map
2774 ceph::shared_ptr
<const OSDMap
> lastmap
, ///< [in] last map
2775 pg_t pgid
, ///< [in] pgid for pg
2776 IsPGRecoverablePredicate
*could_have_gone_active
, /// [in] predicate whether the pg can be active
2777 PastIntervals
*past_intervals
, ///< [out] intervals
2778 ostream
*out
= 0 ///< [out] debug ostream
2781 friend ostream
& operator<<(ostream
& out
, const PastIntervals
&i
);
2783 template <typename F
>
2784 void iterate_mayberw_back_to(
2788 assert(past_intervals
);
2789 past_intervals
->iterate_mayberw_back_to(ec_pool
, les
, std::forward
<F
>(f
));
2792 assert(past_intervals
);
2793 past_intervals
->clear();
2797 * Should return a value which gives an indication of the amount
2798 * of state contained
2800 size_t size() const {
2801 assert(past_intervals
);
2802 return past_intervals
->size();
2805 bool empty() const {
2806 assert(past_intervals
);
2807 return past_intervals
->empty();
2810 void swap(PastIntervals
&other
) {
2812 swap(other
.past_intervals
, past_intervals
);
2816 * Return all shards which have been in the acting set back to the
2817 * latest epoch to which we have trimmed except for pg_whoami
2819 set
<pg_shard_t
> get_might_have_unfound(
2820 pg_shard_t pg_whoami
,
2821 bool ec_pool
) const {
2822 assert(past_intervals
);
2823 auto ret
= past_intervals
->get_all_participants(ec_pool
);
2824 ret
.erase(pg_whoami
);
2829 * Return all shards which we might want to talk to for peering
2831 set
<pg_shard_t
> get_all_probe(
2832 bool ec_pool
) const {
2833 assert(past_intervals
);
2834 return past_intervals
->get_all_participants(ec_pool
);
2837 /* Return the set of epochs [start, end) represented by the
2838 * past_interval set.
2840 pair
<epoch_t
, epoch_t
> get_bounds() const {
2841 assert(past_intervals
);
2842 return past_intervals
->get_bounds();
2852 bool ec_pool
= false;
2853 set
<pg_shard_t
> probe
; /// current+prior OSDs we need to probe.
2854 set
<int> down
; /// down osds that would normally be in @a probe and might be interesting.
2855 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
2857 bool pg_down
= false; /// some down osds are included in @a cur; the DOWN pg state bit should be set.
2858 unique_ptr
<IsPGRecoverablePredicate
> pcontdec
;
2860 PriorSet() = default;
2861 PriorSet(PriorSet
&&) = default;
2862 PriorSet
&operator=(PriorSet
&&) = default;
2864 PriorSet
&operator=(const PriorSet
&) = delete;
2865 PriorSet(const PriorSet
&) = delete;
2867 bool operator==(const PriorSet
&rhs
) const {
2868 return (ec_pool
== rhs
.ec_pool
) &&
2869 (probe
== rhs
.probe
) &&
2870 (down
== rhs
.down
) &&
2871 (blocked_by
== rhs
.blocked_by
) &&
2872 (pg_down
== rhs
.pg_down
);
2875 bool affected_by_map(
2876 const OSDMap
&osdmap
,
2877 const DoutPrefixProvider
*dpp
) const;
2879 // For verifying tests
2882 set
<pg_shard_t
> probe
,
2884 map
<int, epoch_t
> blocked_by
,
2886 IsPGRecoverablePredicate
*pcontdec
)
2887 : ec_pool(ec_pool
), probe(probe
), down(down
), blocked_by(blocked_by
),
2888 pg_down(pg_down
), pcontdec(pcontdec
) {}
2891 template <typename F
>
2893 const PastIntervals
&past_intervals
,
2895 epoch_t last_epoch_started
,
2896 IsPGRecoverablePredicate
*c
,
2898 const vector
<int> &up
,
2899 const vector
<int> &acting
,
2900 const DoutPrefixProvider
*dpp
);
2902 friend class PastIntervals
;
2905 void update_type(bool ec_pool
, bool compact
);
2906 void update_type_from_map(bool ec_pool
, const OSDMap
&osdmap
);
2908 template <typename
... Args
>
2909 PriorSet
get_prior_set(Args
&&... args
) const {
2910 return PriorSet(*this, std::forward
<Args
>(args
)...);
2913 WRITE_CLASS_ENCODER(PastIntervals
)
2915 ostream
& operator<<(ostream
& out
, const PastIntervals::pg_interval_t
& i
);
2916 ostream
& operator<<(ostream
& out
, const PastIntervals
&i
);
2917 ostream
& operator<<(ostream
& out
, const PastIntervals::PriorSet
&i
);
2919 template <typename F
>
2920 PastIntervals::PriorSet::PriorSet(
2921 const PastIntervals
&past_intervals
,
2923 epoch_t last_epoch_started
,
2924 IsPGRecoverablePredicate
*c
,
2926 const vector
<int> &up
,
2927 const vector
<int> &acting
,
2928 const DoutPrefixProvider
*dpp
)
2929 : ec_pool(ec_pool
), pg_down(false), pcontdec(c
)
2932 * We have to be careful to gracefully deal with situations like
2933 * so. Say we have a power outage or something that takes out both
2934 * OSDs, but the monitor doesn't mark them down in the same epoch.
2935 * The history may look like
2939 * 3: let's say B dies for good, too (say, from the power spike)
2942 * which makes it look like B may have applied updates to the PG
2943 * that we need in order to proceed. This sucks...
2945 * To minimize the risk of this happening, we CANNOT go active if
2946 * _any_ OSDs in the prior set are down until we send an MOSDAlive
2947 * to the monitor such that the OSDMap sets osd_up_thru to an epoch.
2948 * Then, we have something like
2955 * -> we can ignore B, bc it couldn't have gone active (alive_thru
2966 * -> we must wait for B, bc it was alive through 2, and could have
2967 * written to the pg.
2969 * If B is really dead, then an administrator will need to manually
2970 * intervene by marking the OSD as "lost."
2973 // Include current acting and up nodes... not because they may
2974 // contain old data (this interval hasn't gone active, obviously),
2975 // but because we want their pg_info to inform choose_acting(), and
2976 // so that we know what they do/do not have explicitly before
2977 // sending them any new info/logs/whatever.
2978 for (unsigned i
= 0; i
< acting
.size(); i
++) {
2979 if (acting
[i
] != 0x7fffffff /* CRUSH_ITEM_NONE, can't import crush.h here */)
2980 probe
.insert(pg_shard_t(acting
[i
], ec_pool
? shard_id_t(i
) : shard_id_t::NO_SHARD
));
2982 // It may be possible to exclude the up nodes, but let's keep them in
2984 for (unsigned i
= 0; i
< up
.size(); i
++) {
2985 if (up
[i
] != 0x7fffffff /* CRUSH_ITEM_NONE, can't import crush.h here */)
2986 probe
.insert(pg_shard_t(up
[i
], ec_pool
? shard_id_t(i
) : shard_id_t::NO_SHARD
));
2989 set
<pg_shard_t
> all_probe
= past_intervals
.get_all_probe(ec_pool
);
2990 ldpp_dout(dpp
, 10) << "build_prior all_probe " << all_probe
<< dendl
;
2991 for (auto &&i
: all_probe
) {
2992 switch (f(0, i
.osd
, nullptr)) {
3006 past_intervals
.iterate_mayberw_back_to(
3009 [&](epoch_t start
, const set
<pg_shard_t
> &acting
) {
3010 ldpp_dout(dpp
, 10) << "build_prior maybe_rw interval:" << start
3011 << ", acting: " << acting
<< dendl
;
3013 // look at candidate osds during this interval. each falls into
3014 // one of three categories: up, down (but potentially
3015 // interesting), or lost (down, but we won't wait for it).
3016 set
<pg_shard_t
> up_now
;
3017 map
<int, epoch_t
> candidate_blocked_by
;
3018 // any candidates down now (that might have useful data)
3019 bool any_down_now
= false;
3021 // consider ACTING osds
3022 for (auto &&so
: acting
) {
3023 epoch_t lost_at
= 0;
3024 switch (f(start
, so
.osd
, &lost_at
)) {
3026 // include past acting osds if they are up.
3031 ldpp_dout(dpp
, 10) << "build_prior prior osd." << so
.osd
3032 << " no longer exists" << dendl
;
3036 ldpp_dout(dpp
, 10) << "build_prior prior osd." << so
.osd
3037 << " is down, but lost_at " << lost_at
<< dendl
;
3042 ldpp_dout(dpp
, 10) << "build_prior prior osd." << so
.osd
3043 << " is down" << dendl
;
3044 candidate_blocked_by
[so
.osd
] = lost_at
;
3045 any_down_now
= true;
3051 // if not enough osds survived this interval, and we may have gone rw,
3052 // then we need to wait for one of those osds to recover to
3053 // ensure that we haven't lost any information.
3054 if (!(*pcontdec
)(up_now
) && any_down_now
) {
3055 // fixme: how do we identify a "clean" shutdown anyway?
3056 ldpp_dout(dpp
, 10) << "build_prior possibly went active+rw,"
3057 << " insufficient up; including down osds" << dendl
;
3058 assert(!candidate_blocked_by
.empty());
3061 candidate_blocked_by
.begin(),
3062 candidate_blocked_by
.end());
3066 ldpp_dout(dpp
, 10) << "build_prior final: probe " << probe
3068 << " blocked_by " << blocked_by
3069 << (pg_down
? " pg_down":"")
3074 * pg_query_t - used to ask a peer for information about a pg.
3076 * note: if version=0, type=LOG, then we just provide our full log.
3085 const char *get_type_name() const {
3087 case INFO
: return "info";
3088 case LOG
: return "log";
3089 case MISSING
: return "missing";
3090 case FULLLOG
: return "fulllog";
3091 default: return "???";
3097 pg_history_t history
;
3102 pg_query_t() : type(-1), epoch_sent(0), to(shard_id_t::NO_SHARD
),
3103 from(shard_id_t::NO_SHARD
) {}
3108 const pg_history_t
& h
,
3112 epoch_sent(epoch_sent
),
3113 to(to
), from(from
) {
3121 const pg_history_t
& h
,
3123 : type(t
), since(s
), history(h
),
3124 epoch_sent(epoch_sent
), to(to
), from(from
) {
3128 void encode(bufferlist
&bl
, uint64_t features
) const;
3129 void decode(bufferlist::iterator
&bl
);
3131 void dump(Formatter
*f
) const;
3132 static void generate_test_instances(list
<pg_query_t
*>& o
);
3134 WRITE_CLASS_ENCODER_FEATURES(pg_query_t
)
3136 inline ostream
& operator<<(ostream
& out
, const pg_query_t
& q
) {
3137 out
<< "query(" << q
.get_type_name() << " " << q
.since
;
3138 if (q
.type
== pg_query_t::LOG
)
3139 out
<< " " << q
.history
;
3145 class ObjectModDesc
{
3146 bool can_local_rollback
;
3147 bool rollback_info_completed
;
3149 // version required to decode, reflected in encode/decode version
3150 __u8 max_required_version
= 1;
3154 virtual void append(uint64_t old_offset
) {}
3155 virtual void setattrs(map
<string
, boost::optional
<bufferlist
> > &attrs
) {}
3156 virtual void rmobject(version_t old_version
) {}
3158 * Used to support the unfound_lost_delete log event: if the stashed
3159 * version exists, we unstash it, otherwise, we do nothing. This way
3160 * each replica rolls back to whatever state it had prior to the attempt
3161 * at mark unfound lost delete
3163 virtual void try_rmobject(version_t old_version
) {
3164 rmobject(old_version
);
3166 virtual void create() {}
3167 virtual void update_snaps(const set
<snapid_t
> &old_snaps
) {}
3168 virtual void rollback_extents(
3170 const vector
<pair
<uint64_t, uint64_t> > &extents
) {}
3171 virtual ~Visitor() {}
3173 void visit(Visitor
*visitor
) const;
3174 mutable bufferlist bl
;
3182 ROLLBACK_EXTENTS
= 7
3184 ObjectModDesc() : can_local_rollback(true), rollback_info_completed(false) {
3185 bl
.reassign_to_mempool(mempool::mempool_osd_pglog
);
3187 void claim(ObjectModDesc
&other
) {
3190 can_local_rollback
= other
.can_local_rollback
;
3191 rollback_info_completed
= other
.rollback_info_completed
;
3193 void claim_append(ObjectModDesc
&other
) {
3194 if (!can_local_rollback
|| rollback_info_completed
)
3196 if (!other
.can_local_rollback
) {
3197 mark_unrollbackable();
3200 bl
.claim_append(other
.bl
);
3201 rollback_info_completed
= other
.rollback_info_completed
;
3203 void swap(ObjectModDesc
&other
) {
3207 swap(other
.can_local_rollback
, can_local_rollback
);
3208 swap(other
.rollback_info_completed
, rollback_info_completed
);
3209 swap(other
.max_required_version
, max_required_version
);
3211 void append_id(ModID id
) {
3215 void append(uint64_t old_size
) {
3216 if (!can_local_rollback
|| rollback_info_completed
)
3218 ENCODE_START(1, 1, bl
);
3220 ::encode(old_size
, bl
);
3223 void setattrs(map
<string
, boost::optional
<bufferlist
> > &old_attrs
) {
3224 if (!can_local_rollback
|| rollback_info_completed
)
3226 ENCODE_START(1, 1, bl
);
3227 append_id(SETATTRS
);
3228 ::encode(old_attrs
, bl
);
3231 bool rmobject(version_t deletion_version
) {
3232 if (!can_local_rollback
|| rollback_info_completed
)
3234 ENCODE_START(1, 1, bl
);
3236 ::encode(deletion_version
, bl
);
3238 rollback_info_completed
= true;
3241 bool try_rmobject(version_t deletion_version
) {
3242 if (!can_local_rollback
|| rollback_info_completed
)
3244 ENCODE_START(1, 1, bl
);
3245 append_id(TRY_DELETE
);
3246 ::encode(deletion_version
, bl
);
3248 rollback_info_completed
= true;
3252 if (!can_local_rollback
|| rollback_info_completed
)
3254 rollback_info_completed
= true;
3255 ENCODE_START(1, 1, bl
);
3259 void update_snaps(const set
<snapid_t
> &old_snaps
) {
3260 if (!can_local_rollback
|| rollback_info_completed
)
3262 ENCODE_START(1, 1, bl
);
3263 append_id(UPDATE_SNAPS
);
3264 ::encode(old_snaps
, bl
);
3267 void rollback_extents(
3268 version_t gen
, const vector
<pair
<uint64_t, uint64_t> > &extents
) {
3269 assert(can_local_rollback
);
3270 assert(!rollback_info_completed
);
3271 if (max_required_version
< 2)
3272 max_required_version
= 2;
3273 ENCODE_START(2, 2, bl
);
3274 append_id(ROLLBACK_EXTENTS
);
3276 ::encode(extents
, bl
);
3280 // cannot be rolled back
3281 void mark_unrollbackable() {
3282 can_local_rollback
= false;
3285 bool can_rollback() const {
3286 return can_local_rollback
;
3288 bool empty() const {
3289 return can_local_rollback
&& (bl
.length() == 0);
3292 bool requires_kraken() const {
3293 return max_required_version
>= 2;
3297 * Create fresh copy of bl bytes to avoid keeping large buffers around
3298 * in the case that bl contains ptrs which point into a much larger
3301 void trim_bl() const {
3302 if (bl
.length() > 0)
3305 void encode(bufferlist
&bl
) const;
3306 void decode(bufferlist::iterator
&bl
);
3307 void dump(Formatter
*f
) const;
3308 static void generate_test_instances(list
<ObjectModDesc
*>& o
);
3310 WRITE_CLASS_ENCODER(ObjectModDesc
)
3314 * pg_log_entry_t - single entry/event in pg log
3317 struct pg_log_entry_t
{
3319 MODIFY
= 1, // some unspecified modification (but not *all* modifications)
3320 CLONE
= 2, // cloned object from head
3321 DELETE
= 3, // deleted object
3322 BACKLOG
= 4, // event invented by generate_backlog [deprecated]
3323 LOST_REVERT
= 5, // lost new version, revert to an older version.
3324 LOST_DELETE
= 6, // lost new version, revert to no object (deleted).
3325 LOST_MARK
= 7, // lost new version, now EIO
3326 PROMOTE
= 8, // promoted object from another tier
3327 CLEAN
= 9, // mark an object clean
3328 ERROR
= 10, // write that returned an error
3330 static const char *get_op_name(int op
) {
3356 const char *get_op_name() const {
3357 return get_op_name(op
);
3360 // describes state for a locally-rollbackable entry
3361 ObjectModDesc mod_desc
;
3362 bufferlist snaps
; // only for clone entries
3364 osd_reqid_t reqid
; // caller+tid to uniquely identify request
3365 mempool::osd_pglog::vector
<pair
<osd_reqid_t
, version_t
> > extra_reqids
;
3366 eversion_t version
, prior_version
, reverting_to
;
3367 version_t user_version
; // the user version for this entry
3368 utime_t mtime
; // this is the _user_ mtime, mind you
3369 int32_t return_code
; // only stored for ERRORs for dup detection
3372 bool invalid_hash
; // only when decoding sobject_t based entries
3373 bool invalid_pool
; // only when decoding pool-less hobject based entries
3376 : user_version(0), return_code(0), op(0),
3377 invalid_hash(false), invalid_pool(false) {
3378 snaps
.reassign_to_mempool(mempool::mempool_osd_pglog
);
3380 pg_log_entry_t(int _op
, const hobject_t
& _soid
,
3381 const eversion_t
& v
, const eversion_t
& pv
,
3383 const osd_reqid_t
& rid
, const utime_t
& mt
,
3385 : soid(_soid
), reqid(rid
), version(v
), prior_version(pv
), user_version(uv
),
3386 mtime(mt
), return_code(return_code
), op(_op
),
3387 invalid_hash(false), invalid_pool(false) {
3388 snaps
.reassign_to_mempool(mempool::mempool_osd_pglog
);
3391 bool is_clone() const { return op
== CLONE
; }
3392 bool is_modify() const { return op
== MODIFY
; }
3393 bool is_promote() const { return op
== PROMOTE
; }
3394 bool is_clean() const { return op
== CLEAN
; }
3395 bool is_backlog() const { return op
== BACKLOG
; }
3396 bool is_lost_revert() const { return op
== LOST_REVERT
; }
3397 bool is_lost_delete() const { return op
== LOST_DELETE
; }
3398 bool is_lost_mark() const { return op
== LOST_MARK
; }
3399 bool is_error() const { return op
== ERROR
; }
3401 bool is_update() const {
3403 is_clone() || is_modify() || is_promote() || is_clean() ||
3404 is_backlog() || is_lost_revert() || is_lost_mark();
3406 bool is_delete() const {
3407 return op
== DELETE
|| op
== LOST_DELETE
;
3410 bool can_rollback() const {
3411 return mod_desc
.can_rollback();
3414 void mark_unrollbackable() {
3415 mod_desc
.mark_unrollbackable();
3418 bool requires_kraken() const {
3419 return mod_desc
.requires_kraken();
3422 // Errors are only used for dup detection, whereas
3423 // the index by objects is used by recovery, copy_get,
3424 // and other facilities that don't expect or need to
3425 // be aware of error entries.
3426 bool object_is_indexed() const {
3430 bool reqid_is_indexed() const {
3431 return reqid
!= osd_reqid_t() &&
3432 (op
== MODIFY
|| op
== DELETE
|| op
== ERROR
);
3435 string
get_key_name() const;
3436 void encode_with_checksum(bufferlist
& bl
) const;
3437 void decode_with_checksum(bufferlist::iterator
& p
);
3439 void encode(bufferlist
&bl
) const;
3440 void decode(bufferlist::iterator
&bl
);
3441 void dump(Formatter
*f
) const;
3442 static void generate_test_instances(list
<pg_log_entry_t
*>& o
);
3445 WRITE_CLASS_ENCODER(pg_log_entry_t
)
3447 ostream
& operator<<(ostream
& out
, const pg_log_entry_t
& e
);
3449 struct pg_log_dup_t
{
3450 osd_reqid_t reqid
; // caller+tid to uniquely identify request
3452 version_t user_version
; // the user version for this entry
3453 int32_t return_code
; // only stored for ERRORs for dup detection
3456 : user_version(0), return_code(0)
3458 explicit pg_log_dup_t(const pg_log_entry_t
& entry
)
3459 : reqid(entry
.reqid
), version(entry
.version
),
3460 user_version(entry
.user_version
), return_code(entry
.return_code
)
3462 pg_log_dup_t(const eversion_t
& v
, version_t uv
,
3463 const osd_reqid_t
& rid
, int return_code
)
3464 : reqid(rid
), version(v
), user_version(uv
),
3465 return_code(return_code
)
3468 string
get_key_name() const;
3469 void encode(bufferlist
&bl
) const;
3470 void decode(bufferlist::iterator
&bl
);
3471 void dump(Formatter
*f
) const;
3472 static void generate_test_instances(list
<pg_log_dup_t
*>& o
);
3474 bool operator==(const pg_log_dup_t
&rhs
) const {
3475 return reqid
== rhs
.reqid
&&
3476 version
== rhs
.version
&&
3477 user_version
== rhs
.user_version
&&
3478 return_code
== rhs
.return_code
;
3480 bool operator!=(const pg_log_dup_t
&rhs
) const {
3481 return !(*this == rhs
);
3484 friend std::ostream
& operator<<(std::ostream
& out
, const pg_log_dup_t
& e
);
3486 WRITE_CLASS_ENCODER(pg_log_dup_t
)
3488 std::ostream
& operator<<(std::ostream
& out
, const pg_log_dup_t
& e
);
3491 * pg_log_t - incremental log of recent pg changes.
3493 * serves as a recovery queue for recent changes.
3497 * head - newest entry (update|delete)
3498 * tail - entry previous to oldest (update|delete) for which we have
3499 * complete negative information.
3500 * i.e. we can infer pg contents for any store whose last_update >= tail.
3502 eversion_t head
; // newest entry
3503 eversion_t tail
; // version prior to oldest
3506 // We can rollback rollback-able entries > can_rollback_to
3507 eversion_t can_rollback_to
;
3509 // always <= can_rollback_to, indicates how far stashed rollback
3510 // data can be found
3511 eversion_t rollback_info_trimmed_to
;
3515 mempool::osd_pglog::list
<pg_log_entry_t
> log
;
3517 // entries just for dup op detection ordered oldest to newest
3518 mempool::osd_pglog::list
<pg_log_dup_t
> dups
;
3520 pg_log_t() = default;
3521 pg_log_t(const eversion_t
&last_update
,
3522 const eversion_t
&log_tail
,
3523 const eversion_t
&can_rollback_to
,
3524 const eversion_t
&rollback_info_trimmed_to
,
3525 mempool::osd_pglog::list
<pg_log_entry_t
> &&entries
,
3526 mempool::osd_pglog::list
<pg_log_dup_t
> &&dup_entries
)
3527 : head(last_update
), tail(log_tail
), can_rollback_to(can_rollback_to
),
3528 rollback_info_trimmed_to(rollback_info_trimmed_to
),
3529 log(std::move(entries
)), dups(std::move(dup_entries
)) {}
3530 pg_log_t(const eversion_t
&last_update
,
3531 const eversion_t
&log_tail
,
3532 const eversion_t
&can_rollback_to
,
3533 const eversion_t
&rollback_info_trimmed_to
,
3534 const std::list
<pg_log_entry_t
> &entries
,
3535 const std::list
<pg_log_dup_t
> &dup_entries
)
3536 : head(last_update
), tail(log_tail
), can_rollback_to(can_rollback_to
),
3537 rollback_info_trimmed_to(rollback_info_trimmed_to
) {
3538 for (auto &&entry
: entries
) {
3539 log
.push_back(entry
);
3541 for (auto &&entry
: dup_entries
) {
3542 dups
.push_back(entry
);
3548 rollback_info_trimmed_to
= can_rollback_to
= head
= tail
= z
;
3553 eversion_t
get_rollback_info_trimmed_to() const {
3554 return rollback_info_trimmed_to
;
3556 eversion_t
get_can_rollback_to() const {
3557 return can_rollback_to
;
3561 pg_log_t
split_out_child(pg_t child_pgid
, unsigned split_bits
) {
3562 mempool::osd_pglog::list
<pg_log_entry_t
> oldlog
, childlog
;
3565 eversion_t old_tail
;
3566 unsigned mask
= ~((~0)<<split_bits
);
3567 for (auto i
= oldlog
.begin();
3570 if ((i
->soid
.get_hash() & mask
) == child_pgid
.m_seed
) {
3571 childlog
.push_back(*i
);
3578 // osd_reqid is unique, so it doesn't matter if there are extra
3579 // dup entries in each pg. To avoid storing oid with the dup
3580 // entries, just copy the whole list.
3581 auto childdups(dups
);
3587 rollback_info_trimmed_to
,
3588 std::move(childlog
),
3589 std::move(childdups
));
3592 mempool::osd_pglog::list
<pg_log_entry_t
> rewind_from_head(eversion_t newhead
) {
3593 assert(newhead
>= tail
);
3595 mempool::osd_pglog::list
<pg_log_entry_t
>::iterator p
= log
.end();
3596 mempool::osd_pglog::list
<pg_log_entry_t
> divergent
;
3598 if (p
== log
.begin()) {
3599 // yikes, the whole thing is divergent!
3601 swap(divergent
, log
);
3605 if (p
->version
.version
<= newhead
.version
) {
3607 * look at eversion.version here. we want to avoid a situation like:
3608 * our log: 100'10 (0'0) m 10000004d3a.00000000/head by client4225.1:18529
3609 * new log: 122'10 (0'0) m 10000004d3a.00000000/head by client4225.1:18529
3610 * lower_bound = 100'9
3611 * i.e, same request, different version. If the eversion.version is > the
3612 * lower_bound, we it is divergent.
3615 divergent
.splice(divergent
.begin(), log
, p
, log
.end());
3618 assert(p
->version
> newhead
);
3622 if (can_rollback_to
> newhead
)
3623 can_rollback_to
= newhead
;
3625 if (rollback_info_trimmed_to
> newhead
)
3626 rollback_info_trimmed_to
= newhead
;
3631 bool empty() const {
3636 return head
.version
== 0 && head
.epoch
== 0;
3639 size_t approx_size() const {
3640 return head
.version
- tail
.version
;
3643 static void filter_log(spg_t import_pgid
, const OSDMap
&curmap
,
3644 const string
&hit_set_namespace
, const pg_log_t
&in
,
3645 pg_log_t
&out
, pg_log_t
&reject
);
3648 * copy entries from the tail of another pg_log_t
3650 * @param other pg_log_t to copy from
3651 * @param from copy entries after this version
3653 void copy_after(const pg_log_t
&other
, eversion_t from
);
3656 * copy a range of entries from another pg_log_t
3658 * @param other pg_log_t to copy from
3659 * @param from copy entries after this version
3660 * @param to up to and including this version
3662 void copy_range(const pg_log_t
&other
, eversion_t from
, eversion_t to
);
3665 * copy up to N entries
3667 * @param other source log
3668 * @param max max number of entries to copy
3670 void copy_up_to(const pg_log_t
&other
, int max
);
3672 ostream
& print(ostream
& out
) const;
3674 void encode(bufferlist
&bl
) const;
3675 void decode(bufferlist::iterator
&bl
, int64_t pool
= -1);
3676 void dump(Formatter
*f
) const;
3677 static void generate_test_instances(list
<pg_log_t
*>& o
);
3679 WRITE_CLASS_ENCODER(pg_log_t
)
3681 inline ostream
& operator<<(ostream
& out
, const pg_log_t
& log
)
3683 out
<< "log((" << log
.tail
<< "," << log
.head
<< "], crt="
3684 << log
.get_can_rollback_to() << ")";
3690 * pg_missing_t - summary of missing objects.
3692 * kept in memory, as a supplement to pg_log_t
3693 * also used to pass missing info in messages.
3695 struct pg_missing_item
{
3696 eversion_t need
, have
;
3697 enum missing_flags_t
{
3701 pg_missing_item() : flags(FLAG_NONE
) {}
3702 explicit pg_missing_item(eversion_t n
) : need(n
), flags(FLAG_NONE
) {} // have no old version
3703 pg_missing_item(eversion_t n
, eversion_t h
, bool is_delete
=false) : need(n
), have(h
) {
3704 set_delete(is_delete
);
3707 void encode(bufferlist
& bl
, uint64_t features
) const {
3708 if (HAVE_FEATURE(features
, OSD_RECOVERY_DELETES
)) {
3709 // encoding a zeroed eversion_t to differentiate between this and
3710 // legacy unversioned encoding - a need value of 0'0 is not
3711 // possible. This can be replaced with the legacy encoding
3712 // macros post-luminous.
3717 ::encode(static_cast<uint8_t>(flags
), bl
);
3719 // legacy unversioned encoding
3724 void decode(bufferlist::iterator
& bl
) {
3727 if (e
!= eversion_t()) {
3728 // legacy encoding, this is the need value
3736 flags
= static_cast<missing_flags_t
>(f
);
3740 void set_delete(bool is_delete
) {
3741 flags
= is_delete
? FLAG_DELETE
: FLAG_NONE
;
3744 bool is_delete() const {
3745 return (flags
& FLAG_DELETE
) == FLAG_DELETE
;
3748 string
flag_str() const {
3749 if (flags
== FLAG_NONE
) {
3756 void dump(Formatter
*f
) const {
3757 f
->dump_stream("need") << need
;
3758 f
->dump_stream("have") << have
;
3759 f
->dump_stream("flags") << flag_str();
3761 static void generate_test_instances(list
<pg_missing_item
*>& o
) {
3762 o
.push_back(new pg_missing_item
);
3763 o
.push_back(new pg_missing_item
);
3764 o
.back()->need
= eversion_t(1, 2);
3765 o
.back()->have
= eversion_t(1, 1);
3766 o
.push_back(new pg_missing_item
);
3767 o
.back()->need
= eversion_t(3, 5);
3768 o
.back()->have
= eversion_t(3, 4);
3769 o
.back()->flags
= FLAG_DELETE
;
3771 bool operator==(const pg_missing_item
&rhs
) const {
3772 return need
== rhs
.need
&& have
== rhs
.have
&& flags
== rhs
.flags
;
3774 bool operator!=(const pg_missing_item
&rhs
) const {
3775 return !(*this == rhs
);
3778 WRITE_CLASS_ENCODER_FEATURES(pg_missing_item
)
3779 ostream
& operator<<(ostream
& out
, const pg_missing_item
&item
);
3781 class pg_missing_const_i
{
3783 virtual const map
<hobject_t
, pg_missing_item
> &
3784 get_items() const = 0;
3785 virtual const map
<version_t
, hobject_t
> &get_rmissing() const = 0;
3786 virtual bool get_may_include_deletes() const = 0;
3787 virtual unsigned int num_missing() const = 0;
3788 virtual bool have_missing() const = 0;
3789 virtual bool is_missing(const hobject_t
& oid
, pg_missing_item
*out
= nullptr) const = 0;
3790 virtual bool is_missing(const hobject_t
& oid
, eversion_t v
) const = 0;
3791 virtual eversion_t
have_old(const hobject_t
& oid
) const = 0;
3792 virtual ~pg_missing_const_i() {}
3796 template <bool Track
>
3797 class ChangeTracker
{
3799 void changed(const hobject_t
&obj
) {}
3800 template <typename F
>
3801 void get_changed(F
&&f
) const {}
3803 bool is_clean() const {
3808 class ChangeTracker
<true> {
3809 set
<hobject_t
> _changed
;
3811 void changed(const hobject_t
&obj
) {
3812 _changed
.insert(obj
);
3814 template <typename F
>
3815 void get_changed(F
&&f
) const {
3816 for (auto const &i
: _changed
) {
3823 bool is_clean() const {
3824 return _changed
.empty();
3828 template <bool TrackChanges
>
3829 class pg_missing_set
: public pg_missing_const_i
{
3830 using item
= pg_missing_item
;
3831 map
<hobject_t
, item
> missing
; // oid -> (need v, have v)
3832 map
<version_t
, hobject_t
> rmissing
; // v -> oid
3833 ChangeTracker
<TrackChanges
> tracker
;
3836 pg_missing_set() = default;
3838 template <typename missing_type
>
3839 pg_missing_set(const missing_type
&m
) {
3840 missing
= m
.get_items();
3841 rmissing
= m
.get_rmissing();
3842 may_include_deletes
= m
.get_may_include_deletes();
3843 for (auto &&i
: missing
)
3844 tracker
.changed(i
.first
);
3847 bool may_include_deletes
= false;
3849 const map
<hobject_t
, item
> &get_items() const override
{
3852 const map
<version_t
, hobject_t
> &get_rmissing() const override
{
3855 bool get_may_include_deletes() const override
{
3856 return may_include_deletes
;
3858 unsigned int num_missing() const override
{
3859 return missing
.size();
3861 bool have_missing() const override
{
3862 return !missing
.empty();
3864 bool is_missing(const hobject_t
& oid
, pg_missing_item
*out
= nullptr) const override
{
3865 auto iter
= missing
.find(oid
);
3866 if (iter
== missing
.end())
3869 *out
= iter
->second
;
3872 bool is_missing(const hobject_t
& oid
, eversion_t v
) const override
{
3873 map
<hobject_t
, item
>::const_iterator m
=
3875 if (m
== missing
.end())
3877 const item
&item(m
->second
);
3882 eversion_t
have_old(const hobject_t
& oid
) const override
{
3883 map
<hobject_t
, item
>::const_iterator m
=
3885 if (m
== missing
.end())
3886 return eversion_t();
3887 const item
&item(m
->second
);
3891 void claim(pg_missing_set
& o
) {
3892 static_assert(!TrackChanges
, "Can't use claim with TrackChanges");
3893 missing
.swap(o
.missing
);
3894 rmissing
.swap(o
.rmissing
);
3898 * this needs to be called in log order as we extend the log. it
3899 * assumes missing is accurate up through the previous log entry.
3901 void add_next_event(const pg_log_entry_t
& e
) {
3902 map
<hobject_t
, item
>::iterator missing_it
;
3903 missing_it
= missing
.find(e
.soid
);
3904 bool is_missing_divergent_item
= missing_it
!= missing
.end();
3905 if (e
.prior_version
== eversion_t() || e
.is_clone()) {
3907 if (is_missing_divergent_item
) { // use iterator
3908 rmissing
.erase((missing_it
->second
).need
.version
);
3909 missing_it
->second
= item(e
.version
, eversion_t(), e
.is_delete()); // .have = nil
3910 } else // create new element in missing map
3911 missing
[e
.soid
] = item(e
.version
, eversion_t(), e
.is_delete()); // .have = nil
3912 } else if (is_missing_divergent_item
) {
3913 // already missing (prior).
3914 rmissing
.erase((missing_it
->second
).need
.version
);
3915 (missing_it
->second
).need
= e
.version
; // leave .have unchanged.
3916 missing_it
->second
.set_delete(e
.is_delete());
3917 } else if (e
.is_backlog()) {
3918 // May not have prior version
3919 assert(0 == "these don't exist anymore");
3921 // not missing, we must have prior_version (if any)
3922 assert(!is_missing_divergent_item
);
3923 missing
[e
.soid
] = item(e
.version
, e
.prior_version
, e
.is_delete());
3925 rmissing
[e
.version
.version
] = e
.soid
;
3926 tracker
.changed(e
.soid
);
3929 void revise_need(hobject_t oid
, eversion_t need
, bool is_delete
) {
3930 if (missing
.count(oid
)) {
3931 rmissing
.erase(missing
[oid
].need
.version
);
3932 missing
[oid
].need
= need
; // no not adjust .have
3933 missing
[oid
].set_delete(is_delete
);
3935 missing
[oid
] = item(need
, eversion_t(), is_delete
);
3937 rmissing
[need
.version
] = oid
;
3939 tracker
.changed(oid
);
3942 void revise_have(hobject_t oid
, eversion_t have
) {
3943 if (missing
.count(oid
)) {
3944 tracker
.changed(oid
);
3945 missing
[oid
].have
= have
;
3949 void add(const hobject_t
& oid
, eversion_t need
, eversion_t have
,
3951 missing
[oid
] = item(need
, have
, is_delete
);
3952 rmissing
[need
.version
] = oid
;
3953 tracker
.changed(oid
);
3956 void rm(const hobject_t
& oid
, eversion_t v
) {
3957 std::map
<hobject_t
, item
>::iterator p
= missing
.find(oid
);
3958 if (p
!= missing
.end() && p
->second
.need
<= v
)
3962 void rm(std::map
<hobject_t
, item
>::const_iterator m
) {
3963 tracker
.changed(m
->first
);
3964 rmissing
.erase(m
->second
.need
.version
);
3968 void got(const hobject_t
& oid
, eversion_t v
) {
3969 std::map
<hobject_t
, item
>::iterator p
= missing
.find(oid
);
3970 assert(p
!= missing
.end());
3971 assert(p
->second
.need
<= v
|| p
->second
.is_delete());
3975 void got(std::map
<hobject_t
, item
>::const_iterator m
) {
3976 tracker
.changed(m
->first
);
3977 rmissing
.erase(m
->second
.need
.version
);
3983 unsigned split_bits
,
3984 pg_missing_set
*omissing
) {
3985 omissing
->may_include_deletes
= may_include_deletes
;
3986 unsigned mask
= ~((~0)<<split_bits
);
3987 for (map
<hobject_t
, item
>::iterator i
= missing
.begin();
3990 if ((i
->first
.get_hash() & mask
) == child_pgid
.m_seed
) {
3991 omissing
->add(i
->first
, i
->second
.need
, i
->second
.have
,
3992 i
->second
.is_delete());
4001 for (auto const &i
: missing
)
4002 tracker
.changed(i
.first
);
4007 void encode(bufferlist
&bl
) const {
4008 ENCODE_START(4, 2, bl
);
4009 ::encode(missing
, bl
, may_include_deletes
? CEPH_FEATURE_OSD_RECOVERY_DELETES
: 0);
4010 ::encode(may_include_deletes
, bl
);
4013 void decode(bufferlist::iterator
&bl
, int64_t pool
= -1) {
4014 for (auto const &i
: missing
)
4015 tracker
.changed(i
.first
);
4016 DECODE_START_LEGACY_COMPAT_LEN(4, 2, 2, bl
);
4017 ::decode(missing
, bl
);
4018 if (struct_v
>= 4) {
4019 ::decode(may_include_deletes
, bl
);
4024 // Handle hobject_t upgrade
4025 map
<hobject_t
, item
> tmp
;
4026 for (map
<hobject_t
, item
>::iterator i
=
4030 if (!i
->first
.is_max() && i
->first
.pool
== -1) {
4031 hobject_t
to_insert(i
->first
);
4032 to_insert
.pool
= pool
;
4033 tmp
[to_insert
] = i
->second
;
4039 missing
.insert(tmp
.begin(), tmp
.end());
4042 for (map
<hobject_t
,item
>::iterator it
=
4044 it
!= missing
.end();
4046 rmissing
[it
->second
.need
.version
] = it
->first
;
4047 for (auto const &i
: missing
)
4048 tracker
.changed(i
.first
);
4050 void dump(Formatter
*f
) const {
4051 f
->open_array_section("missing");
4052 for (map
<hobject_t
,item
>::const_iterator p
=
4053 missing
.begin(); p
!= missing
.end(); ++p
) {
4054 f
->open_object_section("item");
4055 f
->dump_stream("object") << p
->first
;
4060 f
->dump_bool("may_include_deletes", may_include_deletes
);
4062 template <typename F
>
4063 void filter_objects(F
&&f
) {
4064 for (auto i
= missing
.begin(); i
!= missing
.end();) {
4072 static void generate_test_instances(list
<pg_missing_set
*>& o
) {
4073 o
.push_back(new pg_missing_set
);
4074 o
.push_back(new pg_missing_set
);
4076 hobject_t(object_t("foo"), "foo", 123, 456, 0, ""),
4077 eversion_t(5, 6), eversion_t(5, 1), false);
4078 o
.push_back(new pg_missing_set
);
4080 hobject_t(object_t("foo"), "foo", 123, 456, 0, ""),
4081 eversion_t(5, 6), eversion_t(5, 1), true);
4082 o
.back()->may_include_deletes
= true;
4084 template <typename F
>
4085 void get_changed(F
&&f
) const {
4086 tracker
.get_changed(f
);
4091 bool is_clean() const {
4092 return tracker
.is_clean();
4094 template <typename missing_t
>
4095 bool debug_verify_from_init(
4096 const missing_t
&init_missing
,
4097 ostream
*oss
) const {
4100 auto check_missing(init_missing
.get_items());
4101 tracker
.get_changed([&](const hobject_t
&hoid
) {
4102 check_missing
.erase(hoid
);
4103 if (missing
.count(hoid
)) {
4104 check_missing
.insert(*(missing
.find(hoid
)));
4108 if (check_missing
.size() != missing
.size()) {
4110 *oss
<< "Size mismatch, check: " << check_missing
.size()
4111 << ", actual: " << missing
.size() << "\n";
4115 for (auto &i
: missing
) {
4116 if (!check_missing
.count(i
.first
)) {
4118 *oss
<< "check_missing missing " << i
.first
<< "\n";
4120 } else if (check_missing
[i
.first
] != i
.second
) {
4122 *oss
<< "check_missing missing item mismatch on " << i
.first
4123 << ", check: " << check_missing
[i
.first
]
4124 << ", actual: " << i
.second
<< "\n";
4129 *oss
<< "check_missing: " << check_missing
<< "\n";
4130 set
<hobject_t
> changed
;
4131 tracker
.get_changed([&](const hobject_t
&hoid
) { changed
.insert(hoid
); });
4132 *oss
<< "changed: " << changed
<< "\n";
4137 template <bool TrackChanges
>
4139 const pg_missing_set
<TrackChanges
> &c
, bufferlist
&bl
, uint64_t features
=0) {
4142 ENCODE_DUMP_POST(cl
);
4144 template <bool TrackChanges
>
4145 void decode(pg_missing_set
<TrackChanges
> &c
, bufferlist::iterator
&p
) {
4148 template <bool TrackChanges
>
4149 ostream
& operator<<(ostream
& out
, const pg_missing_set
<TrackChanges
> &missing
)
4151 out
<< "missing(" << missing
.num_missing()
4152 << " may_include_deletes = " << missing
.may_include_deletes
;
4153 //if (missing.num_lost()) out << ", " << missing.num_lost() << " lost";
4158 using pg_missing_t
= pg_missing_set
<false>;
4159 using pg_missing_tracker_t
= pg_missing_set
<true>;
4163 * pg list objects response format
4166 struct pg_nls_response_t
{
4167 collection_list_handle_t handle
;
4168 list
<librados::ListObjectImpl
> entries
;
4170 void encode(bufferlist
& bl
) const {
4171 ENCODE_START(1, 1, bl
);
4172 ::encode(handle
, bl
);
4173 __u32 n
= (__u32
)entries
.size();
4175 for (list
<librados::ListObjectImpl
>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
4176 ::encode(i
->nspace
, bl
);
4177 ::encode(i
->oid
, bl
);
4178 ::encode(i
->locator
, bl
);
4182 void decode(bufferlist::iterator
& bl
) {
4183 DECODE_START(1, bl
);
4184 ::decode(handle
, bl
);
4189 librados::ListObjectImpl i
;
4190 ::decode(i
.nspace
, bl
);
4191 ::decode(i
.oid
, bl
);
4192 ::decode(i
.locator
, bl
);
4193 entries
.push_back(i
);
4197 void dump(Formatter
*f
) const {
4198 f
->dump_stream("handle") << handle
;
4199 f
->open_array_section("entries");
4200 for (list
<librados::ListObjectImpl
>::const_iterator p
= entries
.begin(); p
!= entries
.end(); ++p
) {
4201 f
->open_object_section("object");
4202 f
->dump_string("namespace", p
->nspace
);
4203 f
->dump_string("object", p
->oid
);
4204 f
->dump_string("key", p
->locator
);
4209 static void generate_test_instances(list
<pg_nls_response_t
*>& o
) {
4210 o
.push_back(new pg_nls_response_t
);
4211 o
.push_back(new pg_nls_response_t
);
4212 o
.back()->handle
= hobject_t(object_t("hi"), "key", 1, 2, -1, "");
4213 o
.back()->entries
.push_back(librados::ListObjectImpl("", "one", ""));
4214 o
.back()->entries
.push_back(librados::ListObjectImpl("", "two", "twokey"));
4215 o
.back()->entries
.push_back(librados::ListObjectImpl("", "three", ""));
4216 o
.push_back(new pg_nls_response_t
);
4217 o
.back()->handle
= hobject_t(object_t("hi"), "key", 3, 4, -1, "");
4218 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1one", ""));
4219 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1two", "n1twokey"));
4220 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1three", ""));
4221 o
.push_back(new pg_nls_response_t
);
4222 o
.back()->handle
= hobject_t(object_t("hi"), "key", 5, 6, -1, "");
4223 o
.back()->entries
.push_back(librados::ListObjectImpl("", "one", ""));
4224 o
.back()->entries
.push_back(librados::ListObjectImpl("", "two", "twokey"));
4225 o
.back()->entries
.push_back(librados::ListObjectImpl("", "three", ""));
4226 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1one", ""));
4227 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1two", "n1twokey"));
4228 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1three", ""));
4232 WRITE_CLASS_ENCODER(pg_nls_response_t
)
4234 // For backwards compatibility with older OSD requests
4235 struct pg_ls_response_t
{
4236 collection_list_handle_t handle
;
4237 list
<pair
<object_t
, string
> > entries
;
4239 void encode(bufferlist
& bl
) const {
4242 ::encode(handle
, bl
);
4243 ::encode(entries
, bl
);
4245 void decode(bufferlist::iterator
& bl
) {
4249 ::decode(handle
, bl
);
4250 ::decode(entries
, bl
);
4252 void dump(Formatter
*f
) const {
4253 f
->dump_stream("handle") << handle
;
4254 f
->open_array_section("entries");
4255 for (list
<pair
<object_t
, string
> >::const_iterator p
= entries
.begin(); p
!= entries
.end(); ++p
) {
4256 f
->open_object_section("object");
4257 f
->dump_stream("object") << p
->first
;
4258 f
->dump_string("key", p
->second
);
4263 static void generate_test_instances(list
<pg_ls_response_t
*>& o
) {
4264 o
.push_back(new pg_ls_response_t
);
4265 o
.push_back(new pg_ls_response_t
);
4266 o
.back()->handle
= hobject_t(object_t("hi"), "key", 1, 2, -1, "");
4267 o
.back()->entries
.push_back(make_pair(object_t("one"), string()));
4268 o
.back()->entries
.push_back(make_pair(object_t("two"), string("twokey")));
4272 WRITE_CLASS_ENCODER(pg_ls_response_t
)
4275 * object_copy_cursor_t
4277 struct object_copy_cursor_t
{
4278 uint64_t data_offset
;
4284 object_copy_cursor_t()
4286 attr_complete(false),
4287 data_complete(false),
4288 omap_complete(false)
4291 bool is_initial() const {
4292 return !attr_complete
&& data_offset
== 0 && omap_offset
.empty();
4294 bool is_complete() const {
4295 return attr_complete
&& data_complete
&& omap_complete
;
4298 static void generate_test_instances(list
<object_copy_cursor_t
*>& o
);
4299 void encode(bufferlist
& bl
) const;
4300 void decode(bufferlist::iterator
&bl
);
4301 void dump(Formatter
*f
) const;
4303 WRITE_CLASS_ENCODER(object_copy_cursor_t
)
4306 * object_copy_data_t
4308 * Return data from a copy request. The semantics are a little strange
4309 * as a result of the encoding's heritage.
4311 * In particular, the sender unconditionally fills in the cursor (from what
4312 * it receives and sends), the size, and the mtime, but is responsible for
4313 * figuring out whether it should put any data in the attrs, data, or
4314 * omap members (corresponding to xattrs, object data, and the omap entries)
4315 * based on external data (the client includes a max amount to return with
4316 * the copy request). The client then looks into the attrs, data, and/or omap
4317 * based on the contents of the cursor.
4319 struct object_copy_data_t
{
4321 FLAG_DATA_DIGEST
= 1<<0,
4322 FLAG_OMAP_DIGEST
= 1<<1,
4324 object_copy_cursor_t cursor
;
4327 uint32_t data_digest
, omap_digest
;
4329 map
<string
, bufferlist
> attrs
;
4331 bufferlist omap_header
;
4332 bufferlist omap_data
;
4334 /// which snaps we are defined for (if a snap and not the head)
4335 vector
<snapid_t
> snaps
;
4336 ///< latest snap seq for the object (if head)
4339 ///< recent reqids on this object
4340 mempool::osd_pglog::vector
<pair
<osd_reqid_t
, version_t
> > reqids
;
4342 uint64_t truncate_seq
;
4343 uint64_t truncate_size
;
4346 object_copy_data_t() :
4347 size((uint64_t)-1), data_digest(-1),
4348 omap_digest(-1), flags(0),
4352 static void generate_test_instances(list
<object_copy_data_t
*>& o
);
4353 void encode(bufferlist
& bl
, uint64_t features
) const;
4354 void decode(bufferlist::iterator
& bl
);
4355 void dump(Formatter
*f
) const;
4357 WRITE_CLASS_ENCODER_FEATURES(object_copy_data_t
)
4362 struct pg_create_t
{
4363 epoch_t created
; // epoch pg created
4364 pg_t parent
; // split from parent (if != pg_t())
4368 : created(0), split_bits(0) {}
4369 pg_create_t(unsigned c
, pg_t p
, int s
)
4370 : created(c
), parent(p
), split_bits(s
) {}
4372 void encode(bufferlist
&bl
) const;
4373 void decode(bufferlist::iterator
&bl
);
4374 void dump(Formatter
*f
) const;
4375 static void generate_test_instances(list
<pg_create_t
*>& o
);
4377 WRITE_CLASS_ENCODER(pg_create_t
)
4379 // -----------------------------------------
4381 struct osd_peer_stat_t
{
4384 osd_peer_stat_t() { }
4386 void encode(bufferlist
&bl
) const;
4387 void decode(bufferlist::iterator
&bl
);
4388 void dump(Formatter
*f
) const;
4389 static void generate_test_instances(list
<osd_peer_stat_t
*>& o
);
4391 WRITE_CLASS_ENCODER(osd_peer_stat_t
)
4393 ostream
& operator<<(ostream
& out
, const osd_peer_stat_t
&stat
);
4396 // -----------------------------------------
4398 class ObjectExtent
{
4400 * ObjectExtents are used for specifying IO behavior against RADOS
4401 * objects when one is using the ObjectCacher.
4403 * To use this in a real system, *every member* must be filled
4404 * out correctly. In particular, make sure to initialize the
4405 * oloc correctly, as its default values are deliberate poison
4406 * and will cause internal ObjectCacher asserts.
4408 * Similarly, your buffer_extents vector *must* specify a total
4409 * size equal to your length. If the buffer_extents inadvertently
4410 * contain less space than the length member specifies, you
4411 * will get unintelligible asserts deep in the ObjectCacher.
4413 * If you are trying to do testing and don't care about actual
4414 * RADOS function, the simplest thing to do is to initialize
4415 * the ObjectExtent (truncate_size can be 0), create a single entry
4416 * in buffer_extents matching the length, and set oloc.pool to 0.
4419 object_t oid
; // object id
4421 uint64_t offset
; // in object
4422 uint64_t length
; // in object
4423 uint64_t truncate_size
; // in object
4425 object_locator_t oloc
; // object locator (pool etc)
4427 vector
<pair
<uint64_t,uint64_t> > buffer_extents
; // off -> len. extents in buffer being mapped (may be fragmented bc of striping!)
4429 ObjectExtent() : objectno(0), offset(0), length(0), truncate_size(0) {}
4430 ObjectExtent(object_t o
, uint64_t ono
, uint64_t off
, uint64_t l
, uint64_t ts
) :
4431 oid(o
), objectno(ono
), offset(off
), length(l
), truncate_size(ts
) { }
4434 inline ostream
& operator<<(ostream
& out
, const ObjectExtent
&ex
)
4436 return out
<< "extent("
4437 << ex
.oid
<< " (" << ex
.objectno
<< ") in " << ex
.oloc
4438 << " " << ex
.offset
<< "~" << ex
.length
4439 << " -> " << ex
.buffer_extents
4444 // ---------------------------------------
4446 class OSDSuperblock
{
4448 uuid_d cluster_fsid
, osd_fsid
;
4449 int32_t whoami
; // my role in this fs.
4450 epoch_t current_epoch
; // most recent epoch
4451 epoch_t oldest_map
, newest_map
; // oldest/newest maps we have.
4454 CompatSet compat_features
;
4456 // last interval over which i mounted and was then active
4457 epoch_t mounted
; // last epoch i mounted
4458 epoch_t clean_thru
; // epoch i was active and clean thru
4462 current_epoch(0), oldest_map(0), newest_map(0), weight(0),
4463 mounted(0), clean_thru(0) {
4466 void encode(bufferlist
&bl
) const;
4467 void decode(bufferlist::iterator
&bl
);
4468 void dump(Formatter
*f
) const;
4469 static void generate_test_instances(list
<OSDSuperblock
*>& o
);
4471 WRITE_CLASS_ENCODER(OSDSuperblock
)
4473 inline ostream
& operator<<(ostream
& out
, const OSDSuperblock
& sb
)
4475 return out
<< "sb(" << sb
.cluster_fsid
4476 << " osd." << sb
.whoami
4477 << " " << sb
.osd_fsid
4478 << " e" << sb
.current_epoch
4479 << " [" << sb
.oldest_map
<< "," << sb
.newest_map
<< "]"
4480 << " lci=[" << sb
.mounted
<< "," << sb
.clean_thru
<< "]"
4493 * attached to object head. describes most recent snap context, and
4494 * set of existing clones.
4499 vector
<snapid_t
> snaps
; // descending
4500 vector
<snapid_t
> clones
; // ascending
4501 map
<snapid_t
, interval_set
<uint64_t> > clone_overlap
; // overlap w/ next newest
4502 map
<snapid_t
, uint64_t> clone_size
;
4503 map
<snapid_t
, vector
<snapid_t
>> clone_snaps
; // descending
4505 SnapSet() : seq(0), head_exists(false) {}
4506 explicit SnapSet(bufferlist
& bl
) {
4507 bufferlist::iterator p
= bl
.begin();
4511 bool is_legacy() const {
4512 return clone_snaps
.size() < clones
.size() || !head_exists
;
4515 /// populate SnapSet from a librados::snap_set_t
4516 void from_snap_set(const librados::snap_set_t
& ss
, bool legacy
);
4518 /// get space accounted to clone
4519 uint64_t get_clone_bytes(snapid_t clone
) const;
4521 void encode(bufferlist
& bl
) const;
4522 void decode(bufferlist::iterator
& bl
);
4523 void dump(Formatter
*f
) const;
4524 static void generate_test_instances(list
<SnapSet
*>& o
);
4526 SnapContext
get_ssc_as_of(snapid_t as_of
) const {
4529 for (vector
<snapid_t
>::const_iterator i
= snaps
.begin();
4533 out
.snaps
.push_back(*i
);
4538 // return min element of snaps > after, return max if no such element
4539 snapid_t
get_first_snap_after(snapid_t after
, snapid_t max
) const {
4540 for (vector
<snapid_t
>::const_reverse_iterator i
= snaps
.rbegin();
4549 SnapSet
get_filtered(const pg_pool_t
&pinfo
) const;
4550 void filter(const pg_pool_t
&pinfo
);
4552 WRITE_CLASS_ENCODER(SnapSet
)
4554 ostream
& operator<<(ostream
& out
, const SnapSet
& cs
);
4559 #define SS_ATTR "snapset"
4561 struct watch_info_t
{
4563 uint32_t timeout_seconds
;
4566 watch_info_t() : cookie(0), timeout_seconds(0) { }
4567 watch_info_t(uint64_t c
, uint32_t t
, const entity_addr_t
& a
) : cookie(c
), timeout_seconds(t
), addr(a
) {}
4569 void encode(bufferlist
& bl
, uint64_t features
) const;
4570 void decode(bufferlist::iterator
& bl
);
4571 void dump(Formatter
*f
) const;
4572 static void generate_test_instances(list
<watch_info_t
*>& o
);
4574 WRITE_CLASS_ENCODER_FEATURES(watch_info_t
)
4576 static inline bool operator==(const watch_info_t
& l
, const watch_info_t
& r
) {
4577 return l
.cookie
== r
.cookie
&& l
.timeout_seconds
== r
.timeout_seconds
4578 && l
.addr
== r
.addr
;
4581 static inline ostream
& operator<<(ostream
& out
, const watch_info_t
& w
) {
4582 return out
<< "watch(cookie " << w
.cookie
<< " " << w
.timeout_seconds
<< "s"
4583 << " " << w
.addr
<< ")";
4586 struct notify_info_t
{
4593 static inline ostream
& operator<<(ostream
& out
, const notify_info_t
& n
) {
4594 return out
<< "notify(cookie " << n
.cookie
4595 << " notify" << n
.notify_id
4596 << " " << n
.timeout
<< "s)";
4599 struct object_info_t
;
4600 struct object_manifest_t
{
4603 TYPE_REDIRECT
= 1, // start with this
4604 TYPE_CHUNKED
= 2, // do this later
4606 uint8_t type
; // redirect, chunked, ...
4607 hobject_t redirect_target
;
4609 object_manifest_t() : type(0) { }
4610 object_manifest_t(uint8_t type
, const hobject_t
& redirect_target
)
4611 : type(type
), redirect_target(redirect_target
) { }
4613 bool is_empty() const {
4614 return type
== TYPE_NONE
;
4616 bool is_redirect() const {
4617 return type
== TYPE_REDIRECT
;
4619 bool is_chunked() const {
4620 return type
== TYPE_CHUNKED
;
4622 static const char *get_type_name(uint8_t m
) {
4624 case TYPE_NONE
: return "none";
4625 case TYPE_REDIRECT
: return "redirect";
4626 case TYPE_CHUNKED
: return "chunked";
4627 default: return "unknown";
4630 const char *get_type_name() const {
4631 return get_type_name(type
);
4633 static void generate_test_instances(list
<object_manifest_t
*>& o
);
4634 void encode(bufferlist
&bl
) const;
4635 void decode(bufferlist::iterator
&bl
);
4636 void dump(Formatter
*f
) const;
4637 friend ostream
& operator<<(ostream
& out
, const object_info_t
& oi
);
4639 WRITE_CLASS_ENCODER(object_manifest_t
)
4640 ostream
& operator<<(ostream
& out
, const object_manifest_t
& oi
);
4642 struct object_info_t
{
4644 eversion_t version
, prior_version
;
4645 version_t user_version
;
4646 osd_reqid_t last_reqid
;
4650 utime_t local_mtime
; // local mtime
4652 // note: these are currently encoded into a total 16 bits; see
4653 // encode()/decode() for the weirdness.
4656 FLAG_WHITEOUT
= 1<<1, // object logically does not exist
4657 FLAG_DIRTY
= 1<<2, // object has been modified since last flushed or undirtied
4658 FLAG_OMAP
= 1 << 3, // has (or may have) some/any omap data
4659 FLAG_DATA_DIGEST
= 1 << 4, // has data crc
4660 FLAG_OMAP_DIGEST
= 1 << 5, // has omap crc
4661 FLAG_CACHE_PIN
= 1 << 6, // pin the object in cache tier
4662 FLAG_MANIFEST
= 1 << 7, // has manifest
4664 FLAG_USES_TMAP
= 1<<8, // deprecated; no longer used.
4669 static string
get_flag_string(flag_t flags
) {
4671 if (flags
& FLAG_LOST
)
4673 if (flags
& FLAG_WHITEOUT
)
4675 if (flags
& FLAG_DIRTY
)
4677 if (flags
& FLAG_USES_TMAP
)
4679 if (flags
& FLAG_OMAP
)
4681 if (flags
& FLAG_DATA_DIGEST
)
4682 s
+= "|data_digest";
4683 if (flags
& FLAG_OMAP_DIGEST
)
4684 s
+= "|omap_digest";
4685 if (flags
& FLAG_CACHE_PIN
)
4687 if (flags
& FLAG_MANIFEST
)
4693 string
get_flag_string() const {
4694 return get_flag_string(flags
);
4697 /// [clone] descending. pre-luminous; moved to SnapSet
4698 vector
<snapid_t
> legacy_snaps
;
4700 uint64_t truncate_seq
, truncate_size
;
4702 map
<pair
<uint64_t, entity_name_t
>, watch_info_t
> watchers
;
4704 // opportunistic checksums; may or may not be present
4705 __u32 data_digest
; ///< data crc32c
4706 __u32 omap_digest
; ///< omap crc32c
4708 // alloc hint attribute
4709 uint64_t expected_object_size
, expected_write_size
;
4710 uint32_t alloc_hint_flags
;
4712 struct object_manifest_t manifest
;
4714 void copy_user_bits(const object_info_t
& other
);
4716 static ps_t
legacy_object_locator_to_ps(const object_t
&oid
,
4717 const object_locator_t
&loc
);
4719 bool test_flag(flag_t f
) const {
4720 return (flags
& f
) == f
;
4722 void set_flag(flag_t f
) {
4723 flags
= (flag_t
)(flags
| f
);
4725 void clear_flag(flag_t f
) {
4726 flags
= (flag_t
)(flags
& ~f
);
4728 bool is_lost() const {
4729 return test_flag(FLAG_LOST
);
4731 bool is_whiteout() const {
4732 return test_flag(FLAG_WHITEOUT
);
4734 bool is_dirty() const {
4735 return test_flag(FLAG_DIRTY
);
4737 bool is_omap() const {
4738 return test_flag(FLAG_OMAP
);
4740 bool is_data_digest() const {
4741 return test_flag(FLAG_DATA_DIGEST
);
4743 bool is_omap_digest() const {
4744 return test_flag(FLAG_OMAP_DIGEST
);
4746 bool is_cache_pinned() const {
4747 return test_flag(FLAG_CACHE_PIN
);
4749 bool has_manifest() const {
4750 return test_flag(FLAG_MANIFEST
);
4753 void set_data_digest(__u32 d
) {
4754 set_flag(FLAG_DATA_DIGEST
);
4757 void set_omap_digest(__u32 d
) {
4758 set_flag(FLAG_OMAP_DIGEST
);
4761 void clear_data_digest() {
4762 clear_flag(FLAG_DATA_DIGEST
);
4765 void clear_omap_digest() {
4766 clear_flag(FLAG_OMAP_DIGEST
);
4770 set_data_digest(-1);
4771 set_omap_digest(-1);
4774 void encode(bufferlist
& bl
, uint64_t features
) const;
4775 void decode(bufferlist::iterator
& bl
);
4776 void decode(bufferlist
& bl
) {
4777 bufferlist::iterator p
= bl
.begin();
4780 void dump(Formatter
*f
) const;
4781 static void generate_test_instances(list
<object_info_t
*>& o
);
4783 explicit object_info_t()
4784 : user_version(0), size(0), flags((flag_t
)0),
4785 truncate_seq(0), truncate_size(0),
4786 data_digest(-1), omap_digest(-1),
4787 expected_object_size(0), expected_write_size(0),
4791 explicit object_info_t(const hobject_t
& s
)
4793 user_version(0), size(0), flags((flag_t
)0),
4794 truncate_seq(0), truncate_size(0),
4795 data_digest(-1), omap_digest(-1),
4796 expected_object_size(0), expected_write_size(0),
4800 explicit object_info_t(bufferlist
& bl
) {
4804 WRITE_CLASS_ENCODER_FEATURES(object_info_t
)
4806 ostream
& operator<<(ostream
& out
, const object_info_t
& oi
);
4811 struct ObjectRecoveryInfo
{
4816 SnapSet ss
; // only populated if soid is_snap()
4817 interval_set
<uint64_t> copy_subset
;
4818 map
<hobject_t
, interval_set
<uint64_t>> clone_subset
;
4820 ObjectRecoveryInfo() : size(0) { }
4822 static void generate_test_instances(list
<ObjectRecoveryInfo
*>& o
);
4823 void encode(bufferlist
&bl
, uint64_t features
) const;
4824 void decode(bufferlist::iterator
&bl
, int64_t pool
= -1);
4825 ostream
&print(ostream
&out
) const;
4826 void dump(Formatter
*f
) const;
4828 WRITE_CLASS_ENCODER_FEATURES(ObjectRecoveryInfo
)
4829 ostream
& operator<<(ostream
& out
, const ObjectRecoveryInfo
&inf
);
4831 struct ObjectRecoveryProgress
{
4832 uint64_t data_recovered_to
;
4833 string omap_recovered_to
;
4839 ObjectRecoveryProgress()
4840 : data_recovered_to(0),
4842 data_complete(false), omap_complete(false) { }
4844 bool is_complete(const ObjectRecoveryInfo
& info
) const {
4845 return (data_recovered_to
>= (
4846 info
.copy_subset
.empty() ?
4847 0 : info
.copy_subset
.range_end())) &&
4851 static void generate_test_instances(list
<ObjectRecoveryProgress
*>& o
);
4852 void encode(bufferlist
&bl
) const;
4853 void decode(bufferlist::iterator
&bl
);
4854 ostream
&print(ostream
&out
) const;
4855 void dump(Formatter
*f
) const;
4857 WRITE_CLASS_ENCODER(ObjectRecoveryProgress
)
4858 ostream
& operator<<(ostream
& out
, const ObjectRecoveryProgress
&prog
);
4860 struct PushReplyOp
{
4863 static void generate_test_instances(list
<PushReplyOp
*>& o
);
4864 void encode(bufferlist
&bl
) const;
4865 void decode(bufferlist::iterator
&bl
);
4866 ostream
&print(ostream
&out
) const;
4867 void dump(Formatter
*f
) const;
4869 uint64_t cost(CephContext
*cct
) const;
4871 WRITE_CLASS_ENCODER(PushReplyOp
)
4872 ostream
& operator<<(ostream
& out
, const PushReplyOp
&op
);
4877 ObjectRecoveryInfo recovery_info
;
4878 ObjectRecoveryProgress recovery_progress
;
4880 static void generate_test_instances(list
<PullOp
*>& o
);
4881 void encode(bufferlist
&bl
, uint64_t features
) const;
4882 void decode(bufferlist::iterator
&bl
);
4883 ostream
&print(ostream
&out
) const;
4884 void dump(Formatter
*f
) const;
4886 uint64_t cost(CephContext
*cct
) const;
4888 WRITE_CLASS_ENCODER_FEATURES(PullOp
)
4889 ostream
& operator<<(ostream
& out
, const PullOp
&op
);
4895 interval_set
<uint64_t> data_included
;
4896 bufferlist omap_header
;
4897 map
<string
, bufferlist
> omap_entries
;
4898 map
<string
, bufferlist
> attrset
;
4900 ObjectRecoveryInfo recovery_info
;
4901 ObjectRecoveryProgress before_progress
;
4902 ObjectRecoveryProgress after_progress
;
4904 static void generate_test_instances(list
<PushOp
*>& o
);
4905 void encode(bufferlist
&bl
, uint64_t features
) const;
4906 void decode(bufferlist::iterator
&bl
);
4907 ostream
&print(ostream
&out
) const;
4908 void dump(Formatter
*f
) const;
4910 uint64_t cost(CephContext
*cct
) const;
4912 WRITE_CLASS_ENCODER_FEATURES(PushOp
)
4913 ostream
& operator<<(ostream
& out
, const PushOp
&op
);
4917 * summarize pg contents for purposes of a scrub
4921 map
<string
,bufferptr
> attrs
;
4923 __u32 omap_digest
; ///< omap crc32c
4924 __u32 digest
; ///< data crc32c
4926 bool digest_present
:1;
4927 bool omap_digest_present
:1;
4930 bool ec_hash_mismatch
:1;
4931 bool ec_size_mismatch
:1;
4934 // Init invalid size so it won't match if we get a stat EIO error
4935 size(-1), omap_digest(0), digest(0),
4936 negative(false), digest_present(false), omap_digest_present(false),
4937 read_error(false), stat_error(false), ec_hash_mismatch(false), ec_size_mismatch(false) {}
4939 void encode(bufferlist
& bl
) const;
4940 void decode(bufferlist::iterator
& bl
);
4941 void dump(Formatter
*f
) const;
4942 static void generate_test_instances(list
<object
*>& o
);
4944 WRITE_CLASS_ENCODER(object
)
4946 map
<hobject_t
,object
> objects
;
4947 eversion_t valid_through
;
4948 eversion_t incr_since
;
4950 void merge_incr(const ScrubMap
&l
);
4951 void insert(const ScrubMap
&r
) {
4952 objects
.insert(r
.objects
.begin(), r
.objects
.end());
4954 void swap(ScrubMap
&r
) {
4956 swap(objects
, r
.objects
);
4957 swap(valid_through
, r
.valid_through
);
4958 swap(incr_since
, r
.incr_since
);
4961 void encode(bufferlist
& bl
) const;
4962 void decode(bufferlist::iterator
& bl
, int64_t pool
=-1);
4963 void dump(Formatter
*f
) const;
4964 static void generate_test_instances(list
<ScrubMap
*>& o
);
4966 WRITE_CLASS_ENCODER(ScrubMap::object
)
4967 WRITE_CLASS_ENCODER(ScrubMap
)
4973 bufferlist indata
, outdata
;
4977 memset(&op
, 0, sizeof(ceph_osd_op
));
4981 * split a bufferlist into constituent indata members of a vector of OSDOps
4983 * @param ops [out] vector of OSDOps
4984 * @param in [in] combined data buffer
4986 static void split_osd_op_vector_in_data(vector
<OSDOp
>& ops
, bufferlist
& in
);
4989 * merge indata members of a vector of OSDOp into a single bufferlist
4991 * Notably this also encodes certain other OSDOp data into the data
4992 * buffer, including the sobject_t soid.
4994 * @param ops [in] vector of OSDOps
4995 * @param out [out] combined data buffer
4997 static void merge_osd_op_vector_in_data(vector
<OSDOp
>& ops
, bufferlist
& out
);
5000 * split a bufferlist into constituent outdata members of a vector of OSDOps
5002 * @param ops [out] vector of OSDOps
5003 * @param in [in] combined data buffer
5005 static void split_osd_op_vector_out_data(vector
<OSDOp
>& ops
, bufferlist
& in
);
5008 * merge outdata members of a vector of OSDOps into a single bufferlist
5010 * @param ops [in] vector of OSDOps
5011 * @param out [out] combined data buffer
5013 static void merge_osd_op_vector_out_data(vector
<OSDOp
>& ops
, bufferlist
& out
);
5016 * Clear data as much as possible, leave minimal data for historical op dump
5018 * @param ops [in] vector of OSDOps
5020 static void clear_data(vector
<OSDOp
>& ops
);
5023 ostream
& operator<<(ostream
& out
, const OSDOp
& op
);
5025 struct watch_item_t
{
5028 uint32_t timeout_seconds
;
5031 watch_item_t() : cookie(0), timeout_seconds(0) { }
5032 watch_item_t(entity_name_t name
, uint64_t cookie
, uint32_t timeout
,
5033 const entity_addr_t
& addr
)
5034 : name(name
), cookie(cookie
), timeout_seconds(timeout
),
5037 void encode(bufferlist
&bl
, uint64_t features
) const {
5038 ENCODE_START(2, 1, bl
);
5040 ::encode(cookie
, bl
);
5041 ::encode(timeout_seconds
, bl
);
5042 ::encode(addr
, bl
, features
);
5045 void decode(bufferlist::iterator
&bl
) {
5046 DECODE_START(2, bl
);
5048 ::decode(cookie
, bl
);
5049 ::decode(timeout_seconds
, bl
);
5050 if (struct_v
>= 2) {
5056 WRITE_CLASS_ENCODER_FEATURES(watch_item_t
)
5058 struct obj_watch_item_t
{
5064 * obj list watch response format
5067 struct obj_list_watch_response_t
{
5068 list
<watch_item_t
> entries
;
5070 void encode(bufferlist
& bl
, uint64_t features
) const {
5071 ENCODE_START(1, 1, bl
);
5072 ::encode(entries
, bl
, features
);
5075 void decode(bufferlist::iterator
& bl
) {
5076 DECODE_START(1, bl
);
5077 ::decode(entries
, bl
);
5080 void dump(Formatter
*f
) const {
5081 f
->open_array_section("entries");
5082 for (list
<watch_item_t
>::const_iterator p
= entries
.begin(); p
!= entries
.end(); ++p
) {
5083 f
->open_object_section("watch");
5084 f
->dump_stream("watcher") << p
->name
;
5085 f
->dump_int("cookie", p
->cookie
);
5086 f
->dump_int("timeout", p
->timeout_seconds
);
5087 f
->open_object_section("addr");
5094 static void generate_test_instances(list
<obj_list_watch_response_t
*>& o
) {
5096 o
.push_back(new obj_list_watch_response_t
);
5097 o
.push_back(new obj_list_watch_response_t
);
5098 ea
.set_type(entity_addr_t::TYPE_LEGACY
);
5100 ea
.set_family(AF_INET
);
5101 ea
.set_in4_quad(0, 127);
5102 ea
.set_in4_quad(1, 0);
5103 ea
.set_in4_quad(2, 0);
5104 ea
.set_in4_quad(3, 1);
5106 o
.back()->entries
.push_back(watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT
, 1), 10, 30, ea
));
5108 ea
.set_in4_quad(3, 2);
5110 o
.back()->entries
.push_back(watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT
, 2), 20, 60, ea
));
5113 WRITE_CLASS_ENCODER_FEATURES(obj_list_watch_response_t
)
5117 vector
<snapid_t
> snaps
; // ascending
5118 vector
< pair
<uint64_t,uint64_t> > overlap
;
5121 clone_info() : cloneid(CEPH_NOSNAP
), size(0) {}
5123 void encode(bufferlist
& bl
) const {
5124 ENCODE_START(1, 1, bl
);
5125 ::encode(cloneid
, bl
);
5126 ::encode(snaps
, bl
);
5127 ::encode(overlap
, bl
);
5131 void decode(bufferlist::iterator
& bl
) {
5132 DECODE_START(1, bl
);
5133 ::decode(cloneid
, bl
);
5134 ::decode(snaps
, bl
);
5135 ::decode(overlap
, bl
);
5139 void dump(Formatter
*f
) const {
5140 if (cloneid
== CEPH_NOSNAP
)
5141 f
->dump_string("cloneid", "HEAD");
5143 f
->dump_unsigned("cloneid", cloneid
.val
);
5144 f
->open_array_section("snapshots");
5145 for (vector
<snapid_t
>::const_iterator p
= snaps
.begin(); p
!= snaps
.end(); ++p
) {
5146 f
->open_object_section("snap");
5147 f
->dump_unsigned("id", p
->val
);
5151 f
->open_array_section("overlaps");
5152 for (vector
< pair
<uint64_t,uint64_t> >::const_iterator q
= overlap
.begin();
5153 q
!= overlap
.end(); ++q
) {
5154 f
->open_object_section("overlap");
5155 f
->dump_unsigned("offset", q
->first
);
5156 f
->dump_unsigned("length", q
->second
);
5160 f
->dump_unsigned("size", size
);
5162 static void generate_test_instances(list
<clone_info
*>& o
) {
5163 o
.push_back(new clone_info
);
5164 o
.push_back(new clone_info
);
5165 o
.back()->cloneid
= 1;
5166 o
.back()->snaps
.push_back(1);
5167 o
.back()->overlap
.push_back(pair
<uint64_t,uint64_t>(0,4096));
5168 o
.back()->overlap
.push_back(pair
<uint64_t,uint64_t>(8192,4096));
5169 o
.back()->size
= 16384;
5170 o
.push_back(new clone_info
);
5171 o
.back()->cloneid
= CEPH_NOSNAP
;
5172 o
.back()->size
= 32768;
5175 WRITE_CLASS_ENCODER(clone_info
)
5178 * obj list snaps response format
5181 struct obj_list_snap_response_t
{
5182 vector
<clone_info
> clones
; // ascending
5185 void encode(bufferlist
& bl
) const {
5186 ENCODE_START(2, 1, bl
);
5187 ::encode(clones
, bl
);
5191 void decode(bufferlist::iterator
& bl
) {
5192 DECODE_START(2, bl
);
5193 ::decode(clones
, bl
);
5200 void dump(Formatter
*f
) const {
5201 f
->open_array_section("clones");
5202 for (vector
<clone_info
>::const_iterator p
= clones
.begin(); p
!= clones
.end(); ++p
) {
5203 f
->open_object_section("clone");
5207 f
->dump_unsigned("seq", seq
);
5210 static void generate_test_instances(list
<obj_list_snap_response_t
*>& o
) {
5211 o
.push_back(new obj_list_snap_response_t
);
5212 o
.push_back(new obj_list_snap_response_t
);
5215 cl
.snaps
.push_back(1);
5216 cl
.overlap
.push_back(pair
<uint64_t,uint64_t>(0,4096));
5217 cl
.overlap
.push_back(pair
<uint64_t,uint64_t>(8192,4096));
5219 o
.back()->clones
.push_back(cl
);
5220 cl
.cloneid
= CEPH_NOSNAP
;
5224 o
.back()->clones
.push_back(cl
);
5225 o
.back()->seq
= 123;
5229 WRITE_CLASS_ENCODER(obj_list_snap_response_t
)
5233 struct PromoteCounter
{
5234 std::atomic_ullong attempts
{0};
5235 std::atomic_ullong objects
{0};
5236 std::atomic_ullong bytes
{0};
5242 void finish(uint64_t size
) {
5247 void sample_and_attenuate(uint64_t *a
, uint64_t *o
, uint64_t *b
) {
5258 * ObjectStore full statfs information
5260 struct store_statfs_t
5262 uint64_t total
= 0; // Total bytes
5263 uint64_t available
= 0; // Free bytes available
5265 int64_t allocated
= 0; // Bytes allocated by the store
5266 int64_t stored
= 0; // Bytes actually stored by the user
5267 int64_t compressed
= 0; // Bytes stored after compression
5268 int64_t compressed_allocated
= 0; // Bytes allocated for compressed data
5269 int64_t compressed_original
= 0; // Bytes that were successfully compressed
5272 *this = store_statfs_t();
5274 bool operator ==(const store_statfs_t
& other
) const;
5275 void dump(Formatter
*f
) const;
5277 ostream
&operator<<(ostream
&lhs
, const store_statfs_t
&rhs
);