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")
68 /// min recovery priority for MBackfillReserve
69 #define OSD_RECOVERY_PRIORITY_MIN 0
71 /// base backfill priority for MBackfillReserve
72 #define OSD_BACKFILL_PRIORITY_BASE 100
74 /// base backfill priority for MBackfillReserve (degraded PG)
75 #define OSD_BACKFILL_DEGRADED_PRIORITY_BASE 140
77 /// base recovery priority for MBackfillReserve
78 #define OSD_RECOVERY_PRIORITY_BASE 180
80 /// base backfill priority for MBackfillReserve (inactive PG)
81 #define OSD_BACKFILL_INACTIVE_PRIORITY_BASE 220
83 /// max recovery priority for MBackfillReserve
84 #define OSD_RECOVERY_PRIORITY_MAX 255
87 typedef hobject_t collection_list_handle_t
;
89 /// convert a single CPEH_OSD_FLAG_* to a string
90 const char *ceph_osd_flag_name(unsigned flag
);
91 /// convert a single CEPH_OSD_OF_FLAG_* to a string
92 const char *ceph_osd_op_flag_name(unsigned flag
);
94 /// convert CEPH_OSD_FLAG_* op flags to a string
95 string
ceph_osd_flag_string(unsigned flags
);
96 /// conver CEPH_OSD_OP_FLAG_* op flags to a string
97 string
ceph_osd_op_flag_string(unsigned flags
);
98 /// conver CEPH_OSD_ALLOC_HINT_FLAG_* op flags to a string
99 string
ceph_osd_alloc_hint_flag_string(unsigned flags
);
103 * osd request identifier
105 * caller name + incarnation# + tid to unique identify this request.
108 entity_name_t name
; // who
110 int32_t inc
; // incarnation
114 osd_reqid_t(const entity_name_t
& a
, int i
, ceph_tid_t t
)
115 : name(a
), tid(t
), inc(i
) {}
117 DENC(osd_reqid_t
, v
, p
) {
124 void dump(Formatter
*f
) const;
125 static void generate_test_instances(list
<osd_reqid_t
*>& o
);
127 WRITE_CLASS_DENC(osd_reqid_t
)
134 pg_shard_t() : osd(-1), shard(shard_id_t::NO_SHARD
) {}
135 explicit pg_shard_t(int osd
) : osd(osd
), shard(shard_id_t::NO_SHARD
) {}
136 pg_shard_t(int osd
, shard_id_t shard
) : osd(osd
), shard(shard
) {}
137 bool is_undefined() const {
140 void encode(bufferlist
&bl
) const;
141 void decode(bufferlist::iterator
&bl
);
142 void dump(Formatter
*f
) const {
143 f
->dump_unsigned("osd", osd
);
144 if (shard
!= shard_id_t::NO_SHARD
) {
145 f
->dump_unsigned("shard", shard
);
149 WRITE_CLASS_ENCODER(pg_shard_t
)
150 WRITE_EQ_OPERATORS_2(pg_shard_t
, osd
, shard
)
151 WRITE_CMP_OPERATORS_2(pg_shard_t
, osd
, shard
)
152 ostream
&operator<<(ostream
&lhs
, const pg_shard_t
&rhs
);
154 class IsPGRecoverablePredicate
{
157 * have encodes the shards available
159 virtual bool operator()(const set
<pg_shard_t
> &have
) const = 0;
160 virtual ~IsPGRecoverablePredicate() {}
163 class IsPGReadablePredicate
{
166 * have encodes the shards available
168 virtual bool operator()(const set
<pg_shard_t
> &have
) const = 0;
169 virtual ~IsPGReadablePredicate() {}
172 inline ostream
& operator<<(ostream
& out
, const osd_reqid_t
& r
) {
173 return out
<< r
.name
<< "." << r
.inc
<< ":" << r
.tid
;
176 inline bool operator==(const osd_reqid_t
& l
, const osd_reqid_t
& r
) {
177 return (l
.name
== r
.name
) && (l
.inc
== r
.inc
) && (l
.tid
== r
.tid
);
179 inline bool operator!=(const osd_reqid_t
& l
, const osd_reqid_t
& r
) {
180 return (l
.name
!= r
.name
) || (l
.inc
!= r
.inc
) || (l
.tid
!= r
.tid
);
182 inline bool operator<(const osd_reqid_t
& l
, const osd_reqid_t
& r
) {
183 return (l
.name
< r
.name
) || (l
.inc
< r
.inc
) ||
184 (l
.name
== r
.name
&& l
.inc
== r
.inc
&& l
.tid
< r
.tid
);
186 inline bool operator<=(const osd_reqid_t
& l
, const osd_reqid_t
& r
) {
187 return (l
.name
< r
.name
) || (l
.inc
< r
.inc
) ||
188 (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
) { return !(l
<= r
); }
191 inline bool operator>=(const osd_reqid_t
& l
, const osd_reqid_t
& r
) { return !(l
< r
); }
194 template<> struct hash
<osd_reqid_t
> {
195 size_t operator()(const osd_reqid_t
&r
) const {
196 static hash
<uint64_t> H
;
197 return H(r
.name
.num() ^ r
.tid
^ r
.inc
);
205 // a locator constrains the placement of an object. mainly, which pool
207 struct object_locator_t
{
208 // You specify either the hash or the key -- not both
209 int64_t pool
; ///< pool id
210 string key
; ///< key string (if non-empty)
211 string nspace
; ///< namespace
212 int64_t hash
; ///< hash position (if >= 0)
214 explicit object_locator_t()
215 : pool(-1), hash(-1) {}
216 explicit object_locator_t(int64_t po
)
217 : pool(po
), hash(-1) {}
218 explicit object_locator_t(int64_t po
, int64_t ps
)
219 : pool(po
), hash(ps
) {}
220 explicit object_locator_t(int64_t po
, string ns
)
221 : pool(po
), nspace(ns
), hash(-1) {}
222 explicit object_locator_t(int64_t po
, string ns
, int64_t ps
)
223 : pool(po
), nspace(ns
), hash(ps
) {}
224 explicit object_locator_t(int64_t po
, string ns
, string s
)
225 : pool(po
), key(s
), nspace(ns
), hash(-1) {}
226 explicit object_locator_t(const hobject_t
& soid
)
227 : pool(soid
.pool
), key(soid
.get_key()), nspace(soid
.nspace
), hash(-1) {}
229 int64_t get_pool() const {
244 void encode(bufferlist
& bl
) const;
245 void decode(bufferlist::iterator
& p
);
246 void dump(Formatter
*f
) const;
247 static void generate_test_instances(list
<object_locator_t
*>& o
);
249 WRITE_CLASS_ENCODER(object_locator_t
)
251 inline bool operator==(const object_locator_t
& l
, const object_locator_t
& r
) {
252 return l
.pool
== r
.pool
&& l
.key
== r
.key
&& l
.nspace
== r
.nspace
&& l
.hash
== r
.hash
;
254 inline bool operator!=(const object_locator_t
& l
, const object_locator_t
& r
) {
258 inline ostream
& operator<<(ostream
& out
, const object_locator_t
& loc
)
260 out
<< "@" << loc
.pool
;
261 if (loc
.nspace
.length())
262 out
<< ";" << loc
.nspace
;
263 if (loc
.key
.length())
264 out
<< ":" << loc
.key
;
268 struct request_redirect_t
{
270 object_locator_t redirect_locator
; ///< this is authoritative
271 string redirect_object
; ///< If non-empty, the request goes to this object name
272 bufferlist osd_instructions
; ///< a bufferlist for the OSDs, passed but not interpreted by clients
274 friend ostream
& operator<<(ostream
& out
, const request_redirect_t
& redir
);
277 request_redirect_t() {}
278 explicit request_redirect_t(const object_locator_t
& orig
, int64_t rpool
) :
279 redirect_locator(orig
) { redirect_locator
.pool
= rpool
; }
280 explicit request_redirect_t(const object_locator_t
& rloc
) :
281 redirect_locator(rloc
) {}
282 explicit request_redirect_t(const object_locator_t
& orig
,
283 const string
& robj
) :
284 redirect_locator(orig
), redirect_object(robj
) {}
286 void set_instructions(const bufferlist
& bl
) { osd_instructions
= bl
; }
287 const bufferlist
& get_instructions() { return osd_instructions
; }
289 bool empty() const { return redirect_locator
.empty() &&
290 redirect_object
.empty(); }
292 void combine_with_locator(object_locator_t
& orig
, string
& obj
) const {
293 orig
= redirect_locator
;
294 if (!redirect_object
.empty())
295 obj
= redirect_object
;
298 void encode(bufferlist
& bl
) const;
299 void decode(bufferlist::iterator
& bl
);
300 void dump(Formatter
*f
) const;
301 static void generate_test_instances(list
<request_redirect_t
*>& o
);
303 WRITE_CLASS_ENCODER(request_redirect_t
)
305 inline ostream
& operator<<(ostream
& out
, const request_redirect_t
& redir
) {
306 out
<< "object " << redir
.redirect_object
<< ", locator{" << redir
.redirect_locator
<< "}";
310 // Internal OSD op flags - set by the OSD based on the op types
312 CEPH_OSD_RMW_FLAG_READ
= (1 << 1),
313 CEPH_OSD_RMW_FLAG_WRITE
= (1 << 2),
314 CEPH_OSD_RMW_FLAG_CLASS_READ
= (1 << 3),
315 CEPH_OSD_RMW_FLAG_CLASS_WRITE
= (1 << 4),
316 CEPH_OSD_RMW_FLAG_PGOP
= (1 << 5),
317 CEPH_OSD_RMW_FLAG_CACHE
= (1 << 6),
318 CEPH_OSD_RMW_FLAG_FORCE_PROMOTE
= (1 << 7),
319 CEPH_OSD_RMW_FLAG_SKIP_HANDLE_CACHE
= (1 << 8),
320 CEPH_OSD_RMW_FLAG_SKIP_PROMOTE
= (1 << 9),
321 CEPH_OSD_RMW_FLAG_RWORDERED
= (1 << 10),
327 #define OSD_SUPERBLOCK_GOBJECT ghobject_t(hobject_t(sobject_t(object_t("osd_superblock"), 0)))
329 // placement seed (a hash value)
330 typedef uint32_t ps_t
;
332 // old (v1) pg_t encoding (wrap old struct ceph_pg)
335 void encode(bufferlist
& bl
) const {
338 void decode(bufferlist::iterator
& bl
) {
342 WRITE_CLASS_ENCODER(old_pg_t
)
344 // placement group id
350 pg_t() : m_pool(0), m_seed(0), m_preferred(-1) {}
351 pg_t(ps_t seed
, uint64_t pool
, int pref
=-1) :
352 m_pool(pool
), m_seed(seed
), m_preferred(pref
) {}
353 // cppcheck-suppress noExplicitConstructor
354 pg_t(const ceph_pg
& cpg
) :
355 m_pool(cpg
.pool
), m_seed(cpg
.ps
), m_preferred((__s16
)cpg
.preferred
) {}
357 // cppcheck-suppress noExplicitConstructor
358 pg_t(const old_pg_t
& opg
) {
362 old_pg_t
get_old_pg() const {
364 assert(m_pool
< 0xffffffffull
);
367 o
.v
.preferred
= (__s16
)m_preferred
;
374 uint64_t pool() const {
377 int32_t preferred() const {
381 static const uint8_t calc_name_buf_size
= 36; // max length for max values len("18446744073709551615.ffffffff") + future suffix len("_head") + '\0'
382 char *calc_name(char *buf
, const char *suffix_backwords
) const;
384 void set_ps(ps_t p
) {
387 void set_pool(uint64_t p
) {
390 void set_preferred(int32_t osd
) {
394 pg_t
get_parent() const;
395 pg_t
get_ancestor(unsigned old_pg_num
) const;
397 int print(char *o
, int maxlen
) const;
398 bool parse(const char *s
);
400 bool is_split(unsigned old_pg_num
, unsigned new_pg_num
, set
<pg_t
> *pchildren
) const;
403 * Returns b such that for all object o:
404 * ~((~0)<<b) & o.hash) == 0 iff o is in the pg for *this
406 unsigned get_split_bits(unsigned pg_num
) const;
408 bool contains(int bits
, const ghobject_t
& oid
) {
409 return oid
.match(bits
, ps());
411 bool contains(int bits
, const hobject_t
& oid
) {
412 return oid
.match(bits
, ps());
415 hobject_t
get_hobj_start() const;
416 hobject_t
get_hobj_end(unsigned pg_num
) const;
418 void encode(bufferlist
& bl
) const {
421 ::encode(m_pool
, bl
);
422 ::encode(m_seed
, bl
);
423 ::encode(m_preferred
, bl
);
425 void decode(bufferlist::iterator
& bl
) {
428 ::decode(m_pool
, bl
);
429 ::decode(m_seed
, bl
);
430 ::decode(m_preferred
, bl
);
432 void decode_old(bufferlist::iterator
& bl
) {
437 void dump(Formatter
*f
) const;
438 static void generate_test_instances(list
<pg_t
*>& o
);
440 WRITE_CLASS_ENCODER(pg_t
)
442 inline bool operator<(const pg_t
& l
, const pg_t
& r
) {
443 return l
.pool() < r
.pool() ||
444 (l
.pool() == r
.pool() && (l
.preferred() < r
.preferred() ||
445 (l
.preferred() == r
.preferred() && (l
.ps() < r
.ps()))));
447 inline bool operator<=(const pg_t
& l
, const pg_t
& r
) {
448 return l
.pool() < r
.pool() ||
449 (l
.pool() == r
.pool() && (l
.preferred() < r
.preferred() ||
450 (l
.preferred() == r
.preferred() && (l
.ps() <= r
.ps()))));
452 inline bool operator==(const pg_t
& l
, const pg_t
& r
) {
453 return l
.pool() == r
.pool() &&
454 l
.preferred() == r
.preferred() &&
457 inline bool operator!=(const pg_t
& l
, const pg_t
& r
) {
458 return l
.pool() != r
.pool() ||
459 l
.preferred() != r
.preferred() ||
462 inline bool operator>(const pg_t
& l
, const pg_t
& r
) {
463 return l
.pool() > r
.pool() ||
464 (l
.pool() == r
.pool() && (l
.preferred() > r
.preferred() ||
465 (l
.preferred() == r
.preferred() && (l
.ps() > r
.ps()))));
467 inline bool operator>=(const pg_t
& l
, const pg_t
& r
) {
468 return l
.pool() > r
.pool() ||
469 (l
.pool() == r
.pool() && (l
.preferred() > r
.preferred() ||
470 (l
.preferred() == r
.preferred() && (l
.ps() >= r
.ps()))));
473 ostream
& operator<<(ostream
& out
, const pg_t
&pg
);
476 template<> struct hash
< pg_t
>
478 size_t operator()( const pg_t
& x
) const
480 static hash
<uint32_t> H
;
481 return H((x
.pool() & 0xffffffff) ^ (x
.pool() >> 32) ^ x
.ps() ^ x
.preferred());
489 spg_t() : shard(shard_id_t::NO_SHARD
) {}
490 spg_t(pg_t pgid
, shard_id_t shard
) : pgid(pgid
), shard(shard
) {}
491 explicit spg_t(pg_t pgid
) : pgid(pgid
), shard(shard_id_t::NO_SHARD
) {}
492 unsigned get_split_bits(unsigned pg_num
) const {
493 return pgid
.get_split_bits(pg_num
);
495 spg_t
get_parent() const {
496 return spg_t(pgid
.get_parent(), shard
);
501 uint64_t pool() const {
504 int32_t preferred() const {
505 return pgid
.preferred();
508 static const uint8_t calc_name_buf_size
= pg_t::calc_name_buf_size
+ 4; // 36 + len('s') + len("255");
509 char *calc_name(char *buf
, const char *suffix_backwords
) const;
511 bool parse(const char *s
);
512 bool parse(const std::string
& s
) {
513 return parse(s
.c_str());
515 bool is_split(unsigned old_pg_num
, unsigned new_pg_num
,
516 set
<spg_t
> *pchildren
) const {
518 set
<pg_t
> *children
= pchildren
? &_children
: NULL
;
519 bool is_split
= pgid
.is_split(old_pg_num
, new_pg_num
, children
);
520 if (pchildren
&& is_split
) {
521 for (set
<pg_t
>::iterator i
= _children
.begin();
522 i
!= _children
.end();
524 pchildren
->insert(spg_t(*i
, shard
));
529 bool is_no_shard() const {
530 return shard
== shard_id_t::NO_SHARD
;
533 ghobject_t
make_pgmeta_oid() const {
534 return ghobject_t::make_pgmeta(pgid
.pool(), pgid
.ps(), shard
);
537 void encode(bufferlist
&bl
) const {
538 ENCODE_START(1, 1, bl
);
543 void decode(bufferlist::iterator
&bl
) {
550 ghobject_t
make_temp_ghobject(const string
& name
) const {
552 hobject_t(object_t(name
), "", CEPH_NOSNAP
,
554 hobject_t::POOL_TEMP_START
- pgid
.pool(), ""),
559 unsigned hash_to_shard(unsigned num_shards
) const {
560 return ps() % num_shards
;
563 WRITE_CLASS_ENCODER(spg_t
)
564 WRITE_EQ_OPERATORS_2(spg_t
, pgid
, shard
)
565 WRITE_CMP_OPERATORS_2(spg_t
, pgid
, shard
)
568 template<> struct hash
< spg_t
>
570 size_t operator()( const spg_t
& x
) const
572 static hash
<uint32_t> H
;
573 return H(hash
<pg_t
>()(x
.pgid
) ^ x
.shard
);
578 ostream
& operator<<(ostream
& out
, const spg_t
&pg
);
580 // ----------------------
585 TYPE_LEGACY_TEMP
= 1, /* no longer used */
591 uint64_t removal_seq
; // note: deprecated, not encoded
593 char _str_buff
[spg_t::calc_name_buf_size
];
598 coll_t(type_t t
, spg_t p
, uint64_t r
)
599 : type(t
), pgid(p
), removal_seq(r
) {
604 coll_t() : type(TYPE_META
), removal_seq(0)
609 coll_t(const coll_t
& other
)
610 : type(other
.type
), pgid(other
.pgid
), removal_seq(other
.removal_seq
) {
614 explicit coll_t(spg_t pgid
)
615 : type(TYPE_PG
), pgid(pgid
), removal_seq(0)
620 coll_t
& operator=(const coll_t
& rhs
)
622 this->type
= rhs
.type
;
623 this->pgid
= rhs
.pgid
;
624 this->removal_seq
= rhs
.removal_seq
;
629 // named constructors
630 static coll_t
meta() {
633 static coll_t
pg(spg_t p
) {
637 const std::string
to_str() const {
640 const char *c_str() const {
644 bool parse(const std::string
& s
);
646 int operator<(const coll_t
&rhs
) const {
647 return type
< rhs
.type
||
648 (type
== rhs
.type
&& pgid
< rhs
.pgid
);
651 bool is_meta() const {
652 return type
== TYPE_META
;
654 bool is_pg_prefix(spg_t
*pgid_
) const {
655 if (type
== TYPE_PG
|| type
== TYPE_PG_TEMP
) {
662 return type
== TYPE_PG
;
664 bool is_pg(spg_t
*pgid_
) const {
665 if (type
== TYPE_PG
) {
671 bool is_temp() const {
672 return type
== TYPE_PG_TEMP
;
674 bool is_temp(spg_t
*pgid_
) const {
675 if (type
== TYPE_PG_TEMP
) {
682 void encode(bufferlist
& bl
) const;
683 void decode(bufferlist::iterator
& bl
);
684 size_t encoded_size() const;
686 inline bool operator==(const coll_t
& rhs
) const {
687 // only compare type if meta
688 if (type
!= rhs
.type
)
690 if (type
== TYPE_META
)
692 return type
== rhs
.type
&& pgid
== rhs
.pgid
;
694 inline bool operator!=(const coll_t
& rhs
) const {
695 return !(*this == rhs
);
698 // get a TEMP collection that corresponds to the current collection,
699 // which we presume is a pg collection.
700 coll_t
get_temp() const {
701 assert(type
== TYPE_PG
);
702 return coll_t(TYPE_PG_TEMP
, pgid
, 0);
705 ghobject_t
get_min_hobj() const {
709 o
.hobj
.pool
= pgid
.pool();
710 o
.set_shard(pgid
.shard
);
721 unsigned hash_to_shard(unsigned num_shards
) const {
723 return pgid
.hash_to_shard(num_shards
);
724 return 0; // whatever.
727 void dump(Formatter
*f
) const;
728 static void generate_test_instances(list
<coll_t
*>& o
);
731 WRITE_CLASS_ENCODER(coll_t
)
733 inline ostream
& operator<<(ostream
& out
, const coll_t
& c
) {
739 template<> struct hash
<coll_t
> {
740 size_t operator()(const coll_t
&c
) const {
742 string
str(c
.to_str());
743 std::string::const_iterator
end(str
.end());
744 for (std::string::const_iterator s
= str
.begin(); s
!= end
; ++s
) {
757 inline ostream
& operator<<(ostream
& out
, const ceph_object_layout
&ol
)
759 out
<< pg_t(ol
.ol_pgid
);
760 int su
= ol
.ol_stripe_unit
;
768 // compound rados version type
769 /* WARNING: If add member in eversion_t, please make sure the encode/decode function
770 * work well. For little-endian machine, we should make sure there is no padding
771 * in 32-bit machine and 64-bit machine.
778 eversion_t() : version(0), epoch(0), __pad(0) {}
779 eversion_t(epoch_t e
, version_t v
) : version(v
), epoch(e
), __pad(0) {}
781 // cppcheck-suppress noExplicitConstructor
782 eversion_t(const ceph_eversion
& ce
) :
787 explicit eversion_t(bufferlist
& bl
) : __pad(0) { decode(bl
); }
789 static eversion_t
max() {
796 operator ceph_eversion() {
803 string
get_key_name() const;
805 void encode(bufferlist
&bl
) const {
806 #if defined(CEPH_LITTLE_ENDIAN)
807 bl
.append((char *)this, sizeof(version_t
) + sizeof(epoch_t
));
809 ::encode(version
, bl
);
813 void decode(bufferlist::iterator
&bl
) {
814 #if defined(CEPH_LITTLE_ENDIAN)
815 bl
.copy(sizeof(version_t
) + sizeof(epoch_t
), (char *)this);
817 ::decode(version
, bl
);
821 void decode(bufferlist
& bl
) {
822 bufferlist::iterator p
= bl
.begin();
826 WRITE_CLASS_ENCODER(eversion_t
)
828 inline bool operator==(const eversion_t
& l
, const eversion_t
& r
) {
829 return (l
.epoch
== r
.epoch
) && (l
.version
== r
.version
);
831 inline bool operator!=(const eversion_t
& l
, const eversion_t
& r
) {
832 return (l
.epoch
!= r
.epoch
) || (l
.version
!= r
.version
);
834 inline bool operator<(const eversion_t
& l
, const eversion_t
& r
) {
835 return (l
.epoch
== r
.epoch
) ? (l
.version
< r
.version
):(l
.epoch
< r
.epoch
);
837 inline bool operator<=(const eversion_t
& l
, const eversion_t
& r
) {
838 return (l
.epoch
== r
.epoch
) ? (l
.version
<= r
.version
):(l
.epoch
<= r
.epoch
);
840 inline bool operator>(const eversion_t
& l
, const eversion_t
& r
) {
841 return (l
.epoch
== r
.epoch
) ? (l
.version
> r
.version
):(l
.epoch
> r
.epoch
);
843 inline bool operator>=(const eversion_t
& l
, const eversion_t
& r
) {
844 return (l
.epoch
== r
.epoch
) ? (l
.version
>= r
.version
):(l
.epoch
>= r
.epoch
);
846 inline ostream
& operator<<(ostream
& out
, const eversion_t
& e
) {
847 return out
<< e
.epoch
<< "'" << e
.version
;
851 * objectstore_perf_stat_t
853 * current perf information about the osd
855 struct objectstore_perf_stat_t
{
856 // cur_op_latency is in ms since double add/sub are not associative
857 uint32_t os_commit_latency
;
858 uint32_t os_apply_latency
;
860 objectstore_perf_stat_t() :
861 os_commit_latency(0), os_apply_latency(0) {}
863 bool operator==(const objectstore_perf_stat_t
&r
) const {
864 return os_commit_latency
== r
.os_commit_latency
&&
865 os_apply_latency
== r
.os_apply_latency
;
868 void add(const objectstore_perf_stat_t
&o
) {
869 os_commit_latency
+= o
.os_commit_latency
;
870 os_apply_latency
+= o
.os_apply_latency
;
872 void sub(const objectstore_perf_stat_t
&o
) {
873 os_commit_latency
-= o
.os_commit_latency
;
874 os_apply_latency
-= o
.os_apply_latency
;
876 void dump(Formatter
*f
) const;
877 void encode(bufferlist
&bl
) const;
878 void decode(bufferlist::iterator
&bl
);
879 static void generate_test_instances(std::list
<objectstore_perf_stat_t
*>& o
);
881 WRITE_CLASS_ENCODER(objectstore_perf_stat_t
)
884 * aggregate stats for an osd
887 int64_t kb
, kb_used
, kb_avail
;
888 vector
<int> hb_peers
;
889 int32_t snap_trim_queue_len
, num_snap_trimming
;
891 pow2_hist_t op_queue_age_hist
;
893 objectstore_perf_stat_t os_perf_stat
;
898 osd_stat_t() : kb(0), kb_used(0), kb_avail(0),
899 snap_trim_queue_len(0), num_snap_trimming(0) {}
901 void add(const osd_stat_t
& o
) {
903 kb_used
+= o
.kb_used
;
904 kb_avail
+= o
.kb_avail
;
905 snap_trim_queue_len
+= o
.snap_trim_queue_len
;
906 num_snap_trimming
+= o
.num_snap_trimming
;
907 op_queue_age_hist
.add(o
.op_queue_age_hist
);
908 os_perf_stat
.add(o
.os_perf_stat
);
910 void sub(const osd_stat_t
& o
) {
912 kb_used
-= o
.kb_used
;
913 kb_avail
-= o
.kb_avail
;
914 snap_trim_queue_len
-= o
.snap_trim_queue_len
;
915 num_snap_trimming
-= o
.num_snap_trimming
;
916 op_queue_age_hist
.sub(o
.op_queue_age_hist
);
917 os_perf_stat
.sub(o
.os_perf_stat
);
920 void dump(Formatter
*f
) const;
921 void encode(bufferlist
&bl
) const;
922 void decode(bufferlist::iterator
&bl
);
923 static void generate_test_instances(std::list
<osd_stat_t
*>& o
);
925 WRITE_CLASS_ENCODER(osd_stat_t
)
927 inline bool operator==(const osd_stat_t
& l
, const osd_stat_t
& r
) {
928 return l
.kb
== r
.kb
&&
929 l
.kb_used
== r
.kb_used
&&
930 l
.kb_avail
== r
.kb_avail
&&
931 l
.snap_trim_queue_len
== r
.snap_trim_queue_len
&&
932 l
.num_snap_trimming
== r
.num_snap_trimming
&&
933 l
.hb_peers
== r
.hb_peers
&&
934 l
.op_queue_age_hist
== r
.op_queue_age_hist
&&
935 l
.os_perf_stat
== r
.os_perf_stat
;
937 inline bool operator!=(const osd_stat_t
& l
, const osd_stat_t
& r
) {
943 inline ostream
& operator<<(ostream
& out
, const osd_stat_t
& s
) {
944 return out
<< "osd_stat(" << kb_t(s
.kb_used
) << " used, "
945 << kb_t(s
.kb_avail
) << " avail, "
946 << kb_t(s
.kb
) << " total, "
947 << "peers " << s
.hb_peers
948 << " op hist " << s
.op_queue_age_hist
.h
956 #define PG_STATE_CREATING (1<<0) // creating
957 #define PG_STATE_ACTIVE (1<<1) // i am active. (primary: replicas too)
958 #define PG_STATE_CLEAN (1<<2) // peers are complete, clean of stray replicas.
959 #define PG_STATE_DOWN (1<<4) // a needed replica is down, PG offline
960 //#define PG_STATE_REPLAY (1<<5) // crashed, waiting for replay
961 //#define PG_STATE_STRAY (1<<6) // i must notify the primary i exist.
962 //#define PG_STATE_SPLITTING (1<<7) // i am splitting
963 #define PG_STATE_SCRUBBING (1<<8) // scrubbing
964 //#define PG_STATE_SCRUBQ (1<<9) // queued for scrub
965 #define PG_STATE_DEGRADED (1<<10) // pg contains objects with reduced redundancy
966 #define PG_STATE_INCONSISTENT (1<<11) // pg replicas are inconsistent (but shouldn't be)
967 #define PG_STATE_PEERING (1<<12) // pg is (re)peering
968 #define PG_STATE_REPAIR (1<<13) // pg should repair on next scrub
969 #define PG_STATE_RECOVERING (1<<14) // pg is recovering/migrating objects
970 #define PG_STATE_BACKFILL_WAIT (1<<15) // [active] reserving backfill
971 #define PG_STATE_INCOMPLETE (1<<16) // incomplete content, peering failed.
972 #define PG_STATE_STALE (1<<17) // our state for this pg is stale, unknown.
973 #define PG_STATE_REMAPPED (1<<18) // pg is explicitly remapped to different OSDs than CRUSH
974 #define PG_STATE_DEEP_SCRUB (1<<19) // deep scrub: check CRC32 on files
975 #define PG_STATE_BACKFILL (1<<20) // [active] backfilling pg content
976 #define PG_STATE_BACKFILL_TOOFULL (1<<21) // backfill can't proceed: too full
977 #define PG_STATE_RECOVERY_WAIT (1<<22) // waiting for recovery reservations
978 #define PG_STATE_UNDERSIZED (1<<23) // pg acting < pool size
979 #define PG_STATE_ACTIVATING (1<<24) // pg is peered but not yet active
980 #define PG_STATE_PEERED (1<<25) // peered, cannot go active, can recover
981 #define PG_STATE_SNAPTRIM (1<<26) // trimming snaps
982 #define PG_STATE_SNAPTRIM_WAIT (1<<27) // queued to trim snaps
983 #define PG_STATE_RECOVERY_TOOFULL (1<<28) // recovery can't proceed: too full
984 #define PG_STATE_SNAPTRIM_ERROR (1<<29) // error stopped trimming snaps
986 std::string
pg_state_string(int state
);
987 std::string
pg_vector_string(const vector
<int32_t> &a
);
988 int pg_string_state(const std::string
& state
);
994 * attributes for a single pool snapshot.
996 struct pool_snap_info_t
{
1001 void dump(Formatter
*f
) const;
1002 void encode(bufferlist
& bl
, uint64_t features
) const;
1003 void decode(bufferlist::iterator
& bl
);
1004 static void generate_test_instances(list
<pool_snap_info_t
*>& o
);
1006 WRITE_CLASS_ENCODER_FEATURES(pool_snap_info_t
)
1008 inline ostream
& operator<<(ostream
& out
, const pool_snap_info_t
& si
) {
1009 return out
<< si
.snapid
<< '(' << si
.name
<< ' ' << si
.stamp
<< ')';
1024 DEEP_SCRUB_INTERVAL
,
1026 RECOVERY_OP_PRIORITY
,
1029 COMPRESSION_ALGORITHM
,
1030 COMPRESSION_REQUIRED_RATIO
,
1031 COMPRESSION_MAX_BLOB_SIZE
,
1032 COMPRESSION_MIN_BLOB_SIZE
,
1048 opt_desc_t(key_t k
, type_t t
) : key(k
), type(t
) {}
1050 bool operator==(const opt_desc_t
& rhs
) const {
1051 return key
== rhs
.key
&& type
== rhs
.type
;
1055 typedef boost::variant
<std::string
,int,double> value_t
;
1057 static bool is_opt_name(const std::string
& name
);
1058 static opt_desc_t
get_opt_desc(const std::string
& name
);
1060 pool_opts_t() : opts() {}
1062 bool is_set(key_t key
) const;
1064 template<typename T
>
1065 void set(key_t key
, const T
&val
) {
1066 value_t value
= val
;
1070 template<typename T
>
1071 bool get(key_t key
, T
*val
) const {
1072 opts_t::const_iterator i
= opts
.find(key
);
1073 if (i
== opts
.end()) {
1076 *val
= boost::get
<T
>(i
->second
);
1080 const value_t
& get(key_t key
) const;
1082 bool unset(key_t key
);
1084 void dump(const std::string
& name
, Formatter
*f
) const;
1086 void dump(Formatter
*f
) const;
1087 void encode(bufferlist
&bl
) const;
1088 void decode(bufferlist::iterator
&bl
);
1091 typedef std::map
<key_t
, value_t
> opts_t
;
1094 friend ostream
& operator<<(ostream
& out
, const pool_opts_t
& opts
);
1096 WRITE_CLASS_ENCODER(pool_opts_t
)
1103 TYPE_REPLICATED
= 1, // replication
1104 //TYPE_RAID4 = 2, // raid4 (never implemented)
1105 TYPE_ERASURE
= 3, // erasure-coded
1107 static const char *get_type_name(int t
) {
1109 case TYPE_REPLICATED
: return "replicated";
1110 //case TYPE_RAID4: return "raid4";
1111 case TYPE_ERASURE
: return "erasure";
1112 default: return "???";
1115 const char *get_type_name() const {
1116 return get_type_name(type
);
1120 FLAG_HASHPSPOOL
= 1<<0, // hash pg seed and pool together (instead of adding)
1121 FLAG_FULL
= 1<<1, // pool is full
1122 FLAG_EC_OVERWRITES
= 1<<2, // enables overwrites, once enabled, cannot be disabled
1123 FLAG_INCOMPLETE_CLONES
= 1<<3, // may have incomplete clones (bc we are/were an overlay)
1124 FLAG_NODELETE
= 1<<4, // pool can't be deleted
1125 FLAG_NOPGCHANGE
= 1<<5, // pool's pg and pgp num can't be changed
1126 FLAG_NOSIZECHANGE
= 1<<6, // pool's size and min size can't be changed
1127 FLAG_WRITE_FADVISE_DONTNEED
= 1<<7, // write mode with LIBRADOS_OP_FLAG_FADVISE_DONTNEED
1128 FLAG_NOSCRUB
= 1<<8, // block periodic scrub
1129 FLAG_NODEEP_SCRUB
= 1<<9, // block periodic deep-scrub
1132 static const char *get_flag_name(int f
) {
1134 case FLAG_HASHPSPOOL
: return "hashpspool";
1135 case FLAG_FULL
: return "full";
1136 case FLAG_EC_OVERWRITES
: return "ec_overwrites";
1137 case FLAG_INCOMPLETE_CLONES
: return "incomplete_clones";
1138 case FLAG_NODELETE
: return "nodelete";
1139 case FLAG_NOPGCHANGE
: return "nopgchange";
1140 case FLAG_NOSIZECHANGE
: return "nosizechange";
1141 case FLAG_WRITE_FADVISE_DONTNEED
: return "write_fadvise_dontneed";
1142 case FLAG_NOSCRUB
: return "noscrub";
1143 case FLAG_NODEEP_SCRUB
: return "nodeep-scrub";
1144 default: return "???";
1147 static string
get_flags_string(uint64_t f
) {
1149 for (unsigned n
=0; f
&& n
<64; ++n
) {
1150 if (f
& (1ull << n
)) {
1153 s
+= get_flag_name(1ull << n
);
1158 string
get_flags_string() const {
1159 return get_flags_string(flags
);
1161 static uint64_t get_flag_by_name(const string
& name
) {
1162 if (name
== "hashpspool")
1163 return FLAG_HASHPSPOOL
;
1166 if (name
== "ec_overwrites")
1167 return FLAG_EC_OVERWRITES
;
1168 if (name
== "incomplete_clones")
1169 return FLAG_INCOMPLETE_CLONES
;
1170 if (name
== "nodelete")
1171 return FLAG_NODELETE
;
1172 if (name
== "nopgchange")
1173 return FLAG_NOPGCHANGE
;
1174 if (name
== "nosizechange")
1175 return FLAG_NOSIZECHANGE
;
1176 if (name
== "write_fadvise_dontneed")
1177 return FLAG_WRITE_FADVISE_DONTNEED
;
1178 if (name
== "noscrub")
1179 return FLAG_NOSCRUB
;
1180 if (name
== "nodeep-scrub")
1181 return FLAG_NODEEP_SCRUB
;
1185 /// converts the acting/up vector to a set of pg shards
1186 void convert_to_pg_shards(const vector
<int> &from
, set
<pg_shard_t
>* to
) const;
1189 CACHEMODE_NONE
= 0, ///< no caching
1190 CACHEMODE_WRITEBACK
= 1, ///< write to cache, flush later
1191 CACHEMODE_FORWARD
= 2, ///< forward if not in cache
1192 CACHEMODE_READONLY
= 3, ///< handle reads, forward writes [not strongly consistent]
1193 CACHEMODE_READFORWARD
= 4, ///< forward reads, write to cache flush later
1194 CACHEMODE_READPROXY
= 5, ///< proxy reads, write to cache flush later
1195 CACHEMODE_PROXY
= 6, ///< proxy if not in cache
1197 static const char *get_cache_mode_name(cache_mode_t m
) {
1199 case CACHEMODE_NONE
: return "none";
1200 case CACHEMODE_WRITEBACK
: return "writeback";
1201 case CACHEMODE_FORWARD
: return "forward";
1202 case CACHEMODE_READONLY
: return "readonly";
1203 case CACHEMODE_READFORWARD
: return "readforward";
1204 case CACHEMODE_READPROXY
: return "readproxy";
1205 case CACHEMODE_PROXY
: return "proxy";
1206 default: return "unknown";
1209 static cache_mode_t
get_cache_mode_from_str(const string
& s
) {
1211 return CACHEMODE_NONE
;
1212 if (s
== "writeback")
1213 return CACHEMODE_WRITEBACK
;
1215 return CACHEMODE_FORWARD
;
1216 if (s
== "readonly")
1217 return CACHEMODE_READONLY
;
1218 if (s
== "readforward")
1219 return CACHEMODE_READFORWARD
;
1220 if (s
== "readproxy")
1221 return CACHEMODE_READPROXY
;
1223 return CACHEMODE_PROXY
;
1224 return (cache_mode_t
)-1;
1226 const char *get_cache_mode_name() const {
1227 return get_cache_mode_name(cache_mode
);
1229 bool cache_mode_requires_hit_set() const {
1230 switch (cache_mode
) {
1231 case CACHEMODE_NONE
:
1232 case CACHEMODE_FORWARD
:
1233 case CACHEMODE_READONLY
:
1234 case CACHEMODE_PROXY
:
1236 case CACHEMODE_WRITEBACK
:
1237 case CACHEMODE_READFORWARD
:
1238 case CACHEMODE_READPROXY
:
1241 assert(0 == "implement me");
1245 uint64_t flags
; ///< FLAG_*
1246 __u8 type
; ///< TYPE_*
1247 __u8 size
, min_size
; ///< number of osds in each pg
1248 __u8 crush_rule
; ///< crush placement rule
1249 __u8 object_hash
; ///< hash mapping object name to ps
1251 __u32 pg_num
, pgp_num
; ///< number of pgs
1255 map
<string
,string
> properties
; ///< OBSOLETE
1256 string erasure_code_profile
; ///< name of the erasure code profile in OSDMap
1257 epoch_t last_change
; ///< most recent epoch changed, exclusing snapshot changes
1258 epoch_t last_force_op_resend
; ///< last epoch that forced clients to resend
1259 /// last epoch that forced clients to resend (pre-luminous clients only)
1260 epoch_t last_force_op_resend_preluminous
;
1261 snapid_t snap_seq
; ///< seq for per-pool snapshot
1262 epoch_t snap_epoch
; ///< osdmap epoch of last snap
1263 uint64_t auid
; ///< who owns the pg
1264 __u32 crash_replay_interval
; ///< seconds to allow clients to replay ACKed but unCOMMITted requests
1266 uint64_t quota_max_bytes
; ///< maximum number of bytes for this pool
1267 uint64_t quota_max_objects
; ///< maximum number of objects for this pool
1270 * Pool snaps (global to this pool). These define a SnapContext for
1271 * the pool, unless the client manually specifies an alternate
1274 map
<snapid_t
, pool_snap_info_t
> snaps
;
1276 * Alternatively, if we are defining non-pool snaps (e.g. via the
1277 * Ceph MDS), we must track @removed_snaps (since @snaps is not
1278 * used). Snaps and removed_snaps are to be used exclusive of each
1281 interval_set
<snapid_t
> removed_snaps
;
1283 unsigned pg_num_mask
, pgp_num_mask
;
1285 set
<uint64_t> tiers
; ///< pools that are tiers of us
1286 int64_t tier_of
; ///< pool for which we are a tier
1287 // Note that write wins for read+write ops
1288 int64_t read_tier
; ///< pool/tier for objecter to direct reads to
1289 int64_t write_tier
; ///< pool/tier for objecter to direct writes to
1290 cache_mode_t cache_mode
; ///< cache pool mode
1292 bool is_tier() const { return tier_of
>= 0; }
1293 bool has_tiers() const { return !tiers
.empty(); }
1298 clear_tier_tunables();
1300 bool has_read_tier() const { return read_tier
>= 0; }
1301 void clear_read_tier() { read_tier
= -1; }
1302 bool has_write_tier() const { return write_tier
>= 0; }
1303 void clear_write_tier() { write_tier
= -1; }
1304 void clear_tier_tunables() {
1305 if (cache_mode
!= CACHEMODE_NONE
)
1306 flags
|= FLAG_INCOMPLETE_CLONES
;
1307 cache_mode
= CACHEMODE_NONE
;
1309 target_max_bytes
= 0;
1310 target_max_objects
= 0;
1311 cache_target_dirty_ratio_micro
= 0;
1312 cache_target_dirty_high_ratio_micro
= 0;
1313 cache_target_full_ratio_micro
= 0;
1314 hit_set_params
= HitSet::Params();
1317 hit_set_grade_decay_rate
= 0;
1318 hit_set_search_last_n
= 0;
1319 grade_table
.resize(0);
1322 uint64_t target_max_bytes
; ///< tiering: target max pool size
1323 uint64_t target_max_objects
; ///< tiering: target max pool size
1325 uint32_t cache_target_dirty_ratio_micro
; ///< cache: fraction of target to leave dirty
1326 uint32_t cache_target_dirty_high_ratio_micro
; ///<cache: fraction of target to flush with high speed
1327 uint32_t cache_target_full_ratio_micro
; ///< cache: fraction of target to fill before we evict in earnest
1329 uint32_t cache_min_flush_age
; ///< minimum age (seconds) before we can flush
1330 uint32_t cache_min_evict_age
; ///< minimum age (seconds) before we can evict
1332 HitSet::Params hit_set_params
; ///< The HitSet params to use on this pool
1333 uint32_t hit_set_period
; ///< periodicity of HitSet segments (seconds)
1334 uint32_t hit_set_count
; ///< number of periods to retain
1335 bool use_gmt_hitset
; ///< use gmt to name the hitset archive object
1336 uint32_t min_read_recency_for_promote
; ///< minimum number of HitSet to check before promote on read
1337 uint32_t min_write_recency_for_promote
; ///< minimum number of HitSet to check before promote on write
1338 uint32_t hit_set_grade_decay_rate
; ///< current hit_set has highest priority on objects
1339 ///temperature count,the follow hit_set's priority decay
1340 ///by this params than pre hit_set
1341 uint32_t hit_set_search_last_n
; ///<accumulate atmost N hit_sets for temperature
1343 uint32_t stripe_width
; ///< erasure coded stripe size in bytes
1345 uint64_t expected_num_objects
; ///< expected number of objects on this pool, a value of 0 indicates
1346 ///< user does not specify any expected value
1347 bool fast_read
; ///< whether turn on fast read on the pool or not
1349 pool_opts_t opts
; ///< options
1352 vector
<uint32_t> grade_table
;
1355 uint32_t get_grade(unsigned i
) const {
1356 if (grade_table
.size() <= i
)
1358 return grade_table
[i
];
1360 void calc_grade_table() {
1361 unsigned v
= 1000000;
1362 grade_table
.resize(hit_set_count
);
1363 for (unsigned i
= 0; i
< hit_set_count
; i
++) {
1364 v
= v
* (1 - (hit_set_grade_decay_rate
/ 100.0));
1370 : flags(0), type(0), size(0), min_size(0),
1371 crush_rule(0), object_hash(0),
1372 pg_num(0), pgp_num(0),
1374 last_force_op_resend(0),
1375 last_force_op_resend_preluminous(0),
1376 snap_seq(0), snap_epoch(0),
1378 crash_replay_interval(0),
1379 quota_max_bytes(0), quota_max_objects(0),
1380 pg_num_mask(0), pgp_num_mask(0),
1381 tier_of(-1), read_tier(-1), write_tier(-1),
1382 cache_mode(CACHEMODE_NONE
),
1383 target_max_bytes(0), target_max_objects(0),
1384 cache_target_dirty_ratio_micro(0),
1385 cache_target_dirty_high_ratio_micro(0),
1386 cache_target_full_ratio_micro(0),
1387 cache_min_flush_age(0),
1388 cache_min_evict_age(0),
1392 use_gmt_hitset(true),
1393 min_read_recency_for_promote(0),
1394 min_write_recency_for_promote(0),
1395 hit_set_grade_decay_rate(0),
1396 hit_set_search_last_n(0),
1398 expected_num_objects(0),
1403 void dump(Formatter
*f
) const;
1405 uint64_t get_flags() const { return flags
; }
1406 bool has_flag(uint64_t f
) const { return flags
& f
; }
1407 void set_flag(uint64_t f
) { flags
|= f
; }
1408 void unset_flag(uint64_t f
) { flags
&= ~f
; }
1410 bool ec_pool() const {
1411 return type
== TYPE_ERASURE
;
1413 bool require_rollback() const {
1417 /// true if incomplete clones may be present
1418 bool allow_incomplete_clones() const {
1419 return cache_mode
!= CACHEMODE_NONE
|| has_flag(FLAG_INCOMPLETE_CLONES
);
1422 unsigned get_type() const { return type
; }
1423 unsigned get_size() const { return size
; }
1424 unsigned get_min_size() const { return min_size
; }
1425 int get_crush_rule() const { return crush_rule
; }
1426 int get_object_hash() const { return object_hash
; }
1427 const char *get_object_hash_name() const {
1428 return ceph_str_hash_name(get_object_hash());
1430 epoch_t
get_last_change() const { return last_change
; }
1431 epoch_t
get_last_force_op_resend() const { return last_force_op_resend
; }
1432 epoch_t
get_last_force_op_resend_preluminous() const {
1433 return last_force_op_resend_preluminous
;
1435 epoch_t
get_snap_epoch() const { return snap_epoch
; }
1436 snapid_t
get_snap_seq() const { return snap_seq
; }
1437 uint64_t get_auid() const { return auid
; }
1438 unsigned get_crash_replay_interval() const { return crash_replay_interval
; }
1440 void set_snap_seq(snapid_t s
) { snap_seq
= s
; }
1441 void set_snap_epoch(epoch_t e
) { snap_epoch
= e
; }
1443 void set_stripe_width(uint32_t s
) { stripe_width
= s
; }
1444 uint32_t get_stripe_width() const { return stripe_width
; }
1446 bool is_replicated() const { return get_type() == TYPE_REPLICATED
; }
1447 bool is_erasure() const { return get_type() == TYPE_ERASURE
; }
1449 bool supports_omap() const {
1450 return !(get_type() == TYPE_ERASURE
);
1453 bool requires_aligned_append() const {
1454 return is_erasure() && !has_flag(FLAG_EC_OVERWRITES
);
1456 uint64_t required_alignment() const { return stripe_width
; }
1458 bool allows_ecoverwrites() const {
1459 return has_flag(FLAG_EC_OVERWRITES
);
1462 bool can_shift_osds() const {
1463 switch (get_type()) {
1464 case TYPE_REPLICATED
:
1469 assert(0 == "unhandled pool type");
1473 unsigned get_pg_num() const { return pg_num
; }
1474 unsigned get_pgp_num() const { return pgp_num
; }
1476 unsigned get_pg_num_mask() const { return pg_num_mask
; }
1477 unsigned get_pgp_num_mask() const { return pgp_num_mask
; }
1479 // if pg_num is not a multiple of two, pgs are not equally sized.
1480 // return, for a given pg, the fraction (denominator) of the total
1481 // pool size that it represents.
1482 unsigned get_pg_num_divisor(pg_t pgid
) const;
1484 void set_pg_num(int p
) {
1488 void set_pgp_num(int p
) {
1493 void set_quota_max_bytes(uint64_t m
) {
1494 quota_max_bytes
= m
;
1496 uint64_t get_quota_max_bytes() {
1497 return quota_max_bytes
;
1500 void set_quota_max_objects(uint64_t m
) {
1501 quota_max_objects
= m
;
1503 uint64_t get_quota_max_objects() {
1504 return quota_max_objects
;
1507 void set_last_force_op_resend(uint64_t t
) {
1508 last_force_op_resend
= t
;
1509 last_force_op_resend_preluminous
= t
;
1512 void calc_pg_masks();
1515 * we have two snap modes:
1516 * - pool global snaps
1517 * - snap existence/non-existence defined by snaps[] and snap_seq
1518 * - user managed snaps
1519 * - removal governed by removed_snaps
1521 * we know which mode we're using based on whether removed_snaps is empty.
1522 * If nothing has been created, both functions report false.
1524 bool is_pool_snaps_mode() const;
1525 bool is_unmanaged_snaps_mode() const;
1526 bool is_removed_snap(snapid_t s
) const;
1529 * build set of known-removed sets from either pool snaps or
1530 * explicit removed_snaps set.
1532 void build_removed_snaps(interval_set
<snapid_t
>& rs
) const;
1533 snapid_t
snap_exists(const char *s
) const;
1534 void add_snap(const char *n
, utime_t stamp
);
1535 void add_unmanaged_snap(uint64_t& snapid
);
1536 void remove_snap(snapid_t s
);
1537 void remove_unmanaged_snap(snapid_t s
);
1539 SnapContext
get_snap_context() const;
1541 /// hash a object name+namespace key to a hash position
1542 uint32_t hash_key(const string
& key
, const string
& ns
) const;
1544 /// round a hash position down to a pg num
1545 uint32_t raw_hash_to_pg(uint32_t v
) const;
1548 * map a raw pg (with full precision ps) into an actual pg, for storage
1550 pg_t
raw_pg_to_pg(pg_t pg
) const;
1553 * map raw pg (full precision ps) into a placement seed. include
1554 * pool id in that value so that different pools don't use the same
1557 ps_t
raw_pg_to_pps(pg_t pg
) const;
1559 /// choose a random hash position within a pg
1560 uint32_t get_random_pg_position(pg_t pgid
, uint32_t seed
) const;
1562 void encode(bufferlist
& bl
, uint64_t features
) const;
1563 void decode(bufferlist::iterator
& bl
);
1565 static void generate_test_instances(list
<pg_pool_t
*>& o
);
1567 WRITE_CLASS_ENCODER_FEATURES(pg_pool_t
)
1569 ostream
& operator<<(ostream
& out
, const pg_pool_t
& p
);
1573 * a summation of object stats
1575 * This is just a container for object stats; we don't know what for.
1577 * If you add members in object_stat_sum_t, you should make sure there are
1578 * not padding among these members.
1579 * You should also modify the padding_check function.
1582 struct object_stat_sum_t
{
1583 /**************************************************************************
1584 * WARNING: be sure to update operator==, floor, and split when
1585 * adding/removing fields!
1586 **************************************************************************/
1587 int64_t num_bytes
; // in bytes
1588 int64_t num_objects
;
1589 int64_t num_object_clones
;
1590 int64_t num_object_copies
; // num_objects * num_replicas
1591 int64_t num_objects_missing_on_primary
;
1592 int64_t num_objects_degraded
;
1593 int64_t num_objects_unfound
;
1598 int64_t num_scrub_errors
; // total deep and shallow scrub errors
1599 int64_t num_objects_recovered
;
1600 int64_t num_bytes_recovered
;
1601 int64_t num_keys_recovered
;
1602 int64_t num_shallow_scrub_errors
;
1603 int64_t num_deep_scrub_errors
;
1604 int64_t num_objects_dirty
;
1605 int64_t num_whiteouts
;
1606 int64_t num_objects_omap
;
1607 int64_t num_objects_hit_set_archive
;
1608 int64_t num_objects_misplaced
;
1609 int64_t num_bytes_hit_set_archive
;
1611 int64_t num_flush_kb
;
1613 int64_t num_evict_kb
;
1614 int64_t num_promote
;
1615 int32_t num_flush_mode_high
; // 1 when in high flush mode, otherwise 0
1616 int32_t num_flush_mode_low
; // 1 when in low flush mode, otherwise 0
1617 int32_t num_evict_mode_some
; // 1 when in evict some mode, otherwise 0
1618 int32_t num_evict_mode_full
; // 1 when in evict full mode, otherwise 0
1619 int64_t num_objects_pinned
;
1620 int64_t num_objects_missing
;
1621 int64_t num_legacy_snapsets
; ///< upper bound on pre-luminous-style SnapSets
1625 num_objects(0), num_object_clones(0), num_object_copies(0),
1626 num_objects_missing_on_primary(0), num_objects_degraded(0),
1627 num_objects_unfound(0),
1628 num_rd(0), num_rd_kb(0), num_wr(0), num_wr_kb(0),
1629 num_scrub_errors(0),
1630 num_objects_recovered(0),
1631 num_bytes_recovered(0),
1632 num_keys_recovered(0),
1633 num_shallow_scrub_errors(0),
1634 num_deep_scrub_errors(0),
1635 num_objects_dirty(0),
1637 num_objects_omap(0),
1638 num_objects_hit_set_archive(0),
1639 num_objects_misplaced(0),
1640 num_bytes_hit_set_archive(0),
1646 num_flush_mode_high(0), num_flush_mode_low(0),
1647 num_evict_mode_some(0), num_evict_mode_full(0),
1648 num_objects_pinned(0),
1649 num_objects_missing(0),
1650 num_legacy_snapsets(0)
1653 void floor(int64_t f
) {
1654 #define FLOOR(x) if (x < f) x = f
1657 FLOOR(num_object_clones
);
1658 FLOOR(num_object_copies
);
1659 FLOOR(num_objects_missing_on_primary
);
1660 FLOOR(num_objects_missing
);
1661 FLOOR(num_objects_degraded
);
1662 FLOOR(num_objects_misplaced
);
1663 FLOOR(num_objects_unfound
);
1668 FLOOR(num_scrub_errors
);
1669 FLOOR(num_shallow_scrub_errors
);
1670 FLOOR(num_deep_scrub_errors
);
1671 FLOOR(num_objects_recovered
);
1672 FLOOR(num_bytes_recovered
);
1673 FLOOR(num_keys_recovered
);
1674 FLOOR(num_objects_dirty
);
1675 FLOOR(num_whiteouts
);
1676 FLOOR(num_objects_omap
);
1677 FLOOR(num_objects_hit_set_archive
);
1678 FLOOR(num_bytes_hit_set_archive
);
1680 FLOOR(num_flush_kb
);
1682 FLOOR(num_evict_kb
);
1684 FLOOR(num_flush_mode_high
);
1685 FLOOR(num_flush_mode_low
);
1686 FLOOR(num_evict_mode_some
);
1687 FLOOR(num_evict_mode_full
);
1688 FLOOR(num_objects_pinned
);
1689 FLOOR(num_legacy_snapsets
);
1693 void split(vector
<object_stat_sum_t
> &out
) const {
1694 #define SPLIT(PARAM) \
1695 for (unsigned i = 0; i < out.size(); ++i) { \
1696 out[i].PARAM = PARAM / out.size(); \
1697 if (i < (PARAM % out.size())) { \
1701 #define SPLIT_PRESERVE_NONZERO(PARAM) \
1702 for (unsigned i = 0; i < out.size(); ++i) { \
1704 out[i].PARAM = 1 + PARAM / out.size(); \
1711 SPLIT(num_object_clones
);
1712 SPLIT(num_object_copies
);
1713 SPLIT(num_objects_missing_on_primary
);
1714 SPLIT(num_objects_missing
);
1715 SPLIT(num_objects_degraded
);
1716 SPLIT(num_objects_misplaced
);
1717 SPLIT(num_objects_unfound
);
1722 SPLIT(num_scrub_errors
);
1723 SPLIT(num_shallow_scrub_errors
);
1724 SPLIT(num_deep_scrub_errors
);
1725 SPLIT(num_objects_recovered
);
1726 SPLIT(num_bytes_recovered
);
1727 SPLIT(num_keys_recovered
);
1728 SPLIT(num_objects_dirty
);
1729 SPLIT(num_whiteouts
);
1730 SPLIT(num_objects_omap
);
1731 SPLIT(num_objects_hit_set_archive
);
1732 SPLIT(num_bytes_hit_set_archive
);
1734 SPLIT(num_flush_kb
);
1736 SPLIT(num_evict_kb
);
1738 SPLIT(num_flush_mode_high
);
1739 SPLIT(num_flush_mode_low
);
1740 SPLIT(num_evict_mode_some
);
1741 SPLIT(num_evict_mode_full
);
1742 SPLIT(num_objects_pinned
);
1743 SPLIT_PRESERVE_NONZERO(num_legacy_snapsets
);
1745 #undef SPLIT_PRESERVE_NONZERO
1749 memset(this, 0, sizeof(*this));
1752 void calc_copies(int nrep
) {
1753 num_object_copies
= nrep
* num_objects
;
1756 bool is_zero() const {
1757 return mem_is_zero((char*)this, sizeof(*this));
1760 void add(const object_stat_sum_t
& o
);
1761 void sub(const object_stat_sum_t
& o
);
1763 void dump(Formatter
*f
) const;
1764 void padding_check() {
1766 sizeof(object_stat_sum_t
) ==
1768 sizeof(num_objects
) +
1769 sizeof(num_object_clones
) +
1770 sizeof(num_object_copies
) +
1771 sizeof(num_objects_missing_on_primary
) +
1772 sizeof(num_objects_degraded
) +
1773 sizeof(num_objects_unfound
) +
1778 sizeof(num_scrub_errors
) +
1779 sizeof(num_objects_recovered
) +
1780 sizeof(num_bytes_recovered
) +
1781 sizeof(num_keys_recovered
) +
1782 sizeof(num_shallow_scrub_errors
) +
1783 sizeof(num_deep_scrub_errors
) +
1784 sizeof(num_objects_dirty
) +
1785 sizeof(num_whiteouts
) +
1786 sizeof(num_objects_omap
) +
1787 sizeof(num_objects_hit_set_archive
) +
1788 sizeof(num_objects_misplaced
) +
1789 sizeof(num_bytes_hit_set_archive
) +
1791 sizeof(num_flush_kb
) +
1793 sizeof(num_evict_kb
) +
1794 sizeof(num_promote
) +
1795 sizeof(num_flush_mode_high
) +
1796 sizeof(num_flush_mode_low
) +
1797 sizeof(num_evict_mode_some
) +
1798 sizeof(num_evict_mode_full
) +
1799 sizeof(num_objects_pinned
) +
1800 sizeof(num_objects_missing
) +
1801 sizeof(num_legacy_snapsets
)
1803 "object_stat_sum_t have padding");
1805 void encode(bufferlist
& bl
) const;
1806 void decode(bufferlist::iterator
& bl
);
1807 static void generate_test_instances(list
<object_stat_sum_t
*>& o
);
1809 WRITE_CLASS_ENCODER(object_stat_sum_t
)
1811 bool operator==(const object_stat_sum_t
& l
, const object_stat_sum_t
& r
);
1814 * a collection of object stat sums
1816 * This is a collection of stat sums over different categories.
1818 struct object_stat_collection_t
{
1819 /**************************************************************************
1820 * WARNING: be sure to update the operator== when adding/removing fields! *
1821 **************************************************************************/
1822 object_stat_sum_t sum
;
1824 void calc_copies(int nrep
) {
1825 sum
.calc_copies(nrep
);
1828 void dump(Formatter
*f
) const;
1829 void encode(bufferlist
& bl
) const;
1830 void decode(bufferlist::iterator
& bl
);
1831 static void generate_test_instances(list
<object_stat_collection_t
*>& o
);
1833 bool is_zero() const {
1834 return sum
.is_zero();
1841 void floor(int64_t f
) {
1845 void add(const object_stat_sum_t
& o
) {
1849 void add(const object_stat_collection_t
& o
) {
1852 void sub(const object_stat_collection_t
& o
) {
1856 WRITE_CLASS_ENCODER(object_stat_collection_t
)
1858 inline bool operator==(const object_stat_collection_t
& l
,
1859 const object_stat_collection_t
& r
) {
1860 return l
.sum
== r
.sum
;
1865 * aggregate stats for a single PG.
1868 /**************************************************************************
1869 * WARNING: be sure to update the operator== when adding/removing fields! *
1870 **************************************************************************/
1872 version_t reported_seq
; // sequence number
1873 epoch_t reported_epoch
; // epoch of this report
1875 utime_t last_fresh
; // last reported
1876 utime_t last_change
; // new state != previous state
1877 utime_t last_active
; // state & PG_STATE_ACTIVE
1878 utime_t last_peered
; // state & PG_STATE_ACTIVE || state & PG_STATE_PEERED
1879 utime_t last_clean
; // state & PG_STATE_CLEAN
1880 utime_t last_unstale
; // (state & PG_STATE_STALE) == 0
1881 utime_t last_undegraded
; // (state & PG_STATE_DEGRADED) == 0
1882 utime_t last_fullsized
; // (state & PG_STATE_UNDERSIZED) == 0
1884 eversion_t log_start
; // (log_start,version]
1885 eversion_t ondisk_log_start
; // there may be more on disk
1888 epoch_t last_epoch_clean
;
1890 __u32 parent_split_bits
;
1892 eversion_t last_scrub
;
1893 eversion_t last_deep_scrub
;
1894 utime_t last_scrub_stamp
;
1895 utime_t last_deep_scrub_stamp
;
1896 utime_t last_clean_scrub_stamp
;
1898 object_stat_collection_t stats
;
1901 int64_t ondisk_log_size
; // >= active_log_size
1903 vector
<int32_t> up
, acting
;
1904 epoch_t mapping_epoch
;
1906 vector
<int32_t> blocked_by
; ///< osds on which the pg is blocked
1908 utime_t last_became_active
;
1909 utime_t last_became_peered
;
1911 /// up, acting primaries
1913 int32_t acting_primary
;
1915 bool stats_invalid
:1;
1916 /// true if num_objects_dirty is not accurate (because it was not
1917 /// maintained starting from pool creation)
1918 bool dirty_stats_invalid
:1;
1919 bool omap_stats_invalid
:1;
1920 bool hitset_stats_invalid
:1;
1921 bool hitset_bytes_stats_invalid
:1;
1922 bool pin_stats_invalid
:1;
1928 created(0), last_epoch_clean(0),
1929 parent_split_bits(0),
1930 log_size(0), ondisk_log_size(0),
1934 stats_invalid(false),
1935 dirty_stats_invalid(false),
1936 omap_stats_invalid(false),
1937 hitset_stats_invalid(false),
1938 hitset_bytes_stats_invalid(false),
1939 pin_stats_invalid(false)
1942 epoch_t
get_effective_last_epoch_clean() const {
1943 if (state
& PG_STATE_CLEAN
) {
1944 // we are clean as of this report, and should thus take the
1946 return reported_epoch
;
1948 return last_epoch_clean
;
1952 pair
<epoch_t
, version_t
> get_version_pair() const {
1953 return make_pair(reported_epoch
, reported_seq
);
1956 void floor(int64_t f
) {
1960 if (ondisk_log_size
< f
)
1961 ondisk_log_size
= f
;
1964 void add(const pg_stat_t
& o
) {
1966 log_size
+= o
.log_size
;
1967 ondisk_log_size
+= o
.ondisk_log_size
;
1969 void sub(const pg_stat_t
& o
) {
1971 log_size
-= o
.log_size
;
1972 ondisk_log_size
-= o
.ondisk_log_size
;
1975 bool is_acting_osd(int32_t osd
, bool primary
) const;
1976 void dump(Formatter
*f
) const;
1977 void dump_brief(Formatter
*f
) const;
1978 void encode(bufferlist
&bl
) const;
1979 void decode(bufferlist::iterator
&bl
);
1980 static void generate_test_instances(list
<pg_stat_t
*>& o
);
1982 WRITE_CLASS_ENCODER(pg_stat_t
)
1984 bool operator==(const pg_stat_t
& l
, const pg_stat_t
& r
);
1987 * summation over an entire pool
1989 struct pool_stat_t
{
1990 object_stat_collection_t stats
;
1992 int64_t ondisk_log_size
; // >= active_log_size
1993 int32_t up
; ///< number of up replicas or shards
1994 int32_t acting
; ///< number of acting replicas or shards
1996 pool_stat_t() : log_size(0), ondisk_log_size(0), up(0), acting(0)
1999 void floor(int64_t f
) {
2003 if (ondisk_log_size
< f
)
2004 ondisk_log_size
= f
;
2011 void add(const pg_stat_t
& o
) {
2013 log_size
+= o
.log_size
;
2014 ondisk_log_size
+= o
.ondisk_log_size
;
2016 acting
+= o
.acting
.size();
2018 void sub(const pg_stat_t
& o
) {
2020 log_size
-= o
.log_size
;
2021 ondisk_log_size
-= o
.ondisk_log_size
;
2023 acting
-= o
.acting
.size();
2026 bool is_zero() const {
2027 return (stats
.is_zero() &&
2029 ondisk_log_size
== 0 &&
2034 void dump(Formatter
*f
) const;
2035 void encode(bufferlist
&bl
, uint64_t features
) const;
2036 void decode(bufferlist::iterator
&bl
);
2037 static void generate_test_instances(list
<pool_stat_t
*>& o
);
2039 WRITE_CLASS_ENCODER_FEATURES(pool_stat_t
)
2042 // -----------------------------------------
2045 * pg_hit_set_info_t - information about a single recorded HitSet
2047 * Track basic metadata about a HitSet, like the nubmer of insertions
2048 * and the time range it covers.
2050 struct pg_hit_set_info_t
{
2051 utime_t begin
, end
; ///< time interval
2052 eversion_t version
; ///< version this HitSet object was written
2053 bool using_gmt
; ///< use gmt for creating the hit_set archive object name
2055 friend bool operator==(const pg_hit_set_info_t
& l
,
2056 const pg_hit_set_info_t
& r
) {
2058 l
.begin
== r
.begin
&&
2060 l
.version
== r
.version
&&
2061 l
.using_gmt
== r
.using_gmt
;
2064 explicit pg_hit_set_info_t(bool using_gmt
= true)
2065 : using_gmt(using_gmt
) {}
2067 void encode(bufferlist
&bl
) const;
2068 void decode(bufferlist::iterator
&bl
);
2069 void dump(Formatter
*f
) const;
2070 static void generate_test_instances(list
<pg_hit_set_info_t
*>& o
);
2072 WRITE_CLASS_ENCODER(pg_hit_set_info_t
)
2075 * pg_hit_set_history_t - information about a history of hitsets
2077 * Include information about the currently accumulating hit set as well
2078 * as archived/historical ones.
2080 struct pg_hit_set_history_t
{
2081 eversion_t current_last_update
; ///< last version inserted into current set
2082 list
<pg_hit_set_info_t
> history
; ///< archived sets, sorted oldest -> newest
2084 friend bool operator==(const pg_hit_set_history_t
& l
,
2085 const pg_hit_set_history_t
& r
) {
2087 l
.current_last_update
== r
.current_last_update
&&
2088 l
.history
== r
.history
;
2091 void encode(bufferlist
&bl
) const;
2092 void decode(bufferlist::iterator
&bl
);
2093 void dump(Formatter
*f
) const;
2094 static void generate_test_instances(list
<pg_hit_set_history_t
*>& o
);
2096 WRITE_CLASS_ENCODER(pg_hit_set_history_t
)
2099 // -----------------------------------------
2102 * pg_history_t - information about recent pg peering/mapping history
2104 * This is aggressively shared between OSDs to bound the amount of past
2105 * history they need to worry about.
2107 struct pg_history_t
{
2108 epoch_t epoch_created
; // epoch in which *pg* was created (pool or pg)
2109 epoch_t epoch_pool_created
; // epoch in which *pool* was created
2110 // (note: may be pg creation epoch for
2111 // pre-luminous clusters)
2112 epoch_t last_epoch_started
; // lower bound on last epoch started (anywhere, not necessarily locally)
2113 epoch_t last_interval_started
; // first epoch of last_epoch_started interval
2114 epoch_t last_epoch_clean
; // lower bound on last epoch the PG was completely clean.
2115 epoch_t last_interval_clean
; // first epoch of last_epoch_clean interval
2116 epoch_t last_epoch_split
; // as parent or child
2117 epoch_t last_epoch_marked_full
; // pool or cluster
2120 * In the event of a map discontinuity, same_*_since may reflect the first
2121 * map the osd has seen in the new map sequence rather than the actual start
2122 * of the interval. This is ok since a discontinuity at epoch e means there
2123 * must have been a clean interval between e and now and that we cannot be
2124 * in the active set during the interval containing e.
2126 epoch_t same_up_since
; // same acting set since
2127 epoch_t same_interval_since
; // same acting AND up set since
2128 epoch_t same_primary_since
; // same primary at least back through this epoch.
2130 eversion_t last_scrub
;
2131 eversion_t last_deep_scrub
;
2132 utime_t last_scrub_stamp
;
2133 utime_t last_deep_scrub_stamp
;
2134 utime_t last_clean_scrub_stamp
;
2136 friend bool operator==(const pg_history_t
& l
, const pg_history_t
& r
) {
2138 l
.epoch_created
== r
.epoch_created
&&
2139 l
.epoch_pool_created
== r
.epoch_pool_created
&&
2140 l
.last_epoch_started
== r
.last_epoch_started
&&
2141 l
.last_interval_started
== r
.last_interval_started
&&
2142 l
.last_epoch_clean
== r
.last_epoch_clean
&&
2143 l
.last_interval_clean
== r
.last_interval_clean
&&
2144 l
.last_epoch_split
== r
.last_epoch_split
&&
2145 l
.last_epoch_marked_full
== r
.last_epoch_marked_full
&&
2146 l
.same_up_since
== r
.same_up_since
&&
2147 l
.same_interval_since
== r
.same_interval_since
&&
2148 l
.same_primary_since
== r
.same_primary_since
&&
2149 l
.last_scrub
== r
.last_scrub
&&
2150 l
.last_deep_scrub
== r
.last_deep_scrub
&&
2151 l
.last_scrub_stamp
== r
.last_scrub_stamp
&&
2152 l
.last_deep_scrub_stamp
== r
.last_deep_scrub_stamp
&&
2153 l
.last_clean_scrub_stamp
== r
.last_clean_scrub_stamp
;
2158 epoch_pool_created(0),
2159 last_epoch_started(0),
2160 last_interval_started(0),
2161 last_epoch_clean(0),
2162 last_interval_clean(0),
2163 last_epoch_split(0),
2164 last_epoch_marked_full(0),
2165 same_up_since(0), same_interval_since(0), same_primary_since(0) {}
2167 bool merge(const pg_history_t
&other
) {
2168 // Here, we only update the fields which cannot be calculated from the OSDmap.
2169 bool modified
= false;
2170 if (epoch_created
< other
.epoch_created
) {
2171 epoch_created
= other
.epoch_created
;
2174 if (epoch_pool_created
< other
.epoch_pool_created
) {
2175 // FIXME: for jewel compat only; this should either be 0 or always the
2176 // same value across all pg instances.
2177 epoch_pool_created
= other
.epoch_pool_created
;
2180 if (last_epoch_started
< other
.last_epoch_started
) {
2181 last_epoch_started
= other
.last_epoch_started
;
2184 if (last_interval_started
< other
.last_interval_started
) {
2185 last_interval_started
= other
.last_interval_started
;
2188 if (last_epoch_clean
< other
.last_epoch_clean
) {
2189 last_epoch_clean
= other
.last_epoch_clean
;
2192 if (last_interval_clean
< other
.last_interval_clean
) {
2193 last_interval_clean
= other
.last_interval_clean
;
2196 if (last_epoch_split
< other
.last_epoch_split
) {
2197 last_epoch_split
= other
.last_epoch_split
;
2200 if (last_epoch_marked_full
< other
.last_epoch_marked_full
) {
2201 last_epoch_marked_full
= other
.last_epoch_marked_full
;
2204 if (other
.last_scrub
> last_scrub
) {
2205 last_scrub
= other
.last_scrub
;
2208 if (other
.last_scrub_stamp
> last_scrub_stamp
) {
2209 last_scrub_stamp
= other
.last_scrub_stamp
;
2212 if (other
.last_deep_scrub
> last_deep_scrub
) {
2213 last_deep_scrub
= other
.last_deep_scrub
;
2216 if (other
.last_deep_scrub_stamp
> last_deep_scrub_stamp
) {
2217 last_deep_scrub_stamp
= other
.last_deep_scrub_stamp
;
2220 if (other
.last_clean_scrub_stamp
> last_clean_scrub_stamp
) {
2221 last_clean_scrub_stamp
= other
.last_clean_scrub_stamp
;
2227 void encode(bufferlist
& bl
) const;
2228 void decode(bufferlist::iterator
& p
);
2229 void dump(Formatter
*f
) const;
2230 static void generate_test_instances(list
<pg_history_t
*>& o
);
2232 WRITE_CLASS_ENCODER(pg_history_t
)
2234 inline ostream
& operator<<(ostream
& out
, const pg_history_t
& h
) {
2235 return out
<< "ec=" << h
.epoch_created
<< "/" << h
.epoch_pool_created
2236 << " lis/c " << h
.last_interval_started
2237 << "/" << h
.last_interval_clean
2238 << " les/c/f " << h
.last_epoch_started
<< "/" << h
.last_epoch_clean
2239 << "/" << h
.last_epoch_marked_full
2240 << " " << h
.same_up_since
2241 << "/" << h
.same_interval_since
2242 << "/" << h
.same_primary_since
;
2247 * pg_info_t - summary of PG statistics.
2250 * - last_complete implies we have all objects that existed as of that
2251 * stamp, OR a newer object, OR have already applied a later delete.
2252 * - if last_complete >= log.bottom, then we know pg contents thru log.head.
2253 * otherwise, we have no idea what the pg is supposed to contain.
2257 eversion_t last_update
; ///< last object version applied to store.
2258 eversion_t last_complete
; ///< last version pg was complete through.
2259 epoch_t last_epoch_started
; ///< last epoch at which this pg started on this osd
2260 epoch_t last_interval_started
; ///< first epoch of last_epoch_started interval
2262 version_t last_user_version
; ///< last user object version applied to store
2264 eversion_t log_tail
; ///< oldest log entry.
2266 hobject_t last_backfill
; ///< objects >= this and < last_complete may be missing
2267 bool last_backfill_bitwise
; ///< true if last_backfill reflects a bitwise (vs nibblewise) sort
2269 interval_set
<snapid_t
> purged_snaps
;
2273 pg_history_t history
;
2274 pg_hit_set_history_t hit_set
;
2276 friend bool operator==(const pg_info_t
& l
, const pg_info_t
& r
) {
2279 l
.last_update
== r
.last_update
&&
2280 l
.last_complete
== r
.last_complete
&&
2281 l
.last_epoch_started
== r
.last_epoch_started
&&
2282 l
.last_interval_started
== r
.last_interval_started
&&
2283 l
.last_user_version
== r
.last_user_version
&&
2284 l
.log_tail
== r
.log_tail
&&
2285 l
.last_backfill
== r
.last_backfill
&&
2286 l
.last_backfill_bitwise
== r
.last_backfill_bitwise
&&
2287 l
.purged_snaps
== r
.purged_snaps
&&
2288 l
.stats
== r
.stats
&&
2289 l
.history
== r
.history
&&
2290 l
.hit_set
== r
.hit_set
;
2294 : last_epoch_started(0),
2295 last_interval_started(0),
2296 last_user_version(0),
2297 last_backfill(hobject_t::get_max()),
2298 last_backfill_bitwise(false)
2300 // cppcheck-suppress noExplicitConstructor
2303 last_epoch_started(0),
2304 last_interval_started(0),
2305 last_user_version(0),
2306 last_backfill(hobject_t::get_max()),
2307 last_backfill_bitwise(false)
2310 void set_last_backfill(hobject_t pos
) {
2311 last_backfill
= pos
;
2312 last_backfill_bitwise
= true;
2315 bool is_empty() const { return last_update
.version
== 0; }
2316 bool dne() const { return history
.epoch_created
== 0; }
2318 bool is_incomplete() const { return !last_backfill
.is_max(); }
2320 void encode(bufferlist
& bl
) const;
2321 void decode(bufferlist::iterator
& p
);
2322 void dump(Formatter
*f
) const;
2323 bool overlaps_with(const pg_info_t
&oinfo
) const {
2324 return last_update
> oinfo
.log_tail
?
2325 oinfo
.last_update
>= log_tail
:
2326 last_update
>= oinfo
.log_tail
;
2328 static void generate_test_instances(list
<pg_info_t
*>& o
);
2330 WRITE_CLASS_ENCODER(pg_info_t
)
2332 inline ostream
& operator<<(ostream
& out
, const pg_info_t
& pgi
)
2334 out
<< pgi
.pgid
<< "(";
2340 out
<< " v " << pgi
.last_update
;
2341 if (pgi
.last_complete
!= pgi
.last_update
)
2342 out
<< " lc " << pgi
.last_complete
;
2343 out
<< " (" << pgi
.log_tail
<< "," << pgi
.last_update
<< "]";
2345 if (pgi
.is_incomplete())
2346 out
<< " lb " << pgi
.last_backfill
2347 << (pgi
.last_backfill_bitwise
? " (bitwise)" : " (NIBBLEWISE)");
2348 //out << " c " << pgi.epoch_created;
2349 out
<< " local-lis/les=" << pgi
.last_interval_started
2350 << "/" << pgi
.last_epoch_started
;
2351 out
<< " n=" << pgi
.stats
.stats
.sum
.num_objects
;
2352 out
<< " " << pgi
.history
2358 * pg_fast_info_t - common pg_info_t fields
2360 * These are the fields of pg_info_t (and children) that are updated for
2361 * most IO operations.
2364 * Because we rely on these fields to be applied to the normal
2365 * info struct, adding a new field here that is not also new in info
2366 * means that we must set an incompat OSD feature bit!
2368 struct pg_fast_info_t
{
2369 eversion_t last_update
;
2370 eversion_t last_complete
;
2371 version_t last_user_version
;
2372 struct { // pg_stat_t stats
2374 version_t reported_seq
;
2376 utime_t last_active
;
2377 utime_t last_peered
;
2379 utime_t last_unstale
;
2380 utime_t last_undegraded
;
2381 utime_t last_fullsized
;
2382 int64_t log_size
; // (also ondisk_log_size, which has the same value)
2383 struct { // object_stat_collection_t stats;
2384 struct { // objct_stat_sum_t sum
2385 int64_t num_bytes
; // in bytes
2386 int64_t num_objects
;
2387 int64_t num_object_copies
;
2392 int64_t num_objects_dirty
;
2397 void populate_from(const pg_info_t
& info
) {
2398 last_update
= info
.last_update
;
2399 last_complete
= info
.last_complete
;
2400 last_user_version
= info
.last_user_version
;
2401 stats
.version
= info
.stats
.version
;
2402 stats
.reported_seq
= info
.stats
.reported_seq
;
2403 stats
.last_fresh
= info
.stats
.last_fresh
;
2404 stats
.last_active
= info
.stats
.last_active
;
2405 stats
.last_peered
= info
.stats
.last_peered
;
2406 stats
.last_clean
= info
.stats
.last_clean
;
2407 stats
.last_unstale
= info
.stats
.last_unstale
;
2408 stats
.last_undegraded
= info
.stats
.last_undegraded
;
2409 stats
.last_fullsized
= info
.stats
.last_fullsized
;
2410 stats
.log_size
= info
.stats
.log_size
;
2411 stats
.stats
.sum
.num_bytes
= info
.stats
.stats
.sum
.num_bytes
;
2412 stats
.stats
.sum
.num_objects
= info
.stats
.stats
.sum
.num_objects
;
2413 stats
.stats
.sum
.num_object_copies
= info
.stats
.stats
.sum
.num_object_copies
;
2414 stats
.stats
.sum
.num_rd
= info
.stats
.stats
.sum
.num_rd
;
2415 stats
.stats
.sum
.num_rd_kb
= info
.stats
.stats
.sum
.num_rd_kb
;
2416 stats
.stats
.sum
.num_wr
= info
.stats
.stats
.sum
.num_wr
;
2417 stats
.stats
.sum
.num_wr_kb
= info
.stats
.stats
.sum
.num_wr_kb
;
2418 stats
.stats
.sum
.num_objects_dirty
= info
.stats
.stats
.sum
.num_objects_dirty
;
2421 bool try_apply_to(pg_info_t
* info
) {
2422 if (last_update
<= info
->last_update
)
2424 info
->last_update
= last_update
;
2425 info
->last_complete
= last_complete
;
2426 info
->last_user_version
= last_user_version
;
2427 info
->stats
.version
= stats
.version
;
2428 info
->stats
.reported_seq
= stats
.reported_seq
;
2429 info
->stats
.last_fresh
= stats
.last_fresh
;
2430 info
->stats
.last_active
= stats
.last_active
;
2431 info
->stats
.last_peered
= stats
.last_peered
;
2432 info
->stats
.last_clean
= stats
.last_clean
;
2433 info
->stats
.last_unstale
= stats
.last_unstale
;
2434 info
->stats
.last_undegraded
= stats
.last_undegraded
;
2435 info
->stats
.last_fullsized
= stats
.last_fullsized
;
2436 info
->stats
.log_size
= stats
.log_size
;
2437 info
->stats
.ondisk_log_size
= stats
.log_size
;
2438 info
->stats
.stats
.sum
.num_bytes
= stats
.stats
.sum
.num_bytes
;
2439 info
->stats
.stats
.sum
.num_objects
= stats
.stats
.sum
.num_objects
;
2440 info
->stats
.stats
.sum
.num_object_copies
= stats
.stats
.sum
.num_object_copies
;
2441 info
->stats
.stats
.sum
.num_rd
= stats
.stats
.sum
.num_rd
;
2442 info
->stats
.stats
.sum
.num_rd_kb
= stats
.stats
.sum
.num_rd_kb
;
2443 info
->stats
.stats
.sum
.num_wr
= stats
.stats
.sum
.num_wr
;
2444 info
->stats
.stats
.sum
.num_wr_kb
= stats
.stats
.sum
.num_wr_kb
;
2445 info
->stats
.stats
.sum
.num_objects_dirty
= stats
.stats
.sum
.num_objects_dirty
;
2449 void encode(bufferlist
& bl
) const {
2450 ENCODE_START(1, 1, bl
);
2451 ::encode(last_update
, bl
);
2452 ::encode(last_complete
, bl
);
2453 ::encode(last_user_version
, bl
);
2454 ::encode(stats
.version
, bl
);
2455 ::encode(stats
.reported_seq
, bl
);
2456 ::encode(stats
.last_fresh
, bl
);
2457 ::encode(stats
.last_active
, bl
);
2458 ::encode(stats
.last_peered
, bl
);
2459 ::encode(stats
.last_clean
, bl
);
2460 ::encode(stats
.last_unstale
, bl
);
2461 ::encode(stats
.last_undegraded
, bl
);
2462 ::encode(stats
.last_fullsized
, bl
);
2463 ::encode(stats
.log_size
, bl
);
2464 ::encode(stats
.stats
.sum
.num_bytes
, bl
);
2465 ::encode(stats
.stats
.sum
.num_objects
, bl
);
2466 ::encode(stats
.stats
.sum
.num_object_copies
, bl
);
2467 ::encode(stats
.stats
.sum
.num_rd
, bl
);
2468 ::encode(stats
.stats
.sum
.num_rd_kb
, bl
);
2469 ::encode(stats
.stats
.sum
.num_wr
, bl
);
2470 ::encode(stats
.stats
.sum
.num_wr_kb
, bl
);
2471 ::encode(stats
.stats
.sum
.num_objects_dirty
, bl
);
2474 void decode(bufferlist::iterator
& p
) {
2476 ::decode(last_update
, p
);
2477 ::decode(last_complete
, p
);
2478 ::decode(last_user_version
, p
);
2479 ::decode(stats
.version
, p
);
2480 ::decode(stats
.reported_seq
, p
);
2481 ::decode(stats
.last_fresh
, p
);
2482 ::decode(stats
.last_active
, p
);
2483 ::decode(stats
.last_peered
, p
);
2484 ::decode(stats
.last_clean
, p
);
2485 ::decode(stats
.last_unstale
, p
);
2486 ::decode(stats
.last_undegraded
, p
);
2487 ::decode(stats
.last_fullsized
, p
);
2488 ::decode(stats
.log_size
, p
);
2489 ::decode(stats
.stats
.sum
.num_bytes
, p
);
2490 ::decode(stats
.stats
.sum
.num_objects
, p
);
2491 ::decode(stats
.stats
.sum
.num_object_copies
, p
);
2492 ::decode(stats
.stats
.sum
.num_rd
, p
);
2493 ::decode(stats
.stats
.sum
.num_rd_kb
, p
);
2494 ::decode(stats
.stats
.sum
.num_wr
, p
);
2495 ::decode(stats
.stats
.sum
.num_wr_kb
, p
);
2496 ::decode(stats
.stats
.sum
.num_objects_dirty
, p
);
2500 WRITE_CLASS_ENCODER(pg_fast_info_t
)
2503 struct pg_notify_t
{
2504 epoch_t query_epoch
;
2510 query_epoch(0), epoch_sent(0), to(shard_id_t::NO_SHARD
),
2511 from(shard_id_t::NO_SHARD
) {}
2515 epoch_t query_epoch
,
2517 const pg_info_t
&info
)
2518 : query_epoch(query_epoch
),
2519 epoch_sent(epoch_sent
),
2520 info(info
), to(to
), from(from
) {
2521 assert(from
== info
.pgid
.shard
);
2523 void encode(bufferlist
&bl
) const;
2524 void decode(bufferlist::iterator
&p
);
2525 void dump(Formatter
*f
) const;
2526 static void generate_test_instances(list
<pg_notify_t
*> &o
);
2528 WRITE_CLASS_ENCODER(pg_notify_t
)
2529 ostream
&operator<<(ostream
&lhs
, const pg_notify_t
¬ify
);
2534 * PastIntervals -- information needed to determine the PriorSet and
2535 * the might_have_unfound set
2537 class PastIntervals
{
2539 struct pg_interval_t
{
2540 vector
<int32_t> up
, acting
;
2541 epoch_t first
, last
;
2547 : first(0), last(0),
2548 maybe_went_rw(false),
2554 vector
<int32_t> &&up
,
2555 vector
<int32_t> &&acting
,
2561 : up(up
), acting(acting
), first(first
), last(last
),
2562 maybe_went_rw(maybe_went_rw
), primary(primary
), up_primary(up_primary
)
2565 void encode(bufferlist
& bl
) const;
2566 void decode(bufferlist::iterator
& bl
);
2567 void dump(Formatter
*f
) const;
2568 static void generate_test_instances(list
<pg_interval_t
*>& o
);
2571 PastIntervals() = default;
2572 PastIntervals(bool ec_pool
, const OSDMap
&osdmap
) : PastIntervals() {
2573 update_type_from_map(ec_pool
, osdmap
);
2575 PastIntervals(bool ec_pool
, bool compact
) : PastIntervals() {
2576 update_type(ec_pool
, compact
);
2578 PastIntervals(PastIntervals
&&rhs
) = default;
2579 PastIntervals
&operator=(PastIntervals
&&rhs
) = default;
2581 PastIntervals(const PastIntervals
&rhs
);
2582 PastIntervals
&operator=(const PastIntervals
&rhs
);
2584 class interval_rep
{
2586 virtual size_t size() const = 0;
2587 virtual bool empty() const = 0;
2588 virtual void clear() = 0;
2589 virtual pair
<epoch_t
, epoch_t
> get_bounds() const = 0;
2590 virtual set
<pg_shard_t
> get_all_participants(
2591 bool ec_pool
) const = 0;
2592 virtual void add_interval(bool ec_pool
, const pg_interval_t
&interval
) = 0;
2593 virtual unique_ptr
<interval_rep
> clone() const = 0;
2594 virtual ostream
&print(ostream
&out
) const = 0;
2595 virtual void encode(bufferlist
&bl
) const = 0;
2596 virtual void decode(bufferlist::iterator
&bl
) = 0;
2597 virtual void dump(Formatter
*f
) const = 0;
2598 virtual bool is_classic() const = 0;
2599 virtual void iterate_mayberw_back_to(
2602 std::function
<void(epoch_t
, const set
<pg_shard_t
> &)> &&f
) const = 0;
2604 virtual bool has_full_intervals() const { return false; }
2605 virtual void iterate_all_intervals(
2606 std::function
<void(const pg_interval_t
&)> &&f
) const {
2607 assert(!has_full_intervals());
2608 assert(0 == "not valid for this implementation");
2611 virtual ~interval_rep() {}
2613 friend class pi_simple_rep
;
2614 friend class pi_compact_rep
;
2617 unique_ptr
<interval_rep
> past_intervals
;
2619 PastIntervals(interval_rep
*rep
) : past_intervals(rep
) {}
2622 void add_interval(bool ec_pool
, const pg_interval_t
&interval
) {
2623 assert(past_intervals
);
2624 return past_intervals
->add_interval(ec_pool
, interval
);
2627 bool is_classic() const {
2628 assert(past_intervals
);
2629 return past_intervals
->is_classic();
2632 void encode(bufferlist
&bl
) const {
2633 ENCODE_START(1, 1, bl
);
2634 if (past_intervals
) {
2635 __u8 type
= is_classic() ? 1 : 2;
2637 past_intervals
->encode(bl
);
2639 ::encode((__u8
)0, bl
);
2643 void encode_classic(bufferlist
&bl
) const {
2644 if (past_intervals
) {
2645 assert(past_intervals
->is_classic());
2646 past_intervals
->encode(bl
);
2649 ::encode((uint32_t)0, bl
);
2653 void decode(bufferlist::iterator
&bl
);
2654 void decode_classic(bufferlist::iterator
&bl
);
2656 void dump(Formatter
*f
) const {
2657 assert(past_intervals
);
2658 past_intervals
->dump(f
);
2660 static void generate_test_instances(list
<PastIntervals
*> & o
);
2663 * Determines whether there is an interval change
2665 static bool is_new_interval(
2666 int old_acting_primary
,
2667 int new_acting_primary
,
2668 const vector
<int> &old_acting
,
2669 const vector
<int> &new_acting
,
2672 const vector
<int> &old_up
,
2673 const vector
<int> &new_up
,
2678 unsigned old_pg_num
,
2679 unsigned new_pg_num
,
2680 bool old_sort_bitwise
,
2681 bool new_sort_bitwise
,
2686 * Determines whether there is an interval change
2688 static bool is_new_interval(
2689 int old_acting_primary
, ///< [in] primary as of lastmap
2690 int new_acting_primary
, ///< [in] primary as of lastmap
2691 const vector
<int> &old_acting
, ///< [in] acting as of lastmap
2692 const vector
<int> &new_acting
, ///< [in] acting as of osdmap
2693 int old_up_primary
, ///< [in] up primary of lastmap
2694 int new_up_primary
, ///< [in] up primary of osdmap
2695 const vector
<int> &old_up
, ///< [in] up as of lastmap
2696 const vector
<int> &new_up
, ///< [in] up as of osdmap
2697 ceph::shared_ptr
<const OSDMap
> osdmap
, ///< [in] current map
2698 ceph::shared_ptr
<const OSDMap
> lastmap
, ///< [in] last map
2699 pg_t pgid
///< [in] pgid for pg
2703 * Integrates a new map into *past_intervals, returns true
2704 * if an interval was closed out.
2706 static bool check_new_interval(
2707 int old_acting_primary
, ///< [in] primary as of lastmap
2708 int new_acting_primary
, ///< [in] primary as of osdmap
2709 const vector
<int> &old_acting
, ///< [in] acting as of lastmap
2710 const vector
<int> &new_acting
, ///< [in] acting as of osdmap
2711 int old_up_primary
, ///< [in] up primary of lastmap
2712 int new_up_primary
, ///< [in] up primary of osdmap
2713 const vector
<int> &old_up
, ///< [in] up as of lastmap
2714 const vector
<int> &new_up
, ///< [in] up as of osdmap
2715 epoch_t same_interval_since
, ///< [in] as of osdmap
2716 epoch_t last_epoch_clean
, ///< [in] current
2717 ceph::shared_ptr
<const OSDMap
> osdmap
, ///< [in] current map
2718 ceph::shared_ptr
<const OSDMap
> lastmap
, ///< [in] last map
2719 pg_t pgid
, ///< [in] pgid for pg
2720 IsPGRecoverablePredicate
*could_have_gone_active
, /// [in] predicate whether the pg can be active
2721 PastIntervals
*past_intervals
, ///< [out] intervals
2722 ostream
*out
= 0 ///< [out] debug ostream
2724 friend ostream
& operator<<(ostream
& out
, const PastIntervals
&i
);
2726 template <typename F
>
2727 void iterate_mayberw_back_to(
2731 assert(past_intervals
);
2732 past_intervals
->iterate_mayberw_back_to(ec_pool
, les
, std::forward
<F
>(f
));
2735 assert(past_intervals
);
2736 past_intervals
->clear();
2740 * Should return a value which gives an indication of the amount
2741 * of state contained
2743 size_t size() const {
2744 assert(past_intervals
);
2745 return past_intervals
->size();
2748 bool empty() const {
2749 assert(past_intervals
);
2750 return past_intervals
->empty();
2753 void swap(PastIntervals
&other
) {
2755 swap(other
.past_intervals
, past_intervals
);
2759 * Return all shards which have been in the acting set back to the
2760 * latest epoch to which we have trimmed except for pg_whoami
2762 set
<pg_shard_t
> get_might_have_unfound(
2763 pg_shard_t pg_whoami
,
2764 bool ec_pool
) const {
2765 assert(past_intervals
);
2766 auto ret
= past_intervals
->get_all_participants(ec_pool
);
2767 ret
.erase(pg_whoami
);
2772 * Return all shards which we might want to talk to for peering
2774 set
<pg_shard_t
> get_all_probe(
2775 bool ec_pool
) const {
2776 assert(past_intervals
);
2777 return past_intervals
->get_all_participants(ec_pool
);
2780 /* Return the set of epochs [start, end) represented by the
2781 * past_interval set.
2783 pair
<epoch_t
, epoch_t
> get_bounds() const {
2784 assert(past_intervals
);
2785 return past_intervals
->get_bounds();
2795 bool ec_pool
= false;
2796 set
<pg_shard_t
> probe
; /// current+prior OSDs we need to probe.
2797 set
<int> down
; /// down osds that would normally be in @a probe and might be interesting.
2798 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
2800 bool pg_down
= false; /// some down osds are included in @a cur; the DOWN pg state bit should be set.
2801 unique_ptr
<IsPGRecoverablePredicate
> pcontdec
;
2803 PriorSet() = default;
2804 PriorSet(PriorSet
&&) = default;
2805 PriorSet
&operator=(PriorSet
&&) = default;
2807 PriorSet
&operator=(const PriorSet
&) = delete;
2808 PriorSet(const PriorSet
&) = delete;
2810 bool operator==(const PriorSet
&rhs
) const {
2811 return (ec_pool
== rhs
.ec_pool
) &&
2812 (probe
== rhs
.probe
) &&
2813 (down
== rhs
.down
) &&
2814 (blocked_by
== rhs
.blocked_by
) &&
2815 (pg_down
== rhs
.pg_down
);
2818 bool affected_by_map(
2819 const OSDMap
&osdmap
,
2820 const DoutPrefixProvider
*dpp
) const;
2822 // For verifying tests
2825 set
<pg_shard_t
> probe
,
2827 map
<int, epoch_t
> blocked_by
,
2829 IsPGRecoverablePredicate
*pcontdec
)
2830 : ec_pool(ec_pool
), probe(probe
), down(down
), blocked_by(blocked_by
),
2831 pg_down(pg_down
), pcontdec(pcontdec
) {}
2834 template <typename F
>
2836 const PastIntervals
&past_intervals
,
2838 epoch_t last_epoch_started
,
2839 IsPGRecoverablePredicate
*c
,
2841 const vector
<int> &up
,
2842 const vector
<int> &acting
,
2843 const DoutPrefixProvider
*dpp
);
2845 friend class PastIntervals
;
2848 void update_type(bool ec_pool
, bool compact
);
2849 void update_type_from_map(bool ec_pool
, const OSDMap
&osdmap
);
2851 template <typename
... Args
>
2852 PriorSet
get_prior_set(Args
&&... args
) const {
2853 return PriorSet(*this, std::forward
<Args
>(args
)...);
2856 WRITE_CLASS_ENCODER(PastIntervals
)
2858 ostream
& operator<<(ostream
& out
, const PastIntervals::pg_interval_t
& i
);
2859 ostream
& operator<<(ostream
& out
, const PastIntervals
&i
);
2860 ostream
& operator<<(ostream
& out
, const PastIntervals::PriorSet
&i
);
2862 template <typename F
>
2863 PastIntervals::PriorSet::PriorSet(
2864 const PastIntervals
&past_intervals
,
2866 epoch_t last_epoch_started
,
2867 IsPGRecoverablePredicate
*c
,
2869 const vector
<int> &up
,
2870 const vector
<int> &acting
,
2871 const DoutPrefixProvider
*dpp
)
2872 : ec_pool(ec_pool
), pg_down(false), pcontdec(c
)
2875 * We have to be careful to gracefully deal with situations like
2876 * so. Say we have a power outage or something that takes out both
2877 * OSDs, but the monitor doesn't mark them down in the same epoch.
2878 * The history may look like
2882 * 3: let's say B dies for good, too (say, from the power spike)
2885 * which makes it look like B may have applied updates to the PG
2886 * that we need in order to proceed. This sucks...
2888 * To minimize the risk of this happening, we CANNOT go active if
2889 * _any_ OSDs in the prior set are down until we send an MOSDAlive
2890 * to the monitor such that the OSDMap sets osd_up_thru to an epoch.
2891 * Then, we have something like
2898 * -> we can ignore B, bc it couldn't have gone active (alive_thru
2909 * -> we must wait for B, bc it was alive through 2, and could have
2910 * written to the pg.
2912 * If B is really dead, then an administrator will need to manually
2913 * intervene by marking the OSD as "lost."
2916 // Include current acting and up nodes... not because they may
2917 // contain old data (this interval hasn't gone active, obviously),
2918 // but because we want their pg_info to inform choose_acting(), and
2919 // so that we know what they do/do not have explicitly before
2920 // sending them any new info/logs/whatever.
2921 for (unsigned i
= 0; i
< acting
.size(); i
++) {
2922 if (acting
[i
] != 0x7fffffff /* CRUSH_ITEM_NONE, can't import crush.h here */)
2923 probe
.insert(pg_shard_t(acting
[i
], ec_pool
? shard_id_t(i
) : shard_id_t::NO_SHARD
));
2925 // It may be possible to exclude the up nodes, but let's keep them in
2927 for (unsigned i
= 0; i
< up
.size(); i
++) {
2928 if (up
[i
] != 0x7fffffff /* CRUSH_ITEM_NONE, can't import crush.h here */)
2929 probe
.insert(pg_shard_t(up
[i
], ec_pool
? shard_id_t(i
) : shard_id_t::NO_SHARD
));
2932 set
<pg_shard_t
> all_probe
= past_intervals
.get_all_probe(ec_pool
);
2933 ldpp_dout(dpp
, 10) << "build_prior all_probe " << all_probe
<< dendl
;
2934 for (auto &&i
: all_probe
) {
2935 switch (f(0, i
.osd
, nullptr)) {
2949 past_intervals
.iterate_mayberw_back_to(
2952 [&](epoch_t start
, const set
<pg_shard_t
> &acting
) {
2953 ldpp_dout(dpp
, 10) << "build_prior maybe_rw interval:" << start
2954 << ", acting: " << acting
<< dendl
;
2956 // look at candidate osds during this interval. each falls into
2957 // one of three categories: up, down (but potentially
2958 // interesting), or lost (down, but we won't wait for it).
2959 set
<pg_shard_t
> up_now
;
2960 map
<int, epoch_t
> candidate_blocked_by
;
2961 // any candidates down now (that might have useful data)
2962 bool any_down_now
= false;
2964 // consider ACTING osds
2965 for (auto &&so
: acting
) {
2966 epoch_t lost_at
= 0;
2967 switch (f(start
, so
.osd
, &lost_at
)) {
2969 // include past acting osds if they are up.
2974 ldpp_dout(dpp
, 10) << "build_prior prior osd." << so
.osd
2975 << " no longer exists" << dendl
;
2979 ldpp_dout(dpp
, 10) << "build_prior prior osd." << so
.osd
2980 << " is down, but lost_at " << lost_at
<< dendl
;
2985 ldpp_dout(dpp
, 10) << "build_prior prior osd." << so
.osd
2986 << " is down" << dendl
;
2987 candidate_blocked_by
[so
.osd
] = lost_at
;
2988 any_down_now
= true;
2994 // if not enough osds survived this interval, and we may have gone rw,
2995 // then we need to wait for one of those osds to recover to
2996 // ensure that we haven't lost any information.
2997 if (!(*pcontdec
)(up_now
) && any_down_now
) {
2998 // fixme: how do we identify a "clean" shutdown anyway?
2999 ldpp_dout(dpp
, 10) << "build_prior possibly went active+rw,"
3000 << " insufficient up; including down osds" << dendl
;
3001 assert(!candidate_blocked_by
.empty());
3004 candidate_blocked_by
.begin(),
3005 candidate_blocked_by
.end());
3009 ldpp_dout(dpp
, 10) << "build_prior final: probe " << probe
3011 << " blocked_by " << blocked_by
3012 << (pg_down
? " pg_down":"")
3017 * pg_query_t - used to ask a peer for information about a pg.
3019 * note: if version=0, type=LOG, then we just provide our full log.
3028 const char *get_type_name() const {
3030 case INFO
: return "info";
3031 case LOG
: return "log";
3032 case MISSING
: return "missing";
3033 case FULLLOG
: return "fulllog";
3034 default: return "???";
3040 pg_history_t history
;
3045 pg_query_t() : type(-1), epoch_sent(0), to(shard_id_t::NO_SHARD
),
3046 from(shard_id_t::NO_SHARD
) {}
3051 const pg_history_t
& h
,
3055 epoch_sent(epoch_sent
),
3056 to(to
), from(from
) {
3064 const pg_history_t
& h
,
3066 : type(t
), since(s
), history(h
),
3067 epoch_sent(epoch_sent
), to(to
), from(from
) {
3071 void encode(bufferlist
&bl
, uint64_t features
) const;
3072 void decode(bufferlist::iterator
&bl
);
3074 void dump(Formatter
*f
) const;
3075 static void generate_test_instances(list
<pg_query_t
*>& o
);
3077 WRITE_CLASS_ENCODER_FEATURES(pg_query_t
)
3079 inline ostream
& operator<<(ostream
& out
, const pg_query_t
& q
) {
3080 out
<< "query(" << q
.get_type_name() << " " << q
.since
;
3081 if (q
.type
== pg_query_t::LOG
)
3082 out
<< " " << q
.history
;
3088 class ObjectModDesc
{
3089 bool can_local_rollback
;
3090 bool rollback_info_completed
;
3092 // version required to decode, reflected in encode/decode version
3093 __u8 max_required_version
= 1;
3097 virtual void append(uint64_t old_offset
) {}
3098 virtual void setattrs(map
<string
, boost::optional
<bufferlist
> > &attrs
) {}
3099 virtual void rmobject(version_t old_version
) {}
3101 * Used to support the unfound_lost_delete log event: if the stashed
3102 * version exists, we unstash it, otherwise, we do nothing. This way
3103 * each replica rolls back to whatever state it had prior to the attempt
3104 * at mark unfound lost delete
3106 virtual void try_rmobject(version_t old_version
) {
3107 rmobject(old_version
);
3109 virtual void create() {}
3110 virtual void update_snaps(const set
<snapid_t
> &old_snaps
) {}
3111 virtual void rollback_extents(
3113 const vector
<pair
<uint64_t, uint64_t> > &extents
) {}
3114 virtual ~Visitor() {}
3116 void visit(Visitor
*visitor
) const;
3117 mutable bufferlist bl
;
3125 ROLLBACK_EXTENTS
= 7
3127 ObjectModDesc() : can_local_rollback(true), rollback_info_completed(false) {
3128 bl
.reassign_to_mempool(mempool::mempool_osd_pglog
);
3130 void claim(ObjectModDesc
&other
) {
3133 can_local_rollback
= other
.can_local_rollback
;
3134 rollback_info_completed
= other
.rollback_info_completed
;
3136 void claim_append(ObjectModDesc
&other
) {
3137 if (!can_local_rollback
|| rollback_info_completed
)
3139 if (!other
.can_local_rollback
) {
3140 mark_unrollbackable();
3143 bl
.claim_append(other
.bl
);
3144 rollback_info_completed
= other
.rollback_info_completed
;
3146 void swap(ObjectModDesc
&other
) {
3150 swap(other
.can_local_rollback
, can_local_rollback
);
3151 swap(other
.rollback_info_completed
, rollback_info_completed
);
3152 swap(other
.max_required_version
, max_required_version
);
3154 void append_id(ModID id
) {
3158 void append(uint64_t old_size
) {
3159 if (!can_local_rollback
|| rollback_info_completed
)
3161 ENCODE_START(1, 1, bl
);
3163 ::encode(old_size
, bl
);
3166 void setattrs(map
<string
, boost::optional
<bufferlist
> > &old_attrs
) {
3167 if (!can_local_rollback
|| rollback_info_completed
)
3169 ENCODE_START(1, 1, bl
);
3170 append_id(SETATTRS
);
3171 ::encode(old_attrs
, bl
);
3174 bool rmobject(version_t deletion_version
) {
3175 if (!can_local_rollback
|| rollback_info_completed
)
3177 ENCODE_START(1, 1, bl
);
3179 ::encode(deletion_version
, bl
);
3181 rollback_info_completed
= true;
3184 bool try_rmobject(version_t deletion_version
) {
3185 if (!can_local_rollback
|| rollback_info_completed
)
3187 ENCODE_START(1, 1, bl
);
3188 append_id(TRY_DELETE
);
3189 ::encode(deletion_version
, bl
);
3191 rollback_info_completed
= true;
3195 if (!can_local_rollback
|| rollback_info_completed
)
3197 rollback_info_completed
= true;
3198 ENCODE_START(1, 1, bl
);
3202 void update_snaps(const set
<snapid_t
> &old_snaps
) {
3203 if (!can_local_rollback
|| rollback_info_completed
)
3205 ENCODE_START(1, 1, bl
);
3206 append_id(UPDATE_SNAPS
);
3207 ::encode(old_snaps
, bl
);
3210 void rollback_extents(
3211 version_t gen
, const vector
<pair
<uint64_t, uint64_t> > &extents
) {
3212 assert(can_local_rollback
);
3213 assert(!rollback_info_completed
);
3214 if (max_required_version
< 2)
3215 max_required_version
= 2;
3216 ENCODE_START(2, 2, bl
);
3217 append_id(ROLLBACK_EXTENTS
);
3219 ::encode(extents
, bl
);
3223 // cannot be rolled back
3224 void mark_unrollbackable() {
3225 can_local_rollback
= false;
3228 bool can_rollback() const {
3229 return can_local_rollback
;
3231 bool empty() const {
3232 return can_local_rollback
&& (bl
.length() == 0);
3235 bool requires_kraken() const {
3236 return max_required_version
>= 2;
3240 * Create fresh copy of bl bytes to avoid keeping large buffers around
3241 * in the case that bl contains ptrs which point into a much larger
3244 void trim_bl() const {
3245 if (bl
.length() > 0)
3248 void encode(bufferlist
&bl
) const;
3249 void decode(bufferlist::iterator
&bl
);
3250 void dump(Formatter
*f
) const;
3251 static void generate_test_instances(list
<ObjectModDesc
*>& o
);
3253 WRITE_CLASS_ENCODER(ObjectModDesc
)
3257 * pg_log_entry_t - single entry/event in pg log
3260 struct pg_log_entry_t
{
3262 MODIFY
= 1, // some unspecified modification (but not *all* modifications)
3263 CLONE
= 2, // cloned object from head
3264 DELETE
= 3, // deleted object
3265 BACKLOG
= 4, // event invented by generate_backlog [deprecated]
3266 LOST_REVERT
= 5, // lost new version, revert to an older version.
3267 LOST_DELETE
= 6, // lost new version, revert to no object (deleted).
3268 LOST_MARK
= 7, // lost new version, now EIO
3269 PROMOTE
= 8, // promoted object from another tier
3270 CLEAN
= 9, // mark an object clean
3271 ERROR
= 10, // write that returned an error
3273 static const char *get_op_name(int op
) {
3299 const char *get_op_name() const {
3300 return get_op_name(op
);
3303 // describes state for a locally-rollbackable entry
3304 ObjectModDesc mod_desc
;
3305 bufferlist snaps
; // only for clone entries
3307 osd_reqid_t reqid
; // caller+tid to uniquely identify request
3308 mempool::osd_pglog::vector
<pair
<osd_reqid_t
, version_t
> > extra_reqids
;
3309 eversion_t version
, prior_version
, reverting_to
;
3310 version_t user_version
; // the user version for this entry
3311 utime_t mtime
; // this is the _user_ mtime, mind you
3312 int32_t return_code
; // only stored for ERRORs for dup detection
3315 bool invalid_hash
; // only when decoding sobject_t based entries
3316 bool invalid_pool
; // only when decoding pool-less hobject based entries
3319 : user_version(0), return_code(0), op(0),
3320 invalid_hash(false), invalid_pool(false) {
3321 snaps
.reassign_to_mempool(mempool::mempool_osd_pglog
);
3323 pg_log_entry_t(int _op
, const hobject_t
& _soid
,
3324 const eversion_t
& v
, const eversion_t
& pv
,
3326 const osd_reqid_t
& rid
, const utime_t
& mt
,
3328 : soid(_soid
), reqid(rid
), version(v
), prior_version(pv
), user_version(uv
),
3329 mtime(mt
), return_code(return_code
), op(_op
),
3330 invalid_hash(false), invalid_pool(false) {
3331 snaps
.reassign_to_mempool(mempool::mempool_osd_pglog
);
3334 bool is_clone() const { return op
== CLONE
; }
3335 bool is_modify() const { return op
== MODIFY
; }
3336 bool is_promote() const { return op
== PROMOTE
; }
3337 bool is_clean() const { return op
== CLEAN
; }
3338 bool is_backlog() const { return op
== BACKLOG
; }
3339 bool is_lost_revert() const { return op
== LOST_REVERT
; }
3340 bool is_lost_delete() const { return op
== LOST_DELETE
; }
3341 bool is_lost_mark() const { return op
== LOST_MARK
; }
3342 bool is_error() const { return op
== ERROR
; }
3344 bool is_update() const {
3346 is_clone() || is_modify() || is_promote() || is_clean() ||
3347 is_backlog() || is_lost_revert() || is_lost_mark();
3349 bool is_delete() const {
3350 return op
== DELETE
|| op
== LOST_DELETE
;
3353 bool can_rollback() const {
3354 return mod_desc
.can_rollback();
3357 void mark_unrollbackable() {
3358 mod_desc
.mark_unrollbackable();
3361 bool requires_kraken() const {
3362 return mod_desc
.requires_kraken();
3365 // Errors are only used for dup detection, whereas
3366 // the index by objects is used by recovery, copy_get,
3367 // and other facilities that don't expect or need to
3368 // be aware of error entries.
3369 bool object_is_indexed() const {
3373 bool reqid_is_indexed() const {
3374 return reqid
!= osd_reqid_t() &&
3375 (op
== MODIFY
|| op
== DELETE
|| op
== ERROR
);
3378 string
get_key_name() const;
3379 void encode_with_checksum(bufferlist
& bl
) const;
3380 void decode_with_checksum(bufferlist::iterator
& p
);
3382 void encode(bufferlist
&bl
) const;
3383 void decode(bufferlist::iterator
&bl
);
3384 void dump(Formatter
*f
) const;
3385 static void generate_test_instances(list
<pg_log_entry_t
*>& o
);
3388 WRITE_CLASS_ENCODER(pg_log_entry_t
)
3390 ostream
& operator<<(ostream
& out
, const pg_log_entry_t
& e
);
3395 * pg_log_t - incremental log of recent pg changes.
3397 * serves as a recovery queue for recent changes.
3401 * head - newest entry (update|delete)
3402 * tail - entry previous to oldest (update|delete) for which we have
3403 * complete negative information.
3404 * i.e. we can infer pg contents for any store whose last_update >= tail.
3406 eversion_t head
; // newest entry
3407 eversion_t tail
; // version prior to oldest
3410 // We can rollback rollback-able entries > can_rollback_to
3411 eversion_t can_rollback_to
;
3413 // always <= can_rollback_to, indicates how far stashed rollback
3414 // data can be found
3415 eversion_t rollback_info_trimmed_to
;
3418 mempool::osd_pglog::list
<pg_log_entry_t
> log
; // the actual log.
3420 pg_log_t() = default;
3421 pg_log_t(const eversion_t
&last_update
,
3422 const eversion_t
&log_tail
,
3423 const eversion_t
&can_rollback_to
,
3424 const eversion_t
&rollback_info_trimmed_to
,
3425 mempool::osd_pglog::list
<pg_log_entry_t
> &&entries
)
3426 : head(last_update
), tail(log_tail
), can_rollback_to(can_rollback_to
),
3427 rollback_info_trimmed_to(rollback_info_trimmed_to
),
3428 log(std::move(entries
)) {}
3429 pg_log_t(const eversion_t
&last_update
,
3430 const eversion_t
&log_tail
,
3431 const eversion_t
&can_rollback_to
,
3432 const eversion_t
&rollback_info_trimmed_to
,
3433 const std::list
<pg_log_entry_t
> &entries
)
3434 : head(last_update
), tail(log_tail
), can_rollback_to(can_rollback_to
),
3435 rollback_info_trimmed_to(rollback_info_trimmed_to
) {
3436 for (auto &&entry
: entries
) {
3437 log
.push_back(entry
);
3443 rollback_info_trimmed_to
= can_rollback_to
= head
= tail
= z
;
3447 eversion_t
get_rollback_info_trimmed_to() const {
3448 return rollback_info_trimmed_to
;
3450 eversion_t
get_can_rollback_to() const {
3451 return can_rollback_to
;
3455 pg_log_t
split_out_child(pg_t child_pgid
, unsigned split_bits
) {
3456 mempool::osd_pglog::list
<pg_log_entry_t
> oldlog
, childlog
;
3459 eversion_t old_tail
;
3460 unsigned mask
= ~((~0)<<split_bits
);
3461 for (auto i
= oldlog
.begin();
3464 if ((i
->soid
.get_hash() & mask
) == child_pgid
.m_seed
) {
3465 childlog
.push_back(*i
);
3476 rollback_info_trimmed_to
,
3477 std::move(childlog
));
3480 mempool::osd_pglog::list
<pg_log_entry_t
> rewind_from_head(eversion_t newhead
) {
3481 assert(newhead
>= tail
);
3483 mempool::osd_pglog::list
<pg_log_entry_t
>::iterator p
= log
.end();
3484 mempool::osd_pglog::list
<pg_log_entry_t
> divergent
;
3486 if (p
== log
.begin()) {
3487 // yikes, the whole thing is divergent!
3489 swap(divergent
, log
);
3493 if (p
->version
.version
<= newhead
.version
) {
3495 * look at eversion.version here. we want to avoid a situation like:
3496 * our log: 100'10 (0'0) m 10000004d3a.00000000/head by client4225.1:18529
3497 * new log: 122'10 (0'0) m 10000004d3a.00000000/head by client4225.1:18529
3498 * lower_bound = 100'9
3499 * i.e, same request, different version. If the eversion.version is > the
3500 * lower_bound, we it is divergent.
3503 divergent
.splice(divergent
.begin(), log
, p
, log
.end());
3506 assert(p
->version
> newhead
);
3510 if (can_rollback_to
> newhead
)
3511 can_rollback_to
= newhead
;
3513 if (rollback_info_trimmed_to
> newhead
)
3514 rollback_info_trimmed_to
= newhead
;
3519 bool empty() const {
3524 return head
.version
== 0 && head
.epoch
== 0;
3527 size_t approx_size() const {
3528 return head
.version
- tail
.version
;
3531 static void filter_log(spg_t import_pgid
, const OSDMap
&curmap
,
3532 const string
&hit_set_namespace
, const pg_log_t
&in
,
3533 pg_log_t
&out
, pg_log_t
&reject
);
3536 * copy entries from the tail of another pg_log_t
3538 * @param other pg_log_t to copy from
3539 * @param from copy entries after this version
3541 void copy_after(const pg_log_t
&other
, eversion_t from
);
3544 * copy a range of entries from another pg_log_t
3546 * @param other pg_log_t to copy from
3547 * @param from copy entries after this version
3548 * @param to up to and including this version
3550 void copy_range(const pg_log_t
&other
, eversion_t from
, eversion_t to
);
3553 * copy up to N entries
3555 * @param other source log
3556 * @param max max number of entries to copy
3558 void copy_up_to(const pg_log_t
&other
, int max
);
3560 ostream
& print(ostream
& out
) const;
3562 void encode(bufferlist
&bl
) const;
3563 void decode(bufferlist::iterator
&bl
, int64_t pool
= -1);
3564 void dump(Formatter
*f
) const;
3565 static void generate_test_instances(list
<pg_log_t
*>& o
);
3567 WRITE_CLASS_ENCODER(pg_log_t
)
3569 inline ostream
& operator<<(ostream
& out
, const pg_log_t
& log
)
3571 out
<< "log((" << log
.tail
<< "," << log
.head
<< "], crt="
3572 << log
.get_can_rollback_to() << ")";
3578 * pg_missing_t - summary of missing objects.
3580 * kept in memory, as a supplement to pg_log_t
3581 * also used to pass missing info in messages.
3583 struct pg_missing_item
{
3584 eversion_t need
, have
;
3585 pg_missing_item() {}
3586 explicit pg_missing_item(eversion_t n
) : need(n
) {} // have no old version
3587 pg_missing_item(eversion_t n
, eversion_t h
) : need(n
), have(h
) {}
3589 void encode(bufferlist
& bl
) const {
3593 void decode(bufferlist::iterator
& bl
) {
3597 void dump(Formatter
*f
) const {
3598 f
->dump_stream("need") << need
;
3599 f
->dump_stream("have") << have
;
3601 static void generate_test_instances(list
<pg_missing_item
*>& o
) {
3602 o
.push_back(new pg_missing_item
);
3603 o
.push_back(new pg_missing_item
);
3604 o
.back()->need
= eversion_t(1, 2);
3605 o
.back()->have
= eversion_t(1, 1);
3607 bool operator==(const pg_missing_item
&rhs
) const {
3608 return need
== rhs
.need
&& have
== rhs
.have
;
3610 bool operator!=(const pg_missing_item
&rhs
) const {
3611 return !(*this == rhs
);
3614 WRITE_CLASS_ENCODER(pg_missing_item
)
3615 ostream
& operator<<(ostream
& out
, const pg_missing_item
&item
);
3617 class pg_missing_const_i
{
3619 virtual const map
<hobject_t
, pg_missing_item
> &
3620 get_items() const = 0;
3621 virtual const map
<version_t
, hobject_t
> &get_rmissing() const = 0;
3622 virtual unsigned int num_missing() const = 0;
3623 virtual bool have_missing() const = 0;
3624 virtual bool is_missing(const hobject_t
& oid
, pg_missing_item
*out
= nullptr) const = 0;
3625 virtual bool is_missing(const hobject_t
& oid
, eversion_t v
) const = 0;
3626 virtual eversion_t
have_old(const hobject_t
& oid
) const = 0;
3627 virtual ~pg_missing_const_i() {}
3631 template <bool Track
>
3632 class ChangeTracker
{
3634 void changed(const hobject_t
&obj
) {}
3635 template <typename F
>
3636 void get_changed(F
&&f
) const {}
3638 bool is_clean() const {
3643 class ChangeTracker
<true> {
3644 set
<hobject_t
> _changed
;
3646 void changed(const hobject_t
&obj
) {
3647 _changed
.insert(obj
);
3649 template <typename F
>
3650 void get_changed(F
&&f
) const {
3651 for (auto const &i
: _changed
) {
3658 bool is_clean() const {
3659 return _changed
.empty();
3663 template <bool TrackChanges
>
3664 class pg_missing_set
: public pg_missing_const_i
{
3665 using item
= pg_missing_item
;
3666 map
<hobject_t
, item
> missing
; // oid -> (need v, have v)
3667 map
<version_t
, hobject_t
> rmissing
; // v -> oid
3668 ChangeTracker
<TrackChanges
> tracker
;
3671 pg_missing_set() = default;
3673 template <typename missing_type
>
3674 pg_missing_set(const missing_type
&m
) {
3675 missing
= m
.get_items();
3676 rmissing
= m
.get_rmissing();
3677 for (auto &&i
: missing
)
3678 tracker
.changed(i
.first
);
3681 const map
<hobject_t
, item
> &get_items() const override
{
3684 const map
<version_t
, hobject_t
> &get_rmissing() const override
{
3687 unsigned int num_missing() const override
{
3688 return missing
.size();
3690 bool have_missing() const override
{
3691 return !missing
.empty();
3693 bool is_missing(const hobject_t
& oid
, pg_missing_item
*out
= nullptr) const override
{
3694 auto iter
= missing
.find(oid
);
3695 if (iter
== missing
.end())
3698 *out
= iter
->second
;
3701 bool is_missing(const hobject_t
& oid
, eversion_t v
) const override
{
3702 map
<hobject_t
, item
>::const_iterator m
=
3704 if (m
== missing
.end())
3706 const item
&item(m
->second
);
3711 eversion_t
have_old(const hobject_t
& oid
) const override
{
3712 map
<hobject_t
, item
>::const_iterator m
=
3714 if (m
== missing
.end())
3715 return eversion_t();
3716 const item
&item(m
->second
);
3720 void claim(pg_missing_set
& o
) {
3721 static_assert(!TrackChanges
, "Can't use claim with TrackChanges");
3722 missing
.swap(o
.missing
);
3723 rmissing
.swap(o
.rmissing
);
3727 * this needs to be called in log order as we extend the log. it
3728 * assumes missing is accurate up through the previous log entry.
3730 void add_next_event(const pg_log_entry_t
& e
) {
3731 if (e
.is_update()) {
3732 map
<hobject_t
, item
>::iterator missing_it
;
3733 missing_it
= missing
.find(e
.soid
);
3734 bool is_missing_divergent_item
= missing_it
!= missing
.end();
3735 if (e
.prior_version
== eversion_t() || e
.is_clone()) {
3737 if (is_missing_divergent_item
) { // use iterator
3738 rmissing
.erase((missing_it
->second
).need
.version
);
3739 missing_it
->second
= item(e
.version
, eversion_t()); // .have = nil
3740 } else // create new element in missing map
3741 missing
[e
.soid
] = item(e
.version
, eversion_t()); // .have = nil
3742 } else if (is_missing_divergent_item
) {
3743 // already missing (prior).
3744 rmissing
.erase((missing_it
->second
).need
.version
);
3745 (missing_it
->second
).need
= e
.version
; // leave .have unchanged.
3746 } else if (e
.is_backlog()) {
3747 // May not have prior version
3748 assert(0 == "these don't exist anymore");
3750 // not missing, we must have prior_version (if any)
3751 assert(!is_missing_divergent_item
);
3752 missing
[e
.soid
] = item(e
.version
, e
.prior_version
);
3754 rmissing
[e
.version
.version
] = e
.soid
;
3755 } else if (e
.is_delete()) {
3756 rm(e
.soid
, e
.version
);
3759 tracker
.changed(e
.soid
);
3762 void revise_need(hobject_t oid
, eversion_t need
) {
3763 if (missing
.count(oid
)) {
3764 rmissing
.erase(missing
[oid
].need
.version
);
3765 missing
[oid
].need
= need
; // no not adjust .have
3767 missing
[oid
] = item(need
, eversion_t());
3769 rmissing
[need
.version
] = oid
;
3771 tracker
.changed(oid
);
3774 void revise_have(hobject_t oid
, eversion_t have
) {
3775 if (missing
.count(oid
)) {
3776 tracker
.changed(oid
);
3777 missing
[oid
].have
= have
;
3781 void add(const hobject_t
& oid
, eversion_t need
, eversion_t have
) {
3782 missing
[oid
] = item(need
, have
);
3783 rmissing
[need
.version
] = oid
;
3784 tracker
.changed(oid
);
3787 void rm(const hobject_t
& oid
, eversion_t v
) {
3788 std::map
<hobject_t
, item
>::iterator p
= missing
.find(oid
);
3789 if (p
!= missing
.end() && p
->second
.need
<= v
)
3793 void rm(std::map
<hobject_t
, item
>::const_iterator m
) {
3794 tracker
.changed(m
->first
);
3795 rmissing
.erase(m
->second
.need
.version
);
3799 void got(const hobject_t
& oid
, eversion_t v
) {
3800 std::map
<hobject_t
, item
>::iterator p
= missing
.find(oid
);
3801 assert(p
!= missing
.end());
3802 assert(p
->second
.need
<= v
);
3806 void got(std::map
<hobject_t
, item
>::const_iterator m
) {
3807 tracker
.changed(m
->first
);
3808 rmissing
.erase(m
->second
.need
.version
);
3814 unsigned split_bits
,
3815 pg_missing_set
*omissing
) {
3816 unsigned mask
= ~((~0)<<split_bits
);
3817 for (map
<hobject_t
, item
>::iterator i
= missing
.begin();
3820 if ((i
->first
.get_hash() & mask
) == child_pgid
.m_seed
) {
3821 omissing
->add(i
->first
, i
->second
.need
, i
->second
.have
);
3830 for (auto const &i
: missing
)
3831 tracker
.changed(i
.first
);
3836 void encode(bufferlist
&bl
) const {
3837 ENCODE_START(3, 2, bl
);
3838 ::encode(missing
, bl
);
3841 void decode(bufferlist::iterator
&bl
, int64_t pool
= -1) {
3842 for (auto const &i
: missing
)
3843 tracker
.changed(i
.first
);
3844 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl
);
3845 ::decode(missing
, bl
);
3849 // Handle hobject_t upgrade
3850 map
<hobject_t
, item
> tmp
;
3851 for (map
<hobject_t
, item
>::iterator i
=
3855 if (!i
->first
.is_max() && i
->first
.pool
== -1) {
3856 hobject_t
to_insert(i
->first
);
3857 to_insert
.pool
= pool
;
3858 tmp
[to_insert
] = i
->second
;
3864 missing
.insert(tmp
.begin(), tmp
.end());
3867 for (map
<hobject_t
,item
>::iterator it
=
3869 it
!= missing
.end();
3871 rmissing
[it
->second
.need
.version
] = it
->first
;
3872 for (auto const &i
: missing
)
3873 tracker
.changed(i
.first
);
3875 void dump(Formatter
*f
) const {
3876 f
->open_array_section("missing");
3877 for (map
<hobject_t
,item
>::const_iterator p
=
3878 missing
.begin(); p
!= missing
.end(); ++p
) {
3879 f
->open_object_section("item");
3880 f
->dump_stream("object") << p
->first
;
3886 template <typename F
>
3887 void filter_objects(F
&&f
) {
3888 for (auto i
= missing
.begin(); i
!= missing
.end();) {
3896 static void generate_test_instances(list
<pg_missing_set
*>& o
) {
3897 o
.push_back(new pg_missing_set
);
3898 o
.push_back(new pg_missing_set
);
3900 hobject_t(object_t("foo"), "foo", 123, 456, 0, ""),
3901 eversion_t(5, 6), eversion_t(5, 1));
3903 template <typename F
>
3904 void get_changed(F
&&f
) const {
3905 tracker
.get_changed(f
);
3910 bool is_clean() const {
3911 return tracker
.is_clean();
3913 template <typename missing_t
>
3914 bool debug_verify_from_init(
3915 const missing_t
&init_missing
,
3916 ostream
*oss
) const {
3919 auto check_missing(init_missing
.get_items());
3920 tracker
.get_changed([&](const hobject_t
&hoid
) {
3921 check_missing
.erase(hoid
);
3922 if (missing
.count(hoid
)) {
3923 check_missing
.insert(*(missing
.find(hoid
)));
3927 if (check_missing
.size() != missing
.size()) {
3929 *oss
<< "Size mismatch, check: " << check_missing
.size()
3930 << ", actual: " << missing
.size() << "\n";
3934 for (auto &i
: missing
) {
3935 if (!check_missing
.count(i
.first
)) {
3937 *oss
<< "check_missing missing " << i
.first
<< "\n";
3939 } else if (check_missing
[i
.first
] != i
.second
) {
3941 *oss
<< "check_missing missing item mismatch on " << i
.first
3942 << ", check: " << check_missing
[i
.first
]
3943 << ", actual: " << i
.second
<< "\n";
3948 *oss
<< "check_missing: " << check_missing
<< "\n";
3949 set
<hobject_t
> changed
;
3950 tracker
.get_changed([&](const hobject_t
&hoid
) { changed
.insert(hoid
); });
3951 *oss
<< "changed: " << changed
<< "\n";
3956 template <bool TrackChanges
>
3958 const pg_missing_set
<TrackChanges
> &c
, bufferlist
&bl
, uint64_t features
=0) {
3961 ENCODE_DUMP_POST(cl
);
3963 template <bool TrackChanges
>
3964 void decode(pg_missing_set
<TrackChanges
> &c
, bufferlist::iterator
&p
) {
3967 template <bool TrackChanges
>
3968 ostream
& operator<<(ostream
& out
, const pg_missing_set
<TrackChanges
> &missing
)
3970 out
<< "missing(" << missing
.num_missing();
3971 //if (missing.num_lost()) out << ", " << missing.num_lost() << " lost";
3976 using pg_missing_t
= pg_missing_set
<false>;
3977 using pg_missing_tracker_t
= pg_missing_set
<true>;
3981 * pg list objects response format
3984 struct pg_nls_response_t
{
3985 collection_list_handle_t handle
;
3986 list
<librados::ListObjectImpl
> entries
;
3988 void encode(bufferlist
& bl
) const {
3989 ENCODE_START(1, 1, bl
);
3990 ::encode(handle
, bl
);
3991 __u32 n
= (__u32
)entries
.size();
3993 for (list
<librados::ListObjectImpl
>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
3994 ::encode(i
->nspace
, bl
);
3995 ::encode(i
->oid
, bl
);
3996 ::encode(i
->locator
, bl
);
4000 void decode(bufferlist::iterator
& bl
) {
4001 DECODE_START(1, bl
);
4002 ::decode(handle
, bl
);
4007 librados::ListObjectImpl i
;
4008 ::decode(i
.nspace
, bl
);
4009 ::decode(i
.oid
, bl
);
4010 ::decode(i
.locator
, bl
);
4011 entries
.push_back(i
);
4015 void dump(Formatter
*f
) const {
4016 f
->dump_stream("handle") << handle
;
4017 f
->open_array_section("entries");
4018 for (list
<librados::ListObjectImpl
>::const_iterator p
= entries
.begin(); p
!= entries
.end(); ++p
) {
4019 f
->open_object_section("object");
4020 f
->dump_string("namespace", p
->nspace
);
4021 f
->dump_string("object", p
->oid
);
4022 f
->dump_string("key", p
->locator
);
4027 static void generate_test_instances(list
<pg_nls_response_t
*>& o
) {
4028 o
.push_back(new pg_nls_response_t
);
4029 o
.push_back(new pg_nls_response_t
);
4030 o
.back()->handle
= hobject_t(object_t("hi"), "key", 1, 2, -1, "");
4031 o
.back()->entries
.push_back(librados::ListObjectImpl("", "one", ""));
4032 o
.back()->entries
.push_back(librados::ListObjectImpl("", "two", "twokey"));
4033 o
.back()->entries
.push_back(librados::ListObjectImpl("", "three", ""));
4034 o
.push_back(new pg_nls_response_t
);
4035 o
.back()->handle
= hobject_t(object_t("hi"), "key", 3, 4, -1, "");
4036 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1one", ""));
4037 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1two", "n1twokey"));
4038 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1three", ""));
4039 o
.push_back(new pg_nls_response_t
);
4040 o
.back()->handle
= hobject_t(object_t("hi"), "key", 5, 6, -1, "");
4041 o
.back()->entries
.push_back(librados::ListObjectImpl("", "one", ""));
4042 o
.back()->entries
.push_back(librados::ListObjectImpl("", "two", "twokey"));
4043 o
.back()->entries
.push_back(librados::ListObjectImpl("", "three", ""));
4044 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1one", ""));
4045 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1two", "n1twokey"));
4046 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1three", ""));
4050 WRITE_CLASS_ENCODER(pg_nls_response_t
)
4052 // For backwards compatibility with older OSD requests
4053 struct pg_ls_response_t
{
4054 collection_list_handle_t handle
;
4055 list
<pair
<object_t
, string
> > entries
;
4057 void encode(bufferlist
& bl
) const {
4060 ::encode(handle
, bl
);
4061 ::encode(entries
, bl
);
4063 void decode(bufferlist::iterator
& bl
) {
4067 ::decode(handle
, bl
);
4068 ::decode(entries
, bl
);
4070 void dump(Formatter
*f
) const {
4071 f
->dump_stream("handle") << handle
;
4072 f
->open_array_section("entries");
4073 for (list
<pair
<object_t
, string
> >::const_iterator p
= entries
.begin(); p
!= entries
.end(); ++p
) {
4074 f
->open_object_section("object");
4075 f
->dump_stream("object") << p
->first
;
4076 f
->dump_string("key", p
->second
);
4081 static void generate_test_instances(list
<pg_ls_response_t
*>& o
) {
4082 o
.push_back(new pg_ls_response_t
);
4083 o
.push_back(new pg_ls_response_t
);
4084 o
.back()->handle
= hobject_t(object_t("hi"), "key", 1, 2, -1, "");
4085 o
.back()->entries
.push_back(make_pair(object_t("one"), string()));
4086 o
.back()->entries
.push_back(make_pair(object_t("two"), string("twokey")));
4090 WRITE_CLASS_ENCODER(pg_ls_response_t
)
4093 * object_copy_cursor_t
4095 struct object_copy_cursor_t
{
4096 uint64_t data_offset
;
4102 object_copy_cursor_t()
4104 attr_complete(false),
4105 data_complete(false),
4106 omap_complete(false)
4109 bool is_initial() const {
4110 return !attr_complete
&& data_offset
== 0 && omap_offset
.empty();
4112 bool is_complete() const {
4113 return attr_complete
&& data_complete
&& omap_complete
;
4116 static void generate_test_instances(list
<object_copy_cursor_t
*>& o
);
4117 void encode(bufferlist
& bl
) const;
4118 void decode(bufferlist::iterator
&bl
);
4119 void dump(Formatter
*f
) const;
4121 WRITE_CLASS_ENCODER(object_copy_cursor_t
)
4124 * object_copy_data_t
4126 * Return data from a copy request. The semantics are a little strange
4127 * as a result of the encoding's heritage.
4129 * In particular, the sender unconditionally fills in the cursor (from what
4130 * it receives and sends), the size, and the mtime, but is responsible for
4131 * figuring out whether it should put any data in the attrs, data, or
4132 * omap members (corresponding to xattrs, object data, and the omap entries)
4133 * based on external data (the client includes a max amount to return with
4134 * the copy request). The client then looks into the attrs, data, and/or omap
4135 * based on the contents of the cursor.
4137 struct object_copy_data_t
{
4139 FLAG_DATA_DIGEST
= 1<<0,
4140 FLAG_OMAP_DIGEST
= 1<<1,
4142 object_copy_cursor_t cursor
;
4145 uint32_t data_digest
, omap_digest
;
4147 map
<string
, bufferlist
> attrs
;
4149 bufferlist omap_header
;
4150 bufferlist omap_data
;
4152 /// which snaps we are defined for (if a snap and not the head)
4153 vector
<snapid_t
> snaps
;
4154 ///< latest snap seq for the object (if head)
4157 ///< recent reqids on this object
4158 mempool::osd_pglog::vector
<pair
<osd_reqid_t
, version_t
> > reqids
;
4160 uint64_t truncate_seq
;
4161 uint64_t truncate_size
;
4164 object_copy_data_t() :
4165 size((uint64_t)-1), data_digest(-1),
4166 omap_digest(-1), flags(0),
4170 static void generate_test_instances(list
<object_copy_data_t
*>& o
);
4171 void encode(bufferlist
& bl
, uint64_t features
) const;
4172 void decode(bufferlist::iterator
& bl
);
4173 void dump(Formatter
*f
) const;
4175 WRITE_CLASS_ENCODER_FEATURES(object_copy_data_t
)
4180 struct pg_create_t
{
4181 epoch_t created
; // epoch pg created
4182 pg_t parent
; // split from parent (if != pg_t())
4186 : created(0), split_bits(0) {}
4187 pg_create_t(unsigned c
, pg_t p
, int s
)
4188 : created(c
), parent(p
), split_bits(s
) {}
4190 void encode(bufferlist
&bl
) const;
4191 void decode(bufferlist::iterator
&bl
);
4192 void dump(Formatter
*f
) const;
4193 static void generate_test_instances(list
<pg_create_t
*>& o
);
4195 WRITE_CLASS_ENCODER(pg_create_t
)
4197 // -----------------------------------------
4199 struct osd_peer_stat_t
{
4202 osd_peer_stat_t() { }
4204 void encode(bufferlist
&bl
) const;
4205 void decode(bufferlist::iterator
&bl
);
4206 void dump(Formatter
*f
) const;
4207 static void generate_test_instances(list
<osd_peer_stat_t
*>& o
);
4209 WRITE_CLASS_ENCODER(osd_peer_stat_t
)
4211 ostream
& operator<<(ostream
& out
, const osd_peer_stat_t
&stat
);
4214 // -----------------------------------------
4216 class ObjectExtent
{
4218 * ObjectExtents are used for specifying IO behavior against RADOS
4219 * objects when one is using the ObjectCacher.
4221 * To use this in a real system, *every member* must be filled
4222 * out correctly. In particular, make sure to initialize the
4223 * oloc correctly, as its default values are deliberate poison
4224 * and will cause internal ObjectCacher asserts.
4226 * Similarly, your buffer_extents vector *must* specify a total
4227 * size equal to your length. If the buffer_extents inadvertently
4228 * contain less space than the length member specifies, you
4229 * will get unintelligible asserts deep in the ObjectCacher.
4231 * If you are trying to do testing and don't care about actual
4232 * RADOS function, the simplest thing to do is to initialize
4233 * the ObjectExtent (truncate_size can be 0), create a single entry
4234 * in buffer_extents matching the length, and set oloc.pool to 0.
4237 object_t oid
; // object id
4239 uint64_t offset
; // in object
4240 uint64_t length
; // in object
4241 uint64_t truncate_size
; // in object
4243 object_locator_t oloc
; // object locator (pool etc)
4245 vector
<pair
<uint64_t,uint64_t> > buffer_extents
; // off -> len. extents in buffer being mapped (may be fragmented bc of striping!)
4247 ObjectExtent() : objectno(0), offset(0), length(0), truncate_size(0) {}
4248 ObjectExtent(object_t o
, uint64_t ono
, uint64_t off
, uint64_t l
, uint64_t ts
) :
4249 oid(o
), objectno(ono
), offset(off
), length(l
), truncate_size(ts
) { }
4252 inline ostream
& operator<<(ostream
& out
, const ObjectExtent
&ex
)
4254 return out
<< "extent("
4255 << ex
.oid
<< " (" << ex
.objectno
<< ") in " << ex
.oloc
4256 << " " << ex
.offset
<< "~" << ex
.length
4257 << " -> " << ex
.buffer_extents
4266 // ---------------------------------------
4268 class OSDSuperblock
{
4270 uuid_d cluster_fsid
, osd_fsid
;
4271 int32_t whoami
; // my role in this fs.
4272 epoch_t current_epoch
; // most recent epoch
4273 epoch_t oldest_map
, newest_map
; // oldest/newest maps we have.
4276 CompatSet compat_features
;
4278 // last interval over which i mounted and was then active
4279 epoch_t mounted
; // last epoch i mounted
4280 epoch_t clean_thru
; // epoch i was active and clean thru
4284 current_epoch(0), oldest_map(0), newest_map(0), weight(0),
4285 mounted(0), clean_thru(0) {
4288 void encode(bufferlist
&bl
) const;
4289 void decode(bufferlist::iterator
&bl
);
4290 void dump(Formatter
*f
) const;
4291 static void generate_test_instances(list
<OSDSuperblock
*>& o
);
4293 WRITE_CLASS_ENCODER(OSDSuperblock
)
4295 inline ostream
& operator<<(ostream
& out
, const OSDSuperblock
& sb
)
4297 return out
<< "sb(" << sb
.cluster_fsid
4298 << " osd." << sb
.whoami
4299 << " " << sb
.osd_fsid
4300 << " e" << sb
.current_epoch
4301 << " [" << sb
.oldest_map
<< "," << sb
.newest_map
<< "]"
4302 << " lci=[" << sb
.mounted
<< "," << sb
.clean_thru
<< "]"
4315 * attached to object head. describes most recent snap context, and
4316 * set of existing clones.
4321 vector
<snapid_t
> snaps
; // descending
4322 vector
<snapid_t
> clones
; // ascending
4323 map
<snapid_t
, interval_set
<uint64_t> > clone_overlap
; // overlap w/ next newest
4324 map
<snapid_t
, uint64_t> clone_size
;
4325 map
<snapid_t
, vector
<snapid_t
>> clone_snaps
; // descending
4327 SnapSet() : seq(0), head_exists(false) {}
4328 explicit SnapSet(bufferlist
& bl
) {
4329 bufferlist::iterator p
= bl
.begin();
4333 bool is_legacy() const {
4334 return clone_snaps
.size() < clones
.size() || !head_exists
;
4337 /// populate SnapSet from a librados::snap_set_t
4338 void from_snap_set(const librados::snap_set_t
& ss
, bool legacy
);
4340 /// get space accounted to clone
4341 uint64_t get_clone_bytes(snapid_t clone
) const;
4343 void encode(bufferlist
& bl
) const;
4344 void decode(bufferlist::iterator
& bl
);
4345 void dump(Formatter
*f
) const;
4346 static void generate_test_instances(list
<SnapSet
*>& o
);
4348 SnapContext
get_ssc_as_of(snapid_t as_of
) const {
4351 for (vector
<snapid_t
>::const_iterator i
= snaps
.begin();
4355 out
.snaps
.push_back(*i
);
4360 // return min element of snaps > after, return max if no such element
4361 snapid_t
get_first_snap_after(snapid_t after
, snapid_t max
) const {
4362 for (vector
<snapid_t
>::const_reverse_iterator i
= snaps
.rbegin();
4371 SnapSet
get_filtered(const pg_pool_t
&pinfo
) const;
4372 void filter(const pg_pool_t
&pinfo
);
4374 WRITE_CLASS_ENCODER(SnapSet
)
4376 ostream
& operator<<(ostream
& out
, const SnapSet
& cs
);
4381 #define SS_ATTR "snapset"
4383 struct watch_info_t
{
4385 uint32_t timeout_seconds
;
4388 watch_info_t() : cookie(0), timeout_seconds(0) { }
4389 watch_info_t(uint64_t c
, uint32_t t
, const entity_addr_t
& a
) : cookie(c
), timeout_seconds(t
), addr(a
) {}
4391 void encode(bufferlist
& bl
, uint64_t features
) const;
4392 void decode(bufferlist::iterator
& bl
);
4393 void dump(Formatter
*f
) const;
4394 static void generate_test_instances(list
<watch_info_t
*>& o
);
4396 WRITE_CLASS_ENCODER_FEATURES(watch_info_t
)
4398 static inline bool operator==(const watch_info_t
& l
, const watch_info_t
& r
) {
4399 return l
.cookie
== r
.cookie
&& l
.timeout_seconds
== r
.timeout_seconds
4400 && l
.addr
== r
.addr
;
4403 static inline ostream
& operator<<(ostream
& out
, const watch_info_t
& w
) {
4404 return out
<< "watch(cookie " << w
.cookie
<< " " << w
.timeout_seconds
<< "s"
4405 << " " << w
.addr
<< ")";
4408 struct notify_info_t
{
4415 static inline ostream
& operator<<(ostream
& out
, const notify_info_t
& n
) {
4416 return out
<< "notify(cookie " << n
.cookie
4417 << " notify" << n
.notify_id
4418 << " " << n
.timeout
<< "s)";
4421 struct object_info_t
;
4422 struct object_manifest_t
{
4425 TYPE_REDIRECT
= 1, // start with this
4426 TYPE_CHUNKED
= 2, // do this later
4428 uint8_t type
; // redirect, chunked, ...
4429 hobject_t redirect_target
;
4431 object_manifest_t() : type(0) { }
4432 object_manifest_t(uint8_t type
, const hobject_t
& redirect_target
)
4433 : type(type
), redirect_target(redirect_target
) { }
4435 bool is_empty() const {
4436 return type
== TYPE_NONE
;
4438 bool is_redirect() const {
4439 return type
== TYPE_REDIRECT
;
4441 bool is_chunked() const {
4442 return type
== TYPE_CHUNKED
;
4444 static const char *get_type_name(uint8_t m
) {
4446 case TYPE_NONE
: return "none";
4447 case TYPE_REDIRECT
: return "redirect";
4448 case TYPE_CHUNKED
: return "chunked";
4449 default: return "unknown";
4452 const char *get_type_name() const {
4453 return get_type_name(type
);
4455 static void generate_test_instances(list
<object_manifest_t
*>& o
);
4456 void encode(bufferlist
&bl
) const;
4457 void decode(bufferlist::iterator
&bl
);
4458 void dump(Formatter
*f
) const;
4459 friend ostream
& operator<<(ostream
& out
, const object_info_t
& oi
);
4461 WRITE_CLASS_ENCODER(object_manifest_t
)
4462 ostream
& operator<<(ostream
& out
, const object_manifest_t
& oi
);
4464 struct object_info_t
{
4466 eversion_t version
, prior_version
;
4467 version_t user_version
;
4468 osd_reqid_t last_reqid
;
4472 utime_t local_mtime
; // local mtime
4474 // note: these are currently encoded into a total 16 bits; see
4475 // encode()/decode() for the weirdness.
4478 FLAG_WHITEOUT
= 1<<1, // object logically does not exist
4479 FLAG_DIRTY
= 1<<2, // object has been modified since last flushed or undirtied
4480 FLAG_OMAP
= 1 << 3, // has (or may have) some/any omap data
4481 FLAG_DATA_DIGEST
= 1 << 4, // has data crc
4482 FLAG_OMAP_DIGEST
= 1 << 5, // has omap crc
4483 FLAG_CACHE_PIN
= 1 << 6, // pin the object in cache tier
4484 FLAG_MANIFEST
= 1 << 7, // has manifest
4486 FLAG_USES_TMAP
= 1<<8, // deprecated; no longer used.
4491 static string
get_flag_string(flag_t flags
) {
4493 if (flags
& FLAG_LOST
)
4495 if (flags
& FLAG_WHITEOUT
)
4497 if (flags
& FLAG_DIRTY
)
4499 if (flags
& FLAG_USES_TMAP
)
4501 if (flags
& FLAG_OMAP
)
4503 if (flags
& FLAG_DATA_DIGEST
)
4504 s
+= "|data_digest";
4505 if (flags
& FLAG_OMAP_DIGEST
)
4506 s
+= "|omap_digest";
4507 if (flags
& FLAG_CACHE_PIN
)
4509 if (flags
& FLAG_MANIFEST
)
4515 string
get_flag_string() const {
4516 return get_flag_string(flags
);
4519 /// [clone] descending. pre-luminous; moved to SnapSet
4520 vector
<snapid_t
> legacy_snaps
;
4522 uint64_t truncate_seq
, truncate_size
;
4524 map
<pair
<uint64_t, entity_name_t
>, watch_info_t
> watchers
;
4526 // opportunistic checksums; may or may not be present
4527 __u32 data_digest
; ///< data crc32c
4528 __u32 omap_digest
; ///< omap crc32c
4530 // alloc hint attribute
4531 uint64_t expected_object_size
, expected_write_size
;
4532 uint32_t alloc_hint_flags
;
4534 struct object_manifest_t manifest
;
4536 void copy_user_bits(const object_info_t
& other
);
4538 static ps_t
legacy_object_locator_to_ps(const object_t
&oid
,
4539 const object_locator_t
&loc
);
4541 bool test_flag(flag_t f
) const {
4542 return (flags
& f
) == f
;
4544 void set_flag(flag_t f
) {
4545 flags
= (flag_t
)(flags
| f
);
4547 void clear_flag(flag_t f
) {
4548 flags
= (flag_t
)(flags
& ~f
);
4550 bool is_lost() const {
4551 return test_flag(FLAG_LOST
);
4553 bool is_whiteout() const {
4554 return test_flag(FLAG_WHITEOUT
);
4556 bool is_dirty() const {
4557 return test_flag(FLAG_DIRTY
);
4559 bool is_omap() const {
4560 return test_flag(FLAG_OMAP
);
4562 bool is_data_digest() const {
4563 return test_flag(FLAG_DATA_DIGEST
);
4565 bool is_omap_digest() const {
4566 return test_flag(FLAG_OMAP_DIGEST
);
4568 bool is_cache_pinned() const {
4569 return test_flag(FLAG_CACHE_PIN
);
4571 bool has_manifest() const {
4572 return test_flag(FLAG_MANIFEST
);
4575 void set_data_digest(__u32 d
) {
4576 set_flag(FLAG_DATA_DIGEST
);
4579 void set_omap_digest(__u32 d
) {
4580 set_flag(FLAG_OMAP_DIGEST
);
4583 void clear_data_digest() {
4584 clear_flag(FLAG_DATA_DIGEST
);
4587 void clear_omap_digest() {
4588 clear_flag(FLAG_OMAP_DIGEST
);
4592 set_data_digest(-1);
4593 set_omap_digest(-1);
4596 void encode(bufferlist
& bl
, uint64_t features
) const;
4597 void decode(bufferlist::iterator
& bl
);
4598 void decode(bufferlist
& bl
) {
4599 bufferlist::iterator p
= bl
.begin();
4602 void dump(Formatter
*f
) const;
4603 static void generate_test_instances(list
<object_info_t
*>& o
);
4605 explicit object_info_t()
4606 : user_version(0), size(0), flags((flag_t
)0),
4607 truncate_seq(0), truncate_size(0),
4608 data_digest(-1), omap_digest(-1),
4609 expected_object_size(0), expected_write_size(0),
4613 explicit object_info_t(const hobject_t
& s
)
4615 user_version(0), size(0), flags((flag_t
)0),
4616 truncate_seq(0), truncate_size(0),
4617 data_digest(-1), omap_digest(-1),
4618 expected_object_size(0), expected_write_size(0),
4622 explicit object_info_t(bufferlist
& bl
) {
4626 WRITE_CLASS_ENCODER_FEATURES(object_info_t
)
4628 ostream
& operator<<(ostream
& out
, const object_info_t
& oi
);
4633 struct ObjectRecoveryInfo
{
4638 SnapSet ss
; // only populated if soid is_snap()
4639 interval_set
<uint64_t> copy_subset
;
4640 map
<hobject_t
, interval_set
<uint64_t>> clone_subset
;
4642 ObjectRecoveryInfo() : size(0) { }
4644 static void generate_test_instances(list
<ObjectRecoveryInfo
*>& o
);
4645 void encode(bufferlist
&bl
, uint64_t features
) const;
4646 void decode(bufferlist::iterator
&bl
, int64_t pool
= -1);
4647 ostream
&print(ostream
&out
) const;
4648 void dump(Formatter
*f
) const;
4650 WRITE_CLASS_ENCODER_FEATURES(ObjectRecoveryInfo
)
4651 ostream
& operator<<(ostream
& out
, const ObjectRecoveryInfo
&inf
);
4653 struct ObjectRecoveryProgress
{
4654 uint64_t data_recovered_to
;
4655 string omap_recovered_to
;
4661 ObjectRecoveryProgress()
4662 : data_recovered_to(0),
4664 data_complete(false), omap_complete(false) { }
4666 bool is_complete(const ObjectRecoveryInfo
& info
) const {
4667 return (data_recovered_to
>= (
4668 info
.copy_subset
.empty() ?
4669 0 : info
.copy_subset
.range_end())) &&
4673 static void generate_test_instances(list
<ObjectRecoveryProgress
*>& o
);
4674 void encode(bufferlist
&bl
) const;
4675 void decode(bufferlist::iterator
&bl
);
4676 ostream
&print(ostream
&out
) const;
4677 void dump(Formatter
*f
) const;
4679 WRITE_CLASS_ENCODER(ObjectRecoveryProgress
)
4680 ostream
& operator<<(ostream
& out
, const ObjectRecoveryProgress
&prog
);
4682 struct PushReplyOp
{
4685 static void generate_test_instances(list
<PushReplyOp
*>& o
);
4686 void encode(bufferlist
&bl
) const;
4687 void decode(bufferlist::iterator
&bl
);
4688 ostream
&print(ostream
&out
) const;
4689 void dump(Formatter
*f
) const;
4691 uint64_t cost(CephContext
*cct
) const;
4693 WRITE_CLASS_ENCODER(PushReplyOp
)
4694 ostream
& operator<<(ostream
& out
, const PushReplyOp
&op
);
4699 ObjectRecoveryInfo recovery_info
;
4700 ObjectRecoveryProgress recovery_progress
;
4702 static void generate_test_instances(list
<PullOp
*>& o
);
4703 void encode(bufferlist
&bl
, uint64_t features
) const;
4704 void decode(bufferlist::iterator
&bl
);
4705 ostream
&print(ostream
&out
) const;
4706 void dump(Formatter
*f
) const;
4708 uint64_t cost(CephContext
*cct
) const;
4710 WRITE_CLASS_ENCODER_FEATURES(PullOp
)
4711 ostream
& operator<<(ostream
& out
, const PullOp
&op
);
4717 interval_set
<uint64_t> data_included
;
4718 bufferlist omap_header
;
4719 map
<string
, bufferlist
> omap_entries
;
4720 map
<string
, bufferlist
> attrset
;
4722 ObjectRecoveryInfo recovery_info
;
4723 ObjectRecoveryProgress before_progress
;
4724 ObjectRecoveryProgress after_progress
;
4726 static void generate_test_instances(list
<PushOp
*>& o
);
4727 void encode(bufferlist
&bl
, uint64_t features
) const;
4728 void decode(bufferlist::iterator
&bl
);
4729 ostream
&print(ostream
&out
) const;
4730 void dump(Formatter
*f
) const;
4732 uint64_t cost(CephContext
*cct
) const;
4734 WRITE_CLASS_ENCODER_FEATURES(PushOp
)
4735 ostream
& operator<<(ostream
& out
, const PushOp
&op
);
4739 * summarize pg contents for purposes of a scrub
4743 map
<string
,bufferptr
> attrs
;
4745 __u32 omap_digest
; ///< omap crc32c
4746 __u32 digest
; ///< data crc32c
4748 bool digest_present
:1;
4749 bool omap_digest_present
:1;
4752 bool ec_hash_mismatch
:1;
4753 bool ec_size_mismatch
:1;
4756 // Init invalid size so it won't match if we get a stat EIO error
4757 size(-1), omap_digest(0), digest(0),
4758 negative(false), digest_present(false), omap_digest_present(false),
4759 read_error(false), stat_error(false), ec_hash_mismatch(false), ec_size_mismatch(false) {}
4761 void encode(bufferlist
& bl
) const;
4762 void decode(bufferlist::iterator
& bl
);
4763 void dump(Formatter
*f
) const;
4764 static void generate_test_instances(list
<object
*>& o
);
4766 WRITE_CLASS_ENCODER(object
)
4768 map
<hobject_t
,object
> objects
;
4769 eversion_t valid_through
;
4770 eversion_t incr_since
;
4772 void merge_incr(const ScrubMap
&l
);
4773 void insert(const ScrubMap
&r
) {
4774 objects
.insert(r
.objects
.begin(), r
.objects
.end());
4776 void swap(ScrubMap
&r
) {
4778 swap(objects
, r
.objects
);
4779 swap(valid_through
, r
.valid_through
);
4780 swap(incr_since
, r
.incr_since
);
4783 void encode(bufferlist
& bl
) const;
4784 void decode(bufferlist::iterator
& bl
, int64_t pool
=-1);
4785 void dump(Formatter
*f
) const;
4786 static void generate_test_instances(list
<ScrubMap
*>& o
);
4788 WRITE_CLASS_ENCODER(ScrubMap::object
)
4789 WRITE_CLASS_ENCODER(ScrubMap
)
4796 bufferlist indata
, outdata
;
4800 memset(&op
, 0, sizeof(ceph_osd_op
));
4804 * split a bufferlist into constituent indata members of a vector of OSDOps
4806 * @param ops [out] vector of OSDOps
4807 * @param in [in] combined data buffer
4809 static void split_osd_op_vector_in_data(vector
<OSDOp
>& ops
, bufferlist
& in
);
4812 * merge indata members of a vector of OSDOp into a single bufferlist
4814 * Notably this also encodes certain other OSDOp data into the data
4815 * buffer, including the sobject_t soid.
4817 * @param ops [in] vector of OSDOps
4818 * @param out [out] combined data buffer
4820 static void merge_osd_op_vector_in_data(vector
<OSDOp
>& ops
, bufferlist
& out
);
4823 * split a bufferlist into constituent outdata members of a vector of OSDOps
4825 * @param ops [out] vector of OSDOps
4826 * @param in [in] combined data buffer
4828 static void split_osd_op_vector_out_data(vector
<OSDOp
>& ops
, bufferlist
& in
);
4831 * merge outdata members of a vector of OSDOps into a single bufferlist
4833 * @param ops [in] vector of OSDOps
4834 * @param out [out] combined data buffer
4836 static void merge_osd_op_vector_out_data(vector
<OSDOp
>& ops
, bufferlist
& out
);
4839 * Clear data as much as possible, leave minimal data for historical op dump
4841 * @param ops [in] vector of OSDOps
4843 static void clear_data(vector
<OSDOp
>& ops
);
4846 ostream
& operator<<(ostream
& out
, const OSDOp
& op
);
4848 struct watch_item_t
{
4851 uint32_t timeout_seconds
;
4854 watch_item_t() : cookie(0), timeout_seconds(0) { }
4855 watch_item_t(entity_name_t name
, uint64_t cookie
, uint32_t timeout
,
4856 const entity_addr_t
& addr
)
4857 : name(name
), cookie(cookie
), timeout_seconds(timeout
),
4860 void encode(bufferlist
&bl
, uint64_t features
) const {
4861 ENCODE_START(2, 1, bl
);
4863 ::encode(cookie
, bl
);
4864 ::encode(timeout_seconds
, bl
);
4865 ::encode(addr
, bl
, features
);
4868 void decode(bufferlist::iterator
&bl
) {
4869 DECODE_START(2, bl
);
4871 ::decode(cookie
, bl
);
4872 ::decode(timeout_seconds
, bl
);
4873 if (struct_v
>= 2) {
4879 WRITE_CLASS_ENCODER_FEATURES(watch_item_t
)
4881 struct obj_watch_item_t
{
4887 * obj list watch response format
4890 struct obj_list_watch_response_t
{
4891 list
<watch_item_t
> entries
;
4893 void encode(bufferlist
& bl
, uint64_t features
) const {
4894 ENCODE_START(1, 1, bl
);
4895 ::encode(entries
, bl
, features
);
4898 void decode(bufferlist::iterator
& bl
) {
4899 DECODE_START(1, bl
);
4900 ::decode(entries
, bl
);
4903 void dump(Formatter
*f
) const {
4904 f
->open_array_section("entries");
4905 for (list
<watch_item_t
>::const_iterator p
= entries
.begin(); p
!= entries
.end(); ++p
) {
4906 f
->open_object_section("watch");
4907 f
->dump_stream("watcher") << p
->name
;
4908 f
->dump_int("cookie", p
->cookie
);
4909 f
->dump_int("timeout", p
->timeout_seconds
);
4910 f
->open_object_section("addr");
4917 static void generate_test_instances(list
<obj_list_watch_response_t
*>& o
) {
4919 o
.push_back(new obj_list_watch_response_t
);
4920 o
.push_back(new obj_list_watch_response_t
);
4921 ea
.set_type(entity_addr_t::TYPE_LEGACY
);
4923 ea
.set_family(AF_INET
);
4924 ea
.set_in4_quad(0, 127);
4925 ea
.set_in4_quad(1, 0);
4926 ea
.set_in4_quad(2, 0);
4927 ea
.set_in4_quad(3, 1);
4929 o
.back()->entries
.push_back(watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT
, 1), 10, 30, ea
));
4931 ea
.set_in4_quad(3, 2);
4933 o
.back()->entries
.push_back(watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT
, 2), 20, 60, ea
));
4936 WRITE_CLASS_ENCODER_FEATURES(obj_list_watch_response_t
)
4940 vector
<snapid_t
> snaps
; // ascending
4941 vector
< pair
<uint64_t,uint64_t> > overlap
;
4944 clone_info() : cloneid(CEPH_NOSNAP
), size(0) {}
4946 void encode(bufferlist
& bl
) const {
4947 ENCODE_START(1, 1, bl
);
4948 ::encode(cloneid
, bl
);
4949 ::encode(snaps
, bl
);
4950 ::encode(overlap
, bl
);
4954 void decode(bufferlist::iterator
& bl
) {
4955 DECODE_START(1, bl
);
4956 ::decode(cloneid
, bl
);
4957 ::decode(snaps
, bl
);
4958 ::decode(overlap
, bl
);
4962 void dump(Formatter
*f
) const {
4963 if (cloneid
== CEPH_NOSNAP
)
4964 f
->dump_string("cloneid", "HEAD");
4966 f
->dump_unsigned("cloneid", cloneid
.val
);
4967 f
->open_array_section("snapshots");
4968 for (vector
<snapid_t
>::const_iterator p
= snaps
.begin(); p
!= snaps
.end(); ++p
) {
4969 f
->open_object_section("snap");
4970 f
->dump_unsigned("id", p
->val
);
4974 f
->open_array_section("overlaps");
4975 for (vector
< pair
<uint64_t,uint64_t> >::const_iterator q
= overlap
.begin();
4976 q
!= overlap
.end(); ++q
) {
4977 f
->open_object_section("overlap");
4978 f
->dump_unsigned("offset", q
->first
);
4979 f
->dump_unsigned("length", q
->second
);
4983 f
->dump_unsigned("size", size
);
4985 static void generate_test_instances(list
<clone_info
*>& o
) {
4986 o
.push_back(new clone_info
);
4987 o
.push_back(new clone_info
);
4988 o
.back()->cloneid
= 1;
4989 o
.back()->snaps
.push_back(1);
4990 o
.back()->overlap
.push_back(pair
<uint64_t,uint64_t>(0,4096));
4991 o
.back()->overlap
.push_back(pair
<uint64_t,uint64_t>(8192,4096));
4992 o
.back()->size
= 16384;
4993 o
.push_back(new clone_info
);
4994 o
.back()->cloneid
= CEPH_NOSNAP
;
4995 o
.back()->size
= 32768;
4998 WRITE_CLASS_ENCODER(clone_info
)
5001 * obj list snaps response format
5004 struct obj_list_snap_response_t
{
5005 vector
<clone_info
> clones
; // ascending
5008 void encode(bufferlist
& bl
) const {
5009 ENCODE_START(2, 1, bl
);
5010 ::encode(clones
, bl
);
5014 void decode(bufferlist::iterator
& bl
) {
5015 DECODE_START(2, bl
);
5016 ::decode(clones
, bl
);
5023 void dump(Formatter
*f
) const {
5024 f
->open_array_section("clones");
5025 for (vector
<clone_info
>::const_iterator p
= clones
.begin(); p
!= clones
.end(); ++p
) {
5026 f
->open_object_section("clone");
5030 f
->dump_unsigned("seq", seq
);
5033 static void generate_test_instances(list
<obj_list_snap_response_t
*>& o
) {
5034 o
.push_back(new obj_list_snap_response_t
);
5035 o
.push_back(new obj_list_snap_response_t
);
5038 cl
.snaps
.push_back(1);
5039 cl
.overlap
.push_back(pair
<uint64_t,uint64_t>(0,4096));
5040 cl
.overlap
.push_back(pair
<uint64_t,uint64_t>(8192,4096));
5042 o
.back()->clones
.push_back(cl
);
5043 cl
.cloneid
= CEPH_NOSNAP
;
5047 o
.back()->clones
.push_back(cl
);
5048 o
.back()->seq
= 123;
5052 WRITE_CLASS_ENCODER(obj_list_snap_response_t
)
5056 struct PromoteCounter
{
5057 std::atomic_ullong attempts
{0};
5058 std::atomic_ullong objects
{0};
5059 std::atomic_ullong bytes
{0};
5065 void finish(uint64_t size
) {
5070 void sample_and_attenuate(uint64_t *a
, uint64_t *o
, uint64_t *b
) {
5081 * ObjectStore full statfs information
5083 struct store_statfs_t
5085 uint64_t total
= 0; // Total bytes
5086 uint64_t available
= 0; // Free bytes available
5088 int64_t allocated
= 0; // Bytes allocated by the store
5089 int64_t stored
= 0; // Bytes actually stored by the user
5090 int64_t compressed
= 0; // Bytes stored after compression
5091 int64_t compressed_allocated
= 0; // Bytes allocated for compressed data
5092 int64_t compressed_original
= 0; // Bytes that were successfully compressed
5095 *this = store_statfs_t();
5097 bool operator ==(const store_statfs_t
& other
) const;
5098 void dump(Formatter
*f
) const;
5100 ostream
&operator<<(ostream
&lhs
, const store_statfs_t
&rhs
);