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) 2013,2014 Inktank Storage, Inc.
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.
19 #include "common/errno.h"
20 #include "common/scrub_types.h"
21 #include "ReplicatedBackend.h"
22 #include "ScrubStore.h"
23 #include "ECBackend.h"
24 #include "PGBackend.h"
26 #include "erasure-code/ErasureCodePlugin.h"
29 #include "common/LogClient.h"
30 #include "messages/MOSDPGRecoveryDelete.h"
31 #include "messages/MOSDPGRecoveryDeleteReply.h"
33 #define dout_context cct
34 #define dout_subsys ceph_subsys_osd
35 #define DOUT_PREFIX_ARGS this
37 #define dout_prefix _prefix(_dout, this)
38 static ostream
& _prefix(std::ostream
*_dout
, PGBackend
*pgb
) {
39 return pgb
->get_parent()->gen_dbg_prefix(*_dout
);
42 void PGBackend::recover_delete_object(const hobject_t
&oid
, eversion_t v
,
45 ceph_assert(get_parent()->get_acting_recovery_backfill_shards().size() > 0);
46 for (const auto& shard
: get_parent()->get_acting_recovery_backfill_shards()) {
47 if (shard
== get_parent()->whoami_shard())
49 if (get_parent()->get_shard_missing(shard
).is_missing(oid
)) {
50 dout(20) << __func__
<< " will remove " << oid
<< " " << v
<< " from "
52 h
->deletes
[shard
].push_back(make_pair(oid
, v
));
53 get_parent()->begin_peer_recover(shard
, oid
);
58 void PGBackend::send_recovery_deletes(int prio
,
59 const map
<pg_shard_t
, vector
<pair
<hobject_t
, eversion_t
> > > &deletes
)
61 epoch_t min_epoch
= get_parent()->get_last_peering_reset_epoch();
62 for (const auto& p
: deletes
) {
63 const auto& shard
= p
.first
;
64 const auto& objects
= p
.second
;
65 ConnectionRef con
= get_parent()->get_con_osd_cluster(
70 auto it
= objects
.begin();
71 while (it
!= objects
.end()) {
74 spg_t target_pg
= spg_t(get_parent()->get_info().pgid
.pgid
, shard
.shard
);
75 MOSDPGRecoveryDelete
*msg
=
76 new MOSDPGRecoveryDelete(get_parent()->whoami_shard(),
80 msg
->set_priority(prio
);
82 while (it
!= objects
.end() &&
83 cost
< cct
->_conf
->osd_max_push_cost
&&
84 deletes
< cct
->_conf
->osd_max_push_objects
) {
85 dout(20) << __func__
<< ": sending recovery delete << " << it
->first
86 << " " << it
->second
<< " to osd." << shard
<< dendl
;
87 msg
->objects
.push_back(*it
);
88 cost
+= cct
->_conf
->osd_push_per_object_cost
;
94 get_parent()->send_message_osd_cluster(msg
, con
);
99 bool PGBackend::handle_message(OpRequestRef op
)
101 switch (op
->get_req()->get_type()) {
102 case MSG_OSD_PG_RECOVERY_DELETE
:
103 handle_recovery_delete(op
);
106 case MSG_OSD_PG_RECOVERY_DELETE_REPLY
:
107 handle_recovery_delete_reply(op
);
114 return _handle_message(op
);
117 void PGBackend::handle_recovery_delete(OpRequestRef op
)
119 auto m
= op
->get_req
<MOSDPGRecoveryDelete
>();
120 ceph_assert(m
->get_type() == MSG_OSD_PG_RECOVERY_DELETE
);
121 dout(20) << __func__
<< " " << op
<< dendl
;
125 C_GatherBuilder
gather(cct
);
126 for (const auto &p
: m
->objects
) {
127 get_parent()->remove_missing_object(p
.first
, p
.second
, gather
.new_sub());
130 MOSDPGRecoveryDeleteReply
*reply
= new MOSDPGRecoveryDeleteReply
;
131 reply
->from
= get_parent()->whoami_shard();
132 reply
->set_priority(m
->get_priority());
133 reply
->pgid
= spg_t(get_parent()->get_info().pgid
.pgid
, m
->from
.shard
);
134 reply
->map_epoch
= m
->map_epoch
;
135 reply
->min_epoch
= m
->min_epoch
;
136 reply
->objects
= m
->objects
;
137 ConnectionRef conn
= m
->get_connection();
139 gather
.set_finisher(new LambdaContext(
142 get_parent()->send_message_osd_cluster(reply
, conn
.get());
150 void PGBackend::handle_recovery_delete_reply(OpRequestRef op
)
152 auto m
= op
->get_req
<MOSDPGRecoveryDeleteReply
>();
153 ceph_assert(m
->get_type() == MSG_OSD_PG_RECOVERY_DELETE_REPLY
);
154 dout(20) << __func__
<< " " << op
<< dendl
;
156 for (const auto &p
: m
->objects
) {
157 ObjectRecoveryInfo recovery_info
;
158 hobject_t oid
= p
.first
;
159 recovery_info
.version
= p
.second
;
160 get_parent()->on_peer_recover(m
->from
, oid
, recovery_info
);
161 bool peers_recovered
= true;
162 for (const auto& shard
: get_parent()->get_acting_recovery_backfill_shards()) {
163 if (shard
== get_parent()->whoami_shard())
165 if (get_parent()->get_shard_missing(shard
).is_missing(oid
)) {
166 dout(20) << __func__
<< " " << oid
<< " still missing on at least "
168 peers_recovered
= false;
172 if (peers_recovered
&& !get_parent()->get_local_missing().is_missing(oid
)) {
173 dout(20) << __func__
<< " completed recovery, local_missing = "
174 << get_parent()->get_local_missing() << dendl
;
175 object_stat_sum_t stat_diff
;
176 stat_diff
.num_objects_recovered
= 1;
177 get_parent()->on_global_recover(p
.first
, stat_diff
, true);
182 void PGBackend::rollback(
183 const pg_log_entry_t
&entry
,
184 ObjectStore::Transaction
*t
)
187 struct RollbackVisitor
: public ObjectModDesc::Visitor
{
188 const hobject_t
&hoid
;
190 ObjectStore::Transaction t
;
192 const hobject_t
&hoid
,
193 PGBackend
*pg
) : hoid(hoid
), pg(pg
) {}
194 void append(uint64_t old_size
) override
{
195 ObjectStore::Transaction temp
;
196 pg
->rollback_append(hoid
, old_size
, &temp
);
200 void setattrs(map
<string
, std::optional
<bufferlist
> > &attrs
) override
{
201 ObjectStore::Transaction temp
;
202 pg
->rollback_setattrs(hoid
, attrs
, &temp
);
206 void rmobject(version_t old_version
) override
{
207 ObjectStore::Transaction temp
;
208 pg
->rollback_stash(hoid
, old_version
, &temp
);
212 void try_rmobject(version_t old_version
) override
{
213 ObjectStore::Transaction temp
;
214 pg
->rollback_try_stash(hoid
, old_version
, &temp
);
218 void create() override
{
219 ObjectStore::Transaction temp
;
220 pg
->rollback_create(hoid
, &temp
);
224 void update_snaps(const set
<snapid_t
> &snaps
) override
{
225 ObjectStore::Transaction temp
;
226 pg
->get_parent()->pgb_set_object_snap_mapping(hoid
, snaps
, &temp
);
230 void rollback_extents(
232 const vector
<pair
<uint64_t, uint64_t> > &extents
) override
{
233 ObjectStore::Transaction temp
;
234 pg
->rollback_extents(gen
, extents
, hoid
, &temp
);
240 ceph_assert(entry
.mod_desc
.can_rollback());
241 RollbackVisitor
vis(entry
.soid
, this);
242 entry
.mod_desc
.visit(&vis
);
246 struct Trimmer
: public ObjectModDesc::Visitor
{
247 const hobject_t
&soid
;
249 ObjectStore::Transaction
*t
;
251 const hobject_t
&soid
,
253 ObjectStore::Transaction
*t
)
254 : soid(soid
), pg(pg
), t(t
) {}
255 void rmobject(version_t old_version
) override
{
256 pg
->trim_rollback_object(
261 // try_rmobject defaults to rmobject
262 void rollback_extents(
264 const vector
<pair
<uint64_t, uint64_t> > &extents
) override
{
265 pg
->trim_rollback_object(
272 void PGBackend::rollforward(
273 const pg_log_entry_t
&entry
,
274 ObjectStore::Transaction
*t
)
276 auto dpp
= get_parent()->get_dpp();
277 ldpp_dout(dpp
, 20) << __func__
<< ": entry=" << entry
<< dendl
;
278 if (!entry
.can_rollback())
280 Trimmer
trimmer(entry
.soid
, this, t
);
281 entry
.mod_desc
.visit(&trimmer
);
284 void PGBackend::trim(
285 const pg_log_entry_t
&entry
,
286 ObjectStore::Transaction
*t
)
288 if (!entry
.can_rollback())
290 Trimmer
trimmer(entry
.soid
, this, t
);
291 entry
.mod_desc
.visit(&trimmer
);
294 void PGBackend::try_stash(
295 const hobject_t
&hoid
,
297 ObjectStore::Transaction
*t
)
301 ghobject_t(hoid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
302 ghobject_t(hoid
, v
, get_parent()->whoami_shard().shard
));
305 void PGBackend::remove(
306 const hobject_t
&hoid
,
307 ObjectStore::Transaction
*t
) {
308 ceph_assert(!hoid
.is_temp());
311 ghobject_t(hoid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
));
312 get_parent()->pgb_clear_object_snap_mapping(hoid
, t
);
315 void PGBackend::on_change_cleanup(ObjectStore::Transaction
*t
)
317 dout(10) << __func__
<< dendl
;
319 for (set
<hobject_t
>::iterator i
= temp_contents
.begin();
320 i
!= temp_contents
.end();
322 dout(10) << __func__
<< ": Removing oid "
323 << *i
<< " from the temp collection" << dendl
;
326 ghobject_t(*i
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
));
328 temp_contents
.clear();
331 int PGBackend::objects_list_partial(
332 const hobject_t
&begin
,
335 vector
<hobject_t
> *ls
,
339 // Starts with the smallest generation to make sure the result list
340 // has the marker object (it might have multiple generations
341 // though, which would be filtered).
344 _next
= ghobject_t(begin
, 0, get_parent()->whoami_shard().shard
);
351 while (!_next
.is_max() && ls
->size() < (unsigned)min
) {
352 vector
<ghobject_t
> objects
;
353 if (HAVE_FEATURE(parent
->min_upacting_features(),
354 OSD_FIXED_COLLECTION_LIST
)) {
355 r
= store
->collection_list(
358 ghobject_t::get_max(),
363 r
= store
->collection_list_legacy(
366 ghobject_t::get_max(),
372 derr
<< __func__
<< " list collection " << ch
<< " got: " << cpp_strerror(r
) << dendl
;
375 for (vector
<ghobject_t
>::iterator i
= objects
.begin();
378 if (i
->is_pgmeta() || i
->hobj
.is_temp()) {
381 if (i
->is_no_gen()) {
382 ls
->push_back(i
->hobj
);
391 int PGBackend::objects_list_range(
392 const hobject_t
&start
,
393 const hobject_t
&end
,
394 vector
<hobject_t
> *ls
,
395 vector
<ghobject_t
> *gen_obs
)
398 vector
<ghobject_t
> objects
;
400 if (HAVE_FEATURE(parent
->min_upacting_features(),
401 OSD_FIXED_COLLECTION_LIST
)) {
402 r
= store
->collection_list(
404 ghobject_t(start
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
405 ghobject_t(end
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
410 r
= store
->collection_list_legacy(
412 ghobject_t(start
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
413 ghobject_t(end
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
418 ls
->reserve(objects
.size());
419 for (vector
<ghobject_t
>::iterator i
= objects
.begin();
422 if (i
->is_pgmeta() || i
->hobj
.is_temp()) {
425 if (i
->is_no_gen()) {
426 ls
->push_back(i
->hobj
);
427 } else if (gen_obs
) {
428 gen_obs
->push_back(*i
);
434 int PGBackend::objects_get_attr(
435 const hobject_t
&hoid
,
440 int r
= store
->getattr(
442 ghobject_t(hoid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
447 out
->push_back(std::move(bp
));
452 int PGBackend::objects_get_attrs(
453 const hobject_t
&hoid
,
454 map
<string
, bufferlist
> *out
)
456 return store
->getattrs(
458 ghobject_t(hoid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
462 void PGBackend::rollback_setattrs(
463 const hobject_t
&hoid
,
464 map
<string
, std::optional
<bufferlist
> > &old_attrs
,
465 ObjectStore::Transaction
*t
) {
466 map
<string
, bufferlist
> to_set
;
467 ceph_assert(!hoid
.is_temp());
468 for (map
<string
, std::optional
<bufferlist
> >::iterator i
= old_attrs
.begin();
469 i
!= old_attrs
.end();
472 to_set
[i
->first
] = *(i
->second
);
476 ghobject_t(hoid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
482 ghobject_t(hoid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
486 void PGBackend::rollback_append(
487 const hobject_t
&hoid
,
489 ObjectStore::Transaction
*t
) {
490 ceph_assert(!hoid
.is_temp());
493 ghobject_t(hoid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
497 void PGBackend::rollback_stash(
498 const hobject_t
&hoid
,
499 version_t old_version
,
500 ObjectStore::Transaction
*t
) {
501 ceph_assert(!hoid
.is_temp());
504 ghobject_t(hoid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
));
505 t
->collection_move_rename(
507 ghobject_t(hoid
, old_version
, get_parent()->whoami_shard().shard
),
509 ghobject_t(hoid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
));
512 void PGBackend::rollback_try_stash(
513 const hobject_t
&hoid
,
514 version_t old_version
,
515 ObjectStore::Transaction
*t
) {
516 ceph_assert(!hoid
.is_temp());
519 ghobject_t(hoid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
));
522 ghobject_t(hoid
, old_version
, get_parent()->whoami_shard().shard
),
523 ghobject_t(hoid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
));
526 void PGBackend::rollback_extents(
528 const vector
<pair
<uint64_t, uint64_t> > &extents
,
529 const hobject_t
&hoid
,
530 ObjectStore::Transaction
*t
) {
531 auto shard
= get_parent()->whoami_shard().shard
;
532 for (auto &&extent
: extents
) {
535 ghobject_t(hoid
, gen
, shard
),
536 ghobject_t(hoid
, ghobject_t::NO_GEN
, shard
),
543 ghobject_t(hoid
, gen
, shard
));
546 void PGBackend::trim_rollback_object(
547 const hobject_t
&hoid
,
548 version_t old_version
,
549 ObjectStore::Transaction
*t
) {
550 ceph_assert(!hoid
.is_temp());
552 coll
, ghobject_t(hoid
, old_version
, get_parent()->whoami_shard().shard
));
555 PGBackend
*PGBackend::build_pg_backend(
556 const pg_pool_t
&pool
,
557 const map
<string
,string
>& profile
,
560 ObjectStore::CollectionHandle
&ch
,
564 ErasureCodeProfile ec_profile
= profile
;
566 case pg_pool_t::TYPE_REPLICATED
: {
567 return new ReplicatedBackend(l
, coll
, ch
, store
, cct
);
569 case pg_pool_t::TYPE_ERASURE
: {
570 ErasureCodeInterfaceRef ec_impl
;
572 ceph::ErasureCodePluginRegistry::instance().factory(
573 profile
.find("plugin")->second
,
574 cct
->_conf
.get_val
<std::string
>("erasure_code_dir"),
578 ceph_assert(ec_impl
);
579 return new ECBackend(
594 int PGBackend::be_scan_list(
596 ScrubMapBuilder
&pos
)
598 dout(10) << __func__
<< " " << pos
<< dendl
;
599 ceph_assert(!pos
.done());
600 ceph_assert(pos
.pos
< pos
.ls
.size());
601 hobject_t
& poid
= pos
.ls
[pos
.pos
];
607 poid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
611 ScrubMap::object
&o
= map
.objects
[poid
];
613 ceph_assert(!o
.negative
);
617 poid
, ghobject_t::NO_GEN
, get_parent()->whoami_shard().shard
),
621 r
= be_deep_scrub(poid
, map
, pos
, o
);
623 dout(25) << __func__
<< " " << poid
<< dendl
;
624 } else if (r
== -ENOENT
) {
625 dout(25) << __func__
<< " " << poid
<< " got " << r
626 << ", skipping" << dendl
;
627 } else if (r
== -EIO
) {
628 dout(25) << __func__
<< " " << poid
<< " got " << r
629 << ", stat_error" << dendl
;
630 ScrubMap::object
&o
= map
.objects
[poid
];
633 derr
<< __func__
<< " got: " << cpp_strerror(r
) << dendl
;
636 if (r
== -EINPROGRESS
) {
643 bool PGBackend::be_compare_scrub_objects(
644 pg_shard_t auth_shard
,
645 const ScrubMap::object
&auth
,
646 const object_info_t
& auth_oi
,
647 const ScrubMap::object
&candidate
,
648 shard_info_wrapper
&shard_result
,
649 inconsistent_obj_wrapper
&obj_result
,
650 ostream
&errorstream
,
653 enum { CLEAN
, FOUND_ERROR
} error
= CLEAN
;
654 if (auth
.digest_present
&& candidate
.digest_present
) {
655 if (auth
.digest
!= candidate
.digest
) {
659 errorstream
<< "data_digest 0x" << std::hex
<< candidate
.digest
660 << " != data_digest 0x" << auth
.digest
<< std::dec
661 << " from shard " << auth_shard
;
662 obj_result
.set_data_digest_mismatch();
665 if (auth
.omap_digest_present
&& candidate
.omap_digest_present
) {
666 if (auth
.omap_digest
!= candidate
.omap_digest
) {
670 errorstream
<< "omap_digest 0x" << std::hex
<< candidate
.omap_digest
671 << " != omap_digest 0x" << auth
.omap_digest
<< std::dec
672 << " from shard " << auth_shard
;
673 obj_result
.set_omap_digest_mismatch();
676 if (parent
->get_pool().is_replicated()) {
677 if (auth_oi
.is_data_digest() && candidate
.digest_present
) {
678 if (auth_oi
.data_digest
!= candidate
.digest
) {
682 errorstream
<< "data_digest 0x" << std::hex
<< candidate
.digest
683 << " != data_digest 0x" << auth_oi
.data_digest
<< std::dec
684 << " from auth oi " << auth_oi
;
685 shard_result
.set_data_digest_mismatch_info();
688 if (auth_oi
.is_omap_digest() && candidate
.omap_digest_present
) {
689 if (auth_oi
.omap_digest
!= candidate
.omap_digest
) {
693 errorstream
<< "omap_digest 0x" << std::hex
<< candidate
.omap_digest
694 << " != omap_digest 0x" << auth_oi
.omap_digest
<< std::dec
695 << " from auth oi " << auth_oi
;
696 shard_result
.set_omap_digest_mismatch_info();
700 if (candidate
.stat_error
)
701 return error
== FOUND_ERROR
;
702 if (!shard_result
.has_info_missing()
703 && !shard_result
.has_info_corrupted()) {
704 bufferlist can_bl
, auth_bl
;
705 auto can_attr
= candidate
.attrs
.find(OI_ATTR
);
706 auto auth_attr
= auth
.attrs
.find(OI_ATTR
);
708 ceph_assert(auth_attr
!= auth
.attrs
.end());
709 ceph_assert(can_attr
!= candidate
.attrs
.end());
711 can_bl
.push_back(can_attr
->second
);
712 auth_bl
.push_back(auth_attr
->second
);
713 if (!can_bl
.contents_equal(auth_bl
)) {
717 obj_result
.set_object_info_inconsistency();
718 errorstream
<< "object info inconsistent ";
722 if (!shard_result
.has_snapset_missing()
723 && !shard_result
.has_snapset_corrupted()) {
724 bufferlist can_bl
, auth_bl
;
725 auto can_attr
= candidate
.attrs
.find(SS_ATTR
);
726 auto auth_attr
= auth
.attrs
.find(SS_ATTR
);
728 ceph_assert(auth_attr
!= auth
.attrs
.end());
729 ceph_assert(can_attr
!= candidate
.attrs
.end());
731 can_bl
.push_back(can_attr
->second
);
732 auth_bl
.push_back(auth_attr
->second
);
733 if (!can_bl
.contents_equal(auth_bl
)) {
737 obj_result
.set_snapset_inconsistency();
738 errorstream
<< "snapset inconsistent ";
742 if (parent
->get_pool().is_erasure()) {
743 if (!shard_result
.has_hinfo_missing()
744 && !shard_result
.has_hinfo_corrupted()) {
745 bufferlist can_bl
, auth_bl
;
746 auto can_hi
= candidate
.attrs
.find(ECUtil::get_hinfo_key());
747 auto auth_hi
= auth
.attrs
.find(ECUtil::get_hinfo_key());
749 ceph_assert(auth_hi
!= auth
.attrs
.end());
750 ceph_assert(can_hi
!= candidate
.attrs
.end());
752 can_bl
.push_back(can_hi
->second
);
753 auth_bl
.push_back(auth_hi
->second
);
754 if (!can_bl
.contents_equal(auth_bl
)) {
758 obj_result
.set_hinfo_inconsistency();
759 errorstream
<< "hinfo inconsistent ";
763 uint64_t oi_size
= be_get_ondisk_size(auth_oi
.size
);
764 if (oi_size
!= candidate
.size
) {
768 errorstream
<< "size " << candidate
.size
769 << " != size " << oi_size
770 << " from auth oi " << auth_oi
;
771 shard_result
.set_size_mismatch_info();
773 if (auth
.size
!= candidate
.size
) {
777 errorstream
<< "size " << candidate
.size
778 << " != size " << auth
.size
779 << " from shard " << auth_shard
;
780 obj_result
.set_size_mismatch();
782 // If the replica is too large and we didn't already count it for this object
784 if (candidate
.size
> cct
->_conf
->osd_max_object_size
785 && !obj_result
.has_size_too_large()) {
789 errorstream
<< "size " << candidate
.size
790 << " > " << cct
->_conf
->osd_max_object_size
792 obj_result
.set_size_too_large();
794 for (map
<string
,bufferptr
>::const_iterator i
= auth
.attrs
.begin();
795 i
!= auth
.attrs
.end();
797 // We check system keys seperately
798 if (i
->first
== OI_ATTR
|| i
->first
[0] != '_')
800 if (!candidate
.attrs
.count(i
->first
)) {
804 errorstream
<< "attr name mismatch '" << i
->first
<< "'";
805 obj_result
.set_attr_name_mismatch();
806 } else if (candidate
.attrs
.find(i
->first
)->second
.cmp(i
->second
)) {
810 errorstream
<< "attr value mismatch '" << i
->first
<< "'";
811 obj_result
.set_attr_value_mismatch();
814 for (map
<string
,bufferptr
>::const_iterator i
= candidate
.attrs
.begin();
815 i
!= candidate
.attrs
.end();
817 // We check system keys seperately
818 if (i
->first
== OI_ATTR
|| i
->first
[0] != '_')
820 if (!auth
.attrs
.count(i
->first
)) {
824 errorstream
<< "attr name mismatch '" << i
->first
<< "'";
825 obj_result
.set_attr_name_mismatch();
828 return error
== FOUND_ERROR
;
831 static int dcount(const object_info_t
&oi
)
834 if (oi
.is_data_digest())
836 if (oi
.is_omap_digest())
841 map
<pg_shard_t
, ScrubMap
*>::const_iterator
842 PGBackend::be_select_auth_object(
843 const hobject_t
&obj
,
844 const map
<pg_shard_t
,ScrubMap
*> &maps
,
845 object_info_t
*auth_oi
,
846 map
<pg_shard_t
, shard_info_wrapper
> &shard_map
,
849 ostream
&errorstream
)
851 eversion_t auth_version
;
853 // Create list of shards with primary first so it will be auth copy all
854 // other things being equal.
855 list
<pg_shard_t
> shards
;
856 for (map
<pg_shard_t
, ScrubMap
*>::const_iterator j
= maps
.begin();
859 if (j
->first
== get_parent()->whoami_shard())
861 shards
.push_back(j
->first
);
863 shards
.push_front(get_parent()->whoami_shard());
865 map
<pg_shard_t
, ScrubMap
*>::const_iterator auth
= maps
.end();
867 for (auto &l
: shards
) {
868 ostringstream shard_errorstream
;
870 map
<pg_shard_t
, ScrubMap
*>::const_iterator j
= maps
.find(l
);
871 map
<hobject_t
, ScrubMap::object
>::iterator i
=
872 j
->second
->objects
.find(obj
);
873 if (i
== j
->second
->objects
.end()) {
876 auto& shard_info
= shard_map
[j
->first
];
877 if (j
->first
== get_parent()->whoami_shard())
878 shard_info
.primary
= true;
879 if (i
->second
.read_error
) {
880 shard_info
.set_read_error();
882 shard_errorstream
<< ", ";
884 shard_errorstream
<< "candidate had a read error";
886 if (i
->second
.ec_hash_mismatch
) {
887 shard_info
.set_ec_hash_mismatch();
889 shard_errorstream
<< ", ";
891 shard_errorstream
<< "candidate had an ec hash mismatch";
893 if (i
->second
.ec_size_mismatch
) {
894 shard_info
.set_ec_size_mismatch();
896 shard_errorstream
<< ", ";
898 shard_errorstream
<< "candidate had an ec size mismatch";
903 map
<string
, bufferptr
>::iterator k
;
905 bufferlist ss_bl
, hk_bl
;
907 if (i
->second
.stat_error
) {
908 shard_info
.set_stat_error();
910 shard_errorstream
<< ", ";
912 shard_errorstream
<< "candidate had a stat error";
913 // With stat_error no further checking
914 // We don't need to also see a missing_object_info_attr
918 // We won't pick an auth copy if the snapset is missing or won't decode.
919 ceph_assert(!obj
.is_snapdir());
921 k
= i
->second
.attrs
.find(SS_ATTR
);
922 if (k
== i
->second
.attrs
.end()) {
923 shard_info
.set_snapset_missing();
925 shard_errorstream
<< ", ";
927 shard_errorstream
<< "candidate had a missing snapset key";
929 ss_bl
.push_back(k
->second
);
931 auto bliter
= ss_bl
.cbegin();
934 // invalid snapset, probably corrupt
935 shard_info
.set_snapset_corrupted();
937 shard_errorstream
<< ", ";
939 shard_errorstream
<< "candidate had a corrupt snapset";
944 if (parent
->get_pool().is_erasure()) {
946 k
= i
->second
.attrs
.find(ECUtil::get_hinfo_key());
947 if (k
== i
->second
.attrs
.end()) {
948 shard_info
.set_hinfo_missing();
950 shard_errorstream
<< ", ";
952 shard_errorstream
<< "candidate had a missing hinfo key";
954 hk_bl
.push_back(k
->second
);
956 auto bliter
= hk_bl
.cbegin();
959 // invalid snapset, probably corrupt
960 shard_info
.set_hinfo_corrupted();
962 shard_errorstream
<< ", ";
964 shard_errorstream
<< "candidate had a corrupt hinfo";
969 k
= i
->second
.attrs
.find(OI_ATTR
);
970 if (k
== i
->second
.attrs
.end()) {
971 // no object info on object, probably corrupt
972 shard_info
.set_info_missing();
974 shard_errorstream
<< ", ";
976 shard_errorstream
<< "candidate had a missing info key";
979 bl
.push_back(k
->second
);
981 auto bliter
= bl
.cbegin();
984 // invalid object info, probably corrupt
985 shard_info
.set_info_corrupted();
987 shard_errorstream
<< ", ";
989 shard_errorstream
<< "candidate had a corrupt info";
993 // This is automatically corrected in PG::_repair_oinfo_oid()
994 ceph_assert(oi
.soid
== obj
);
996 if (i
->second
.size
!= be_get_ondisk_size(oi
.size
)) {
997 shard_info
.set_obj_size_info_mismatch();
999 shard_errorstream
<< ", ";
1001 shard_errorstream
<< "candidate size " << i
->second
.size
<< " info size "
1002 << oi
.size
<< " mismatch";
1005 // digest_match will only be true if computed digests are the same
1006 if (auth_version
!= eversion_t()
1007 && auth
->second
->objects
[obj
].digest_present
1008 && i
->second
.digest_present
1009 && auth
->second
->objects
[obj
].digest
!= i
->second
.digest
) {
1010 digest_match
= false;
1011 dout(10) << __func__
<< " digest_match = false, " << obj
<< " data_digest 0x" << std::hex
<< i
->second
.digest
1012 << " != data_digest 0x" << auth
->second
->objects
[obj
].digest
<< std::dec
1016 // Don't use this particular shard due to previous errors
1017 // XXX: For now we can't pick one shard for repair and another's object info or snapset
1018 if (shard_info
.errors
)
1021 if (auth_version
== eversion_t() || oi
.version
> auth_version
||
1022 (oi
.version
== auth_version
&& dcount(oi
) > dcount(*auth_oi
))) {
1025 auth_version
= oi
.version
;
1030 errorstream
<< pgid
.pgid
<< " shard " << l
<< " soid " << obj
1031 << " : " << shard_errorstream
.str() << "\n";
1032 // Keep scanning other shards
1034 dout(10) << __func__
<< ": selecting osd " << auth
->first
1035 << " for obj " << obj
1036 << " with oi " << *auth_oi
1041 void PGBackend::be_compare_scrubmaps(
1042 const map
<pg_shard_t
,ScrubMap
*> &maps
,
1043 const set
<hobject_t
> &master_set
,
1045 map
<hobject_t
, set
<pg_shard_t
>> &missing
,
1046 map
<hobject_t
, set
<pg_shard_t
>> &inconsistent
,
1047 map
<hobject_t
, list
<pg_shard_t
>> &authoritative
,
1048 map
<hobject_t
, pair
<std::optional
<uint32_t>,
1049 std::optional
<uint32_t>>> &missing_digest
,
1050 int &shallow_errors
, int &deep_errors
,
1051 Scrub::Store
*store
,
1053 const vector
<int> &acting
,
1054 ostream
&errorstream
)
1056 utime_t now
= ceph_clock_now();
1058 // Check maps against master set and each other
1059 for (set
<hobject_t
>::const_iterator k
= master_set
.begin();
1060 k
!= master_set
.end();
1062 object_info_t auth_oi
;
1063 map
<pg_shard_t
, shard_info_wrapper
> shard_map
;
1065 inconsistent_obj_wrapper object_error
{*k
};
1068 map
<pg_shard_t
, ScrubMap
*>::const_iterator auth
=
1069 be_select_auth_object(*k
, maps
, &auth_oi
, shard_map
, digest_match
,
1072 list
<pg_shard_t
> auth_list
;
1073 set
<pg_shard_t
> object_errors
;
1074 if (auth
== maps
.end()) {
1075 object_error
.set_version(0);
1076 object_error
.set_auth_missing(*k
, maps
, shard_map
, shallow_errors
,
1077 deep_errors
, get_parent()->whoami_shard());
1078 if (object_error
.has_deep_errors())
1080 else if (object_error
.has_shallow_errors())
1082 store
->add_object_error(k
->pool
, object_error
);
1083 errorstream
<< pgid
.pgid
<< " soid " << *k
1084 << " : failed to pick suitable object info\n";
1087 object_error
.set_version(auth_oi
.user_version
);
1088 ScrubMap::object
& auth_object
= auth
->second
->objects
[*k
];
1089 set
<pg_shard_t
> cur_missing
;
1090 set
<pg_shard_t
> cur_inconsistent
;
1091 bool fix_digest
= false;
1093 for (auto j
= maps
.cbegin(); j
!= maps
.cend(); ++j
) {
1095 shard_map
[auth
->first
].selected_oi
= true;
1096 if (j
->second
->objects
.count(*k
)) {
1097 shard_map
[j
->first
].set_object(j
->second
->objects
[*k
]);
1100 bool found
= be_compare_scrub_objects(auth
->first
,
1103 j
->second
->objects
[*k
],
1104 shard_map
[j
->first
],
1109 dout(20) << __func__
<< (repair
? " repair " : " ") << (parent
->get_pool().is_replicated() ? "replicated " : "")
1110 << (j
== auth
? "auth" : "") << "shards " << shard_map
.size() << (digest_match
? " digest_match " : " ")
1111 << (shard_map
[j
->first
].only_data_digest_mismatch_info() ? "'info mismatch info'" : "")
1113 // If all replicas match, but they don't match object_info we can
1114 // repair it by using missing_digest mechanism
1115 if (repair
&& parent
->get_pool().is_replicated() && j
== auth
&& shard_map
.size() > 1
1116 && digest_match
&& shard_map
[j
->first
].only_data_digest_mismatch_info()
1117 && auth_object
.digest_present
) {
1118 // Set in missing_digests
1121 shard_map
[j
->first
].clear_data_digest_mismatch_info();
1122 errorstream
<< pgid
<< " soid " << *k
<< " : repairing object info data_digest" << "\n";
1124 // Some errors might have already been set in be_select_auth_object()
1125 if (shard_map
[j
->first
].errors
!= 0) {
1126 cur_inconsistent
.insert(j
->first
);
1127 if (shard_map
[j
->first
].has_deep_errors())
1131 // Only true if be_compare_scrub_objects() found errors and put something
1134 errorstream
<< pgid
<< " shard " << j
->first
<< " soid " << *k
1135 << " : " << ss
.str() << "\n";
1137 // Track possible shard to use as authoritative, if needed
1138 // There are errors, without identifying the shard
1139 object_errors
.insert(j
->first
);
1140 errorstream
<< pgid
<< " soid " << *k
<< " : " << ss
.str() << "\n";
1142 // XXX: The auth shard might get here that we don't know
1143 // that it has the "correct" data.
1144 auth_list
.push_back(j
->first
);
1147 cur_missing
.insert(j
->first
);
1148 shard_map
[j
->first
].set_missing();
1149 shard_map
[j
->first
].primary
= (j
->first
== get_parent()->whoami_shard());
1150 // Can't have any other errors if there is no information available
1152 errorstream
<< pgid
<< " shard " << j
->first
<< " " << *k
<< " : missing\n";
1154 object_error
.add_shard(j
->first
, shard_map
[j
->first
]);
1157 if (auth_list
.empty()) {
1158 if (object_errors
.empty()) {
1159 errorstream
<< pgid
.pgid
<< " soid " << *k
1160 << " : failed to pick suitable auth object\n";
1163 // Object errors exist and nothing in auth_list
1164 // Prefer the auth shard otherwise take first from list.
1166 if (object_errors
.count(auth
->first
)) {
1167 shard
= auth
->first
;
1169 shard
= *(object_errors
.begin());
1171 auth_list
.push_back(shard
);
1172 object_errors
.erase(shard
);
1174 // At this point auth_list is populated, so we add the object errors shards
1176 cur_inconsistent
.insert(object_errors
.begin(), object_errors
.end());
1177 if (!cur_missing
.empty()) {
1178 missing
[*k
] = cur_missing
;
1180 if (!cur_inconsistent
.empty()) {
1181 inconsistent
[*k
] = cur_inconsistent
;
1185 std::optional
<uint32_t> data_digest
, omap_digest
;
1186 ceph_assert(auth_object
.digest_present
);
1187 data_digest
= auth_object
.digest
;
1188 if (auth_object
.omap_digest_present
) {
1189 omap_digest
= auth_object
.omap_digest
;
1191 missing_digest
[*k
] = make_pair(data_digest
, omap_digest
);
1193 if (!cur_inconsistent
.empty() || !cur_missing
.empty()) {
1194 authoritative
[*k
] = auth_list
;
1195 } else if (!fix_digest
&& parent
->get_pool().is_replicated()) {
1202 if (auth_object
.digest_present
&& !auth_oi
.is_data_digest()) {
1203 dout(20) << __func__
<< " missing data digest on " << *k
<< dendl
;
1206 if (auth_object
.omap_digest_present
&& !auth_oi
.is_omap_digest()) {
1207 dout(20) << __func__
<< " missing omap digest on " << *k
<< dendl
;
1211 // recorded digest != actual digest?
1212 if (auth_oi
.is_data_digest() && auth_object
.digest_present
&&
1213 auth_oi
.data_digest
!= auth_object
.digest
) {
1214 ceph_assert(shard_map
[auth
->first
].has_data_digest_mismatch_info());
1215 errorstream
<< pgid
<< " recorded data digest 0x"
1216 << std::hex
<< auth_oi
.data_digest
<< " != on disk 0x"
1217 << auth_object
.digest
<< std::dec
<< " on " << auth_oi
.soid
1222 if (auth_oi
.is_omap_digest() && auth_object
.omap_digest_present
&&
1223 auth_oi
.omap_digest
!= auth_object
.omap_digest
) {
1224 ceph_assert(shard_map
[auth
->first
].has_omap_digest_mismatch_info());
1225 errorstream
<< pgid
<< " recorded omap digest 0x"
1226 << std::hex
<< auth_oi
.omap_digest
<< " != on disk 0x"
1227 << auth_object
.omap_digest
<< std::dec
1228 << " on " << auth_oi
.soid
<< "\n";
1234 utime_t age
= now
- auth_oi
.local_mtime
;
1235 if (update
== FORCE
||
1236 age
> cct
->_conf
->osd_deep_scrub_update_digest_min_age
) {
1237 std::optional
<uint32_t> data_digest
, omap_digest
;
1238 if (auth_object
.digest_present
) {
1239 data_digest
= auth_object
.digest
;
1240 dout(20) << __func__
<< " will update data digest on " << *k
<< dendl
;
1242 if (auth_object
.omap_digest_present
) {
1243 omap_digest
= auth_object
.omap_digest
;
1244 dout(20) << __func__
<< " will update omap digest on " << *k
<< dendl
;
1246 missing_digest
[*k
] = make_pair(data_digest
, omap_digest
);
1248 dout(20) << __func__
<< " missing digest but age " << age
1249 << " < " << cct
->_conf
->osd_deep_scrub_update_digest_min_age
1250 << " on " << *k
<< dendl
;
1255 if (object_error
.has_deep_errors())
1257 else if (object_error
.has_shallow_errors())
1259 if (object_error
.errors
|| object_error
.union_shards
.errors
) {
1260 store
->add_object_error(k
->pool
, object_error
);
1265 void PGBackend::be_omap_checks(const map
<pg_shard_t
,ScrubMap
*> &maps
,
1266 const set
<hobject_t
> &master_set
,
1267 omap_stat_t
& omap_stats
,
1268 ostream
&warnstream
) const
1270 bool needs_omap_check
= false;
1271 for (const auto& map
: maps
) {
1272 if (map
.second
->has_large_omap_object_errors
|| map
.second
->has_omap_keys
) {
1273 needs_omap_check
= true;
1278 if (!needs_omap_check
) {
1279 return; // Nothing to do
1282 // Iterate through objects and update omap stats
1283 for (const auto& k
: master_set
) {
1284 for (const auto& map
: maps
) {
1285 if (map
.first
!= get_parent()->primary_shard()) {
1286 // Only set omap stats for the primary
1289 auto it
= map
.second
->objects
.find(k
);
1290 if (it
== map
.second
->objects
.end())
1292 ScrubMap::object
& obj
= it
->second
;
1293 omap_stats
.omap_bytes
+= obj
.object_omap_bytes
;
1294 omap_stats
.omap_keys
+= obj
.object_omap_keys
;
1295 if (obj
.large_omap_object_found
) {
1297 auto osdmap
= get_osdmap();
1298 osdmap
->map_to_pg(k
.pool
, k
.oid
.name
, k
.get_key(), k
.nspace
, &pg
);
1299 pg_t mpg
= osdmap
->raw_pg_to_pg(pg
);
1300 omap_stats
.large_omap_objects
++;
1301 warnstream
<< "Large omap object found. Object: " << k
1302 << " PG: " << pg
<< " (" << mpg
<< ")"
1303 << " Key count: " << obj
.large_omap_object_key_count
1304 << " Size (bytes): " << obj
.large_omap_object_value_size