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
;
895 osd_stat_t() : kb(0), kb_used(0), kb_avail(0),
896 snap_trim_queue_len(0), num_snap_trimming(0) {}
898 void add(const osd_stat_t
& o
) {
900 kb_used
+= o
.kb_used
;
901 kb_avail
+= o
.kb_avail
;
902 snap_trim_queue_len
+= o
.snap_trim_queue_len
;
903 num_snap_trimming
+= o
.num_snap_trimming
;
904 op_queue_age_hist
.add(o
.op_queue_age_hist
);
905 os_perf_stat
.add(o
.os_perf_stat
);
907 void sub(const osd_stat_t
& o
) {
909 kb_used
-= o
.kb_used
;
910 kb_avail
-= o
.kb_avail
;
911 snap_trim_queue_len
-= o
.snap_trim_queue_len
;
912 num_snap_trimming
-= o
.num_snap_trimming
;
913 op_queue_age_hist
.sub(o
.op_queue_age_hist
);
914 os_perf_stat
.sub(o
.os_perf_stat
);
917 void dump(Formatter
*f
) const;
918 void encode(bufferlist
&bl
) const;
919 void decode(bufferlist::iterator
&bl
);
920 static void generate_test_instances(std::list
<osd_stat_t
*>& o
);
922 WRITE_CLASS_ENCODER(osd_stat_t
)
924 inline bool operator==(const osd_stat_t
& l
, const osd_stat_t
& r
) {
925 return l
.kb
== r
.kb
&&
926 l
.kb_used
== r
.kb_used
&&
927 l
.kb_avail
== r
.kb_avail
&&
928 l
.snap_trim_queue_len
== r
.snap_trim_queue_len
&&
929 l
.num_snap_trimming
== r
.num_snap_trimming
&&
930 l
.hb_peers
== r
.hb_peers
&&
931 l
.op_queue_age_hist
== r
.op_queue_age_hist
&&
932 l
.os_perf_stat
== r
.os_perf_stat
;
934 inline bool operator!=(const osd_stat_t
& l
, const osd_stat_t
& r
) {
940 inline ostream
& operator<<(ostream
& out
, const osd_stat_t
& s
) {
941 return out
<< "osd_stat(" << kb_t(s
.kb_used
) << " used, "
942 << kb_t(s
.kb_avail
) << " avail, "
943 << kb_t(s
.kb
) << " total, "
944 << "peers " << s
.hb_peers
945 << " op hist " << s
.op_queue_age_hist
.h
953 #define PG_STATE_CREATING (1<<0) // creating
954 #define PG_STATE_ACTIVE (1<<1) // i am active. (primary: replicas too)
955 #define PG_STATE_CLEAN (1<<2) // peers are complete, clean of stray replicas.
956 #define PG_STATE_DOWN (1<<4) // a needed replica is down, PG offline
957 //#define PG_STATE_REPLAY (1<<5) // crashed, waiting for replay
958 //#define PG_STATE_STRAY (1<<6) // i must notify the primary i exist.
959 //#define PG_STATE_SPLITTING (1<<7) // i am splitting
960 #define PG_STATE_SCRUBBING (1<<8) // scrubbing
961 //#define PG_STATE_SCRUBQ (1<<9) // queued for scrub
962 #define PG_STATE_DEGRADED (1<<10) // pg contains objects with reduced redundancy
963 #define PG_STATE_INCONSISTENT (1<<11) // pg replicas are inconsistent (but shouldn't be)
964 #define PG_STATE_PEERING (1<<12) // pg is (re)peering
965 #define PG_STATE_REPAIR (1<<13) // pg should repair on next scrub
966 #define PG_STATE_RECOVERING (1<<14) // pg is recovering/migrating objects
967 #define PG_STATE_BACKFILL_WAIT (1<<15) // [active] reserving backfill
968 #define PG_STATE_INCOMPLETE (1<<16) // incomplete content, peering failed.
969 #define PG_STATE_STALE (1<<17) // our state for this pg is stale, unknown.
970 #define PG_STATE_REMAPPED (1<<18) // pg is explicitly remapped to different OSDs than CRUSH
971 #define PG_STATE_DEEP_SCRUB (1<<19) // deep scrub: check CRC32 on files
972 #define PG_STATE_BACKFILL (1<<20) // [active] backfilling pg content
973 #define PG_STATE_BACKFILL_TOOFULL (1<<21) // backfill can't proceed: too full
974 #define PG_STATE_RECOVERY_WAIT (1<<22) // waiting for recovery reservations
975 #define PG_STATE_UNDERSIZED (1<<23) // pg acting < pool size
976 #define PG_STATE_ACTIVATING (1<<24) // pg is peered but not yet active
977 #define PG_STATE_PEERED (1<<25) // peered, cannot go active, can recover
978 #define PG_STATE_SNAPTRIM (1<<26) // trimming snaps
979 #define PG_STATE_SNAPTRIM_WAIT (1<<27) // queued to trim snaps
980 #define PG_STATE_RECOVERY_TOOFULL (1<<28) // recovery can't proceed: too full
982 std::string
pg_state_string(int state
);
983 std::string
pg_vector_string(const vector
<int32_t> &a
);
984 int pg_string_state(const std::string
& state
);
990 * attributes for a single pool snapshot.
992 struct pool_snap_info_t
{
997 void dump(Formatter
*f
) const;
998 void encode(bufferlist
& bl
, uint64_t features
) const;
999 void decode(bufferlist::iterator
& bl
);
1000 static void generate_test_instances(list
<pool_snap_info_t
*>& o
);
1002 WRITE_CLASS_ENCODER_FEATURES(pool_snap_info_t
)
1004 inline ostream
& operator<<(ostream
& out
, const pool_snap_info_t
& si
) {
1005 return out
<< si
.snapid
<< '(' << si
.name
<< ' ' << si
.stamp
<< ')';
1020 DEEP_SCRUB_INTERVAL
,
1022 RECOVERY_OP_PRIORITY
,
1025 COMPRESSION_ALGORITHM
,
1026 COMPRESSION_REQUIRED_RATIO
,
1027 COMPRESSION_MAX_BLOB_SIZE
,
1028 COMPRESSION_MIN_BLOB_SIZE
,
1044 opt_desc_t(key_t k
, type_t t
) : key(k
), type(t
) {}
1046 bool operator==(const opt_desc_t
& rhs
) const {
1047 return key
== rhs
.key
&& type
== rhs
.type
;
1051 typedef boost::variant
<std::string
,int,double> value_t
;
1053 static bool is_opt_name(const std::string
& name
);
1054 static opt_desc_t
get_opt_desc(const std::string
& name
);
1056 pool_opts_t() : opts() {}
1058 bool is_set(key_t key
) const;
1060 template<typename T
>
1061 void set(key_t key
, const T
&val
) {
1062 value_t value
= val
;
1066 template<typename T
>
1067 bool get(key_t key
, T
*val
) const {
1068 opts_t::const_iterator i
= opts
.find(key
);
1069 if (i
== opts
.end()) {
1072 *val
= boost::get
<T
>(i
->second
);
1076 const value_t
& get(key_t key
) const;
1078 bool unset(key_t key
);
1080 void dump(const std::string
& name
, Formatter
*f
) const;
1082 void dump(Formatter
*f
) const;
1083 void encode(bufferlist
&bl
) const;
1084 void decode(bufferlist::iterator
&bl
);
1087 typedef std::map
<key_t
, value_t
> opts_t
;
1090 friend ostream
& operator<<(ostream
& out
, const pool_opts_t
& opts
);
1092 WRITE_CLASS_ENCODER(pool_opts_t
)
1099 TYPE_REPLICATED
= 1, // replication
1100 //TYPE_RAID4 = 2, // raid4 (never implemented)
1101 TYPE_ERASURE
= 3, // erasure-coded
1103 static const char *get_type_name(int t
) {
1105 case TYPE_REPLICATED
: return "replicated";
1106 //case TYPE_RAID4: return "raid4";
1107 case TYPE_ERASURE
: return "erasure";
1108 default: return "???";
1111 const char *get_type_name() const {
1112 return get_type_name(type
);
1114 static const char* get_default_type() {
1115 return "replicated";
1119 FLAG_HASHPSPOOL
= 1<<0, // hash pg seed and pool together (instead of adding)
1120 FLAG_FULL
= 1<<1, // pool is full
1121 FLAG_EC_OVERWRITES
= 1<<2, // enables overwrites, once enabled, cannot be disabled
1122 FLAG_INCOMPLETE_CLONES
= 1<<3, // may have incomplete clones (bc we are/were an overlay)
1123 FLAG_NODELETE
= 1<<4, // pool can't be deleted
1124 FLAG_NOPGCHANGE
= 1<<5, // pool's pg and pgp num can't be changed
1125 FLAG_NOSIZECHANGE
= 1<<6, // pool's size and min size can't be changed
1126 FLAG_WRITE_FADVISE_DONTNEED
= 1<<7, // write mode with LIBRADOS_OP_FLAG_FADVISE_DONTNEED
1127 FLAG_NOSCRUB
= 1<<8, // block periodic scrub
1128 FLAG_NODEEP_SCRUB
= 1<<9, // block periodic deep-scrub
1131 static const char *get_flag_name(int f
) {
1133 case FLAG_HASHPSPOOL
: return "hashpspool";
1134 case FLAG_FULL
: return "full";
1135 case FLAG_EC_OVERWRITES
: return "ec_overwrites";
1136 case FLAG_INCOMPLETE_CLONES
: return "incomplete_clones";
1137 case FLAG_NODELETE
: return "nodelete";
1138 case FLAG_NOPGCHANGE
: return "nopgchange";
1139 case FLAG_NOSIZECHANGE
: return "nosizechange";
1140 case FLAG_WRITE_FADVISE_DONTNEED
: return "write_fadvise_dontneed";
1141 case FLAG_NOSCRUB
: return "noscrub";
1142 case FLAG_NODEEP_SCRUB
: return "nodeep-scrub";
1143 default: return "???";
1146 static string
get_flags_string(uint64_t f
) {
1148 for (unsigned n
=0; f
&& n
<64; ++n
) {
1149 if (f
& (1ull << n
)) {
1152 s
+= get_flag_name(1ull << n
);
1157 string
get_flags_string() const {
1158 return get_flags_string(flags
);
1160 static uint64_t get_flag_by_name(const string
& name
) {
1161 if (name
== "hashpspool")
1162 return FLAG_HASHPSPOOL
;
1165 if (name
== "ec_overwrites")
1166 return FLAG_EC_OVERWRITES
;
1167 if (name
== "incomplete_clones")
1168 return FLAG_INCOMPLETE_CLONES
;
1169 if (name
== "nodelete")
1170 return FLAG_NODELETE
;
1171 if (name
== "nopgchange")
1172 return FLAG_NOPGCHANGE
;
1173 if (name
== "nosizechange")
1174 return FLAG_NOSIZECHANGE
;
1175 if (name
== "write_fadvise_dontneed")
1176 return FLAG_WRITE_FADVISE_DONTNEED
;
1177 if (name
== "noscrub")
1178 return FLAG_NOSCRUB
;
1179 if (name
== "nodeep-scrub")
1180 return FLAG_NODEEP_SCRUB
;
1184 /// converts the acting/up vector to a set of pg shards
1185 void convert_to_pg_shards(const vector
<int> &from
, set
<pg_shard_t
>* to
) const;
1188 CACHEMODE_NONE
= 0, ///< no caching
1189 CACHEMODE_WRITEBACK
= 1, ///< write to cache, flush later
1190 CACHEMODE_FORWARD
= 2, ///< forward if not in cache
1191 CACHEMODE_READONLY
= 3, ///< handle reads, forward writes [not strongly consistent]
1192 CACHEMODE_READFORWARD
= 4, ///< forward reads, write to cache flush later
1193 CACHEMODE_READPROXY
= 5, ///< proxy reads, write to cache flush later
1194 CACHEMODE_PROXY
= 6, ///< proxy if not in cache
1196 static const char *get_cache_mode_name(cache_mode_t m
) {
1198 case CACHEMODE_NONE
: return "none";
1199 case CACHEMODE_WRITEBACK
: return "writeback";
1200 case CACHEMODE_FORWARD
: return "forward";
1201 case CACHEMODE_READONLY
: return "readonly";
1202 case CACHEMODE_READFORWARD
: return "readforward";
1203 case CACHEMODE_READPROXY
: return "readproxy";
1204 case CACHEMODE_PROXY
: return "proxy";
1205 default: return "unknown";
1208 static cache_mode_t
get_cache_mode_from_str(const string
& s
) {
1210 return CACHEMODE_NONE
;
1211 if (s
== "writeback")
1212 return CACHEMODE_WRITEBACK
;
1214 return CACHEMODE_FORWARD
;
1215 if (s
== "readonly")
1216 return CACHEMODE_READONLY
;
1217 if (s
== "readforward")
1218 return CACHEMODE_READFORWARD
;
1219 if (s
== "readproxy")
1220 return CACHEMODE_READPROXY
;
1222 return CACHEMODE_PROXY
;
1223 return (cache_mode_t
)-1;
1225 const char *get_cache_mode_name() const {
1226 return get_cache_mode_name(cache_mode
);
1228 bool cache_mode_requires_hit_set() const {
1229 switch (cache_mode
) {
1230 case CACHEMODE_NONE
:
1231 case CACHEMODE_FORWARD
:
1232 case CACHEMODE_READONLY
:
1233 case CACHEMODE_PROXY
:
1235 case CACHEMODE_WRITEBACK
:
1236 case CACHEMODE_READFORWARD
:
1237 case CACHEMODE_READPROXY
:
1240 assert(0 == "implement me");
1244 uint64_t flags
; ///< FLAG_*
1245 __u8 type
; ///< TYPE_*
1246 __u8 size
, min_size
; ///< number of osds in each pg
1247 __u8 crush_ruleset
; ///< crush placement rule set
1248 __u8 object_hash
; ///< hash mapping object name to ps
1250 __u32 pg_num
, pgp_num
; ///< number of pgs
1254 map
<string
,string
> properties
; ///< OBSOLETE
1255 string erasure_code_profile
; ///< name of the erasure code profile in OSDMap
1256 epoch_t last_change
; ///< most recent epoch changed, exclusing snapshot changes
1257 epoch_t last_force_op_resend
; ///< last epoch that forced clients to resend
1258 /// last epoch that forced clients to resend (pre-luminous clients only)
1259 epoch_t last_force_op_resend_preluminous
;
1260 snapid_t snap_seq
; ///< seq for per-pool snapshot
1261 epoch_t snap_epoch
; ///< osdmap epoch of last snap
1262 uint64_t auid
; ///< who owns the pg
1263 __u32 crash_replay_interval
; ///< seconds to allow clients to replay ACKed but unCOMMITted requests
1265 uint64_t quota_max_bytes
; ///< maximum number of bytes for this pool
1266 uint64_t quota_max_objects
; ///< maximum number of objects for this pool
1269 * Pool snaps (global to this pool). These define a SnapContext for
1270 * the pool, unless the client manually specifies an alternate
1273 map
<snapid_t
, pool_snap_info_t
> snaps
;
1275 * Alternatively, if we are defining non-pool snaps (e.g. via the
1276 * Ceph MDS), we must track @removed_snaps (since @snaps is not
1277 * used). Snaps and removed_snaps are to be used exclusive of each
1280 interval_set
<snapid_t
> removed_snaps
;
1282 unsigned pg_num_mask
, pgp_num_mask
;
1284 set
<uint64_t> tiers
; ///< pools that are tiers of us
1285 int64_t tier_of
; ///< pool for which we are a tier
1286 // Note that write wins for read+write ops
1287 int64_t read_tier
; ///< pool/tier for objecter to direct reads to
1288 int64_t write_tier
; ///< pool/tier for objecter to direct writes to
1289 cache_mode_t cache_mode
; ///< cache pool mode
1291 bool is_tier() const { return tier_of
>= 0; }
1292 bool has_tiers() const { return !tiers
.empty(); }
1297 clear_tier_tunables();
1299 bool has_read_tier() const { return read_tier
>= 0; }
1300 void clear_read_tier() { read_tier
= -1; }
1301 bool has_write_tier() const { return write_tier
>= 0; }
1302 void clear_write_tier() { write_tier
= -1; }
1303 void clear_tier_tunables() {
1304 if (cache_mode
!= CACHEMODE_NONE
)
1305 flags
|= FLAG_INCOMPLETE_CLONES
;
1306 cache_mode
= CACHEMODE_NONE
;
1308 target_max_bytes
= 0;
1309 target_max_objects
= 0;
1310 cache_target_dirty_ratio_micro
= 0;
1311 cache_target_dirty_high_ratio_micro
= 0;
1312 cache_target_full_ratio_micro
= 0;
1313 hit_set_params
= HitSet::Params();
1316 hit_set_grade_decay_rate
= 0;
1317 hit_set_search_last_n
= 0;
1318 grade_table
.resize(0);
1321 uint64_t target_max_bytes
; ///< tiering: target max pool size
1322 uint64_t target_max_objects
; ///< tiering: target max pool size
1324 uint32_t cache_target_dirty_ratio_micro
; ///< cache: fraction of target to leave dirty
1325 uint32_t cache_target_dirty_high_ratio_micro
; ///<cache: fraction of target to flush with high speed
1326 uint32_t cache_target_full_ratio_micro
; ///< cache: fraction of target to fill before we evict in earnest
1328 uint32_t cache_min_flush_age
; ///< minimum age (seconds) before we can flush
1329 uint32_t cache_min_evict_age
; ///< minimum age (seconds) before we can evict
1331 HitSet::Params hit_set_params
; ///< The HitSet params to use on this pool
1332 uint32_t hit_set_period
; ///< periodicity of HitSet segments (seconds)
1333 uint32_t hit_set_count
; ///< number of periods to retain
1334 bool use_gmt_hitset
; ///< use gmt to name the hitset archive object
1335 uint32_t min_read_recency_for_promote
; ///< minimum number of HitSet to check before promote on read
1336 uint32_t min_write_recency_for_promote
; ///< minimum number of HitSet to check before promote on write
1337 uint32_t hit_set_grade_decay_rate
; ///< current hit_set has highest priority on objects
1338 ///temperature count,the follow hit_set's priority decay
1339 ///by this params than pre hit_set
1340 uint32_t hit_set_search_last_n
; ///<accumulate atmost N hit_sets for temperature
1342 uint32_t stripe_width
; ///< erasure coded stripe size in bytes
1344 uint64_t expected_num_objects
; ///< expected number of objects on this pool, a value of 0 indicates
1345 ///< user does not specify any expected value
1346 bool fast_read
; ///< whether turn on fast read on the pool or not
1348 pool_opts_t opts
; ///< options
1351 vector
<uint32_t> grade_table
;
1354 uint32_t get_grade(unsigned i
) const {
1355 if (grade_table
.size() <= i
)
1357 return grade_table
[i
];
1359 void calc_grade_table() {
1360 unsigned v
= 1000000;
1361 grade_table
.resize(hit_set_count
);
1362 for (unsigned i
= 0; i
< hit_set_count
; i
++) {
1363 v
= v
* (1 - (hit_set_grade_decay_rate
/ 100.0));
1369 : flags(0), type(0), size(0), min_size(0),
1370 crush_ruleset(0), object_hash(0),
1371 pg_num(0), pgp_num(0),
1373 last_force_op_resend(0),
1374 last_force_op_resend_preluminous(0),
1375 snap_seq(0), snap_epoch(0),
1377 crash_replay_interval(0),
1378 quota_max_bytes(0), quota_max_objects(0),
1379 pg_num_mask(0), pgp_num_mask(0),
1380 tier_of(-1), read_tier(-1), write_tier(-1),
1381 cache_mode(CACHEMODE_NONE
),
1382 target_max_bytes(0), target_max_objects(0),
1383 cache_target_dirty_ratio_micro(0),
1384 cache_target_dirty_high_ratio_micro(0),
1385 cache_target_full_ratio_micro(0),
1386 cache_min_flush_age(0),
1387 cache_min_evict_age(0),
1391 use_gmt_hitset(true),
1392 min_read_recency_for_promote(0),
1393 min_write_recency_for_promote(0),
1394 hit_set_grade_decay_rate(0),
1395 hit_set_search_last_n(0),
1397 expected_num_objects(0),
1402 void dump(Formatter
*f
) const;
1404 uint64_t get_flags() const { return flags
; }
1405 bool has_flag(uint64_t f
) const { return flags
& f
; }
1406 void set_flag(uint64_t f
) { flags
|= f
; }
1407 void unset_flag(uint64_t f
) { flags
&= ~f
; }
1409 bool ec_pool() const {
1410 return type
== TYPE_ERASURE
;
1412 bool require_rollback() const {
1416 /// true if incomplete clones may be present
1417 bool allow_incomplete_clones() const {
1418 return cache_mode
!= CACHEMODE_NONE
|| has_flag(FLAG_INCOMPLETE_CLONES
);
1421 unsigned get_type() const { return type
; }
1422 unsigned get_size() const { return size
; }
1423 unsigned get_min_size() const { return min_size
; }
1424 int get_crush_ruleset() const { return crush_ruleset
; }
1425 int get_object_hash() const { return object_hash
; }
1426 const char *get_object_hash_name() const {
1427 return ceph_str_hash_name(get_object_hash());
1429 epoch_t
get_last_change() const { return last_change
; }
1430 epoch_t
get_last_force_op_resend() const { return last_force_op_resend
; }
1431 epoch_t
get_last_force_op_resend_preluminous() const {
1432 return last_force_op_resend_preluminous
;
1434 epoch_t
get_snap_epoch() const { return snap_epoch
; }
1435 snapid_t
get_snap_seq() const { return snap_seq
; }
1436 uint64_t get_auid() const { return auid
; }
1437 unsigned get_crash_replay_interval() const { return crash_replay_interval
; }
1439 void set_snap_seq(snapid_t s
) { snap_seq
= s
; }
1440 void set_snap_epoch(epoch_t e
) { snap_epoch
= e
; }
1442 void set_stripe_width(uint32_t s
) { stripe_width
= s
; }
1443 uint32_t get_stripe_width() const { return stripe_width
; }
1445 bool is_replicated() const { return get_type() == TYPE_REPLICATED
; }
1446 bool is_erasure() const { return get_type() == TYPE_ERASURE
; }
1448 bool supports_omap() const {
1449 return !(get_type() == TYPE_ERASURE
);
1452 bool requires_aligned_append() const {
1453 return is_erasure() && !has_flag(FLAG_EC_OVERWRITES
);
1455 uint64_t required_alignment() const { return stripe_width
; }
1457 bool allows_ecoverwrites() const {
1458 return has_flag(FLAG_EC_OVERWRITES
);
1461 bool can_shift_osds() const {
1462 switch (get_type()) {
1463 case TYPE_REPLICATED
:
1468 assert(0 == "unhandled pool type");
1472 unsigned get_pg_num() const { return pg_num
; }
1473 unsigned get_pgp_num() const { return pgp_num
; }
1475 unsigned get_pg_num_mask() const { return pg_num_mask
; }
1476 unsigned get_pgp_num_mask() const { return pgp_num_mask
; }
1478 // if pg_num is not a multiple of two, pgs are not equally sized.
1479 // return, for a given pg, the fraction (denominator) of the total
1480 // pool size that it represents.
1481 unsigned get_pg_num_divisor(pg_t pgid
) const;
1483 void set_pg_num(int p
) {
1487 void set_pgp_num(int p
) {
1492 void set_quota_max_bytes(uint64_t m
) {
1493 quota_max_bytes
= m
;
1495 uint64_t get_quota_max_bytes() {
1496 return quota_max_bytes
;
1499 void set_quota_max_objects(uint64_t m
) {
1500 quota_max_objects
= m
;
1502 uint64_t get_quota_max_objects() {
1503 return quota_max_objects
;
1506 void set_last_force_op_resend(uint64_t t
) {
1507 last_force_op_resend
= t
;
1508 last_force_op_resend_preluminous
= t
;
1511 void calc_pg_masks();
1514 * we have two snap modes:
1515 * - pool global snaps
1516 * - snap existence/non-existence defined by snaps[] and snap_seq
1517 * - user managed snaps
1518 * - removal governed by removed_snaps
1520 * we know which mode we're using based on whether removed_snaps is empty.
1521 * If nothing has been created, both functions report false.
1523 bool is_pool_snaps_mode() const;
1524 bool is_unmanaged_snaps_mode() const;
1525 bool is_removed_snap(snapid_t s
) const;
1528 * build set of known-removed sets from either pool snaps or
1529 * explicit removed_snaps set.
1531 void build_removed_snaps(interval_set
<snapid_t
>& rs
) const;
1532 snapid_t
snap_exists(const char *s
) const;
1533 void add_snap(const char *n
, utime_t stamp
);
1534 void add_unmanaged_snap(uint64_t& snapid
);
1535 void remove_snap(snapid_t s
);
1536 void remove_unmanaged_snap(snapid_t s
);
1538 SnapContext
get_snap_context() const;
1540 /// hash a object name+namespace key to a hash position
1541 uint32_t hash_key(const string
& key
, const string
& ns
) const;
1543 /// round a hash position down to a pg num
1544 uint32_t raw_hash_to_pg(uint32_t v
) const;
1547 * map a raw pg (with full precision ps) into an actual pg, for storage
1549 pg_t
raw_pg_to_pg(pg_t pg
) const;
1552 * map raw pg (full precision ps) into a placement seed. include
1553 * pool id in that value so that different pools don't use the same
1556 ps_t
raw_pg_to_pps(pg_t pg
) const;
1558 /// choose a random hash position within a pg
1559 uint32_t get_random_pg_position(pg_t pgid
, uint32_t seed
) const;
1561 void encode(bufferlist
& bl
, uint64_t features
) const;
1562 void decode(bufferlist::iterator
& bl
);
1564 static void generate_test_instances(list
<pg_pool_t
*>& o
);
1566 WRITE_CLASS_ENCODER_FEATURES(pg_pool_t
)
1568 ostream
& operator<<(ostream
& out
, const pg_pool_t
& p
);
1572 * a summation of object stats
1574 * This is just a container for object stats; we don't know what for.
1576 * If you add members in object_stat_sum_t, you should make sure there are
1577 * not padding among these members.
1578 * You should also modify the padding_check function.
1581 struct object_stat_sum_t
{
1582 /**************************************************************************
1583 * WARNING: be sure to update operator==, floor, and split when
1584 * adding/removing fields!
1585 **************************************************************************/
1586 int64_t num_bytes
; // in bytes
1587 int64_t num_objects
;
1588 int64_t num_object_clones
;
1589 int64_t num_object_copies
; // num_objects * num_replicas
1590 int64_t num_objects_missing_on_primary
;
1591 int64_t num_objects_degraded
;
1592 int64_t num_objects_unfound
;
1597 int64_t num_scrub_errors
; // total deep and shallow scrub errors
1598 int64_t num_objects_recovered
;
1599 int64_t num_bytes_recovered
;
1600 int64_t num_keys_recovered
;
1601 int64_t num_shallow_scrub_errors
;
1602 int64_t num_deep_scrub_errors
;
1603 int64_t num_objects_dirty
;
1604 int64_t num_whiteouts
;
1605 int64_t num_objects_omap
;
1606 int64_t num_objects_hit_set_archive
;
1607 int64_t num_objects_misplaced
;
1608 int64_t num_bytes_hit_set_archive
;
1610 int64_t num_flush_kb
;
1612 int64_t num_evict_kb
;
1613 int64_t num_promote
;
1614 int32_t num_flush_mode_high
; // 1 when in high flush mode, otherwise 0
1615 int32_t num_flush_mode_low
; // 1 when in low flush mode, otherwise 0
1616 int32_t num_evict_mode_some
; // 1 when in evict some mode, otherwise 0
1617 int32_t num_evict_mode_full
; // 1 when in evict full mode, otherwise 0
1618 int64_t num_objects_pinned
;
1619 int64_t num_objects_missing
;
1620 int64_t num_legacy_snapsets
; ///< upper bound on pre-luminous-style SnapSets
1624 num_objects(0), num_object_clones(0), num_object_copies(0),
1625 num_objects_missing_on_primary(0), num_objects_degraded(0),
1626 num_objects_unfound(0),
1627 num_rd(0), num_rd_kb(0), num_wr(0), num_wr_kb(0),
1628 num_scrub_errors(0),
1629 num_objects_recovered(0),
1630 num_bytes_recovered(0),
1631 num_keys_recovered(0),
1632 num_shallow_scrub_errors(0),
1633 num_deep_scrub_errors(0),
1634 num_objects_dirty(0),
1636 num_objects_omap(0),
1637 num_objects_hit_set_archive(0),
1638 num_objects_misplaced(0),
1639 num_bytes_hit_set_archive(0),
1645 num_flush_mode_high(0), num_flush_mode_low(0),
1646 num_evict_mode_some(0), num_evict_mode_full(0),
1647 num_objects_pinned(0),
1648 num_objects_missing(0),
1649 num_legacy_snapsets(0)
1652 void floor(int64_t f
) {
1653 #define FLOOR(x) if (x < f) x = f
1656 FLOOR(num_object_clones
);
1657 FLOOR(num_object_copies
);
1658 FLOOR(num_objects_missing_on_primary
);
1659 FLOOR(num_objects_missing
);
1660 FLOOR(num_objects_degraded
);
1661 FLOOR(num_objects_misplaced
);
1662 FLOOR(num_objects_unfound
);
1667 FLOOR(num_scrub_errors
);
1668 FLOOR(num_shallow_scrub_errors
);
1669 FLOOR(num_deep_scrub_errors
);
1670 FLOOR(num_objects_recovered
);
1671 FLOOR(num_bytes_recovered
);
1672 FLOOR(num_keys_recovered
);
1673 FLOOR(num_objects_dirty
);
1674 FLOOR(num_whiteouts
);
1675 FLOOR(num_objects_omap
);
1676 FLOOR(num_objects_hit_set_archive
);
1677 FLOOR(num_bytes_hit_set_archive
);
1679 FLOOR(num_flush_kb
);
1681 FLOOR(num_evict_kb
);
1683 FLOOR(num_flush_mode_high
);
1684 FLOOR(num_flush_mode_low
);
1685 FLOOR(num_evict_mode_some
);
1686 FLOOR(num_evict_mode_full
);
1687 FLOOR(num_objects_pinned
);
1688 FLOOR(num_legacy_snapsets
);
1692 void split(vector
<object_stat_sum_t
> &out
) const {
1693 #define SPLIT(PARAM) \
1694 for (unsigned i = 0; i < out.size(); ++i) { \
1695 out[i].PARAM = PARAM / out.size(); \
1696 if (i < (PARAM % out.size())) { \
1700 #define SPLIT_PRESERVE_NONZERO(PARAM) \
1701 for (unsigned i = 0; i < out.size(); ++i) { \
1703 out[i].PARAM = 1 + PARAM / out.size(); \
1710 SPLIT(num_object_clones
);
1711 SPLIT(num_object_copies
);
1712 SPLIT(num_objects_missing_on_primary
);
1713 SPLIT(num_objects_missing
);
1714 SPLIT(num_objects_degraded
);
1715 SPLIT(num_objects_misplaced
);
1716 SPLIT(num_objects_unfound
);
1721 SPLIT(num_scrub_errors
);
1722 SPLIT(num_shallow_scrub_errors
);
1723 SPLIT(num_deep_scrub_errors
);
1724 SPLIT(num_objects_recovered
);
1725 SPLIT(num_bytes_recovered
);
1726 SPLIT(num_keys_recovered
);
1727 SPLIT(num_objects_dirty
);
1728 SPLIT(num_whiteouts
);
1729 SPLIT(num_objects_omap
);
1730 SPLIT(num_objects_hit_set_archive
);
1731 SPLIT(num_bytes_hit_set_archive
);
1733 SPLIT(num_flush_kb
);
1735 SPLIT(num_evict_kb
);
1737 SPLIT(num_flush_mode_high
);
1738 SPLIT(num_flush_mode_low
);
1739 SPLIT(num_evict_mode_some
);
1740 SPLIT(num_evict_mode_full
);
1741 SPLIT(num_objects_pinned
);
1742 SPLIT_PRESERVE_NONZERO(num_legacy_snapsets
);
1744 #undef SPLIT_PRESERVE_NONZERO
1748 memset(this, 0, sizeof(*this));
1751 void calc_copies(int nrep
) {
1752 num_object_copies
= nrep
* num_objects
;
1755 bool is_zero() const {
1756 return mem_is_zero((char*)this, sizeof(*this));
1759 void add(const object_stat_sum_t
& o
);
1760 void sub(const object_stat_sum_t
& o
);
1762 void dump(Formatter
*f
) const;
1763 void padding_check() {
1765 sizeof(object_stat_sum_t
) ==
1767 sizeof(num_objects
) +
1768 sizeof(num_object_clones
) +
1769 sizeof(num_object_copies
) +
1770 sizeof(num_objects_missing_on_primary
) +
1771 sizeof(num_objects_degraded
) +
1772 sizeof(num_objects_unfound
) +
1777 sizeof(num_scrub_errors
) +
1778 sizeof(num_objects_recovered
) +
1779 sizeof(num_bytes_recovered
) +
1780 sizeof(num_keys_recovered
) +
1781 sizeof(num_shallow_scrub_errors
) +
1782 sizeof(num_deep_scrub_errors
) +
1783 sizeof(num_objects_dirty
) +
1784 sizeof(num_whiteouts
) +
1785 sizeof(num_objects_omap
) +
1786 sizeof(num_objects_hit_set_archive
) +
1787 sizeof(num_objects_misplaced
) +
1788 sizeof(num_bytes_hit_set_archive
) +
1790 sizeof(num_flush_kb
) +
1792 sizeof(num_evict_kb
) +
1793 sizeof(num_promote
) +
1794 sizeof(num_flush_mode_high
) +
1795 sizeof(num_flush_mode_low
) +
1796 sizeof(num_evict_mode_some
) +
1797 sizeof(num_evict_mode_full
) +
1798 sizeof(num_objects_pinned
) +
1799 sizeof(num_objects_missing
) +
1800 sizeof(num_legacy_snapsets
)
1802 "object_stat_sum_t have padding");
1804 void encode(bufferlist
& bl
) const;
1805 void decode(bufferlist::iterator
& bl
);
1806 static void generate_test_instances(list
<object_stat_sum_t
*>& o
);
1808 WRITE_CLASS_ENCODER(object_stat_sum_t
)
1810 bool operator==(const object_stat_sum_t
& l
, const object_stat_sum_t
& r
);
1813 * a collection of object stat sums
1815 * This is a collection of stat sums over different categories.
1817 struct object_stat_collection_t
{
1818 /**************************************************************************
1819 * WARNING: be sure to update the operator== when adding/removing fields! *
1820 **************************************************************************/
1821 object_stat_sum_t sum
;
1823 void calc_copies(int nrep
) {
1824 sum
.calc_copies(nrep
);
1827 void dump(Formatter
*f
) const;
1828 void encode(bufferlist
& bl
) const;
1829 void decode(bufferlist::iterator
& bl
);
1830 static void generate_test_instances(list
<object_stat_collection_t
*>& o
);
1832 bool is_zero() const {
1833 return sum
.is_zero();
1840 void floor(int64_t f
) {
1844 void add(const object_stat_sum_t
& o
) {
1848 void add(const object_stat_collection_t
& o
) {
1851 void sub(const object_stat_collection_t
& o
) {
1855 WRITE_CLASS_ENCODER(object_stat_collection_t
)
1857 inline bool operator==(const object_stat_collection_t
& l
,
1858 const object_stat_collection_t
& r
) {
1859 return l
.sum
== r
.sum
;
1864 * aggregate stats for a single PG.
1867 /**************************************************************************
1868 * WARNING: be sure to update the operator== when adding/removing fields! *
1869 **************************************************************************/
1871 version_t reported_seq
; // sequence number
1872 epoch_t reported_epoch
; // epoch of this report
1874 utime_t last_fresh
; // last reported
1875 utime_t last_change
; // new state != previous state
1876 utime_t last_active
; // state & PG_STATE_ACTIVE
1877 utime_t last_peered
; // state & PG_STATE_ACTIVE || state & PG_STATE_PEERED
1878 utime_t last_clean
; // state & PG_STATE_CLEAN
1879 utime_t last_unstale
; // (state & PG_STATE_STALE) == 0
1880 utime_t last_undegraded
; // (state & PG_STATE_DEGRADED) == 0
1881 utime_t last_fullsized
; // (state & PG_STATE_UNDERSIZED) == 0
1883 eversion_t log_start
; // (log_start,version]
1884 eversion_t ondisk_log_start
; // there may be more on disk
1887 epoch_t last_epoch_clean
;
1889 __u32 parent_split_bits
;
1891 eversion_t last_scrub
;
1892 eversion_t last_deep_scrub
;
1893 utime_t last_scrub_stamp
;
1894 utime_t last_deep_scrub_stamp
;
1895 utime_t last_clean_scrub_stamp
;
1897 object_stat_collection_t stats
;
1900 int64_t ondisk_log_size
; // >= active_log_size
1902 vector
<int32_t> up
, acting
;
1903 epoch_t mapping_epoch
;
1905 vector
<int32_t> blocked_by
; ///< osds on which the pg is blocked
1907 utime_t last_became_active
;
1908 utime_t last_became_peered
;
1910 /// up, acting primaries
1912 int32_t acting_primary
;
1914 bool stats_invalid
:1;
1915 /// true if num_objects_dirty is not accurate (because it was not
1916 /// maintained starting from pool creation)
1917 bool dirty_stats_invalid
:1;
1918 bool omap_stats_invalid
:1;
1919 bool hitset_stats_invalid
:1;
1920 bool hitset_bytes_stats_invalid
:1;
1921 bool pin_stats_invalid
:1;
1927 created(0), last_epoch_clean(0),
1928 parent_split_bits(0),
1929 log_size(0), ondisk_log_size(0),
1933 stats_invalid(false),
1934 dirty_stats_invalid(false),
1935 omap_stats_invalid(false),
1936 hitset_stats_invalid(false),
1937 hitset_bytes_stats_invalid(false),
1938 pin_stats_invalid(false)
1941 epoch_t
get_effective_last_epoch_clean() const {
1942 if (state
& PG_STATE_CLEAN
) {
1943 // we are clean as of this report, and should thus take the
1945 return reported_epoch
;
1947 return last_epoch_clean
;
1951 pair
<epoch_t
, version_t
> get_version_pair() const {
1952 return make_pair(reported_epoch
, reported_seq
);
1955 void floor(int64_t f
) {
1959 if (ondisk_log_size
< f
)
1960 ondisk_log_size
= f
;
1963 void add(const pg_stat_t
& o
) {
1965 log_size
+= o
.log_size
;
1966 ondisk_log_size
+= o
.ondisk_log_size
;
1968 void sub(const pg_stat_t
& o
) {
1970 log_size
-= o
.log_size
;
1971 ondisk_log_size
-= o
.ondisk_log_size
;
1974 bool is_acting_osd(int32_t osd
, bool primary
) const;
1975 void dump(Formatter
*f
) const;
1976 void dump_brief(Formatter
*f
) const;
1977 void encode(bufferlist
&bl
) const;
1978 void decode(bufferlist::iterator
&bl
);
1979 static void generate_test_instances(list
<pg_stat_t
*>& o
);
1981 WRITE_CLASS_ENCODER(pg_stat_t
)
1983 bool operator==(const pg_stat_t
& l
, const pg_stat_t
& r
);
1986 * summation over an entire pool
1988 struct pool_stat_t
{
1989 object_stat_collection_t stats
;
1991 int64_t ondisk_log_size
; // >= active_log_size
1992 int32_t up
; ///< number of up replicas or shards
1993 int32_t acting
; ///< number of acting replicas or shards
1995 pool_stat_t() : log_size(0), ondisk_log_size(0), up(0), acting(0)
1998 void floor(int64_t f
) {
2002 if (ondisk_log_size
< f
)
2003 ondisk_log_size
= f
;
2010 void add(const pg_stat_t
& o
) {
2012 log_size
+= o
.log_size
;
2013 ondisk_log_size
+= o
.ondisk_log_size
;
2015 acting
+= o
.acting
.size();
2017 void sub(const pg_stat_t
& o
) {
2019 log_size
-= o
.log_size
;
2020 ondisk_log_size
-= o
.ondisk_log_size
;
2022 acting
-= o
.acting
.size();
2025 bool is_zero() const {
2026 return (stats
.is_zero() &&
2028 ondisk_log_size
== 0 &&
2033 void dump(Formatter
*f
) const;
2034 void encode(bufferlist
&bl
, uint64_t features
) const;
2035 void decode(bufferlist::iterator
&bl
);
2036 static void generate_test_instances(list
<pool_stat_t
*>& o
);
2038 WRITE_CLASS_ENCODER_FEATURES(pool_stat_t
)
2041 // -----------------------------------------
2044 * pg_hit_set_info_t - information about a single recorded HitSet
2046 * Track basic metadata about a HitSet, like the nubmer of insertions
2047 * and the time range it covers.
2049 struct pg_hit_set_info_t
{
2050 utime_t begin
, end
; ///< time interval
2051 eversion_t version
; ///< version this HitSet object was written
2052 bool using_gmt
; ///< use gmt for creating the hit_set archive object name
2054 friend bool operator==(const pg_hit_set_info_t
& l
,
2055 const pg_hit_set_info_t
& r
) {
2057 l
.begin
== r
.begin
&&
2059 l
.version
== r
.version
&&
2060 l
.using_gmt
== r
.using_gmt
;
2063 explicit pg_hit_set_info_t(bool using_gmt
= true)
2064 : using_gmt(using_gmt
) {}
2066 void encode(bufferlist
&bl
) const;
2067 void decode(bufferlist::iterator
&bl
);
2068 void dump(Formatter
*f
) const;
2069 static void generate_test_instances(list
<pg_hit_set_info_t
*>& o
);
2071 WRITE_CLASS_ENCODER(pg_hit_set_info_t
)
2074 * pg_hit_set_history_t - information about a history of hitsets
2076 * Include information about the currently accumulating hit set as well
2077 * as archived/historical ones.
2079 struct pg_hit_set_history_t
{
2080 eversion_t current_last_update
; ///< last version inserted into current set
2081 list
<pg_hit_set_info_t
> history
; ///< archived sets, sorted oldest -> newest
2083 friend bool operator==(const pg_hit_set_history_t
& l
,
2084 const pg_hit_set_history_t
& r
) {
2086 l
.current_last_update
== r
.current_last_update
&&
2087 l
.history
== r
.history
;
2090 void encode(bufferlist
&bl
) const;
2091 void decode(bufferlist::iterator
&bl
);
2092 void dump(Formatter
*f
) const;
2093 static void generate_test_instances(list
<pg_hit_set_history_t
*>& o
);
2095 WRITE_CLASS_ENCODER(pg_hit_set_history_t
)
2098 // -----------------------------------------
2101 * pg_history_t - information about recent pg peering/mapping history
2103 * This is aggressively shared between OSDs to bound the amount of past
2104 * history they need to worry about.
2106 struct pg_history_t
{
2107 epoch_t epoch_created
; // epoch in which PG was created
2108 epoch_t last_epoch_started
; // lower bound on last epoch started (anywhere, not necessarily locally)
2109 epoch_t last_interval_started
; // first epoch of last_epoch_started interval
2110 epoch_t last_epoch_clean
; // lower bound on last epoch the PG was completely clean.
2111 epoch_t last_interval_clean
; // first epoch of last_epoch_clean interval
2112 epoch_t last_epoch_split
; // as parent
2113 epoch_t last_epoch_marked_full
; // pool or cluster
2116 * In the event of a map discontinuity, same_*_since may reflect the first
2117 * map the osd has seen in the new map sequence rather than the actual start
2118 * of the interval. This is ok since a discontinuity at epoch e means there
2119 * must have been a clean interval between e and now and that we cannot be
2120 * in the active set during the interval containing e.
2122 epoch_t same_up_since
; // same acting set since
2123 epoch_t same_interval_since
; // same acting AND up set since
2124 epoch_t same_primary_since
; // same primary at least back through this epoch.
2126 eversion_t last_scrub
;
2127 eversion_t last_deep_scrub
;
2128 utime_t last_scrub_stamp
;
2129 utime_t last_deep_scrub_stamp
;
2130 utime_t last_clean_scrub_stamp
;
2132 friend bool operator==(const pg_history_t
& l
, const pg_history_t
& r
) {
2134 l
.epoch_created
== r
.epoch_created
&&
2135 l
.last_epoch_started
== r
.last_epoch_started
&&
2136 l
.last_interval_started
== r
.last_interval_started
&&
2137 l
.last_epoch_clean
== r
.last_epoch_clean
&&
2138 l
.last_interval_clean
== r
.last_interval_clean
&&
2139 l
.last_epoch_split
== r
.last_epoch_split
&&
2140 l
.last_epoch_marked_full
== r
.last_epoch_marked_full
&&
2141 l
.same_up_since
== r
.same_up_since
&&
2142 l
.same_interval_since
== r
.same_interval_since
&&
2143 l
.same_primary_since
== r
.same_primary_since
&&
2144 l
.last_scrub
== r
.last_scrub
&&
2145 l
.last_deep_scrub
== r
.last_deep_scrub
&&
2146 l
.last_scrub_stamp
== r
.last_scrub_stamp
&&
2147 l
.last_deep_scrub_stamp
== r
.last_deep_scrub_stamp
&&
2148 l
.last_clean_scrub_stamp
== r
.last_clean_scrub_stamp
;
2153 last_epoch_started(0),
2154 last_interval_started(0),
2155 last_epoch_clean(0),
2156 last_interval_clean(0),
2157 last_epoch_split(0),
2158 last_epoch_marked_full(0),
2159 same_up_since(0), same_interval_since(0), same_primary_since(0) {}
2161 bool merge(const pg_history_t
&other
) {
2162 // Here, we only update the fields which cannot be calculated from the OSDmap.
2163 bool modified
= false;
2164 if (epoch_created
< other
.epoch_created
) {
2165 epoch_created
= other
.epoch_created
;
2168 if (last_epoch_started
< other
.last_epoch_started
) {
2169 last_epoch_started
= other
.last_epoch_started
;
2172 if (last_interval_started
< other
.last_interval_started
) {
2173 last_interval_started
= other
.last_interval_started
;
2176 if (last_epoch_clean
< other
.last_epoch_clean
) {
2177 last_epoch_clean
= other
.last_epoch_clean
;
2180 if (last_interval_clean
< other
.last_interval_clean
) {
2181 last_interval_clean
= other
.last_interval_clean
;
2184 if (last_epoch_split
< other
.last_epoch_split
) {
2185 last_epoch_split
= other
.last_epoch_split
;
2188 if (last_epoch_marked_full
< other
.last_epoch_marked_full
) {
2189 last_epoch_marked_full
= other
.last_epoch_marked_full
;
2192 if (other
.last_scrub
> last_scrub
) {
2193 last_scrub
= other
.last_scrub
;
2196 if (other
.last_scrub_stamp
> last_scrub_stamp
) {
2197 last_scrub_stamp
= other
.last_scrub_stamp
;
2200 if (other
.last_deep_scrub
> last_deep_scrub
) {
2201 last_deep_scrub
= other
.last_deep_scrub
;
2204 if (other
.last_deep_scrub_stamp
> last_deep_scrub_stamp
) {
2205 last_deep_scrub_stamp
= other
.last_deep_scrub_stamp
;
2208 if (other
.last_clean_scrub_stamp
> last_clean_scrub_stamp
) {
2209 last_clean_scrub_stamp
= other
.last_clean_scrub_stamp
;
2215 void encode(bufferlist
& bl
) const;
2216 void decode(bufferlist::iterator
& p
);
2217 void dump(Formatter
*f
) const;
2218 static void generate_test_instances(list
<pg_history_t
*>& o
);
2220 WRITE_CLASS_ENCODER(pg_history_t
)
2222 inline ostream
& operator<<(ostream
& out
, const pg_history_t
& h
) {
2223 return out
<< "ec=" << h
.epoch_created
2224 << " lis/c " << h
.last_interval_started
2225 << "/" << h
.last_interval_clean
2226 << " les/c/f " << h
.last_epoch_started
<< "/" << h
.last_epoch_clean
2227 << "/" << h
.last_epoch_marked_full
2228 << " " << h
.same_up_since
2229 << "/" << h
.same_interval_since
2230 << "/" << h
.same_primary_since
;
2235 * pg_info_t - summary of PG statistics.
2238 * - last_complete implies we have all objects that existed as of that
2239 * stamp, OR a newer object, OR have already applied a later delete.
2240 * - if last_complete >= log.bottom, then we know pg contents thru log.head.
2241 * otherwise, we have no idea what the pg is supposed to contain.
2245 eversion_t last_update
; ///< last object version applied to store.
2246 eversion_t last_complete
; ///< last version pg was complete through.
2247 epoch_t last_epoch_started
; ///< last epoch at which this pg started on this osd
2248 epoch_t last_interval_started
; ///< first epoch of last_epoch_started interval
2250 version_t last_user_version
; ///< last user object version applied to store
2252 eversion_t log_tail
; ///< oldest log entry.
2254 hobject_t last_backfill
; ///< objects >= this and < last_complete may be missing
2255 bool last_backfill_bitwise
; ///< true if last_backfill reflects a bitwise (vs nibblewise) sort
2257 interval_set
<snapid_t
> purged_snaps
;
2261 pg_history_t history
;
2262 pg_hit_set_history_t hit_set
;
2264 friend bool operator==(const pg_info_t
& l
, const pg_info_t
& r
) {
2267 l
.last_update
== r
.last_update
&&
2268 l
.last_complete
== r
.last_complete
&&
2269 l
.last_epoch_started
== r
.last_epoch_started
&&
2270 l
.last_interval_started
== r
.last_interval_started
&&
2271 l
.last_user_version
== r
.last_user_version
&&
2272 l
.log_tail
== r
.log_tail
&&
2273 l
.last_backfill
== r
.last_backfill
&&
2274 l
.last_backfill_bitwise
== r
.last_backfill_bitwise
&&
2275 l
.purged_snaps
== r
.purged_snaps
&&
2276 l
.stats
== r
.stats
&&
2277 l
.history
== r
.history
&&
2278 l
.hit_set
== r
.hit_set
;
2282 : last_epoch_started(0),
2283 last_interval_started(0),
2284 last_user_version(0),
2285 last_backfill(hobject_t::get_max()),
2286 last_backfill_bitwise(false)
2288 // cppcheck-suppress noExplicitConstructor
2291 last_epoch_started(0),
2292 last_interval_started(0),
2293 last_user_version(0),
2294 last_backfill(hobject_t::get_max()),
2295 last_backfill_bitwise(false)
2298 void set_last_backfill(hobject_t pos
) {
2299 last_backfill
= pos
;
2300 last_backfill_bitwise
= true;
2303 bool is_empty() const { return last_update
.version
== 0; }
2304 bool dne() const { return history
.epoch_created
== 0; }
2306 bool is_incomplete() const { return !last_backfill
.is_max(); }
2308 void encode(bufferlist
& bl
) const;
2309 void decode(bufferlist::iterator
& p
);
2310 void dump(Formatter
*f
) const;
2311 bool overlaps_with(const pg_info_t
&oinfo
) const {
2312 return last_update
> oinfo
.log_tail
?
2313 oinfo
.last_update
>= log_tail
:
2314 last_update
>= oinfo
.log_tail
;
2316 static void generate_test_instances(list
<pg_info_t
*>& o
);
2318 WRITE_CLASS_ENCODER(pg_info_t
)
2320 inline ostream
& operator<<(ostream
& out
, const pg_info_t
& pgi
)
2322 out
<< pgi
.pgid
<< "(";
2328 out
<< " v " << pgi
.last_update
;
2329 if (pgi
.last_complete
!= pgi
.last_update
)
2330 out
<< " lc " << pgi
.last_complete
;
2331 out
<< " (" << pgi
.log_tail
<< "," << pgi
.last_update
<< "]";
2333 if (pgi
.is_incomplete())
2334 out
<< " lb " << pgi
.last_backfill
2335 << (pgi
.last_backfill_bitwise
? " (bitwise)" : " (NIBBLEWISE)");
2336 //out << " c " << pgi.epoch_created;
2337 out
<< " local-lis/les=" << pgi
.last_interval_started
2338 << "/" << pgi
.last_epoch_started
;
2339 out
<< " n=" << pgi
.stats
.stats
.sum
.num_objects
;
2340 out
<< " " << pgi
.history
2346 * pg_fast_info_t - common pg_info_t fields
2348 * These are the fields of pg_info_t (and children) that are updated for
2349 * most IO operations.
2352 * Because we rely on these fields to be applied to the normal
2353 * info struct, adding a new field here that is not also new in info
2354 * means that we must set an incompat OSD feature bit!
2356 struct pg_fast_info_t
{
2357 eversion_t last_update
;
2358 eversion_t last_complete
;
2359 version_t last_user_version
;
2360 struct { // pg_stat_t stats
2362 version_t reported_seq
;
2364 utime_t last_active
;
2365 utime_t last_peered
;
2367 utime_t last_unstale
;
2368 utime_t last_undegraded
;
2369 utime_t last_fullsized
;
2370 int64_t log_size
; // (also ondisk_log_size, which has the same value)
2371 struct { // object_stat_collection_t stats;
2372 struct { // objct_stat_sum_t sum
2373 int64_t num_bytes
; // in bytes
2374 int64_t num_objects
;
2375 int64_t num_object_copies
;
2380 int64_t num_objects_dirty
;
2385 void populate_from(const pg_info_t
& info
) {
2386 last_update
= info
.last_update
;
2387 last_complete
= info
.last_complete
;
2388 last_user_version
= info
.last_user_version
;
2389 stats
.version
= info
.stats
.version
;
2390 stats
.reported_seq
= info
.stats
.reported_seq
;
2391 stats
.last_fresh
= info
.stats
.last_fresh
;
2392 stats
.last_active
= info
.stats
.last_active
;
2393 stats
.last_peered
= info
.stats
.last_peered
;
2394 stats
.last_clean
= info
.stats
.last_clean
;
2395 stats
.last_unstale
= info
.stats
.last_unstale
;
2396 stats
.last_undegraded
= info
.stats
.last_undegraded
;
2397 stats
.last_fullsized
= info
.stats
.last_fullsized
;
2398 stats
.log_size
= info
.stats
.log_size
;
2399 stats
.stats
.sum
.num_bytes
= info
.stats
.stats
.sum
.num_bytes
;
2400 stats
.stats
.sum
.num_objects
= info
.stats
.stats
.sum
.num_objects
;
2401 stats
.stats
.sum
.num_object_copies
= info
.stats
.stats
.sum
.num_object_copies
;
2402 stats
.stats
.sum
.num_rd
= info
.stats
.stats
.sum
.num_rd
;
2403 stats
.stats
.sum
.num_rd_kb
= info
.stats
.stats
.sum
.num_rd_kb
;
2404 stats
.stats
.sum
.num_wr
= info
.stats
.stats
.sum
.num_wr
;
2405 stats
.stats
.sum
.num_wr_kb
= info
.stats
.stats
.sum
.num_wr_kb
;
2406 stats
.stats
.sum
.num_objects_dirty
= info
.stats
.stats
.sum
.num_objects_dirty
;
2409 bool try_apply_to(pg_info_t
* info
) {
2410 if (last_update
<= info
->last_update
)
2412 info
->last_update
= last_update
;
2413 info
->last_complete
= last_complete
;
2414 info
->last_user_version
= last_user_version
;
2415 info
->stats
.version
= stats
.version
;
2416 info
->stats
.reported_seq
= stats
.reported_seq
;
2417 info
->stats
.last_fresh
= stats
.last_fresh
;
2418 info
->stats
.last_active
= stats
.last_active
;
2419 info
->stats
.last_peered
= stats
.last_peered
;
2420 info
->stats
.last_clean
= stats
.last_clean
;
2421 info
->stats
.last_unstale
= stats
.last_unstale
;
2422 info
->stats
.last_undegraded
= stats
.last_undegraded
;
2423 info
->stats
.last_fullsized
= stats
.last_fullsized
;
2424 info
->stats
.log_size
= stats
.log_size
;
2425 info
->stats
.ondisk_log_size
= stats
.log_size
;
2426 info
->stats
.stats
.sum
.num_bytes
= stats
.stats
.sum
.num_bytes
;
2427 info
->stats
.stats
.sum
.num_objects
= stats
.stats
.sum
.num_objects
;
2428 info
->stats
.stats
.sum
.num_object_copies
= stats
.stats
.sum
.num_object_copies
;
2429 info
->stats
.stats
.sum
.num_rd
= stats
.stats
.sum
.num_rd
;
2430 info
->stats
.stats
.sum
.num_rd_kb
= stats
.stats
.sum
.num_rd_kb
;
2431 info
->stats
.stats
.sum
.num_wr
= stats
.stats
.sum
.num_wr
;
2432 info
->stats
.stats
.sum
.num_wr_kb
= stats
.stats
.sum
.num_wr_kb
;
2433 info
->stats
.stats
.sum
.num_objects_dirty
= stats
.stats
.sum
.num_objects_dirty
;
2437 void encode(bufferlist
& bl
) const {
2438 ENCODE_START(1, 1, bl
);
2439 ::encode(last_update
, bl
);
2440 ::encode(last_complete
, bl
);
2441 ::encode(last_user_version
, bl
);
2442 ::encode(stats
.version
, bl
);
2443 ::encode(stats
.reported_seq
, bl
);
2444 ::encode(stats
.last_fresh
, bl
);
2445 ::encode(stats
.last_active
, bl
);
2446 ::encode(stats
.last_peered
, bl
);
2447 ::encode(stats
.last_clean
, bl
);
2448 ::encode(stats
.last_unstale
, bl
);
2449 ::encode(stats
.last_undegraded
, bl
);
2450 ::encode(stats
.last_fullsized
, bl
);
2451 ::encode(stats
.log_size
, bl
);
2452 ::encode(stats
.stats
.sum
.num_bytes
, bl
);
2453 ::encode(stats
.stats
.sum
.num_objects
, bl
);
2454 ::encode(stats
.stats
.sum
.num_object_copies
, bl
);
2455 ::encode(stats
.stats
.sum
.num_rd
, bl
);
2456 ::encode(stats
.stats
.sum
.num_rd_kb
, bl
);
2457 ::encode(stats
.stats
.sum
.num_wr
, bl
);
2458 ::encode(stats
.stats
.sum
.num_wr_kb
, bl
);
2459 ::encode(stats
.stats
.sum
.num_objects_dirty
, bl
);
2462 void decode(bufferlist::iterator
& p
) {
2464 ::decode(last_update
, p
);
2465 ::decode(last_complete
, p
);
2466 ::decode(last_user_version
, p
);
2467 ::decode(stats
.version
, p
);
2468 ::decode(stats
.reported_seq
, p
);
2469 ::decode(stats
.last_fresh
, p
);
2470 ::decode(stats
.last_active
, p
);
2471 ::decode(stats
.last_peered
, p
);
2472 ::decode(stats
.last_clean
, p
);
2473 ::decode(stats
.last_unstale
, p
);
2474 ::decode(stats
.last_undegraded
, p
);
2475 ::decode(stats
.last_fullsized
, p
);
2476 ::decode(stats
.log_size
, p
);
2477 ::decode(stats
.stats
.sum
.num_bytes
, p
);
2478 ::decode(stats
.stats
.sum
.num_objects
, p
);
2479 ::decode(stats
.stats
.sum
.num_object_copies
, p
);
2480 ::decode(stats
.stats
.sum
.num_rd
, p
);
2481 ::decode(stats
.stats
.sum
.num_rd_kb
, p
);
2482 ::decode(stats
.stats
.sum
.num_wr
, p
);
2483 ::decode(stats
.stats
.sum
.num_wr_kb
, p
);
2484 ::decode(stats
.stats
.sum
.num_objects_dirty
, p
);
2488 WRITE_CLASS_ENCODER(pg_fast_info_t
)
2491 struct pg_notify_t
{
2492 epoch_t query_epoch
;
2498 query_epoch(0), epoch_sent(0), to(shard_id_t::NO_SHARD
),
2499 from(shard_id_t::NO_SHARD
) {}
2503 epoch_t query_epoch
,
2505 const pg_info_t
&info
)
2506 : query_epoch(query_epoch
),
2507 epoch_sent(epoch_sent
),
2508 info(info
), to(to
), from(from
) {
2509 assert(from
== info
.pgid
.shard
);
2511 void encode(bufferlist
&bl
) const;
2512 void decode(bufferlist::iterator
&p
);
2513 void dump(Formatter
*f
) const;
2514 static void generate_test_instances(list
<pg_notify_t
*> &o
);
2516 WRITE_CLASS_ENCODER(pg_notify_t
)
2517 ostream
&operator<<(ostream
&lhs
, const pg_notify_t
¬ify
);
2522 * PastIntervals -- information needed to determine the PriorSet and
2523 * the might_have_unfound set
2525 class PastIntervals
{
2527 struct pg_interval_t
{
2528 vector
<int32_t> up
, acting
;
2529 epoch_t first
, last
;
2535 : first(0), last(0),
2536 maybe_went_rw(false),
2542 vector
<int32_t> &&up
,
2543 vector
<int32_t> &&acting
,
2549 : up(up
), acting(acting
), first(first
), last(last
),
2550 maybe_went_rw(maybe_went_rw
), primary(primary
), up_primary(up_primary
)
2553 void encode(bufferlist
& bl
) const;
2554 void decode(bufferlist::iterator
& bl
);
2555 void dump(Formatter
*f
) const;
2556 static void generate_test_instances(list
<pg_interval_t
*>& o
);
2559 PastIntervals() = default;
2560 PastIntervals(bool ec_pool
, const OSDMap
&osdmap
) : PastIntervals() {
2561 update_type_from_map(ec_pool
, osdmap
);
2563 PastIntervals(bool ec_pool
, bool compact
) : PastIntervals() {
2564 update_type(ec_pool
, compact
);
2566 PastIntervals(PastIntervals
&&rhs
) = default;
2567 PastIntervals
&operator=(PastIntervals
&&rhs
) = default;
2569 PastIntervals(const PastIntervals
&rhs
);
2570 PastIntervals
&operator=(const PastIntervals
&rhs
);
2572 class interval_rep
{
2574 virtual size_t size() const = 0;
2575 virtual bool empty() const = 0;
2576 virtual void clear() = 0;
2577 virtual pair
<epoch_t
, epoch_t
> get_bounds() const = 0;
2578 virtual set
<pg_shard_t
> get_all_participants(
2579 bool ec_pool
) const = 0;
2580 virtual void add_interval(bool ec_pool
, const pg_interval_t
&interval
) = 0;
2581 virtual unique_ptr
<interval_rep
> clone() const = 0;
2582 virtual ostream
&print(ostream
&out
) const = 0;
2583 virtual void encode(bufferlist
&bl
) const = 0;
2584 virtual void decode(bufferlist::iterator
&bl
) = 0;
2585 virtual void dump(Formatter
*f
) const = 0;
2586 virtual bool is_classic() const = 0;
2587 virtual void iterate_mayberw_back_to(
2590 std::function
<void(epoch_t
, const set
<pg_shard_t
> &)> &&f
) const = 0;
2592 virtual bool has_full_intervals() const { return false; }
2593 virtual void iterate_all_intervals(
2594 std::function
<void(const pg_interval_t
&)> &&f
) const {
2595 assert(!has_full_intervals());
2596 assert(0 == "not valid for this implementation");
2599 virtual ~interval_rep() {}
2601 friend class pi_simple_rep
;
2602 friend class pi_compact_rep
;
2605 unique_ptr
<interval_rep
> past_intervals
;
2607 PastIntervals(interval_rep
*rep
) : past_intervals(rep
) {}
2610 void add_interval(bool ec_pool
, const pg_interval_t
&interval
) {
2611 assert(past_intervals
);
2612 return past_intervals
->add_interval(ec_pool
, interval
);
2615 bool is_classic() const {
2616 assert(past_intervals
);
2617 return past_intervals
->is_classic();
2620 void encode(bufferlist
&bl
) const {
2621 ENCODE_START(1, 1, bl
);
2622 if (past_intervals
) {
2623 __u8 type
= is_classic() ? 1 : 2;
2625 past_intervals
->encode(bl
);
2627 ::encode((__u8
)0, bl
);
2631 void encode_classic(bufferlist
&bl
) const {
2632 if (past_intervals
) {
2633 assert(past_intervals
->is_classic());
2634 past_intervals
->encode(bl
);
2637 ::encode((uint32_t)0, bl
);
2641 void decode(bufferlist::iterator
&bl
);
2642 void decode_classic(bufferlist::iterator
&bl
);
2644 void dump(Formatter
*f
) const {
2645 assert(past_intervals
);
2646 past_intervals
->dump(f
);
2648 static void generate_test_instances(list
<PastIntervals
*> & o
);
2651 * Determines whether there is an interval change
2653 static bool is_new_interval(
2654 int old_acting_primary
,
2655 int new_acting_primary
,
2656 const vector
<int> &old_acting
,
2657 const vector
<int> &new_acting
,
2660 const vector
<int> &old_up
,
2661 const vector
<int> &new_up
,
2666 unsigned old_pg_num
,
2667 unsigned new_pg_num
,
2668 bool old_sort_bitwise
,
2669 bool new_sort_bitwise
,
2674 * Determines whether there is an interval change
2676 static bool is_new_interval(
2677 int old_acting_primary
, ///< [in] primary as of lastmap
2678 int new_acting_primary
, ///< [in] primary as of lastmap
2679 const vector
<int> &old_acting
, ///< [in] acting as of lastmap
2680 const vector
<int> &new_acting
, ///< [in] acting as of osdmap
2681 int old_up_primary
, ///< [in] up primary of lastmap
2682 int new_up_primary
, ///< [in] up primary of osdmap
2683 const vector
<int> &old_up
, ///< [in] up as of lastmap
2684 const vector
<int> &new_up
, ///< [in] up as of osdmap
2685 ceph::shared_ptr
<const OSDMap
> osdmap
, ///< [in] current map
2686 ceph::shared_ptr
<const OSDMap
> lastmap
, ///< [in] last map
2687 pg_t pgid
///< [in] pgid for pg
2691 * Integrates a new map into *past_intervals, returns true
2692 * if an interval was closed out.
2694 static bool check_new_interval(
2695 int old_acting_primary
, ///< [in] primary as of lastmap
2696 int new_acting_primary
, ///< [in] primary as of osdmap
2697 const vector
<int> &old_acting
, ///< [in] acting as of lastmap
2698 const vector
<int> &new_acting
, ///< [in] acting as of osdmap
2699 int old_up_primary
, ///< [in] up primary of lastmap
2700 int new_up_primary
, ///< [in] up primary of osdmap
2701 const vector
<int> &old_up
, ///< [in] up as of lastmap
2702 const vector
<int> &new_up
, ///< [in] up as of osdmap
2703 epoch_t same_interval_since
, ///< [in] as of osdmap
2704 epoch_t last_epoch_clean
, ///< [in] current
2705 ceph::shared_ptr
<const OSDMap
> osdmap
, ///< [in] current map
2706 ceph::shared_ptr
<const OSDMap
> lastmap
, ///< [in] last map
2707 pg_t pgid
, ///< [in] pgid for pg
2708 IsPGRecoverablePredicate
*could_have_gone_active
, /// [in] predicate whether the pg can be active
2709 PastIntervals
*past_intervals
, ///< [out] intervals
2710 ostream
*out
= 0 ///< [out] debug ostream
2712 friend ostream
& operator<<(ostream
& out
, const PastIntervals
&i
);
2714 template <typename F
>
2715 void iterate_mayberw_back_to(
2719 assert(past_intervals
);
2720 past_intervals
->iterate_mayberw_back_to(ec_pool
, les
, std::forward
<F
>(f
));
2723 assert(past_intervals
);
2724 past_intervals
->clear();
2728 * Should return a value which gives an indication of the amount
2729 * of state contained
2731 size_t size() const {
2732 assert(past_intervals
);
2733 return past_intervals
->size();
2736 bool empty() const {
2737 assert(past_intervals
);
2738 return past_intervals
->empty();
2741 void swap(PastIntervals
&other
) {
2742 ::swap(other
.past_intervals
, past_intervals
);
2746 * Return all shards which have been in the acting set back to the
2747 * latest epoch to which we have trimmed except for pg_whoami
2749 set
<pg_shard_t
> get_might_have_unfound(
2750 pg_shard_t pg_whoami
,
2751 bool ec_pool
) const {
2752 assert(past_intervals
);
2753 auto ret
= past_intervals
->get_all_participants(ec_pool
);
2754 ret
.erase(pg_whoami
);
2759 * Return all shards which we might want to talk to for peering
2761 set
<pg_shard_t
> get_all_probe(
2762 bool ec_pool
) const {
2763 assert(past_intervals
);
2764 return past_intervals
->get_all_participants(ec_pool
);
2767 /* Return the set of epochs [start, end) represented by the
2768 * past_interval set.
2770 pair
<epoch_t
, epoch_t
> get_bounds() const {
2771 assert(past_intervals
);
2772 return past_intervals
->get_bounds();
2782 bool ec_pool
= false;
2783 set
<pg_shard_t
> probe
; /// current+prior OSDs we need to probe.
2784 set
<int> down
; /// down osds that would normally be in @a probe and might be interesting.
2785 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
2787 bool pg_down
= false; /// some down osds are included in @a cur; the DOWN pg state bit should be set.
2788 unique_ptr
<IsPGRecoverablePredicate
> pcontdec
;
2790 PriorSet() = default;
2791 PriorSet(PriorSet
&&) = default;
2792 PriorSet
&operator=(PriorSet
&&) = default;
2794 PriorSet
&operator=(const PriorSet
&) = delete;
2795 PriorSet(const PriorSet
&) = delete;
2797 bool operator==(const PriorSet
&rhs
) const {
2798 return (ec_pool
== rhs
.ec_pool
) &&
2799 (probe
== rhs
.probe
) &&
2800 (down
== rhs
.down
) &&
2801 (blocked_by
== rhs
.blocked_by
) &&
2802 (pg_down
== rhs
.pg_down
);
2805 bool affected_by_map(
2806 const OSDMap
&osdmap
,
2807 const DoutPrefixProvider
*dpp
) const;
2809 // For verifying tests
2812 set
<pg_shard_t
> probe
,
2814 map
<int, epoch_t
> blocked_by
,
2816 IsPGRecoverablePredicate
*pcontdec
)
2817 : ec_pool(ec_pool
), probe(probe
), down(down
), blocked_by(blocked_by
),
2818 pg_down(pg_down
), pcontdec(pcontdec
) {}
2821 template <typename F
>
2823 const PastIntervals
&past_intervals
,
2825 epoch_t last_epoch_started
,
2826 IsPGRecoverablePredicate
*c
,
2828 const vector
<int> &up
,
2829 const vector
<int> &acting
,
2830 const DoutPrefixProvider
*dpp
);
2832 friend class PastIntervals
;
2835 void update_type(bool ec_pool
, bool compact
);
2836 void update_type_from_map(bool ec_pool
, const OSDMap
&osdmap
);
2838 template <typename
... Args
>
2839 PriorSet
get_prior_set(Args
&&... args
) const {
2840 return PriorSet(*this, std::forward
<Args
>(args
)...);
2843 WRITE_CLASS_ENCODER(PastIntervals
)
2845 ostream
& operator<<(ostream
& out
, const PastIntervals::pg_interval_t
& i
);
2846 ostream
& operator<<(ostream
& out
, const PastIntervals
&i
);
2847 ostream
& operator<<(ostream
& out
, const PastIntervals::PriorSet
&i
);
2849 template <typename F
>
2850 PastIntervals::PriorSet::PriorSet(
2851 const PastIntervals
&past_intervals
,
2853 epoch_t last_epoch_started
,
2854 IsPGRecoverablePredicate
*c
,
2856 const vector
<int> &up
,
2857 const vector
<int> &acting
,
2858 const DoutPrefixProvider
*dpp
)
2859 : ec_pool(ec_pool
), pg_down(false), pcontdec(c
)
2862 * We have to be careful to gracefully deal with situations like
2863 * so. Say we have a power outage or something that takes out both
2864 * OSDs, but the monitor doesn't mark them down in the same epoch.
2865 * The history may look like
2869 * 3: let's say B dies for good, too (say, from the power spike)
2872 * which makes it look like B may have applied updates to the PG
2873 * that we need in order to proceed. This sucks...
2875 * To minimize the risk of this happening, we CANNOT go active if
2876 * _any_ OSDs in the prior set are down until we send an MOSDAlive
2877 * to the monitor such that the OSDMap sets osd_up_thru to an epoch.
2878 * Then, we have something like
2885 * -> we can ignore B, bc it couldn't have gone active (alive_thru
2896 * -> we must wait for B, bc it was alive through 2, and could have
2897 * written to the pg.
2899 * If B is really dead, then an administrator will need to manually
2900 * intervene by marking the OSD as "lost."
2903 // Include current acting and up nodes... not because they may
2904 // contain old data (this interval hasn't gone active, obviously),
2905 // but because we want their pg_info to inform choose_acting(), and
2906 // so that we know what they do/do not have explicitly before
2907 // sending them any new info/logs/whatever.
2908 for (unsigned i
= 0; i
< acting
.size(); i
++) {
2909 if (acting
[i
] != 0x7fffffff /* CRUSH_ITEM_NONE, can't import crush.h here */)
2910 probe
.insert(pg_shard_t(acting
[i
], ec_pool
? shard_id_t(i
) : shard_id_t::NO_SHARD
));
2912 // It may be possible to exclude the up nodes, but let's keep them in
2914 for (unsigned i
= 0; i
< up
.size(); i
++) {
2915 if (up
[i
] != 0x7fffffff /* CRUSH_ITEM_NONE, can't import crush.h here */)
2916 probe
.insert(pg_shard_t(up
[i
], ec_pool
? shard_id_t(i
) : shard_id_t::NO_SHARD
));
2919 set
<pg_shard_t
> all_probe
= past_intervals
.get_all_probe(ec_pool
);
2920 ldpp_dout(dpp
, 10) << "build_prior all_probe " << all_probe
<< dendl
;
2921 for (auto &&i
: all_probe
) {
2922 switch (f(0, i
.osd
, nullptr)) {
2936 past_intervals
.iterate_mayberw_back_to(
2939 [&](epoch_t start
, const set
<pg_shard_t
> &acting
) {
2940 ldpp_dout(dpp
, 10) << "build_prior maybe_rw interval:" << start
2941 << ", acting: " << acting
<< dendl
;
2943 // look at candidate osds during this interval. each falls into
2944 // one of three categories: up, down (but potentially
2945 // interesting), or lost (down, but we won't wait for it).
2946 set
<pg_shard_t
> up_now
;
2947 map
<int, epoch_t
> candidate_blocked_by
;
2948 // any candidates down now (that might have useful data)
2949 bool any_down_now
= false;
2951 // consider ACTING osds
2952 for (auto &&so
: acting
) {
2953 epoch_t lost_at
= 0;
2954 switch (f(start
, so
.osd
, &lost_at
)) {
2956 // include past acting osds if they are up.
2961 ldpp_dout(dpp
, 10) << "build_prior prior osd." << so
.osd
2962 << " no longer exists" << dendl
;
2966 ldpp_dout(dpp
, 10) << "build_prior prior osd." << so
.osd
2967 << " is down, but lost_at " << lost_at
<< dendl
;
2972 ldpp_dout(dpp
, 10) << "build_prior prior osd." << so
.osd
2973 << " is down" << dendl
;
2974 candidate_blocked_by
[so
.osd
] = lost_at
;
2975 any_down_now
= true;
2981 // if not enough osds survived this interval, and we may have gone rw,
2982 // then we need to wait for one of those osds to recover to
2983 // ensure that we haven't lost any information.
2984 if (!(*pcontdec
)(up_now
) && any_down_now
) {
2985 // fixme: how do we identify a "clean" shutdown anyway?
2986 ldpp_dout(dpp
, 10) << "build_prior possibly went active+rw,"
2987 << " insufficient up; including down osds" << dendl
;
2988 assert(!candidate_blocked_by
.empty());
2991 candidate_blocked_by
.begin(),
2992 candidate_blocked_by
.end());
2996 ldpp_dout(dpp
, 10) << "build_prior final: probe " << probe
2998 << " blocked_by " << blocked_by
2999 << (pg_down
? " pg_down":"")
3004 * pg_query_t - used to ask a peer for information about a pg.
3006 * note: if version=0, type=LOG, then we just provide our full log.
3015 const char *get_type_name() const {
3017 case INFO
: return "info";
3018 case LOG
: return "log";
3019 case MISSING
: return "missing";
3020 case FULLLOG
: return "fulllog";
3021 default: return "???";
3027 pg_history_t history
;
3032 pg_query_t() : type(-1), epoch_sent(0), to(shard_id_t::NO_SHARD
),
3033 from(shard_id_t::NO_SHARD
) {}
3038 const pg_history_t
& h
,
3042 epoch_sent(epoch_sent
),
3043 to(to
), from(from
) {
3051 const pg_history_t
& h
,
3053 : type(t
), since(s
), history(h
),
3054 epoch_sent(epoch_sent
), to(to
), from(from
) {
3058 void encode(bufferlist
&bl
, uint64_t features
) const;
3059 void decode(bufferlist::iterator
&bl
);
3061 void dump(Formatter
*f
) const;
3062 static void generate_test_instances(list
<pg_query_t
*>& o
);
3064 WRITE_CLASS_ENCODER_FEATURES(pg_query_t
)
3066 inline ostream
& operator<<(ostream
& out
, const pg_query_t
& q
) {
3067 out
<< "query(" << q
.get_type_name() << " " << q
.since
;
3068 if (q
.type
== pg_query_t::LOG
)
3069 out
<< " " << q
.history
;
3075 class ObjectModDesc
{
3076 bool can_local_rollback
;
3077 bool rollback_info_completed
;
3079 // version required to decode, reflected in encode/decode version
3080 __u8 max_required_version
= 1;
3084 virtual void append(uint64_t old_offset
) {}
3085 virtual void setattrs(map
<string
, boost::optional
<bufferlist
> > &attrs
) {}
3086 virtual void rmobject(version_t old_version
) {}
3088 * Used to support the unfound_lost_delete log event: if the stashed
3089 * version exists, we unstash it, otherwise, we do nothing. This way
3090 * each replica rolls back to whatever state it had prior to the attempt
3091 * at mark unfound lost delete
3093 virtual void try_rmobject(version_t old_version
) {
3094 rmobject(old_version
);
3096 virtual void create() {}
3097 virtual void update_snaps(const set
<snapid_t
> &old_snaps
) {}
3098 virtual void rollback_extents(
3100 const vector
<pair
<uint64_t, uint64_t> > &extents
) {}
3101 virtual ~Visitor() {}
3103 void visit(Visitor
*visitor
) const;
3104 mutable bufferlist bl
;
3112 ROLLBACK_EXTENTS
= 7
3114 ObjectModDesc() : can_local_rollback(true), rollback_info_completed(false) {}
3115 void claim(ObjectModDesc
&other
) {
3118 can_local_rollback
= other
.can_local_rollback
;
3119 rollback_info_completed
= other
.rollback_info_completed
;
3121 void claim_append(ObjectModDesc
&other
) {
3122 if (!can_local_rollback
|| rollback_info_completed
)
3124 if (!other
.can_local_rollback
) {
3125 mark_unrollbackable();
3128 bl
.claim_append(other
.bl
);
3129 rollback_info_completed
= other
.rollback_info_completed
;
3131 void swap(ObjectModDesc
&other
) {
3134 ::swap(other
.can_local_rollback
, can_local_rollback
);
3135 ::swap(other
.rollback_info_completed
, rollback_info_completed
);
3136 ::swap(other
.max_required_version
, max_required_version
);
3138 void append_id(ModID id
) {
3142 void append(uint64_t old_size
) {
3143 if (!can_local_rollback
|| rollback_info_completed
)
3145 ENCODE_START(1, 1, bl
);
3147 ::encode(old_size
, bl
);
3150 void setattrs(map
<string
, boost::optional
<bufferlist
> > &old_attrs
) {
3151 if (!can_local_rollback
|| rollback_info_completed
)
3153 ENCODE_START(1, 1, bl
);
3154 append_id(SETATTRS
);
3155 ::encode(old_attrs
, bl
);
3158 bool rmobject(version_t deletion_version
) {
3159 if (!can_local_rollback
|| rollback_info_completed
)
3161 ENCODE_START(1, 1, bl
);
3163 ::encode(deletion_version
, bl
);
3165 rollback_info_completed
= true;
3168 bool try_rmobject(version_t deletion_version
) {
3169 if (!can_local_rollback
|| rollback_info_completed
)
3171 ENCODE_START(1, 1, bl
);
3172 append_id(TRY_DELETE
);
3173 ::encode(deletion_version
, bl
);
3175 rollback_info_completed
= true;
3179 if (!can_local_rollback
|| rollback_info_completed
)
3181 rollback_info_completed
= true;
3182 ENCODE_START(1, 1, bl
);
3186 void update_snaps(const set
<snapid_t
> &old_snaps
) {
3187 if (!can_local_rollback
|| rollback_info_completed
)
3189 ENCODE_START(1, 1, bl
);
3190 append_id(UPDATE_SNAPS
);
3191 ::encode(old_snaps
, bl
);
3194 void rollback_extents(
3195 version_t gen
, const vector
<pair
<uint64_t, uint64_t> > &extents
) {
3196 assert(can_local_rollback
);
3197 assert(!rollback_info_completed
);
3198 if (max_required_version
< 2)
3199 max_required_version
= 2;
3200 ENCODE_START(2, 2, bl
);
3201 append_id(ROLLBACK_EXTENTS
);
3203 ::encode(extents
, bl
);
3207 // cannot be rolled back
3208 void mark_unrollbackable() {
3209 can_local_rollback
= false;
3212 bool can_rollback() const {
3213 return can_local_rollback
;
3215 bool empty() const {
3216 return can_local_rollback
&& (bl
.length() == 0);
3219 bool requires_kraken() const {
3220 return max_required_version
>= 2;
3224 * Create fresh copy of bl bytes to avoid keeping large buffers around
3225 * in the case that bl contains ptrs which point into a much larger
3229 if (bl
.length() > 0)
3232 void encode(bufferlist
&bl
) const;
3233 void decode(bufferlist::iterator
&bl
);
3234 void dump(Formatter
*f
) const;
3235 static void generate_test_instances(list
<ObjectModDesc
*>& o
);
3237 WRITE_CLASS_ENCODER(ObjectModDesc
)
3241 * pg_log_entry_t - single entry/event in pg log
3244 struct pg_log_entry_t
{
3246 MODIFY
= 1, // some unspecified modification (but not *all* modifications)
3247 CLONE
= 2, // cloned object from head
3248 DELETE
= 3, // deleted object
3249 BACKLOG
= 4, // event invented by generate_backlog [deprecated]
3250 LOST_REVERT
= 5, // lost new version, revert to an older version.
3251 LOST_DELETE
= 6, // lost new version, revert to no object (deleted).
3252 LOST_MARK
= 7, // lost new version, now EIO
3253 PROMOTE
= 8, // promoted object from another tier
3254 CLEAN
= 9, // mark an object clean
3255 ERROR
= 10, // write that returned an error
3257 static const char *get_op_name(int op
) {
3283 const char *get_op_name() const {
3284 return get_op_name(op
);
3287 // describes state for a locally-rollbackable entry
3288 ObjectModDesc mod_desc
;
3289 bufferlist snaps
; // only for clone entries
3291 osd_reqid_t reqid
; // caller+tid to uniquely identify request
3292 vector
<pair
<osd_reqid_t
, version_t
> > extra_reqids
;
3293 eversion_t version
, prior_version
, reverting_to
;
3294 version_t user_version
; // the user version for this entry
3295 utime_t mtime
; // this is the _user_ mtime, mind you
3296 int32_t return_code
; // only stored for ERRORs for dup detection
3299 bool invalid_hash
; // only when decoding sobject_t based entries
3300 bool invalid_pool
; // only when decoding pool-less hobject based entries
3303 : user_version(0), return_code(0), op(0),
3304 invalid_hash(false), invalid_pool(false) {}
3305 pg_log_entry_t(int _op
, const hobject_t
& _soid
,
3306 const eversion_t
& v
, const eversion_t
& pv
,
3308 const osd_reqid_t
& rid
, const utime_t
& mt
,
3310 : soid(_soid
), reqid(rid
), version(v
), prior_version(pv
), user_version(uv
),
3311 mtime(mt
), return_code(return_code
), op(_op
),
3312 invalid_hash(false), invalid_pool(false)
3315 bool is_clone() const { return op
== CLONE
; }
3316 bool is_modify() const { return op
== MODIFY
; }
3317 bool is_promote() const { return op
== PROMOTE
; }
3318 bool is_clean() const { return op
== CLEAN
; }
3319 bool is_backlog() const { return op
== BACKLOG
; }
3320 bool is_lost_revert() const { return op
== LOST_REVERT
; }
3321 bool is_lost_delete() const { return op
== LOST_DELETE
; }
3322 bool is_lost_mark() const { return op
== LOST_MARK
; }
3323 bool is_error() const { return op
== ERROR
; }
3325 bool is_update() const {
3327 is_clone() || is_modify() || is_promote() || is_clean() ||
3328 is_backlog() || is_lost_revert() || is_lost_mark();
3330 bool is_delete() const {
3331 return op
== DELETE
|| op
== LOST_DELETE
;
3334 bool can_rollback() const {
3335 return mod_desc
.can_rollback();
3338 void mark_unrollbackable() {
3339 mod_desc
.mark_unrollbackable();
3342 bool requires_kraken() const {
3343 return mod_desc
.requires_kraken();
3346 // Errors are only used for dup detection, whereas
3347 // the index by objects is used by recovery, copy_get,
3348 // and other facilities that don't expect or need to
3349 // be aware of error entries.
3350 bool object_is_indexed() const {
3354 bool reqid_is_indexed() const {
3355 return reqid
!= osd_reqid_t() &&
3356 (op
== MODIFY
|| op
== DELETE
|| op
== ERROR
);
3359 string
get_key_name() const;
3360 void encode_with_checksum(bufferlist
& bl
) const;
3361 void decode_with_checksum(bufferlist::iterator
& p
);
3363 void encode(bufferlist
&bl
) const;
3364 void decode(bufferlist::iterator
&bl
);
3365 void dump(Formatter
*f
) const;
3366 static void generate_test_instances(list
<pg_log_entry_t
*>& o
);
3369 WRITE_CLASS_ENCODER(pg_log_entry_t
)
3371 ostream
& operator<<(ostream
& out
, const pg_log_entry_t
& e
);
3376 * pg_log_t - incremental log of recent pg changes.
3378 * serves as a recovery queue for recent changes.
3382 * head - newest entry (update|delete)
3383 * tail - entry previous to oldest (update|delete) for which we have
3384 * complete negative information.
3385 * i.e. we can infer pg contents for any store whose last_update >= tail.
3387 eversion_t head
; // newest entry
3388 eversion_t tail
; // version prior to oldest
3391 // We can rollback rollback-able entries > can_rollback_to
3392 eversion_t can_rollback_to
;
3394 // always <= can_rollback_to, indicates how far stashed rollback
3395 // data can be found
3396 eversion_t rollback_info_trimmed_to
;
3399 mempool::osd::list
<pg_log_entry_t
> log
; // the actual log.
3401 pg_log_t() = default;
3402 pg_log_t(const eversion_t
&last_update
,
3403 const eversion_t
&log_tail
,
3404 const eversion_t
&can_rollback_to
,
3405 const eversion_t
&rollback_info_trimmed_to
,
3406 mempool::osd::list
<pg_log_entry_t
> &&entries
)
3407 : head(last_update
), tail(log_tail
), can_rollback_to(can_rollback_to
),
3408 rollback_info_trimmed_to(rollback_info_trimmed_to
),
3409 log(std::move(entries
)) {}
3410 pg_log_t(const eversion_t
&last_update
,
3411 const eversion_t
&log_tail
,
3412 const eversion_t
&can_rollback_to
,
3413 const eversion_t
&rollback_info_trimmed_to
,
3414 const std::list
<pg_log_entry_t
> &entries
)
3415 : head(last_update
), tail(log_tail
), can_rollback_to(can_rollback_to
),
3416 rollback_info_trimmed_to(rollback_info_trimmed_to
) {
3417 for (auto &&entry
: entries
) {
3418 log
.push_back(entry
);
3424 rollback_info_trimmed_to
= can_rollback_to
= head
= tail
= z
;
3428 eversion_t
get_rollback_info_trimmed_to() const {
3429 return rollback_info_trimmed_to
;
3431 eversion_t
get_can_rollback_to() const {
3432 return can_rollback_to
;
3436 pg_log_t
split_out_child(pg_t child_pgid
, unsigned split_bits
) {
3437 mempool::osd::list
<pg_log_entry_t
> oldlog
, childlog
;
3440 eversion_t old_tail
;
3441 unsigned mask
= ~((~0)<<split_bits
);
3442 for (auto i
= oldlog
.begin();
3445 if ((i
->soid
.get_hash() & mask
) == child_pgid
.m_seed
) {
3446 childlog
.push_back(*i
);
3457 rollback_info_trimmed_to
,
3458 std::move(childlog
));
3461 mempool::osd::list
<pg_log_entry_t
> rewind_from_head(eversion_t newhead
) {
3462 assert(newhead
>= tail
);
3464 mempool::osd::list
<pg_log_entry_t
>::iterator p
= log
.end();
3465 mempool::osd::list
<pg_log_entry_t
> divergent
;
3467 if (p
== log
.begin()) {
3468 // yikes, the whole thing is divergent!
3469 ::swap(divergent
, log
);
3473 if (p
->version
.version
<= newhead
.version
) {
3475 * look at eversion.version here. we want to avoid a situation like:
3476 * our log: 100'10 (0'0) m 10000004d3a.00000000/head by client4225.1:18529
3477 * new log: 122'10 (0'0) m 10000004d3a.00000000/head by client4225.1:18529
3478 * lower_bound = 100'9
3479 * i.e, same request, different version. If the eversion.version is > the
3480 * lower_bound, we it is divergent.
3483 divergent
.splice(divergent
.begin(), log
, p
, log
.end());
3486 assert(p
->version
> newhead
);
3490 if (can_rollback_to
> newhead
)
3491 can_rollback_to
= newhead
;
3493 if (rollback_info_trimmed_to
> newhead
)
3494 rollback_info_trimmed_to
= newhead
;
3499 bool empty() const {
3504 return head
.version
== 0 && head
.epoch
== 0;
3507 size_t approx_size() const {
3508 return head
.version
- tail
.version
;
3511 static void filter_log(spg_t import_pgid
, const OSDMap
&curmap
,
3512 const string
&hit_set_namespace
, const pg_log_t
&in
,
3513 pg_log_t
&out
, pg_log_t
&reject
);
3516 * copy entries from the tail of another pg_log_t
3518 * @param other pg_log_t to copy from
3519 * @param from copy entries after this version
3521 void copy_after(const pg_log_t
&other
, eversion_t from
);
3524 * copy a range of entries from another pg_log_t
3526 * @param other pg_log_t to copy from
3527 * @param from copy entries after this version
3528 * @param to up to and including this version
3530 void copy_range(const pg_log_t
&other
, eversion_t from
, eversion_t to
);
3533 * copy up to N entries
3535 * @param other source log
3536 * @param max max number of entries to copy
3538 void copy_up_to(const pg_log_t
&other
, int max
);
3540 ostream
& print(ostream
& out
) const;
3542 void encode(bufferlist
&bl
) const;
3543 void decode(bufferlist::iterator
&bl
, int64_t pool
= -1);
3544 void dump(Formatter
*f
) const;
3545 static void generate_test_instances(list
<pg_log_t
*>& o
);
3547 WRITE_CLASS_ENCODER(pg_log_t
)
3549 inline ostream
& operator<<(ostream
& out
, const pg_log_t
& log
)
3551 out
<< "log((" << log
.tail
<< "," << log
.head
<< "], crt="
3552 << log
.get_can_rollback_to() << ")";
3558 * pg_missing_t - summary of missing objects.
3560 * kept in memory, as a supplement to pg_log_t
3561 * also used to pass missing info in messages.
3563 struct pg_missing_item
{
3564 eversion_t need
, have
;
3565 pg_missing_item() {}
3566 explicit pg_missing_item(eversion_t n
) : need(n
) {} // have no old version
3567 pg_missing_item(eversion_t n
, eversion_t h
) : need(n
), have(h
) {}
3569 void encode(bufferlist
& bl
) const {
3573 void decode(bufferlist::iterator
& bl
) {
3577 void dump(Formatter
*f
) const {
3578 f
->dump_stream("need") << need
;
3579 f
->dump_stream("have") << have
;
3581 static void generate_test_instances(list
<pg_missing_item
*>& o
) {
3582 o
.push_back(new pg_missing_item
);
3583 o
.push_back(new pg_missing_item
);
3584 o
.back()->need
= eversion_t(1, 2);
3585 o
.back()->have
= eversion_t(1, 1);
3587 bool operator==(const pg_missing_item
&rhs
) const {
3588 return need
== rhs
.need
&& have
== rhs
.have
;
3590 bool operator!=(const pg_missing_item
&rhs
) const {
3591 return !(*this == rhs
);
3594 WRITE_CLASS_ENCODER(pg_missing_item
)
3595 ostream
& operator<<(ostream
& out
, const pg_missing_item
&item
);
3597 class pg_missing_const_i
{
3599 virtual const map
<hobject_t
, pg_missing_item
> &
3600 get_items() const = 0;
3601 virtual const map
<version_t
, hobject_t
> &get_rmissing() const = 0;
3602 virtual unsigned int num_missing() const = 0;
3603 virtual bool have_missing() const = 0;
3604 virtual bool is_missing(const hobject_t
& oid
, pg_missing_item
*out
= nullptr) const = 0;
3605 virtual bool is_missing(const hobject_t
& oid
, eversion_t v
) const = 0;
3606 virtual eversion_t
have_old(const hobject_t
& oid
) const = 0;
3607 virtual ~pg_missing_const_i() {}
3611 template <bool Track
>
3612 class ChangeTracker
{
3614 void changed(const hobject_t
&obj
) {}
3615 template <typename F
>
3616 void get_changed(F
&&f
) const {}
3618 bool is_clean() const {
3623 class ChangeTracker
<true> {
3624 set
<hobject_t
> _changed
;
3626 void changed(const hobject_t
&obj
) {
3627 _changed
.insert(obj
);
3629 template <typename F
>
3630 void get_changed(F
&&f
) const {
3631 for (auto const &i
: _changed
) {
3638 bool is_clean() const {
3639 return _changed
.empty();
3643 template <bool TrackChanges
>
3644 class pg_missing_set
: public pg_missing_const_i
{
3645 using item
= pg_missing_item
;
3646 map
<hobject_t
, item
> missing
; // oid -> (need v, have v)
3647 map
<version_t
, hobject_t
> rmissing
; // v -> oid
3648 ChangeTracker
<TrackChanges
> tracker
;
3651 pg_missing_set() = default;
3653 template <typename missing_type
>
3654 pg_missing_set(const missing_type
&m
) {
3655 for (auto &&i
: missing
)
3656 tracker
.changed(i
.first
);
3657 missing
= m
.get_items();
3658 rmissing
= m
.get_rmissing();
3659 for (auto &&i
: missing
)
3660 tracker
.changed(i
.first
);
3663 const map
<hobject_t
, item
> &get_items() const override
{
3666 const map
<version_t
, hobject_t
> &get_rmissing() const override
{
3669 unsigned int num_missing() const override
{
3670 return missing
.size();
3672 bool have_missing() const override
{
3673 return !missing
.empty();
3675 bool is_missing(const hobject_t
& oid
, pg_missing_item
*out
= nullptr) const override
{
3676 auto iter
= missing
.find(oid
);
3677 if (iter
== missing
.end())
3680 *out
= iter
->second
;
3683 bool is_missing(const hobject_t
& oid
, eversion_t v
) const override
{
3684 map
<hobject_t
, item
>::const_iterator m
=
3686 if (m
== missing
.end())
3688 const item
&item(m
->second
);
3693 eversion_t
have_old(const hobject_t
& oid
) const override
{
3694 map
<hobject_t
, item
>::const_iterator m
=
3696 if (m
== missing
.end())
3697 return eversion_t();
3698 const item
&item(m
->second
);
3702 void claim(pg_missing_set
& o
) {
3703 static_assert(!TrackChanges
, "Can't use claim with TrackChanges");
3704 missing
.swap(o
.missing
);
3705 rmissing
.swap(o
.rmissing
);
3709 * this needs to be called in log order as we extend the log. it
3710 * assumes missing is accurate up through the previous log entry.
3712 void add_next_event(const pg_log_entry_t
& e
) {
3713 if (e
.is_update()) {
3714 map
<hobject_t
, item
>::iterator missing_it
;
3715 missing_it
= missing
.find(e
.soid
);
3716 bool is_missing_divergent_item
= missing_it
!= missing
.end();
3717 if (e
.prior_version
== eversion_t() || e
.is_clone()) {
3719 if (is_missing_divergent_item
) { // use iterator
3720 rmissing
.erase((missing_it
->second
).need
.version
);
3721 missing_it
->second
= item(e
.version
, eversion_t()); // .have = nil
3722 } else // create new element in missing map
3723 missing
[e
.soid
] = item(e
.version
, eversion_t()); // .have = nil
3724 } else if (is_missing_divergent_item
) {
3725 // already missing (prior).
3726 rmissing
.erase((missing_it
->second
).need
.version
);
3727 (missing_it
->second
).need
= e
.version
; // leave .have unchanged.
3728 } else if (e
.is_backlog()) {
3729 // May not have prior version
3730 assert(0 == "these don't exist anymore");
3732 // not missing, we must have prior_version (if any)
3733 assert(!is_missing_divergent_item
);
3734 missing
[e
.soid
] = item(e
.version
, e
.prior_version
);
3736 rmissing
[e
.version
.version
] = e
.soid
;
3737 } else if (e
.is_delete()) {
3738 rm(e
.soid
, e
.version
);
3741 tracker
.changed(e
.soid
);
3744 void revise_need(hobject_t oid
, eversion_t need
) {
3745 if (missing
.count(oid
)) {
3746 rmissing
.erase(missing
[oid
].need
.version
);
3747 missing
[oid
].need
= need
; // no not adjust .have
3749 missing
[oid
] = item(need
, eversion_t());
3751 rmissing
[need
.version
] = oid
;
3753 tracker
.changed(oid
);
3756 void revise_have(hobject_t oid
, eversion_t have
) {
3757 if (missing
.count(oid
)) {
3758 tracker
.changed(oid
);
3759 missing
[oid
].have
= have
;
3763 void add(const hobject_t
& oid
, eversion_t need
, eversion_t have
) {
3764 missing
[oid
] = item(need
, have
);
3765 rmissing
[need
.version
] = oid
;
3766 tracker
.changed(oid
);
3769 void rm(const hobject_t
& oid
, eversion_t v
) {
3770 std::map
<hobject_t
, item
>::iterator p
= missing
.find(oid
);
3771 if (p
!= missing
.end() && p
->second
.need
<= v
)
3775 void rm(std::map
<hobject_t
, item
>::const_iterator m
) {
3776 tracker
.changed(m
->first
);
3777 rmissing
.erase(m
->second
.need
.version
);
3781 void got(const hobject_t
& oid
, eversion_t v
) {
3782 std::map
<hobject_t
, item
>::iterator p
= missing
.find(oid
);
3783 assert(p
!= missing
.end());
3784 assert(p
->second
.need
<= v
);
3788 void got(std::map
<hobject_t
, item
>::const_iterator m
) {
3789 tracker
.changed(m
->first
);
3790 rmissing
.erase(m
->second
.need
.version
);
3796 unsigned split_bits
,
3797 pg_missing_set
*omissing
) {
3798 unsigned mask
= ~((~0)<<split_bits
);
3799 for (map
<hobject_t
, item
>::iterator i
= missing
.begin();
3802 if ((i
->first
.get_hash() & mask
) == child_pgid
.m_seed
) {
3803 omissing
->add(i
->first
, i
->second
.need
, i
->second
.have
);
3812 for (auto const &i
: missing
)
3813 tracker
.changed(i
.first
);
3818 void encode(bufferlist
&bl
) const {
3819 ENCODE_START(3, 2, bl
);
3820 ::encode(missing
, bl
);
3823 void decode(bufferlist::iterator
&bl
, int64_t pool
= -1) {
3824 for (auto const &i
: missing
)
3825 tracker
.changed(i
.first
);
3826 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl
);
3827 ::decode(missing
, bl
);
3831 // Handle hobject_t upgrade
3832 map
<hobject_t
, item
> tmp
;
3833 for (map
<hobject_t
, item
>::iterator i
=
3837 if (!i
->first
.is_max() && i
->first
.pool
== -1) {
3838 hobject_t
to_insert(i
->first
);
3839 to_insert
.pool
= pool
;
3840 tmp
[to_insert
] = i
->second
;
3846 missing
.insert(tmp
.begin(), tmp
.end());
3849 for (map
<hobject_t
,item
>::iterator it
=
3851 it
!= missing
.end();
3853 rmissing
[it
->second
.need
.version
] = it
->first
;
3854 for (auto const &i
: missing
)
3855 tracker
.changed(i
.first
);
3857 void dump(Formatter
*f
) const {
3858 f
->open_array_section("missing");
3859 for (map
<hobject_t
,item
>::const_iterator p
=
3860 missing
.begin(); p
!= missing
.end(); ++p
) {
3861 f
->open_object_section("item");
3862 f
->dump_stream("object") << p
->first
;
3868 template <typename F
>
3869 void filter_objects(F
&&f
) {
3870 for (auto i
= missing
.begin(); i
!= missing
.end();) {
3878 static void generate_test_instances(list
<pg_missing_set
*>& o
) {
3879 o
.push_back(new pg_missing_set
);
3880 o
.push_back(new pg_missing_set
);
3882 hobject_t(object_t("foo"), "foo", 123, 456, 0, ""),
3883 eversion_t(5, 6), eversion_t(5, 1));
3885 template <typename F
>
3886 void get_changed(F
&&f
) const {
3887 tracker
.get_changed(f
);
3892 bool is_clean() const {
3893 return tracker
.is_clean();
3895 template <typename missing_t
>
3896 bool debug_verify_from_init(
3897 const missing_t
&init_missing
,
3898 ostream
*oss
) const {
3901 auto check_missing(init_missing
.get_items());
3902 tracker
.get_changed([&](const hobject_t
&hoid
) {
3903 check_missing
.erase(hoid
);
3904 if (missing
.count(hoid
)) {
3905 check_missing
.insert(*(missing
.find(hoid
)));
3909 if (check_missing
.size() != missing
.size()) {
3911 *oss
<< "Size mismatch, check: " << check_missing
.size()
3912 << ", actual: " << missing
.size() << "\n";
3916 for (auto &i
: missing
) {
3917 if (!check_missing
.count(i
.first
)) {
3919 *oss
<< "check_missing missing " << i
.first
<< "\n";
3921 } else if (check_missing
[i
.first
] != i
.second
) {
3923 *oss
<< "check_missing missing item mismatch on " << i
.first
3924 << ", check: " << check_missing
[i
.first
]
3925 << ", actual: " << i
.second
<< "\n";
3930 *oss
<< "check_missing: " << check_missing
<< "\n";
3931 set
<hobject_t
> changed
;
3932 tracker
.get_changed([&](const hobject_t
&hoid
) { changed
.insert(hoid
); });
3933 *oss
<< "changed: " << changed
<< "\n";
3938 template <bool TrackChanges
>
3940 const pg_missing_set
<TrackChanges
> &c
, bufferlist
&bl
, uint64_t features
=0) {
3943 ENCODE_DUMP_POST(cl
);
3945 template <bool TrackChanges
>
3946 void decode(pg_missing_set
<TrackChanges
> &c
, bufferlist::iterator
&p
) {
3949 template <bool TrackChanges
>
3950 ostream
& operator<<(ostream
& out
, const pg_missing_set
<TrackChanges
> &missing
)
3952 out
<< "missing(" << missing
.num_missing();
3953 //if (missing.num_lost()) out << ", " << missing.num_lost() << " lost";
3958 using pg_missing_t
= pg_missing_set
<false>;
3959 using pg_missing_tracker_t
= pg_missing_set
<true>;
3963 * pg list objects response format
3966 struct pg_nls_response_t
{
3967 collection_list_handle_t handle
;
3968 list
<librados::ListObjectImpl
> entries
;
3970 void encode(bufferlist
& bl
) const {
3971 ENCODE_START(1, 1, bl
);
3972 ::encode(handle
, bl
);
3973 __u32 n
= (__u32
)entries
.size();
3975 for (list
<librados::ListObjectImpl
>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
3976 ::encode(i
->nspace
, bl
);
3977 ::encode(i
->oid
, bl
);
3978 ::encode(i
->locator
, bl
);
3982 void decode(bufferlist::iterator
& bl
) {
3983 DECODE_START(1, bl
);
3984 ::decode(handle
, bl
);
3989 librados::ListObjectImpl i
;
3990 ::decode(i
.nspace
, bl
);
3991 ::decode(i
.oid
, bl
);
3992 ::decode(i
.locator
, bl
);
3993 entries
.push_back(i
);
3997 void dump(Formatter
*f
) const {
3998 f
->dump_stream("handle") << handle
;
3999 f
->open_array_section("entries");
4000 for (list
<librados::ListObjectImpl
>::const_iterator p
= entries
.begin(); p
!= entries
.end(); ++p
) {
4001 f
->open_object_section("object");
4002 f
->dump_string("namespace", p
->nspace
);
4003 f
->dump_string("object", p
->oid
);
4004 f
->dump_string("key", p
->locator
);
4009 static void generate_test_instances(list
<pg_nls_response_t
*>& o
) {
4010 o
.push_back(new pg_nls_response_t
);
4011 o
.push_back(new pg_nls_response_t
);
4012 o
.back()->handle
= hobject_t(object_t("hi"), "key", 1, 2, -1, "");
4013 o
.back()->entries
.push_back(librados::ListObjectImpl("", "one", ""));
4014 o
.back()->entries
.push_back(librados::ListObjectImpl("", "two", "twokey"));
4015 o
.back()->entries
.push_back(librados::ListObjectImpl("", "three", ""));
4016 o
.push_back(new pg_nls_response_t
);
4017 o
.back()->handle
= hobject_t(object_t("hi"), "key", 3, 4, -1, "");
4018 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1one", ""));
4019 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1two", "n1twokey"));
4020 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1three", ""));
4021 o
.push_back(new pg_nls_response_t
);
4022 o
.back()->handle
= hobject_t(object_t("hi"), "key", 5, 6, -1, "");
4023 o
.back()->entries
.push_back(librados::ListObjectImpl("", "one", ""));
4024 o
.back()->entries
.push_back(librados::ListObjectImpl("", "two", "twokey"));
4025 o
.back()->entries
.push_back(librados::ListObjectImpl("", "three", ""));
4026 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1one", ""));
4027 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1two", "n1twokey"));
4028 o
.back()->entries
.push_back(librados::ListObjectImpl("n1", "n1three", ""));
4032 WRITE_CLASS_ENCODER(pg_nls_response_t
)
4034 // For backwards compatibility with older OSD requests
4035 struct pg_ls_response_t
{
4036 collection_list_handle_t handle
;
4037 list
<pair
<object_t
, string
> > entries
;
4039 void encode(bufferlist
& bl
) const {
4042 ::encode(handle
, bl
);
4043 ::encode(entries
, bl
);
4045 void decode(bufferlist::iterator
& bl
) {
4049 ::decode(handle
, bl
);
4050 ::decode(entries
, bl
);
4052 void dump(Formatter
*f
) const {
4053 f
->dump_stream("handle") << handle
;
4054 f
->open_array_section("entries");
4055 for (list
<pair
<object_t
, string
> >::const_iterator p
= entries
.begin(); p
!= entries
.end(); ++p
) {
4056 f
->open_object_section("object");
4057 f
->dump_stream("object") << p
->first
;
4058 f
->dump_string("key", p
->second
);
4063 static void generate_test_instances(list
<pg_ls_response_t
*>& o
) {
4064 o
.push_back(new pg_ls_response_t
);
4065 o
.push_back(new pg_ls_response_t
);
4066 o
.back()->handle
= hobject_t(object_t("hi"), "key", 1, 2, -1, "");
4067 o
.back()->entries
.push_back(make_pair(object_t("one"), string()));
4068 o
.back()->entries
.push_back(make_pair(object_t("two"), string("twokey")));
4072 WRITE_CLASS_ENCODER(pg_ls_response_t
)
4075 * object_copy_cursor_t
4077 struct object_copy_cursor_t
{
4078 uint64_t data_offset
;
4084 object_copy_cursor_t()
4086 attr_complete(false),
4087 data_complete(false),
4088 omap_complete(false)
4091 bool is_initial() const {
4092 return !attr_complete
&& data_offset
== 0 && omap_offset
.empty();
4094 bool is_complete() const {
4095 return attr_complete
&& data_complete
&& omap_complete
;
4098 static void generate_test_instances(list
<object_copy_cursor_t
*>& o
);
4099 void encode(bufferlist
& bl
) const;
4100 void decode(bufferlist::iterator
&bl
);
4101 void dump(Formatter
*f
) const;
4103 WRITE_CLASS_ENCODER(object_copy_cursor_t
)
4106 * object_copy_data_t
4108 * Return data from a copy request. The semantics are a little strange
4109 * as a result of the encoding's heritage.
4111 * In particular, the sender unconditionally fills in the cursor (from what
4112 * it receives and sends), the size, and the mtime, but is responsible for
4113 * figuring out whether it should put any data in the attrs, data, or
4114 * omap members (corresponding to xattrs, object data, and the omap entries)
4115 * based on external data (the client includes a max amount to return with
4116 * the copy request). The client then looks into the attrs, data, and/or omap
4117 * based on the contents of the cursor.
4119 struct object_copy_data_t
{
4121 FLAG_DATA_DIGEST
= 1<<0,
4122 FLAG_OMAP_DIGEST
= 1<<1,
4124 object_copy_cursor_t cursor
;
4127 uint32_t data_digest
, omap_digest
;
4129 map
<string
, bufferlist
> attrs
;
4131 bufferlist omap_header
;
4132 bufferlist omap_data
;
4134 /// which snaps we are defined for (if a snap and not the head)
4135 vector
<snapid_t
> snaps
;
4136 ///< latest snap seq for the object (if head)
4139 ///< recent reqids on this object
4140 vector
<pair
<osd_reqid_t
, version_t
> > reqids
;
4142 uint64_t truncate_seq
;
4143 uint64_t truncate_size
;
4146 object_copy_data_t() :
4147 size((uint64_t)-1), data_digest(-1),
4148 omap_digest(-1), flags(0),
4152 static void generate_test_instances(list
<object_copy_data_t
*>& o
);
4153 void encode(bufferlist
& bl
, uint64_t features
) const;
4154 void decode(bufferlist::iterator
& bl
);
4155 void dump(Formatter
*f
) const;
4157 WRITE_CLASS_ENCODER_FEATURES(object_copy_data_t
)
4162 struct pg_create_t
{
4163 epoch_t created
; // epoch pg created
4164 pg_t parent
; // split from parent (if != pg_t())
4168 : created(0), split_bits(0) {}
4169 pg_create_t(unsigned c
, pg_t p
, int s
)
4170 : created(c
), parent(p
), split_bits(s
) {}
4172 void encode(bufferlist
&bl
) const;
4173 void decode(bufferlist::iterator
&bl
);
4174 void dump(Formatter
*f
) const;
4175 static void generate_test_instances(list
<pg_create_t
*>& o
);
4177 WRITE_CLASS_ENCODER(pg_create_t
)
4179 // -----------------------------------------
4181 struct osd_peer_stat_t
{
4184 osd_peer_stat_t() { }
4186 void encode(bufferlist
&bl
) const;
4187 void decode(bufferlist::iterator
&bl
);
4188 void dump(Formatter
*f
) const;
4189 static void generate_test_instances(list
<osd_peer_stat_t
*>& o
);
4191 WRITE_CLASS_ENCODER(osd_peer_stat_t
)
4193 ostream
& operator<<(ostream
& out
, const osd_peer_stat_t
&stat
);
4196 // -----------------------------------------
4198 class ObjectExtent
{
4200 * ObjectExtents are used for specifying IO behavior against RADOS
4201 * objects when one is using the ObjectCacher.
4203 * To use this in a real system, *every member* must be filled
4204 * out correctly. In particular, make sure to initialize the
4205 * oloc correctly, as its default values are deliberate poison
4206 * and will cause internal ObjectCacher asserts.
4208 * Similarly, your buffer_extents vector *must* specify a total
4209 * size equal to your length. If the buffer_extents inadvertently
4210 * contain less space than the length member specifies, you
4211 * will get unintelligible asserts deep in the ObjectCacher.
4213 * If you are trying to do testing and don't care about actual
4214 * RADOS function, the simplest thing to do is to initialize
4215 * the ObjectExtent (truncate_size can be 0), create a single entry
4216 * in buffer_extents matching the length, and set oloc.pool to 0.
4219 object_t oid
; // object id
4221 uint64_t offset
; // in object
4222 uint64_t length
; // in object
4223 uint64_t truncate_size
; // in object
4225 object_locator_t oloc
; // object locator (pool etc)
4227 vector
<pair
<uint64_t,uint64_t> > buffer_extents
; // off -> len. extents in buffer being mapped (may be fragmented bc of striping!)
4229 ObjectExtent() : objectno(0), offset(0), length(0), truncate_size(0) {}
4230 ObjectExtent(object_t o
, uint64_t ono
, uint64_t off
, uint64_t l
, uint64_t ts
) :
4231 oid(o
), objectno(ono
), offset(off
), length(l
), truncate_size(ts
) { }
4234 inline ostream
& operator<<(ostream
& out
, const ObjectExtent
&ex
)
4236 return out
<< "extent("
4237 << ex
.oid
<< " (" << ex
.objectno
<< ") in " << ex
.oloc
4238 << " " << ex
.offset
<< "~" << ex
.length
4239 << " -> " << ex
.buffer_extents
4248 // ---------------------------------------
4250 class OSDSuperblock
{
4252 uuid_d cluster_fsid
, osd_fsid
;
4253 int32_t whoami
; // my role in this fs.
4254 epoch_t current_epoch
; // most recent epoch
4255 epoch_t oldest_map
, newest_map
; // oldest/newest maps we have.
4258 CompatSet compat_features
;
4260 // last interval over which i mounted and was then active
4261 epoch_t mounted
; // last epoch i mounted
4262 epoch_t clean_thru
; // epoch i was active and clean thru
4266 current_epoch(0), oldest_map(0), newest_map(0), weight(0),
4267 mounted(0), clean_thru(0) {
4270 void encode(bufferlist
&bl
) const;
4271 void decode(bufferlist::iterator
&bl
);
4272 void dump(Formatter
*f
) const;
4273 static void generate_test_instances(list
<OSDSuperblock
*>& o
);
4275 WRITE_CLASS_ENCODER(OSDSuperblock
)
4277 inline ostream
& operator<<(ostream
& out
, const OSDSuperblock
& sb
)
4279 return out
<< "sb(" << sb
.cluster_fsid
4280 << " osd." << sb
.whoami
4281 << " " << sb
.osd_fsid
4282 << " e" << sb
.current_epoch
4283 << " [" << sb
.oldest_map
<< "," << sb
.newest_map
<< "]"
4284 << " lci=[" << sb
.mounted
<< "," << sb
.clean_thru
<< "]"
4297 * attached to object head. describes most recent snap context, and
4298 * set of existing clones.
4303 vector
<snapid_t
> snaps
; // descending
4304 vector
<snapid_t
> clones
; // ascending
4305 map
<snapid_t
, interval_set
<uint64_t> > clone_overlap
; // overlap w/ next newest
4306 map
<snapid_t
, uint64_t> clone_size
;
4307 map
<snapid_t
, vector
<snapid_t
>> clone_snaps
; // descending
4309 SnapSet() : seq(0), head_exists(false) {}
4310 explicit SnapSet(bufferlist
& bl
) {
4311 bufferlist::iterator p
= bl
.begin();
4315 bool is_legacy() const {
4316 return clone_snaps
.size() < clones
.size() || !head_exists
;
4319 /// populate SnapSet from a librados::snap_set_t
4320 void from_snap_set(const librados::snap_set_t
& ss
, bool legacy
);
4322 /// get space accounted to clone
4323 uint64_t get_clone_bytes(snapid_t clone
) const;
4325 void encode(bufferlist
& bl
) const;
4326 void decode(bufferlist::iterator
& bl
);
4327 void dump(Formatter
*f
) const;
4328 static void generate_test_instances(list
<SnapSet
*>& o
);
4330 SnapContext
get_ssc_as_of(snapid_t as_of
) const {
4333 for (vector
<snapid_t
>::const_iterator i
= snaps
.begin();
4337 out
.snaps
.push_back(*i
);
4342 // return min element of snaps > after, return max if no such element
4343 snapid_t
get_first_snap_after(snapid_t after
, snapid_t max
) const {
4344 for (vector
<snapid_t
>::const_reverse_iterator i
= snaps
.rbegin();
4353 SnapSet
get_filtered(const pg_pool_t
&pinfo
) const;
4354 void filter(const pg_pool_t
&pinfo
);
4356 WRITE_CLASS_ENCODER(SnapSet
)
4358 ostream
& operator<<(ostream
& out
, const SnapSet
& cs
);
4363 #define SS_ATTR "snapset"
4365 struct watch_info_t
{
4367 uint32_t timeout_seconds
;
4370 watch_info_t() : cookie(0), timeout_seconds(0) { }
4371 watch_info_t(uint64_t c
, uint32_t t
, const entity_addr_t
& a
) : cookie(c
), timeout_seconds(t
), addr(a
) {}
4373 void encode(bufferlist
& bl
, uint64_t features
) const;
4374 void decode(bufferlist::iterator
& bl
);
4375 void dump(Formatter
*f
) const;
4376 static void generate_test_instances(list
<watch_info_t
*>& o
);
4378 WRITE_CLASS_ENCODER_FEATURES(watch_info_t
)
4380 static inline bool operator==(const watch_info_t
& l
, const watch_info_t
& r
) {
4381 return l
.cookie
== r
.cookie
&& l
.timeout_seconds
== r
.timeout_seconds
4382 && l
.addr
== r
.addr
;
4385 static inline ostream
& operator<<(ostream
& out
, const watch_info_t
& w
) {
4386 return out
<< "watch(cookie " << w
.cookie
<< " " << w
.timeout_seconds
<< "s"
4387 << " " << w
.addr
<< ")";
4390 struct notify_info_t
{
4397 static inline ostream
& operator<<(ostream
& out
, const notify_info_t
& n
) {
4398 return out
<< "notify(cookie " << n
.cookie
4399 << " notify" << n
.notify_id
4400 << " " << n
.timeout
<< "s)";
4404 struct object_info_t
{
4406 eversion_t version
, prior_version
;
4407 version_t user_version
;
4408 osd_reqid_t last_reqid
;
4412 utime_t local_mtime
; // local mtime
4414 // note: these are currently encoded into a total 16 bits; see
4415 // encode()/decode() for the weirdness.
4418 FLAG_WHITEOUT
= 1<<1, // object logically does not exist
4419 FLAG_DIRTY
= 1<<2, // object has been modified since last flushed or undirtied
4420 FLAG_OMAP
= 1 << 3, // has (or may have) some/any omap data
4421 FLAG_DATA_DIGEST
= 1 << 4, // has data crc
4422 FLAG_OMAP_DIGEST
= 1 << 5, // has omap crc
4423 FLAG_CACHE_PIN
= 1 << 6, // pin the object in cache tier
4425 FLAG_USES_TMAP
= 1<<8, // deprecated; no longer used.
4430 static string
get_flag_string(flag_t flags
) {
4432 if (flags
& FLAG_LOST
)
4434 if (flags
& FLAG_WHITEOUT
)
4436 if (flags
& FLAG_DIRTY
)
4438 if (flags
& FLAG_USES_TMAP
)
4440 if (flags
& FLAG_OMAP
)
4442 if (flags
& FLAG_DATA_DIGEST
)
4443 s
+= "|data_digest";
4444 if (flags
& FLAG_OMAP_DIGEST
)
4445 s
+= "|omap_digest";
4446 if (flags
& FLAG_CACHE_PIN
)
4452 string
get_flag_string() const {
4453 return get_flag_string(flags
);
4456 /// [clone] descending. pre-luminous; moved to SnapSet
4457 vector
<snapid_t
> legacy_snaps
;
4459 uint64_t truncate_seq
, truncate_size
;
4461 map
<pair
<uint64_t, entity_name_t
>, watch_info_t
> watchers
;
4463 // opportunistic checksums; may or may not be present
4464 __u32 data_digest
; ///< data crc32c
4465 __u32 omap_digest
; ///< omap crc32c
4467 // alloc hint attribute
4468 uint64_t expected_object_size
, expected_write_size
;
4469 uint32_t alloc_hint_flags
;
4471 void copy_user_bits(const object_info_t
& other
);
4473 static ps_t
legacy_object_locator_to_ps(const object_t
&oid
,
4474 const object_locator_t
&loc
);
4476 bool test_flag(flag_t f
) const {
4477 return (flags
& f
) == f
;
4479 void set_flag(flag_t f
) {
4480 flags
= (flag_t
)(flags
| f
);
4482 void clear_flag(flag_t f
) {
4483 flags
= (flag_t
)(flags
& ~f
);
4485 bool is_lost() const {
4486 return test_flag(FLAG_LOST
);
4488 bool is_whiteout() const {
4489 return test_flag(FLAG_WHITEOUT
);
4491 bool is_dirty() const {
4492 return test_flag(FLAG_DIRTY
);
4494 bool is_omap() const {
4495 return test_flag(FLAG_OMAP
);
4497 bool is_data_digest() const {
4498 return test_flag(FLAG_DATA_DIGEST
);
4500 bool is_omap_digest() const {
4501 return test_flag(FLAG_OMAP_DIGEST
);
4503 bool is_cache_pinned() const {
4504 return test_flag(FLAG_CACHE_PIN
);
4507 void set_data_digest(__u32 d
) {
4508 set_flag(FLAG_DATA_DIGEST
);
4511 void set_omap_digest(__u32 d
) {
4512 set_flag(FLAG_OMAP_DIGEST
);
4515 void clear_data_digest() {
4516 clear_flag(FLAG_DATA_DIGEST
);
4519 void clear_omap_digest() {
4520 clear_flag(FLAG_OMAP_DIGEST
);
4524 set_data_digest(-1);
4525 set_omap_digest(-1);
4528 void encode(bufferlist
& bl
, uint64_t features
) const;
4529 void decode(bufferlist::iterator
& bl
);
4530 void decode(bufferlist
& bl
) {
4531 bufferlist::iterator p
= bl
.begin();
4534 void dump(Formatter
*f
) const;
4535 static void generate_test_instances(list
<object_info_t
*>& o
);
4537 explicit object_info_t()
4538 : user_version(0), size(0), flags((flag_t
)0),
4539 truncate_seq(0), truncate_size(0),
4540 data_digest(-1), omap_digest(-1),
4541 expected_object_size(0), expected_write_size(0),
4545 explicit object_info_t(const hobject_t
& s
)
4547 user_version(0), size(0), flags((flag_t
)0),
4548 truncate_seq(0), truncate_size(0),
4549 data_digest(-1), omap_digest(-1),
4550 expected_object_size(0), expected_write_size(0),
4554 explicit object_info_t(bufferlist
& bl
) {
4558 WRITE_CLASS_ENCODER_FEATURES(object_info_t
)
4560 ostream
& operator<<(ostream
& out
, const object_info_t
& oi
);
4565 struct ObjectRecoveryInfo
{
4570 SnapSet ss
; // only populated if soid is_snap()
4571 interval_set
<uint64_t> copy_subset
;
4572 map
<hobject_t
, interval_set
<uint64_t>> clone_subset
;
4574 ObjectRecoveryInfo() : size(0) { }
4576 static void generate_test_instances(list
<ObjectRecoveryInfo
*>& o
);
4577 void encode(bufferlist
&bl
, uint64_t features
) const;
4578 void decode(bufferlist::iterator
&bl
, int64_t pool
= -1);
4579 ostream
&print(ostream
&out
) const;
4580 void dump(Formatter
*f
) const;
4582 WRITE_CLASS_ENCODER_FEATURES(ObjectRecoveryInfo
)
4583 ostream
& operator<<(ostream
& out
, const ObjectRecoveryInfo
&inf
);
4585 struct ObjectRecoveryProgress
{
4586 uint64_t data_recovered_to
;
4587 string omap_recovered_to
;
4592 ObjectRecoveryProgress()
4593 : data_recovered_to(0),
4595 data_complete(false), omap_complete(false) { }
4597 bool is_complete(const ObjectRecoveryInfo
& info
) const {
4598 return (data_recovered_to
>= (
4599 info
.copy_subset
.empty() ?
4600 0 : info
.copy_subset
.range_end())) &&
4604 static void generate_test_instances(list
<ObjectRecoveryProgress
*>& o
);
4605 void encode(bufferlist
&bl
) const;
4606 void decode(bufferlist::iterator
&bl
);
4607 ostream
&print(ostream
&out
) const;
4608 void dump(Formatter
*f
) const;
4610 WRITE_CLASS_ENCODER(ObjectRecoveryProgress
)
4611 ostream
& operator<<(ostream
& out
, const ObjectRecoveryProgress
&prog
);
4613 struct PushReplyOp
{
4616 static void generate_test_instances(list
<PushReplyOp
*>& o
);
4617 void encode(bufferlist
&bl
) const;
4618 void decode(bufferlist::iterator
&bl
);
4619 ostream
&print(ostream
&out
) const;
4620 void dump(Formatter
*f
) const;
4622 uint64_t cost(CephContext
*cct
) const;
4624 WRITE_CLASS_ENCODER(PushReplyOp
)
4625 ostream
& operator<<(ostream
& out
, const PushReplyOp
&op
);
4630 ObjectRecoveryInfo recovery_info
;
4631 ObjectRecoveryProgress recovery_progress
;
4633 static void generate_test_instances(list
<PullOp
*>& o
);
4634 void encode(bufferlist
&bl
, uint64_t features
) const;
4635 void decode(bufferlist::iterator
&bl
);
4636 ostream
&print(ostream
&out
) const;
4637 void dump(Formatter
*f
) const;
4639 uint64_t cost(CephContext
*cct
) const;
4641 WRITE_CLASS_ENCODER_FEATURES(PullOp
)
4642 ostream
& operator<<(ostream
& out
, const PullOp
&op
);
4648 interval_set
<uint64_t> data_included
;
4649 bufferlist omap_header
;
4650 map
<string
, bufferlist
> omap_entries
;
4651 map
<string
, bufferlist
> attrset
;
4653 ObjectRecoveryInfo recovery_info
;
4654 ObjectRecoveryProgress before_progress
;
4655 ObjectRecoveryProgress after_progress
;
4657 static void generate_test_instances(list
<PushOp
*>& o
);
4658 void encode(bufferlist
&bl
, uint64_t features
) const;
4659 void decode(bufferlist::iterator
&bl
);
4660 ostream
&print(ostream
&out
) const;
4661 void dump(Formatter
*f
) const;
4663 uint64_t cost(CephContext
*cct
) const;
4665 WRITE_CLASS_ENCODER_FEATURES(PushOp
)
4666 ostream
& operator<<(ostream
& out
, const PushOp
&op
);
4670 * summarize pg contents for purposes of a scrub
4674 map
<string
,bufferptr
> attrs
;
4676 __u32 omap_digest
; ///< omap crc32c
4677 __u32 digest
; ///< data crc32c
4679 bool digest_present
:1;
4680 bool omap_digest_present
:1;
4683 bool ec_hash_mismatch
:1;
4684 bool ec_size_mismatch
:1;
4687 // Init invalid size so it won't match if we get a stat EIO error
4688 size(-1), omap_digest(0), digest(0),
4689 negative(false), digest_present(false), omap_digest_present(false),
4690 read_error(false), stat_error(false), ec_hash_mismatch(false), ec_size_mismatch(false) {}
4692 void encode(bufferlist
& bl
) const;
4693 void decode(bufferlist::iterator
& bl
);
4694 void dump(Formatter
*f
) const;
4695 static void generate_test_instances(list
<object
*>& o
);
4697 WRITE_CLASS_ENCODER(object
)
4699 map
<hobject_t
,object
> objects
;
4700 eversion_t valid_through
;
4701 eversion_t incr_since
;
4703 void merge_incr(const ScrubMap
&l
);
4704 void insert(const ScrubMap
&r
) {
4705 objects
.insert(r
.objects
.begin(), r
.objects
.end());
4707 void swap(ScrubMap
&r
) {
4708 ::swap(objects
, r
.objects
);
4709 ::swap(valid_through
, r
.valid_through
);
4710 ::swap(incr_since
, r
.incr_since
);
4713 void encode(bufferlist
& bl
) const;
4714 void decode(bufferlist::iterator
& bl
, int64_t pool
=-1);
4715 void dump(Formatter
*f
) const;
4716 static void generate_test_instances(list
<ScrubMap
*>& o
);
4718 WRITE_CLASS_ENCODER(ScrubMap::object
)
4719 WRITE_CLASS_ENCODER(ScrubMap
)
4726 bufferlist indata
, outdata
;
4730 memset(&op
, 0, sizeof(ceph_osd_op
));
4734 * split a bufferlist into constituent indata members of a vector of OSDOps
4736 * @param ops [out] vector of OSDOps
4737 * @param in [in] combined data buffer
4739 static void split_osd_op_vector_in_data(vector
<OSDOp
>& ops
, bufferlist
& in
);
4742 * merge indata members of a vector of OSDOp into a single bufferlist
4744 * Notably this also encodes certain other OSDOp data into the data
4745 * buffer, including the sobject_t soid.
4747 * @param ops [in] vector of OSDOps
4748 * @param out [out] combined data buffer
4750 static void merge_osd_op_vector_in_data(vector
<OSDOp
>& ops
, bufferlist
& out
);
4753 * split a bufferlist into constituent outdata members of a vector of OSDOps
4755 * @param ops [out] vector of OSDOps
4756 * @param in [in] combined data buffer
4758 static void split_osd_op_vector_out_data(vector
<OSDOp
>& ops
, bufferlist
& in
);
4761 * merge outdata members of a vector of OSDOps into a single bufferlist
4763 * @param ops [in] vector of OSDOps
4764 * @param out [out] combined data buffer
4766 static void merge_osd_op_vector_out_data(vector
<OSDOp
>& ops
, bufferlist
& out
);
4769 ostream
& operator<<(ostream
& out
, const OSDOp
& op
);
4771 struct watch_item_t
{
4774 uint32_t timeout_seconds
;
4777 watch_item_t() : cookie(0), timeout_seconds(0) { }
4778 watch_item_t(entity_name_t name
, uint64_t cookie
, uint32_t timeout
,
4779 const entity_addr_t
& addr
)
4780 : name(name
), cookie(cookie
), timeout_seconds(timeout
),
4783 void encode(bufferlist
&bl
, uint64_t features
) const {
4784 ENCODE_START(2, 1, bl
);
4786 ::encode(cookie
, bl
);
4787 ::encode(timeout_seconds
, bl
);
4788 ::encode(addr
, bl
, features
);
4791 void decode(bufferlist::iterator
&bl
) {
4792 DECODE_START(2, bl
);
4794 ::decode(cookie
, bl
);
4795 ::decode(timeout_seconds
, bl
);
4796 if (struct_v
>= 2) {
4802 WRITE_CLASS_ENCODER_FEATURES(watch_item_t
)
4804 struct obj_watch_item_t
{
4810 * obj list watch response format
4813 struct obj_list_watch_response_t
{
4814 list
<watch_item_t
> entries
;
4816 void encode(bufferlist
& bl
, uint64_t features
) const {
4817 ENCODE_START(1, 1, bl
);
4818 ::encode(entries
, bl
, features
);
4821 void decode(bufferlist::iterator
& bl
) {
4822 DECODE_START(1, bl
);
4823 ::decode(entries
, bl
);
4826 void dump(Formatter
*f
) const {
4827 f
->open_array_section("entries");
4828 for (list
<watch_item_t
>::const_iterator p
= entries
.begin(); p
!= entries
.end(); ++p
) {
4829 f
->open_object_section("watch");
4830 f
->dump_stream("watcher") << p
->name
;
4831 f
->dump_int("cookie", p
->cookie
);
4832 f
->dump_int("timeout", p
->timeout_seconds
);
4833 f
->open_object_section("addr");
4840 static void generate_test_instances(list
<obj_list_watch_response_t
*>& o
) {
4842 o
.push_back(new obj_list_watch_response_t
);
4843 o
.push_back(new obj_list_watch_response_t
);
4844 ea
.set_type(entity_addr_t::TYPE_LEGACY
);
4846 ea
.set_family(AF_INET
);
4847 ea
.set_in4_quad(0, 127);
4848 ea
.set_in4_quad(1, 0);
4849 ea
.set_in4_quad(2, 0);
4850 ea
.set_in4_quad(3, 1);
4852 o
.back()->entries
.push_back(watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT
, 1), 10, 30, ea
));
4854 ea
.set_in4_quad(3, 2);
4856 o
.back()->entries
.push_back(watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT
, 2), 20, 60, ea
));
4859 WRITE_CLASS_ENCODER_FEATURES(obj_list_watch_response_t
)
4863 vector
<snapid_t
> snaps
; // ascending
4864 vector
< pair
<uint64_t,uint64_t> > overlap
;
4867 clone_info() : cloneid(CEPH_NOSNAP
), size(0) {}
4869 void encode(bufferlist
& bl
) const {
4870 ENCODE_START(1, 1, bl
);
4871 ::encode(cloneid
, bl
);
4872 ::encode(snaps
, bl
);
4873 ::encode(overlap
, bl
);
4877 void decode(bufferlist::iterator
& bl
) {
4878 DECODE_START(1, bl
);
4879 ::decode(cloneid
, bl
);
4880 ::decode(snaps
, bl
);
4881 ::decode(overlap
, bl
);
4885 void dump(Formatter
*f
) const {
4886 if (cloneid
== CEPH_NOSNAP
)
4887 f
->dump_string("cloneid", "HEAD");
4889 f
->dump_unsigned("cloneid", cloneid
.val
);
4890 f
->open_array_section("snapshots");
4891 for (vector
<snapid_t
>::const_iterator p
= snaps
.begin(); p
!= snaps
.end(); ++p
) {
4892 f
->open_object_section("snap");
4893 f
->dump_unsigned("id", p
->val
);
4897 f
->open_array_section("overlaps");
4898 for (vector
< pair
<uint64_t,uint64_t> >::const_iterator q
= overlap
.begin();
4899 q
!= overlap
.end(); ++q
) {
4900 f
->open_object_section("overlap");
4901 f
->dump_unsigned("offset", q
->first
);
4902 f
->dump_unsigned("length", q
->second
);
4906 f
->dump_unsigned("size", size
);
4908 static void generate_test_instances(list
<clone_info
*>& o
) {
4909 o
.push_back(new clone_info
);
4910 o
.push_back(new clone_info
);
4911 o
.back()->cloneid
= 1;
4912 o
.back()->snaps
.push_back(1);
4913 o
.back()->overlap
.push_back(pair
<uint64_t,uint64_t>(0,4096));
4914 o
.back()->overlap
.push_back(pair
<uint64_t,uint64_t>(8192,4096));
4915 o
.back()->size
= 16384;
4916 o
.push_back(new clone_info
);
4917 o
.back()->cloneid
= CEPH_NOSNAP
;
4918 o
.back()->size
= 32768;
4921 WRITE_CLASS_ENCODER(clone_info
)
4924 * obj list snaps response format
4927 struct obj_list_snap_response_t
{
4928 vector
<clone_info
> clones
; // ascending
4931 void encode(bufferlist
& bl
) const {
4932 ENCODE_START(2, 1, bl
);
4933 ::encode(clones
, bl
);
4937 void decode(bufferlist::iterator
& bl
) {
4938 DECODE_START(2, bl
);
4939 ::decode(clones
, bl
);
4946 void dump(Formatter
*f
) const {
4947 f
->open_array_section("clones");
4948 for (vector
<clone_info
>::const_iterator p
= clones
.begin(); p
!= clones
.end(); ++p
) {
4949 f
->open_object_section("clone");
4953 f
->dump_unsigned("seq", seq
);
4956 static void generate_test_instances(list
<obj_list_snap_response_t
*>& o
) {
4957 o
.push_back(new obj_list_snap_response_t
);
4958 o
.push_back(new obj_list_snap_response_t
);
4961 cl
.snaps
.push_back(1);
4962 cl
.overlap
.push_back(pair
<uint64_t,uint64_t>(0,4096));
4963 cl
.overlap
.push_back(pair
<uint64_t,uint64_t>(8192,4096));
4965 o
.back()->clones
.push_back(cl
);
4966 cl
.cloneid
= CEPH_NOSNAP
;
4970 o
.back()->clones
.push_back(cl
);
4971 o
.back()->seq
= 123;
4975 WRITE_CLASS_ENCODER(obj_list_snap_response_t
)
4979 struct PromoteCounter
{
4980 std::atomic_ullong attempts
{0};
4981 std::atomic_ullong objects
{0};
4982 std::atomic_ullong bytes
{0};
4988 void finish(uint64_t size
) {
4993 void sample_and_attenuate(uint64_t *a
, uint64_t *o
, uint64_t *b
) {
5004 * ObjectStore full statfs information
5006 struct store_statfs_t
5008 uint64_t total
= 0; // Total bytes
5009 uint64_t available
= 0; // Free bytes available
5011 int64_t allocated
= 0; // Bytes allocated by the store
5012 int64_t stored
= 0; // Bytes actually stored by the user
5013 int64_t compressed
= 0; // Bytes stored after compression
5014 int64_t compressed_allocated
= 0; // Bytes allocated for compressed data
5015 int64_t compressed_original
= 0; // Bytes that were successfully compressed
5018 *this = store_statfs_t();
5020 bool operator ==(const store_statfs_t
& other
) const;
5021 void dump(Formatter
*f
) const;
5023 ostream
&operator<<(ostream
&lhs
, const store_statfs_t
&rhs
);