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.
22 #include <boost/algorithm/string.hpp>
25 #include "common/config.h"
26 #include "common/errno.h"
27 #include "common/Formatter.h"
28 #include "common/TextTable.h"
29 #include "global/global_context.h"
30 #include "include/ceph_features.h"
31 #include "include/str_map.h"
33 #include "common/code_environment.h"
34 #include "mon/health_check.h"
36 #include "crush/CrushTreeDumper.h"
37 #include "common/Clock.h"
38 #include "mon/PGMap.h"
40 #define dout_subsys ceph_subsys_osd
42 MEMPOOL_DEFINE_OBJECT_FACTORY(OSDMap
, osdmap
, osdmap
);
43 MEMPOOL_DEFINE_OBJECT_FACTORY(OSDMap::Incremental
, osdmap_inc
, osdmap
);
46 // ----------------------------------
49 void osd_info_t::dump(Formatter
*f
) const
51 f
->dump_int("last_clean_begin", last_clean_begin
);
52 f
->dump_int("last_clean_end", last_clean_end
);
53 f
->dump_int("up_from", up_from
);
54 f
->dump_int("up_thru", up_thru
);
55 f
->dump_int("down_at", down_at
);
56 f
->dump_int("lost_at", lost_at
);
59 void osd_info_t::encode(bufferlist
& bl
) const
64 encode(last_clean_begin
, bl
);
65 encode(last_clean_end
, bl
);
72 void osd_info_t::decode(bufferlist::const_iterator
& bl
)
77 decode(last_clean_begin
, bl
);
78 decode(last_clean_end
, bl
);
85 void osd_info_t::generate_test_instances(list
<osd_info_t
*>& o
)
87 o
.push_back(new osd_info_t
);
88 o
.push_back(new osd_info_t
);
89 o
.back()->last_clean_begin
= 1;
90 o
.back()->last_clean_end
= 2;
91 o
.back()->up_from
= 30;
92 o
.back()->up_thru
= 40;
93 o
.back()->down_at
= 5;
94 o
.back()->lost_at
= 6;
97 ostream
& operator<<(ostream
& out
, const osd_info_t
& info
)
99 out
<< "up_from " << info
.up_from
100 << " up_thru " << info
.up_thru
101 << " down_at " << info
.down_at
102 << " last_clean_interval [" << info
.last_clean_begin
<< "," << info
.last_clean_end
<< ")";
104 out
<< " lost_at " << info
.lost_at
;
108 // ----------------------------------
111 void osd_xinfo_t::dump(Formatter
*f
) const
113 f
->dump_stream("down_stamp") << down_stamp
;
114 f
->dump_float("laggy_probability", laggy_probability
);
115 f
->dump_int("laggy_interval", laggy_interval
);
116 f
->dump_int("features", features
);
117 f
->dump_unsigned("old_weight", old_weight
);
120 void osd_xinfo_t::encode(bufferlist
& bl
) const
122 ENCODE_START(3, 1, bl
);
123 encode(down_stamp
, bl
);
124 __u32 lp
= laggy_probability
* 0xfffffffful
;
126 encode(laggy_interval
, bl
);
127 encode(features
, bl
);
128 encode(old_weight
, bl
);
132 void osd_xinfo_t::decode(bufferlist::const_iterator
& bl
)
135 decode(down_stamp
, bl
);
138 laggy_probability
= (float)lp
/ (float)0xffffffff;
139 decode(laggy_interval
, bl
);
141 decode(features
, bl
);
145 decode(old_weight
, bl
);
151 void osd_xinfo_t::generate_test_instances(list
<osd_xinfo_t
*>& o
)
153 o
.push_back(new osd_xinfo_t
);
154 o
.push_back(new osd_xinfo_t
);
155 o
.back()->down_stamp
= utime_t(2, 3);
156 o
.back()->laggy_probability
= .123;
157 o
.back()->laggy_interval
= 123456;
158 o
.back()->old_weight
= 0x7fff;
161 ostream
& operator<<(ostream
& out
, const osd_xinfo_t
& xi
)
163 return out
<< "down_stamp " << xi
.down_stamp
164 << " laggy_probability " << xi
.laggy_probability
165 << " laggy_interval " << xi
.laggy_interval
166 << " old_weight " << xi
.old_weight
;
169 // ----------------------------------
170 // OSDMap::Incremental
172 int OSDMap::Incremental::get_net_marked_out(const OSDMap
*previous
) const
175 for (auto &weight
: new_weight
) {
176 if (weight
.second
== CEPH_OSD_OUT
&& !previous
->is_out(weight
.first
))
178 else if (weight
.second
!= CEPH_OSD_OUT
&& previous
->is_out(weight
.first
))
184 int OSDMap::Incremental::get_net_marked_down(const OSDMap
*previous
) const
187 for (auto &state
: new_state
) { //
188 if (state
.second
& CEPH_OSD_UP
) {
189 if (previous
->is_up(state
.first
))
198 int OSDMap::Incremental::identify_osd(uuid_d u
) const
200 for (auto &uuid
: new_uuid
)
201 if (uuid
.second
== u
)
206 int OSDMap::Incremental::propagate_snaps_to_tiers(CephContext
*cct
,
207 const OSDMap
& osdmap
)
209 ceph_assert(epoch
== osdmap
.get_epoch() + 1);
211 for (auto &new_pool
: new_pools
) {
212 if (!new_pool
.second
.tiers
.empty()) {
213 pg_pool_t
& base
= new_pool
.second
;
215 auto new_rem_it
= new_removed_snaps
.find(new_pool
.first
);
217 for (const auto &tier_pool
: base
.tiers
) {
218 const auto &r
= new_pools
.find(tier_pool
);
220 if (r
== new_pools
.end()) {
221 const pg_pool_t
*orig
= osdmap
.get_pg_pool(tier_pool
);
223 lderr(cct
) << __func__
<< " no pool " << tier_pool
<< dendl
;
226 tier
= get_new_pool(tier_pool
, orig
);
230 if (tier
->tier_of
!= new_pool
.first
) {
231 lderr(cct
) << __func__
<< " " << r
->first
<< " tier_of != " << new_pool
.first
<< dendl
;
235 ldout(cct
, 10) << __func__
<< " from " << new_pool
.first
<< " to "
236 << tier_pool
<< dendl
;
237 tier
->snap_seq
= base
.snap_seq
;
238 tier
->snap_epoch
= base
.snap_epoch
;
239 tier
->snaps
= base
.snaps
;
240 tier
->removed_snaps
= base
.removed_snaps
;
241 tier
->flags
|= base
.flags
& (pg_pool_t::FLAG_SELFMANAGED_SNAPS
|
242 pg_pool_t::FLAG_POOL_SNAPS
);
244 if (new_rem_it
!= new_removed_snaps
.end()) {
245 new_removed_snaps
[tier_pool
] = new_rem_it
->second
;
253 // ----------------------------------
256 bool OSDMap::subtree_is_down(int id
, set
<int> *down_cache
) const
262 down_cache
->count(id
)) {
267 crush
->get_children(id
, &children
);
268 for (const auto &child
: children
) {
269 if (!subtree_is_down(child
, down_cache
)) {
274 down_cache
->insert(id
);
279 bool OSDMap::containing_subtree_is_down(CephContext
*cct
, int id
, int subtree_type
, set
<int> *down_cache
) const
281 // use a stack-local down_cache if we didn't get one from the
282 // caller. then at least this particular call will avoid duplicated
284 set
<int> local_down_cache
;
286 down_cache
= &local_down_cache
;
295 type
= crush
->get_bucket_type(current
);
297 ceph_assert(type
>= 0);
299 if (!subtree_is_down(current
, down_cache
)) {
300 ldout(cct
, 30) << "containing_subtree_is_down(" << id
<< ") = false" << dendl
;
304 // is this a big enough subtree to be marked as down?
305 if (type
>= subtree_type
) {
306 ldout(cct
, 30) << "containing_subtree_is_down(" << id
<< ") = true ... " << type
<< " >= " << subtree_type
<< dendl
;
310 int r
= crush
->get_immediate_parent_id(current
, ¤t
);
317 bool OSDMap::subtree_type_is_down(
321 set
<int> *down_in_osds
,
322 set
<int> *up_in_osds
,
323 set
<int> *subtree_up
,
324 unordered_map
<int, set
<int> > *subtree_type_down
) const
327 bool is_down_ret
= is_down(id
);
330 down_in_osds
->insert(id
);
332 up_in_osds
->insert(id
);
338 if (subtree_type_down
&&
339 (*subtree_type_down
)[subtree_type
].count(id
)) {
344 crush
->get_children(id
, &children
);
345 for (const auto &child
: children
) {
346 if (!subtree_type_is_down(
347 cct
, child
, crush
->get_bucket_type(child
),
348 down_in_osds
, up_in_osds
, subtree_up
, subtree_type_down
)) {
349 subtree_up
->insert(id
);
353 if (subtree_type_down
) {
354 (*subtree_type_down
)[subtree_type
].insert(id
);
359 void OSDMap::Incremental::encode_client_old(bufferlist
& bl
) const
366 encode(modified
, bl
);
367 int32_t new_t
= new_pool_max
;
369 encode(new_flags
, bl
);
373 encode(new_max_osd
, bl
);
374 // for encode(new_pools, bl);
375 __u32 n
= new_pools
.size();
377 for (const auto &new_pool
: new_pools
) {
380 encode(new_pool
.second
, bl
, 0);
382 // for encode(new_pool_names, bl);
383 n
= new_pool_names
.size();
386 for (const auto &new_pool_name
: new_pool_names
) {
387 n
= new_pool_name
.first
;
389 encode(new_pool_name
.second
, bl
);
391 // for encode(old_pools, bl);
392 n
= old_pools
.size();
394 for (auto &old_pool
: old_pools
) {
398 encode(new_up_client
, bl
, 0);
400 // legacy is map<int32_t,uint8_t>
401 uint32_t n
= new_state
.size();
403 for (auto p
: new_state
) {
405 encode((uint8_t)p
.second
, bl
);
408 encode(new_weight
, bl
);
409 // for encode(new_pg_temp, bl);
410 n
= new_pg_temp
.size();
413 for (const auto &pg_temp
: new_pg_temp
) {
414 old_pg_t opg
= pg_temp
.first
.get_old_pg();
416 encode(pg_temp
.second
, bl
);
420 void OSDMap::Incremental::encode_classic(bufferlist
& bl
, uint64_t features
) const
423 if ((features
& CEPH_FEATURE_PGID64
) == 0) {
424 encode_client_old(bl
);
433 encode(modified
, bl
);
434 encode(new_pool_max
, bl
);
435 encode(new_flags
, bl
);
439 encode(new_max_osd
, bl
);
440 encode(new_pools
, bl
, features
);
441 encode(new_pool_names
, bl
);
442 encode(old_pools
, bl
);
443 encode(new_up_client
, bl
, features
);
445 uint32_t n
= new_state
.size();
447 for (auto p
: new_state
) {
449 encode((uint8_t)p
.second
, bl
);
452 encode(new_weight
, bl
);
453 encode(new_pg_temp
, bl
);
458 encode(new_hb_back_up
, bl
, features
);
459 encode(new_up_thru
, bl
);
460 encode(new_last_clean_interval
, bl
);
461 encode(new_lost
, bl
);
462 encode(new_blacklist
, bl
, features
);
463 encode(old_blacklist
, bl
, features
);
464 encode(new_up_cluster
, bl
, features
);
465 encode(cluster_snapshot
, bl
);
466 encode(new_uuid
, bl
);
467 encode(new_xinfo
, bl
);
468 encode(new_hb_front_up
, bl
, features
);
472 static void encode_addrvec_map_as_addr(const T
& m
, bufferlist
& bl
, uint64_t f
)
474 uint32_t n
= m
.size();
478 encode(i
.second
.legacy_addr(), bl
, f
);
483 static void encode_addrvec_pvec_as_addr(const T
& m
, bufferlist
& bl
, uint64_t f
)
485 uint32_t n
= m
.size();
489 encode(i
->legacy_addr(), bl
, f
);
491 encode(entity_addr_t(), bl
, f
);
496 /* for a description of osdmap incremental versions, and when they were
497 * introduced, please refer to
498 * doc/dev/osd_internals/osdmap_versions.txt
500 void OSDMap::Incremental::encode(bufferlist
& bl
, uint64_t features
) const
503 if ((features
& CEPH_FEATURE_OSDMAP_ENC
) == 0) {
504 encode_classic(bl
, features
);
508 // only a select set of callers should *ever* be encoding new
509 // OSDMaps. others should be passing around the canonical encoded
510 // buffers from on high. select out those callers by passing in an
511 // "impossible" feature bit.
512 ceph_assert(features
& CEPH_FEATURE_RESERVED
);
513 features
&= ~CEPH_FEATURE_RESERVED
;
515 size_t start_offset
= bl
.length();
518 std::optional
<buffer::list::contiguous_filler
> crc_filler
;
520 // meta-encoding: how we include client-used and osd-specific data
521 ENCODE_START(8, 7, bl
);
525 if (!HAVE_FEATURE(features
, SERVER_LUMINOUS
)) {
527 } else if (!HAVE_FEATURE(features
, SERVER_MIMIC
)) {
529 } else if (!HAVE_FEATURE(features
, SERVER_NAUTILUS
)) {
532 ENCODE_START(v
, 1, bl
); // client-usable data
535 encode(modified
, bl
);
536 encode(new_pool_max
, bl
);
537 encode(new_flags
, bl
);
541 encode(new_max_osd
, bl
);
542 encode(new_pools
, bl
, features
);
543 encode(new_pool_names
, bl
);
544 encode(old_pools
, bl
);
546 encode(new_up_client
, bl
, features
);
548 encode_addrvec_map_as_addr(new_up_client
, bl
, features
);
551 encode(new_state
, bl
);
553 uint32_t n
= new_state
.size();
555 for (auto p
: new_state
) {
557 encode((uint8_t)p
.second
, bl
);
560 encode(new_weight
, bl
);
561 encode(new_pg_temp
, bl
);
562 encode(new_primary_temp
, bl
);
563 encode(new_primary_affinity
, bl
);
564 encode(new_erasure_code_profiles
, bl
);
565 encode(old_erasure_code_profiles
, bl
);
567 encode(new_pg_upmap
, bl
);
568 encode(old_pg_upmap
, bl
);
569 encode(new_pg_upmap_items
, bl
);
570 encode(old_pg_upmap_items
, bl
);
573 encode(new_removed_snaps
, bl
);
574 encode(new_purged_snaps
, bl
);
577 encode(new_last_up_change
, bl
);
578 encode(new_last_in_change
, bl
);
580 ENCODE_FINISH(bl
); // client-usable data
584 uint8_t target_v
= 9;
585 if (!HAVE_FEATURE(features
, SERVER_LUMINOUS
)) {
587 } else if (!HAVE_FEATURE(features
, SERVER_NAUTILUS
)) {
590 ENCODE_START(target_v
, 1, bl
); // extended, osd-only data
592 encode_addrvec_map_as_addr(new_hb_back_up
, bl
, features
);
594 encode(new_hb_back_up
, bl
, features
);
596 encode(new_up_thru
, bl
);
597 encode(new_last_clean_interval
, bl
);
598 encode(new_lost
, bl
);
599 encode(new_blacklist
, bl
, features
);
600 encode(old_blacklist
, bl
, features
);
602 encode_addrvec_map_as_addr(new_up_cluster
, bl
, features
);
604 encode(new_up_cluster
, bl
, features
);
606 encode(cluster_snapshot
, bl
);
607 encode(new_uuid
, bl
);
608 encode(new_xinfo
, bl
);
610 encode_addrvec_map_as_addr(new_hb_front_up
, bl
, features
);
612 encode(new_hb_front_up
, bl
, features
);
614 encode(features
, bl
); // NOTE: features arg, not the member
616 encode(new_nearfull_ratio
, bl
);
617 encode(new_full_ratio
, bl
);
618 encode(new_backfillfull_ratio
, bl
);
620 // 5 was string-based new_require_min_compat_client
622 encode(new_require_min_compat_client
, bl
);
623 encode(new_require_osd_release
, bl
);
626 encode(new_crush_node_flags
, bl
);
629 encode(new_device_class_flags
, bl
);
631 ENCODE_FINISH(bl
); // osd-only data
634 crc_offset
= bl
.length();
635 crc_filler
= bl
.append_hole(sizeof(uint32_t));
636 tail_offset
= bl
.length();
638 encode(full_crc
, bl
);
640 ENCODE_FINISH(bl
); // meta-encoding wrapper
644 front
.substr_of(bl
, start_offset
, crc_offset
- start_offset
);
645 inc_crc
= front
.crc32c(-1);
647 tail
.substr_of(bl
, tail_offset
, bl
.length() - tail_offset
);
648 inc_crc
= tail
.crc32c(inc_crc
);
651 crc_filler
->copy_in(4u, (char*)&crc_le
);
655 void OSDMap::Incremental::decode_classic(bufferlist::const_iterator
&p
)
665 if (v
== 4 || v
== 5) {
669 decode(new_pool_max
, p
);
670 decode(new_flags
, p
);
674 decode(new_max_osd
, p
);
680 decode(new_pools
[t
], p
);
683 decode(new_pools
, p
);
686 new_pool_names
.clear();
690 decode(new_pool_names
[t
], p
);
693 decode(new_pool_names
, p
);
703 decode(old_pools
, p
);
705 decode(new_up_client
, p
);
707 map
<int32_t,uint8_t> ns
;
710 new_state
[q
.first
] = q
.second
;
713 decode(new_weight
, p
);
720 ::decode_raw(opg
, p
);
721 decode(new_pg_temp
[pg_t(opg
)], p
);
724 decode(new_pg_temp
, p
);
727 // decode short map, too.
728 if (v
== 5 && p
.end())
735 decode(new_hb_back_up
, p
);
737 decode(new_pool_names
, p
);
738 decode(new_up_thru
, p
);
739 decode(new_last_clean_interval
, p
);
741 decode(new_blacklist
, p
);
742 decode(old_blacklist
, p
);
744 decode(new_up_cluster
, p
);
746 decode(cluster_snapshot
, p
);
750 decode(new_xinfo
, p
);
752 decode(new_hb_front_up
, p
);
755 /* for a description of osdmap incremental versions, and when they were
756 * introduced, please refer to
757 * doc/dev/osd_internals/osdmap_versions.txt
759 void OSDMap::Incremental::decode(bufferlist::const_iterator
& bl
)
763 * Older encodings of the Incremental had a single struct_v which
764 * covered the whole encoding, and was prior to our modern
765 * stuff which includes a compatv and a size. So if we see
766 * a struct_v < 7, we must rewind to the beginning and use our
769 size_t start_offset
= bl
.get_off();
770 size_t tail_offset
= 0;
771 bufferlist crc_front
, crc_tail
;
773 DECODE_START_LEGACY_COMPAT_LEN(8, 7, 7, bl
); // wrapper
775 bl
.seek(start_offset
);
779 encode_features
= CEPH_FEATURE_PGID64
;
785 DECODE_START(8, bl
); // client-usable data
788 decode(modified
, bl
);
789 decode(new_pool_max
, bl
);
790 decode(new_flags
, bl
);
794 decode(new_max_osd
, bl
);
795 decode(new_pools
, bl
);
796 decode(new_pool_names
, bl
);
797 decode(old_pools
, bl
);
798 decode(new_up_client
, bl
);
800 decode(new_state
, bl
);
802 map
<int32_t,uint8_t> ns
;
805 new_state
[q
.first
] = q
.second
;
808 decode(new_weight
, bl
);
809 decode(new_pg_temp
, bl
);
810 decode(new_primary_temp
, bl
);
812 decode(new_primary_affinity
, bl
);
814 new_primary_affinity
.clear();
816 decode(new_erasure_code_profiles
, bl
);
817 decode(old_erasure_code_profiles
, bl
);
819 new_erasure_code_profiles
.clear();
820 old_erasure_code_profiles
.clear();
823 decode(new_pg_upmap
, bl
);
824 decode(old_pg_upmap
, bl
);
825 decode(new_pg_upmap_items
, bl
);
826 decode(old_pg_upmap_items
, bl
);
829 decode(new_removed_snaps
, bl
);
830 decode(new_purged_snaps
, bl
);
833 decode(new_last_up_change
, bl
);
834 decode(new_last_in_change
, bl
);
836 DECODE_FINISH(bl
); // client-usable data
840 DECODE_START(9, bl
); // extended, osd-only data
841 decode(new_hb_back_up
, bl
);
842 decode(new_up_thru
, bl
);
843 decode(new_last_clean_interval
, bl
);
844 decode(new_lost
, bl
);
845 decode(new_blacklist
, bl
);
846 decode(old_blacklist
, bl
);
847 decode(new_up_cluster
, bl
);
848 decode(cluster_snapshot
, bl
);
849 decode(new_uuid
, bl
);
850 decode(new_xinfo
, bl
);
851 decode(new_hb_front_up
, bl
);
853 decode(encode_features
, bl
);
855 encode_features
= CEPH_FEATURE_PGID64
| CEPH_FEATURE_OSDMAP_ENC
;
857 decode(new_nearfull_ratio
, bl
);
858 decode(new_full_ratio
, bl
);
860 new_nearfull_ratio
= -1;
864 decode(new_backfillfull_ratio
, bl
);
866 new_backfillfull_ratio
= -1;
872 new_require_min_compat_client
= ceph_release_from_name(r
.c_str());
876 decode(new_require_min_compat_client
, bl
);
877 decode(new_require_osd_release
, bl
);
879 if (new_flags
>= 0 && (new_flags
& CEPH_OSDMAP_REQUIRE_LUMINOUS
)) {
880 // only for compat with post-kraken pre-luminous test clusters
881 new_require_osd_release
= CEPH_RELEASE_LUMINOUS
;
882 new_flags
&= ~(CEPH_OSDMAP_LEGACY_REQUIRE_FLAGS
);
883 } else if (new_flags
>= 0 && (new_flags
& CEPH_OSDMAP_REQUIRE_KRAKEN
)) {
884 new_require_osd_release
= CEPH_RELEASE_KRAKEN
;
885 } else if (new_flags
>= 0 && (new_flags
& CEPH_OSDMAP_REQUIRE_JEWEL
)) {
886 new_require_osd_release
= CEPH_RELEASE_JEWEL
;
888 new_require_osd_release
= -1;
892 decode(new_crush_node_flags
, bl
);
895 decode(new_device_class_flags
, bl
);
897 DECODE_FINISH(bl
); // osd-only data
902 crc_front
.substr_of(bl
.get_bl(), start_offset
, bl
.get_off() - start_offset
);
904 tail_offset
= bl
.get_off();
905 decode(full_crc
, bl
);
912 DECODE_FINISH(bl
); // wrapper
916 uint32_t actual
= crc_front
.crc32c(-1);
917 if (tail_offset
< bl
.get_off()) {
919 tail
.substr_of(bl
.get_bl(), tail_offset
, bl
.get_off() - tail_offset
);
920 actual
= tail
.crc32c(actual
);
922 if (inc_crc
!= actual
) {
924 ss
<< "bad crc, actual " << actual
<< " != expected " << inc_crc
;
926 throw buffer::malformed_input(s
.c_str());
931 void OSDMap::Incremental::dump(Formatter
*f
) const
933 f
->dump_int("epoch", epoch
);
934 f
->dump_stream("fsid") << fsid
;
935 f
->dump_stream("modified") << modified
;
936 f
->dump_stream("new_last_up_change") << new_last_up_change
;
937 f
->dump_stream("new_last_in_change") << new_last_in_change
;
938 f
->dump_int("new_pool_max", new_pool_max
);
939 f
->dump_int("new_flags", new_flags
);
940 f
->dump_float("new_full_ratio", new_full_ratio
);
941 f
->dump_float("new_nearfull_ratio", new_nearfull_ratio
);
942 f
->dump_float("new_backfillfull_ratio", new_backfillfull_ratio
);
943 f
->dump_int("new_require_min_compat_client", new_require_min_compat_client
);
944 f
->dump_int("new_require_osd_release", new_require_osd_release
);
946 if (fullmap
.length()) {
947 f
->open_object_section("full_map");
949 bufferlist fbl
= fullmap
; // kludge around constness.
950 auto p
= fbl
.cbegin();
955 if (crush
.length()) {
956 f
->open_object_section("crush");
958 bufferlist tbl
= crush
; // kludge around constness.
959 auto p
= tbl
.cbegin();
965 f
->dump_int("new_max_osd", new_max_osd
);
967 f
->open_array_section("new_pools");
969 for (const auto &new_pool
: new_pools
) {
970 f
->open_object_section("pool");
971 f
->dump_int("pool", new_pool
.first
);
972 new_pool
.second
.dump(f
);
976 f
->open_array_section("new_pool_names");
978 for (const auto &new_pool_name
: new_pool_names
) {
979 f
->open_object_section("pool_name");
980 f
->dump_int("pool", new_pool_name
.first
);
981 f
->dump_string("name", new_pool_name
.second
);
985 f
->open_array_section("old_pools");
987 for (const auto &old_pool
: old_pools
)
988 f
->dump_int("pool", old_pool
);
991 f
->open_array_section("new_up_osds");
993 for (const auto &upclient
: new_up_client
) {
994 f
->open_object_section("osd");
995 f
->dump_int("osd", upclient
.first
);
996 f
->dump_stream("public_addr") << upclient
.second
.legacy_addr();
997 f
->dump_object("public_addrs", upclient
.second
);
998 if (auto p
= new_up_cluster
.find(upclient
.first
);
999 p
!= new_up_cluster
.end()) {
1000 f
->dump_stream("cluster_addr") << p
->second
.legacy_addr();
1001 f
->dump_object("cluster_addrs", p
->second
);
1003 if (auto p
= new_hb_back_up
.find(upclient
.first
);
1004 p
!= new_hb_back_up
.end()) {
1005 f
->dump_object("heartbeat_back_addrs", p
->second
);
1007 if (auto p
= new_hb_front_up
.find(upclient
.first
);
1008 p
!= new_hb_front_up
.end()) {
1009 f
->dump_object("heartbeat_front_addrs", p
->second
);
1015 f
->open_array_section("new_weight");
1017 for (const auto &weight
: new_weight
) {
1018 f
->open_object_section("osd");
1019 f
->dump_int("osd", weight
.first
);
1020 f
->dump_int("weight", weight
.second
);
1025 f
->open_array_section("osd_state_xor");
1026 for (const auto &ns
: new_state
) {
1027 f
->open_object_section("osd");
1028 f
->dump_int("osd", ns
.first
);
1030 calc_state_set(new_state
.find(ns
.first
)->second
, st
);
1031 f
->open_array_section("state_xor");
1032 for (auto &state
: st
)
1033 f
->dump_string("state", state
);
1039 f
->open_array_section("new_pg_temp");
1041 for (const auto &pg_temp
: new_pg_temp
) {
1042 f
->open_object_section("pg");
1043 f
->dump_stream("pgid") << pg_temp
.first
;
1044 f
->open_array_section("osds");
1046 for (const auto &osd
: pg_temp
.second
)
1047 f
->dump_int("osd", osd
);
1053 f
->open_array_section("primary_temp");
1055 for (const auto &primary_temp
: new_primary_temp
) {
1056 f
->dump_stream("pgid") << primary_temp
.first
;
1057 f
->dump_int("osd", primary_temp
.second
);
1059 f
->close_section(); // primary_temp
1061 f
->open_array_section("new_pg_upmap");
1062 for (auto& i
: new_pg_upmap
) {
1063 f
->open_object_section("mapping");
1064 f
->dump_stream("pgid") << i
.first
;
1065 f
->open_array_section("osds");
1066 for (auto osd
: i
.second
) {
1067 f
->dump_int("osd", osd
);
1073 f
->open_array_section("old_pg_upmap");
1074 for (auto& i
: old_pg_upmap
) {
1075 f
->dump_stream("pgid") << i
;
1079 f
->open_array_section("new_pg_upmap_items");
1080 for (auto& i
: new_pg_upmap_items
) {
1081 f
->open_object_section("mapping");
1082 f
->dump_stream("pgid") << i
.first
;
1083 f
->open_array_section("mappings");
1084 for (auto& p
: i
.second
) {
1085 f
->open_object_section("mapping");
1086 f
->dump_int("from", p
.first
);
1087 f
->dump_int("to", p
.second
);
1094 f
->open_array_section("old_pg_upmap_items");
1095 for (auto& i
: old_pg_upmap_items
) {
1096 f
->dump_stream("pgid") << i
;
1100 f
->open_array_section("new_up_thru");
1102 for (const auto &up_thru
: new_up_thru
) {
1103 f
->open_object_section("osd");
1104 f
->dump_int("osd", up_thru
.first
);
1105 f
->dump_int("up_thru", up_thru
.second
);
1110 f
->open_array_section("new_lost");
1112 for (const auto &lost
: new_lost
) {
1113 f
->open_object_section("osd");
1114 f
->dump_int("osd", lost
.first
);
1115 f
->dump_int("epoch_lost", lost
.second
);
1120 f
->open_array_section("new_last_clean_interval");
1122 for (const auto &last_clean_interval
: new_last_clean_interval
) {
1123 f
->open_object_section("osd");
1124 f
->dump_int("osd", last_clean_interval
.first
);
1125 f
->dump_int("first", last_clean_interval
.second
.first
);
1126 f
->dump_int("last", last_clean_interval
.second
.second
);
1131 f
->open_array_section("new_blacklist");
1132 for (const auto &blist
: new_blacklist
) {
1135 f
->dump_stream(ss
.str().c_str()) << blist
.second
;
1138 f
->open_array_section("old_blacklist");
1139 for (const auto &blist
: old_blacklist
)
1140 f
->dump_stream("addr") << blist
;
1143 f
->open_array_section("new_xinfo");
1144 for (const auto &xinfo
: new_xinfo
) {
1145 f
->open_object_section("xinfo");
1146 f
->dump_int("osd", xinfo
.first
);
1147 xinfo
.second
.dump(f
);
1152 if (cluster_snapshot
.size())
1153 f
->dump_string("cluster_snapshot", cluster_snapshot
);
1155 f
->open_array_section("new_uuid");
1156 for (const auto &uuid
: new_uuid
) {
1157 f
->open_object_section("osd");
1158 f
->dump_int("osd", uuid
.first
);
1159 f
->dump_stream("uuid") << uuid
.second
;
1164 OSDMap::dump_erasure_code_profiles(new_erasure_code_profiles
, f
);
1165 f
->open_array_section("old_erasure_code_profiles");
1166 for (const auto &erasure_code_profile
: old_erasure_code_profiles
) {
1167 f
->dump_string("old", erasure_code_profile
.c_str());
1171 f
->open_array_section("new_removed_snaps");
1172 for (auto& p
: new_removed_snaps
) {
1173 f
->open_object_section("pool");
1174 f
->dump_int("pool", p
.first
);
1175 f
->open_array_section("snaps");
1176 for (auto q
= p
.second
.begin(); q
!= p
.second
.end(); ++q
) {
1177 f
->open_object_section("interval");
1178 f
->dump_unsigned("begin", q
.get_start());
1179 f
->dump_unsigned("length", q
.get_len());
1186 f
->open_array_section("new_purged_snaps");
1187 for (auto& p
: new_purged_snaps
) {
1188 f
->open_object_section("pool");
1189 f
->dump_int("pool", p
.first
);
1190 f
->open_array_section("snaps");
1191 for (auto q
= p
.second
.begin(); q
!= p
.second
.end(); ++q
) {
1192 f
->open_object_section("interval");
1193 f
->dump_unsigned("begin", q
.get_start());
1194 f
->dump_unsigned("length", q
.get_len());
1200 f
->open_array_section("new_crush_node_flags");
1201 for (auto& i
: new_crush_node_flags
) {
1202 f
->open_object_section("node");
1203 f
->dump_int("id", i
.first
);
1205 calc_state_set(i
.second
, st
);
1206 for (auto& j
: st
) {
1207 f
->dump_string("flag", j
);
1212 f
->open_array_section("new_device_class_flags");
1213 for (auto& i
: new_device_class_flags
) {
1214 f
->open_object_section("device_class");
1215 f
->dump_int("id", i
.first
);
1217 calc_state_set(i
.second
, st
);
1218 for (auto& j
: st
) {
1219 f
->dump_string("flag", j
);
1227 void OSDMap::Incremental::generate_test_instances(list
<Incremental
*>& o
)
1229 o
.push_back(new Incremental
);
1232 // ----------------------------------
1235 void OSDMap::set_epoch(epoch_t e
)
1238 for (auto &pool
: pools
)
1239 pool
.second
.last_change
= e
;
1242 bool OSDMap::is_blacklisted(const entity_addr_t
& orig
) const
1244 if (blacklist
.empty()) {
1248 // all blacklist entries are type ANY for nautilus+
1249 // FIXME: avoid this copy!
1250 entity_addr_t a
= orig
;
1251 if (require_osd_release
< CEPH_RELEASE_NAUTILUS
) {
1252 a
.set_type(entity_addr_t::TYPE_LEGACY
);
1254 a
.set_type(entity_addr_t::TYPE_ANY
);
1257 // this specific instance?
1258 if (blacklist
.count(a
)) {
1262 // is entire ip blacklisted?
1266 if (blacklist
.count(a
)) {
1274 bool OSDMap::is_blacklisted(const entity_addrvec_t
& av
) const
1276 if (blacklist
.empty())
1279 for (auto& a
: av
.v
) {
1280 if (is_blacklisted(a
)) {
1288 void OSDMap::get_blacklist(list
<pair
<entity_addr_t
,utime_t
> > *bl
) const
1290 std::copy(blacklist
.begin(), blacklist
.end(), std::back_inserter(*bl
));
1293 void OSDMap::get_blacklist(std::set
<entity_addr_t
> *bl
) const
1295 for (const auto &i
: blacklist
) {
1296 bl
->insert(i
.first
);
1300 void OSDMap::set_max_osd(int m
)
1304 osd_state
.resize(m
);
1305 osd_weight
.resize(m
);
1306 for (; o
<max_osd
; o
++) {
1308 osd_weight
[o
] = CEPH_OSD_OUT
;
1311 osd_xinfo
.resize(m
);
1312 osd_addrs
->client_addrs
.resize(m
);
1313 osd_addrs
->cluster_addrs
.resize(m
);
1314 osd_addrs
->hb_back_addrs
.resize(m
);
1315 osd_addrs
->hb_front_addrs
.resize(m
);
1316 osd_uuid
->resize(m
);
1317 if (osd_primary_affinity
)
1318 osd_primary_affinity
->resize(m
, CEPH_OSD_DEFAULT_PRIMARY_AFFINITY
);
1323 int OSDMap::calc_num_osds()
1328 for (int i
=0; i
<max_osd
; i
++) {
1329 if (osd_state
[i
] & CEPH_OSD_EXISTS
) {
1331 if (osd_state
[i
] & CEPH_OSD_UP
) {
1334 if (get_weight(i
) != CEPH_OSD_OUT
) {
1342 void OSDMap::get_full_pools(CephContext
*cct
,
1344 set
<int64_t> *backfillfull
,
1345 set
<int64_t> *nearfull
) const
1348 ceph_assert(backfillfull
);
1349 ceph_assert(nearfull
);
1351 backfillfull
->clear();
1354 vector
<int> full_osds
;
1355 vector
<int> backfillfull_osds
;
1356 vector
<int> nearfull_osds
;
1357 for (int i
= 0; i
< max_osd
; ++i
) {
1358 if (exists(i
) && is_up(i
) && is_in(i
)) {
1359 if (osd_state
[i
] & CEPH_OSD_FULL
)
1360 full_osds
.push_back(i
);
1361 else if (osd_state
[i
] & CEPH_OSD_BACKFILLFULL
)
1362 backfillfull_osds
.push_back(i
);
1363 else if (osd_state
[i
] & CEPH_OSD_NEARFULL
)
1364 nearfull_osds
.push_back(i
);
1368 for (auto i
: full_osds
) {
1369 get_pool_ids_by_osd(cct
, i
, full
);
1371 for (auto i
: backfillfull_osds
) {
1372 get_pool_ids_by_osd(cct
, i
, backfillfull
);
1374 for (auto i
: nearfull_osds
) {
1375 get_pool_ids_by_osd(cct
, i
, nearfull
);
1379 void OSDMap::get_full_osd_counts(set
<int> *full
, set
<int> *backfill
,
1380 set
<int> *nearfull
) const
1385 for (int i
= 0; i
< max_osd
; ++i
) {
1386 if (exists(i
) && is_up(i
) && is_in(i
)) {
1387 if (osd_state
[i
] & CEPH_OSD_FULL
)
1389 else if (osd_state
[i
] & CEPH_OSD_BACKFILLFULL
)
1390 backfill
->emplace(i
);
1391 else if (osd_state
[i
] & CEPH_OSD_NEARFULL
)
1392 nearfull
->emplace(i
);
1397 void OSDMap::get_all_osds(set
<int32_t>& ls
) const
1399 for (int i
=0; i
<max_osd
; i
++)
1404 void OSDMap::get_up_osds(set
<int32_t>& ls
) const
1406 for (int i
= 0; i
< max_osd
; i
++) {
1412 void OSDMap::get_out_existing_osds(set
<int32_t>& ls
) const
1414 for (int i
= 0; i
< max_osd
; i
++) {
1415 if (exists(i
) && get_weight(i
) == CEPH_OSD_OUT
)
1420 void OSDMap::get_flag_set(set
<string
> *flagset
) const
1422 for (unsigned i
= 0; i
< sizeof(flags
) * 8; ++i
) {
1423 if (flags
& (1<<i
)) {
1424 flagset
->insert(get_flag_string(flags
& (1<<i
)));
1429 void OSDMap::calc_state_set(int state
, set
<string
>& st
)
1432 for (unsigned s
= 1; t
; s
<<= 1) {
1435 st
.insert(ceph_osd_state_name(s
));
1440 void OSDMap::adjust_osd_weights(const map
<int,double>& weights
, Incremental
& inc
) const
1443 for (const auto &weight
: weights
) {
1444 if (weight
.second
> max
)
1445 max
= weight
.second
;
1448 for (const auto &weight
: weights
) {
1449 inc
.new_weight
[weight
.first
] = (unsigned)((weight
.second
/ max
) * CEPH_OSD_IN
);
1453 int OSDMap::identify_osd(const entity_addr_t
& addr
) const
1455 for (int i
=0; i
<max_osd
; i
++)
1456 if (exists(i
) && (get_addrs(i
).contains(addr
) ||
1457 get_cluster_addrs(i
).contains(addr
)))
1462 int OSDMap::identify_osd(const uuid_d
& u
) const
1464 for (int i
=0; i
<max_osd
; i
++)
1465 if (exists(i
) && get_uuid(i
) == u
)
1470 int OSDMap::identify_osd_on_all_channels(const entity_addr_t
& addr
) const
1472 for (int i
=0; i
<max_osd
; i
++)
1473 if (exists(i
) && (get_addrs(i
).contains(addr
) ||
1474 get_cluster_addrs(i
).contains(addr
) ||
1475 get_hb_back_addrs(i
).contains(addr
) ||
1476 get_hb_front_addrs(i
).contains(addr
)))
1481 int OSDMap::find_osd_on_ip(const entity_addr_t
& ip
) const
1483 for (int i
=0; i
<max_osd
; i
++)
1484 if (exists(i
) && (get_addrs(i
).is_same_host(ip
) ||
1485 get_cluster_addrs(i
).is_same_host(ip
)))
1491 uint64_t OSDMap::get_features(int entity_type
, uint64_t *pmask
) const
1493 uint64_t features
= 0; // things we actually have
1494 uint64_t mask
= 0; // things we could have
1496 if (crush
->has_nondefault_tunables())
1497 features
|= CEPH_FEATURE_CRUSH_TUNABLES
;
1498 if (crush
->has_nondefault_tunables2())
1499 features
|= CEPH_FEATURE_CRUSH_TUNABLES2
;
1500 if (crush
->has_nondefault_tunables3())
1501 features
|= CEPH_FEATURE_CRUSH_TUNABLES3
;
1502 if (crush
->has_v4_buckets())
1503 features
|= CEPH_FEATURE_CRUSH_V4
;
1504 if (crush
->has_nondefault_tunables5())
1505 features
|= CEPH_FEATURE_CRUSH_TUNABLES5
;
1506 if (crush
->has_incompat_choose_args()) {
1507 features
|= CEPH_FEATUREMASK_CRUSH_CHOOSE_ARGS
;
1509 mask
|= CEPH_FEATURES_CRUSH
;
1511 if (!pg_upmap
.empty() || !pg_upmap_items
.empty())
1512 features
|= CEPH_FEATUREMASK_OSDMAP_PG_UPMAP
;
1513 mask
|= CEPH_FEATUREMASK_OSDMAP_PG_UPMAP
;
1515 for (auto &pool
: pools
) {
1516 if (pool
.second
.has_flag(pg_pool_t::FLAG_HASHPSPOOL
)) {
1517 features
|= CEPH_FEATURE_OSDHASHPSPOOL
;
1519 if (!pool
.second
.tiers
.empty() ||
1520 pool
.second
.is_tier()) {
1521 features
|= CEPH_FEATURE_OSD_CACHEPOOL
;
1523 int ruleid
= crush
->find_rule(pool
.second
.get_crush_rule(),
1524 pool
.second
.get_type(),
1525 pool
.second
.get_size());
1527 if (crush
->is_v2_rule(ruleid
))
1528 features
|= CEPH_FEATURE_CRUSH_V2
;
1529 if (crush
->is_v3_rule(ruleid
))
1530 features
|= CEPH_FEATURE_CRUSH_TUNABLES3
;
1531 if (crush
->is_v5_rule(ruleid
))
1532 features
|= CEPH_FEATURE_CRUSH_TUNABLES5
;
1535 mask
|= CEPH_FEATURE_OSDHASHPSPOOL
| CEPH_FEATURE_OSD_CACHEPOOL
;
1537 if (osd_primary_affinity
) {
1538 for (int i
= 0; i
< max_osd
; ++i
) {
1539 if ((*osd_primary_affinity
)[i
] != CEPH_OSD_DEFAULT_PRIMARY_AFFINITY
) {
1540 features
|= CEPH_FEATURE_OSD_PRIMARY_AFFINITY
;
1545 mask
|= CEPH_FEATURE_OSD_PRIMARY_AFFINITY
;
1547 if (entity_type
== CEPH_ENTITY_TYPE_OSD
) {
1548 const uint64_t jewel_features
= CEPH_FEATURE_SERVER_JEWEL
;
1549 if (require_osd_release
>= CEPH_RELEASE_JEWEL
) {
1550 features
|= jewel_features
;
1552 mask
|= jewel_features
;
1554 const uint64_t kraken_features
= CEPH_FEATUREMASK_SERVER_KRAKEN
1555 | CEPH_FEATURE_MSG_ADDR2
;
1556 if (require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
1557 features
|= kraken_features
;
1559 mask
|= kraken_features
;
1562 if (require_min_compat_client
>= CEPH_RELEASE_NAUTILUS
) {
1563 // if min_compat_client is >= nautilus, require v2 cephx signatures
1565 features
|= CEPH_FEATUREMASK_CEPHX_V2
;
1566 } else if (require_osd_release
>= CEPH_RELEASE_NAUTILUS
&&
1567 entity_type
== CEPH_ENTITY_TYPE_OSD
) {
1568 // if osds are >= nautilus, at least require the signatures from them
1569 features
|= CEPH_FEATUREMASK_CEPHX_V2
;
1571 mask
|= CEPH_FEATUREMASK_CEPHX_V2
;
1578 uint8_t OSDMap::get_min_compat_client() const
1580 uint64_t f
= get_features(CEPH_ENTITY_TYPE_CLIENT
, nullptr);
1582 if (HAVE_FEATURE(f
, OSDMAP_PG_UPMAP
) || // v12.0.0-1733-g27d6f43
1583 HAVE_FEATURE(f
, CRUSH_CHOOSE_ARGS
)) { // v12.0.1-2172-gef1ef28
1584 return CEPH_RELEASE_LUMINOUS
; // v12.2.0
1586 if (HAVE_FEATURE(f
, CRUSH_TUNABLES5
)) { // v10.0.0-612-g043a737
1587 return CEPH_RELEASE_JEWEL
; // v10.2.0
1589 if (HAVE_FEATURE(f
, CRUSH_V4
)) { // v0.91-678-g325fc56
1590 return CEPH_RELEASE_HAMMER
; // v0.94.0
1592 if (HAVE_FEATURE(f
, OSD_PRIMARY_AFFINITY
) || // v0.76-553-gf825624
1593 HAVE_FEATURE(f
, CRUSH_TUNABLES3
) || // v0.76-395-ge20a55d
1594 HAVE_FEATURE(f
, OSD_CACHEPOOL
)) { // v0.67-401-gb91c1c5
1595 return CEPH_RELEASE_FIREFLY
; // v0.80.0
1597 if (HAVE_FEATURE(f
, CRUSH_TUNABLES2
) || // v0.54-684-g0cc47ff
1598 HAVE_FEATURE(f
, OSDHASHPSPOOL
)) { // v0.57-398-g8cc2b0f
1599 return CEPH_RELEASE_DUMPLING
; // v0.67.0
1601 if (HAVE_FEATURE(f
, CRUSH_TUNABLES
)) { // v0.48argonaut-206-g6f381af
1602 return CEPH_RELEASE_ARGONAUT
; // v0.48argonaut-206-g6f381af
1604 return CEPH_RELEASE_ARGONAUT
; // v0.48argonaut-206-g6f381af
1607 uint8_t OSDMap::get_require_min_compat_client() const
1609 return require_min_compat_client
;
1612 void OSDMap::_calc_up_osd_features()
1615 cached_up_osd_features
= 0;
1616 for (int osd
= 0; osd
< max_osd
; ++osd
) {
1619 const osd_xinfo_t
&xi
= get_xinfo(osd
);
1620 if (xi
.features
== 0)
1621 continue; // bogus xinfo, maybe #20751 or similar, skipping
1623 cached_up_osd_features
= xi
.features
;
1626 cached_up_osd_features
&= xi
.features
;
1631 uint64_t OSDMap::get_up_osd_features() const
1633 return cached_up_osd_features
;
1636 void OSDMap::dedup(const OSDMap
*o
, OSDMap
*n
)
1639 if (o
->epoch
== n
->epoch
)
1645 if (o
->max_osd
!= n
->max_osd
)
1647 for (int i
= 0; i
< o
->max_osd
&& i
< n
->max_osd
; i
++) {
1648 if ( n
->osd_addrs
->client_addrs
[i
] && o
->osd_addrs
->client_addrs
[i
] &&
1649 *n
->osd_addrs
->client_addrs
[i
] == *o
->osd_addrs
->client_addrs
[i
])
1650 n
->osd_addrs
->client_addrs
[i
] = o
->osd_addrs
->client_addrs
[i
];
1653 if ( n
->osd_addrs
->cluster_addrs
[i
] && o
->osd_addrs
->cluster_addrs
[i
] &&
1654 *n
->osd_addrs
->cluster_addrs
[i
] == *o
->osd_addrs
->cluster_addrs
[i
])
1655 n
->osd_addrs
->cluster_addrs
[i
] = o
->osd_addrs
->cluster_addrs
[i
];
1658 if ( n
->osd_addrs
->hb_back_addrs
[i
] && o
->osd_addrs
->hb_back_addrs
[i
] &&
1659 *n
->osd_addrs
->hb_back_addrs
[i
] == *o
->osd_addrs
->hb_back_addrs
[i
])
1660 n
->osd_addrs
->hb_back_addrs
[i
] = o
->osd_addrs
->hb_back_addrs
[i
];
1663 if ( n
->osd_addrs
->hb_front_addrs
[i
] && o
->osd_addrs
->hb_front_addrs
[i
] &&
1664 *n
->osd_addrs
->hb_front_addrs
[i
] == *o
->osd_addrs
->hb_front_addrs
[i
])
1665 n
->osd_addrs
->hb_front_addrs
[i
] = o
->osd_addrs
->hb_front_addrs
[i
];
1670 // zoinks, no differences at all!
1671 n
->osd_addrs
= o
->osd_addrs
;
1674 // does crush match?
1676 encode(*o
->crush
, oc
, CEPH_FEATURES_SUPPORTED_DEFAULT
);
1677 encode(*n
->crush
, nc
, CEPH_FEATURES_SUPPORTED_DEFAULT
);
1678 if (oc
.contents_equal(nc
)) {
1679 n
->crush
= o
->crush
;
1682 // does pg_temp match?
1683 if (*o
->pg_temp
== *n
->pg_temp
)
1684 n
->pg_temp
= o
->pg_temp
;
1686 // does primary_temp match?
1687 if (o
->primary_temp
->size() == n
->primary_temp
->size()) {
1688 if (*o
->primary_temp
== *n
->primary_temp
)
1689 n
->primary_temp
= o
->primary_temp
;
1693 if (o
->osd_uuid
->size() == n
->osd_uuid
->size() &&
1694 *o
->osd_uuid
== *n
->osd_uuid
)
1695 n
->osd_uuid
= o
->osd_uuid
;
1698 void OSDMap::clean_temps(CephContext
*cct
,
1699 const OSDMap
& oldmap
,
1700 const OSDMap
& nextmap
,
1701 Incremental
*pending_inc
)
1703 ldout(cct
, 10) << __func__
<< dendl
;
1705 for (auto pg
: *nextmap
.pg_temp
) {
1706 // if pool does not exist, remove any existing pg_temps associated with
1707 // it. we don't care about pg_temps on the pending_inc either; if there
1708 // are new_pg_temp entries on the pending, clear them out just as well.
1709 if (!nextmap
.have_pg_pool(pg
.first
.pool())) {
1710 ldout(cct
, 10) << __func__
<< " removing pg_temp " << pg
.first
1711 << " for nonexistent pool " << pg
.first
.pool() << dendl
;
1712 pending_inc
->new_pg_temp
[pg
.first
].clear();
1716 unsigned num_up
= 0;
1717 for (auto o
: pg
.second
) {
1718 if (!nextmap
.is_down(o
)) {
1724 ldout(cct
, 10) << __func__
<< " removing pg_temp " << pg
.first
1725 << " with all down osds" << pg
.second
<< dendl
;
1726 pending_inc
->new_pg_temp
[pg
.first
].clear();
1729 // redundant pg_temp?
1732 nextmap
.pg_to_raw_up(pg
.first
, &raw_up
, &primary
);
1733 bool remove
= false;
1734 if (raw_up
== pg
.second
) {
1735 ldout(cct
, 10) << __func__
<< " removing pg_temp " << pg
.first
<< " "
1736 << pg
.second
<< " that matches raw_up mapping" << dendl
;
1739 // oversized pg_temp?
1740 if (pg
.second
.size() > nextmap
.get_pg_pool(pg
.first
.pool())->get_size()) {
1741 ldout(cct
, 10) << __func__
<< " removing pg_temp " << pg
.first
<< " "
1742 << pg
.second
<< " exceeds pool size" << dendl
;
1746 if (oldmap
.pg_temp
->count(pg
.first
))
1747 pending_inc
->new_pg_temp
[pg
.first
].clear();
1749 pending_inc
->new_pg_temp
.erase(pg
.first
);
1753 for (auto &pg
: *nextmap
.primary_temp
) {
1755 if (nextmap
.is_down(pg
.second
)) {
1756 ldout(cct
, 10) << __func__
<< " removing primary_temp " << pg
.first
1757 << " to down " << pg
.second
<< dendl
;
1758 pending_inc
->new_primary_temp
[pg
.first
] = -1;
1761 // redundant primary_temp?
1762 vector
<int> real_up
, templess_up
;
1763 int real_primary
, templess_primary
;
1764 pg_t pgid
= pg
.first
;
1765 nextmap
.pg_to_acting_osds(pgid
, &real_up
, &real_primary
);
1766 nextmap
.pg_to_raw_up(pgid
, &templess_up
, &templess_primary
);
1767 if (real_primary
== templess_primary
){
1768 ldout(cct
, 10) << __func__
<< " removing primary_temp "
1769 << pgid
<< " -> " << real_primary
1770 << " (unnecessary/redundant)" << dendl
;
1771 if (oldmap
.primary_temp
->count(pgid
))
1772 pending_inc
->new_primary_temp
[pgid
] = -1;
1774 pending_inc
->new_primary_temp
.erase(pgid
);
1779 void OSDMap::maybe_remove_pg_upmaps(CephContext
*cct
,
1780 const OSDMap
& oldmap
,
1781 const OSDMap
& nextmap
,
1782 Incremental
*pending_inc
)
1784 ldout(cct
, 10) << __func__
<< dendl
;
1786 set
<pg_t
> to_cancel
;
1787 map
<int, map
<int, float>> rule_weight_map
;
1789 for (auto& p
: nextmap
.pg_upmap
) {
1790 to_check
.insert(p
.first
);
1792 for (auto& p
: nextmap
.pg_upmap_items
) {
1793 to_check
.insert(p
.first
);
1795 for (auto& p
: pending_inc
->new_pg_upmap
) {
1796 to_check
.insert(p
.first
);
1798 for (auto& p
: pending_inc
->new_pg_upmap_items
) {
1799 to_check
.insert(p
.first
);
1801 for (auto& pg
: to_check
) {
1802 const pg_pool_t
*pi
= nextmap
.get_pg_pool(pg
.pool());
1803 if (!pi
|| pg
.ps() >= pi
->get_pg_num_pending()) {
1804 ldout(cct
, 0) << __func__
<< " pg " << pg
<< " is gone or merge source"
1806 to_cancel
.insert(pg
);
1809 if (pi
->is_pending_merge(pg
, nullptr)) {
1810 ldout(cct
, 0) << __func__
<< " pg " << pg
<< " is pending merge"
1812 to_cancel
.insert(pg
);
1817 nextmap
.pg_to_raw_up(pg
, &raw_up
, &primary
);
1819 up
.reserve(raw_up
.size());
1820 for (auto osd
: raw_up
) {
1821 // skip non-existent/down osd for erasure-coded PGs
1822 if (osd
== CRUSH_ITEM_NONE
)
1826 auto crush_rule
= nextmap
.get_pg_pool_crush_rule(pg
);
1827 auto r
= nextmap
.crush
->verify_upmap(cct
,
1829 nextmap
.get_pg_pool_size(pg
),
1832 ldout(cct
, 0) << __func__
<< " verify_upmap of pg " << pg
1833 << " returning " << r
1835 to_cancel
.insert(pg
);
1838 // below we check against crush-topology changing..
1839 map
<int, float> weight_map
;
1840 auto it
= rule_weight_map
.find(crush_rule
);
1841 if (it
== rule_weight_map
.end()) {
1842 auto r
= nextmap
.crush
->get_rule_weight_osd_map(crush_rule
, &weight_map
);
1844 lderr(cct
) << __func__
<< " unable to get crush weight_map for "
1845 << "crush_rule " << crush_rule
<< dendl
;
1848 rule_weight_map
[crush_rule
] = weight_map
;
1850 weight_map
= it
->second
;
1852 ldout(cct
, 10) << __func__
<< " pg " << pg
1853 << " weight_map " << weight_map
1855 for (auto osd
: up
) {
1856 auto it
= weight_map
.find(osd
);
1857 if (it
== weight_map
.end()) {
1858 // osd is gone or has been moved out of the specific crush-tree
1859 to_cancel
.insert(pg
);
1862 auto adjusted_weight
= nextmap
.get_weightf(it
->first
) * it
->second
;
1863 if (adjusted_weight
== 0) {
1864 // osd is out/crush-out
1865 to_cancel
.insert(pg
);
1870 for (auto &pg
: to_cancel
) {
1872 auto it
= pending_inc
->new_pg_upmap
.find(pg
);
1873 if (it
!= pending_inc
->new_pg_upmap
.end()) {
1874 ldout(cct
, 10) << __func__
<< " cancel invalid pending "
1875 << "pg_upmap entry "
1876 << it
->first
<< "->" << it
->second
1878 pending_inc
->new_pg_upmap
.erase(it
);
1880 if (oldmap
.pg_upmap
.count(pg
)) {
1881 ldout(cct
, 10) << __func__
<< " cancel invalid pg_upmap entry "
1882 << oldmap
.pg_upmap
.find(pg
)->first
<< "->"
1883 << oldmap
.pg_upmap
.find(pg
)->second
1885 pending_inc
->old_pg_upmap
.insert(pg
);
1889 auto it
= pending_inc
->new_pg_upmap_items
.find(pg
);
1890 if (it
!= pending_inc
->new_pg_upmap_items
.end()) {
1891 ldout(cct
, 10) << __func__
<< " cancel invalid pending "
1892 << "pg_upmap_items entry "
1893 << it
->first
<< "->" << it
->second
1895 pending_inc
->new_pg_upmap_items
.erase(it
);
1897 if (oldmap
.pg_upmap_items
.count(pg
)) {
1898 ldout(cct
, 10) << __func__
<< " cancel invalid "
1899 << "pg_upmap_items entry "
1900 << oldmap
.pg_upmap_items
.find(pg
)->first
<< "->"
1901 << oldmap
.pg_upmap_items
.find(pg
)->second
1903 pending_inc
->old_pg_upmap_items
.insert(pg
);
1907 nextmap
.clean_pg_upmaps(cct
, pending_inc
);
1910 int OSDMap::apply_incremental(const Incremental
&inc
)
1912 new_blacklist_entries
= false;
1915 else if (inc
.fsid
!= fsid
)
1918 ceph_assert(inc
.epoch
== epoch
+1);
1921 modified
= inc
.modified
;
1924 if (inc
.fullmap
.length()) {
1925 bufferlist
bl(inc
.fullmap
);
1930 // nope, incremental.
1931 if (inc
.new_flags
>= 0) {
1932 flags
= inc
.new_flags
;
1933 // the below is just to cover a newly-upgraded luminous mon
1934 // cluster that has to set require_jewel_osds or
1935 // require_kraken_osds before the osds can be upgraded to
1937 if (flags
& CEPH_OSDMAP_REQUIRE_KRAKEN
) {
1938 if (require_osd_release
< CEPH_RELEASE_KRAKEN
) {
1939 require_osd_release
= CEPH_RELEASE_KRAKEN
;
1941 } else if (flags
& CEPH_OSDMAP_REQUIRE_JEWEL
) {
1942 if (require_osd_release
< CEPH_RELEASE_JEWEL
) {
1943 require_osd_release
= CEPH_RELEASE_JEWEL
;
1948 if (inc
.new_max_osd
>= 0)
1949 set_max_osd(inc
.new_max_osd
);
1951 if (inc
.new_pool_max
!= -1)
1952 pool_max
= inc
.new_pool_max
;
1954 for (const auto &pool
: inc
.new_pools
) {
1955 pools
[pool
.first
] = pool
.second
;
1956 pools
[pool
.first
].last_change
= epoch
;
1959 new_removed_snaps
= inc
.new_removed_snaps
;
1960 new_purged_snaps
= inc
.new_purged_snaps
;
1961 for (auto p
= new_removed_snaps
.begin();
1962 p
!= new_removed_snaps
.end();
1964 removed_snaps_queue
[p
->first
].union_of(p
->second
);
1966 for (auto p
= new_purged_snaps
.begin();
1967 p
!= new_purged_snaps
.end();
1969 auto q
= removed_snaps_queue
.find(p
->first
);
1970 ceph_assert(q
!= removed_snaps_queue
.end());
1971 q
->second
.subtract(p
->second
);
1972 if (q
->second
.empty()) {
1973 removed_snaps_queue
.erase(q
);
1977 if (inc
.new_last_up_change
!= utime_t()) {
1978 last_up_change
= inc
.new_last_up_change
;
1980 if (inc
.new_last_in_change
!= utime_t()) {
1981 last_in_change
= inc
.new_last_in_change
;
1984 for (const auto &pname
: inc
.new_pool_names
) {
1985 auto pool_name_entry
= pool_name
.find(pname
.first
);
1986 if (pool_name_entry
!= pool_name
.end()) {
1987 name_pool
.erase(pool_name_entry
->second
);
1988 pool_name_entry
->second
= pname
.second
;
1990 pool_name
[pname
.first
] = pname
.second
;
1992 name_pool
[pname
.second
] = pname
.first
;
1995 for (const auto &pool
: inc
.old_pools
) {
1997 name_pool
.erase(pool_name
[pool
]);
1998 pool_name
.erase(pool
);
2001 for (const auto &weight
: inc
.new_weight
) {
2002 set_weight(weight
.first
, weight
.second
);
2004 // if we are marking in, clear the AUTOOUT and NEW bits, and clear
2005 // xinfo old_weight.
2006 if (weight
.second
) {
2007 osd_state
[weight
.first
] &= ~(CEPH_OSD_AUTOOUT
| CEPH_OSD_NEW
);
2008 osd_xinfo
[weight
.first
].old_weight
= 0;
2012 for (const auto &primary_affinity
: inc
.new_primary_affinity
) {
2013 set_primary_affinity(primary_affinity
.first
, primary_affinity
.second
);
2016 // erasure_code_profiles
2017 for (const auto &profile
: inc
.old_erasure_code_profiles
)
2018 erasure_code_profiles
.erase(profile
);
2020 for (const auto &profile
: inc
.new_erasure_code_profiles
) {
2021 set_erasure_code_profile(profile
.first
, profile
.second
);
2025 for (const auto &state
: inc
.new_state
) {
2026 const auto osd
= state
.first
;
2027 int s
= state
.second
? state
.second
: CEPH_OSD_UP
;
2028 if ((osd_state
[osd
] & CEPH_OSD_UP
) &&
2029 (s
& CEPH_OSD_UP
)) {
2030 osd_info
[osd
].down_at
= epoch
;
2031 osd_xinfo
[osd
].down_stamp
= modified
;
2033 if ((osd_state
[osd
] & CEPH_OSD_EXISTS
) &&
2034 (s
& CEPH_OSD_EXISTS
)) {
2035 // osd is destroyed; clear out anything interesting.
2036 (*osd_uuid
)[osd
] = uuid_d();
2037 osd_info
[osd
] = osd_info_t();
2038 osd_xinfo
[osd
] = osd_xinfo_t();
2039 set_primary_affinity(osd
, CEPH_OSD_DEFAULT_PRIMARY_AFFINITY
);
2040 osd_addrs
->client_addrs
[osd
].reset(new entity_addrvec_t());
2041 osd_addrs
->cluster_addrs
[osd
].reset(new entity_addrvec_t());
2042 osd_addrs
->hb_front_addrs
[osd
].reset(new entity_addrvec_t());
2043 osd_addrs
->hb_back_addrs
[osd
].reset(new entity_addrvec_t());
2046 osd_state
[osd
] ^= s
;
2050 for (const auto &client
: inc
.new_up_client
) {
2051 osd_state
[client
.first
] |= CEPH_OSD_EXISTS
| CEPH_OSD_UP
;
2052 osd_addrs
->client_addrs
[client
.first
].reset(
2053 new entity_addrvec_t(client
.second
));
2054 osd_addrs
->hb_back_addrs
[client
.first
].reset(
2055 new entity_addrvec_t(inc
.new_hb_back_up
.find(client
.first
)->second
));
2056 osd_addrs
->hb_front_addrs
[client
.first
].reset(
2057 new entity_addrvec_t(inc
.new_hb_front_up
.find(client
.first
)->second
));
2059 osd_info
[client
.first
].up_from
= epoch
;
2062 for (const auto &cluster
: inc
.new_up_cluster
)
2063 osd_addrs
->cluster_addrs
[cluster
.first
].reset(
2064 new entity_addrvec_t(cluster
.second
));
2067 for (const auto &thru
: inc
.new_up_thru
)
2068 osd_info
[thru
.first
].up_thru
= thru
.second
;
2070 for (const auto &interval
: inc
.new_last_clean_interval
) {
2071 osd_info
[interval
.first
].last_clean_begin
= interval
.second
.first
;
2072 osd_info
[interval
.first
].last_clean_end
= interval
.second
.second
;
2075 for (const auto &lost
: inc
.new_lost
)
2076 osd_info
[lost
.first
].lost_at
= lost
.second
;
2079 for (const auto &xinfo
: inc
.new_xinfo
)
2080 osd_xinfo
[xinfo
.first
] = xinfo
.second
;
2083 for (const auto &uuid
: inc
.new_uuid
)
2084 (*osd_uuid
)[uuid
.first
] = uuid
.second
;
2087 for (const auto &pg
: inc
.new_pg_temp
) {
2088 if (pg
.second
.empty())
2089 pg_temp
->erase(pg
.first
);
2091 pg_temp
->set(pg
.first
, pg
.second
);
2093 if (!inc
.new_pg_temp
.empty()) {
2094 // make sure pg_temp is efficiently stored
2098 for (const auto &pg
: inc
.new_primary_temp
) {
2099 if (pg
.second
== -1)
2100 primary_temp
->erase(pg
.first
);
2102 (*primary_temp
)[pg
.first
] = pg
.second
;
2105 for (auto& p
: inc
.new_pg_upmap
) {
2106 pg_upmap
[p
.first
] = p
.second
;
2108 for (auto& pg
: inc
.old_pg_upmap
) {
2111 for (auto& p
: inc
.new_pg_upmap_items
) {
2112 pg_upmap_items
[p
.first
] = p
.second
;
2114 for (auto& pg
: inc
.old_pg_upmap_items
) {
2115 pg_upmap_items
.erase(pg
);
2119 if (!inc
.new_blacklist
.empty()) {
2120 blacklist
.insert(inc
.new_blacklist
.begin(),inc
.new_blacklist
.end());
2121 new_blacklist_entries
= true;
2123 for (const auto &addr
: inc
.old_blacklist
)
2124 blacklist
.erase(addr
);
2126 for (auto& i
: inc
.new_crush_node_flags
) {
2128 crush_node_flags
[i
.first
] = i
.second
;
2130 crush_node_flags
.erase(i
.first
);
2134 for (auto& i
: inc
.new_device_class_flags
) {
2136 device_class_flags
[i
.first
] = i
.second
;
2138 device_class_flags
.erase(i
.first
);
2142 // cluster snapshot?
2143 if (inc
.cluster_snapshot
.length()) {
2144 cluster_snapshot
= inc
.cluster_snapshot
;
2145 cluster_snapshot_epoch
= inc
.epoch
;
2147 cluster_snapshot
.clear();
2148 cluster_snapshot_epoch
= 0;
2151 if (inc
.new_nearfull_ratio
>= 0) {
2152 nearfull_ratio
= inc
.new_nearfull_ratio
;
2154 if (inc
.new_backfillfull_ratio
>= 0) {
2155 backfillfull_ratio
= inc
.new_backfillfull_ratio
;
2157 if (inc
.new_full_ratio
>= 0) {
2158 full_ratio
= inc
.new_full_ratio
;
2160 if (inc
.new_require_min_compat_client
> 0) {
2161 require_min_compat_client
= inc
.new_require_min_compat_client
;
2163 if (inc
.new_require_osd_release
>= 0) {
2164 require_osd_release
= inc
.new_require_osd_release
;
2165 if (require_osd_release
>= CEPH_RELEASE_LUMINOUS
) {
2166 flags
&= ~(CEPH_OSDMAP_LEGACY_REQUIRE_FLAGS
);
2167 flags
|= CEPH_OSDMAP_RECOVERY_DELETES
;
2171 if (inc
.new_require_osd_release
>= 0) {
2172 require_osd_release
= inc
.new_require_osd_release
;
2173 if (require_osd_release
>= CEPH_RELEASE_NAUTILUS
) {
2174 flags
|= CEPH_OSDMAP_PGLOG_HARDLIMIT
;
2177 // do new crush map last (after up/down stuff)
2178 if (inc
.crush
.length()) {
2179 bufferlist
bl(inc
.crush
);
2180 auto blp
= bl
.cbegin();
2181 crush
.reset(new CrushWrapper
);
2183 if (require_osd_release
>= CEPH_RELEASE_LUMINOUS
) {
2184 // only increment if this is a luminous-encoded osdmap, lest
2185 // the mon's crush_version diverge from what the osds or others
2186 // are decoding and applying on their end. if we won't encode
2187 // it in the canonical version, don't change it.
2190 for (auto it
= device_class_flags
.begin();
2191 it
!= device_class_flags
.end();) {
2192 const char* class_name
= crush
->get_class_name(it
->first
);
2193 if (!class_name
) // device class is gone
2194 it
= device_class_flags
.erase(it
);
2201 _calc_up_osd_features();
2206 int OSDMap::map_to_pg(
2210 const string
& nspace
,
2213 // calculate ps (placement seed)
2214 const pg_pool_t
*pool
= get_pg_pool(poolid
);
2219 ps
= pool
->hash_key(key
, nspace
);
2221 ps
= pool
->hash_key(name
, nspace
);
2222 *pg
= pg_t(ps
, poolid
);
2226 int OSDMap::object_locator_to_pg(
2227 const object_t
& oid
, const object_locator_t
& loc
, pg_t
&pg
) const
2229 if (loc
.hash
>= 0) {
2230 if (!get_pg_pool(loc
.get_pool())) {
2233 pg
= pg_t(loc
.hash
, loc
.get_pool());
2236 return map_to_pg(loc
.get_pool(), oid
.name
, loc
.key
, loc
.nspace
, &pg
);
2239 ceph_object_layout
OSDMap::make_object_layout(
2240 object_t oid
, int pg_pool
, string nspace
) const
2242 object_locator_t
loc(pg_pool
, nspace
);
2244 ceph_object_layout ol
;
2245 pg_t pgid
= object_locator_to_pg(oid
, loc
);
2246 ol
.ol_pgid
= pgid
.get_old_pg().v
;
2247 ol
.ol_stripe_unit
= 0;
2251 void OSDMap::_remove_nonexistent_osds(const pg_pool_t
& pool
,
2252 vector
<int>& osds
) const
2254 if (pool
.can_shift_osds()) {
2255 unsigned removed
= 0;
2256 for (unsigned i
= 0; i
< osds
.size(); i
++) {
2257 if (!exists(osds
[i
])) {
2262 osds
[i
- removed
] = osds
[i
];
2266 osds
.resize(osds
.size() - removed
);
2268 for (auto& osd
: osds
) {
2270 osd
= CRUSH_ITEM_NONE
;
2275 void OSDMap::_pg_to_raw_osds(
2276 const pg_pool_t
& pool
, pg_t pg
,
2281 ps_t pps
= pool
.raw_pg_to_pps(pg
); // placement ps
2282 unsigned size
= pool
.get_size();
2285 int ruleno
= crush
->find_rule(pool
.get_crush_rule(), pool
.get_type(), size
);
2287 crush
->do_rule(ruleno
, pps
, *osds
, size
, osd_weight
, pg
.pool());
2289 _remove_nonexistent_osds(pool
, *osds
);
2295 int OSDMap::_pick_primary(const vector
<int>& osds
) const
2297 for (auto osd
: osds
) {
2298 if (osd
!= CRUSH_ITEM_NONE
) {
2305 void OSDMap::_apply_upmap(const pg_pool_t
& pi
, pg_t raw_pg
, vector
<int> *raw
) const
2307 pg_t pg
= pi
.raw_pg_to_pg(raw_pg
);
2308 auto p
= pg_upmap
.find(pg
);
2309 if (p
!= pg_upmap
.end()) {
2310 // make sure targets aren't marked out
2311 for (auto osd
: p
->second
) {
2312 if (osd
!= CRUSH_ITEM_NONE
&& osd
< max_osd
&& osd
>= 0 &&
2313 osd_weight
[osd
] == 0) {
2314 // reject/ignore the explicit mapping
2318 *raw
= vector
<int>(p
->second
.begin(), p
->second
.end());
2319 // continue to check and apply pg_upmap_items if any
2322 auto q
= pg_upmap_items
.find(pg
);
2323 if (q
!= pg_upmap_items
.end()) {
2324 // NOTE: this approach does not allow a bidirectional swap,
2325 // e.g., [[1,2],[2,1]] applied to [0,1,2] -> [0,2,1].
2326 for (auto& r
: q
->second
) {
2327 // make sure the replacement value doesn't already appear
2328 bool exists
= false;
2330 for (unsigned i
= 0; i
< raw
->size(); ++i
) {
2331 int osd
= (*raw
)[i
];
2332 if (osd
== r
.second
) {
2336 // ignore mapping if target is marked out (or invalid osd id)
2337 if (osd
== r
.first
&&
2339 !(r
.second
!= CRUSH_ITEM_NONE
&& r
.second
< max_osd
&&
2340 r
.second
>= 0 && osd_weight
[r
.second
] == 0)) {
2344 if (!exists
&& pos
>= 0) {
2345 (*raw
)[pos
] = r
.second
;
2351 // pg -> (up osd list)
2352 void OSDMap::_raw_to_up_osds(const pg_pool_t
& pool
, const vector
<int>& raw
,
2353 vector
<int> *up
) const
2355 if (pool
.can_shift_osds()) {
2358 up
->reserve(raw
.size());
2359 for (unsigned i
=0; i
<raw
.size(); i
++) {
2360 if (!exists(raw
[i
]) || is_down(raw
[i
]))
2362 up
->push_back(raw
[i
]);
2365 // set down/dne devices to NONE
2366 up
->resize(raw
.size());
2367 for (int i
= raw
.size() - 1; i
>= 0; --i
) {
2368 if (!exists(raw
[i
]) || is_down(raw
[i
])) {
2369 (*up
)[i
] = CRUSH_ITEM_NONE
;
2377 void OSDMap::_apply_primary_affinity(ps_t seed
,
2378 const pg_pool_t
& pool
,
2382 // do we have any non-default primary_affinity values for these osds?
2383 if (!osd_primary_affinity
)
2387 for (const auto osd
: *osds
) {
2388 if (osd
!= CRUSH_ITEM_NONE
&&
2389 (*osd_primary_affinity
)[osd
] != CEPH_OSD_DEFAULT_PRIMARY_AFFINITY
) {
2397 // pick the primary. feed both the seed (for the pg) and the osd
2398 // into the hash/rng so that a proportional fraction of an osd's pgs
2399 // get rejected as primary.
2401 for (unsigned i
= 0; i
< osds
->size(); ++i
) {
2403 if (o
== CRUSH_ITEM_NONE
)
2405 unsigned a
= (*osd_primary_affinity
)[o
];
2406 if (a
< CEPH_OSD_MAX_PRIMARY_AFFINITY
&&
2407 (crush_hash32_2(CRUSH_HASH_RJENKINS1
,
2408 seed
, o
) >> 16) >= a
) {
2409 // we chose not to use this primary. note it anyway as a
2410 // fallback in case we don't pick anyone else, but keep looking.
2421 *primary
= (*osds
)[pos
];
2423 if (pool
.can_shift_osds() && pos
> 0) {
2424 // move the new primary to the front.
2425 for (int i
= pos
; i
> 0; --i
) {
2426 (*osds
)[i
] = (*osds
)[i
-1];
2428 (*osds
)[0] = *primary
;
2432 void OSDMap::_get_temp_osds(const pg_pool_t
& pool
, pg_t pg
,
2433 vector
<int> *temp_pg
, int *temp_primary
) const
2435 pg
= pool
.raw_pg_to_pg(pg
);
2436 const auto p
= pg_temp
->find(pg
);
2438 if (p
!= pg_temp
->end()) {
2439 for (unsigned i
=0; i
<p
->second
.size(); i
++) {
2440 if (!exists(p
->second
[i
]) || is_down(p
->second
[i
])) {
2441 if (pool
.can_shift_osds()) {
2444 temp_pg
->push_back(CRUSH_ITEM_NONE
);
2447 temp_pg
->push_back(p
->second
[i
]);
2451 const auto &pp
= primary_temp
->find(pg
);
2453 if (pp
!= primary_temp
->end()) {
2454 *temp_primary
= pp
->second
;
2455 } else if (!temp_pg
->empty()) { // apply pg_temp's primary
2456 for (unsigned i
= 0; i
< temp_pg
->size(); ++i
) {
2457 if ((*temp_pg
)[i
] != CRUSH_ITEM_NONE
) {
2458 *temp_primary
= (*temp_pg
)[i
];
2465 void OSDMap::pg_to_raw_osds(pg_t pg
, vector
<int> *raw
, int *primary
) const
2467 const pg_pool_t
*pool
= get_pg_pool(pg
.pool());
2473 _pg_to_raw_osds(*pool
, pg
, raw
, NULL
);
2474 *primary
= _pick_primary(*raw
);
2477 void OSDMap::pg_to_raw_upmap(pg_t pg
, vector
<int> *raw_upmap
) const
2479 auto pool
= get_pg_pool(pg
.pool());
2484 _pg_to_raw_osds(*pool
, pg
, raw_upmap
, NULL
);
2485 _apply_upmap(*pool
, pg
, raw_upmap
);
2488 void OSDMap::pg_to_raw_up(pg_t pg
, vector
<int> *up
, int *primary
) const
2490 const pg_pool_t
*pool
= get_pg_pool(pg
.pool());
2498 _pg_to_raw_osds(*pool
, pg
, &raw
, &pps
);
2499 _apply_upmap(*pool
, pg
, &raw
);
2500 _raw_to_up_osds(*pool
, raw
, up
);
2501 *primary
= _pick_primary(raw
);
2502 _apply_primary_affinity(pps
, *pool
, up
, primary
);
2505 void OSDMap::_pg_to_up_acting_osds(
2506 const pg_t
& pg
, vector
<int> *up
, int *up_primary
,
2507 vector
<int> *acting
, int *acting_primary
,
2508 bool raw_pg_to_pg
) const
2510 const pg_pool_t
*pool
= get_pg_pool(pg
.pool());
2512 (!raw_pg_to_pg
&& pg
.ps() >= pool
->get_pg_num())) {
2520 *acting_primary
= -1;
2525 vector
<int> _acting
;
2527 int _acting_primary
;
2529 _get_temp_osds(*pool
, pg
, &_acting
, &_acting_primary
);
2530 if (_acting
.empty() || up
|| up_primary
) {
2531 _pg_to_raw_osds(*pool
, pg
, &raw
, &pps
);
2532 _apply_upmap(*pool
, pg
, &raw
);
2533 _raw_to_up_osds(*pool
, raw
, &_up
);
2534 _up_primary
= _pick_primary(_up
);
2535 _apply_primary_affinity(pps
, *pool
, &_up
, &_up_primary
);
2536 if (_acting
.empty()) {
2538 if (_acting_primary
== -1) {
2539 _acting_primary
= _up_primary
;
2546 *up_primary
= _up_primary
;
2550 acting
->swap(_acting
);
2552 *acting_primary
= _acting_primary
;
2555 int OSDMap::calc_pg_rank(int osd
, const vector
<int>& acting
, int nrep
)
2558 nrep
= acting
.size();
2559 for (int i
=0; i
<nrep
; i
++)
2560 if (acting
[i
] == osd
)
2565 int OSDMap::calc_pg_role(int osd
, const vector
<int>& acting
, int nrep
)
2567 return calc_pg_rank(osd
, acting
, nrep
);
2570 bool OSDMap::primary_changed(
2572 const vector
<int> &oldacting
,
2574 const vector
<int> &newacting
)
2576 if (oldacting
.empty() && newacting
.empty())
2577 return false; // both still empty
2578 if (oldacting
.empty() ^ newacting
.empty())
2579 return true; // was empty, now not, or vice versa
2580 if (oldprimary
!= newprimary
)
2581 return true; // primary changed
2582 if (calc_pg_rank(oldprimary
, oldacting
) !=
2583 calc_pg_rank(newprimary
, newacting
))
2585 return false; // same primary (tho replicas may have changed)
2588 uint64_t OSDMap::get_encoding_features() const
2590 uint64_t f
= SIGNIFICANT_FEATURES
;
2591 if (require_osd_release
< CEPH_RELEASE_NAUTILUS
) {
2592 f
&= ~CEPH_FEATURE_SERVER_NAUTILUS
;
2594 if (require_osd_release
< CEPH_RELEASE_MIMIC
) {
2595 f
&= ~CEPH_FEATURE_SERVER_MIMIC
;
2597 if (require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
2598 f
&= ~(CEPH_FEATURE_SERVER_LUMINOUS
|
2599 CEPH_FEATURE_CRUSH_CHOOSE_ARGS
);
2601 if (require_osd_release
< CEPH_RELEASE_KRAKEN
) {
2602 f
&= ~(CEPH_FEATURE_SERVER_KRAKEN
|
2603 CEPH_FEATURE_MSG_ADDR2
);
2605 if (require_osd_release
< CEPH_RELEASE_JEWEL
) {
2606 f
&= ~(CEPH_FEATURE_SERVER_JEWEL
|
2607 CEPH_FEATURE_NEW_OSDOP_ENCODING
|
2608 CEPH_FEATURE_CRUSH_TUNABLES5
);
2613 // serialize, unserialize
2614 void OSDMap::encode_client_old(bufferlist
& bl
) const
2623 encode(created
, bl
);
2624 encode(modified
, bl
);
2626 // for encode(pools, bl);
2627 __u32 n
= pools
.size();
2630 for (const auto &pool
: pools
) {
2633 encode(pool
.second
, bl
, 0);
2635 // for encode(pool_name, bl);
2636 n
= pool_name
.size();
2638 for (const auto &pname
: pool_name
) {
2641 encode(pname
.second
, bl
);
2643 // for encode(pool_max, bl);
2649 encode(max_osd
, bl
);
2651 uint32_t n
= osd_state
.size();
2653 for (auto s
: osd_state
) {
2654 encode((uint8_t)s
, bl
);
2657 encode(osd_weight
, bl
);
2658 encode(osd_addrs
->client_addrs
, bl
, 0);
2660 // for encode(pg_temp, bl);
2661 n
= pg_temp
->size();
2663 for (const auto pg
: *pg_temp
) {
2664 old_pg_t opg
= pg
.first
.get_old_pg();
2666 encode(pg
.second
, bl
);
2671 crush
->encode(cbl
, 0 /* legacy (no) features */);
2675 void OSDMap::encode_classic(bufferlist
& bl
, uint64_t features
) const
2678 if ((features
& CEPH_FEATURE_PGID64
) == 0) {
2679 encode_client_old(bl
);
2689 encode(created
, bl
);
2690 encode(modified
, bl
);
2692 encode(pools
, bl
, features
);
2693 encode(pool_name
, bl
);
2694 encode(pool_max
, bl
);
2698 encode(max_osd
, bl
);
2700 uint32_t n
= osd_state
.size();
2702 for (auto s
: osd_state
) {
2703 encode((uint8_t)s
, bl
);
2706 encode(osd_weight
, bl
);
2707 encode(osd_addrs
->client_addrs
, bl
, features
);
2709 encode(*pg_temp
, bl
);
2713 crush
->encode(cbl
, 0 /* legacy (no) features */);
2719 encode(osd_addrs
->hb_back_addrs
, bl
, features
);
2720 encode(osd_info
, bl
);
2721 encode(blacklist
, bl
, features
);
2722 encode(osd_addrs
->cluster_addrs
, bl
, features
);
2723 encode(cluster_snapshot_epoch
, bl
);
2724 encode(cluster_snapshot
, bl
);
2725 encode(*osd_uuid
, bl
);
2726 encode(osd_xinfo
, bl
);
2727 encode(osd_addrs
->hb_front_addrs
, bl
, features
);
2730 /* for a description of osdmap versions, and when they were introduced, please
2732 * doc/dev/osd_internals/osdmap_versions.txt
2734 void OSDMap::encode(bufferlist
& bl
, uint64_t features
) const
2737 if ((features
& CEPH_FEATURE_OSDMAP_ENC
) == 0) {
2738 encode_classic(bl
, features
);
2742 // only a select set of callers should *ever* be encoding new
2743 // OSDMaps. others should be passing around the canonical encoded
2744 // buffers from on high. select out those callers by passing in an
2745 // "impossible" feature bit.
2746 ceph_assert(features
& CEPH_FEATURE_RESERVED
);
2747 features
&= ~CEPH_FEATURE_RESERVED
;
2749 size_t start_offset
= bl
.length();
2752 std::optional
<buffer::list::contiguous_filler
> crc_filler
;
2754 // meta-encoding: how we include client-used and osd-specific data
2755 ENCODE_START(8, 7, bl
);
2758 // NOTE: any new encoding dependencies must be reflected by
2759 // SIGNIFICANT_FEATURES
2761 if (!HAVE_FEATURE(features
, SERVER_LUMINOUS
)) {
2763 } else if (!HAVE_FEATURE(features
, SERVER_MIMIC
)) {
2765 } else if (!HAVE_FEATURE(features
, SERVER_NAUTILUS
)) {
2768 ENCODE_START(v
, 1, bl
); // client-usable data
2772 encode(created
, bl
);
2773 encode(modified
, bl
);
2775 encode(pools
, bl
, features
);
2776 encode(pool_name
, bl
);
2777 encode(pool_max
, bl
);
2780 decltype(flags
) f
= flags
;
2781 if (require_osd_release
>= CEPH_RELEASE_LUMINOUS
)
2782 f
|= CEPH_OSDMAP_REQUIRE_LUMINOUS
| CEPH_OSDMAP_RECOVERY_DELETES
;
2783 else if (require_osd_release
== CEPH_RELEASE_KRAKEN
)
2784 f
|= CEPH_OSDMAP_REQUIRE_KRAKEN
;
2785 else if (require_osd_release
== CEPH_RELEASE_JEWEL
)
2786 f
|= CEPH_OSDMAP_REQUIRE_JEWEL
;
2792 encode(max_osd
, bl
);
2794 encode(osd_state
, bl
);
2796 uint32_t n
= osd_state
.size();
2798 for (auto s
: osd_state
) {
2799 encode((uint8_t)s
, bl
);
2802 encode(osd_weight
, bl
);
2804 encode(osd_addrs
->client_addrs
, bl
, features
);
2806 encode_addrvec_pvec_as_addr(osd_addrs
->client_addrs
, bl
, features
);
2809 encode(*pg_temp
, bl
);
2810 encode(*primary_temp
, bl
);
2811 if (osd_primary_affinity
) {
2812 encode(*osd_primary_affinity
, bl
);
2820 crush
->encode(cbl
, features
);
2822 encode(erasure_code_profiles
, bl
);
2825 encode(pg_upmap
, bl
);
2826 encode(pg_upmap_items
, bl
);
2828 ceph_assert(pg_upmap
.empty());
2829 ceph_assert(pg_upmap_items
.empty());
2832 encode(crush_version
, bl
);
2835 encode(new_removed_snaps
, bl
);
2836 encode(new_purged_snaps
, bl
);
2839 encode(last_up_change
, bl
);
2840 encode(last_in_change
, bl
);
2842 ENCODE_FINISH(bl
); // client-usable data
2846 // NOTE: any new encoding dependencies must be reflected by
2847 // SIGNIFICANT_FEATURES
2848 uint8_t target_v
= 9;
2849 if (!HAVE_FEATURE(features
, SERVER_LUMINOUS
)) {
2851 } else if (!HAVE_FEATURE(features
, SERVER_MIMIC
)) {
2853 } else if (!HAVE_FEATURE(features
, SERVER_NAUTILUS
)) {
2856 ENCODE_START(target_v
, 1, bl
); // extended, osd-only data
2858 encode_addrvec_pvec_as_addr(osd_addrs
->hb_back_addrs
, bl
, features
);
2860 encode(osd_addrs
->hb_back_addrs
, bl
, features
);
2862 encode(osd_info
, bl
);
2864 // put this in a sorted, ordered map<> so that we encode in a
2865 // deterministic order.
2866 map
<entity_addr_t
,utime_t
> blacklist_map
;
2867 for (const auto &addr
: blacklist
)
2868 blacklist_map
.insert(make_pair(addr
.first
, addr
.second
));
2869 encode(blacklist_map
, bl
, features
);
2872 encode_addrvec_pvec_as_addr(osd_addrs
->cluster_addrs
, bl
, features
);
2874 encode(osd_addrs
->cluster_addrs
, bl
, features
);
2876 encode(cluster_snapshot_epoch
, bl
);
2877 encode(cluster_snapshot
, bl
);
2878 encode(*osd_uuid
, bl
);
2879 encode(osd_xinfo
, bl
);
2881 encode_addrvec_pvec_as_addr(osd_addrs
->hb_front_addrs
, bl
, features
);
2883 encode(osd_addrs
->hb_front_addrs
, bl
, features
);
2885 if (target_v
>= 2) {
2886 encode(nearfull_ratio
, bl
);
2887 encode(full_ratio
, bl
);
2888 encode(backfillfull_ratio
, bl
);
2890 // 4 was string-based new_require_min_compat_client
2891 if (target_v
>= 5) {
2892 encode(require_min_compat_client
, bl
);
2893 encode(require_osd_release
, bl
);
2895 if (target_v
>= 6) {
2896 encode(removed_snaps_queue
, bl
);
2898 if (target_v
>= 8) {
2899 encode(crush_node_flags
, bl
);
2901 if (target_v
>= 9) {
2902 encode(device_class_flags
, bl
);
2904 ENCODE_FINISH(bl
); // osd-only data
2907 crc_offset
= bl
.length();
2908 crc_filler
= bl
.append_hole(sizeof(uint32_t));
2909 tail_offset
= bl
.length();
2911 ENCODE_FINISH(bl
); // meta-encoding wrapper
2915 front
.substr_of(bl
, start_offset
, crc_offset
- start_offset
);
2916 crc
= front
.crc32c(-1);
2917 if (tail_offset
< bl
.length()) {
2919 tail
.substr_of(bl
, tail_offset
, bl
.length() - tail_offset
);
2920 crc
= tail
.crc32c(crc
);
2924 crc_filler
->copy_in(4, (char*)&crc_le
);
2928 /* for a description of osdmap versions, and when they were introduced, please
2930 * doc/dev/osd_internals/osdmap_versions.txt
2932 void OSDMap::decode(bufferlist
& bl
)
2934 auto p
= bl
.cbegin();
2938 void OSDMap::decode_classic(bufferlist::const_iterator
& p
)
2949 decode(modified
, p
);
2953 int32_t max_pools
= 0;
2954 decode(max_pools
, p
);
2955 pool_max
= max_pools
;
2961 decode(pools
[t
], p
);
2966 } else if (v
== 5) {
2971 decode(pool_name
[t
], p
);
2978 decode(pool_name
, p
);
2979 decode(pool_max
, p
);
2981 // kludge around some old bug that zeroed out pool_max (#2307)
2982 if (pools
.size() && pool_max
< pools
.rbegin()->first
) {
2983 pool_max
= pools
.rbegin()->first
;
2992 osd_state
.resize(os
.size());
2993 for (unsigned i
= 0; i
< os
.size(); ++i
) {
2994 osd_state
[i
] = os
[i
];
2997 decode(osd_weight
, p
);
2998 decode(osd_addrs
->client_addrs
, p
);
3004 ::decode_raw(opg
, p
);
3005 mempool::osdmap::vector
<int32_t> v
;
3007 pg_temp
->set(pg_t(opg
), v
);
3010 decode(*pg_temp
, p
);
3016 auto cblp
= cbl
.cbegin();
3017 crush
->decode(cblp
);
3023 decode(osd_addrs
->hb_back_addrs
, p
);
3024 decode(osd_info
, p
);
3026 decode(pool_name
, p
);
3028 decode(blacklist
, p
);
3030 decode(osd_addrs
->cluster_addrs
, p
);
3032 osd_addrs
->cluster_addrs
.resize(osd_addrs
->client_addrs
.size());
3035 decode(cluster_snapshot_epoch
, p
);
3036 decode(cluster_snapshot
, p
);
3040 decode(*osd_uuid
, p
);
3042 osd_uuid
->resize(max_osd
);
3045 decode(osd_xinfo
, p
);
3047 osd_xinfo
.resize(max_osd
);
3050 decode(osd_addrs
->hb_front_addrs
, p
);
3052 osd_addrs
->hb_front_addrs
.resize(osd_addrs
->hb_back_addrs
.size());
3054 osd_primary_affinity
.reset();
3059 void OSDMap::decode(bufferlist::const_iterator
& bl
)
3063 * Older encodings of the OSDMap had a single struct_v which
3064 * covered the whole encoding, and was prior to our modern
3065 * stuff which includes a compatv and a size. So if we see
3066 * a struct_v < 7, we must rewind to the beginning and use our
3069 size_t start_offset
= bl
.get_off();
3070 size_t tail_offset
= 0;
3071 bufferlist crc_front
, crc_tail
;
3073 DECODE_START_LEGACY_COMPAT_LEN(8, 7, 7, bl
); // wrapper
3075 bl
.seek(start_offset
);
3080 * Since we made it past that hurdle, we can use our normal paths.
3083 DECODE_START(9, bl
); // client-usable data
3087 decode(created
, bl
);
3088 decode(modified
, bl
);
3091 decode(pool_name
, bl
);
3092 decode(pool_max
, bl
);
3096 decode(max_osd
, bl
);
3097 if (struct_v
>= 5) {
3098 decode(osd_state
, bl
);
3102 osd_state
.resize(os
.size());
3103 for (unsigned i
= 0; i
< os
.size(); ++i
) {
3104 osd_state
[i
] = os
[i
];
3107 decode(osd_weight
, bl
);
3108 decode(osd_addrs
->client_addrs
, bl
);
3110 decode(*pg_temp
, bl
);
3111 decode(*primary_temp
, bl
);
3112 // dates back to firefly. version increased from 2 to 3 still in firefly.
3113 // do we really still need to keep this around? even for old clients?
3114 if (struct_v
>= 2) {
3115 osd_primary_affinity
.reset(new mempool::osdmap::vector
<__u32
>);
3116 decode(*osd_primary_affinity
, bl
);
3117 if (osd_primary_affinity
->empty())
3118 osd_primary_affinity
.reset();
3120 osd_primary_affinity
.reset();
3126 auto cblp
= cbl
.cbegin();
3127 crush
->decode(cblp
);
3128 // added in firefly; version increased in luminous, so it affects
3129 // giant, hammer, infernallis, jewel, and kraken. probably should be left
3130 // alone until we require clients to be all luminous?
3131 if (struct_v
>= 3) {
3132 decode(erasure_code_profiles
, bl
);
3134 erasure_code_profiles
.clear();
3136 // version increased from 3 to 4 still in luminous, so same as above
3138 if (struct_v
>= 4) {
3139 decode(pg_upmap
, bl
);
3140 decode(pg_upmap_items
, bl
);
3143 pg_upmap_items
.clear();
3145 // again, version increased from 5 to 6 still in luminous, so above
3147 if (struct_v
>= 6) {
3148 decode(crush_version
, bl
);
3150 // version increase from 6 to 7 in mimic
3151 if (struct_v
>= 7) {
3152 decode(new_removed_snaps
, bl
);
3153 decode(new_purged_snaps
, bl
);
3155 // version increase from 7 to 8, 8 to 9, in nautilus.
3156 if (struct_v
>= 9) {
3157 decode(last_up_change
, bl
);
3158 decode(last_in_change
, bl
);
3160 DECODE_FINISH(bl
); // client-usable data
3164 DECODE_START(9, bl
); // extended, osd-only data
3165 decode(osd_addrs
->hb_back_addrs
, bl
);
3166 decode(osd_info
, bl
);
3167 decode(blacklist
, bl
);
3168 decode(osd_addrs
->cluster_addrs
, bl
);
3169 decode(cluster_snapshot_epoch
, bl
);
3170 decode(cluster_snapshot
, bl
);
3171 decode(*osd_uuid
, bl
);
3172 decode(osd_xinfo
, bl
);
3173 decode(osd_addrs
->hb_front_addrs
, bl
);
3175 if (struct_v
>= 2) {
3176 decode(nearfull_ratio
, bl
);
3177 decode(full_ratio
, bl
);
3182 if (struct_v
>= 3) {
3183 decode(backfillfull_ratio
, bl
);
3185 backfillfull_ratio
= 0;
3187 if (struct_v
== 4) {
3191 require_min_compat_client
= ceph_release_from_name(r
.c_str());
3193 if (struct_v
>= 5) {
3194 decode(require_min_compat_client
, bl
);
3195 decode(require_osd_release
, bl
);
3196 if (require_osd_release
>= CEPH_RELEASE_NAUTILUS
) {
3197 flags
|= CEPH_OSDMAP_PGLOG_HARDLIMIT
;
3199 if (require_osd_release
>= CEPH_RELEASE_LUMINOUS
) {
3200 flags
&= ~(CEPH_OSDMAP_LEGACY_REQUIRE_FLAGS
);
3201 flags
|= CEPH_OSDMAP_RECOVERY_DELETES
;
3204 if (flags
& CEPH_OSDMAP_REQUIRE_LUMINOUS
) {
3205 // only for compat with post-kraken pre-luminous test clusters
3206 require_osd_release
= CEPH_RELEASE_LUMINOUS
;
3207 flags
&= ~(CEPH_OSDMAP_LEGACY_REQUIRE_FLAGS
);
3208 flags
|= CEPH_OSDMAP_RECOVERY_DELETES
;
3209 } else if (flags
& CEPH_OSDMAP_REQUIRE_KRAKEN
) {
3210 require_osd_release
= CEPH_RELEASE_KRAKEN
;
3211 } else if (flags
& CEPH_OSDMAP_REQUIRE_JEWEL
) {
3212 require_osd_release
= CEPH_RELEASE_JEWEL
;
3214 require_osd_release
= 0;
3217 if (struct_v
>= 6) {
3218 decode(removed_snaps_queue
, bl
);
3220 if (struct_v
>= 8) {
3221 decode(crush_node_flags
, bl
);
3223 crush_node_flags
.clear();
3225 if (struct_v
>= 9) {
3226 decode(device_class_flags
, bl
);
3228 device_class_flags
.clear();
3230 DECODE_FINISH(bl
); // osd-only data
3233 if (struct_v
>= 8) {
3234 crc_front
.substr_of(bl
.get_bl(), start_offset
, bl
.get_off() - start_offset
);
3236 tail_offset
= bl
.get_off();
3239 crc_defined
= false;
3243 DECODE_FINISH(bl
); // wrapper
3247 uint32_t actual
= crc_front
.crc32c(-1);
3248 if (tail_offset
< bl
.get_off()) {
3250 tail
.substr_of(bl
.get_bl(), tail_offset
, bl
.get_off() - tail_offset
);
3251 actual
= tail
.crc32c(actual
);
3253 if (crc
!= actual
) {
3255 ss
<< "bad crc, actual " << actual
<< " != expected " << crc
;
3256 string s
= ss
.str();
3257 throw buffer::malformed_input(s
.c_str());
3264 void OSDMap::post_decode()
3268 for (const auto &pname
: pool_name
) {
3269 name_pool
[pname
.second
] = pname
.first
;
3273 _calc_up_osd_features();
3276 void OSDMap::dump_erasure_code_profiles(
3277 const mempool::osdmap::map
<string
,map
<string
,string
>>& profiles
,
3280 f
->open_object_section("erasure_code_profiles");
3281 for (const auto &profile
: profiles
) {
3282 f
->open_object_section(profile
.first
.c_str());
3283 for (const auto &profm
: profile
.second
) {
3284 f
->dump_string(profm
.first
.c_str(), profm
.second
.c_str());
3291 void OSDMap::dump(Formatter
*f
) const
3293 f
->dump_int("epoch", get_epoch());
3294 f
->dump_stream("fsid") << get_fsid();
3295 f
->dump_stream("created") << get_created();
3296 f
->dump_stream("modified") << get_modified();
3297 f
->dump_stream("last_up_change") << last_up_change
;
3298 f
->dump_stream("last_in_change") << last_in_change
;
3299 f
->dump_string("flags", get_flag_string());
3300 f
->dump_unsigned("flags_num", flags
);
3301 f
->open_array_section("flags_set");
3302 set
<string
> flagset
;
3303 get_flag_set(&flagset
);
3304 for (auto p
: flagset
) {
3305 f
->dump_string("flag", p
);
3308 f
->dump_unsigned("crush_version", get_crush_version());
3309 f
->dump_float("full_ratio", full_ratio
);
3310 f
->dump_float("backfillfull_ratio", backfillfull_ratio
);
3311 f
->dump_float("nearfull_ratio", nearfull_ratio
);
3312 f
->dump_string("cluster_snapshot", get_cluster_snapshot());
3313 f
->dump_int("pool_max", get_pool_max());
3314 f
->dump_int("max_osd", get_max_osd());
3315 f
->dump_string("require_min_compat_client",
3316 ceph_release_name(require_min_compat_client
));
3317 f
->dump_string("min_compat_client",
3318 ceph_release_name(get_min_compat_client()));
3319 f
->dump_string("require_osd_release",
3320 ceph_release_name(require_osd_release
));
3322 f
->open_array_section("pools");
3323 for (const auto &pool
: pools
) {
3324 std::string
name("<unknown>");
3325 const auto &pni
= pool_name
.find(pool
.first
);
3326 if (pni
!= pool_name
.end())
3328 f
->open_object_section("pool");
3329 f
->dump_int("pool", pool
.first
);
3330 f
->dump_string("pool_name", name
);
3331 pool
.second
.dump(f
);
3336 f
->open_array_section("osds");
3337 for (int i
=0; i
<get_max_osd(); i
++)
3339 f
->open_object_section("osd_info");
3340 f
->dump_int("osd", i
);
3341 f
->dump_stream("uuid") << get_uuid(i
);
3342 f
->dump_int("up", is_up(i
));
3343 f
->dump_int("in", is_in(i
));
3344 f
->dump_float("weight", get_weightf(i
));
3345 f
->dump_float("primary_affinity", get_primary_affinityf(i
));
3346 get_info(i
).dump(f
);
3347 f
->dump_object("public_addrs", get_addrs(i
));
3348 f
->dump_object("cluster_addrs", get_cluster_addrs(i
));
3349 f
->dump_object("heartbeat_back_addrs", get_hb_back_addrs(i
));
3350 f
->dump_object("heartbeat_front_addrs", get_hb_front_addrs(i
));
3352 f
->dump_stream("public_addr") << get_addrs(i
).get_legacy_str();
3353 f
->dump_stream("cluster_addr") << get_cluster_addrs(i
).get_legacy_str();
3354 f
->dump_stream("heartbeat_back_addr")
3355 << get_hb_back_addrs(i
).get_legacy_str();
3356 f
->dump_stream("heartbeat_front_addr")
3357 << get_hb_front_addrs(i
).get_legacy_str();
3361 f
->open_array_section("state");
3362 for (const auto &state
: st
)
3363 f
->dump_string("state", state
);
3370 f
->open_array_section("osd_xinfo");
3371 for (int i
=0; i
<get_max_osd(); i
++) {
3373 f
->open_object_section("xinfo");
3374 f
->dump_int("osd", i
);
3375 osd_xinfo
[i
].dump(f
);
3381 f
->open_array_section("pg_upmap");
3382 for (auto& p
: pg_upmap
) {
3383 f
->open_object_section("mapping");
3384 f
->dump_stream("pgid") << p
.first
;
3385 f
->open_array_section("osds");
3386 for (auto q
: p
.second
) {
3387 f
->dump_int("osd", q
);
3393 f
->open_array_section("pg_upmap_items");
3394 for (auto& p
: pg_upmap_items
) {
3395 f
->open_object_section("mapping");
3396 f
->dump_stream("pgid") << p
.first
;
3397 f
->open_array_section("mappings");
3398 for (auto& q
: p
.second
) {
3399 f
->open_object_section("mapping");
3400 f
->dump_int("from", q
.first
);
3401 f
->dump_int("to", q
.second
);
3408 f
->open_array_section("pg_temp");
3412 f
->open_array_section("primary_temp");
3413 for (const auto &pg
: *primary_temp
) {
3414 f
->dump_stream("pgid") << pg
.first
;
3415 f
->dump_int("osd", pg
.second
);
3417 f
->close_section(); // primary_temp
3419 f
->open_object_section("blacklist");
3420 for (const auto &addr
: blacklist
) {
3423 f
->dump_stream(ss
.str().c_str()) << addr
.second
;
3427 dump_erasure_code_profiles(erasure_code_profiles
, f
);
3429 f
->open_array_section("removed_snaps_queue");
3430 for (auto& p
: removed_snaps_queue
) {
3431 f
->open_object_section("pool");
3432 f
->dump_int("pool", p
.first
);
3433 f
->open_array_section("snaps");
3434 for (auto q
= p
.second
.begin(); q
!= p
.second
.end(); ++q
) {
3435 f
->open_object_section("interval");
3436 f
->dump_unsigned("begin", q
.get_start());
3437 f
->dump_unsigned("length", q
.get_len());
3444 f
->open_array_section("new_removed_snaps");
3445 for (auto& p
: new_removed_snaps
) {
3446 f
->open_object_section("pool");
3447 f
->dump_int("pool", p
.first
);
3448 f
->open_array_section("snaps");
3449 for (auto q
= p
.second
.begin(); q
!= p
.second
.end(); ++q
) {
3450 f
->open_object_section("interval");
3451 f
->dump_unsigned("begin", q
.get_start());
3452 f
->dump_unsigned("length", q
.get_len());
3459 f
->open_array_section("new_purged_snaps");
3460 for (auto& p
: new_purged_snaps
) {
3461 f
->open_object_section("pool");
3462 f
->dump_int("pool", p
.first
);
3463 f
->open_array_section("snaps");
3464 for (auto q
= p
.second
.begin(); q
!= p
.second
.end(); ++q
) {
3465 f
->open_object_section("interval");
3466 f
->dump_unsigned("begin", q
.get_start());
3467 f
->dump_unsigned("length", q
.get_len());
3474 f
->open_object_section("crush_node_flags");
3475 for (auto& i
: crush_node_flags
) {
3476 string s
= crush
->item_exists(i
.first
) ? crush
->get_item_name(i
.first
)
3477 : stringify(i
.first
);
3478 f
->open_array_section(s
.c_str());
3480 calc_state_set(i
.second
, st
);
3481 for (auto& j
: st
) {
3482 f
->dump_string("flag", j
);
3487 f
->open_object_section("device_class_flags");
3488 for (auto& i
: device_class_flags
) {
3489 const char* class_name
= crush
->get_class_name(i
.first
);
3490 string s
= class_name
? class_name
: stringify(i
.first
);
3491 f
->open_array_section(s
.c_str());
3493 calc_state_set(i
.second
, st
);
3494 for (auto& j
: st
) {
3495 f
->dump_string("flag", j
);
3502 void OSDMap::generate_test_instances(list
<OSDMap
*>& o
)
3504 o
.push_back(new OSDMap
);
3506 CephContext
*cct
= new CephContext(CODE_ENVIRONMENT_UTILITY
);
3507 o
.push_back(new OSDMap
);
3509 o
.back()->build_simple(cct
, 1, fsid
, 16);
3510 o
.back()->created
= o
.back()->modified
= utime_t(1, 2); // fix timestamp
3511 o
.back()->blacklist
[entity_addr_t()] = utime_t(5, 6);
3515 string
OSDMap::get_flag_string(unsigned f
)
3518 if ( f
& CEPH_OSDMAP_NEARFULL
)
3520 if (f
& CEPH_OSDMAP_FULL
)
3522 if (f
& CEPH_OSDMAP_PAUSERD
)
3524 if (f
& CEPH_OSDMAP_PAUSEWR
)
3526 if (f
& CEPH_OSDMAP_PAUSEREC
)
3528 if (f
& CEPH_OSDMAP_NOUP
)
3530 if (f
& CEPH_OSDMAP_NODOWN
)
3532 if (f
& CEPH_OSDMAP_NOOUT
)
3534 if (f
& CEPH_OSDMAP_NOIN
)
3536 if (f
& CEPH_OSDMAP_NOBACKFILL
)
3538 if (f
& CEPH_OSDMAP_NOREBALANCE
)
3539 s
+= ",norebalance";
3540 if (f
& CEPH_OSDMAP_NORECOVER
)
3542 if (f
& CEPH_OSDMAP_NOSCRUB
)
3544 if (f
& CEPH_OSDMAP_NODEEP_SCRUB
)
3545 s
+= ",nodeep-scrub";
3546 if (f
& CEPH_OSDMAP_NOTIERAGENT
)
3547 s
+= ",notieragent";
3548 if (f
& CEPH_OSDMAP_NOSNAPTRIM
)
3550 if (f
& CEPH_OSDMAP_SORTBITWISE
)
3551 s
+= ",sortbitwise";
3552 if (f
& CEPH_OSDMAP_REQUIRE_JEWEL
)
3553 s
+= ",require_jewel_osds";
3554 if (f
& CEPH_OSDMAP_REQUIRE_KRAKEN
)
3555 s
+= ",require_kraken_osds";
3556 if (f
& CEPH_OSDMAP_REQUIRE_LUMINOUS
)
3557 s
+= ",require_luminous_osds";
3558 if (f
& CEPH_OSDMAP_RECOVERY_DELETES
)
3559 s
+= ",recovery_deletes";
3560 if (f
& CEPH_OSDMAP_PURGED_SNAPDIRS
)
3561 s
+= ",purged_snapdirs";
3562 if (f
& CEPH_OSDMAP_PGLOG_HARDLIMIT
)
3563 s
+= ",pglog_hardlimit";
3569 string
OSDMap::get_flag_string() const
3571 return get_flag_string(flags
);
3574 void OSDMap::print_pools(ostream
& out
) const
3576 for (const auto &pool
: pools
) {
3577 std::string
name("<unknown>");
3578 const auto &pni
= pool_name
.find(pool
.first
);
3579 if (pni
!= pool_name
.end())
3581 out
<< "pool " << pool
.first
3583 << "' " << pool
.second
<< "\n";
3585 for (const auto &snap
: pool
.second
.snaps
)
3586 out
<< "\tsnap " << snap
.second
.snapid
<< " '" << snap
.second
.name
<< "' " << snap
.second
.stamp
<< "\n";
3588 if (!pool
.second
.removed_snaps
.empty())
3589 out
<< "\tremoved_snaps " << pool
.second
.removed_snaps
<< "\n";
3590 auto p
= removed_snaps_queue
.find(pool
.first
);
3591 if (p
!= removed_snaps_queue
.end()) {
3592 out
<< "\tremoved_snaps_queue " << p
->second
<< "\n";
3598 void OSDMap::print(ostream
& out
) const
3600 out
<< "epoch " << get_epoch() << "\n"
3601 << "fsid " << get_fsid() << "\n"
3602 << "created " << get_created() << "\n"
3603 << "modified " << get_modified() << "\n";
3605 out
<< "flags " << get_flag_string() << "\n";
3606 out
<< "crush_version " << get_crush_version() << "\n";
3607 out
<< "full_ratio " << full_ratio
<< "\n";
3608 out
<< "backfillfull_ratio " << backfillfull_ratio
<< "\n";
3609 out
<< "nearfull_ratio " << nearfull_ratio
<< "\n";
3610 if (require_min_compat_client
> 0) {
3611 out
<< "require_min_compat_client "
3612 << ceph_release_name(require_min_compat_client
) << "\n";
3614 out
<< "min_compat_client " << ceph_release_name(get_min_compat_client())
3616 if (require_osd_release
> 0) {
3617 out
<< "require_osd_release " << ceph_release_name(require_osd_release
)
3620 if (get_cluster_snapshot().length())
3621 out
<< "cluster_snapshot " << get_cluster_snapshot() << "\n";
3626 out
<< "max_osd " << get_max_osd() << "\n";
3627 for (int i
=0; i
<get_max_osd(); i
++) {
3630 out
<< (is_up(i
) ? " up ":" down");
3631 out
<< (is_in(i
) ? " in ":" out");
3632 out
<< " weight " << get_weightf(i
);
3633 if (get_primary_affinity(i
) != CEPH_OSD_DEFAULT_PRIMARY_AFFINITY
)
3634 out
<< " primary_affinity " << get_primary_affinityf(i
);
3635 const osd_info_t
& info(get_info(i
));
3637 out
<< " " << get_addrs(i
) << " " << get_cluster_addrs(i
);
3641 if (!get_uuid(i
).is_zero())
3642 out
<< " " << get_uuid(i
);
3648 for (auto& p
: pg_upmap
) {
3649 out
<< "pg_upmap " << p
.first
<< " " << p
.second
<< "\n";
3651 for (auto& p
: pg_upmap_items
) {
3652 out
<< "pg_upmap_items " << p
.first
<< " " << p
.second
<< "\n";
3655 for (const auto pg
: *pg_temp
)
3656 out
<< "pg_temp " << pg
.first
<< " " << pg
.second
<< "\n";
3658 for (const auto pg
: *primary_temp
)
3659 out
<< "primary_temp " << pg
.first
<< " " << pg
.second
<< "\n";
3661 for (const auto &addr
: blacklist
)
3662 out
<< "blacklist " << addr
.first
<< " expires " << addr
.second
<< "\n";
3665 class OSDTreePlainDumper
: public CrushTreeDumper::Dumper
<TextTable
> {
3667 typedef CrushTreeDumper::Dumper
<TextTable
> Parent
;
3669 OSDTreePlainDumper(const CrushWrapper
*crush
, const OSDMap
*osdmap_
,
3671 : Parent(crush
, osdmap_
->get_pool_names()), osdmap(osdmap_
), filter(f
) { }
3673 bool should_dump_leaf(int i
) const override
{
3675 return true; // normal case
3677 if (((filter
& OSDMap::DUMP_UP
) && osdmap
->is_up(i
)) ||
3678 ((filter
& OSDMap::DUMP_DOWN
) && osdmap
->is_down(i
)) ||
3679 ((filter
& OSDMap::DUMP_IN
) && osdmap
->is_in(i
)) ||
3680 ((filter
& OSDMap::DUMP_OUT
) && osdmap
->is_out(i
)) ||
3681 ((filter
& OSDMap::DUMP_DESTROYED
) && osdmap
->is_destroyed(i
))) {
3687 bool should_dump_empty_bucket() const override
{
3691 void init_table(TextTable
*tbl
) {
3692 tbl
->define_column("ID", TextTable::LEFT
, TextTable::RIGHT
);
3693 tbl
->define_column("CLASS", TextTable::LEFT
, TextTable::RIGHT
);
3694 tbl
->define_column("WEIGHT", TextTable::LEFT
, TextTable::RIGHT
);
3695 tbl
->define_column("TYPE NAME", TextTable::LEFT
, TextTable::LEFT
);
3696 tbl
->define_column("STATUS", TextTable::LEFT
, TextTable::RIGHT
);
3697 tbl
->define_column("REWEIGHT", TextTable::LEFT
, TextTable::RIGHT
);
3698 tbl
->define_column("PRI-AFF", TextTable::LEFT
, TextTable::RIGHT
);
3700 void dump(TextTable
*tbl
, string
& bucket
) {
3703 if (!bucket
.empty()) {
3708 for (int i
= 0; i
< osdmap
->get_max_osd(); i
++) {
3709 if (osdmap
->exists(i
) && !is_touched(i
) && should_dump_leaf(i
)) {
3710 dump_item(CrushTreeDumper::Item(i
, 0, 0, 0), tbl
);
3717 void dump_item(const CrushTreeDumper::Item
&qi
, TextTable
*tbl
) override
{
3718 const char *c
= crush
->get_item_class(qi
.id
);
3723 << weightf_t(qi
.weight
);
3726 for (int k
= 0; k
< qi
.depth
; k
++)
3728 if (qi
.is_bucket()) {
3729 name
<< crush
->get_type_name(crush
->get_bucket_type(qi
.id
)) << " "
3730 << crush
->get_item_name(qi
.id
);
3732 name
<< "osd." << qi
.id
;
3736 if (!qi
.is_bucket()) {
3737 if (!osdmap
->exists(qi
.id
)) {
3742 if (osdmap
->is_up(qi
.id
)) {
3744 } else if (osdmap
->is_destroyed(qi
.id
)) {
3750 << weightf_t(osdmap
->get_weightf(qi
.id
))
3751 << weightf_t(osdmap
->get_primary_affinityf(qi
.id
));
3754 *tbl
<< TextTable::endrow
;
3758 const OSDMap
*osdmap
;
3759 const unsigned filter
;
3762 class OSDTreeFormattingDumper
: public CrushTreeDumper::FormattingDumper
{
3764 typedef CrushTreeDumper::FormattingDumper Parent
;
3766 OSDTreeFormattingDumper(const CrushWrapper
*crush
, const OSDMap
*osdmap_
,
3768 : Parent(crush
, osdmap_
->get_pool_names()), osdmap(osdmap_
), filter(f
) { }
3770 bool should_dump_leaf(int i
) const override
{
3772 return true; // normal case
3774 if (((filter
& OSDMap::DUMP_UP
) && osdmap
->is_up(i
)) ||
3775 ((filter
& OSDMap::DUMP_DOWN
) && osdmap
->is_down(i
)) ||
3776 ((filter
& OSDMap::DUMP_IN
) && osdmap
->is_in(i
)) ||
3777 ((filter
& OSDMap::DUMP_OUT
) && osdmap
->is_out(i
)) ||
3778 ((filter
& OSDMap::DUMP_DESTROYED
) && osdmap
->is_destroyed(i
))) {
3784 bool should_dump_empty_bucket() const override
{
3788 void dump(Formatter
*f
, string
& bucket
) {
3789 if (!bucket
.empty()) {
3791 f
->open_array_section("nodes");
3795 f
->open_array_section("nodes");
3798 f
->open_array_section("stray");
3799 for (int i
= 0; i
< osdmap
->get_max_osd(); i
++) {
3800 if (osdmap
->exists(i
) && !is_touched(i
) && should_dump_leaf(i
))
3801 dump_item(CrushTreeDumper::Item(i
, 0, 0, 0), f
);
3808 void dump_item_fields(const CrushTreeDumper::Item
&qi
, Formatter
*f
) override
{
3809 Parent::dump_item_fields(qi
, f
);
3810 if (!qi
.is_bucket())
3813 if (osdmap
->is_up(qi
.id
)) {
3815 } else if (osdmap
->is_destroyed(qi
.id
)) {
3820 f
->dump_unsigned("exists", (int)osdmap
->exists(qi
.id
));
3821 f
->dump_string("status", s
);
3822 f
->dump_float("reweight", osdmap
->get_weightf(qi
.id
));
3823 f
->dump_float("primary_affinity", osdmap
->get_primary_affinityf(qi
.id
));
3828 const OSDMap
*osdmap
;
3829 const unsigned filter
;
3832 void OSDMap::print_tree(Formatter
*f
, ostream
*out
, unsigned filter
, string bucket
) const
3835 OSDTreeFormattingDumper(crush
.get(), this, filter
).dump(f
, bucket
);
3839 OSDTreePlainDumper(crush
.get(), this, filter
).dump(&tbl
, bucket
);
3844 void OSDMap::print_summary(Formatter
*f
, ostream
& out
,
3845 const string
& prefix
, bool extra
) const
3848 f
->open_object_section("osdmap");
3849 f
->dump_int("epoch", get_epoch());
3850 f
->dump_int("num_osds", get_num_osds());
3851 f
->dump_int("num_up_osds", get_num_up_osds());
3852 f
->dump_int("num_in_osds", get_num_in_osds());
3853 f
->dump_bool("full", test_flag(CEPH_OSDMAP_FULL
) ? true : false);
3854 f
->dump_bool("nearfull", test_flag(CEPH_OSDMAP_NEARFULL
) ? true : false);
3855 f
->dump_unsigned("num_remapped_pgs", get_num_pg_temp());
3858 utime_t now
= ceph_clock_now();
3859 out
<< get_num_osds() << " osds: "
3860 << get_num_up_osds() << " up";
3861 if (last_up_change
!= utime_t()) {
3862 out
<< " (since " << utimespan_str(now
- last_up_change
) << ")";
3864 out
<< ", " << get_num_in_osds() << " in";
3865 if (last_in_change
!= utime_t()) {
3866 out
<< " (since " << utimespan_str(now
- last_in_change
) << ")";
3869 out
<< "; epoch: e" << get_epoch();
3870 if (get_num_pg_temp())
3871 out
<< "; " << get_num_pg_temp() << " remapped pgs";
3873 uint64_t important_flags
= flags
& ~CEPH_OSDMAP_SEMIHIDDEN_FLAGS
;
3874 if (important_flags
)
3875 out
<< prefix
<< "flags " << get_flag_string(important_flags
) << "\n";
3879 void OSDMap::print_oneline_summary(ostream
& out
) const
3881 out
<< "e" << get_epoch() << ": "
3882 << get_num_osds() << " total, "
3883 << get_num_up_osds() << " up, "
3884 << get_num_in_osds() << " in";
3885 if (test_flag(CEPH_OSDMAP_FULL
))
3886 out
<< "; full flag set";
3887 else if (test_flag(CEPH_OSDMAP_NEARFULL
))
3888 out
<< "; nearfull flag set";
3891 bool OSDMap::crush_rule_in_use(int rule_id
) const
3893 for (const auto &pool
: pools
) {
3894 if (pool
.second
.crush_rule
== rule_id
)
3900 int OSDMap::validate_crush_rules(CrushWrapper
*newcrush
,
3903 for (auto& i
: pools
) {
3904 auto& pool
= i
.second
;
3905 int ruleno
= pool
.get_crush_rule();
3906 if (!newcrush
->rule_exists(ruleno
)) {
3907 *ss
<< "pool " << i
.first
<< " references crush_rule " << ruleno
3908 << " but it is not present";
3911 if (newcrush
->get_rule_mask_ruleset(ruleno
) != ruleno
) {
3912 *ss
<< "rule " << ruleno
<< " mask ruleset does not match rule id";
3915 if (newcrush
->get_rule_mask_type(ruleno
) != (int)pool
.get_type()) {
3916 *ss
<< "pool " << i
.first
<< " type does not match rule " << ruleno
;
3919 int poolsize
= pool
.get_size();
3920 if (poolsize
< newcrush
->get_rule_mask_min_size(ruleno
) ||
3921 poolsize
> newcrush
->get_rule_mask_max_size(ruleno
)) {
3922 *ss
<< "pool " << i
.first
<< " size " << poolsize
<< " does not"
3923 << " fall within rule " << ruleno
3924 << " min_size " << newcrush
->get_rule_mask_min_size(ruleno
)
3925 << " and max_size " << newcrush
->get_rule_mask_max_size(ruleno
);
3932 int OSDMap::build_simple_optioned(CephContext
*cct
, epoch_t e
, uuid_d
&fsid
,
3933 int nosd
, int pg_bits
, int pgp_bits
,
3936 ldout(cct
, 10) << "build_simple on " << nosd
3937 << " osds" << dendl
;
3940 created
= modified
= ceph_clock_now();
3947 const auto& conf
= cct
->_conf
;
3948 vector
<string
> sections
;
3949 conf
.get_all_sections(sections
);
3951 for (auto §ion
: sections
) {
3952 if (section
.find("osd.") != 0)
3955 const char *begin
= section
.c_str() + 4;
3956 char *end
= (char*)begin
;
3957 int o
= strtol(begin
, &end
, 10);
3961 if (o
> cct
->_conf
->mon_max_osd
) {
3962 lderr(cct
) << "[osd." << o
<< "] in config has id > mon_max_osd " << cct
->_conf
->mon_max_osd
<< dendl
;
3970 set_max_osd(maxosd
+ 1);
3977 r
= build_simple_crush_map(cct
, *crush
, nosd
, &ss
);
3979 r
= build_simple_crush_map_from_conf(cct
, *crush
, &ss
);
3980 ceph_assert(r
== 0);
3982 int poolbase
= get_max_osd() ? get_max_osd() : 1;
3984 const int default_replicated_rule
= crush
->get_osd_pool_default_crush_replicated_ruleset(cct
);
3985 ceph_assert(default_replicated_rule
>= 0);
3988 // pgp_num <= pg_num
3989 if (pgp_bits
> pg_bits
)
3992 vector
<string
> pool_names
;
3993 pool_names
.push_back("rbd");
3994 for (auto &plname
: pool_names
) {
3995 int64_t pool
= ++pool_max
;
3996 pools
[pool
].type
= pg_pool_t::TYPE_REPLICATED
;
3997 pools
[pool
].flags
= cct
->_conf
->osd_pool_default_flags
;
3998 if (cct
->_conf
->osd_pool_default_flag_hashpspool
)
3999 pools
[pool
].set_flag(pg_pool_t::FLAG_HASHPSPOOL
);
4000 if (cct
->_conf
->osd_pool_default_flag_nodelete
)
4001 pools
[pool
].set_flag(pg_pool_t::FLAG_NODELETE
);
4002 if (cct
->_conf
->osd_pool_default_flag_nopgchange
)
4003 pools
[pool
].set_flag(pg_pool_t::FLAG_NOPGCHANGE
);
4004 if (cct
->_conf
->osd_pool_default_flag_nosizechange
)
4005 pools
[pool
].set_flag(pg_pool_t::FLAG_NOSIZECHANGE
);
4006 pools
[pool
].size
= cct
->_conf
.get_val
<uint64_t>("osd_pool_default_size");
4007 pools
[pool
].min_size
= cct
->_conf
.get_osd_pool_default_min_size(
4009 pools
[pool
].crush_rule
= default_replicated_rule
;
4010 pools
[pool
].object_hash
= CEPH_STR_HASH_RJENKINS
;
4011 pools
[pool
].set_pg_num(poolbase
<< pg_bits
);
4012 pools
[pool
].set_pgp_num(poolbase
<< pgp_bits
);
4013 pools
[pool
].set_pg_num_target(poolbase
<< pg_bits
);
4014 pools
[pool
].set_pgp_num_target(poolbase
<< pgp_bits
);
4015 pools
[pool
].last_change
= epoch
;
4016 pools
[pool
].application_metadata
.insert(
4017 {pg_pool_t::APPLICATION_NAME_RBD
, {}});
4018 auto m
= pg_pool_t::get_pg_autoscale_mode_by_name(
4019 cct
->_conf
.get_val
<string
>("osd_pool_default_pg_autoscale_mode"));
4020 pools
[pool
].pg_autoscale_mode
= m
>= 0 ? m
: 0;
4021 pool_name
[pool
] = plname
;
4022 name_pool
[plname
] = pool
;
4026 for (int i
=0; i
<get_max_osd(); i
++) {
4028 set_weight(i
, CEPH_OSD_OUT
);
4031 map
<string
,string
> profile_map
;
4032 r
= get_erasure_code_profile_default(cct
, profile_map
, &ss
);
4034 lderr(cct
) << ss
.str() << dendl
;
4037 set_erasure_code_profile("default", profile_map
);
4041 int OSDMap::get_erasure_code_profile_default(CephContext
*cct
,
4042 map
<string
,string
> &profile_map
,
4045 int r
= get_json_str_map(cct
->_conf
.get_val
<string
>("osd_pool_default_erasure_code_profile"),
4051 int OSDMap::_build_crush_types(CrushWrapper
& crush
)
4053 crush
.set_type_name(0, "osd");
4054 crush
.set_type_name(1, "host");
4055 crush
.set_type_name(2, "chassis");
4056 crush
.set_type_name(3, "rack");
4057 crush
.set_type_name(4, "row");
4058 crush
.set_type_name(5, "pdu");
4059 crush
.set_type_name(6, "pod");
4060 crush
.set_type_name(7, "room");
4061 crush
.set_type_name(8, "datacenter");
4062 crush
.set_type_name(9, "zone");
4063 crush
.set_type_name(10, "region");
4064 crush
.set_type_name(11, "root");
4068 int OSDMap::build_simple_crush_map(CephContext
*cct
, CrushWrapper
& crush
,
4069 int nosd
, ostream
*ss
)
4074 int root_type
= _build_crush_types(crush
);
4076 int r
= crush
.add_bucket(0, 0, CRUSH_HASH_DEFAULT
,
4077 root_type
, 0, NULL
, NULL
, &rootid
);
4078 ceph_assert(r
== 0);
4079 crush
.set_item_name(rootid
, "default");
4081 for (int o
=0; o
<nosd
; o
++) {
4082 map
<string
,string
> loc
;
4083 loc
["host"] = "localhost";
4084 loc
["rack"] = "localrack";
4085 loc
["root"] = "default";
4086 ldout(cct
, 10) << " adding osd." << o
<< " at " << loc
<< dendl
;
4088 snprintf(name
, sizeof(name
), "osd.%d", o
);
4089 crush
.insert_item(cct
, o
, 1.0, name
, loc
);
4092 build_simple_crush_rules(cct
, crush
, "default", ss
);
4099 int OSDMap::build_simple_crush_map_from_conf(CephContext
*cct
,
4100 CrushWrapper
& crush
,
4103 const auto& conf
= cct
->_conf
;
4108 int root_type
= _build_crush_types(crush
);
4110 int r
= crush
.add_bucket(0, 0,
4112 root_type
, 0, NULL
, NULL
, &rootid
);
4113 ceph_assert(r
== 0);
4114 crush
.set_item_name(rootid
, "default");
4117 vector
<string
> sections
;
4118 conf
.get_all_sections(sections
);
4120 for (auto §ion
: sections
) {
4121 if (section
.find("osd.") != 0)
4124 const char *begin
= section
.c_str() + 4;
4125 char *end
= (char*)begin
;
4126 int o
= strtol(begin
, &end
, 10);
4130 string host
, rack
, row
, room
, dc
, pool
;
4131 vector
<string
> sectiontmp
;
4132 sectiontmp
.push_back("osd");
4133 sectiontmp
.push_back(section
);
4134 conf
.get_val_from_conf_file(sectiontmp
, "host", host
, false);
4135 conf
.get_val_from_conf_file(sectiontmp
, "rack", rack
, false);
4136 conf
.get_val_from_conf_file(sectiontmp
, "row", row
, false);
4137 conf
.get_val_from_conf_file(sectiontmp
, "room", room
, false);
4138 conf
.get_val_from_conf_file(sectiontmp
, "datacenter", dc
, false);
4139 conf
.get_val_from_conf_file(sectiontmp
, "root", pool
, false);
4141 if (host
.length() == 0)
4142 host
= "unknownhost";
4143 if (rack
.length() == 0)
4144 rack
= "unknownrack";
4146 map
<string
,string
> loc
;
4154 loc
["datacenter"] = dc
;
4155 loc
["root"] = "default";
4157 ldout(cct
, 5) << " adding osd." << o
<< " at " << loc
<< dendl
;
4158 crush
.insert_item(cct
, o
, 1.0, section
, loc
);
4161 build_simple_crush_rules(cct
, crush
, "default", ss
);
4169 int OSDMap::build_simple_crush_rules(
4171 CrushWrapper
& crush
,
4175 int crush_rule
= crush
.get_osd_pool_default_crush_replicated_ruleset(cct
);
4176 string failure_domain
=
4177 crush
.get_type_name(cct
->_conf
->osd_crush_chooseleaf_type
);
4180 r
= crush
.add_simple_rule_at(
4181 "replicated_rule", root
, failure_domain
, "",
4182 "firstn", pg_pool_t::TYPE_REPLICATED
,
4186 // do not add an erasure rule by default or else we will implicitly
4187 // require the crush_v2 feature of clients
4191 int OSDMap::summarize_mapping_stats(
4193 const set
<int64_t> *pools
,
4201 for (auto &p
: get_pools())
4205 unsigned total_pg
= 0;
4206 unsigned moved_pg
= 0;
4207 vector
<unsigned> base_by_osd(get_max_osd(), 0);
4208 vector
<unsigned> new_by_osd(get_max_osd(), 0);
4209 for (int64_t pool_id
: ls
) {
4210 const pg_pool_t
*pi
= get_pg_pool(pool_id
);
4211 vector
<int> up
, up2
;
4213 for (unsigned ps
= 0; ps
< pi
->get_pg_num(); ++ps
) {
4214 pg_t
pgid(ps
, pool_id
);
4215 total_pg
+= pi
->get_size();
4216 pg_to_up_acting_osds(pgid
, &up
, &up_primary
, nullptr, nullptr);
4217 for (int osd
: up
) {
4218 if (osd
>= 0 && osd
< get_max_osd())
4222 newmap
->pg_to_up_acting_osds(pgid
, &up2
, &up_primary
, nullptr, nullptr);
4223 for (int osd
: up2
) {
4224 if (osd
>= 0 && osd
< get_max_osd())
4227 if (pi
->type
== pg_pool_t::TYPE_ERASURE
) {
4228 for (unsigned i
=0; i
<up
.size(); ++i
) {
4229 if (up
[i
] != up2
[i
]) {
4233 } else if (pi
->type
== pg_pool_t::TYPE_REPLICATED
) {
4234 for (int osd
: up
) {
4235 if (std::find(up2
.begin(), up2
.end(), osd
) == up2
.end()) {
4240 ceph_abort_msg("unhandled pool type");
4246 unsigned num_up_in
= 0;
4247 for (int osd
= 0; osd
< get_max_osd(); ++osd
) {
4248 if (is_up(osd
) && is_in(osd
))
4255 float avg_pg
= (float)total_pg
/ (float)num_up_in
;
4256 float base_stddev
= 0, new_stddev
= 0;
4257 int min
= -1, max
= -1;
4258 unsigned min_base_pg
= 0, max_base_pg
= 0;
4259 unsigned min_new_pg
= 0, max_new_pg
= 0;
4260 for (int osd
= 0; osd
< get_max_osd(); ++osd
) {
4261 if (is_up(osd
) && is_in(osd
)) {
4262 float base_diff
= (float)base_by_osd
[osd
] - avg_pg
;
4263 base_stddev
+= base_diff
* base_diff
;
4264 float new_diff
= (float)new_by_osd
[osd
] - avg_pg
;
4265 new_stddev
+= new_diff
* new_diff
;
4266 if (min
< 0 || base_by_osd
[osd
] < min_base_pg
) {
4268 min_base_pg
= base_by_osd
[osd
];
4269 min_new_pg
= new_by_osd
[osd
];
4271 if (max
< 0 || base_by_osd
[osd
] > max_base_pg
) {
4273 max_base_pg
= base_by_osd
[osd
];
4274 max_new_pg
= new_by_osd
[osd
];
4278 base_stddev
= sqrt(base_stddev
/ num_up_in
);
4279 new_stddev
= sqrt(new_stddev
/ num_up_in
);
4281 float edev
= sqrt(avg_pg
* (1.0 - (1.0 / (double)num_up_in
)));
4285 f
->open_object_section("utilization");
4288 f
->dump_unsigned("moved_pgs", moved_pg
);
4289 f
->dump_unsigned("total_pgs", total_pg
);
4293 percent
= (float)moved_pg
* 100.0 / (float)total_pg
;
4294 ss
<< "moved " << moved_pg
<< " / " << total_pg
4295 << " (" << percent
<< "%)\n";
4299 f
->dump_float("avg_pgs", avg_pg
);
4300 f
->dump_float("std_dev", base_stddev
);
4301 f
->dump_float("expected_baseline_std_dev", edev
);
4303 f
->dump_float("new_std_dev", new_stddev
);
4305 ss
<< "avg " << avg_pg
<< "\n";
4306 ss
<< "stddev " << base_stddev
;
4308 ss
<< " -> " << new_stddev
;
4309 ss
<< " (expected baseline " << edev
<< ")\n";
4313 f
->dump_unsigned("min_osd", min
);
4314 f
->dump_unsigned("min_osd_pgs", min_base_pg
);
4316 f
->dump_unsigned("new_min_osd_pgs", min_new_pg
);
4318 ss
<< "min osd." << min
<< " with " << min_base_pg
;
4320 ss
<< " -> " << min_new_pg
;
4321 ss
<< " pgs (" << (float)min_base_pg
/ avg_pg
;
4323 ss
<< " -> " << (float)min_new_pg
/ avg_pg
;
4329 f
->dump_unsigned("max_osd", max
);
4330 f
->dump_unsigned("max_osd_pgs", max_base_pg
);
4332 f
->dump_unsigned("new_max_osd_pgs", max_new_pg
);
4334 ss
<< "max osd." << max
<< " with " << max_base_pg
;
4336 ss
<< " -> " << max_new_pg
;
4337 ss
<< " pgs (" << (float)max_base_pg
/ avg_pg
;
4339 ss
<< " -> " << (float)max_new_pg
/ avg_pg
;
4351 int OSDMap::clean_pg_upmaps(
4353 Incremental
*pending_inc
) const
4355 ldout(cct
, 10) << __func__
<< dendl
;
4357 for (auto& p
: pg_upmap
) {
4360 pg_to_raw_osds(p
.first
, &raw
, &primary
);
4361 if (raw
== p
.second
) {
4362 ldout(cct
, 10) << " removing redundant pg_upmap " << p
.first
<< " "
4363 << p
.second
<< dendl
;
4364 pending_inc
->old_pg_upmap
.insert(p
.first
);
4368 for (auto& p
: pg_upmap_items
) {
4371 pg_to_raw_osds(p
.first
, &raw
, &primary
);
4372 mempool::osdmap::vector
<pair
<int,int>> newmap
;
4373 for (auto& q
: p
.second
) {
4374 if (std::find(raw
.begin(), raw
.end(), q
.first
) == raw
.end()) {
4375 // cancel mapping if source osd does not exist anymore
4378 if (q
.second
!= CRUSH_ITEM_NONE
&& q
.second
< max_osd
&&
4379 q
.second
>= 0 && osd_weight
[q
.second
] == 0) {
4380 // cancel mapping if target osd is out
4383 newmap
.push_back(q
);
4385 if (newmap
.empty()) {
4386 ldout(cct
, 10) << " removing no-op pg_upmap_items " << p
.first
<< " "
4387 << p
.second
<< dendl
;
4388 pending_inc
->old_pg_upmap_items
.insert(p
.first
);
4390 } else if (newmap
!= p
.second
) {
4391 ldout(cct
, 10) << " simplifying partially no-op pg_upmap_items "
4392 << p
.first
<< " " << p
.second
<< " -> " << newmap
<< dendl
;
4393 pending_inc
->new_pg_upmap_items
[p
.first
] = newmap
;
4400 bool OSDMap::try_pg_upmap(
4402 pg_t pg
, ///< pg to potentially remap
4403 const set
<int>& overfull
, ///< osds we'd want to evacuate
4404 const vector
<int>& underfull
, ///< osds to move to, in order of preference
4406 vector
<int> *out
) ///< resulting alternative mapping
4408 const pg_pool_t
*pool
= get_pg_pool(pg
.pool());
4411 int rule
= crush
->find_rule(pool
->get_crush_rule(), pool
->get_type(),
4416 // make sure there is something there to remap
4418 for (auto osd
: *orig
) {
4419 if (overfull
.count(osd
)) {
4428 int r
= crush
->try_remap_rule(
4432 overfull
, underfull
,
4442 int OSDMap::calc_pg_upmaps(
4444 float max_deviation_ratio
,
4446 const set
<int64_t>& only_pools
,
4447 OSDMap::Incremental
*pending_inc
)
4449 ldout(cct
, 10) << __func__
<< " pools " << only_pools
<< dendl
;
4451 tmp
.deepish_copy_from(*this);
4452 int num_changed
= 0;
4453 map
<int,set
<pg_t
>> pgs_by_osd
;
4455 float osd_weight_total
= 0;
4456 map
<int,float> osd_weight
;
4457 for (auto& i
: pools
) {
4458 if (!only_pools
.empty() && !only_pools
.count(i
.first
))
4460 for (unsigned ps
= 0; ps
< i
.second
.get_pg_num(); ++ps
) {
4461 pg_t
pg(ps
, i
.first
);
4463 tmp
.pg_to_up_acting_osds(pg
, &up
, nullptr, nullptr, nullptr);
4464 ldout(cct
, 20) << __func__
<< " " << pg
<< " up " << up
<< dendl
;
4465 for (auto osd
: up
) {
4466 if (osd
!= CRUSH_ITEM_NONE
)
4467 pgs_by_osd
[osd
].insert(pg
);
4470 total_pgs
+= i
.second
.get_size() * i
.second
.get_pg_num();
4472 map
<int,float> pmap
;
4473 int ruleno
= tmp
.crush
->find_rule(i
.second
.get_crush_rule(),
4474 i
.second
.get_type(),
4475 i
.second
.get_size());
4476 tmp
.crush
->get_rule_weight_osd_map(ruleno
, &pmap
);
4477 ldout(cct
,20) << __func__
<< " pool " << i
.first
4478 << " ruleno " << ruleno
4479 << " weight-map " << pmap
4481 for (auto p
: pmap
) {
4482 auto adjusted_weight
= tmp
.get_weightf(p
.first
) * p
.second
;
4483 if (adjusted_weight
== 0) {
4486 osd_weight
[p
.first
] += adjusted_weight
;
4487 osd_weight_total
+= adjusted_weight
;
4490 for (auto& i
: osd_weight
) {
4492 auto p
= pgs_by_osd
.find(i
.first
);
4493 if (p
!= pgs_by_osd
.end())
4494 pgs
= p
->second
.size();
4496 pgs_by_osd
.emplace(i
.first
, set
<pg_t
>());
4497 ldout(cct
, 20) << " osd." << i
.first
<< " weight " << i
.second
4498 << " pgs " << pgs
<< dendl
;
4500 if (osd_weight_total
== 0) {
4501 lderr(cct
) << __func__
<< " abort due to osd_weight_total == 0" << dendl
;
4504 float pgs_per_weight
= total_pgs
/ osd_weight_total
;
4505 ldout(cct
, 10) << " osd_weight_total " << osd_weight_total
<< dendl
;
4506 ldout(cct
, 10) << " pgs_per_weight " << pgs_per_weight
<< dendl
;
4509 lderr(cct
) << __func__
<< " abort due to max <= 0" << dendl
;
4512 float decay_factor
= 1.0 / float(max
);
4514 map
<int,float> osd_deviation
; // osd, deviation(pgs)
4515 multimap
<float,int> deviation_osd
; // deviation(pgs), osd
4516 for (auto& i
: pgs_by_osd
) {
4517 // make sure osd is still there (belongs to this crush-tree)
4518 ceph_assert(osd_weight
.count(i
.first
));
4519 float target
= osd_weight
[i
.first
] * pgs_per_weight
;
4520 float deviation
= (float)i
.second
.size() - target
;
4521 ldout(cct
, 20) << " osd." << i
.first
4522 << "\tpgs " << i
.second
.size()
4523 << "\ttarget " << target
4524 << "\tdeviation " << deviation
4526 osd_deviation
[i
.first
] = deviation
;
4527 deviation_osd
.insert(make_pair(deviation
, i
.first
));
4528 stddev
+= deviation
* deviation
;
4530 if (stddev
<= cct
->_conf
.get_val
<double>("osd_calc_pg_upmaps_max_stddev")) {
4531 ldout(cct
, 10) << __func__
<< " distribution is almost perfect"
4535 bool skip_overfull
= false;
4537 cct
->_conf
.get_val
<bool>("osd_calc_pg_upmaps_aggressively");
4538 auto local_fallback_retries
=
4539 cct
->_conf
.get_val
<uint64_t>("osd_calc_pg_upmaps_local_fallback_retries");
4541 // build overfull and underfull
4543 vector
<int> underfull
;
4545 int decay_count
= 0;
4546 while (overfull
.empty()) {
4547 for (auto i
= deviation_osd
.rbegin(); i
!= deviation_osd
.rend(); i
++) {
4548 if (i
->first
>= (1.0 - decay
))
4549 overfull
.insert(i
->second
);
4551 if (!overfull
.empty())
4554 decay
= decay_factor
* decay_count
;
4557 ldout(cct
, 30) << " decay_factor = " << decay_factor
4558 << " decay_count = " << decay_count
4559 << " decay (overfull) = " << decay
4562 if (overfull
.empty()) {
4563 lderr(cct
) << __func__
<< " failed to build overfull" << dendl
;
4569 while (underfull
.empty()) {
4570 for (auto i
= deviation_osd
.begin(); i
!= deviation_osd
.end(); i
++) {
4571 if (i
->first
>= (-.999 + decay
))
4573 underfull
.push_back(i
->second
);
4575 if (!underfull
.empty())
4578 decay
= decay_factor
* decay_count
;
4581 ldout(cct
, 30) << " decay_factor = " << decay_factor
4582 << " decay_count = " << decay_count
4583 << " decay (underfull) = " << decay
4586 if (underfull
.empty()) {
4587 lderr(cct
) << __func__
<< " failed to build underfull" << dendl
;
4591 ldout(cct
, 10) << " overfull " << overfull
4592 << " underfull " << underfull
4595 uint64_t local_fallback_retried
= 0;
4600 map
<pg_t
, mempool::osdmap::vector
<pair
<int32_t,int32_t>>> to_upmap
;
4601 auto temp_pgs_by_osd
= pgs_by_osd
;
4602 // always start with fullest, break if we find any changes to make
4603 for (auto p
= deviation_osd
.rbegin(); p
!= deviation_osd
.rend(); ++p
) {
4604 if (skip_overfull
) {
4605 ldout(cct
, 10) << " skipping overfull " << dendl
;
4606 break; // fall through to check underfull
4608 int osd
= p
->second
;
4609 float deviation
= p
->first
;
4610 float target
= osd_weight
[osd
] * pgs_per_weight
;
4611 ceph_assert(target
> 0);
4612 float deviation_ratio
= deviation
/ target
;
4613 if (deviation_ratio
< max_deviation_ratio
) {
4614 ldout(cct
, 10) << " osd." << osd
4615 << " target " << target
4616 << " deviation " << deviation
4617 << " -> ratio " << deviation_ratio
4618 << " < max ratio " << max_deviation_ratio
4624 pgs
.reserve(pgs_by_osd
[osd
].size());
4625 for (auto& pg
: pgs_by_osd
[osd
]) {
4626 if (to_skip
.count(pg
))
4631 // shuffle PG list so they all get equal (in)attention
4632 std::random_device rd
;
4633 std::default_random_engine rng
{rd()};
4634 std::shuffle(pgs
.begin(), pgs
.end(), rng
);
4636 // look for remaps we can un-remap
4637 for (auto pg
: pgs
) {
4638 auto p
= tmp
.pg_upmap_items
.find(pg
);
4639 if (p
== tmp
.pg_upmap_items
.end())
4641 mempool::osdmap::vector
<pair
<int32_t,int32_t>> new_upmap_items
;
4642 for (auto q
: p
->second
) {
4643 if (q
.second
== osd
) {
4644 ldout(cct
, 10) << " will try dropping existing"
4645 << " remapping pair "
4646 << q
.first
<< " -> " << q
.second
4647 << " which remapped " << pg
4648 << " into overfull osd." << osd
4650 temp_pgs_by_osd
[q
.second
].erase(pg
);
4651 temp_pgs_by_osd
[q
.first
].insert(pg
);
4653 new_upmap_items
.push_back(q
);
4656 if (new_upmap_items
.empty()) {
4658 ldout(cct
, 10) << " existing pg_upmap_items " << p
->second
4659 << " remapped " << pg
<< " into overfull osd." << osd
4660 << ", will try cancelling it entirely"
4662 to_unmap
.insert(pg
);
4664 } else if (new_upmap_items
.size() != p
->second
.size()) {
4665 // drop single remapping pair, updating
4666 ceph_assert(new_upmap_items
.size() < p
->second
.size());
4667 ldout(cct
, 10) << " existing pg_upmap_items " << p
->second
4668 << " remapped " << pg
<< " into overfull osd." << osd
4669 << ", new_pg_upmap_items now " << new_upmap_items
4671 to_upmap
[pg
] = new_upmap_items
;
4677 for (auto pg
: pgs
) {
4678 auto temp_it
= tmp
.pg_upmap
.find(pg
);
4679 if (temp_it
!= tmp
.pg_upmap
.end()) {
4680 // leave pg_upmap alone
4681 // it must be specified by admin since balancer does not
4682 // support pg_upmap yet
4683 ldout(cct
, 10) << " " << pg
<< " already has pg_upmap "
4684 << temp_it
->second
<< ", skipping"
4688 auto pg_pool_size
= tmp
.get_pg_pool_size(pg
);
4689 mempool::osdmap::vector
<pair
<int32_t,int32_t>> new_upmap_items
;
4691 auto it
= tmp
.pg_upmap_items
.find(pg
);
4692 if (it
!= tmp
.pg_upmap_items
.end() &&
4693 it
->second
.size() >= (size_t)pg_pool_size
) {
4694 ldout(cct
, 10) << " " << pg
<< " already has full-size pg_upmap_items "
4695 << it
->second
<< ", skipping"
4698 } else if (it
!= tmp
.pg_upmap_items
.end()) {
4699 ldout(cct
, 10) << " " << pg
<< " already has pg_upmap_items "
4702 new_upmap_items
= it
->second
;
4703 // build existing too (for dedup)
4704 for (auto i
: it
->second
) {
4705 existing
.insert(i
.first
);
4706 existing
.insert(i
.second
);
4709 // to see if we can append more remapping pairs
4711 ldout(cct
, 10) << " trying " << pg
<< dendl
;
4712 vector
<int> orig
, out
;
4713 tmp
.pg_to_raw_upmap(pg
, &orig
); // including existing upmaps too
4714 if (!try_pg_upmap(cct
, pg
, overfull
, underfull
, &orig
, &out
)) {
4717 ldout(cct
, 10) << " " << pg
<< " " << orig
<< " -> " << out
<< dendl
;
4718 if (orig
.size() != out
.size()) {
4721 ceph_assert(orig
!= out
);
4722 for (unsigned i
= 0; i
< out
.size(); ++i
) {
4723 if (orig
[i
] == out
[i
])
4724 continue; // skip invalid remappings
4725 if (existing
.count(orig
[i
]) || existing
.count(out
[i
]))
4726 continue; // we want new remappings only!
4727 ldout(cct
, 10) << " will try adding new remapping pair "
4728 << orig
[i
] << " -> " << out
[i
] << " for " << pg
4730 existing
.insert(orig
[i
]);
4731 existing
.insert(out
[i
]);
4732 temp_pgs_by_osd
[orig
[i
]].erase(pg
);
4733 temp_pgs_by_osd
[out
[i
]].insert(pg
);
4734 ceph_assert(new_upmap_items
.size() < (size_t)pg_pool_size
);
4735 new_upmap_items
.push_back(make_pair(orig
[i
], out
[i
]));
4736 // append new remapping pairs slowly
4737 // This way we can make sure that each tiny change will
4738 // definitely make distribution of PGs converging to
4739 // the perfect status.
4740 to_upmap
[pg
] = new_upmap_items
;
4746 ceph_assert(!(to_unmap
.size() || to_upmap
.size()));
4747 ldout(cct
, 10) << " failed to find any changes for overfull osds"
4749 for (auto& p
: deviation_osd
) {
4750 if (std::find(underfull
.begin(), underfull
.end(), p
.second
) ==
4754 float deviation
= p
.first
;
4755 float target
= osd_weight
[osd
] * pgs_per_weight
;
4756 ceph_assert(target
> 0);
4757 float deviation_ratio
= abs(deviation
/ target
);
4758 if (deviation_ratio
< max_deviation_ratio
) {
4759 // respect max_deviation_ratio too
4760 ldout(cct
, 10) << " osd." << osd
4761 << " target " << target
4762 << " deviation " << deviation
4763 << " -> absolute ratio " << deviation_ratio
4764 << " < max ratio " << max_deviation_ratio
4768 // look for remaps we can un-remap
4770 mempool::osdmap::vector
<pair
<int32_t,int32_t>>>> candidates
;
4771 candidates
.reserve(tmp
.pg_upmap_items
.size());
4772 for (auto& i
: tmp
.pg_upmap_items
) {
4773 if (to_skip
.count(i
.first
))
4775 if (!only_pools
.empty() && !only_pools
.count(i
.first
.pool()))
4777 candidates
.push_back(make_pair(i
.first
, i
.second
));
4780 // shuffle candidates so they all get equal (in)attention
4781 std::random_device rd
;
4782 std::default_random_engine rng
{rd()};
4783 std::shuffle(candidates
.begin(), candidates
.end(), rng
);
4785 for (auto& i
: candidates
) {
4787 mempool::osdmap::vector
<pair
<int32_t,int32_t>> new_upmap_items
;
4788 for (auto& j
: i
.second
) {
4789 if (j
.first
== osd
) {
4790 ldout(cct
, 10) << " will try dropping existing"
4791 << " remapping pair "
4792 << j
.first
<< " -> " << j
.second
4793 << " which remapped " << pg
4794 << " out from underfull osd." << osd
4796 temp_pgs_by_osd
[j
.second
].erase(pg
);
4797 temp_pgs_by_osd
[j
.first
].insert(pg
);
4799 new_upmap_items
.push_back(j
);
4802 if (new_upmap_items
.empty()) {
4804 ldout(cct
, 10) << " existing pg_upmap_items " << i
.second
4805 << " remapped " << pg
4806 << " out from underfull osd." << osd
4807 << ", will try cancelling it entirely"
4809 to_unmap
.insert(pg
);
4811 } else if (new_upmap_items
.size() != i
.second
.size()) {
4812 // drop single remapping pair, updating
4813 ceph_assert(new_upmap_items
.size() < i
.second
.size());
4814 ldout(cct
, 10) << " existing pg_upmap_items " << i
.second
4815 << " remapped " << pg
4816 << " out from underfull osd." << osd
4817 << ", new_pg_upmap_items now " << new_upmap_items
4819 to_upmap
[pg
] = new_upmap_items
;
4825 ceph_assert(!(to_unmap
.size() || to_upmap
.size()));
4826 ldout(cct
, 10) << " failed to find any changes for underfull osds"
4829 ldout(cct
, 10) << " break due to aggressive mode not enabled" << dendl
;
4831 } else if (!skip_overfull
) {
4832 // safe to quit because below here we know
4833 // we've done checking both overfull and underfull osds..
4834 ldout(cct
, 10) << " break due to not being able to find any"
4835 << " further optimizations"
4839 // restart with fullest and do exhaustive searching
4840 skip_overfull
= false;
4845 // test change, apply if change is good
4846 ceph_assert(to_unmap
.size() || to_upmap
.size());
4847 float new_stddev
= 0;
4848 map
<int,float> temp_osd_deviation
;
4849 multimap
<float,int> temp_deviation_osd
;
4850 for (auto& i
: temp_pgs_by_osd
) {
4851 // make sure osd is still there (belongs to this crush-tree)
4852 ceph_assert(osd_weight
.count(i
.first
));
4853 float target
= osd_weight
[i
.first
] * pgs_per_weight
;
4854 float deviation
= (float)i
.second
.size() - target
;
4855 ldout(cct
, 20) << " osd." << i
.first
4856 << "\tpgs " << i
.second
.size()
4857 << "\ttarget " << target
4858 << "\tdeviation " << deviation
4860 temp_osd_deviation
[i
.first
] = deviation
;
4861 temp_deviation_osd
.insert(make_pair(deviation
, i
.first
));
4862 new_stddev
+= deviation
* deviation
;
4864 ldout(cct
, 10) << " stddev " << stddev
<< " -> " << new_stddev
<< dendl
;
4865 if (new_stddev
>= stddev
) {
4867 ldout(cct
, 10) << " break because stddev is not decreasing"
4868 << " and aggressive mode is not enabled"
4872 local_fallback_retried
++;
4873 if (local_fallback_retried
>= local_fallback_retries
) {
4874 // does not make progress
4875 // flip *skip_overfull* so both overfull and underfull
4876 // get equal (in)attention
4877 skip_overfull
= !skip_overfull
;
4878 ldout(cct
, 10) << " hit local_fallback_retries "
4879 << local_fallback_retries
4883 for (auto& i
: to_unmap
)
4885 for (auto& i
: to_upmap
)
4886 to_skip
.insert(i
.first
);
4887 ldout(cct
, 20) << " local_fallback_retried " << local_fallback_retried
4888 << " to_skip " << to_skip
4894 ceph_assert(new_stddev
< stddev
);
4895 stddev
= new_stddev
;
4896 pgs_by_osd
= temp_pgs_by_osd
;
4897 osd_deviation
= temp_osd_deviation
;
4898 deviation_osd
= temp_deviation_osd
;
4899 for (auto& i
: to_unmap
) {
4900 ldout(cct
, 10) << " unmap pg " << i
<< dendl
;
4901 ceph_assert(tmp
.pg_upmap_items
.count(i
));
4902 tmp
.pg_upmap_items
.erase(i
);
4903 pending_inc
->old_pg_upmap_items
.insert(i
);
4906 for (auto& i
: to_upmap
) {
4907 ldout(cct
, 10) << " upmap pg " << i
.first
4908 << " new pg_upmap_items " << i
.second
4910 tmp
.pg_upmap_items
[i
.first
] = i
.second
;
4911 pending_inc
->new_pg_upmap_items
[i
.first
] = i
.second
;
4915 ldout(cct
, 10) << " num_changed = " << num_changed
<< dendl
;
4919 int OSDMap::get_osds_by_bucket_name(const string
&name
, set
<int> *osds
) const
4921 return crush
->get_leaves(name
, osds
);
4924 // get pools whose crush rules might reference the given osd
4925 void OSDMap::get_pool_ids_by_osd(CephContext
*cct
,
4927 set
<int64_t> *pool_ids
) const
4929 ceph_assert(pool_ids
);
4931 int r
= crush
->get_rules_by_osd(osd
, &raw_rules
);
4933 lderr(cct
) << __func__
<< " get_rules_by_osd failed: " << cpp_strerror(r
)
4935 ceph_assert(r
>= 0);
4938 for (auto &i
: raw_rules
) {
4939 // exclude any dead rule
4940 if (crush_rule_in_use(i
)) {
4944 for (auto &r
: rules
) {
4945 get_pool_ids_by_rule(r
, pool_ids
);
4949 template <typename F
>
4950 class OSDUtilizationDumper
: public CrushTreeDumper::Dumper
<F
> {
4952 typedef CrushTreeDumper::Dumper
<F
> Parent
;
4954 OSDUtilizationDumper(const CrushWrapper
*crush
, const OSDMap
*osdmap_
,
4955 const PGMap
& pgmap_
, bool tree_
,
4956 const string
& class_name_
,
4957 const string
& item_name_
) :
4958 Parent(crush
, osdmap_
->get_pool_names()),
4962 class_name(class_name_
),
4963 item_name(item_name_
),
4968 if (osdmap
->crush
->name_exists(item_name
)) {
4969 // filter out items we are allowed to dump
4970 auto item_id
= osdmap
->crush
->get_item_id(item_name
);
4971 allowed
.insert(item_id
);
4972 osdmap
->crush
->get_all_children(item_id
, &allowed
);
4974 average_util
= average_utilization();
4979 bool should_dump(int id
) const {
4980 if (!allowed
.empty() && !allowed
.count(id
)) // filter by name
4982 if (id
>= 0 && !class_name
.empty()) {
4983 const char* item_class_name
= osdmap
->crush
->get_item_class(id
);
4984 if (!item_class_name
|| // not bound to a class yet
4985 item_class_name
!= class_name
) // or already bound to
4986 // a different class
4992 set
<int> get_dumped_osds() {
4993 if (class_name
.empty() && item_name
.empty()) {
5000 void dump_stray(F
*f
) {
5001 for (int i
= 0; i
< osdmap
->get_max_osd(); i
++) {
5002 if (osdmap
->exists(i
) && !this->is_touched(i
))
5003 dump_item(CrushTreeDumper::Item(i
, 0, 0, 0), f
);
5007 void dump_item(const CrushTreeDumper::Item
&qi
, F
*f
) override
{
5008 if (!tree
&& qi
.is_bucket())
5010 if (!should_dump(qi
.id
))
5013 if (!qi
.is_bucket())
5014 dumped_osds
.insert(qi
.id
);
5015 float reweight
= qi
.is_bucket() ? -1 : osdmap
->get_weightf(qi
.id
);
5016 int64_t kb
= 0, kb_used
= 0, kb_used_data
= 0, kb_used_omap
= 0,
5017 kb_used_meta
= 0, kb_avail
= 0;
5019 if (get_bucket_utilization(qi
.id
, &kb
, &kb_used
, &kb_used_data
,
5020 &kb_used_omap
, &kb_used_meta
, &kb_avail
))
5022 util
= 100.0 * (double)kb_used
/ (double)kb
;
5026 var
= util
/ average_util
;
5028 size_t num_pgs
= qi
.is_bucket() ? 0 : pgmap
.get_num_pg_by_osd(qi
.id
);
5030 dump_item(qi
, reweight
, kb
, kb_used
,
5031 kb_used_data
, kb_used_omap
, kb_used_meta
,
5032 kb_avail
, util
, var
, num_pgs
, f
);
5034 if (!qi
.is_bucket() && reweight
> 0) {
5035 if (min_var
< 0 || var
< min_var
)
5037 if (max_var
< 0 || var
> max_var
)
5040 double dev
= util
- average_util
;
5042 stddev
+= reweight
* dev
;
5047 virtual void dump_item(const CrushTreeDumper::Item
&qi
,
5051 int64_t kb_used_data
,
5052 int64_t kb_used_omap
,
5053 int64_t kb_used_meta
,
5057 const size_t num_pgs
,
5061 return sum
> 0 ? sqrt(stddev
/ sum
) : 0;
5064 double average_utilization() {
5065 int64_t kb
= 0, kb_used
= 0;
5066 for (int i
= 0; i
< osdmap
->get_max_osd(); i
++) {
5067 if (!osdmap
->exists(i
) ||
5068 osdmap
->get_weight(i
) == 0 ||
5071 int64_t kb_i
, kb_used_i
, kb_used_data_i
, kb_used_omap_i
, kb_used_meta_i
,
5073 if (get_osd_utilization(i
, &kb_i
, &kb_used_i
, &kb_used_data_i
,
5074 &kb_used_omap_i
, &kb_used_meta_i
, &kb_avail_i
)) {
5076 kb_used
+= kb_used_i
;
5079 return kb
> 0 ? 100.0 * (double)kb_used
/ (double)kb
: 0;
5082 bool get_osd_utilization(int id
, int64_t* kb
, int64_t* kb_used
,
5083 int64_t* kb_used_data
,
5084 int64_t* kb_used_omap
,
5085 int64_t* kb_used_meta
,
5086 int64_t* kb_avail
) const {
5087 const osd_stat_t
*p
= pgmap
.get_osd_stat(id
);
5088 if (!p
) return false;
5089 *kb
= p
->statfs
.kb();
5090 *kb_used
= p
->statfs
.kb_used_raw();
5091 *kb_used_data
= p
->statfs
.kb_used_data();
5092 *kb_used_omap
= p
->statfs
.kb_used_omap();
5093 *kb_used_meta
= p
->statfs
.kb_used_internal_metadata();
5094 *kb_avail
= p
->statfs
.kb_avail();
5099 bool get_bucket_utilization(int id
, int64_t* kb
, int64_t* kb_used
,
5100 int64_t* kb_used_data
,
5101 int64_t* kb_used_omap
,
5102 int64_t* kb_used_meta
,
5103 int64_t* kb_avail
) const {
5105 if (osdmap
->is_out(id
) || !should_dump(id
)) {
5114 return get_osd_utilization(id
, kb
, kb_used
, kb_used_data
,
5115 kb_used_omap
, kb_used_meta
, kb_avail
);
5125 for (int k
= osdmap
->crush
->get_bucket_size(id
) - 1; k
>= 0; k
--) {
5126 int item
= osdmap
->crush
->get_bucket_item(id
, k
);
5127 int64_t kb_i
= 0, kb_used_i
= 0, kb_used_data_i
= 0,
5128 kb_used_omap_i
= 0, kb_used_meta_i
= 0, kb_avail_i
= 0;
5129 if (!get_bucket_utilization(item
, &kb_i
, &kb_used_i
,
5130 &kb_used_data_i
, &kb_used_omap_i
,
5131 &kb_used_meta_i
, &kb_avail_i
))
5134 *kb_used
+= kb_used_i
;
5135 *kb_used_data
+= kb_used_data_i
;
5136 *kb_used_omap
+= kb_used_omap_i
;
5137 *kb_used_meta
+= kb_used_meta_i
;
5138 *kb_avail
+= kb_avail_i
;
5144 const OSDMap
*osdmap
;
5147 const string class_name
;
5148 const string item_name
;
5149 double average_util
;
5155 set
<int> dumped_osds
;
5159 class OSDUtilizationPlainDumper
: public OSDUtilizationDumper
<TextTable
> {
5161 typedef OSDUtilizationDumper
<TextTable
> Parent
;
5163 OSDUtilizationPlainDumper(const CrushWrapper
*crush
, const OSDMap
*osdmap
,
5164 const PGMap
& pgmap
, bool tree
,
5165 const string
& class_name
,
5166 const string
& item_name
) :
5167 Parent(crush
, osdmap
, pgmap
, tree
, class_name
, item_name
) {}
5169 void dump(TextTable
*tbl
) {
5170 tbl
->define_column("ID", TextTable::LEFT
, TextTable::RIGHT
);
5171 tbl
->define_column("CLASS", TextTable::LEFT
, TextTable::RIGHT
);
5172 tbl
->define_column("WEIGHT", TextTable::LEFT
, TextTable::RIGHT
);
5173 tbl
->define_column("REWEIGHT", TextTable::LEFT
, TextTable::RIGHT
);
5174 tbl
->define_column("SIZE", TextTable::LEFT
, TextTable::RIGHT
);
5175 tbl
->define_column("RAW USE", TextTable::LEFT
, TextTable::RIGHT
);
5176 tbl
->define_column("DATA", TextTable::LEFT
, TextTable::RIGHT
);
5177 tbl
->define_column("OMAP", TextTable::LEFT
, TextTable::RIGHT
);
5178 tbl
->define_column("META", TextTable::LEFT
, TextTable::RIGHT
);
5179 tbl
->define_column("AVAIL", TextTable::LEFT
, TextTable::RIGHT
);
5180 tbl
->define_column("%USE", TextTable::LEFT
, TextTable::RIGHT
);
5181 tbl
->define_column("VAR", TextTable::LEFT
, TextTable::RIGHT
);
5182 tbl
->define_column("PGS", TextTable::LEFT
, TextTable::RIGHT
);
5183 tbl
->define_column("STATUS", TextTable::LEFT
, TextTable::RIGHT
);
5185 tbl
->define_column("TYPE NAME", TextTable::LEFT
, TextTable::LEFT
);
5191 auto sum
= pgmap
.get_osd_sum(get_dumped_osds());
5195 << byte_u_t(sum
.statfs
.total
)
5196 << byte_u_t(sum
.statfs
.get_used_raw())
5197 << byte_u_t(sum
.statfs
.allocated
)
5198 << byte_u_t(sum
.statfs
.omap_allocated
)
5199 << byte_u_t(sum
.statfs
.internal_metadata
)
5200 << byte_u_t(sum
.statfs
.available
)
5201 << lowprecision_t(average_util
)
5203 << TextTable::endrow
;
5207 struct lowprecision_t
{
5209 explicit lowprecision_t(float _v
) : v(_v
) {}
5211 friend std::ostream
&operator<<(ostream
& out
, const lowprecision_t
& v
);
5213 using OSDUtilizationDumper
<TextTable
>::dump_item
;
5214 void dump_item(const CrushTreeDumper::Item
&qi
,
5218 int64_t kb_used_data
,
5219 int64_t kb_used_omap
,
5220 int64_t kb_used_meta
,
5224 const size_t num_pgs
,
5225 TextTable
*tbl
) override
{
5226 const char *c
= crush
->get_item_class(qi
.id
);
5231 << weightf_t(qi
.weight
)
5232 << weightf_t(reweight
)
5233 << byte_u_t(kb
<< 10)
5234 << byte_u_t(kb_used
<< 10)
5235 << byte_u_t(kb_used_data
<< 10)
5236 << byte_u_t(kb_used_omap
<< 10)
5237 << byte_u_t(kb_used_meta
<< 10)
5238 << byte_u_t(kb_avail
<< 10)
5239 << lowprecision_t(util
)
5240 << lowprecision_t(var
);
5242 if (qi
.is_bucket()) {
5247 if (osdmap
->is_up(qi
.id
)) {
5249 } else if (osdmap
->is_destroyed(qi
.id
)) {
5250 *tbl
<< "destroyed";
5258 for (int k
= 0; k
< qi
.depth
; k
++)
5260 if (qi
.is_bucket()) {
5261 int type
= crush
->get_bucket_type(qi
.id
);
5262 name
<< crush
->get_type_name(type
) << " "
5263 << crush
->get_item_name(qi
.id
);
5265 name
<< "osd." << qi
.id
;
5270 *tbl
<< TextTable::endrow
;
5276 out
<< "MIN/MAX VAR: " << lowprecision_t(min_var
)
5277 << "/" << lowprecision_t(max_var
) << " "
5278 << "STDDEV: " << lowprecision_t(dev());
5283 ostream
& operator<<(ostream
& out
,
5284 const OSDUtilizationPlainDumper::lowprecision_t
& v
)
5288 } else if (v
.v
< 0.001) {
5291 std::streamsize p
= out
.precision();
5292 return out
<< std::fixed
<< std::setprecision(2) << v
.v
<< std::setprecision(p
);
5296 class OSDUtilizationFormatDumper
: public OSDUtilizationDumper
<Formatter
> {
5298 typedef OSDUtilizationDumper
<Formatter
> Parent
;
5300 OSDUtilizationFormatDumper(const CrushWrapper
*crush
, const OSDMap
*osdmap
,
5301 const PGMap
& pgmap
, bool tree
,
5302 const string
& class_name
,
5303 const string
& item_name
) :
5304 Parent(crush
, osdmap
, pgmap
, tree
, class_name
, item_name
) {}
5306 void dump(Formatter
*f
) {
5307 f
->open_array_section("nodes");
5311 f
->open_array_section("stray");
5317 using OSDUtilizationDumper
<Formatter
>::dump_item
;
5318 void dump_item(const CrushTreeDumper::Item
&qi
,
5322 int64_t kb_used_data
,
5323 int64_t kb_used_omap
,
5324 int64_t kb_used_meta
,
5328 const size_t num_pgs
,
5329 Formatter
*f
) override
{
5330 f
->open_object_section("item");
5331 CrushTreeDumper::dump_item_fields(crush
, weight_set_names
, qi
, f
);
5332 f
->dump_float("reweight", reweight
);
5333 f
->dump_int("kb", kb
);
5334 f
->dump_int("kb_used", kb_used
);
5335 f
->dump_int("kb_used_data", kb_used_data
);
5336 f
->dump_int("kb_used_omap", kb_used_omap
);
5337 f
->dump_int("kb_used_meta", kb_used_meta
);
5338 f
->dump_int("kb_avail", kb_avail
);
5339 f
->dump_float("utilization", util
);
5340 f
->dump_float("var", var
);
5341 f
->dump_unsigned("pgs", num_pgs
);
5342 if (!qi
.is_bucket()) {
5343 if (osdmap
->is_up(qi
.id
)) {
5344 f
->dump_string("status", "up");
5345 } else if (osdmap
->is_destroyed(qi
.id
)) {
5346 f
->dump_string("status", "destroyed");
5348 f
->dump_string("status", "down");
5351 CrushTreeDumper::dump_bucket_children(crush
, qi
, f
);
5356 void summary(Formatter
*f
) {
5357 f
->open_object_section("summary");
5358 auto sum
= pgmap
.get_osd_sum(get_dumped_osds());
5359 auto& s
= sum
.statfs
;
5361 f
->dump_int("total_kb", s
.kb());
5362 f
->dump_int("total_kb_used", s
.kb_used_raw());
5363 f
->dump_int("total_kb_used_data", s
.kb_used_data());
5364 f
->dump_int("total_kb_used_omap", s
.kb_used_omap());
5365 f
->dump_int("total_kb_used_meta", s
.kb_used_internal_metadata());
5366 f
->dump_int("total_kb_avail", s
.kb_avail());
5367 f
->dump_float("average_utilization", average_util
);
5368 f
->dump_float("min_var", min_var
);
5369 f
->dump_float("max_var", max_var
);
5370 f
->dump_float("dev", dev());
5375 void print_osd_utilization(const OSDMap
& osdmap
,
5380 const string
& class_name
,
5381 const string
& item_name
)
5383 const CrushWrapper
*crush
= osdmap
.crush
.get();
5385 f
->open_object_section("df");
5386 OSDUtilizationFormatDumper
d(crush
, &osdmap
, pgmap
, tree
,
5387 class_name
, item_name
);
5393 OSDUtilizationPlainDumper
d(crush
, &osdmap
, pgmap
, tree
,
5394 class_name
, item_name
);
5397 out
<< tbl
<< d
.summary() << "\n";
5401 void OSDMap::check_health(health_check_map_t
*checks
) const
5403 int num_osds
= get_num_osds();
5406 // OSD_$subtree_DOWN
5408 if (num_osds
>= 0) {
5409 int num_in_osds
= 0;
5410 int num_down_in_osds
= 0;
5412 set
<int> down_in_osds
;
5413 set
<int> up_in_osds
;
5414 set
<int> subtree_up
;
5415 unordered_map
<int, set
<int> > subtree_type_down
;
5416 unordered_map
<int, int> num_osds_subtree
;
5417 int max_type
= crush
->get_max_type_id();
5419 for (int i
= 0; i
< get_max_osd(); i
++) {
5421 if (crush
->item_exists(i
)) {
5429 if (down_in_osds
.count(i
) || up_in_osds
.count(i
))
5432 down_in_osds
.insert(i
);
5435 for (int type
= 0; type
<= max_type
; type
++) {
5436 if (!crush
->get_type_name(type
))
5438 int r
= crush
->get_immediate_parent_id(current
, &parent_id
);
5441 // break early if this parent is already marked as up
5442 if (subtree_up
.count(parent_id
))
5444 type
= crush
->get_bucket_type(parent_id
);
5445 if (!subtree_type_is_down(
5446 g_ceph_context
, parent_id
, type
,
5447 &down_in_osds
, &up_in_osds
, &subtree_up
, &subtree_type_down
))
5449 current
= parent_id
;
5454 // calculate the number of down osds in each down subtree and
5455 // store it in num_osds_subtree
5456 for (int type
= 1; type
<= max_type
; type
++) {
5457 if (!crush
->get_type_name(type
))
5459 for (auto j
= subtree_type_down
[type
].begin();
5460 j
!= subtree_type_down
[type
].end();
5464 int num_children
= crush
->get_children(*j
, &children
);
5465 if (num_children
== 0)
5467 for (auto l
= children
.begin(); l
!= children
.end(); ++l
) {
5470 } else if (num_osds_subtree
[*l
] > 0) {
5471 num
= num
+ num_osds_subtree
[*l
];
5474 num_osds_subtree
[*j
] = num
;
5477 num_down_in_osds
= down_in_osds
.size();
5478 ceph_assert(num_down_in_osds
<= num_in_osds
);
5479 if (num_down_in_osds
> 0) {
5480 // summary of down subtree types and osds
5481 for (int type
= max_type
; type
> 0; type
--) {
5482 if (!crush
->get_type_name(type
))
5484 if (subtree_type_down
[type
].size() > 0) {
5486 ss
<< subtree_type_down
[type
].size() << " "
5487 << crush
->get_type_name(type
);
5488 if (subtree_type_down
[type
].size() > 1) {
5491 int sum_down_osds
= 0;
5492 for (auto j
= subtree_type_down
[type
].begin();
5493 j
!= subtree_type_down
[type
].end();
5495 sum_down_osds
= sum_down_osds
+ num_osds_subtree
[*j
];
5497 ss
<< " (" << sum_down_osds
<< " osds) down";
5498 string err
= string("OSD_") +
5499 string(crush
->get_type_name(type
)) + "_DOWN";
5500 boost::to_upper(err
);
5501 auto& d
= checks
->add(err
, HEALTH_WARN
, ss
.str());
5502 for (auto j
= subtree_type_down
[type
].rbegin();
5503 j
!= subtree_type_down
[type
].rend();
5506 ss
<< crush
->get_type_name(type
);
5508 ss
<< crush
->get_item_name(*j
);
5509 // at the top level, do not print location
5510 if (type
!= max_type
) {
5512 ss
<< crush
->get_full_location_ordered_string(*j
);
5515 int num
= num_osds_subtree
[*j
];
5516 ss
<< " (" << num
<< " osds)";
5518 d
.detail
.push_back(ss
.str());
5523 ss
<< down_in_osds
.size() << " osds down";
5524 auto& d
= checks
->add("OSD_DOWN", HEALTH_WARN
, ss
.str());
5525 for (auto it
= down_in_osds
.begin(); it
!= down_in_osds
.end(); ++it
) {
5527 ss
<< "osd." << *it
<< " (";
5528 ss
<< crush
->get_full_location_ordered_string(*it
);
5530 d
.detail
.push_back(ss
.str());
5534 if (!osds
.empty()) {
5536 ss
<< osds
.size() << " osds exist in the crush map but not in the osdmap";
5537 auto& d
= checks
->add("OSD_ORPHAN", HEALTH_WARN
, ss
.str());
5538 for (auto osd
: osds
) {
5540 ss
<< "osd." << osd
<< " exists in crush map but not in osdmap";
5541 d
.detail
.push_back(ss
.str());
5546 // OSD_OUT_OF_ORDER_FULL
5548 // An osd could configure failsafe ratio, to something different
5549 // but for now assume it is the same here.
5550 float fsr
= g_conf()->osd_failsafe_full_ratio
;
5551 if (fsr
> 1.0) fsr
/= 100;
5552 float fr
= get_full_ratio();
5553 float br
= get_backfillfull_ratio();
5554 float nr
= get_nearfull_ratio();
5556 list
<string
> detail
;
5557 // These checks correspond to how OSDService::check_full_status() in an OSD
5558 // handles the improper setting of these values.
5561 ss
<< "backfillfull_ratio (" << br
5562 << ") < nearfull_ratio (" << nr
<< "), increased";
5563 detail
.push_back(ss
.str());
5568 ss
<< "full_ratio (" << fr
<< ") < backfillfull_ratio (" << br
5570 detail
.push_back(ss
.str());
5575 ss
<< "osd_failsafe_full_ratio (" << fsr
<< ") < full_ratio (" << fr
5577 detail
.push_back(ss
.str());
5579 if (!detail
.empty()) {
5580 auto& d
= checks
->add("OSD_OUT_OF_ORDER_FULL", HEALTH_ERR
,
5581 "full ratio(s) out of order");
5582 d
.detail
.swap(detail
);
5589 // OSD_FAILSAFE_FULL
5591 set
<int> full
, backfillfull
, nearfull
;
5592 get_full_osd_counts(&full
, &backfillfull
, &nearfull
);
5595 ss
<< full
.size() << " full osd(s)";
5596 auto& d
= checks
->add("OSD_FULL", HEALTH_ERR
, ss
.str());
5597 for (auto& i
: full
) {
5599 ss
<< "osd." << i
<< " is full";
5600 d
.detail
.push_back(ss
.str());
5603 if (backfillfull
.size()) {
5605 ss
<< backfillfull
.size() << " backfillfull osd(s)";
5606 auto& d
= checks
->add("OSD_BACKFILLFULL", HEALTH_WARN
, ss
.str());
5607 for (auto& i
: backfillfull
) {
5609 ss
<< "osd." << i
<< " is backfill full";
5610 d
.detail
.push_back(ss
.str());
5613 if (nearfull
.size()) {
5615 ss
<< nearfull
.size() << " nearfull osd(s)";
5616 auto& d
= checks
->add("OSD_NEARFULL", HEALTH_WARN
, ss
.str());
5617 for (auto& i
: nearfull
) {
5619 ss
<< "osd." << i
<< " is near full";
5620 d
.detail
.push_back(ss
.str());
5628 uint64_t warn_flags
=
5629 CEPH_OSDMAP_NEARFULL
|
5631 CEPH_OSDMAP_PAUSERD
|
5632 CEPH_OSDMAP_PAUSEWR
|
5633 CEPH_OSDMAP_PAUSEREC
|
5635 CEPH_OSDMAP_NODOWN
|
5638 CEPH_OSDMAP_NOBACKFILL
|
5639 CEPH_OSDMAP_NORECOVER
|
5640 CEPH_OSDMAP_NOSCRUB
|
5641 CEPH_OSDMAP_NODEEP_SCRUB
|
5642 CEPH_OSDMAP_NOTIERAGENT
|
5643 CEPH_OSDMAP_NOSNAPTRIM
|
5644 CEPH_OSDMAP_NOREBALANCE
;
5645 if (test_flag(warn_flags
)) {
5647 ss
<< get_flag_string(get_flags() & warn_flags
)
5649 checks
->add("OSDMAP_FLAGS", HEALTH_WARN
, ss
.str());
5655 list
<string
> detail
;
5656 const unsigned flags
=
5661 for (int i
= 0; i
< max_osd
; ++i
) {
5662 if (osd_state
[i
] & flags
) {
5665 OSDMap::calc_state_set(osd_state
[i
] & flags
, states
);
5666 ss
<< "osd." << i
<< " has flags " << states
;
5667 detail
.push_back(ss
.str());
5670 for (auto& i
: crush_node_flags
) {
5671 if (i
.second
&& crush
->item_exists(i
.first
)) {
5674 OSDMap::calc_state_set(i
.second
, states
);
5675 int t
= i
.first
>= 0 ? 0 : crush
->get_bucket_type(i
.first
);
5676 const char *tn
= crush
->get_type_name(t
);
5677 ss
<< (tn
? tn
: "node") << " "
5678 << crush
->get_item_name(i
.first
) << " has flags " << states
;
5679 detail
.push_back(ss
.str());
5682 for (auto& i
: device_class_flags
) {
5683 const char* class_name
= crush
->get_class_name(i
.first
);
5684 if (i
.second
&& class_name
) {
5687 OSDMap::calc_state_set(i
.second
, states
);
5688 ss
<< "device class '" << class_name
<< "' has flags " << states
;
5689 detail
.push_back(ss
.str());
5692 if (!detail
.empty()) {
5694 ss
<< detail
.size() << " OSDs or CRUSH {nodes, device-classes} have {NOUP,NODOWN,NOIN,NOOUT} flags set";
5695 auto& d
= checks
->add("OSD_FLAGS", HEALTH_WARN
, ss
.str());
5696 d
.detail
.swap(detail
);
5700 // OLD_CRUSH_TUNABLES
5701 if (g_conf()->mon_warn_on_legacy_crush_tunables
) {
5702 string min
= crush
->get_min_required_version();
5703 if (min
< g_conf()->mon_crush_min_required_version
) {
5705 ss
<< "crush map has legacy tunables (require " << min
5706 << ", min is " << g_conf()->mon_crush_min_required_version
<< ")";
5707 auto& d
= checks
->add("OLD_CRUSH_TUNABLES", HEALTH_WARN
, ss
.str());
5708 d
.detail
.push_back("see http://docs.ceph.com/docs/master/rados/operations/crush-map/#tunables");
5712 // OLD_CRUSH_STRAW_CALC_VERSION
5713 if (g_conf()->mon_warn_on_crush_straw_calc_version_zero
) {
5714 if (crush
->get_straw_calc_version() == 0) {
5716 ss
<< "crush map has straw_calc_version=0";
5717 auto& d
= checks
->add("OLD_CRUSH_STRAW_CALC_VERSION", HEALTH_WARN
, ss
.str());
5719 "see http://docs.ceph.com/docs/master/rados/operations/crush-map/#tunables");
5723 // CACHE_POOL_NO_HIT_SET
5724 if (g_conf()->mon_warn_on_cache_pools_without_hit_sets
) {
5725 list
<string
> detail
;
5726 for (map
<int64_t, pg_pool_t
>::const_iterator p
= pools
.begin();
5729 const pg_pool_t
& info
= p
->second
;
5730 if (info
.cache_mode_requires_hit_set() &&
5731 info
.hit_set_params
.get_type() == HitSet::TYPE_NONE
) {
5733 ss
<< "pool '" << get_pool_name(p
->first
)
5734 << "' with cache_mode " << info
.get_cache_mode_name()
5735 << " needs hit_set_type to be set but it is not";
5736 detail
.push_back(ss
.str());
5739 if (!detail
.empty()) {
5741 ss
<< detail
.size() << " cache pools are missing hit_sets";
5742 auto& d
= checks
->add("CACHE_POOL_NO_HIT_SET", HEALTH_WARN
, ss
.str());
5743 d
.detail
.swap(detail
);
5747 // OSD_NO_SORTBITWISE
5748 if (!test_flag(CEPH_OSDMAP_SORTBITWISE
)) {
5750 ss
<< "'sortbitwise' flag is not set";
5751 checks
->add("OSD_NO_SORTBITWISE", HEALTH_WARN
, ss
.str());
5754 // OSD_UPGRADE_FINISHED
5755 // none of these (yet) since we don't run until luminous upgrade is done.
5757 // POOL_NEARFULL/BACKFILLFULL/FULL
5759 list
<string
> full_detail
, backfillfull_detail
, nearfull_detail
;
5760 for (auto it
: get_pools()) {
5761 const pg_pool_t
&pool
= it
.second
;
5762 const string
& pool_name
= get_pool_name(it
.first
);
5763 if (pool
.has_flag(pg_pool_t::FLAG_FULL
)) {
5765 if (pool
.has_flag(pg_pool_t::FLAG_FULL_QUOTA
)) {
5766 // may run out of space too,
5767 // but we want EQUOTA taking precedence
5768 ss
<< "pool '" << pool_name
<< "' is full (running out of quota)";
5770 ss
<< "pool '" << pool_name
<< "' is full (no space)";
5772 full_detail
.push_back(ss
.str());
5773 } else if (pool
.has_flag(pg_pool_t::FLAG_BACKFILLFULL
)) {
5775 ss
<< "pool '" << pool_name
<< "' is backfillfull";
5776 backfillfull_detail
.push_back(ss
.str());
5777 } else if (pool
.has_flag(pg_pool_t::FLAG_NEARFULL
)) {
5779 ss
<< "pool '" << pool_name
<< "' is nearfull";
5780 nearfull_detail
.push_back(ss
.str());
5783 if (!full_detail
.empty()) {
5785 ss
<< full_detail
.size() << " pool(s) full";
5786 auto& d
= checks
->add("POOL_FULL", HEALTH_WARN
, ss
.str());
5787 d
.detail
.swap(full_detail
);
5789 if (!backfillfull_detail
.empty()) {
5791 ss
<< backfillfull_detail
.size() << " pool(s) backfillfull";
5792 auto& d
= checks
->add("POOL_BACKFILLFULL", HEALTH_WARN
, ss
.str());
5793 d
.detail
.swap(backfillfull_detail
);
5795 if (!nearfull_detail
.empty()) {
5797 ss
<< nearfull_detail
.size() << " pool(s) nearfull";
5798 auto& d
= checks
->add("POOL_NEARFULL", HEALTH_WARN
, ss
.str());
5799 d
.detail
.swap(nearfull_detail
);
5804 int OSDMap::parse_osd_id_list(const vector
<string
>& ls
, set
<int> *out
,
5808 for (auto i
= ls
.begin(); i
!= ls
.end(); ++i
) {
5809 if (i
== ls
.begin() &&
5810 (*i
== "any" || *i
== "all" || *i
== "*")) {
5814 long osd
= parse_osd_id(i
->c_str(), ss
);
5816 *ss
<< "invalid osd id '" << *i
<< "'";
5824 void OSDMap::get_random_up_osds_by_subtree(int n
, // whoami
5826 int limit
, // how many
5828 set
<int> *want
) const {
5831 int subtree_type
= crush
->get_type_id(subtree
);
5832 if (subtree_type
< 1)
5834 vector
<int> subtrees
;
5835 crush
->get_subtree_of_type(subtree_type
, &subtrees
);
5836 std::random_device rd
;
5837 std::default_random_engine rng
{rd()};
5838 std::shuffle(subtrees
.begin(), subtrees
.end(), rng
);
5839 for (auto s
: subtrees
) {
5842 if (crush
->subtree_contains(s
, n
))
5845 crush
->get_children_of_type(s
, 0, &osds
);
5848 vector
<int> up_osds
;
5849 for (auto o
: osds
) {
5850 if (is_up(o
) && !skip
.count(o
))
5851 up_osds
.push_back(o
);
5853 if (up_osds
.empty())
5855 auto it
= up_osds
.begin();
5856 std::advance(it
, (n
% up_osds
.size()));
5862 float OSDMap::pool_raw_used_rate(int64_t poolid
) const
5864 const pg_pool_t
*pool
= get_pg_pool(poolid
);
5865 assert(pool
!= nullptr);
5867 switch (pool
->get_type()) {
5868 case pg_pool_t::TYPE_REPLICATED
:
5869 return pool
->get_size();
5871 case pg_pool_t::TYPE_ERASURE
:
5874 get_erasure_code_profile(pool
->erasure_code_profile
);
5875 auto pm
= ecp
.find("m");
5876 auto pk
= ecp
.find("k");
5877 if (pm
!= ecp
.end() && pk
!= ecp
.end()) {
5878 int k
= atoi(pk
->second
.c_str());
5879 int m
= atoi(pm
->second
.c_str());
5881 ceph_assert(mk
!= 0);
5882 ceph_assert(k
!= 0);
5883 return (float)mk
/ k
;
5890 ceph_abort_msg("unrecognized pool type");
5894 unsigned OSDMap::get_osd_crush_node_flags(int osd
) const
5897 if (!crush_node_flags
.empty()) {
5898 // the map will contain type -> name
5899 std::map
<std::string
,std::string
> ploc
= crush
->get_full_location(osd
);
5900 for (auto& i
: ploc
) {
5901 int id
= crush
->get_item_id(i
.second
);
5902 auto p
= crush_node_flags
.find(id
);
5903 if (p
!= crush_node_flags
.end()) {
5911 unsigned OSDMap::get_crush_node_flags(int id
) const
5914 auto it
= crush_node_flags
.find(id
);
5915 if (it
!= crush_node_flags
.end())
5920 unsigned OSDMap::get_device_class_flags(int id
) const
5923 auto it
= device_class_flags
.find(id
);
5924 if (it
!= device_class_flags
.end())