1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 * Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
9 * Author: Loic Dachary <loic@dachary.org>
11 * This is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License version 2.1, as published by the Free Software
14 * Foundation. See file COPYING.
18 #include "boost/tuple/tuple.hpp"
19 #include "boost/intrusive_ptr.hpp"
21 #include "PrimaryLogPG.h"
23 #include "OpRequest.h"
24 #include "ScrubStore.h"
26 #include "objclass/objclass.h"
28 #include "common/errno.h"
29 #include "common/scrub_types.h"
30 #include "common/perf_counters.h"
32 #include "messages/MOSDOp.h"
33 #include "messages/MOSDBackoff.h"
34 #include "messages/MOSDSubOp.h"
35 #include "messages/MOSDSubOpReply.h"
36 #include "messages/MOSDPGTrim.h"
37 #include "messages/MOSDPGScan.h"
38 #include "messages/MOSDRepScrub.h"
39 #include "messages/MOSDPGBackfill.h"
40 #include "messages/MOSDPGBackfillRemove.h"
41 #include "messages/MOSDPGUpdateLogMissing.h"
42 #include "messages/MOSDPGUpdateLogMissingReply.h"
43 #include "messages/MCommandReply.h"
44 #include "messages/MOSDScrubReserve.h"
45 #include "mds/inode_backtrace.h" // Ugh
46 #include "common/EventTrace.h"
48 #include "common/config.h"
49 #include "include/compat.h"
50 #include "mon/MonClient.h"
51 #include "osdc/Objecter.h"
52 #include "json_spirit/json_spirit_value.h"
53 #include "json_spirit/json_spirit_reader.h"
54 #include "include/assert.h" // json_spirit clobbers it
55 #include "include/rados/rados_types.hpp"
58 #include "tracing/osd.h"
60 #define tracepoint(...)
63 #define dout_context cct
64 #define dout_subsys ceph_subsys_osd
65 #define DOUT_PREFIX_ARGS this, osd->whoami, get_osdmap()
67 #define dout_prefix _prefix(_dout, this)
69 static ostream
& _prefix(std::ostream
*_dout
, T
*pg
) {
70 return *_dout
<< pg
->gen_prefix();
79 MEMPOOL_DEFINE_OBJECT_FACTORY(PrimaryLogPG
, replicatedpg
, osd
);
81 PGLSFilter::PGLSFilter() : cct(nullptr)
85 PGLSFilter::~PGLSFilter()
89 struct PrimaryLogPG::C_OSD_OnApplied
: Context
{
97 : pg(pg
), epoch(epoch
), v(v
) {}
98 void finish(int) override
{
100 if (!pg
->pg_has_reset_since(epoch
))
107 * The CopyCallback class defines an interface for completions to the
108 * copy_start code. Users of the copy infrastructure must implement
109 * one and give an instance of the class to start_copy.
111 * The implementer is responsible for making sure that the CopyCallback
112 * can associate itself with the correct copy operation.
114 class PrimaryLogPG::CopyCallback
: public GenContext
<CopyCallbackResults
> {
118 * results.get<0>() is the return code: 0 for success; -ECANCELED if
119 * the operation was cancelled by the local OSD; -errno for other issues.
120 * results.get<1>() is a pointer to a CopyResults object, which you are
121 * responsible for deleting.
123 void finish(CopyCallbackResults results_
) override
= 0;
126 /// Provide the final size of the copied object to the CopyCallback
127 ~CopyCallback() override
{}
130 template <typename T
>
131 class PrimaryLogPG::BlessedGenContext
: public GenContext
<T
> {
133 unique_ptr
<GenContext
<T
>> c
;
136 BlessedGenContext(PrimaryLogPG
*pg
, GenContext
<T
> *c
, epoch_t e
)
137 : pg(pg
), c(c
), e(e
) {}
138 void finish(T t
) override
{
140 if (pg
->pg_has_reset_since(e
))
143 c
.release()->complete(t
);
148 GenContext
<ThreadPool::TPHandle
&> *PrimaryLogPG::bless_gencontext(
149 GenContext
<ThreadPool::TPHandle
&> *c
) {
150 return new BlessedGenContext
<ThreadPool::TPHandle
&>(
151 this, c
, get_osdmap()->get_epoch());
154 class PrimaryLogPG::BlessedContext
: public Context
{
156 unique_ptr
<Context
> c
;
159 BlessedContext(PrimaryLogPG
*pg
, Context
*c
, epoch_t e
)
160 : pg(pg
), c(c
), e(e
) {}
161 void finish(int r
) override
{
163 if (pg
->pg_has_reset_since(e
))
166 c
.release()->complete(r
);
172 Context
*PrimaryLogPG::bless_context(Context
*c
) {
173 return new BlessedContext(this, c
, get_osdmap()->get_epoch());
176 class PrimaryLogPG::C_PG_ObjectContext
: public Context
{
180 C_PG_ObjectContext(PrimaryLogPG
*p
, ObjectContext
*o
) :
182 void finish(int r
) override
{
183 pg
->object_context_destructor_callback(obc
);
187 class PrimaryLogPG::C_OSD_OndiskWriteUnlock
: public Context
{
188 ObjectContextRef obc
, obc2
, obc3
;
190 C_OSD_OndiskWriteUnlock(
192 ObjectContextRef o2
= ObjectContextRef(),
193 ObjectContextRef o3
= ObjectContextRef()) : obc(o
), obc2(o2
), obc3(o3
) {}
194 void finish(int r
) override
{
195 obc
->ondisk_write_unlock();
197 obc2
->ondisk_write_unlock();
199 obc3
->ondisk_write_unlock();
203 struct OnReadComplete
: public Context
{
205 PrimaryLogPG::OpContext
*opcontext
;
208 PrimaryLogPG::OpContext
*ctx
) : pg(pg
), opcontext(ctx
) {}
209 void finish(int r
) override
{
210 opcontext
->finish_read(pg
);
212 ~OnReadComplete() override
{}
215 class PrimaryLogPG::C_OSD_AppliedRecoveredObject
: public Context
{
217 ObjectContextRef obc
;
219 C_OSD_AppliedRecoveredObject(PrimaryLogPG
*p
, ObjectContextRef o
) :
221 void finish(int r
) override
{
222 pg
->_applied_recovered_object(obc
);
226 class PrimaryLogPG::C_OSD_CommittedPushedObject
: public Context
{
229 eversion_t last_complete
;
231 C_OSD_CommittedPushedObject(
232 PrimaryLogPG
*p
, epoch_t epoch
, eversion_t lc
) :
233 pg(p
), epoch(epoch
), last_complete(lc
) {
235 void finish(int r
) override
{
236 pg
->_committed_pushed_object(epoch
, last_complete
);
240 class PrimaryLogPG::C_OSD_AppliedRecoveredObjectReplica
: public Context
{
243 explicit C_OSD_AppliedRecoveredObjectReplica(PrimaryLogPG
*p
) :
245 void finish(int r
) override
{
246 pg
->_applied_recovered_object_replica();
251 void PrimaryLogPG::OpContext::start_async_reads(PrimaryLogPG
*pg
)
254 list
<pair
<boost::tuple
<uint64_t, uint64_t, unsigned>,
255 pair
<bufferlist
*, Context
*> > > in
;
256 in
.swap(pending_async_reads
);
257 pg
->pgbackend
->objects_read_async(
260 new OnReadComplete(pg
, this), pg
->get_pool().fast_read
);
262 void PrimaryLogPG::OpContext::finish_read(PrimaryLogPG
*pg
)
264 assert(inflightreads
> 0);
266 if (async_reads_complete()) {
267 assert(pg
->in_progress_async_reads
.size());
268 assert(pg
->in_progress_async_reads
.front().second
== this);
269 pg
->in_progress_async_reads
.pop_front();
271 // Restart the op context now that all reads have been
272 // completed. Read failures will be handled by the op finisher
273 pg
->execute_ctx(this);
277 class CopyFromCallback
: public PrimaryLogPG::CopyCallback
{
279 PrimaryLogPG::CopyResults
*results
= nullptr;
280 PrimaryLogPG::OpContext
*ctx
;
283 CopyFromCallback(PrimaryLogPG::OpContext
*ctx
, OSDOp
&osd_op
)
284 : ctx(ctx
), osd_op(osd_op
) {
286 ~CopyFromCallback() override
{}
288 void finish(PrimaryLogPG::CopyCallbackResults results_
) override
{
289 results
= results_
.get
<1>();
290 int r
= results_
.get
<0>();
292 // for finish_copyfrom
293 ctx
->user_at_version
= results
->user_version
;
296 ctx
->pg
->execute_ctx(ctx
);
298 if (r
!= -ECANCELED
) { // on cancel just toss it out; client resends
300 ctx
->pg
->osd
->reply_op_error(ctx
->op
, r
);
301 } else if (results
->should_requeue
) {
303 ctx
->pg
->requeue_op(ctx
->op
);
305 ctx
->pg
->close_op_ctx(ctx
);
309 bool is_temp_obj_used() {
310 return results
->started_temp_obj
;
312 uint64_t get_data_size() {
313 return results
->object_size
;
317 struct CopyFromFinisher
: public PrimaryLogPG::OpFinisher
{
318 CopyFromCallback
*copy_from_callback
;
320 CopyFromFinisher(CopyFromCallback
*copy_from_callback
)
321 : copy_from_callback(copy_from_callback
) {
324 int execute() override
{
325 // instance will be destructed after this method completes
326 copy_from_callback
->ctx
->pg
->finish_copyfrom(copy_from_callback
);
331 // ======================
332 // PGBackend::Listener
334 void PrimaryLogPG::on_local_recover(
335 const hobject_t
&hoid
,
336 const ObjectRecoveryInfo
&_recovery_info
,
337 ObjectContextRef obc
,
339 ObjectStore::Transaction
*t
342 dout(10) << __func__
<< ": " << hoid
<< dendl
;
344 ObjectRecoveryInfo
recovery_info(_recovery_info
);
345 clear_object_snap_mapping(t
, hoid
);
346 if (!is_delete
&& recovery_info
.soid
.is_snap()) {
347 OSDriver::OSTransaction
_t(osdriver
.get_transaction(t
));
349 dout(20) << " snapset " << recovery_info
.ss
350 << " legacy_snaps " << recovery_info
.oi
.legacy_snaps
<< dendl
;
351 if (recovery_info
.ss
.is_legacy() ||
352 recovery_info
.ss
.seq
== 0 /* jewel osd doesn't populate this */) {
353 assert(recovery_info
.oi
.legacy_snaps
.size());
354 snaps
.insert(recovery_info
.oi
.legacy_snaps
.begin(),
355 recovery_info
.oi
.legacy_snaps
.end());
357 auto p
= recovery_info
.ss
.clone_snaps
.find(hoid
.snap
);
358 assert(p
!= recovery_info
.ss
.clone_snaps
.end()); // hmm, should we warn?
359 snaps
.insert(p
->second
.begin(), p
->second
.end());
361 dout(20) << " snaps " << snaps
<< dendl
;
367 if (!is_delete
&& pg_log
.get_missing().is_missing(recovery_info
.soid
) &&
368 pg_log
.get_missing().get_items().find(recovery_info
.soid
)->second
.need
> recovery_info
.version
) {
369 assert(is_primary());
370 const pg_log_entry_t
*latest
= pg_log
.get_log().objects
.find(recovery_info
.soid
)->second
;
371 if (latest
->op
== pg_log_entry_t::LOST_REVERT
&&
372 latest
->reverting_to
== recovery_info
.version
) {
373 dout(10) << " got old revert version " << recovery_info
.version
374 << " for " << *latest
<< dendl
;
375 recovery_info
.version
= latest
->version
;
376 // update the attr to the revert event version
377 recovery_info
.oi
.prior_version
= recovery_info
.oi
.version
;
378 recovery_info
.oi
.version
= latest
->version
;
380 ::encode(recovery_info
.oi
, bl
,
381 get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
382 assert(!pool
.info
.require_rollback());
383 t
->setattr(coll
, ghobject_t(recovery_info
.soid
), OI_ATTR
, bl
);
385 obc
->attr_cache
[OI_ATTR
] = bl
;
389 // keep track of active pushes for scrub
392 if (recovery_info
.version
> pg_log
.get_can_rollback_to()) {
393 /* This can only happen during a repair, and even then, it would
394 * be one heck of a race. If we are repairing the object, the
395 * write in question must be fully committed, so it's not valid
396 * to roll it back anyway (and we'll be rolled forward shortly
398 PGLogEntryHandler h
{this, t
};
399 pg_log
.roll_forward_to(recovery_info
.version
, &h
);
401 recover_got(recovery_info
.soid
, recovery_info
.version
);
405 obc
->obs
.exists
= true;
406 obc
->ondisk_write_lock();
408 bool got
= obc
->get_recovery_read();
411 assert(recovering
.count(obc
->obs
.oi
.soid
));
412 recovering
[obc
->obs
.oi
.soid
] = obc
;
413 obc
->obs
.oi
= recovery_info
.oi
; // may have been updated above
414 t
->register_on_applied_sync(new C_OSD_OndiskWriteUnlock(obc
));
417 t
->register_on_applied(new C_OSD_AppliedRecoveredObject(this, obc
));
419 publish_stats_to_osd();
420 assert(missing_loc
.needs_recovery(hoid
));
422 missing_loc
.add_location(hoid
, pg_whoami
);
423 release_backoffs(hoid
);
424 if (!is_unreadable_object(hoid
)) {
425 auto unreadable_object_entry
= waiting_for_unreadable_object
.find(hoid
);
426 if (unreadable_object_entry
!= waiting_for_unreadable_object
.end()) {
427 dout(20) << " kicking unreadable waiters on " << hoid
<< dendl
;
428 requeue_ops(unreadable_object_entry
->second
);
429 waiting_for_unreadable_object
.erase(unreadable_object_entry
);
433 t
->register_on_applied(
434 new C_OSD_AppliedRecoveredObjectReplica(this));
438 t
->register_on_commit(
439 new C_OSD_CommittedPushedObject(
441 get_osdmap()->get_epoch(),
442 info
.last_complete
));
449 void PrimaryLogPG::on_global_recover(
450 const hobject_t
&soid
,
451 const object_stat_sum_t
&stat_diff
,
454 info
.stats
.stats
.sum
.add(stat_diff
);
455 missing_loc
.recovered(soid
);
456 publish_stats_to_osd();
457 dout(10) << "pushed " << soid
<< " to all replicas" << dendl
;
458 map
<hobject_t
, ObjectContextRef
>::iterator i
= recovering
.find(soid
);
459 assert(i
!= recovering
.end());
462 // recover missing won't have had an obc, but it gets filled in
463 // during on_local_recover
465 list
<OpRequestRef
> requeue_list
;
466 i
->second
->drop_recovery_read(&requeue_list
);
467 requeue_ops(requeue_list
);
470 backfills_in_flight
.erase(soid
);
473 finish_recovery_op(soid
);
474 release_backoffs(soid
);
475 auto degraded_object_entry
= waiting_for_degraded_object
.find(soid
);
476 if (degraded_object_entry
!= waiting_for_degraded_object
.end()) {
477 dout(20) << " kicking degraded waiters on " << soid
<< dendl
;
478 requeue_ops(degraded_object_entry
->second
);
479 waiting_for_degraded_object
.erase(degraded_object_entry
);
481 auto unreadable_object_entry
= waiting_for_unreadable_object
.find(soid
);
482 if (unreadable_object_entry
!= waiting_for_unreadable_object
.end()) {
483 dout(20) << " kicking unreadable waiters on " << soid
<< dendl
;
484 requeue_ops(unreadable_object_entry
->second
);
485 waiting_for_unreadable_object
.erase(unreadable_object_entry
);
487 finish_degraded_object(soid
);
490 void PrimaryLogPG::on_peer_recover(
492 const hobject_t
&soid
,
493 const ObjectRecoveryInfo
&recovery_info
)
495 publish_stats_to_osd();
497 peer_missing
[peer
].got(soid
, recovery_info
.version
);
500 void PrimaryLogPG::begin_peer_recover(
502 const hobject_t soid
)
504 peer_missing
[peer
].revise_have(soid
, eversion_t());
507 void PrimaryLogPG::schedule_recovery_work(
508 GenContext
<ThreadPool::TPHandle
&> *c
)
510 osd
->recovery_gen_wq
.queue(c
);
513 void PrimaryLogPG::send_message_osd_cluster(
514 int peer
, Message
*m
, epoch_t from_epoch
)
516 osd
->send_message_osd_cluster(peer
, m
, from_epoch
);
519 void PrimaryLogPG::send_message_osd_cluster(
520 Message
*m
, Connection
*con
)
522 osd
->send_message_osd_cluster(m
, con
);
525 void PrimaryLogPG::send_message_osd_cluster(
526 Message
*m
, const ConnectionRef
& con
)
528 osd
->send_message_osd_cluster(m
, con
);
531 void PrimaryLogPG::on_primary_error(
532 const hobject_t
&oid
,
535 dout(0) << __func__
<< ": oid " << oid
<< " version " << v
<< dendl
;
537 primary_error(oid
, v
);
538 backfills_in_flight
.erase(oid
);
539 missing_loc
.add_missing(oid
, v
, eversion_t());
542 ConnectionRef
PrimaryLogPG::get_con_osd_cluster(
543 int peer
, epoch_t from_epoch
)
545 return osd
->get_con_osd_cluster(peer
, from_epoch
);
548 PerfCounters
*PrimaryLogPG::get_logger()
554 // ====================
557 bool PrimaryLogPG::is_missing_object(const hobject_t
& soid
) const
559 return pg_log
.get_missing().get_items().count(soid
);
562 void PrimaryLogPG::maybe_kick_recovery(
563 const hobject_t
&soid
)
566 if (!missing_loc
.needs_recovery(soid
, &v
))
569 map
<hobject_t
, ObjectContextRef
>::const_iterator p
= recovering
.find(soid
);
570 if (p
!= recovering
.end()) {
571 dout(7) << "object " << soid
<< " v " << v
<< ", already recovering." << dendl
;
572 } else if (missing_loc
.is_unfound(soid
)) {
573 dout(7) << "object " << soid
<< " v " << v
<< ", is unfound." << dendl
;
575 dout(7) << "object " << soid
<< " v " << v
<< ", recovering." << dendl
;
576 PGBackend::RecoveryHandle
*h
= pgbackend
->open_recovery_op();
577 if (is_missing_object(soid
)) {
578 recover_missing(soid
, v
, cct
->_conf
->osd_client_op_priority
, h
);
579 } else if (missing_loc
.is_deleted(soid
)) {
580 prep_object_replica_deletes(soid
, v
, h
);
582 prep_object_replica_pushes(soid
, v
, h
);
584 pgbackend
->run_recovery_op(h
, cct
->_conf
->osd_client_op_priority
);
588 void PrimaryLogPG::wait_for_unreadable_object(
589 const hobject_t
& soid
, OpRequestRef op
)
591 assert(is_unreadable_object(soid
));
592 maybe_kick_recovery(soid
);
593 waiting_for_unreadable_object
[soid
].push_back(op
);
594 op
->mark_delayed("waiting for missing object");
597 bool PrimaryLogPG::is_degraded_or_backfilling_object(const hobject_t
& soid
)
599 /* The conditions below may clear (on_local_recover, before we queue
600 * the transaction) before we actually requeue the degraded waiters
601 * in on_global_recover after the transaction completes.
603 if (waiting_for_degraded_object
.count(soid
))
605 if (pg_log
.get_missing().get_items().count(soid
))
607 assert(!actingbackfill
.empty());
608 for (set
<pg_shard_t
>::iterator i
= actingbackfill
.begin();
609 i
!= actingbackfill
.end();
611 if (*i
== get_primary()) continue;
612 pg_shard_t peer
= *i
;
613 auto peer_missing_entry
= peer_missing
.find(peer
);
614 if (peer_missing_entry
!= peer_missing
.end() &&
615 peer_missing_entry
->second
.get_items().count(soid
))
618 // Object is degraded if after last_backfill AND
619 // we are backfilling it
620 if (is_backfill_targets(peer
) &&
621 peer_info
[peer
].last_backfill
<= soid
&&
622 last_backfill_started
>= soid
&&
623 backfills_in_flight
.count(soid
))
629 void PrimaryLogPG::wait_for_degraded_object(const hobject_t
& soid
, OpRequestRef op
)
631 assert(is_degraded_or_backfilling_object(soid
));
633 maybe_kick_recovery(soid
);
634 waiting_for_degraded_object
[soid
].push_back(op
);
635 op
->mark_delayed("waiting for degraded object");
638 void PrimaryLogPG::block_write_on_full_cache(
639 const hobject_t
& _oid
, OpRequestRef op
)
641 const hobject_t oid
= _oid
.get_head();
642 dout(20) << __func__
<< ": blocking object " << oid
643 << " on full cache" << dendl
;
644 objects_blocked_on_cache_full
.insert(oid
);
645 waiting_for_cache_not_full
.push_back(op
);
646 op
->mark_delayed("waiting for cache not full");
649 void PrimaryLogPG::block_for_clean(
650 const hobject_t
& oid
, OpRequestRef op
)
652 dout(20) << __func__
<< ": blocking object " << oid
653 << " on primary repair" << dendl
;
654 waiting_for_clean_to_primary_repair
.push_back(op
);
655 op
->mark_delayed("waiting for clean to repair");
658 void PrimaryLogPG::block_write_on_snap_rollback(
659 const hobject_t
& oid
, ObjectContextRef obc
, OpRequestRef op
)
661 dout(20) << __func__
<< ": blocking object " << oid
.get_head()
662 << " on snap promotion " << obc
->obs
.oi
.soid
<< dendl
;
663 // otherwise, we'd have blocked in do_op
664 assert(oid
.is_head());
665 assert(objects_blocked_on_snap_promotion
.count(oid
) == 0);
666 objects_blocked_on_snap_promotion
[oid
] = obc
;
667 wait_for_blocked_object(obc
->obs
.oi
.soid
, op
);
670 void PrimaryLogPG::block_write_on_degraded_snap(
671 const hobject_t
& snap
, OpRequestRef op
)
673 dout(20) << __func__
<< ": blocking object " << snap
.get_head()
674 << " on degraded snap " << snap
<< dendl
;
675 // otherwise, we'd have blocked in do_op
676 assert(objects_blocked_on_degraded_snap
.count(snap
.get_head()) == 0);
677 objects_blocked_on_degraded_snap
[snap
.get_head()] = snap
.snap
;
678 wait_for_degraded_object(snap
, op
);
681 bool PrimaryLogPG::maybe_await_blocked_snapset(
682 const hobject_t
&hoid
,
685 ObjectContextRef obc
;
686 obc
= object_contexts
.lookup(hoid
.get_head());
688 if (obc
->is_blocked()) {
689 wait_for_blocked_object(obc
->obs
.oi
.soid
, op
);
695 obc
= object_contexts
.lookup(hoid
.get_snapdir());
697 if (obc
->is_blocked()) {
698 wait_for_blocked_object(obc
->obs
.oi
.soid
, op
);
707 void PrimaryLogPG::wait_for_blocked_object(const hobject_t
& soid
, OpRequestRef op
)
709 dout(10) << __func__
<< " " << soid
<< " " << op
<< dendl
;
710 waiting_for_blocked_object
[soid
].push_back(op
);
711 op
->mark_delayed("waiting for blocked object");
714 void PrimaryLogPG::maybe_force_recovery()
716 // no force if not in degraded/recovery/backfill stats
717 if (!is_degraded() &&
718 !state_test(PG_STATE_RECOVERING
|
719 PG_STATE_RECOVERY_WAIT
|
721 PG_STATE_BACKFILL_WAIT
|
722 PG_STATE_BACKFILL_TOOFULL
))
725 if (pg_log
.get_log().approx_size() <
726 cct
->_conf
->osd_max_pg_log_entries
*
727 cct
->_conf
->osd_force_recovery_pg_log_entries_factor
)
730 // find the oldest missing object
731 version_t min_version
= 0;
733 if (!pg_log
.get_missing().get_items().empty()) {
734 min_version
= pg_log
.get_missing().get_rmissing().begin()->first
;
735 soid
= pg_log
.get_missing().get_rmissing().begin()->second
;
737 assert(!actingbackfill
.empty());
738 for (set
<pg_shard_t
>::iterator it
= actingbackfill
.begin();
739 it
!= actingbackfill
.end();
741 if (*it
== get_primary()) continue;
742 pg_shard_t peer
= *it
;
743 if (peer_missing
.count(peer
) &&
744 !peer_missing
[peer
].get_items().empty() &&
745 min_version
> peer_missing
[peer
].get_rmissing().begin()->first
) {
746 min_version
= peer_missing
[peer
].get_rmissing().begin()->first
;
747 soid
= peer_missing
[peer
].get_rmissing().begin()->second
;
752 if (soid
!= hobject_t())
753 maybe_kick_recovery(soid
);
756 class PGLSPlainFilter
: public PGLSFilter
{
759 int init(bufferlist::iterator
¶ms
) override
762 ::decode(xattr
, params
);
763 ::decode(val
, params
);
764 } catch (buffer::error
&e
) {
770 ~PGLSPlainFilter() override
{}
771 bool filter(const hobject_t
&obj
, bufferlist
& xattr_data
,
772 bufferlist
& outdata
) override
;
775 class PGLSParentFilter
: public PGLSFilter
{
776 inodeno_t parent_ino
;
779 PGLSParentFilter(CephContext
* cct
) : cct(cct
) {
782 int init(bufferlist::iterator
¶ms
) override
785 ::decode(parent_ino
, params
);
786 } catch (buffer::error
&e
) {
789 generic_dout(0) << "parent_ino=" << parent_ino
<< dendl
;
793 ~PGLSParentFilter() override
{}
794 bool filter(const hobject_t
&obj
, bufferlist
& xattr_data
,
795 bufferlist
& outdata
) override
;
798 bool PGLSParentFilter::filter(const hobject_t
&obj
,
799 bufferlist
& xattr_data
, bufferlist
& outdata
)
801 bufferlist::iterator iter
= xattr_data
.begin();
802 inode_backtrace_t bt
;
804 generic_dout(0) << "PGLSParentFilter::filter" << dendl
;
808 vector
<inode_backpointer_t
>::iterator vi
;
809 for (vi
= bt
.ancestors
.begin(); vi
!= bt
.ancestors
.end(); ++vi
) {
810 generic_dout(0) << "vi->dirino=" << vi
->dirino
<< " parent_ino=" << parent_ino
<< dendl
;
811 if (vi
->dirino
== parent_ino
) {
812 ::encode(*vi
, outdata
);
820 bool PGLSPlainFilter::filter(const hobject_t
&obj
,
821 bufferlist
& xattr_data
, bufferlist
& outdata
)
823 if (val
.size() != xattr_data
.length())
826 if (memcmp(val
.c_str(), xattr_data
.c_str(), val
.size()))
832 bool PrimaryLogPG::pgls_filter(PGLSFilter
*filter
, hobject_t
& sobj
, bufferlist
& outdata
)
836 // If filter has expressed an interest in an xattr, load it.
837 if (!filter
->get_xattr().empty()) {
838 int ret
= pgbackend
->objects_get_attr(
842 dout(0) << "getattr (sobj=" << sobj
<< ", attr=" << filter
->get_xattr() << ") returned " << ret
<< dendl
;
844 if (ret
!= -ENODATA
|| filter
->reject_empty_xattr()) {
850 return filter
->filter(sobj
, bl
, outdata
);
853 int PrimaryLogPG::get_pgls_filter(bufferlist::iterator
& iter
, PGLSFilter
**pfilter
)
859 ::decode(type
, iter
);
861 catch (buffer::error
& e
) {
865 if (type
.compare("parent") == 0) {
866 filter
= new PGLSParentFilter(cct
);
867 } else if (type
.compare("plain") == 0) {
868 filter
= new PGLSPlainFilter();
870 std::size_t dot
= type
.find(".");
871 if (dot
== std::string::npos
|| dot
== 0 || dot
== type
.size() - 1) {
875 const std::string class_name
= type
.substr(0, dot
);
876 const std::string filter_name
= type
.substr(dot
+ 1);
877 ClassHandler::ClassData
*cls
= NULL
;
878 int r
= osd
->class_handler
->open_class(class_name
, &cls
);
880 derr
<< "Error opening class '" << class_name
<< "': "
881 << cpp_strerror(r
) << dendl
;
882 if (r
!= -EPERM
) // propogate permission error
889 ClassHandler::ClassFilter
*class_filter
= cls
->get_filter(filter_name
);
890 if (class_filter
== NULL
) {
891 derr
<< "Error finding filter '" << filter_name
<< "' in class "
892 << class_name
<< dendl
;
895 filter
= class_filter
->fn();
897 // Object classes are obliged to return us something, but let's
898 // give an error rather than asserting out.
899 derr
<< "Buggy class " << class_name
<< " failed to construct "
900 "filter " << filter_name
<< dendl
;
906 int r
= filter
->init(iter
);
908 derr
<< "Error initializing filter " << type
<< ": "
909 << cpp_strerror(r
) << dendl
;
913 // Successfully constructed and initialized, return it.
920 // ==========================================================
922 int PrimaryLogPG::do_command(
930 const auto &missing
= pg_log
.get_missing();
934 cmd_getval(cct
, cmdmap
, "format", format
);
935 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
, "json-pretty", "json"));
938 cmd_getval(cct
, cmdmap
, "cmd", command
);
939 if (command
== "query") {
940 f
->open_object_section("pg");
941 f
->dump_string("state", pg_state_string(get_state()));
942 f
->dump_stream("snap_trimq") << snap_trimq
;
943 f
->dump_unsigned("epoch", get_osdmap()->get_epoch());
944 f
->open_array_section("up");
945 for (vector
<int>::iterator p
= up
.begin(); p
!= up
.end(); ++p
)
946 f
->dump_unsigned("osd", *p
);
948 f
->open_array_section("acting");
949 for (vector
<int>::iterator p
= acting
.begin(); p
!= acting
.end(); ++p
)
950 f
->dump_unsigned("osd", *p
);
952 if (!backfill_targets
.empty()) {
953 f
->open_array_section("backfill_targets");
954 for (set
<pg_shard_t
>::iterator p
= backfill_targets
.begin();
955 p
!= backfill_targets
.end();
957 f
->dump_stream("shard") << *p
;
960 if (!actingbackfill
.empty()) {
961 f
->open_array_section("actingbackfill");
962 for (set
<pg_shard_t
>::iterator p
= actingbackfill
.begin();
963 p
!= actingbackfill
.end();
965 f
->dump_stream("shard") << *p
;
968 f
->open_object_section("info");
969 _update_calc_stats();
973 f
->open_array_section("peer_info");
974 for (map
<pg_shard_t
, pg_info_t
>::iterator p
= peer_info
.begin();
975 p
!= peer_info
.end();
977 f
->open_object_section("info");
978 f
->dump_stream("peer") << p
->first
;
979 p
->second
.dump(f
.get());
984 f
->open_array_section("recovery_state");
985 handle_query_state(f
.get());
988 f
->open_object_section("agent_state");
990 agent_state
->dump(f
.get());
997 else if (command
== "mark_unfound_lost") {
999 cmd_getval(cct
, cmdmap
, "mulcmd", mulcmd
);
1001 if (mulcmd
== "revert") {
1002 if (pool
.info
.ec_pool()) {
1003 ss
<< "mode must be 'delete' for ec pool";
1006 mode
= pg_log_entry_t::LOST_REVERT
;
1007 } else if (mulcmd
== "delete") {
1008 mode
= pg_log_entry_t::LOST_DELETE
;
1010 ss
<< "mode must be 'revert' or 'delete'; mark not yet implemented";
1013 assert(mode
== pg_log_entry_t::LOST_REVERT
||
1014 mode
== pg_log_entry_t::LOST_DELETE
);
1016 if (!is_primary()) {
1017 ss
<< "not primary";
1021 uint64_t unfound
= missing_loc
.num_unfound();
1023 ss
<< "pg has no unfound objects";
1024 return 0; // make command idempotent
1027 if (!all_unfound_are_queried_or_lost(get_osdmap())) {
1028 ss
<< "pg has " << unfound
1029 << " unfound objects but we haven't probed all sources, not marking lost";
1033 mark_all_unfound_lost(mode
, con
, tid
);
1036 else if (command
== "list_missing") {
1039 if (cmd_getval(cct
, cmdmap
, "offset", offset_json
)) {
1040 json_spirit::Value v
;
1042 if (!json_spirit::read(offset_json
, v
))
1043 throw std::runtime_error("bad json");
1045 } catch (std::runtime_error
& e
) {
1046 ss
<< "error parsing offset: " << e
.what();
1050 f
->open_object_section("missing");
1052 f
->open_object_section("offset");
1053 offset
.dump(f
.get());
1056 f
->dump_int("num_missing", missing
.num_missing());
1057 f
->dump_int("num_unfound", get_num_unfound());
1058 const map
<hobject_t
, pg_missing_item
> &needs_recovery_map
=
1059 missing_loc
.get_needs_recovery();
1060 map
<hobject_t
, pg_missing_item
>::const_iterator p
=
1061 needs_recovery_map
.upper_bound(offset
);
1063 f
->open_array_section("objects");
1065 for (; p
!= needs_recovery_map
.end() && num
< cct
->_conf
->osd_command_max_records
; ++p
) {
1066 if (missing_loc
.is_unfound(p
->first
)) {
1067 f
->open_object_section("object");
1069 f
->open_object_section("oid");
1070 p
->first
.dump(f
.get());
1073 p
->second
.dump(f
.get()); // have, need keys
1075 f
->open_array_section("locations");
1076 for (set
<pg_shard_t
>::iterator r
=
1077 missing_loc
.get_locations(p
->first
).begin();
1078 r
!= missing_loc
.get_locations(p
->first
).end();
1080 f
->dump_stream("shard") << *r
;
1089 f
->dump_bool("more", p
!= needs_recovery_map
.end());
1095 ss
<< "unknown pg command " << prefix
;
1099 // ==========================================================
1101 void PrimaryLogPG::do_pg_op(OpRequestRef op
)
1103 // NOTE: this is non-const because we modify the OSDOp.outdata in
1105 MOSDOp
*m
= static_cast<MOSDOp
*>(op
->get_nonconst_req());
1106 assert(m
->get_type() == CEPH_MSG_OSD_OP
);
1107 dout(10) << "do_pg_op " << *m
<< dendl
;
1112 string cname
, mname
;
1113 PGLSFilter
*filter
= NULL
;
1114 bufferlist filter_out
;
1116 snapid_t snapid
= m
->get_snapid();
1118 vector
<OSDOp
> ops
= m
->ops
;
1120 for (vector
<OSDOp
>::iterator p
= ops
.begin(); p
!= ops
.end(); ++p
) {
1122 bufferlist::iterator bp
= p
->indata
.begin();
1124 case CEPH_OSD_OP_PGNLS_FILTER
:
1126 ::decode(cname
, bp
);
1127 ::decode(mname
, bp
);
1129 catch (const buffer::error
& e
) {
1130 dout(0) << "unable to decode PGLS_FILTER description in " << *m
<< dendl
;
1138 result
= get_pgls_filter(bp
, &filter
);
1146 case CEPH_OSD_OP_PGNLS
:
1147 if (snapid
!= CEPH_NOSNAP
) {
1151 if (get_osdmap()->raw_pg_to_pg(m
->get_pg()) != info
.pgid
.pgid
) {
1152 dout(10) << " pgnls pg=" << m
->get_pg()
1153 << " " << get_osdmap()->raw_pg_to_pg(m
->get_pg())
1154 << " != " << info
.pgid
<< dendl
;
1157 unsigned list_size
= MIN(cct
->_conf
->osd_max_pgls
, p
->op
.pgls
.count
);
1159 dout(10) << " pgnls pg=" << m
->get_pg() << " count " << list_size
<< dendl
;
1160 // read into a buffer
1161 vector
<hobject_t
> sentries
;
1162 pg_nls_response_t response
;
1164 ::decode(response
.handle
, bp
);
1166 catch (const buffer::error
& e
) {
1167 dout(0) << "unable to decode PGNLS handle in " << *m
<< dendl
;
1173 hobject_t lower_bound
= response
.handle
;
1174 hobject_t pg_start
= info
.pgid
.pgid
.get_hobj_start();
1175 hobject_t pg_end
= info
.pgid
.pgid
.get_hobj_end(pool
.info
.get_pg_num());
1176 dout(10) << " pgnls lower_bound " << lower_bound
1177 << " pg_end " << pg_end
<< dendl
;
1178 if (((!lower_bound
.is_max() && lower_bound
>= pg_end
) ||
1179 (lower_bound
!= hobject_t() && lower_bound
< pg_start
))) {
1180 // this should only happen with a buggy client.
1181 dout(10) << "outside of PG bounds " << pg_start
<< " .. "
1187 hobject_t current
= lower_bound
;
1189 int r
= pgbackend
->objects_list_partial(
1200 map
<hobject_t
, pg_missing_item
>::const_iterator missing_iter
=
1201 pg_log
.get_missing().get_items().lower_bound(current
);
1202 vector
<hobject_t
>::iterator ls_iter
= sentries
.begin();
1203 hobject_t _max
= hobject_t::get_max();
1205 const hobject_t
&mcand
=
1206 missing_iter
== pg_log
.get_missing().get_items().end() ?
1208 missing_iter
->first
;
1209 const hobject_t
&lcand
=
1210 ls_iter
== sentries
.end() ?
1214 hobject_t candidate
;
1215 if (mcand
== lcand
) {
1217 if (!mcand
.is_max()) {
1221 } else if (mcand
< lcand
) {
1223 assert(!mcand
.is_max());
1227 assert(!lcand
.is_max());
1231 dout(10) << " pgnls candidate 0x" << std::hex
<< candidate
.get_hash()
1232 << " vs lower bound 0x" << lower_bound
.get_hash() << dendl
;
1234 if (candidate
>= next
) {
1238 if (response
.entries
.size() == list_size
) {
1243 // skip snapdir objects
1244 if (candidate
.snap
== CEPH_SNAPDIR
)
1247 if (candidate
.snap
!= CEPH_NOSNAP
)
1250 // skip internal namespace
1251 if (candidate
.get_namespace() == cct
->_conf
->osd_hit_set_namespace
)
1254 if (missing_loc
.is_deleted(candidate
))
1257 // skip wrong namespace
1258 if (m
->get_hobj().nspace
!= librados::all_nspaces
&&
1259 candidate
.get_namespace() != m
->get_hobj().nspace
)
1262 if (filter
&& !pgls_filter(filter
, candidate
, filter_out
))
1265 dout(20) << "pgnls item 0x" << std::hex
1266 << candidate
.get_hash()
1267 << ", rev 0x" << hobject_t::_reverse_bits(candidate
.get_hash())
1269 << candidate
.oid
.name
<< dendl
;
1271 librados::ListObjectImpl item
;
1272 item
.nspace
= candidate
.get_namespace();
1273 item
.oid
= candidate
.oid
.name
;
1274 item
.locator
= candidate
.get_key();
1275 response
.entries
.push_back(item
);
1278 if (next
.is_max() &&
1279 missing_iter
== pg_log
.get_missing().get_items().end() &&
1280 ls_iter
== sentries
.end()) {
1283 // Set response.handle to the start of the next PG according
1284 // to the object sort order.
1285 response
.handle
= info
.pgid
.pgid
.get_hobj_end(pool
.info
.get_pg_num());
1287 response
.handle
= next
;
1289 dout(10) << "pgnls handle=" << response
.handle
<< dendl
;
1290 ::encode(response
, osd_op
.outdata
);
1292 ::encode(filter_out
, osd_op
.outdata
);
1293 dout(10) << " pgnls result=" << result
<< " outdata.length()="
1294 << osd_op
.outdata
.length() << dendl
;
1298 case CEPH_OSD_OP_PGLS_FILTER
:
1300 ::decode(cname
, bp
);
1301 ::decode(mname
, bp
);
1303 catch (const buffer::error
& e
) {
1304 dout(0) << "unable to decode PGLS_FILTER description in " << *m
<< dendl
;
1312 result
= get_pgls_filter(bp
, &filter
);
1320 case CEPH_OSD_OP_PGLS
:
1321 if (snapid
!= CEPH_NOSNAP
) {
1325 if (get_osdmap()->raw_pg_to_pg(m
->get_pg()) != info
.pgid
.pgid
) {
1326 dout(10) << " pgls pg=" << m
->get_pg()
1327 << " " << get_osdmap()->raw_pg_to_pg(m
->get_pg())
1328 << " != " << info
.pgid
<< dendl
;
1331 unsigned list_size
= MIN(cct
->_conf
->osd_max_pgls
, p
->op
.pgls
.count
);
1333 dout(10) << " pgls pg=" << m
->get_pg() << " count " << list_size
<< dendl
;
1334 // read into a buffer
1335 vector
<hobject_t
> sentries
;
1336 pg_ls_response_t response
;
1338 ::decode(response
.handle
, bp
);
1340 catch (const buffer::error
& e
) {
1341 dout(0) << "unable to decode PGLS handle in " << *m
<< dendl
;
1347 hobject_t current
= response
.handle
;
1349 int r
= pgbackend
->objects_list_partial(
1360 assert(snapid
== CEPH_NOSNAP
|| pg_log
.get_missing().get_items().empty());
1362 map
<hobject_t
, pg_missing_item
>::const_iterator missing_iter
=
1363 pg_log
.get_missing().get_items().lower_bound(current
);
1364 vector
<hobject_t
>::iterator ls_iter
= sentries
.begin();
1365 hobject_t _max
= hobject_t::get_max();
1367 const hobject_t
&mcand
=
1368 missing_iter
== pg_log
.get_missing().get_items().end() ?
1370 missing_iter
->first
;
1371 const hobject_t
&lcand
=
1372 ls_iter
== sentries
.end() ?
1376 hobject_t candidate
;
1377 if (mcand
== lcand
) {
1379 if (!mcand
.is_max()) {
1383 } else if (mcand
< lcand
) {
1385 assert(!mcand
.is_max());
1389 assert(!lcand
.is_max());
1393 if (candidate
>= next
) {
1397 if (response
.entries
.size() == list_size
) {
1402 // skip snapdir objects
1403 if (candidate
.snap
== CEPH_SNAPDIR
)
1406 if (candidate
.snap
!= CEPH_NOSNAP
)
1409 // skip wrong namespace
1410 if (candidate
.get_namespace() != m
->get_hobj().nspace
)
1413 if (missing_loc
.is_deleted(candidate
))
1416 if (filter
&& !pgls_filter(filter
, candidate
, filter_out
))
1419 response
.entries
.push_back(make_pair(candidate
.oid
,
1420 candidate
.get_key()));
1422 if (next
.is_max() &&
1423 missing_iter
== pg_log
.get_missing().get_items().end() &&
1424 ls_iter
== sentries
.end()) {
1427 response
.handle
= next
;
1428 ::encode(response
, osd_op
.outdata
);
1430 ::encode(filter_out
, osd_op
.outdata
);
1431 dout(10) << " pgls result=" << result
<< " outdata.length()="
1432 << osd_op
.outdata
.length() << dendl
;
1436 case CEPH_OSD_OP_PG_HITSET_LS
:
1438 list
< pair
<utime_t
,utime_t
> > ls
;
1439 for (list
<pg_hit_set_info_t
>::const_iterator p
= info
.hit_set
.history
.begin();
1440 p
!= info
.hit_set
.history
.end();
1442 ls
.push_back(make_pair(p
->begin
, p
->end
));
1444 ls
.push_back(make_pair(hit_set_start_stamp
, utime_t()));
1445 ::encode(ls
, osd_op
.outdata
);
1449 case CEPH_OSD_OP_PG_HITSET_GET
:
1451 utime_t
stamp(osd_op
.op
.hit_set_get
.stamp
);
1452 if (hit_set_start_stamp
&& stamp
>= hit_set_start_stamp
) {
1453 // read the current in-memory HitSet, not the version we've
1459 ::encode(*hit_set
, osd_op
.outdata
);
1460 result
= osd_op
.outdata
.length();
1462 // read an archived HitSet.
1464 for (list
<pg_hit_set_info_t
>::const_iterator p
= info
.hit_set
.history
.begin();
1465 p
!= info
.hit_set
.history
.end();
1467 if (stamp
>= p
->begin
&& stamp
<= p
->end
) {
1468 oid
= get_hit_set_archive_object(p
->begin
, p
->end
, p
->using_gmt
);
1472 if (oid
== hobject_t()) {
1476 if (!pool
.info
.is_replicated()) {
1477 // FIXME: EC not supported yet
1478 result
= -EOPNOTSUPP
;
1481 if (is_unreadable_object(oid
)) {
1482 wait_for_unreadable_object(oid
, op
);
1486 result
= osd
->store
->read(ch
, ghobject_t(oid
), 0, 0, osd_op
.outdata
);
1491 case CEPH_OSD_OP_SCRUBLS
:
1492 result
= do_scrub_ls(m
, &osd_op
);
1505 MOSDOpReply
*reply
= new MOSDOpReply(m
, 0, get_osdmap()->get_epoch(),
1506 CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
,
1508 reply
->claim_op_out_data(ops
);
1509 reply
->set_result(result
);
1510 reply
->set_reply_versions(info
.last_update
, info
.last_user_version
);
1511 osd
->send_message_osd_client(reply
, m
->get_connection());
1515 int PrimaryLogPG::do_scrub_ls(MOSDOp
*m
, OSDOp
*osd_op
)
1517 if (m
->get_pg() != info
.pgid
.pgid
) {
1518 dout(10) << " scrubls pg=" << m
->get_pg() << " != " << info
.pgid
<< dendl
;
1519 return -EINVAL
; // hmm?
1521 auto bp
= osd_op
->indata
.begin();
1525 } catch (buffer::error
&) {
1526 dout(10) << " corrupted scrub_ls_arg_t" << dendl
;
1530 scrub_ls_result_t result
= {.interval
= info
.history
.same_interval_since
};
1531 if (arg
.interval
!= 0 && arg
.interval
!= info
.history
.same_interval_since
) {
1533 } else if (!scrubber
.store
) {
1535 } else if (arg
.get_snapsets
) {
1536 result
.vals
= scrubber
.store
->get_snap_errors(osd
->store
,
1541 result
.vals
= scrubber
.store
->get_object_errors(osd
->store
,
1546 ::encode(result
, osd_op
->outdata
);
1550 void PrimaryLogPG::calc_trim_to()
1552 size_t target
= cct
->_conf
->osd_min_pg_log_entries
;
1553 if (is_degraded() ||
1554 state_test(PG_STATE_RECOVERING
|
1555 PG_STATE_RECOVERY_WAIT
|
1557 PG_STATE_BACKFILL_WAIT
|
1558 PG_STATE_BACKFILL_TOOFULL
)) {
1559 target
= cct
->_conf
->osd_max_pg_log_entries
;
1562 eversion_t limit
= MIN(
1563 min_last_complete_ondisk
,
1564 pg_log
.get_can_rollback_to());
1565 if (limit
!= eversion_t() &&
1566 limit
!= pg_trim_to
&&
1567 pg_log
.get_log().approx_size() > target
) {
1568 size_t num_to_trim
= pg_log
.get_log().approx_size() - target
;
1569 if (num_to_trim
< cct
->_conf
->osd_pg_log_trim_min
) {
1572 list
<pg_log_entry_t
>::const_iterator it
= pg_log
.get_log().log
.begin();
1573 eversion_t new_trim_to
;
1574 for (size_t i
= 0; i
< num_to_trim
; ++i
) {
1575 new_trim_to
= it
->version
;
1577 if (new_trim_to
> limit
) {
1578 new_trim_to
= limit
;
1579 dout(10) << "calc_trim_to trimming to min_last_complete_ondisk" << dendl
;
1583 dout(10) << "calc_trim_to " << pg_trim_to
<< " -> " << new_trim_to
<< dendl
;
1584 pg_trim_to
= new_trim_to
;
1585 assert(pg_trim_to
<= pg_log
.get_head());
1586 assert(pg_trim_to
<= min_last_complete_ondisk
);
1590 PrimaryLogPG::PrimaryLogPG(OSDService
*o
, OSDMapRef curmap
,
1591 const PGPool
&_pool
, spg_t p
) :
1592 PG(o
, curmap
, _pool
, p
),
1594 PGBackend::build_pg_backend(
1595 _pool
.info
, curmap
, this, coll_t(p
), ch
, o
->store
, cct
)),
1596 object_contexts(o
->cct
, o
->cct
->_conf
->osd_pg_object_context_cache_count
),
1597 snapset_contexts_lock("PrimaryLogPG::snapset_contexts_lock"),
1598 new_backfill(false),
1600 snap_trimmer_machine(this)
1602 missing_loc
.set_backend_predicates(
1603 pgbackend
->get_is_readable_predicate(),
1604 pgbackend
->get_is_recoverable_predicate());
1605 snap_trimmer_machine
.initiate();
1608 void PrimaryLogPG::get_src_oloc(const object_t
& oid
, const object_locator_t
& oloc
, object_locator_t
& src_oloc
)
1611 if (oloc
.key
.empty())
1612 src_oloc
.key
= oid
.name
;
1615 void PrimaryLogPG::handle_backoff(OpRequestRef
& op
)
1617 const MOSDBackoff
*m
= static_cast<const MOSDBackoff
*>(op
->get_req());
1618 SessionRef session
= static_cast<Session
*>(m
->get_connection()->get_priv());
1621 session
->put(); // get_priv takes a ref, and so does the SessionRef
1622 hobject_t begin
= info
.pgid
.pgid
.get_hobj_start();
1623 hobject_t end
= info
.pgid
.pgid
.get_hobj_end(pool
.info
.get_pg_num());
1624 if (begin
< m
->begin
) {
1630 dout(10) << __func__
<< " backoff ack id " << m
->id
1631 << " [" << begin
<< "," << end
<< ")" << dendl
;
1632 session
->ack_backoff(cct
, m
->pgid
, m
->id
, begin
, end
);
1635 void PrimaryLogPG::do_request(
1637 ThreadPool::TPHandle
&handle
)
1639 if (op
->osd_trace
) {
1640 op
->pg_trace
.init("pg op", &trace_endpoint
, &op
->osd_trace
);
1641 op
->pg_trace
.event("do request");
1643 // make sure we have a new enough map
1644 auto p
= waiting_for_map
.find(op
->get_source());
1645 if (p
!= waiting_for_map
.end()) {
1646 // preserve ordering
1647 dout(20) << __func__
<< " waiting_for_map "
1648 << p
->first
<< " not empty, queueing" << dendl
;
1649 p
->second
.push_back(op
);
1650 op
->mark_delayed("waiting_for_map not empty");
1653 if (!have_same_or_newer_map(op
->min_epoch
)) {
1654 dout(20) << __func__
<< " min " << op
->min_epoch
1655 << ", queue on waiting_for_map " << op
->get_source() << dendl
;
1656 waiting_for_map
[op
->get_source()].push_back(op
);
1657 op
->mark_delayed("op must wait for map");
1661 if (can_discard_request(op
)) {
1666 const Message
*m
= op
->get_req();
1667 if (m
->get_connection()->has_feature(CEPH_FEATURE_RADOS_BACKOFF
)) {
1668 SessionRef session
= static_cast<Session
*>(m
->get_connection()->get_priv());
1671 session
->put(); // get_priv takes a ref, and so does the SessionRef
1673 if (op
->get_req()->get_type() == CEPH_MSG_OSD_OP
) {
1674 if (session
->check_backoff(cct
, info
.pgid
,
1675 info
.pgid
.pgid
.get_hobj_start(), m
)) {
1682 (!is_active() && is_peered());
1683 if (g_conf
->osd_backoff_on_peering
&& !backoff
) {
1689 add_pg_backoff(session
);
1693 // pg backoff acks at pg-level
1694 if (op
->get_req()->get_type() == CEPH_MSG_OSD_BACKOFF
) {
1695 const MOSDBackoff
*ba
= static_cast<const MOSDBackoff
*>(m
);
1696 if (ba
->begin
!= ba
->end
) {
1703 if (flushes_in_progress
> 0) {
1704 dout(20) << flushes_in_progress
1705 << " flushes_in_progress pending "
1706 << "waiting for active on " << op
<< dendl
;
1707 waiting_for_peered
.push_back(op
);
1708 op
->mark_delayed("waiting for peered");
1713 // Delay unless PGBackend says it's ok
1714 if (pgbackend
->can_handle_while_inactive(op
)) {
1715 bool handled
= pgbackend
->handle_message(op
);
1719 waiting_for_peered
.push_back(op
);
1720 op
->mark_delayed("waiting for peered");
1725 assert(is_peered() && flushes_in_progress
== 0);
1726 if (pgbackend
->handle_message(op
))
1729 switch (op
->get_req()->get_type()) {
1730 case CEPH_MSG_OSD_OP
:
1731 case CEPH_MSG_OSD_BACKOFF
:
1733 dout(20) << " peered, not active, waiting for active on " << op
<< dendl
;
1734 waiting_for_active
.push_back(op
);
1735 op
->mark_delayed("waiting for active");
1738 switch (op
->get_req()->get_type()) {
1739 case CEPH_MSG_OSD_OP
:
1740 // verify client features
1741 if ((pool
.info
.has_tiers() || pool
.info
.is_tier()) &&
1742 !op
->has_feature(CEPH_FEATURE_OSD_CACHEPOOL
)) {
1743 osd
->reply_op_error(op
, -EOPNOTSUPP
);
1748 case CEPH_MSG_OSD_BACKOFF
:
1749 // object-level backoff acks handled in osdop context
1759 case MSG_OSD_SUBOPREPLY
:
1760 do_sub_op_reply(op
);
1763 case MSG_OSD_PG_SCAN
:
1764 do_scan(op
, handle
);
1767 case MSG_OSD_PG_BACKFILL
:
1771 case MSG_OSD_PG_BACKFILL_REMOVE
:
1772 do_backfill_remove(op
);
1775 case MSG_OSD_SCRUB_RESERVE
:
1777 const MOSDScrubReserve
*m
=
1778 static_cast<const MOSDScrubReserve
*>(op
->get_req());
1780 case MOSDScrubReserve::REQUEST
:
1781 handle_scrub_reserve_request(op
);
1783 case MOSDScrubReserve::GRANT
:
1784 handle_scrub_reserve_grant(op
, m
->from
);
1786 case MOSDScrubReserve::REJECT
:
1787 handle_scrub_reserve_reject(op
, m
->from
);
1789 case MOSDScrubReserve::RELEASE
:
1790 handle_scrub_reserve_release(op
);
1796 case MSG_OSD_REP_SCRUB
:
1797 replica_scrub(op
, handle
);
1800 case MSG_OSD_REP_SCRUBMAP
:
1801 do_replica_scrub_map(op
);
1804 case MSG_OSD_PG_UPDATE_LOG_MISSING
:
1805 do_update_log_missing(op
);
1808 case MSG_OSD_PG_UPDATE_LOG_MISSING_REPLY
:
1809 do_update_log_missing_reply(op
);
1813 assert(0 == "bad message type in do_request");
1817 hobject_t
PrimaryLogPG::earliest_backfill() const
1819 hobject_t e
= hobject_t::get_max();
1820 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
1821 i
!= backfill_targets
.end();
1824 map
<pg_shard_t
, pg_info_t
>::const_iterator iter
= peer_info
.find(bt
);
1825 assert(iter
!= peer_info
.end());
1826 if (iter
->second
.last_backfill
< e
)
1827 e
= iter
->second
.last_backfill
;
1832 /** do_op - do an op
1833 * pg lock will be held (if multithreaded)
1834 * osd_lock NOT held.
1836 void PrimaryLogPG::do_op(OpRequestRef
& op
)
1839 // NOTE: take a non-const pointer here; we must be careful not to
1840 // change anything that will break other reads on m (operator<<).
1841 MOSDOp
*m
= static_cast<MOSDOp
*>(op
->get_nonconst_req());
1842 assert(m
->get_type() == CEPH_MSG_OSD_OP
);
1843 if (m
->finish_decode()) {
1844 op
->reset_desc(); // for TrackedOp
1848 dout(20) << __func__
<< ": op " << *m
<< dendl
;
1850 hobject_t head
= m
->get_hobj();
1851 head
.snap
= CEPH_NOSNAP
;
1853 if (!info
.pgid
.pgid
.contains(
1854 info
.pgid
.pgid
.get_split_bits(pool
.info
.get_pg_num()), head
)) {
1855 derr
<< __func__
<< " " << info
.pgid
.pgid
<< " does not contain "
1856 << head
<< " pg_num " << pool
.info
.get_pg_num() << " hash "
1857 << std::hex
<< head
.get_hash() << std::dec
<< dendl
;
1858 osd
->clog
->warn() << info
.pgid
.pgid
<< " does not contain " << head
1860 assert(!cct
->_conf
->osd_debug_misdirected_ops
);
1865 m
->get_connection()->has_feature(CEPH_FEATURE_RADOS_BACKOFF
);
1868 session
= static_cast<Session
*>(m
->get_connection()->get_priv());
1869 if (!session
.get()) {
1870 dout(10) << __func__
<< " no session" << dendl
;
1873 session
->put(); // get_priv() takes a ref, and so does the intrusive_ptr
1875 if (session
->check_backoff(cct
, info
.pgid
, head
, m
)) {
1880 if (m
->has_flag(CEPH_OSD_FLAG_PARALLELEXEC
)) {
1882 dout(20) << __func__
<< ": PARALLELEXEC not implemented " << *m
<< dendl
;
1883 osd
->reply_op_error(op
, -EINVAL
);
1887 if (op
->rmw_flags
== 0) {
1888 int r
= osd
->osd
->init_op_flags(op
);
1890 osd
->reply_op_error(op
, r
);
1895 if ((m
->get_flags() & (CEPH_OSD_FLAG_BALANCE_READS
|
1896 CEPH_OSD_FLAG_LOCALIZE_READS
)) &&
1898 !(op
->may_write() || op
->may_cache())) {
1899 // balanced reads; any replica will do
1900 if (!(is_primary() || is_replica())) {
1901 osd
->handle_misdirected_op(this, op
);
1905 // normal case; must be primary
1906 if (!is_primary()) {
1907 osd
->handle_misdirected_op(this, op
);
1912 if (!op_has_sufficient_caps(op
)) {
1913 osd
->reply_op_error(op
, -EPERM
);
1917 if (op
->includes_pg_op()) {
1918 return do_pg_op(op
);
1921 // object name too long?
1922 if (m
->get_oid().name
.size() > cct
->_conf
->osd_max_object_name_len
) {
1923 dout(4) << "do_op name is longer than "
1924 << cct
->_conf
->osd_max_object_name_len
1925 << " bytes" << dendl
;
1926 osd
->reply_op_error(op
, -ENAMETOOLONG
);
1929 if (m
->get_hobj().get_key().size() > cct
->_conf
->osd_max_object_name_len
) {
1930 dout(4) << "do_op locator is longer than "
1931 << cct
->_conf
->osd_max_object_name_len
1932 << " bytes" << dendl
;
1933 osd
->reply_op_error(op
, -ENAMETOOLONG
);
1936 if (m
->get_hobj().nspace
.size() > cct
->_conf
->osd_max_object_namespace_len
) {
1937 dout(4) << "do_op namespace is longer than "
1938 << cct
->_conf
->osd_max_object_namespace_len
1939 << " bytes" << dendl
;
1940 osd
->reply_op_error(op
, -ENAMETOOLONG
);
1944 if (int r
= osd
->store
->validate_hobject_key(head
)) {
1945 dout(4) << "do_op object " << head
<< " invalid for backing store: "
1947 osd
->reply_op_error(op
, r
);
1952 if (get_osdmap()->is_blacklisted(m
->get_source_addr())) {
1953 dout(10) << "do_op " << m
->get_source_addr() << " is blacklisted" << dendl
;
1954 osd
->reply_op_error(op
, -EBLACKLISTED
);
1958 // order this op as a write?
1959 bool write_ordered
= op
->rwordered();
1961 // discard due to cluster full transition? (we discard any op that
1962 // originates before the cluster or pool is marked full; the client
1963 // will resend after the full flag is removed or if they expect the
1964 // op to succeed despite being full). The except is FULL_FORCE and
1965 // FULL_TRY ops, which there is no reason to discard because they
1966 // bypass all full checks anyway. If this op isn't write or
1967 // read-ordered, we skip.
1968 // FIXME: we exclude mds writes for now.
1969 if (write_ordered
&& !(m
->get_source().is_mds() ||
1970 m
->has_flag(CEPH_OSD_FLAG_FULL_TRY
) ||
1971 m
->has_flag(CEPH_OSD_FLAG_FULL_FORCE
)) &&
1972 info
.history
.last_epoch_marked_full
> m
->get_map_epoch()) {
1973 dout(10) << __func__
<< " discarding op sent before full " << m
<< " "
1977 // mds should have stopped writing before this point.
1978 // We can't allow OSD to become non-startable even if mds
1979 // could be writing as part of file removals.
1981 if (write_ordered
&& osd
->check_failsafe_full(ss
)) {
1982 dout(10) << __func__
<< " fail-safe full check failed, dropping request"
1987 int64_t poolid
= get_pgid().pool();
1988 if (op
->may_write()) {
1990 const pg_pool_t
*pi
= get_osdmap()->get_pg_pool(poolid
);
1996 if (m
->get_snapid() != CEPH_NOSNAP
) {
1997 dout(20) << __func__
<< ": write to clone not valid " << *m
<< dendl
;
1998 osd
->reply_op_error(op
, -EINVAL
);
2003 if (cct
->_conf
->osd_max_write_size
&&
2004 m
->get_data_len() > cct
->_conf
->osd_max_write_size
<< 20) {
2005 // journal can't hold commit!
2006 derr
<< "do_op msg data len " << m
->get_data_len()
2007 << " > osd_max_write_size " << (cct
->_conf
->osd_max_write_size
<< 20)
2008 << " on " << *m
<< dendl
;
2009 osd
->reply_op_error(op
, -OSD_WRITETOOBIG
);
2014 dout(10) << "do_op " << *m
2015 << (op
->may_write() ? " may_write" : "")
2016 << (op
->may_read() ? " may_read" : "")
2017 << (op
->may_cache() ? " may_cache" : "")
2018 << " -> " << (write_ordered
? "write-ordered" : "read-ordered")
2019 << " flags " << ceph_osd_flag_string(m
->get_flags())
2023 if (is_unreadable_object(head
)) {
2024 if (!is_primary()) {
2025 osd
->reply_op_error(op
, -EAGAIN
);
2029 (g_conf
->osd_backoff_on_degraded
||
2030 (g_conf
->osd_backoff_on_unfound
&& missing_loc
.is_unfound(head
)))) {
2031 add_backoff(session
, head
, head
);
2032 maybe_kick_recovery(head
);
2034 wait_for_unreadable_object(head
, op
);
2040 if (write_ordered
&& is_degraded_or_backfilling_object(head
)) {
2041 if (can_backoff
&& g_conf
->osd_backoff_on_degraded
) {
2042 add_backoff(session
, head
, head
);
2044 wait_for_degraded_object(head
, op
);
2049 if (write_ordered
&&
2050 scrubber
.write_blocked_by_scrub(head
)) {
2051 dout(20) << __func__
<< ": waiting for scrub" << dendl
;
2052 waiting_for_scrub
.push_back(op
);
2053 op
->mark_delayed("waiting for scrub");
2058 map
<hobject_t
, snapid_t
>::iterator blocked_iter
=
2059 objects_blocked_on_degraded_snap
.find(head
);
2060 if (write_ordered
&& blocked_iter
!= objects_blocked_on_degraded_snap
.end()) {
2061 hobject_t
to_wait_on(head
);
2062 to_wait_on
.snap
= blocked_iter
->second
;
2063 wait_for_degraded_object(to_wait_on
, op
);
2066 map
<hobject_t
, ObjectContextRef
>::iterator blocked_snap_promote_iter
=
2067 objects_blocked_on_snap_promotion
.find(head
);
2068 if (write_ordered
&&
2069 blocked_snap_promote_iter
!= objects_blocked_on_snap_promotion
.end()) {
2070 wait_for_blocked_object(
2071 blocked_snap_promote_iter
->second
->obs
.oi
.soid
,
2075 if (write_ordered
&& objects_blocked_on_cache_full
.count(head
)) {
2076 block_write_on_full_cache(head
, op
);
2081 hobject_t snapdir
= head
.get_snapdir();
2083 if (is_unreadable_object(snapdir
)) {
2084 wait_for_unreadable_object(snapdir
, op
);
2089 if (write_ordered
&& is_degraded_or_backfilling_object(snapdir
)) {
2090 wait_for_degraded_object(snapdir
, op
);
2095 if (op
->may_write() || op
->may_cache()) {
2096 // warning: we will get back *a* request for this reqid, but not
2097 // necessarily the most recent. this happens with flush and
2098 // promote ops, but we can't possible have both in our log where
2099 // the original request is still not stable on disk, so for our
2100 // purposes here it doesn't matter which one we get.
2102 version_t user_version
;
2103 int return_code
= 0;
2104 bool got
= check_in_progress_op(
2105 m
->get_reqid(), &version
, &user_version
, &return_code
);
2107 dout(3) << __func__
<< " dup " << m
->get_reqid()
2108 << " version " << version
<< dendl
;
2109 if (already_complete(version
)) {
2110 osd
->reply_op_error(op
, return_code
, version
, user_version
);
2112 dout(10) << " waiting for " << version
<< " to commit" << dendl
;
2113 // always queue ondisk waiters, so that we can requeue if needed
2114 waiting_for_ondisk
[version
].push_back(make_pair(op
, user_version
));
2115 op
->mark_delayed("waiting for ondisk");
2121 ObjectContextRef obc
;
2122 bool can_create
= op
->may_write() || op
->may_cache();
2123 hobject_t missing_oid
;
2124 const hobject_t
& oid
= m
->get_hobj();
2126 // io blocked on obc?
2127 if (!m
->has_flag(CEPH_OSD_FLAG_FLUSH
) &&
2128 maybe_await_blocked_snapset(oid
, op
)) {
2132 int r
= find_object_context(
2133 oid
, &obc
, can_create
,
2134 m
->has_flag(CEPH_OSD_FLAG_MAP_SNAP_CLONE
),
2138 // If we're not the primary of this OSD, we just return -EAGAIN. Otherwise,
2139 // we have to wait for the object.
2141 // missing the specific snap we need; requeue and wait.
2142 assert(!op
->may_write()); // only happens on a read/cache
2143 wait_for_unreadable_object(missing_oid
, op
);
2146 } else if (r
== 0) {
2147 if (is_unreadable_object(obc
->obs
.oi
.soid
)) {
2148 dout(10) << __func__
<< ": clone " << obc
->obs
.oi
.soid
2149 << " is unreadable, waiting" << dendl
;
2150 wait_for_unreadable_object(obc
->obs
.oi
.soid
, op
);
2154 // degraded object? (the check above was for head; this could be a clone)
2155 if (write_ordered
&&
2156 obc
->obs
.oi
.soid
.snap
!= CEPH_NOSNAP
&&
2157 is_degraded_or_backfilling_object(obc
->obs
.oi
.soid
)) {
2158 dout(10) << __func__
<< ": clone " << obc
->obs
.oi
.soid
2159 << " is degraded, waiting" << dendl
;
2160 wait_for_degraded_object(obc
->obs
.oi
.soid
, op
);
2165 bool in_hit_set
= false;
2168 if (obc
->obs
.oi
.soid
!= hobject_t() && hit_set
->contains(obc
->obs
.oi
.soid
))
2171 if (missing_oid
!= hobject_t() && hit_set
->contains(missing_oid
))
2174 if (!op
->hitset_inserted
) {
2175 hit_set
->insert(oid
);
2176 op
->hitset_inserted
= true;
2177 if (hit_set
->is_full() ||
2178 hit_set_start_stamp
+ pool
.info
.hit_set_period
<= m
->get_recv_stamp()) {
2185 if (agent_choose_mode(false, op
))
2189 if (obc
.get() && obc
->obs
.exists
&& obc
->obs
.oi
.has_manifest()) {
2190 if (maybe_handle_manifest(op
,
2196 if (maybe_handle_cache(op
,
2205 if (r
&& (r
!= -ENOENT
|| !obc
)) {
2206 // copy the reqids for copy get on ENOENT
2208 (m
->ops
[0].op
.op
== CEPH_OSD_OP_COPY_GET
)) {
2209 fill_in_copy_get_noent(op
, oid
, m
->ops
[0]);
2212 dout(20) << __func__
<< ": find_object_context got error " << r
<< dendl
;
2213 if (op
->may_write() &&
2214 get_osdmap()->require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
2215 record_write_error(op
, oid
, nullptr, r
);
2217 osd
->reply_op_error(op
, r
);
2222 // make sure locator is consistent
2223 object_locator_t
oloc(obc
->obs
.oi
.soid
);
2224 if (m
->get_object_locator() != oloc
) {
2225 dout(10) << " provided locator " << m
->get_object_locator()
2226 << " != object's " << obc
->obs
.oi
.soid
<< dendl
;
2227 osd
->clog
->warn() << "bad locator " << m
->get_object_locator()
2228 << " on object " << oloc
2232 // io blocked on obc?
2233 if (obc
->is_blocked() &&
2234 !m
->has_flag(CEPH_OSD_FLAG_FLUSH
)) {
2235 wait_for_blocked_object(obc
->obs
.oi
.soid
, op
);
2239 dout(25) << __func__
<< " oi " << obc
->obs
.oi
<< dendl
;
2241 for (vector
<OSDOp
>::iterator p
= m
->ops
.begin(); p
!= m
->ops
.end(); ++p
) {
2244 // make sure LIST_SNAPS is on CEPH_SNAPDIR and nothing else
2245 if (osd_op
.op
.op
== CEPH_OSD_OP_LIST_SNAPS
&&
2246 m
->get_snapid() != CEPH_SNAPDIR
) {
2247 dout(10) << "LIST_SNAPS with incorrect context" << dendl
;
2248 osd
->reply_op_error(op
, -EINVAL
);
2253 OpContext
*ctx
= new OpContext(op
, m
->get_reqid(), &m
->ops
, obc
, this);
2255 if (!obc
->obs
.exists
)
2256 ctx
->snapset_obc
= get_object_context(obc
->obs
.oi
.soid
.get_snapdir(), false);
2258 /* Due to obc caching, we might have a cached non-existent snapset_obc
2259 * for the snapdir. If so, we can ignore it. Subsequent parts of the
2260 * do_op pipeline make decisions based on whether snapset_obc is
2263 if (ctx
->snapset_obc
&& !ctx
->snapset_obc
->obs
.exists
)
2264 ctx
->snapset_obc
= ObjectContextRef();
2266 if (m
->has_flag(CEPH_OSD_FLAG_SKIPRWLOCKS
)) {
2267 dout(20) << __func__
<< ": skipping rw locks" << dendl
;
2268 } else if (m
->get_flags() & CEPH_OSD_FLAG_FLUSH
) {
2269 dout(20) << __func__
<< ": part of flush, will ignore write lock" << dendl
;
2271 // verify there is in fact a flush in progress
2272 // FIXME: we could make this a stronger test.
2273 map
<hobject_t
,FlushOpRef
>::iterator p
= flush_ops
.find(obc
->obs
.oi
.soid
);
2274 if (p
== flush_ops
.end()) {
2275 dout(10) << __func__
<< " no flush in progress, aborting" << dendl
;
2276 reply_ctx(ctx
, -EINVAL
);
2279 } else if (!get_rw_locks(write_ordered
, ctx
)) {
2280 dout(20) << __func__
<< " waiting for rw locks " << dendl
;
2281 op
->mark_delayed("waiting for rw locks");
2285 dout(20) << __func__
<< " obc " << *obc
<< dendl
;
2288 dout(20) << __func__
<< " returned an error: " << r
<< dendl
;
2290 if (op
->may_write() &&
2291 get_osdmap()->require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
2292 record_write_error(op
, oid
, nullptr, r
);
2294 osd
->reply_op_error(op
, r
);
2299 if (m
->has_flag(CEPH_OSD_FLAG_IGNORE_CACHE
)) {
2300 ctx
->ignore_cache
= true;
2303 if ((op
->may_read()) && (obc
->obs
.oi
.is_lost())) {
2304 // This object is lost. Reading from it returns an error.
2305 dout(20) << __func__
<< ": object " << obc
->obs
.oi
.soid
2306 << " is lost" << dendl
;
2307 reply_ctx(ctx
, -ENFILE
);
2310 if (!op
->may_write() &&
2312 (!obc
->obs
.exists
||
2313 ((m
->get_snapid() != CEPH_SNAPDIR
) &&
2314 obc
->obs
.oi
.is_whiteout()))) {
2315 // copy the reqids for copy get on ENOENT
2316 if (m
->ops
[0].op
.op
== CEPH_OSD_OP_COPY_GET
) {
2317 fill_in_copy_get_noent(op
, oid
, m
->ops
[0]);
2321 reply_ctx(ctx
, -ENOENT
);
2328 utime_t prepare_latency
= ceph_clock_now();
2329 prepare_latency
-= op
->get_dequeued_time();
2330 osd
->logger
->tinc(l_osd_op_prepare_lat
, prepare_latency
);
2331 if (op
->may_read() && op
->may_write()) {
2332 osd
->logger
->tinc(l_osd_op_rw_prepare_lat
, prepare_latency
);
2333 } else if (op
->may_read()) {
2334 osd
->logger
->tinc(l_osd_op_r_prepare_lat
, prepare_latency
);
2335 } else if (op
->may_write() || op
->may_cache()) {
2336 osd
->logger
->tinc(l_osd_op_w_prepare_lat
, prepare_latency
);
2339 // force recovery of the oldest missing object if too many logs
2340 maybe_force_recovery();
2342 PrimaryLogPG::cache_result_t
PrimaryLogPG::maybe_handle_manifest_detail(
2345 ObjectContextRef obc
)
2347 if (static_cast<const MOSDOp
*>(op
->get_req())->get_flags() &
2348 CEPH_OSD_FLAG_IGNORE_REDIRECT
) {
2349 dout(20) << __func__
<< ": ignoring redirect due to flag" << dendl
;
2350 return cache_result_t::NOOP
;
2354 dout(10) << __func__
<< " " << obc
->obs
.oi
<< " "
2355 << (obc
->obs
.exists
? "exists" : "DNE")
2358 // if it is write-ordered and blocked, stop now
2359 if (obc
.get() && obc
->is_blocked() && write_ordered
) {
2360 // we're already doing something with this object
2361 dout(20) << __func__
<< " blocked on " << obc
->obs
.oi
.soid
<< dendl
;
2362 return cache_result_t::NOOP
;
2365 vector
<OSDOp
> ops
= static_cast<const MOSDOp
*>(op
->get_req())->ops
;
2366 for (vector
<OSDOp
>::iterator p
= ops
.begin(); p
!= ops
.end(); ++p
) {
2368 ceph_osd_op
& op
= osd_op
.op
;
2369 if (op
.op
== CEPH_OSD_OP_SET_REDIRECT
) {
2370 return cache_result_t::NOOP
;
2374 switch (obc
->obs
.oi
.manifest
.type
) {
2375 case object_manifest_t::TYPE_REDIRECT
:
2376 if (op
->may_write() || write_ordered
) {
2377 do_proxy_write(op
, obc
->obs
.oi
.soid
, obc
);
2379 do_proxy_read(op
, obc
);
2381 return cache_result_t::HANDLED_PROXY
;
2382 case object_manifest_t::TYPE_CHUNKED
:
2384 assert(0 == "unrecognized manifest type");
2387 return cache_result_t::NOOP
;
2390 void PrimaryLogPG::record_write_error(OpRequestRef op
, const hobject_t
&soid
,
2391 MOSDOpReply
*orig_reply
, int r
)
2393 dout(20) << __func__
<< " r=" << r
<< dendl
;
2394 assert(op
->may_write());
2395 const osd_reqid_t
&reqid
= static_cast<const MOSDOp
*>(op
->get_req())->get_reqid();
2396 ObjectContextRef obc
;
2397 mempool::osd_pglog::list
<pg_log_entry_t
> entries
;
2398 entries
.push_back(pg_log_entry_t(pg_log_entry_t::ERROR
, soid
,
2399 get_next_version(), eversion_t(), 0,
2400 reqid
, utime_t(), r
));
2405 boost::intrusive_ptr
<MOSDOpReply
> orig_reply
;
2410 MOSDOpReply
*orig_reply
,
2413 orig_reply(orig_reply
, false /* take over ref */), r(r
)
2416 ldpp_dout(pg
, 20) << "finished " << __func__
<< " r=" << r
<< dendl
;
2417 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
2418 int flags
= m
->get_flags() & (CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
2419 MOSDOpReply
*reply
= orig_reply
.detach();
2420 if (reply
== nullptr) {
2421 reply
= new MOSDOpReply(m
, r
, pg
->get_osdmap()->get_epoch(),
2424 ldpp_dout(pg
, 10) << " sending commit on " << *m
<< " " << reply
<< dendl
;
2425 pg
->osd
->send_message_osd_client(reply
, m
->get_connection());
2429 ObcLockManager lock_manager
;
2432 std::move(lock_manager
),
2433 boost::optional
<std::function
<void(void)> >(
2434 OnComplete(this, op
, orig_reply
, r
)),
2439 PrimaryLogPG::cache_result_t
PrimaryLogPG::maybe_handle_cache_detail(
2442 ObjectContextRef obc
,
2443 int r
, hobject_t missing_oid
,
2446 ObjectContextRef
*promote_obc
)
2450 op
->get_req()->get_type() == CEPH_MSG_OSD_OP
&&
2451 (static_cast<const MOSDOp
*>(op
->get_req())->get_flags() &
2452 CEPH_OSD_FLAG_IGNORE_CACHE
)) {
2453 dout(20) << __func__
<< ": ignoring cache due to flag" << dendl
;
2454 return cache_result_t::NOOP
;
2456 // return quickly if caching is not enabled
2457 if (pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
)
2458 return cache_result_t::NOOP
;
2460 must_promote
= must_promote
|| op
->need_promote();
2463 dout(25) << __func__
<< " " << obc
->obs
.oi
<< " "
2464 << (obc
->obs
.exists
? "exists" : "DNE")
2465 << " missing_oid " << missing_oid
2466 << " must_promote " << (int)must_promote
2467 << " in_hit_set " << (int)in_hit_set
2470 dout(25) << __func__
<< " (no obc)"
2471 << " missing_oid " << missing_oid
2472 << " must_promote " << (int)must_promote
2473 << " in_hit_set " << (int)in_hit_set
2476 // if it is write-ordered and blocked, stop now
2477 if (obc
.get() && obc
->is_blocked() && write_ordered
) {
2478 // we're already doing something with this object
2479 dout(20) << __func__
<< " blocked on " << obc
->obs
.oi
.soid
<< dendl
;
2480 return cache_result_t::NOOP
;
2483 if (r
== -ENOENT
&& missing_oid
== hobject_t()) {
2484 // we know this object is logically absent (e.g., an undefined clone)
2485 return cache_result_t::NOOP
;
2488 if (obc
.get() && obc
->obs
.exists
) {
2489 osd
->logger
->inc(l_osd_op_cache_hit
);
2490 return cache_result_t::NOOP
;
2493 if (missing_oid
== hobject_t() && obc
.get()) {
2494 missing_oid
= obc
->obs
.oi
.soid
;
2497 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
2498 const object_locator_t oloc
= m
->get_object_locator();
2500 if (op
->need_skip_handle_cache()) {
2501 return cache_result_t::NOOP
;
2504 // older versions do not proxy the feature bits.
2505 bool can_proxy_write
= get_osdmap()->get_up_osd_features() &
2506 CEPH_FEATURE_OSD_PROXY_WRITE_FEATURES
;
2507 OpRequestRef promote_op
;
2509 switch (pool
.info
.cache_mode
) {
2510 case pg_pool_t::CACHEMODE_WRITEBACK
:
2512 agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
2513 if (!op
->may_write() && !op
->may_cache() &&
2514 !write_ordered
&& !must_promote
) {
2515 dout(20) << __func__
<< " cache pool full, proxying read" << dendl
;
2517 return cache_result_t::HANDLED_PROXY
;
2519 dout(20) << __func__
<< " cache pool full, waiting" << dendl
;
2520 block_write_on_full_cache(missing_oid
, op
);
2521 return cache_result_t::BLOCKED_FULL
;
2524 if (must_promote
|| (!hit_set
&& !op
->need_skip_promote())) {
2525 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2526 return cache_result_t::BLOCKED_PROMOTE
;
2529 if (op
->may_write() || op
->may_cache()) {
2530 if (can_proxy_write
) {
2531 do_proxy_write(op
, missing_oid
);
2533 // promote if can't proxy the write
2534 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2535 return cache_result_t::BLOCKED_PROMOTE
;
2539 if (!op
->need_skip_promote() &&
2540 maybe_promote(obc
, missing_oid
, oloc
, in_hit_set
,
2541 pool
.info
.min_write_recency_for_promote
,
2544 return cache_result_t::BLOCKED_PROMOTE
;
2546 return cache_result_t::HANDLED_PROXY
;
2550 // Avoid duplicate promotion
2551 if (obc
.get() && obc
->is_blocked()) {
2554 return cache_result_t::BLOCKED_PROMOTE
;
2558 if (!op
->need_skip_promote()) {
2559 (void)maybe_promote(obc
, missing_oid
, oloc
, in_hit_set
,
2560 pool
.info
.min_read_recency_for_promote
,
2561 promote_op
, promote_obc
);
2564 return cache_result_t::HANDLED_PROXY
;
2566 assert(0 == "unreachable");
2567 return cache_result_t::NOOP
;
2569 case pg_pool_t::CACHEMODE_FORWARD
:
2570 // FIXME: this mode allows requests to be reordered.
2571 do_cache_redirect(op
);
2572 return cache_result_t::HANDLED_REDIRECT
;
2574 case pg_pool_t::CACHEMODE_READONLY
:
2575 // TODO: clean this case up
2576 if (!obc
.get() && r
== -ENOENT
) {
2577 // we don't have the object and op's a read
2578 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2579 return cache_result_t::BLOCKED_PROMOTE
;
2581 if (!r
) { // it must be a write
2582 do_cache_redirect(op
);
2583 return cache_result_t::HANDLED_REDIRECT
;
2585 // crap, there was a failure of some kind
2586 return cache_result_t::NOOP
;
2588 case pg_pool_t::CACHEMODE_READFORWARD
:
2589 // Do writeback to the cache tier for writes
2590 if (op
->may_write() || write_ordered
|| must_promote
) {
2592 agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
2593 dout(20) << __func__
<< " cache pool full, waiting" << dendl
;
2594 block_write_on_full_cache(missing_oid
, op
);
2595 return cache_result_t::BLOCKED_FULL
;
2597 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2598 return cache_result_t::BLOCKED_PROMOTE
;
2601 // If it is a read, we can read, we need to forward it
2602 do_cache_redirect(op
);
2603 return cache_result_t::HANDLED_REDIRECT
;
2605 case pg_pool_t::CACHEMODE_PROXY
:
2606 if (!must_promote
) {
2607 if (op
->may_write() || op
->may_cache() || write_ordered
) {
2608 if (can_proxy_write
) {
2609 do_proxy_write(op
, missing_oid
);
2610 return cache_result_t::HANDLED_PROXY
;
2614 return cache_result_t::HANDLED_PROXY
;
2617 // ugh, we're forced to promote.
2619 agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
2620 dout(20) << __func__
<< " cache pool full, waiting" << dendl
;
2621 block_write_on_full_cache(missing_oid
, op
);
2622 return cache_result_t::BLOCKED_FULL
;
2624 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2625 return cache_result_t::BLOCKED_PROMOTE
;
2627 case pg_pool_t::CACHEMODE_READPROXY
:
2628 // Do writeback to the cache tier for writes
2629 if (op
->may_write() || write_ordered
|| must_promote
) {
2631 agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
2632 dout(20) << __func__
<< " cache pool full, waiting" << dendl
;
2633 block_write_on_full_cache(missing_oid
, op
);
2634 return cache_result_t::BLOCKED_FULL
;
2636 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2637 return cache_result_t::BLOCKED_PROMOTE
;
2640 // If it is a read, we can read, we need to proxy it
2642 return cache_result_t::HANDLED_PROXY
;
2645 assert(0 == "unrecognized cache_mode");
2647 return cache_result_t::NOOP
;
2650 bool PrimaryLogPG::maybe_promote(ObjectContextRef obc
,
2651 const hobject_t
& missing_oid
,
2652 const object_locator_t
& oloc
,
2655 OpRequestRef promote_op
,
2656 ObjectContextRef
*promote_obc
)
2658 dout(20) << __func__
<< " missing_oid " << missing_oid
2659 << " in_hit_set " << in_hit_set
<< dendl
;
2665 // Check if in the current hit set
2675 unsigned count
= (int)in_hit_set
;
2677 // Check if in other hit sets
2678 const hobject_t
& oid
= obc
.get() ? obc
->obs
.oi
.soid
: missing_oid
;
2679 for (map
<time_t,HitSetRef
>::reverse_iterator itor
=
2680 agent_state
->hit_set_map
.rbegin();
2681 itor
!= agent_state
->hit_set_map
.rend();
2683 if (!itor
->second
->contains(oid
)) {
2687 if (count
>= recency
) {
2692 if (count
>= recency
) {
2695 return false; // not promoting
2700 if (osd
->promote_throttle()) {
2701 dout(10) << __func__
<< " promote throttled" << dendl
;
2704 promote_object(obc
, missing_oid
, oloc
, promote_op
, promote_obc
);
2708 void PrimaryLogPG::do_cache_redirect(OpRequestRef op
)
2710 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
2711 int flags
= m
->get_flags() & (CEPH_OSD_FLAG_ACK
|CEPH_OSD_FLAG_ONDISK
);
2712 MOSDOpReply
*reply
= new MOSDOpReply(m
, -ENOENT
,
2713 get_osdmap()->get_epoch(), flags
, false);
2714 request_redirect_t
redir(m
->get_object_locator(), pool
.info
.tier_of
);
2715 reply
->set_redirect(redir
);
2716 dout(10) << "sending redirect to pool " << pool
.info
.tier_of
<< " for op "
2718 m
->get_connection()->send_message(reply
);
2722 struct C_ProxyRead
: public Context
{
2725 epoch_t last_peering_reset
;
2727 PrimaryLogPG::ProxyReadOpRef prdop
;
2729 C_ProxyRead(PrimaryLogPG
*p
, hobject_t o
, epoch_t lpr
,
2730 const PrimaryLogPG::ProxyReadOpRef
& prd
)
2731 : pg(p
), oid(o
), last_peering_reset(lpr
),
2732 tid(0), prdop(prd
), start(ceph_clock_now())
2734 void finish(int r
) override
{
2735 if (prdop
->canceled
)
2738 if (prdop
->canceled
) {
2742 if (last_peering_reset
== pg
->get_last_peering_reset()) {
2743 pg
->finish_proxy_read(oid
, tid
, r
);
2744 pg
->osd
->logger
->tinc(l_osd_tier_r_lat
, ceph_clock_now() - start
);
2750 void PrimaryLogPG::do_proxy_read(OpRequestRef op
, ObjectContextRef obc
)
2752 // NOTE: non-const here because the ProxyReadOp needs mutable refs to
2753 // stash the result in the request's OSDOp vector
2754 MOSDOp
*m
= static_cast<MOSDOp
*>(op
->get_nonconst_req());
2755 object_locator_t oloc
;
2757 /* extensible tier */
2758 if (obc
&& obc
->obs
.exists
&& obc
->obs
.oi
.has_manifest()) {
2759 switch (obc
->obs
.oi
.manifest
.type
) {
2760 case object_manifest_t::TYPE_REDIRECT
:
2761 oloc
= object_locator_t(obc
->obs
.oi
.manifest
.redirect_target
);
2762 soid
= obc
->obs
.oi
.manifest
.redirect_target
;
2764 case object_manifest_t::TYPE_CHUNKED
:
2766 assert(0 == "unrecognized manifest type");
2770 soid
= m
->get_hobj();
2771 oloc
= object_locator_t(m
->get_object_locator());
2772 oloc
.pool
= pool
.info
.tier_of
;
2774 unsigned flags
= CEPH_OSD_FLAG_IGNORE_CACHE
| CEPH_OSD_FLAG_IGNORE_OVERLAY
;
2776 // pass through some original flags that make sense.
2777 // - leave out redirection and balancing flags since we are
2778 // already proxying through the primary
2779 // - leave off read/write/exec flags that are derived from the op
2780 flags
|= m
->get_flags() & (CEPH_OSD_FLAG_RWORDERED
|
2781 CEPH_OSD_FLAG_ORDERSNAP
|
2782 CEPH_OSD_FLAG_ENFORCE_SNAPC
|
2783 CEPH_OSD_FLAG_MAP_SNAP_CLONE
);
2785 dout(10) << __func__
<< " Start proxy read for " << *m
<< dendl
;
2787 ProxyReadOpRef
prdop(std::make_shared
<ProxyReadOp
>(op
, soid
, m
->ops
));
2789 ObjectOperation obj_op
;
2790 obj_op
.dup(prdop
->ops
);
2792 if (pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_WRITEBACK
&&
2793 (agent_state
&& agent_state
->evict_mode
!= TierAgentState::EVICT_MODE_FULL
)) {
2794 for (unsigned i
= 0; i
< obj_op
.ops
.size(); i
++) {
2795 ceph_osd_op op
= obj_op
.ops
[i
].op
;
2797 case CEPH_OSD_OP_READ
:
2798 case CEPH_OSD_OP_SYNC_READ
:
2799 case CEPH_OSD_OP_SPARSE_READ
:
2800 case CEPH_OSD_OP_CHECKSUM
:
2801 case CEPH_OSD_OP_CMPEXT
:
2802 op
.flags
= (op
.flags
| CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL
) &
2803 ~(CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
| CEPH_OSD_OP_FLAG_FADVISE_NOCACHE
);
2808 C_ProxyRead
*fin
= new C_ProxyRead(this, soid
, get_last_peering_reset(),
2810 ceph_tid_t tid
= osd
->objecter
->read(
2811 soid
.oid
, oloc
, obj_op
,
2812 m
->get_snapid(), NULL
,
2813 flags
, new C_OnFinisher(fin
, &osd
->objecter_finisher
),
2814 &prdop
->user_version
,
2815 &prdop
->data_offset
,
2818 prdop
->objecter_tid
= tid
;
2819 proxyread_ops
[tid
] = prdop
;
2820 in_progress_proxy_ops
[soid
].push_back(op
);
2823 void PrimaryLogPG::finish_proxy_read(hobject_t oid
, ceph_tid_t tid
, int r
)
2825 dout(10) << __func__
<< " " << oid
<< " tid " << tid
2826 << " " << cpp_strerror(r
) << dendl
;
2828 map
<ceph_tid_t
, ProxyReadOpRef
>::iterator p
= proxyread_ops
.find(tid
);
2829 if (p
== proxyread_ops
.end()) {
2830 dout(10) << __func__
<< " no proxyread_op found" << dendl
;
2833 ProxyReadOpRef prdop
= p
->second
;
2834 if (tid
!= prdop
->objecter_tid
) {
2835 dout(10) << __func__
<< " tid " << tid
<< " != prdop " << prdop
2836 << " tid " << prdop
->objecter_tid
<< dendl
;
2839 if (oid
!= prdop
->soid
) {
2840 dout(10) << __func__
<< " oid " << oid
<< " != prdop " << prdop
2841 << " soid " << prdop
->soid
<< dendl
;
2844 proxyread_ops
.erase(tid
);
2846 map
<hobject_t
, list
<OpRequestRef
>>::iterator q
= in_progress_proxy_ops
.find(oid
);
2847 if (q
== in_progress_proxy_ops
.end()) {
2848 dout(10) << __func__
<< " no in_progress_proxy_ops found" << dendl
;
2851 assert(q
->second
.size());
2852 list
<OpRequestRef
>::iterator it
= std::find(q
->second
.begin(),
2855 assert(it
!= q
->second
.end());
2856 OpRequestRef op
= *it
;
2857 q
->second
.erase(it
);
2858 if (q
->second
.size() == 0) {
2859 in_progress_proxy_ops
.erase(oid
);
2862 osd
->logger
->inc(l_osd_tier_proxy_read
);
2864 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
2865 OpContext
*ctx
= new OpContext(op
, m
->get_reqid(), &prdop
->ops
, this);
2866 ctx
->reply
= new MOSDOpReply(m
, 0, get_osdmap()->get_epoch(), 0, false);
2867 ctx
->user_at_version
= prdop
->user_version
;
2868 ctx
->data_off
= prdop
->data_offset
;
2869 ctx
->ignore_log_op_stats
= true;
2870 complete_read_ctx(r
, ctx
);
2873 void PrimaryLogPG::kick_proxy_ops_blocked(hobject_t
& soid
)
2875 map
<hobject_t
, list
<OpRequestRef
>>::iterator p
= in_progress_proxy_ops
.find(soid
);
2876 if (p
== in_progress_proxy_ops
.end())
2879 list
<OpRequestRef
>& ls
= p
->second
;
2880 dout(10) << __func__
<< " " << soid
<< " requeuing " << ls
.size() << " requests" << dendl
;
2882 in_progress_proxy_ops
.erase(p
);
2885 void PrimaryLogPG::cancel_proxy_read(ProxyReadOpRef prdop
)
2887 dout(10) << __func__
<< " " << prdop
->soid
<< dendl
;
2888 prdop
->canceled
= true;
2890 // cancel objecter op, if we can
2891 if (prdop
->objecter_tid
) {
2892 osd
->objecter
->op_cancel(prdop
->objecter_tid
, -ECANCELED
);
2893 for (uint32_t i
= 0; i
< prdop
->ops
.size(); i
++) {
2894 prdop
->ops
[i
].outdata
.clear();
2896 proxyread_ops
.erase(prdop
->objecter_tid
);
2897 prdop
->objecter_tid
= 0;
2901 void PrimaryLogPG::cancel_proxy_ops(bool requeue
)
2903 dout(10) << __func__
<< dendl
;
2905 // cancel proxy reads
2906 map
<ceph_tid_t
, ProxyReadOpRef
>::iterator p
= proxyread_ops
.begin();
2907 while (p
!= proxyread_ops
.end()) {
2908 cancel_proxy_read((p
++)->second
);
2911 // cancel proxy writes
2912 map
<ceph_tid_t
, ProxyWriteOpRef
>::iterator q
= proxywrite_ops
.begin();
2913 while (q
!= proxywrite_ops
.end()) {
2914 cancel_proxy_write((q
++)->second
);
2918 map
<hobject_t
, list
<OpRequestRef
>>::iterator p
=
2919 in_progress_proxy_ops
.begin();
2920 while (p
!= in_progress_proxy_ops
.end()) {
2921 list
<OpRequestRef
>& ls
= p
->second
;
2922 dout(10) << __func__
<< " " << p
->first
<< " requeuing " << ls
.size()
2923 << " requests" << dendl
;
2925 in_progress_proxy_ops
.erase(p
++);
2928 in_progress_proxy_ops
.clear();
2932 struct C_ProxyWrite_Commit
: public Context
{
2935 epoch_t last_peering_reset
;
2937 PrimaryLogPG::ProxyWriteOpRef pwop
;
2938 C_ProxyWrite_Commit(PrimaryLogPG
*p
, hobject_t o
, epoch_t lpr
,
2939 const PrimaryLogPG::ProxyWriteOpRef
& pw
)
2940 : pg(p
), oid(o
), last_peering_reset(lpr
),
2943 void finish(int r
) override
{
2947 if (pwop
->canceled
) {
2951 if (last_peering_reset
== pg
->get_last_peering_reset()) {
2952 pg
->finish_proxy_write(oid
, tid
, r
);
2958 void PrimaryLogPG::do_proxy_write(OpRequestRef op
, const hobject_t
& missing_oid
, ObjectContextRef obc
)
2960 // NOTE: non-const because ProxyWriteOp takes a mutable ref
2961 MOSDOp
*m
= static_cast<MOSDOp
*>(op
->get_nonconst_req());
2962 object_locator_t oloc
;
2963 SnapContext
snapc(m
->get_snap_seq(), m
->get_snaps());
2965 /* extensible tier */
2966 if (obc
&& obc
->obs
.exists
&& obc
->obs
.oi
.has_manifest()) {
2967 switch (obc
->obs
.oi
.manifest
.type
) {
2968 case object_manifest_t::TYPE_REDIRECT
:
2969 oloc
= object_locator_t(obc
->obs
.oi
.manifest
.redirect_target
);
2970 soid
= obc
->obs
.oi
.manifest
.redirect_target
;
2972 case object_manifest_t::TYPE_CHUNKED
:
2974 assert(0 == "unrecognized manifest type");
2978 soid
= m
->get_hobj();
2979 oloc
= object_locator_t(m
->get_object_locator());
2980 oloc
.pool
= pool
.info
.tier_of
;
2983 unsigned flags
= CEPH_OSD_FLAG_IGNORE_CACHE
| CEPH_OSD_FLAG_IGNORE_OVERLAY
;
2984 if (!(op
->may_write() || op
->may_cache())) {
2985 flags
|= CEPH_OSD_FLAG_RWORDERED
;
2987 dout(10) << __func__
<< " Start proxy write for " << *m
<< dendl
;
2989 ProxyWriteOpRef
pwop(std::make_shared
<ProxyWriteOp
>(op
, soid
, m
->ops
, m
->get_reqid()));
2990 pwop
->ctx
= new OpContext(op
, m
->get_reqid(), &pwop
->ops
, this);
2991 pwop
->mtime
= m
->get_mtime();
2993 ObjectOperation obj_op
;
2994 obj_op
.dup(pwop
->ops
);
2996 C_ProxyWrite_Commit
*fin
= new C_ProxyWrite_Commit(
2997 this, soid
, get_last_peering_reset(), pwop
);
2998 ceph_tid_t tid
= osd
->objecter
->mutate(
2999 soid
.oid
, oloc
, obj_op
, snapc
,
3000 ceph::real_clock::from_ceph_timespec(pwop
->mtime
),
3001 flags
, new C_OnFinisher(fin
, &osd
->objecter_finisher
),
3002 &pwop
->user_version
, pwop
->reqid
);
3004 pwop
->objecter_tid
= tid
;
3005 proxywrite_ops
[tid
] = pwop
;
3006 in_progress_proxy_ops
[soid
].push_back(op
);
3009 void PrimaryLogPG::finish_proxy_write(hobject_t oid
, ceph_tid_t tid
, int r
)
3011 dout(10) << __func__
<< " " << oid
<< " tid " << tid
3012 << " " << cpp_strerror(r
) << dendl
;
3014 map
<ceph_tid_t
, ProxyWriteOpRef
>::iterator p
= proxywrite_ops
.find(tid
);
3015 if (p
== proxywrite_ops
.end()) {
3016 dout(10) << __func__
<< " no proxywrite_op found" << dendl
;
3019 ProxyWriteOpRef pwop
= p
->second
;
3020 assert(tid
== pwop
->objecter_tid
);
3021 assert(oid
== pwop
->soid
);
3023 proxywrite_ops
.erase(tid
);
3025 map
<hobject_t
, list
<OpRequestRef
> >::iterator q
= in_progress_proxy_ops
.find(oid
);
3026 if (q
== in_progress_proxy_ops
.end()) {
3027 dout(10) << __func__
<< " no in_progress_proxy_ops found" << dendl
;
3032 list
<OpRequestRef
>& in_progress_op
= q
->second
;
3033 assert(in_progress_op
.size());
3034 list
<OpRequestRef
>::iterator it
= std::find(in_progress_op
.begin(),
3035 in_progress_op
.end(),
3037 assert(it
!= in_progress_op
.end());
3038 in_progress_op
.erase(it
);
3039 if (in_progress_op
.size() == 0) {
3040 in_progress_proxy_ops
.erase(oid
);
3043 osd
->logger
->inc(l_osd_tier_proxy_write
);
3045 const MOSDOp
*m
= static_cast<const MOSDOp
*>(pwop
->op
->get_req());
3048 if (!pwop
->sent_reply
) {
3050 MOSDOpReply
*reply
= pwop
->ctx
->reply
;
3052 pwop
->ctx
->reply
= NULL
;
3054 reply
= new MOSDOpReply(m
, r
, get_osdmap()->get_epoch(), 0, true);
3055 reply
->set_reply_versions(eversion_t(), pwop
->user_version
);
3057 reply
->add_flags(CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
3058 dout(10) << " sending commit on " << pwop
<< " " << reply
<< dendl
;
3059 osd
->send_message_osd_client(reply
, m
->get_connection());
3060 pwop
->sent_reply
= true;
3061 pwop
->ctx
->op
->mark_commit_sent();
3068 void PrimaryLogPG::cancel_proxy_write(ProxyWriteOpRef pwop
)
3070 dout(10) << __func__
<< " " << pwop
->soid
<< dendl
;
3071 pwop
->canceled
= true;
3073 // cancel objecter op, if we can
3074 if (pwop
->objecter_tid
) {
3075 osd
->objecter
->op_cancel(pwop
->objecter_tid
, -ECANCELED
);
3078 proxywrite_ops
.erase(pwop
->objecter_tid
);
3079 pwop
->objecter_tid
= 0;
3083 class PromoteCallback
: public PrimaryLogPG::CopyCallback
{
3084 ObjectContextRef obc
;
3088 PromoteCallback(ObjectContextRef obc_
, PrimaryLogPG
*pg_
)
3091 start(ceph_clock_now()) {}
3093 void finish(PrimaryLogPG::CopyCallbackResults results
) override
{
3094 PrimaryLogPG::CopyResults
*results_data
= results
.get
<1>();
3095 int r
= results
.get
<0>();
3096 pg
->finish_promote(r
, results_data
, obc
);
3097 pg
->osd
->logger
->tinc(l_osd_tier_promote_lat
, ceph_clock_now() - start
);
3101 void PrimaryLogPG::promote_object(ObjectContextRef obc
,
3102 const hobject_t
& missing_oid
,
3103 const object_locator_t
& oloc
,
3105 ObjectContextRef
*promote_obc
)
3107 hobject_t hoid
= obc
? obc
->obs
.oi
.soid
: missing_oid
;
3108 assert(hoid
!= hobject_t());
3109 if (scrubber
.write_blocked_by_scrub(hoid
)) {
3110 dout(10) << __func__
<< " " << hoid
3111 << " blocked by scrub" << dendl
;
3113 waiting_for_scrub
.push_back(op
);
3114 op
->mark_delayed("waiting for scrub");
3115 dout(10) << __func__
<< " " << hoid
3116 << " placing op in waiting_for_scrub" << dendl
;
3118 dout(10) << __func__
<< " " << hoid
3119 << " no op, dropping on the floor" << dendl
;
3123 if (!obc
) { // we need to create an ObjectContext
3124 assert(missing_oid
!= hobject_t());
3125 obc
= get_object_context(missing_oid
, true);
3131 * Before promote complete, if there are proxy-reads for the object,
3132 * for this case we don't use DONTNEED.
3134 unsigned src_fadvise_flags
= LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL
;
3135 map
<hobject_t
, list
<OpRequestRef
>>::iterator q
= in_progress_proxy_ops
.find(obc
->obs
.oi
.soid
);
3136 if (q
== in_progress_proxy_ops
.end()) {
3137 src_fadvise_flags
|= LIBRADOS_OP_FLAG_FADVISE_DONTNEED
;
3140 PromoteCallback
*cb
= new PromoteCallback(obc
, this);
3141 object_locator_t my_oloc
= oloc
;
3142 my_oloc
.pool
= pool
.info
.tier_of
;
3144 unsigned flags
= CEPH_OSD_COPY_FROM_FLAG_IGNORE_OVERLAY
|
3145 CEPH_OSD_COPY_FROM_FLAG_IGNORE_CACHE
|
3146 CEPH_OSD_COPY_FROM_FLAG_MAP_SNAP_CLONE
|
3147 CEPH_OSD_COPY_FROM_FLAG_RWORDERED
;
3148 start_copy(cb
, obc
, obc
->obs
.oi
.soid
, my_oloc
, 0, flags
,
3149 obc
->obs
.oi
.soid
.snap
== CEPH_NOSNAP
,
3150 src_fadvise_flags
, 0);
3152 assert(obc
->is_blocked());
3155 wait_for_blocked_object(obc
->obs
.oi
.soid
, op
);
3156 info
.stats
.stats
.sum
.num_promote
++;
3159 void PrimaryLogPG::execute_ctx(OpContext
*ctx
)
3162 dout(10) << __func__
<< " " << ctx
<< dendl
;
3163 ctx
->reset_obs(ctx
->obc
);
3164 ctx
->update_log_only
= false; // reset in case finish_copyfrom() is re-running execute_ctx
3165 OpRequestRef op
= ctx
->op
;
3166 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
3167 ObjectContextRef obc
= ctx
->obc
;
3168 const hobject_t
& soid
= obc
->obs
.oi
.soid
;
3170 // this method must be idempotent since we may call it several times
3171 // before we finally apply the resulting transaction.
3172 ctx
->op_t
.reset(new PGTransaction
);
3174 if (op
->may_write() || op
->may_cache()) {
3176 if (!(m
->has_flag(CEPH_OSD_FLAG_ENFORCE_SNAPC
)) &&
3177 pool
.info
.is_pool_snaps_mode()) {
3179 ctx
->snapc
= pool
.snapc
;
3181 // client specified snapc
3182 ctx
->snapc
.seq
= m
->get_snap_seq();
3183 ctx
->snapc
.snaps
= m
->get_snaps();
3184 filter_snapc(ctx
->snapc
.snaps
);
3186 if ((m
->has_flag(CEPH_OSD_FLAG_ORDERSNAP
)) &&
3187 ctx
->snapc
.seq
< obc
->ssc
->snapset
.seq
) {
3188 dout(10) << " ORDERSNAP flag set and snapc seq " << ctx
->snapc
.seq
3189 << " < snapset seq " << obc
->ssc
->snapset
.seq
3190 << " on " << obc
->obs
.oi
.soid
<< dendl
;
3191 reply_ctx(ctx
, -EOLDSNAPC
);
3196 ctx
->at_version
= get_next_version();
3197 ctx
->mtime
= m
->get_mtime();
3199 dout(10) << __func__
<< " " << soid
<< " " << *ctx
->ops
3200 << " ov " << obc
->obs
.oi
.version
<< " av " << ctx
->at_version
3201 << " snapc " << ctx
->snapc
3202 << " snapset " << obc
->ssc
->snapset
3205 dout(10) << __func__
<< " " << soid
<< " " << *ctx
->ops
3206 << " ov " << obc
->obs
.oi
.version
3210 if (!ctx
->user_at_version
)
3211 ctx
->user_at_version
= obc
->obs
.oi
.user_version
;
3212 dout(30) << __func__
<< " user_at_version " << ctx
->user_at_version
<< dendl
;
3214 if (op
->may_read()) {
3215 dout(10) << " taking ondisk_read_lock" << dendl
;
3216 obc
->ondisk_read_lock();
3221 osd_reqid_t reqid
= ctx
->op
->get_reqid();
3223 tracepoint(osd
, prepare_tx_enter
, reqid
.name
._type
,
3224 reqid
.name
._num
, reqid
.tid
, reqid
.inc
);
3227 int result
= prepare_transaction(ctx
);
3231 osd_reqid_t reqid
= ctx
->op
->get_reqid();
3233 tracepoint(osd
, prepare_tx_exit
, reqid
.name
._type
,
3234 reqid
.name
._num
, reqid
.tid
, reqid
.inc
);
3237 if (op
->may_read()) {
3238 dout(10) << " dropping ondisk_read_lock" << dendl
;
3239 obc
->ondisk_read_unlock();
3242 bool pending_async_reads
= !ctx
->pending_async_reads
.empty();
3243 if (result
== -EINPROGRESS
|| pending_async_reads
) {
3245 if (pending_async_reads
) {
3246 in_progress_async_reads
.push_back(make_pair(op
, ctx
));
3247 ctx
->start_async_reads(this);
3252 if (result
== -EAGAIN
) {
3253 // clean up after the ctx
3258 bool successful_write
= !ctx
->op_t
->empty() && op
->may_write() && result
>= 0;
3259 // prepare the reply
3260 ctx
->reply
= new MOSDOpReply(m
, 0, get_osdmap()->get_epoch(), 0,
3263 // Write operations aren't allowed to return a data payload because
3264 // we can't do so reliably. If the client has to resend the request
3265 // and it has already been applied, we will return 0 with no
3266 // payload. Non-deterministic behavior is no good. However, it is
3267 // possible to construct an operation that does a read, does a guard
3268 // check (e.g., CMPXATTR), and then a write. Then we either succeed
3269 // with the write, or return a CMPXATTR and the read value.
3270 if (successful_write
) {
3271 // write. normalize the result code.
3272 dout(20) << " zeroing write result code " << result
<< dendl
;
3275 ctx
->reply
->set_result(result
);
3278 if ((ctx
->op_t
->empty() || result
< 0) && !ctx
->update_log_only
) {
3279 // finish side-effects
3281 do_osd_op_effects(ctx
, m
->get_connection());
3283 complete_read_ctx(result
, ctx
);
3287 ctx
->reply
->set_reply_versions(ctx
->at_version
, ctx
->user_at_version
);
3289 assert(op
->may_write() || op
->may_cache());
3294 // verify that we are doing this in order?
3295 if (cct
->_conf
->osd_debug_op_order
&& m
->get_source().is_client() &&
3296 !pool
.info
.is_tier() && !pool
.info
.has_tiers()) {
3297 map
<client_t
,ceph_tid_t
>& cm
= debug_op_order
[obc
->obs
.oi
.soid
];
3298 ceph_tid_t t
= m
->get_tid();
3299 client_t n
= m
->get_source().num();
3300 map
<client_t
,ceph_tid_t
>::iterator p
= cm
.find(n
);
3301 if (p
== cm
.end()) {
3302 dout(20) << " op order client." << n
<< " tid " << t
<< " (first)" << dendl
;
3305 dout(20) << " op order client." << n
<< " tid " << t
<< " last was " << p
->second
<< dendl
;
3306 if (p
->second
> t
) {
3307 derr
<< "bad op order, already applied " << p
->second
<< " > this " << t
<< dendl
;
3308 assert(0 == "out of order op");
3314 if (ctx
->update_log_only
) {
3316 do_osd_op_effects(ctx
, m
->get_connection());
3318 dout(20) << __func__
<< " update_log_only -- result=" << result
<< dendl
;
3319 // save just what we need from ctx
3320 MOSDOpReply
*reply
= ctx
->reply
;
3321 ctx
->reply
= nullptr;
3322 reply
->claim_op_out_data(*ctx
->ops
);
3323 reply
->get_header().data_off
= (ctx
->data_off
? *ctx
->data_off
: 0);
3326 if (result
== -ENOENT
) {
3327 reply
->set_enoent_reply_versions(info
.last_update
,
3328 info
.last_user_version
);
3330 reply
->add_flags(CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
3331 // append to pg log for dup detection - don't save buffers for now
3332 record_write_error(op
, soid
, reply
, result
);
3336 // no need to capture PG ref, repop cancel will handle that
3337 // Can capture the ctx by pointer, it's owned by the repop
3338 ctx
->register_on_commit(
3344 if (m
&& !ctx
->sent_reply
) {
3345 MOSDOpReply
*reply
= ctx
->reply
;
3347 ctx
->reply
= nullptr;
3349 reply
= new MOSDOpReply(m
, 0, get_osdmap()->get_epoch(), 0, true);
3350 reply
->set_reply_versions(ctx
->at_version
,
3351 ctx
->user_at_version
);
3353 reply
->add_flags(CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
3354 dout(10) << " sending reply on " << *m
<< " " << reply
<< dendl
;
3355 osd
->send_message_osd_client(reply
, m
->get_connection());
3356 ctx
->sent_reply
= true;
3357 ctx
->op
->mark_commit_sent();
3360 ctx
->register_on_success(
3364 ctx
->op
? ctx
->op
->get_req()->get_connection() :
3367 ctx
->register_on_finish(
3372 // issue replica writes
3373 ceph_tid_t rep_tid
= osd
->get_tid();
3375 RepGather
*repop
= new_repop(ctx
, obc
, rep_tid
);
3377 issue_repop(repop
, ctx
);
3382 void PrimaryLogPG::close_op_ctx(OpContext
*ctx
) {
3383 release_object_locks(ctx
->lock_manager
);
3387 for (auto p
= ctx
->on_finish
.begin(); p
!= ctx
->on_finish
.end();
3388 ctx
->on_finish
.erase(p
++)) {
3394 void PrimaryLogPG::reply_ctx(OpContext
*ctx
, int r
)
3397 osd
->reply_op_error(ctx
->op
, r
);
3401 void PrimaryLogPG::reply_ctx(OpContext
*ctx
, int r
, eversion_t v
, version_t uv
)
3404 osd
->reply_op_error(ctx
->op
, r
, v
, uv
);
3408 void PrimaryLogPG::log_op_stats(OpContext
*ctx
)
3410 OpRequestRef op
= ctx
->op
;
3411 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
3413 utime_t now
= ceph_clock_now();
3414 utime_t latency
= now
;
3415 latency
-= ctx
->op
->get_req()->get_recv_stamp();
3416 utime_t process_latency
= now
;
3417 process_latency
-= ctx
->op
->get_dequeued_time();
3419 uint64_t inb
= ctx
->bytes_written
;
3420 uint64_t outb
= ctx
->bytes_read
;
3422 osd
->logger
->inc(l_osd_op
);
3424 osd
->logger
->inc(l_osd_op_outb
, outb
);
3425 osd
->logger
->inc(l_osd_op_inb
, inb
);
3426 osd
->logger
->tinc(l_osd_op_lat
, latency
);
3427 osd
->logger
->tinc(l_osd_op_process_lat
, process_latency
);
3429 if (op
->may_read() && op
->may_write()) {
3430 osd
->logger
->inc(l_osd_op_rw
);
3431 osd
->logger
->inc(l_osd_op_rw_inb
, inb
);
3432 osd
->logger
->inc(l_osd_op_rw_outb
, outb
);
3433 osd
->logger
->tinc(l_osd_op_rw_lat
, latency
);
3434 osd
->logger
->hinc(l_osd_op_rw_lat_inb_hist
, latency
.to_nsec(), inb
);
3435 osd
->logger
->hinc(l_osd_op_rw_lat_outb_hist
, latency
.to_nsec(), outb
);
3436 osd
->logger
->tinc(l_osd_op_rw_process_lat
, process_latency
);
3437 } else if (op
->may_read()) {
3438 osd
->logger
->inc(l_osd_op_r
);
3439 osd
->logger
->inc(l_osd_op_r_outb
, outb
);
3440 osd
->logger
->tinc(l_osd_op_r_lat
, latency
);
3441 osd
->logger
->hinc(l_osd_op_r_lat_outb_hist
, latency
.to_nsec(), outb
);
3442 osd
->logger
->tinc(l_osd_op_r_process_lat
, process_latency
);
3443 } else if (op
->may_write() || op
->may_cache()) {
3444 osd
->logger
->inc(l_osd_op_w
);
3445 osd
->logger
->inc(l_osd_op_w_inb
, inb
);
3446 osd
->logger
->tinc(l_osd_op_w_lat
, latency
);
3447 osd
->logger
->hinc(l_osd_op_w_lat_inb_hist
, latency
.to_nsec(), inb
);
3448 osd
->logger
->tinc(l_osd_op_w_process_lat
, process_latency
);
3452 dout(15) << "log_op_stats " << *m
3455 << " lat " << latency
<< dendl
;
3458 void PrimaryLogPG::do_sub_op(OpRequestRef op
)
3460 const MOSDSubOp
*m
= static_cast<const MOSDSubOp
*>(op
->get_req());
3461 assert(have_same_or_newer_map(m
->map_epoch
));
3462 assert(m
->get_type() == MSG_OSD_SUBOP
);
3463 dout(15) << "do_sub_op " << *op
->get_req() << dendl
;
3466 waiting_for_peered
.push_back(op
);
3467 op
->mark_delayed("waiting for active");
3471 const OSDOp
*first
= NULL
;
3472 if (m
->ops
.size() >= 1) {
3477 switch (first
->op
.op
) {
3478 case CEPH_OSD_OP_DELETE
:
3481 case CEPH_OSD_OP_SCRUB_RESERVE
:
3482 handle_scrub_reserve_request(op
);
3484 case CEPH_OSD_OP_SCRUB_UNRESERVE
:
3485 handle_scrub_reserve_release(op
);
3487 case CEPH_OSD_OP_SCRUB_MAP
:
3488 sub_op_scrub_map(op
);
3494 void PrimaryLogPG::do_sub_op_reply(OpRequestRef op
)
3496 const MOSDSubOpReply
*r
= static_cast<const MOSDSubOpReply
*>(op
->get_req());
3497 assert(r
->get_type() == MSG_OSD_SUBOPREPLY
);
3498 if (r
->ops
.size() >= 1) {
3499 const OSDOp
& first
= r
->ops
[0];
3500 switch (first
.op
.op
) {
3501 case CEPH_OSD_OP_SCRUB_RESERVE
:
3503 pg_shard_t from
= r
->from
;
3504 bufferlist::iterator p
= const_cast<bufferlist
&>(r
->get_data()).begin();
3506 ::decode(reserved
, p
);
3508 handle_scrub_reserve_grant(op
, from
);
3510 handle_scrub_reserve_reject(op
, from
);
3518 void PrimaryLogPG::do_scan(
3520 ThreadPool::TPHandle
&handle
)
3522 const MOSDPGScan
*m
= static_cast<const MOSDPGScan
*>(op
->get_req());
3523 assert(m
->get_type() == MSG_OSD_PG_SCAN
);
3524 dout(10) << "do_scan " << *m
<< dendl
;
3529 case MOSDPGScan::OP_SCAN_GET_DIGEST
:
3532 if (osd
->check_backfill_full(ss
)) {
3533 dout(1) << __func__
<< ": Canceling backfill, " << ss
.str() << dendl
;
3534 queue_peering_event(
3536 std::make_shared
<CephPeeringEvt
>(
3537 get_osdmap()->get_epoch(),
3538 get_osdmap()->get_epoch(),
3539 BackfillTooFull())));
3543 BackfillInterval bi
;
3544 bi
.begin
= m
->begin
;
3545 // No need to flush, there won't be any in progress writes occuring
3548 cct
->_conf
->osd_backfill_scan_min
,
3549 cct
->_conf
->osd_backfill_scan_max
,
3552 MOSDPGScan
*reply
= new MOSDPGScan(
3553 MOSDPGScan::OP_SCAN_DIGEST
,
3555 get_osdmap()->get_epoch(), m
->query_epoch
,
3556 spg_t(info
.pgid
.pgid
, get_primary().shard
), bi
.begin
, bi
.end
);
3557 ::encode(bi
.objects
, reply
->get_data());
3558 osd
->send_message_osd_cluster(reply
, m
->get_connection());
3562 case MOSDPGScan::OP_SCAN_DIGEST
:
3564 pg_shard_t from
= m
->from
;
3566 // Check that from is in backfill_targets vector
3567 assert(is_backfill_targets(from
));
3569 BackfillInterval
& bi
= peer_backfill_info
[from
];
3570 bi
.begin
= m
->begin
;
3572 bufferlist::iterator p
= const_cast<bufferlist
&>(m
->get_data()).begin();
3574 // take care to preserve ordering!
3576 ::decode_noclear(bi
.objects
, p
);
3578 if (waiting_on_backfill
.erase(from
)) {
3579 if (waiting_on_backfill
.empty()) {
3580 assert(peer_backfill_info
.size() == backfill_targets
.size());
3581 finish_recovery_op(hobject_t::get_max());
3584 // we canceled backfill for a while due to a too full, and this
3585 // is an extra response from a non-too-full peer
3592 void PrimaryLogPG::do_backfill(OpRequestRef op
)
3594 const MOSDPGBackfill
*m
= static_cast<const MOSDPGBackfill
*>(op
->get_req());
3595 assert(m
->get_type() == MSG_OSD_PG_BACKFILL
);
3596 dout(10) << "do_backfill " << *m
<< dendl
;
3601 case MOSDPGBackfill::OP_BACKFILL_FINISH
:
3603 assert(cct
->_conf
->osd_kill_backfill_at
!= 1);
3605 MOSDPGBackfill
*reply
= new MOSDPGBackfill(
3606 MOSDPGBackfill::OP_BACKFILL_FINISH_ACK
,
3607 get_osdmap()->get_epoch(),
3609 spg_t(info
.pgid
.pgid
, get_primary().shard
));
3610 reply
->set_priority(get_recovery_op_priority());
3611 osd
->send_message_osd_cluster(reply
, m
->get_connection());
3612 queue_peering_event(
3614 std::make_shared
<CephPeeringEvt
>(
3615 get_osdmap()->get_epoch(),
3616 get_osdmap()->get_epoch(),
3621 case MOSDPGBackfill::OP_BACKFILL_PROGRESS
:
3623 assert(cct
->_conf
->osd_kill_backfill_at
!= 2);
3625 info
.set_last_backfill(m
->last_backfill
);
3626 info
.stats
= m
->stats
;
3628 ObjectStore::Transaction t
;
3631 int tr
= osd
->store
->queue_transaction(osr
.get(), std::move(t
), NULL
);
3636 case MOSDPGBackfill::OP_BACKFILL_FINISH_ACK
:
3638 assert(is_primary());
3639 assert(cct
->_conf
->osd_kill_backfill_at
!= 3);
3640 finish_recovery_op(hobject_t::get_max());
3646 void PrimaryLogPG::do_backfill_remove(OpRequestRef op
)
3648 const MOSDPGBackfillRemove
*m
= static_cast<const MOSDPGBackfillRemove
*>(
3650 assert(m
->get_type() == MSG_OSD_PG_BACKFILL_REMOVE
);
3651 dout(7) << __func__
<< " " << m
->ls
<< dendl
;
3655 ObjectStore::Transaction t
;
3656 for (auto& p
: m
->ls
) {
3657 remove_snap_mapped_object(t
, p
.first
);
3659 int r
= osd
->store
->queue_transaction(osr
.get(), std::move(t
), NULL
);
3663 int PrimaryLogPG::trim_object(
3664 bool first
, const hobject_t
&coid
, PrimaryLogPG::OpContextUPtr
*ctxp
)
3669 ObjectContextRef obc
= get_object_context(coid
, false, NULL
);
3670 if (!obc
|| !obc
->ssc
|| !obc
->ssc
->exists
) {
3671 osd
->clog
->error() << __func__
<< ": Can not trim " << coid
3672 << " repair needed " << (obc
? "(no obc->ssc or !exists)" : "(no obc)");
3677 coid
.oid
, coid
.get_key(),
3678 obc
->ssc
->snapset
.head_exists
? CEPH_NOSNAP
:CEPH_SNAPDIR
, coid
.get_hash(),
3679 info
.pgid
.pool(), coid
.get_namespace());
3680 ObjectContextRef snapset_obc
= get_object_context(snapoid
, false);
3682 osd
->clog
->error() << __func__
<< ": Can not trim " << coid
3683 << " repair needed, no snapset obc for " << snapoid
;
3687 SnapSet
& snapset
= obc
->ssc
->snapset
;
3689 bool legacy
= snapset
.is_legacy() ||
3690 get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
;
3692 object_info_t
&coi
= obc
->obs
.oi
;
3693 set
<snapid_t
> old_snaps
;
3695 old_snaps
.insert(coi
.legacy_snaps
.begin(), coi
.legacy_snaps
.end());
3697 auto p
= snapset
.clone_snaps
.find(coid
.snap
);
3698 if (p
== snapset
.clone_snaps
.end()) {
3699 osd
->clog
->error() << "No clone_snaps in snapset " << snapset
3700 << " for object " << coid
<< "\n";
3703 old_snaps
.insert(snapset
.clone_snaps
[coid
.snap
].begin(),
3704 snapset
.clone_snaps
[coid
.snap
].end());
3706 if (old_snaps
.empty()) {
3707 osd
->clog
->error() << "No object info snaps for object " << coid
;
3711 dout(10) << coid
<< " old_snaps " << old_snaps
3712 << " old snapset " << snapset
<< dendl
;
3713 if (snapset
.seq
== 0) {
3714 osd
->clog
->error() << "No snapset.seq for object " << coid
;
3718 set
<snapid_t
> new_snaps
;
3719 for (set
<snapid_t
>::iterator i
= old_snaps
.begin();
3720 i
!= old_snaps
.end();
3722 if (!pool
.info
.is_removed_snap(*i
))
3723 new_snaps
.insert(*i
);
3726 vector
<snapid_t
>::iterator p
= snapset
.clones
.end();
3728 if (new_snaps
.empty()) {
3729 p
= std::find(snapset
.clones
.begin(), snapset
.clones
.end(), coid
.snap
);
3730 if (p
== snapset
.clones
.end()) {
3731 osd
->clog
->error() << "Snap " << coid
.snap
<< " not in clones";
3736 OpContextUPtr ctx
= simple_opc_create(obc
);
3737 ctx
->snapset_obc
= snapset_obc
;
3739 if (!ctx
->lock_manager
.get_snaptrimmer_write(
3743 close_op_ctx(ctx
.release());
3744 dout(10) << __func__
<< ": Unable to get a wlock on " << coid
<< dendl
;
3748 if (!ctx
->lock_manager
.get_snaptrimmer_write(
3752 close_op_ctx(ctx
.release());
3753 dout(10) << __func__
<< ": Unable to get a wlock on " << snapoid
<< dendl
;
3757 ctx
->at_version
= get_next_version();
3759 PGTransaction
*t
= ctx
->op_t
.get();
3761 if (new_snaps
.empty()) {
3763 dout(10) << coid
<< " snaps " << old_snaps
<< " -> "
3764 << new_snaps
<< " ... deleting" << dendl
;
3767 assert(p
!= snapset
.clones
.end());
3769 snapid_t last
= coid
.snap
;
3770 ctx
->delta_stats
.num_bytes
-= snapset
.get_clone_bytes(last
);
3772 if (p
!= snapset
.clones
.begin()) {
3773 // not the oldest... merge overlap into next older clone
3774 vector
<snapid_t
>::iterator n
= p
- 1;
3775 hobject_t prev_coid
= coid
;
3776 prev_coid
.snap
= *n
;
3777 bool adjust_prev_bytes
= is_present_clone(prev_coid
);
3779 if (adjust_prev_bytes
)
3780 ctx
->delta_stats
.num_bytes
-= snapset
.get_clone_bytes(*n
);
3782 snapset
.clone_overlap
[*n
].intersection_of(
3783 snapset
.clone_overlap
[*p
]);
3785 if (adjust_prev_bytes
)
3786 ctx
->delta_stats
.num_bytes
+= snapset
.get_clone_bytes(*n
);
3788 ctx
->delta_stats
.num_objects
--;
3790 ctx
->delta_stats
.num_objects_dirty
--;
3792 ctx
->delta_stats
.num_objects_omap
--;
3793 if (coi
.is_whiteout()) {
3794 dout(20) << __func__
<< " trimming whiteout on " << coid
<< dendl
;
3795 ctx
->delta_stats
.num_whiteouts
--;
3797 ctx
->delta_stats
.num_object_clones
--;
3798 if (coi
.is_cache_pinned())
3799 ctx
->delta_stats
.num_objects_pinned
--;
3800 obc
->obs
.exists
= false;
3802 snapset
.clones
.erase(p
);
3803 snapset
.clone_overlap
.erase(last
);
3804 snapset
.clone_size
.erase(last
);
3805 snapset
.clone_snaps
.erase(last
);
3809 pg_log_entry_t::DELETE
,
3812 ctx
->obs
->oi
.version
,
3824 coi
= object_info_t(coid
);
3826 ctx
->at_version
.version
++;
3828 // save adjusted snaps for this object
3829 dout(10) << coid
<< " snaps " << old_snaps
<< " -> " << new_snaps
<< dendl
;
3831 coi
.legacy_snaps
= vector
<snapid_t
>(new_snaps
.rbegin(), new_snaps
.rend());
3833 snapset
.clone_snaps
[coid
.snap
] = vector
<snapid_t
>(new_snaps
.rbegin(),
3835 // we still do a 'modify' event on this object just to trigger a
3836 // snapmapper.update ... :(
3839 coi
.prior_version
= coi
.version
;
3840 coi
.version
= ctx
->at_version
;
3842 ::encode(coi
, bl
, get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
3843 t
->setattr(coid
, OI_ATTR
, bl
);
3847 pg_log_entry_t::MODIFY
,
3856 ctx
->at_version
.version
++;
3864 // save head snapset
3865 dout(10) << coid
<< " new snapset " << snapset
<< " on "
3866 << snapset_obc
->obs
.oi
<< dendl
;
3867 if (snapset
.clones
.empty() &&
3868 (!snapset
.head_exists
||
3869 (snapset_obc
->obs
.oi
.is_whiteout() &&
3870 !(snapset_obc
->obs
.oi
.is_dirty() && pool
.info
.is_tier()) &&
3871 !snapset_obc
->obs
.oi
.is_cache_pinned()))) {
3872 // NOTE: this arguably constitutes minor interference with the
3873 // tiering agent if this is a cache tier since a snap trim event
3874 // is effectively evicting a whiteout we might otherwise want to
3876 dout(10) << coid
<< " removing " << snapoid
<< dendl
;
3879 pg_log_entry_t::DELETE
,
3882 ctx
->snapset_obc
->obs
.oi
.version
,
3888 if (snapoid
.is_head()) {
3889 derr
<< "removing snap head" << dendl
;
3890 object_info_t
& oi
= ctx
->snapset_obc
->obs
.oi
;
3891 ctx
->delta_stats
.num_objects
--;
3892 if (oi
.is_dirty()) {
3893 ctx
->delta_stats
.num_objects_dirty
--;
3896 ctx
->delta_stats
.num_objects_omap
--;
3897 if (oi
.is_whiteout()) {
3898 dout(20) << __func__
<< " trimming whiteout on " << oi
.soid
<< dendl
;
3899 ctx
->delta_stats
.num_whiteouts
--;
3901 if (oi
.is_cache_pinned()) {
3902 ctx
->delta_stats
.num_objects_pinned
--;
3905 ctx
->snapset_obc
->obs
.exists
= false;
3906 ctx
->snapset_obc
->obs
.oi
= object_info_t(snapoid
);
3909 dout(10) << coid
<< " filtering snapset on " << snapoid
<< dendl
;
3910 snapset
.filter(pool
.info
);
3911 dout(10) << coid
<< " writing updated snapset on " << snapoid
3912 << ", snapset is " << snapset
<< dendl
;
3915 pg_log_entry_t::MODIFY
,
3918 ctx
->snapset_obc
->obs
.oi
.version
,
3925 ctx
->snapset_obc
->obs
.oi
.prior_version
=
3926 ctx
->snapset_obc
->obs
.oi
.version
;
3927 ctx
->snapset_obc
->obs
.oi
.version
= ctx
->at_version
;
3929 map
<string
, bufferlist
> attrs
;
3931 ::encode(snapset
, bl
);
3932 attrs
[SS_ATTR
].claim(bl
);
3935 ::encode(ctx
->snapset_obc
->obs
.oi
, bl
,
3936 get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
3937 attrs
[OI_ATTR
].claim(bl
);
3938 t
->setattrs(snapoid
, attrs
);
3941 *ctxp
= std::move(ctx
);
3945 void PrimaryLogPG::kick_snap_trim()
3947 assert(is_active());
3948 assert(is_primary());
3949 if (is_clean() && !snap_trimq
.empty()) {
3950 dout(10) << __func__
<< ": clean and snaps to trim, kicking" << dendl
;
3951 snap_trimmer_machine
.process_event(KickTrim());
3955 void PrimaryLogPG::snap_trimmer_scrub_complete()
3957 if (is_primary() && is_active() && is_clean()) {
3958 assert(!snap_trimq
.empty());
3959 snap_trimmer_machine
.process_event(ScrubComplete());
3963 void PrimaryLogPG::snap_trimmer(epoch_t queued
)
3965 if (deleting
|| pg_has_reset_since(queued
)) {
3969 assert(is_primary());
3971 dout(10) << "snap_trimmer posting" << dendl
;
3972 snap_trimmer_machine
.process_event(DoSnapWork());
3973 dout(10) << "snap_trimmer complete" << dendl
;
3977 int PrimaryLogPG::do_xattr_cmp_u64(int op
, __u64 v1
, bufferlist
& xattr
)
3981 string
v2s(xattr
.c_str(), xattr
.length());
3983 v2
= strtoull(v2s
.c_str(), NULL
, 10);
3987 dout(20) << "do_xattr_cmp_u64 '" << v1
<< "' vs '" << v2
<< "' op " << op
<< dendl
;
3990 case CEPH_OSD_CMPXATTR_OP_EQ
:
3992 case CEPH_OSD_CMPXATTR_OP_NE
:
3994 case CEPH_OSD_CMPXATTR_OP_GT
:
3996 case CEPH_OSD_CMPXATTR_OP_GTE
:
3998 case CEPH_OSD_CMPXATTR_OP_LT
:
4000 case CEPH_OSD_CMPXATTR_OP_LTE
:
4007 int PrimaryLogPG::do_xattr_cmp_str(int op
, string
& v1s
, bufferlist
& xattr
)
4009 string
v2s(xattr
.c_str(), xattr
.length());
4011 dout(20) << "do_xattr_cmp_str '" << v1s
<< "' vs '" << v2s
<< "' op " << op
<< dendl
;
4014 case CEPH_OSD_CMPXATTR_OP_EQ
:
4015 return (v1s
.compare(v2s
) == 0);
4016 case CEPH_OSD_CMPXATTR_OP_NE
:
4017 return (v1s
.compare(v2s
) != 0);
4018 case CEPH_OSD_CMPXATTR_OP_GT
:
4019 return (v1s
.compare(v2s
) > 0);
4020 case CEPH_OSD_CMPXATTR_OP_GTE
:
4021 return (v1s
.compare(v2s
) >= 0);
4022 case CEPH_OSD_CMPXATTR_OP_LT
:
4023 return (v1s
.compare(v2s
) < 0);
4024 case CEPH_OSD_CMPXATTR_OP_LTE
:
4025 return (v1s
.compare(v2s
) <= 0);
4031 int PrimaryLogPG::do_writesame(OpContext
*ctx
, OSDOp
& osd_op
)
4033 ceph_osd_op
& op
= osd_op
.op
;
4034 vector
<OSDOp
> write_ops(1);
4035 OSDOp
& write_op
= write_ops
[0];
4036 uint64_t write_length
= op
.writesame
.length
;
4042 if (!op
.writesame
.data_length
|| write_length
% op
.writesame
.data_length
)
4045 if (op
.writesame
.data_length
!= osd_op
.indata
.length()) {
4046 derr
<< "invalid length ws data length " << op
.writesame
.data_length
<< " actual len " << osd_op
.indata
.length() << dendl
;
4050 while (write_length
) {
4051 write_op
.indata
.append(osd_op
.indata
);
4052 write_length
-= op
.writesame
.data_length
;
4055 write_op
.op
.op
= CEPH_OSD_OP_WRITE
;
4056 write_op
.op
.extent
.offset
= op
.writesame
.offset
;
4057 write_op
.op
.extent
.length
= op
.writesame
.length
;
4058 result
= do_osd_ops(ctx
, write_ops
);
4060 derr
<< "do_writesame do_osd_ops failed " << result
<< dendl
;
4065 // ========================================================================
4066 // low level osd ops
4068 int PrimaryLogPG::do_tmap2omap(OpContext
*ctx
, unsigned flags
)
4070 dout(20) << " convert tmap to omap for " << ctx
->new_obs
.oi
.soid
<< dendl
;
4071 bufferlist header
, vals
;
4072 int r
= _get_tmap(ctx
, &header
, &vals
);
4074 if (r
== -ENODATA
&& (flags
& CEPH_OSD_TMAP2OMAP_NULLOK
))
4079 vector
<OSDOp
> ops(3);
4081 ops
[0].op
.op
= CEPH_OSD_OP_TRUNCATE
;
4082 ops
[0].op
.extent
.offset
= 0;
4083 ops
[0].op
.extent
.length
= 0;
4085 ops
[1].op
.op
= CEPH_OSD_OP_OMAPSETHEADER
;
4086 ops
[1].indata
.claim(header
);
4088 ops
[2].op
.op
= CEPH_OSD_OP_OMAPSETVALS
;
4089 ops
[2].indata
.claim(vals
);
4091 return do_osd_ops(ctx
, ops
);
4094 int PrimaryLogPG::do_tmapup_slow(OpContext
*ctx
, bufferlist::iterator
& bp
, OSDOp
& osd_op
,
4099 map
<string
, bufferlist
> m
;
4101 bufferlist::iterator p
= bl
.begin();
4102 ::decode(header
, p
);
4114 case CEPH_OSD_TMAP_SET
: // insert key
4122 case CEPH_OSD_TMAP_RM
: // remove key
4124 if (!m
.count(key
)) {
4129 case CEPH_OSD_TMAP_RMSLOPPY
: // remove key
4133 case CEPH_OSD_TMAP_HDR
: // update header
4135 ::decode(header
, bp
);
4145 ::encode(header
, obl
);
4149 vector
<OSDOp
> nops(1);
4150 OSDOp
& newop
= nops
[0];
4151 newop
.op
.op
= CEPH_OSD_OP_WRITEFULL
;
4152 newop
.op
.extent
.offset
= 0;
4153 newop
.op
.extent
.length
= obl
.length();
4155 do_osd_ops(ctx
, nops
);
4156 osd_op
.outdata
.claim(newop
.outdata
);
4160 int PrimaryLogPG::do_tmapup(OpContext
*ctx
, bufferlist::iterator
& bp
, OSDOp
& osd_op
)
4162 bufferlist::iterator orig_bp
= bp
;
4165 dout(10) << "tmapup is a no-op" << dendl
;
4167 // read the whole object
4168 vector
<OSDOp
> nops(1);
4169 OSDOp
& newop
= nops
[0];
4170 newop
.op
.op
= CEPH_OSD_OP_READ
;
4171 newop
.op
.extent
.offset
= 0;
4172 newop
.op
.extent
.length
= 0;
4173 result
= do_osd_ops(ctx
, nops
);
4175 dout(10) << "tmapup read " << newop
.outdata
.length() << dendl
;
4177 dout(30) << " starting is \n";
4178 newop
.outdata
.hexdump(*_dout
);
4181 bufferlist::iterator ip
= newop
.outdata
.begin();
4184 dout(30) << "the update command is: \n";
4185 osd_op
.indata
.hexdump(*_dout
);
4191 if (newop
.outdata
.length()) {
4192 ::decode(header
, ip
);
4193 ::decode(nkeys
, ip
);
4195 dout(10) << "tmapup header " << header
.length() << dendl
;
4197 if (!bp
.end() && *bp
== CEPH_OSD_TMAP_HDR
) {
4199 ::decode(header
, bp
);
4200 dout(10) << "tmapup new header " << header
.length() << dendl
;
4203 ::encode(header
, obl
);
4205 dout(20) << "tmapup initial nkeys " << nkeys
<< dendl
;
4208 bufferlist newkeydata
;
4209 string nextkey
, last_in_key
;
4211 bool have_next
= false;
4214 ::decode(nextkey
, ip
);
4215 ::decode(nextval
, ip
);
4217 while (!bp
.end() && !result
) {
4224 catch (buffer::error
& e
) {
4227 if (key
< last_in_key
) {
4228 dout(5) << "tmapup warning: key '" << key
<< "' < previous key '" << last_in_key
4229 << "', falling back to an inefficient (unsorted) update" << dendl
;
4231 return do_tmapup_slow(ctx
, bp
, osd_op
, newop
.outdata
);
4235 dout(10) << "tmapup op " << (int)op
<< " key " << key
<< dendl
;
4237 // skip existing intervening keys
4238 bool key_exists
= false;
4239 while (have_next
&& !key_exists
) {
4240 dout(20) << " (have_next=" << have_next
<< " nextkey=" << nextkey
<< ")" << dendl
;
4243 if (nextkey
< key
) {
4245 ::encode(nextkey
, newkeydata
);
4246 ::encode(nextval
, newkeydata
);
4247 dout(20) << " keep " << nextkey
<< " " << nextval
.length() << dendl
;
4249 // don't copy; discard old value. and stop.
4250 dout(20) << " drop " << nextkey
<< " " << nextval
.length() << dendl
;
4255 ::decode(nextkey
, ip
);
4256 ::decode(nextval
, ip
);
4262 if (op
== CEPH_OSD_TMAP_SET
) {
4267 catch (buffer::error
& e
) {
4270 ::encode(key
, newkeydata
);
4271 ::encode(val
, newkeydata
);
4272 dout(20) << " set " << key
<< " " << val
.length() << dendl
;
4274 } else if (op
== CEPH_OSD_TMAP_CREATE
) {
4282 catch (buffer::error
& e
) {
4285 ::encode(key
, newkeydata
);
4286 ::encode(val
, newkeydata
);
4287 dout(20) << " create " << key
<< " " << val
.length() << dendl
;
4289 } else if (op
== CEPH_OSD_TMAP_RM
) {
4294 } else if (op
== CEPH_OSD_TMAP_RMSLOPPY
) {
4297 dout(10) << " invalid tmap op " << (int)op
<< dendl
;
4304 ::encode(nextkey
, newkeydata
);
4305 ::encode(nextval
, newkeydata
);
4306 dout(20) << " keep " << nextkey
<< " " << nextval
.length() << dendl
;
4310 rest
.substr_of(newop
.outdata
, ip
.get_off(), newop
.outdata
.length() - ip
.get_off());
4311 dout(20) << " keep trailing " << rest
.length()
4312 << " at " << newkeydata
.length() << dendl
;
4313 newkeydata
.claim_append(rest
);
4316 // encode final key count + key data
4317 dout(20) << "tmapup final nkeys " << nkeys
<< dendl
;
4318 ::encode(nkeys
, obl
);
4319 obl
.claim_append(newkeydata
);
4322 dout(30) << " final is \n";
4323 obl
.hexdump(*_dout
);
4327 bufferlist::iterator tp
= obl
.begin();
4330 map
<string
,bufferlist
> d
;
4333 dout(0) << " **** debug sanity check, looks ok ****" << dendl
;
4338 dout(20) << "tmapput write " << obl
.length() << dendl
;
4339 newop
.op
.op
= CEPH_OSD_OP_WRITEFULL
;
4340 newop
.op
.extent
.offset
= 0;
4341 newop
.op
.extent
.length
= obl
.length();
4343 do_osd_ops(ctx
, nops
);
4344 osd_op
.outdata
.claim(newop
.outdata
);
4350 static int check_offset_and_length(uint64_t offset
, uint64_t length
, uint64_t max
)
4352 if (offset
>= max
||
4354 offset
+ length
> max
)
4360 struct FillInVerifyExtent
: public Context
{
4363 bufferlist
*outdatap
;
4364 boost::optional
<uint32_t> maybe_crc
;
4369 FillInVerifyExtent(ceph_le64
*r
, int32_t *rv
, bufferlist
*blp
,
4370 boost::optional
<uint32_t> mc
, uint64_t size
,
4371 OSDService
*osd
, hobject_t soid
, __le32 flags
) :
4372 r(r
), rval(rv
), outdatap(blp
), maybe_crc(mc
),
4373 size(size
), osd(osd
), soid(soid
), flags(flags
) {}
4374 void finish(int len
) override
{
4382 // whole object? can we verify the checksum?
4383 if (maybe_crc
&& *r
== size
) {
4384 uint32_t crc
= outdatap
->crc32c(-1);
4385 if (maybe_crc
!= crc
) {
4386 osd
->clog
->error() << std::hex
<< " full-object read crc 0x" << crc
4387 << " != expected 0x" << *maybe_crc
4388 << std::dec
<< " on " << soid
;
4389 if (!(flags
& CEPH_OSD_OP_FLAG_FAILOK
)) {
4398 struct ToSparseReadResult
: public Context
{
4400 bufferlist
* data_bl
;
4401 uint64_t data_offset
;
4403 ToSparseReadResult(int* result
, bufferlist
* bl
, uint64_t offset
,
4405 : result(result
), data_bl(bl
), data_offset(offset
),len(len
) {}
4406 void finish(int r
) override
{
4414 map
<uint64_t, uint64_t> extents
= {{data_offset
, r
}};
4415 ::encode(extents
, outdata
);
4416 ::encode_destructively(*data_bl
, outdata
);
4417 data_bl
->swap(outdata
);
4421 template<typename V
>
4422 static string
list_keys(const map
<string
, V
>& m
) {
4424 for (typename map
<string
, V
>::const_iterator itr
= m
.begin(); itr
!= m
.end(); ++itr
) {
4428 s
.append(itr
->first
);
4433 template<typename T
>
4434 static string
list_entries(const T
& m
) {
4436 for (typename
T::const_iterator itr
= m
.begin(); itr
!= m
.end(); ++itr
) {
4445 void PrimaryLogPG::maybe_create_new_object(
4447 bool ignore_transaction
)
4449 ObjectState
& obs
= ctx
->new_obs
;
4451 ctx
->delta_stats
.num_objects
++;
4453 assert(!obs
.oi
.is_whiteout());
4454 obs
.oi
.new_object();
4455 if (!ignore_transaction
)
4456 ctx
->op_t
->create(obs
.oi
.soid
);
4457 } else if (obs
.oi
.is_whiteout()) {
4458 dout(10) << __func__
<< " clearing whiteout on " << obs
.oi
.soid
<< dendl
;
4459 ctx
->new_obs
.oi
.clear_flag(object_info_t::FLAG_WHITEOUT
);
4460 --ctx
->delta_stats
.num_whiteouts
;
4464 struct ReadFinisher
: public PrimaryLogPG::OpFinisher
{
4467 ReadFinisher(OSDOp
& osd_op
) : osd_op(osd_op
) {
4470 int execute() override
{
4475 struct C_ChecksumRead
: public Context
{
4476 PrimaryLogPG
*primary_log_pg
;
4478 Checksummer::CSumType csum_type
;
4479 bufferlist init_value_bl
;
4480 ceph_le64 read_length
;
4482 Context
*fill_extent_ctx
;
4484 C_ChecksumRead(PrimaryLogPG
*primary_log_pg
, OSDOp
&osd_op
,
4485 Checksummer::CSumType csum_type
, bufferlist
&&init_value_bl
,
4486 boost::optional
<uint32_t> maybe_crc
, uint64_t size
,
4487 OSDService
*osd
, hobject_t soid
, __le32 flags
)
4488 : primary_log_pg(primary_log_pg
), osd_op(osd_op
),
4489 csum_type(csum_type
), init_value_bl(std::move(init_value_bl
)),
4490 fill_extent_ctx(new FillInVerifyExtent(&read_length
, &osd_op
.rval
,
4491 &read_bl
, maybe_crc
, size
,
4492 osd
, soid
, flags
)) {
4494 ~C_ChecksumRead() override
{
4495 delete fill_extent_ctx
;
4498 void finish(int r
) override
{
4499 fill_extent_ctx
->complete(r
);
4500 fill_extent_ctx
= nullptr;
4502 if (osd_op
.rval
>= 0) {
4503 bufferlist::iterator init_value_bl_it
= init_value_bl
.begin();
4504 osd_op
.rval
= primary_log_pg
->finish_checksum(osd_op
, csum_type
,
4505 &init_value_bl_it
, read_bl
);
4510 int PrimaryLogPG::do_checksum(OpContext
*ctx
, OSDOp
& osd_op
,
4511 bufferlist::iterator
*bl_it
)
4513 dout(20) << __func__
<< dendl
;
4515 auto& op
= osd_op
.op
;
4516 if (op
.checksum
.chunk_size
> 0) {
4517 if (op
.checksum
.length
== 0) {
4518 dout(10) << __func__
<< ": length required when chunk size provided"
4522 if (op
.checksum
.length
% op
.checksum
.chunk_size
!= 0) {
4523 dout(10) << __func__
<< ": length not aligned to chunk size" << dendl
;
4528 auto& oi
= ctx
->new_obs
.oi
;
4529 if (op
.checksum
.offset
== 0 && op
.checksum
.length
== 0) {
4530 // zeroed offset+length implies checksum whole object
4531 op
.checksum
.length
= oi
.size
;
4532 } else if (op
.checksum
.offset
+ op
.checksum
.length
> oi
.size
) {
4536 Checksummer::CSumType csum_type
;
4537 switch (op
.checksum
.type
) {
4538 case CEPH_OSD_CHECKSUM_OP_TYPE_XXHASH32
:
4539 csum_type
= Checksummer::CSUM_XXHASH32
;
4541 case CEPH_OSD_CHECKSUM_OP_TYPE_XXHASH64
:
4542 csum_type
= Checksummer::CSUM_XXHASH64
;
4544 case CEPH_OSD_CHECKSUM_OP_TYPE_CRC32C
:
4545 csum_type
= Checksummer::CSUM_CRC32C
;
4548 dout(10) << __func__
<< ": unknown crc type ("
4549 << static_cast<uint32_t>(op
.checksum
.type
) << ")" << dendl
;
4553 size_t csum_init_value_size
= Checksummer::get_csum_init_value_size(csum_type
);
4554 if (bl_it
->get_remaining() < csum_init_value_size
) {
4555 dout(10) << __func__
<< ": init value not provided" << dendl
;
4559 bufferlist init_value_bl
;
4560 init_value_bl
.substr_of(bl_it
->get_bl(), bl_it
->get_off(),
4561 csum_init_value_size
);
4562 bl_it
->advance(csum_init_value_size
);
4564 if (pool
.info
.require_rollback() && op
.checksum
.length
> 0) {
4565 // If there is a data digest and it is possible we are reading
4566 // entire object, pass the digest.
4567 boost::optional
<uint32_t> maybe_crc
;
4568 if (oi
.is_data_digest() && op
.checksum
.offset
== 0 &&
4569 op
.checksum
.length
>= oi
.size
) {
4570 maybe_crc
= oi
.data_digest
;
4574 auto& soid
= oi
.soid
;
4575 auto checksum_ctx
= new C_ChecksumRead(this, osd_op
, csum_type
,
4576 std::move(init_value_bl
), maybe_crc
,
4577 oi
.size
, osd
, soid
, op
.flags
);
4579 ctx
->pending_async_reads
.push_back({
4580 {op
.checksum
.offset
, op
.checksum
.length
, op
.flags
},
4581 {&checksum_ctx
->read_bl
, checksum_ctx
}});
4583 dout(10) << __func__
<< ": async_read noted for " << soid
<< dendl
;
4584 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
4585 new ReadFinisher(osd_op
));
4586 return -EINPROGRESS
;
4590 std::vector
<OSDOp
> read_ops(1);
4591 auto& read_op
= read_ops
[0];
4592 if (op
.checksum
.length
> 0) {
4593 read_op
.op
.op
= CEPH_OSD_OP_READ
;
4594 read_op
.op
.flags
= op
.flags
;
4595 read_op
.op
.extent
.offset
= op
.checksum
.offset
;
4596 read_op
.op
.extent
.length
= op
.checksum
.length
;
4597 read_op
.op
.extent
.truncate_size
= 0;
4598 read_op
.op
.extent
.truncate_seq
= 0;
4600 int r
= do_osd_ops(ctx
, read_ops
);
4602 derr
<< __func__
<< ": do_osd_ops failed: " << cpp_strerror(r
) << dendl
;
4607 bufferlist::iterator init_value_bl_it
= init_value_bl
.begin();
4608 return finish_checksum(osd_op
, csum_type
, &init_value_bl_it
,
4612 int PrimaryLogPG::finish_checksum(OSDOp
& osd_op
,
4613 Checksummer::CSumType csum_type
,
4614 bufferlist::iterator
*init_value_bl_it
,
4615 const bufferlist
&read_bl
) {
4616 dout(20) << __func__
<< dendl
;
4618 auto& op
= osd_op
.op
;
4620 if (op
.checksum
.length
> 0 && read_bl
.length() != op
.checksum
.length
) {
4621 derr
<< __func__
<< ": bytes read " << read_bl
.length() << " != "
4622 << op
.checksum
.length
<< dendl
;
4626 size_t csum_chunk_size
= (op
.checksum
.chunk_size
!= 0 ?
4627 op
.checksum
.chunk_size
: read_bl
.length());
4628 uint32_t csum_count
= (csum_chunk_size
> 0 ?
4629 read_bl
.length() / csum_chunk_size
: 0);
4632 bufferptr csum_data
;
4633 if (csum_count
> 0) {
4634 size_t csum_value_size
= Checksummer::get_csum_value_size(csum_type
);
4635 csum_data
= buffer::create(csum_value_size
* csum_count
);
4637 csum
.append(csum_data
);
4639 switch (csum_type
) {
4640 case Checksummer::CSUM_XXHASH32
:
4642 Checksummer::xxhash32::init_value_t init_value
;
4643 ::decode(init_value
, *init_value_bl_it
);
4644 Checksummer::calculate
<Checksummer::xxhash32
>(
4645 init_value
, csum_chunk_size
, 0, read_bl
.length(), read_bl
,
4649 case Checksummer::CSUM_XXHASH64
:
4651 Checksummer::xxhash64::init_value_t init_value
;
4652 ::decode(init_value
, *init_value_bl_it
);
4653 Checksummer::calculate
<Checksummer::xxhash64
>(
4654 init_value
, csum_chunk_size
, 0, read_bl
.length(), read_bl
,
4658 case Checksummer::CSUM_CRC32C
:
4660 Checksummer::crc32c::init_value_t init_value
;
4661 ::decode(init_value
, *init_value_bl_it
);
4662 Checksummer::calculate
<Checksummer::crc32c
>(
4663 init_value
, csum_chunk_size
, 0, read_bl
.length(), read_bl
,
4672 ::encode(csum_count
, osd_op
.outdata
);
4673 osd_op
.outdata
.claim_append(csum
);
4677 struct C_ExtentCmpRead
: public Context
{
4678 PrimaryLogPG
*primary_log_pg
;
4680 ceph_le64 read_length
;
4682 Context
*fill_extent_ctx
;
4684 C_ExtentCmpRead(PrimaryLogPG
*primary_log_pg
, OSDOp
&osd_op
,
4685 boost::optional
<uint32_t> maybe_crc
, uint64_t size
,
4686 OSDService
*osd
, hobject_t soid
, __le32 flags
)
4687 : primary_log_pg(primary_log_pg
), osd_op(osd_op
),
4688 fill_extent_ctx(new FillInVerifyExtent(&read_length
, &osd_op
.rval
,
4689 &read_bl
, maybe_crc
, size
,
4690 osd
, soid
, flags
)) {
4692 ~C_ExtentCmpRead() override
{
4693 delete fill_extent_ctx
;
4696 void finish(int r
) override
{
4700 delete fill_extent_ctx
;
4702 fill_extent_ctx
->complete(r
);
4704 fill_extent_ctx
= nullptr;
4706 if (osd_op
.rval
>= 0) {
4707 osd_op
.rval
= primary_log_pg
->finish_extent_cmp(osd_op
, read_bl
);
4712 int PrimaryLogPG::do_extent_cmp(OpContext
*ctx
, OSDOp
& osd_op
)
4714 dout(20) << __func__
<< dendl
;
4715 ceph_osd_op
& op
= osd_op
.op
;
4717 if (!ctx
->obs
->exists
|| ctx
->obs
->oi
.is_whiteout()) {
4718 dout(20) << __func__
<< " object DNE" << dendl
;
4719 return finish_extent_cmp(osd_op
, {});
4720 } else if (pool
.info
.require_rollback()) {
4721 // If there is a data digest and it is possible we are reading
4722 // entire object, pass the digest.
4723 auto& oi
= ctx
->new_obs
.oi
;
4724 boost::optional
<uint32_t> maybe_crc
;
4725 if (oi
.is_data_digest() && op
.checksum
.offset
== 0 &&
4726 op
.checksum
.length
>= oi
.size
) {
4727 maybe_crc
= oi
.data_digest
;
4731 auto& soid
= oi
.soid
;
4732 auto extent_cmp_ctx
= new C_ExtentCmpRead(this, osd_op
, maybe_crc
, oi
.size
,
4733 osd
, soid
, op
.flags
);
4734 ctx
->pending_async_reads
.push_back({
4735 {op
.extent
.offset
, op
.extent
.length
, op
.flags
},
4736 {&extent_cmp_ctx
->read_bl
, extent_cmp_ctx
}});
4738 dout(10) << __func__
<< ": async_read noted for " << soid
<< dendl
;
4740 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
4741 new ReadFinisher(osd_op
));
4742 return -EINPROGRESS
;
4746 vector
<OSDOp
> read_ops(1);
4747 OSDOp
& read_op
= read_ops
[0];
4749 read_op
.op
.op
= CEPH_OSD_OP_SYNC_READ
;
4750 read_op
.op
.extent
.offset
= op
.extent
.offset
;
4751 read_op
.op
.extent
.length
= op
.extent
.length
;
4752 read_op
.op
.extent
.truncate_seq
= op
.extent
.truncate_seq
;
4753 read_op
.op
.extent
.truncate_size
= op
.extent
.truncate_size
;
4755 int result
= do_osd_ops(ctx
, read_ops
);
4757 derr
<< __func__
<< " failed " << result
<< dendl
;
4760 return finish_extent_cmp(osd_op
, read_op
.outdata
);
4763 int PrimaryLogPG::finish_extent_cmp(OSDOp
& osd_op
, const bufferlist
&read_bl
)
4765 for (uint64_t idx
= 0; idx
< osd_op
.indata
.length(); ++idx
) {
4766 char read_byte
= (idx
< read_bl
.length() ? read_bl
[idx
] : 0);
4767 if (osd_op
.indata
[idx
] != read_byte
) {
4768 return (-MAX_ERRNO
- idx
);
4775 int PrimaryLogPG::do_read(OpContext
*ctx
, OSDOp
& osd_op
) {
4776 dout(20) << __func__
<< dendl
;
4777 auto& op
= osd_op
.op
;
4778 auto& oi
= ctx
->new_obs
.oi
;
4779 auto& soid
= oi
.soid
;
4780 __u32 seq
= oi
.truncate_seq
;
4781 uint64_t size
= oi
.size
;
4782 bool trimmed_read
= false;
4784 // are we beyond truncate_size?
4785 if ( (seq
< op
.extent
.truncate_seq
) &&
4786 (op
.extent
.offset
+ op
.extent
.length
> op
.extent
.truncate_size
) )
4787 size
= op
.extent
.truncate_size
;
4789 if (op
.extent
.length
== 0) //length is zero mean read the whole object
4790 op
.extent
.length
= size
;
4792 if (op
.extent
.offset
>= size
) {
4793 op
.extent
.length
= 0;
4794 trimmed_read
= true;
4795 } else if (op
.extent
.offset
+ op
.extent
.length
> size
) {
4796 op
.extent
.length
= size
- op
.extent
.offset
;
4797 trimmed_read
= true;
4800 // read into a buffer
4802 if (trimmed_read
&& op
.extent
.length
== 0) {
4803 // read size was trimmed to zero and it is expected to do nothing
4804 // a read operation of 0 bytes does *not* do nothing, this is why
4805 // the trimmed_read boolean is needed
4806 } else if (pool
.info
.require_rollback()) {
4807 boost::optional
<uint32_t> maybe_crc
;
4808 // If there is a data digest and it is possible we are reading
4809 // entire object, pass the digest. FillInVerifyExtent will
4810 // will check the oi.size again.
4811 if (oi
.is_data_digest() && op
.extent
.offset
== 0 &&
4812 op
.extent
.length
>= oi
.size
)
4813 maybe_crc
= oi
.data_digest
;
4814 ctx
->pending_async_reads
.push_back(
4816 boost::make_tuple(op
.extent
.offset
, op
.extent
.length
, op
.flags
),
4817 make_pair(&osd_op
.outdata
,
4818 new FillInVerifyExtent(&op
.extent
.length
, &osd_op
.rval
,
4819 &osd_op
.outdata
, maybe_crc
, oi
.size
,
4820 osd
, soid
, op
.flags
))));
4821 dout(10) << " async_read noted for " << soid
<< dendl
;
4823 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
4824 new ReadFinisher(osd_op
));
4826 int r
= pgbackend
->objects_read_sync(
4827 soid
, op
.extent
.offset
, op
.extent
.length
, op
.flags
, &osd_op
.outdata
);
4829 r
= rep_repair_primary_object(soid
, ctx
->op
);
4832 op
.extent
.length
= r
;
4835 op
.extent
.length
= 0;
4837 dout(10) << " read got " << r
<< " / " << op
.extent
.length
4838 << " bytes from obj " << soid
<< dendl
;
4840 // whole object? can we verify the checksum?
4841 if (op
.extent
.length
== oi
.size
&& oi
.is_data_digest()) {
4842 uint32_t crc
= osd_op
.outdata
.crc32c(-1);
4843 if (oi
.data_digest
!= crc
) {
4844 osd
->clog
->error() << info
.pgid
<< std::hex
4845 << " full-object read crc 0x" << crc
4846 << " != expected 0x" << oi
.data_digest
4847 << std::dec
<< " on " << soid
;
4848 // FIXME fall back to replica or something?
4854 // XXX the op.extent.length is the requested length for async read
4855 // On error this length is changed to 0 after the error comes back.
4856 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(op
.extent
.length
, 10);
4857 ctx
->delta_stats
.num_rd
++;
4861 int PrimaryLogPG::do_sparse_read(OpContext
*ctx
, OSDOp
& osd_op
) {
4862 dout(20) << __func__
<< dendl
;
4863 auto& op
= osd_op
.op
;
4864 auto& oi
= ctx
->new_obs
.oi
;
4865 auto& soid
= oi
.soid
;
4867 if (op
.extent
.truncate_seq
) {
4868 dout(0) << "sparse_read does not support truncation sequence " << dendl
;
4873 if (pool
.info
.ec_pool()) {
4874 // translate sparse read to a normal one if not supported
4875 uint64_t offset
= op
.extent
.offset
;
4876 uint64_t length
= op
.extent
.length
;
4877 if (offset
> oi
.size
) {
4879 } else if (offset
+ length
> oi
.size
) {
4880 length
= oi
.size
- offset
;
4884 ctx
->pending_async_reads
.push_back(
4886 boost::make_tuple(offset
, length
, op
.flags
),
4889 new ToSparseReadResult(&osd_op
.rval
, &osd_op
.outdata
, offset
,
4890 &op
.extent
.length
))));
4891 dout(10) << " async_read (was sparse_read) noted for " << soid
<< dendl
;
4893 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
4894 new ReadFinisher(osd_op
));
4896 dout(10) << " sparse read ended up empty for " << soid
<< dendl
;
4897 map
<uint64_t, uint64_t> extents
;
4898 ::encode(extents
, osd_op
.outdata
);
4901 // read into a buffer
4902 map
<uint64_t, uint64_t> m
;
4903 uint32_t total_read
= 0;
4904 int r
= osd
->store
->fiemap(ch
, ghobject_t(soid
, ghobject_t::NO_GEN
,
4906 op
.extent
.offset
, op
.extent
.length
, m
);
4911 map
<uint64_t, uint64_t>::iterator miter
;
4913 uint64_t last
= op
.extent
.offset
;
4914 for (miter
= m
.begin(); miter
!= m
.end(); ++miter
) {
4916 if (cct
->_conf
->osd_verify_sparse_read_holes
&&
4917 last
< miter
->first
) {
4919 uint64_t len
= miter
->first
- last
;
4920 r
= pgbackend
->objects_read_sync(soid
, last
, len
, op
.flags
, &t
);
4922 r
= rep_repair_primary_object(soid
, ctx
->op
);
4925 osd
->clog
->error() << coll
<< " " << soid
4926 << " sparse-read failed to read: "
4928 } else if (!t
.is_zero()) {
4929 osd
->clog
->error() << coll
<< " " << soid
4930 << " sparse-read found data in hole "
4931 << last
<< "~" << len
;
4936 r
= pgbackend
->objects_read_sync(soid
, miter
->first
, miter
->second
,
4942 // this is usually happen when we get extent that exceeds the actual file
4944 if (r
< (int)miter
->second
)
4947 dout(10) << "sparse-read " << miter
->first
<< "@" << miter
->second
4949 data_bl
.claim_append(tmpbl
);
4950 last
= miter
->first
+ r
;
4957 // verify trailing hole?
4958 if (cct
->_conf
->osd_verify_sparse_read_holes
) {
4959 uint64_t end
= MIN(op
.extent
.offset
+ op
.extent
.length
, oi
.size
);
4962 uint64_t len
= end
- last
;
4963 r
= pgbackend
->objects_read_sync(soid
, last
, len
, op
.flags
, &t
);
4965 osd
->clog
->error() << coll
<< " " << soid
4966 << " sparse-read failed to read: " << r
;
4967 } else if (!t
.is_zero()) {
4968 osd
->clog
->error() << coll
<< " " << soid
4969 << " sparse-read found data in hole "
4970 << last
<< "~" << len
;
4975 // Why SPARSE_READ need checksum? In fact, librbd always use sparse-read.
4976 // Maybe at first, there is no much whole objects. With continued use, more
4977 // and more whole object exist. So from this point, for spare-read add
4978 // checksum make sense.
4979 if (total_read
== oi
.size
&& oi
.is_data_digest()) {
4980 uint32_t crc
= data_bl
.crc32c(-1);
4981 if (oi
.data_digest
!= crc
) {
4982 osd
->clog
->error() << info
.pgid
<< std::hex
4983 << " full-object read crc 0x" << crc
4984 << " != expected 0x" << oi
.data_digest
4985 << std::dec
<< " on " << soid
;
4986 // FIXME fall back to replica or something?
4991 op
.extent
.length
= total_read
;
4993 ::encode(m
, osd_op
.outdata
); // re-encode since it might be modified
4994 ::encode_destructively(data_bl
, osd_op
.outdata
);
4996 dout(10) << " sparse_read got " << total_read
<< " bytes from object "
5000 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(op
.extent
.length
, 10);
5001 ctx
->delta_stats
.num_rd
++;
5005 int PrimaryLogPG::do_osd_ops(OpContext
*ctx
, vector
<OSDOp
>& ops
)
5008 SnapSetContext
*ssc
= ctx
->obc
->ssc
;
5009 ObjectState
& obs
= ctx
->new_obs
;
5010 object_info_t
& oi
= obs
.oi
;
5011 const hobject_t
& soid
= oi
.soid
;
5013 PGTransaction
* t
= ctx
->op_t
.get();
5015 dout(10) << "do_osd_op " << soid
<< " " << ops
<< dendl
;
5017 ctx
->current_osd_subop_num
= 0;
5018 for (vector
<OSDOp
>::iterator p
= ops
.begin(); p
!= ops
.end(); ++p
, ctx
->current_osd_subop_num
++) {
5020 ceph_osd_op
& op
= osd_op
.op
;
5022 OpFinisher
* op_finisher
= nullptr;
5024 auto op_finisher_it
= ctx
->op_finishers
.find(ctx
->current_osd_subop_num
);
5025 if (op_finisher_it
!= ctx
->op_finishers
.end()) {
5026 op_finisher
= op_finisher_it
->second
.get();
5030 // TODO: check endianness (__le32 vs uint32_t, etc.)
5031 // The fields in ceph_osd_op are little-endian (according to the definition in rados.h),
5032 // but the code in this function seems to treat them as native-endian. What should the
5034 tracepoint(osd
, do_osd_op_pre
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.op
, ceph_osd_op_name(op
.op
), op
.flags
);
5036 dout(10) << "do_osd_op " << osd_op
<< dendl
;
5038 bufferlist::iterator bp
= osd_op
.indata
.begin();
5040 // user-visible modifcation?
5042 // non user-visible modifications
5043 case CEPH_OSD_OP_WATCH
:
5044 case CEPH_OSD_OP_CACHE_EVICT
:
5045 case CEPH_OSD_OP_CACHE_FLUSH
:
5046 case CEPH_OSD_OP_CACHE_TRY_FLUSH
:
5047 case CEPH_OSD_OP_UNDIRTY
:
5048 case CEPH_OSD_OP_COPY_FROM
: // we handle user_version update explicitly
5049 case CEPH_OSD_OP_CACHE_PIN
:
5050 case CEPH_OSD_OP_CACHE_UNPIN
:
5051 case CEPH_OSD_OP_SET_REDIRECT
:
5054 if (op
.op
& CEPH_OSD_OP_MODE_WR
)
5055 ctx
->user_modify
= true;
5058 // munge -1 truncate to 0 truncate
5059 if (ceph_osd_op_uses_extent(op
.op
) &&
5060 op
.extent
.truncate_seq
== 1 &&
5061 op
.extent
.truncate_size
== (-1ULL)) {
5062 op
.extent
.truncate_size
= 0;
5063 op
.extent
.truncate_seq
= 0;
5066 // munge ZERO -> TRUNCATE? (don't munge to DELETE or we risk hosing attributes)
5067 if (op
.op
== CEPH_OSD_OP_ZERO
&&
5069 op
.extent
.offset
< cct
->_conf
->osd_max_object_size
&&
5070 op
.extent
.length
>= 1 &&
5071 op
.extent
.length
<= cct
->_conf
->osd_max_object_size
&&
5072 op
.extent
.offset
+ op
.extent
.length
>= oi
.size
) {
5073 if (op
.extent
.offset
>= oi
.size
) {
5077 dout(10) << " munging ZERO " << op
.extent
.offset
<< "~" << op
.extent
.length
5078 << " -> TRUNCATE " << op
.extent
.offset
<< " (old size is " << oi
.size
<< ")" << dendl
;
5079 op
.op
= CEPH_OSD_OP_TRUNCATE
;
5086 case CEPH_OSD_OP_CMPEXT
:
5088 tracepoint(osd
, do_osd_op_pre_extent_cmp
, soid
.oid
.name
.c_str(),
5089 soid
.snap
.val
, oi
.size
, oi
.truncate_seq
, op
.extent
.offset
,
5090 op
.extent
.length
, op
.extent
.truncate_size
,
5091 op
.extent
.truncate_seq
);
5093 if (op_finisher
== nullptr) {
5094 result
= do_extent_cmp(ctx
, osd_op
);
5096 result
= op_finisher
->execute();
5100 case CEPH_OSD_OP_SYNC_READ
:
5101 if (pool
.info
.require_rollback()) {
5102 result
= -EOPNOTSUPP
;
5106 case CEPH_OSD_OP_READ
:
5108 tracepoint(osd
, do_osd_op_pre_read
, soid
.oid
.name
.c_str(),
5109 soid
.snap
.val
, oi
.size
, oi
.truncate_seq
, op
.extent
.offset
,
5110 op
.extent
.length
, op
.extent
.truncate_size
,
5111 op
.extent
.truncate_seq
);
5112 if (op_finisher
== nullptr) {
5113 if (!ctx
->data_off
) {
5114 ctx
->data_off
= op
.extent
.offset
;
5116 result
= do_read(ctx
, osd_op
);
5118 result
= op_finisher
->execute();
5122 case CEPH_OSD_OP_CHECKSUM
:
5125 tracepoint(osd
, do_osd_op_pre_checksum
, soid
.oid
.name
.c_str(),
5126 soid
.snap
.val
, oi
.size
, oi
.truncate_seq
, op
.checksum
.type
,
5127 op
.checksum
.offset
, op
.checksum
.length
,
5128 op
.checksum
.chunk_size
);
5130 if (op_finisher
== nullptr) {
5131 result
= do_checksum(ctx
, osd_op
, &bp
);
5133 result
= op_finisher
->execute();
5139 case CEPH_OSD_OP_MAPEXT
:
5140 tracepoint(osd
, do_osd_op_pre_mapext
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.extent
.offset
, op
.extent
.length
);
5141 if (pool
.info
.require_rollback()) {
5142 result
= -EOPNOTSUPP
;
5147 // read into a buffer
5149 int r
= osd
->store
->fiemap(ch
, ghobject_t(soid
, ghobject_t::NO_GEN
,
5151 op
.extent
.offset
, op
.extent
.length
, bl
);
5152 osd_op
.outdata
.claim(bl
);
5156 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(bl
.length(), 10);
5157 ctx
->delta_stats
.num_rd
++;
5158 dout(10) << " map_extents done on object " << soid
<< dendl
;
5163 case CEPH_OSD_OP_SPARSE_READ
:
5164 tracepoint(osd
, do_osd_op_pre_sparse_read
, soid
.oid
.name
.c_str(),
5165 soid
.snap
.val
, oi
.size
, oi
.truncate_seq
, op
.extent
.offset
,
5166 op
.extent
.length
, op
.extent
.truncate_size
,
5167 op
.extent
.truncate_seq
);
5168 if (op_finisher
== nullptr) {
5169 result
= do_sparse_read(ctx
, osd_op
);
5171 result
= op_finisher
->execute();
5175 case CEPH_OSD_OP_CALL
:
5177 string cname
, mname
;
5180 bp
.copy(op
.cls
.class_len
, cname
);
5181 bp
.copy(op
.cls
.method_len
, mname
);
5182 bp
.copy(op
.cls
.indata_len
, indata
);
5183 } catch (buffer::error
& e
) {
5184 dout(10) << "call unable to decode class + method + indata" << dendl
;
5185 dout(30) << "in dump: ";
5186 osd_op
.indata
.hexdump(*_dout
);
5189 tracepoint(osd
, do_osd_op_pre_call
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???", "???");
5192 tracepoint(osd
, do_osd_op_pre_call
, soid
.oid
.name
.c_str(), soid
.snap
.val
, cname
.c_str(), mname
.c_str());
5194 ClassHandler::ClassData
*cls
;
5195 result
= osd
->class_handler
->open_class(cname
, &cls
);
5196 assert(result
== 0); // init_op_flags() already verified this works.
5198 ClassHandler::ClassMethod
*method
= cls
->get_method(mname
.c_str());
5200 dout(10) << "call method " << cname
<< "." << mname
<< " does not exist" << dendl
;
5201 result
= -EOPNOTSUPP
;
5205 int flags
= method
->get_flags();
5206 if (flags
& CLS_METHOD_WR
)
5207 ctx
->user_modify
= true;
5210 dout(10) << "call method " << cname
<< "." << mname
<< dendl
;
5211 int prev_rd
= ctx
->num_read
;
5212 int prev_wr
= ctx
->num_write
;
5213 result
= method
->exec((cls_method_context_t
)&ctx
, indata
, outdata
);
5215 if (ctx
->num_read
> prev_rd
&& !(flags
& CLS_METHOD_RD
)) {
5216 derr
<< "method " << cname
<< "." << mname
<< " tried to read object but is not marked RD" << dendl
;
5220 if (ctx
->num_write
> prev_wr
&& !(flags
& CLS_METHOD_WR
)) {
5221 derr
<< "method " << cname
<< "." << mname
<< " tried to update object but is not marked WR" << dendl
;
5226 dout(10) << "method called response length=" << outdata
.length() << dendl
;
5227 op
.extent
.length
= outdata
.length();
5228 osd_op
.outdata
.claim_append(outdata
);
5229 dout(30) << "out dump: ";
5230 osd_op
.outdata
.hexdump(*_dout
);
5235 case CEPH_OSD_OP_STAT
:
5236 // note: stat does not require RD
5238 tracepoint(osd
, do_osd_op_pre_stat
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5240 if (obs
.exists
&& !oi
.is_whiteout()) {
5241 ::encode(oi
.size
, osd_op
.outdata
);
5242 ::encode(oi
.mtime
, osd_op
.outdata
);
5243 dout(10) << "stat oi has " << oi
.size
<< " " << oi
.mtime
<< dendl
;
5246 dout(10) << "stat oi object does not exist" << dendl
;
5249 ctx
->delta_stats
.num_rd
++;
5253 case CEPH_OSD_OP_ISDIRTY
:
5256 tracepoint(osd
, do_osd_op_pre_isdirty
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5257 bool is_dirty
= obs
.oi
.is_dirty();
5258 ::encode(is_dirty
, osd_op
.outdata
);
5259 ctx
->delta_stats
.num_rd
++;
5264 case CEPH_OSD_OP_UNDIRTY
:
5267 tracepoint(osd
, do_osd_op_pre_undirty
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5268 if (oi
.is_dirty()) {
5269 ctx
->undirty
= true; // see make_writeable()
5271 ctx
->delta_stats
.num_wr
++;
5277 case CEPH_OSD_OP_CACHE_TRY_FLUSH
:
5280 tracepoint(osd
, do_osd_op_pre_try_flush
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5281 if (ctx
->lock_type
!= ObjectContext::RWState::RWNONE
) {
5282 dout(10) << "cache-try-flush without SKIPRWLOCKS flag set" << dendl
;
5286 if (pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
) {
5294 if (oi
.is_cache_pinned()) {
5295 dout(10) << "cache-try-flush on a pinned object, consider unpin this object first" << dendl
;
5299 if (oi
.is_dirty()) {
5300 result
= start_flush(ctx
->op
, ctx
->obc
, false, NULL
, boost::none
);
5301 if (result
== -EINPROGRESS
)
5309 case CEPH_OSD_OP_CACHE_FLUSH
:
5312 tracepoint(osd
, do_osd_op_pre_cache_flush
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5313 if (ctx
->lock_type
== ObjectContext::RWState::RWNONE
) {
5314 dout(10) << "cache-flush with SKIPRWLOCKS flag set" << dendl
;
5318 if (pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
) {
5326 if (oi
.is_cache_pinned()) {
5327 dout(10) << "cache-flush on a pinned object, consider unpin this object first" << dendl
;
5332 if (oi
.is_dirty()) {
5333 result
= start_flush(ctx
->op
, ctx
->obc
, true, &missing
, boost::none
);
5334 if (result
== -EINPROGRESS
)
5339 // Check special return value which has set missing_return
5340 if (result
== -ENOENT
) {
5341 dout(10) << __func__
<< " CEPH_OSD_OP_CACHE_FLUSH got ENOENT" << dendl
;
5342 assert(!missing
.is_min());
5343 wait_for_unreadable_object(missing
, ctx
->op
);
5344 // Error code which is used elsewhere when wait_for_unreadable_object() is used
5350 case CEPH_OSD_OP_CACHE_EVICT
:
5353 tracepoint(osd
, do_osd_op_pre_cache_evict
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5354 if (pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
) {
5362 if (oi
.is_cache_pinned()) {
5363 dout(10) << "cache-evict on a pinned object, consider unpin this object first" << dendl
;
5367 if (oi
.is_dirty()) {
5371 if (!oi
.watchers
.empty()) {
5375 if (soid
.snap
== CEPH_NOSNAP
) {
5376 result
= _verify_no_head_clones(soid
, ssc
->snapset
);
5380 result
= _delete_oid(ctx
, true, false);
5382 // mark that this is a cache eviction to avoid triggering normal
5383 // make_writeable() clone or snapdir object creation in finish_ctx()
5384 ctx
->cache_evict
= true;
5386 osd
->logger
->inc(l_osd_tier_evict
);
5390 case CEPH_OSD_OP_GETXATTR
:
5394 bp
.copy(op
.xattr
.name_len
, aname
);
5395 tracepoint(osd
, do_osd_op_pre_getxattr
, soid
.oid
.name
.c_str(), soid
.snap
.val
, aname
.c_str());
5396 string name
= "_" + aname
;
5397 int r
= getattr_maybe_cache(
5402 op
.xattr
.value_len
= osd_op
.outdata
.length();
5404 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(osd_op
.outdata
.length(), 10);
5408 ctx
->delta_stats
.num_rd
++;
5412 case CEPH_OSD_OP_GETXATTRS
:
5415 tracepoint(osd
, do_osd_op_pre_getxattrs
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5416 map
<string
, bufferlist
> out
;
5417 result
= getattrs_maybe_cache(
5424 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(bl
.length(), 10);
5425 ctx
->delta_stats
.num_rd
++;
5426 osd_op
.outdata
.claim_append(bl
);
5430 case CEPH_OSD_OP_CMPXATTR
:
5434 bp
.copy(op
.xattr
.name_len
, aname
);
5435 tracepoint(osd
, do_osd_op_pre_cmpxattr
, soid
.oid
.name
.c_str(), soid
.snap
.val
, aname
.c_str());
5436 string name
= "_" + aname
;
5437 name
[op
.xattr
.name_len
+ 1] = 0;
5440 result
= getattr_maybe_cache(
5444 if (result
< 0 && result
!= -EEXIST
&& result
!= -ENODATA
)
5447 ctx
->delta_stats
.num_rd
++;
5448 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(xattr
.length(), 10);
5450 switch (op
.xattr
.cmp_mode
) {
5451 case CEPH_OSD_CMPXATTR_MODE_STRING
:
5454 bp
.copy(op
.xattr
.value_len
, val
);
5455 val
[op
.xattr
.value_len
] = 0;
5456 dout(10) << "CEPH_OSD_OP_CMPXATTR name=" << name
<< " val=" << val
5457 << " op=" << (int)op
.xattr
.cmp_op
<< " mode=" << (int)op
.xattr
.cmp_mode
<< dendl
;
5458 result
= do_xattr_cmp_str(op
.xattr
.cmp_op
, val
, xattr
);
5462 case CEPH_OSD_CMPXATTR_MODE_U64
:
5466 ::decode(u64val
, bp
);
5468 catch (buffer::error
& e
) {
5472 dout(10) << "CEPH_OSD_OP_CMPXATTR name=" << name
<< " val=" << u64val
5473 << " op=" << (int)op
.xattr
.cmp_op
<< " mode=" << (int)op
.xattr
.cmp_mode
<< dendl
;
5474 result
= do_xattr_cmp_u64(op
.xattr
.cmp_op
, u64val
, xattr
);
5479 dout(10) << "bad cmp mode " << (int)op
.xattr
.cmp_mode
<< dendl
;
5484 dout(10) << "comparison returned false" << dendl
;
5485 result
= -ECANCELED
;
5489 dout(10) << "comparison returned " << result
<< " " << cpp_strerror(-result
) << dendl
;
5493 dout(10) << "comparison returned true" << dendl
;
5497 case CEPH_OSD_OP_ASSERT_VER
:
5500 uint64_t ver
= op
.assert_ver
.ver
;
5501 tracepoint(osd
, do_osd_op_pre_assert_ver
, soid
.oid
.name
.c_str(), soid
.snap
.val
, ver
);
5504 else if (ver
< oi
.user_version
)
5506 else if (ver
> oi
.user_version
)
5507 result
= -EOVERFLOW
;
5511 case CEPH_OSD_OP_LIST_WATCHERS
:
5514 tracepoint(osd
, do_osd_op_pre_list_watchers
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5515 obj_list_watch_response_t resp
;
5517 map
<pair
<uint64_t, entity_name_t
>, watch_info_t
>::const_iterator oi_iter
;
5518 for (oi_iter
= oi
.watchers
.begin(); oi_iter
!= oi
.watchers
.end();
5520 dout(20) << "key cookie=" << oi_iter
->first
.first
5521 << " entity=" << oi_iter
->first
.second
<< " "
5522 << oi_iter
->second
<< dendl
;
5523 assert(oi_iter
->first
.first
== oi_iter
->second
.cookie
);
5524 assert(oi_iter
->first
.second
.is_client());
5526 watch_item_t
wi(oi_iter
->first
.second
, oi_iter
->second
.cookie
,
5527 oi_iter
->second
.timeout_seconds
, oi_iter
->second
.addr
);
5528 resp
.entries
.push_back(wi
);
5531 resp
.encode(osd_op
.outdata
, ctx
->get_features());
5534 ctx
->delta_stats
.num_rd
++;
5538 case CEPH_OSD_OP_LIST_SNAPS
:
5541 tracepoint(osd
, do_osd_op_pre_list_snaps
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5542 obj_list_snap_response_t resp
;
5545 ssc
= ctx
->obc
->ssc
= get_snapset_context(soid
, false);
5549 int clonecount
= ssc
->snapset
.clones
.size();
5550 if (ssc
->snapset
.head_exists
)
5552 resp
.clones
.reserve(clonecount
);
5553 for (auto clone_iter
= ssc
->snapset
.clones
.begin();
5554 clone_iter
!= ssc
->snapset
.clones
.end(); ++clone_iter
) {
5556 ci
.cloneid
= *clone_iter
;
5558 hobject_t clone_oid
= soid
;
5559 clone_oid
.snap
= *clone_iter
;
5561 if (!ssc
->snapset
.is_legacy()) {
5562 auto p
= ssc
->snapset
.clone_snaps
.find(*clone_iter
);
5563 if (p
== ssc
->snapset
.clone_snaps
.end()) {
5564 osd
->clog
->error() << "osd." << osd
->whoami
5565 << ": inconsistent clone_snaps found for oid "
5566 << soid
<< " clone " << *clone_iter
5567 << " snapset " << ssc
->snapset
;
5571 for (auto q
= p
->second
.rbegin(); q
!= p
->second
.rend(); ++q
) {
5572 ci
.snaps
.push_back(*q
);
5575 /* No need to take a lock here. We are only inspecting state cached on
5576 * in the ObjectContext, so we aren't performing an actual read unless
5577 * the clone obc is not already loaded (in which case, it cannot have
5578 * an in progress write). We also do not risk exposing uncommitted
5579 * state since we do have a read lock on the head object or snapdir,
5580 * which we would have to write lock in order to make user visible
5581 * modifications to the snapshot state (snap trim related mutations
5582 * are not user visible).
5584 if (is_missing_object(clone_oid
)) {
5585 dout(20) << "LIST_SNAPS " << clone_oid
<< " missing" << dendl
;
5586 wait_for_unreadable_object(clone_oid
, ctx
->op
);
5591 ObjectContextRef clone_obc
= get_object_context(clone_oid
, false);
5593 if (maybe_handle_cache(
5594 ctx
->op
, true, clone_obc
, -ENOENT
, clone_oid
, true)) {
5595 // promoting the clone
5598 osd
->clog
->error() << "osd." << osd
->whoami
5599 << ": missing clone " << clone_oid
5602 // should not happen
5607 for (vector
<snapid_t
>::reverse_iterator p
=
5608 clone_obc
->obs
.oi
.legacy_snaps
.rbegin();
5609 p
!= clone_obc
->obs
.oi
.legacy_snaps
.rend();
5611 ci
.snaps
.push_back(*p
);
5615 dout(20) << " clone " << *clone_iter
<< " snaps " << ci
.snaps
<< dendl
;
5617 map
<snapid_t
, interval_set
<uint64_t> >::const_iterator coi
;
5618 coi
= ssc
->snapset
.clone_overlap
.find(ci
.cloneid
);
5619 if (coi
== ssc
->snapset
.clone_overlap
.end()) {
5620 osd
->clog
->error() << "osd." << osd
->whoami
5621 << ": inconsistent clone_overlap found for oid "
5622 << soid
<< " clone " << *clone_iter
;
5626 const interval_set
<uint64_t> &o
= coi
->second
;
5627 ci
.overlap
.reserve(o
.num_intervals());
5628 for (interval_set
<uint64_t>::const_iterator r
= o
.begin();
5629 r
!= o
.end(); ++r
) {
5630 ci
.overlap
.push_back(pair
<uint64_t,uint64_t>(r
.get_start(),
5634 map
<snapid_t
, uint64_t>::const_iterator si
;
5635 si
= ssc
->snapset
.clone_size
.find(ci
.cloneid
);
5636 if (si
== ssc
->snapset
.clone_size
.end()) {
5637 osd
->clog
->error() << "osd." << osd
->whoami
5638 << ": inconsistent clone_size found for oid "
5639 << soid
<< " clone " << *clone_iter
;
5643 ci
.size
= si
->second
;
5645 resp
.clones
.push_back(ci
);
5650 if (ssc
->snapset
.head_exists
&&
5651 !ctx
->obc
->obs
.oi
.is_whiteout()) {
5654 ci
.cloneid
= CEPH_NOSNAP
;
5656 //Size for HEAD is oi.size
5659 resp
.clones
.push_back(ci
);
5661 resp
.seq
= ssc
->snapset
.seq
;
5663 resp
.encode(osd_op
.outdata
);
5666 ctx
->delta_stats
.num_rd
++;
5670 case CEPH_OSD_OP_NOTIFY
:
5677 uint32_t ver
; // obsolete
5679 ::decode(timeout
, bp
);
5681 } catch (const buffer::error
&e
) {
5684 tracepoint(osd
, do_osd_op_pre_notify
, soid
.oid
.name
.c_str(), soid
.snap
.val
, timeout
);
5686 timeout
= cct
->_conf
->osd_default_notify_timeout
;
5689 n
.timeout
= timeout
;
5690 n
.notify_id
= osd
->get_next_id(get_osdmap()->get_epoch());
5691 n
.cookie
= op
.watch
.cookie
;
5693 ctx
->notifies
.push_back(n
);
5695 // return our unique notify id to the client
5696 ::encode(n
.notify_id
, osd_op
.outdata
);
5700 case CEPH_OSD_OP_NOTIFY_ACK
:
5704 uint64_t notify_id
= 0;
5705 uint64_t watch_cookie
= 0;
5706 ::decode(notify_id
, bp
);
5707 ::decode(watch_cookie
, bp
);
5708 bufferlist reply_bl
;
5710 ::decode(reply_bl
, bp
);
5712 tracepoint(osd
, do_osd_op_pre_notify_ack
, soid
.oid
.name
.c_str(), soid
.snap
.val
, notify_id
, watch_cookie
, "Y");
5713 OpContext::NotifyAck
ack(notify_id
, watch_cookie
, reply_bl
);
5714 ctx
->notify_acks
.push_back(ack
);
5715 } catch (const buffer::error
&e
) {
5716 tracepoint(osd
, do_osd_op_pre_notify_ack
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.watch
.cookie
, 0, "N");
5717 OpContext::NotifyAck
ack(
5718 // op.watch.cookie is actually the notify_id for historical reasons
5721 ctx
->notify_acks
.push_back(ack
);
5726 case CEPH_OSD_OP_SETALLOCHINT
:
5729 tracepoint(osd
, do_osd_op_pre_setallochint
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.alloc_hint
.expected_object_size
, op
.alloc_hint
.expected_write_size
);
5730 maybe_create_new_object(ctx
);
5731 oi
.expected_object_size
= op
.alloc_hint
.expected_object_size
;
5732 oi
.expected_write_size
= op
.alloc_hint
.expected_write_size
;
5733 oi
.alloc_hint_flags
= op
.alloc_hint
.flags
;
5734 t
->set_alloc_hint(soid
, op
.alloc_hint
.expected_object_size
,
5735 op
.alloc_hint
.expected_write_size
,
5736 op
.alloc_hint
.flags
);
5737 ctx
->delta_stats
.num_wr
++;
5745 // -- object data --
5747 case CEPH_OSD_OP_WRITE
:
5750 __u32 seq
= oi
.truncate_seq
;
5751 tracepoint(osd
, do_osd_op_pre_write
, soid
.oid
.name
.c_str(), soid
.snap
.val
, oi
.size
, seq
, op
.extent
.offset
, op
.extent
.length
, op
.extent
.truncate_size
, op
.extent
.truncate_seq
);
5752 if (op
.extent
.length
!= osd_op
.indata
.length()) {
5757 if (pool
.info
.has_flag(pg_pool_t::FLAG_WRITE_FADVISE_DONTNEED
))
5758 op
.flags
= op
.flags
| CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
;
5760 if (pool
.info
.requires_aligned_append() &&
5761 (op
.extent
.offset
% pool
.info
.required_alignment() != 0)) {
5762 result
= -EOPNOTSUPP
;
5767 if (pool
.info
.requires_aligned_append() && op
.extent
.offset
) {
5768 result
= -EOPNOTSUPP
;
5771 } else if (op
.extent
.offset
!= oi
.size
&&
5772 pool
.info
.requires_aligned_append()) {
5773 result
= -EOPNOTSUPP
;
5777 if (seq
&& (seq
> op
.extent
.truncate_seq
) &&
5778 (op
.extent
.offset
+ op
.extent
.length
> oi
.size
)) {
5779 // old write, arrived after trimtrunc
5780 op
.extent
.length
= (op
.extent
.offset
> oi
.size
? 0 : oi
.size
- op
.extent
.offset
);
5781 dout(10) << " old truncate_seq " << op
.extent
.truncate_seq
<< " < current " << seq
5782 << ", adjusting write length to " << op
.extent
.length
<< dendl
;
5784 t
.substr_of(osd_op
.indata
, 0, op
.extent
.length
);
5785 osd_op
.indata
.swap(t
);
5787 if (op
.extent
.truncate_seq
> seq
) {
5788 // write arrives before trimtrunc
5789 if (obs
.exists
&& !oi
.is_whiteout()) {
5790 dout(10) << " truncate_seq " << op
.extent
.truncate_seq
<< " > current " << seq
5791 << ", truncating to " << op
.extent
.truncate_size
<< dendl
;
5792 t
->truncate(soid
, op
.extent
.truncate_size
);
5793 oi
.truncate_seq
= op
.extent
.truncate_seq
;
5794 oi
.truncate_size
= op
.extent
.truncate_size
;
5795 if (op
.extent
.truncate_size
!= oi
.size
) {
5796 ctx
->delta_stats
.num_bytes
-= oi
.size
;
5797 ctx
->delta_stats
.num_bytes
+= op
.extent
.truncate_size
;
5798 oi
.size
= op
.extent
.truncate_size
;
5801 dout(10) << " truncate_seq " << op
.extent
.truncate_seq
<< " > current " << seq
5802 << ", but object is new" << dendl
;
5803 oi
.truncate_seq
= op
.extent
.truncate_seq
;
5804 oi
.truncate_size
= op
.extent
.truncate_size
;
5807 result
= check_offset_and_length(op
.extent
.offset
, op
.extent
.length
, cct
->_conf
->osd_max_object_size
);
5811 maybe_create_new_object(ctx
);
5813 if (op
.extent
.length
== 0) {
5814 if (op
.extent
.offset
> oi
.size
) {
5816 soid
, op
.extent
.offset
);
5822 soid
, op
.extent
.offset
, op
.extent
.length
, osd_op
.indata
, op
.flags
);
5825 if (op
.extent
.offset
== 0 && op
.extent
.length
>= oi
.size
)
5826 obs
.oi
.set_data_digest(osd_op
.indata
.crc32c(-1));
5827 else if (op
.extent
.offset
== oi
.size
&& obs
.oi
.is_data_digest())
5828 obs
.oi
.set_data_digest(osd_op
.indata
.crc32c(obs
.oi
.data_digest
));
5830 obs
.oi
.clear_data_digest();
5831 write_update_size_and_usage(ctx
->delta_stats
, oi
, ctx
->modified_ranges
,
5832 op
.extent
.offset
, op
.extent
.length
);
5837 case CEPH_OSD_OP_WRITEFULL
:
5839 { // write full object
5840 tracepoint(osd
, do_osd_op_pre_writefull
, soid
.oid
.name
.c_str(), soid
.snap
.val
, oi
.size
, 0, op
.extent
.length
);
5842 if (op
.extent
.length
!= osd_op
.indata
.length()) {
5846 result
= check_offset_and_length(0, op
.extent
.length
, cct
->_conf
->osd_max_object_size
);
5850 if (pool
.info
.has_flag(pg_pool_t::FLAG_WRITE_FADVISE_DONTNEED
))
5851 op
.flags
= op
.flags
| CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
;
5853 maybe_create_new_object(ctx
);
5854 if (pool
.info
.require_rollback()) {
5855 t
->truncate(soid
, 0);
5856 } else if (obs
.exists
&& op
.extent
.length
< oi
.size
) {
5857 t
->truncate(soid
, op
.extent
.length
);
5859 if (op
.extent
.length
) {
5860 t
->write(soid
, 0, op
.extent
.length
, osd_op
.indata
, op
.flags
);
5862 obs
.oi
.set_data_digest(osd_op
.indata
.crc32c(-1));
5864 write_update_size_and_usage(ctx
->delta_stats
, oi
, ctx
->modified_ranges
,
5865 0, op
.extent
.length
, true);
5869 case CEPH_OSD_OP_WRITESAME
:
5871 tracepoint(osd
, do_osd_op_pre_writesame
, soid
.oid
.name
.c_str(), soid
.snap
.val
, oi
.size
, op
.writesame
.offset
, op
.writesame
.length
, op
.writesame
.data_length
);
5872 result
= do_writesame(ctx
, osd_op
);
5875 case CEPH_OSD_OP_ROLLBACK
:
5877 tracepoint(osd
, do_osd_op_pre_rollback
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5878 result
= _rollback_to(ctx
, op
);
5881 case CEPH_OSD_OP_ZERO
:
5882 tracepoint(osd
, do_osd_op_pre_zero
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.extent
.offset
, op
.extent
.length
);
5883 if (pool
.info
.requires_aligned_append()) {
5884 result
= -EOPNOTSUPP
;
5889 result
= check_offset_and_length(op
.extent
.offset
, op
.extent
.length
, cct
->_conf
->osd_max_object_size
);
5892 assert(op
.extent
.length
);
5893 if (obs
.exists
&& !oi
.is_whiteout()) {
5894 t
->zero(soid
, op
.extent
.offset
, op
.extent
.length
);
5895 interval_set
<uint64_t> ch
;
5896 ch
.insert(op
.extent
.offset
, op
.extent
.length
);
5897 ctx
->modified_ranges
.union_of(ch
);
5898 ctx
->delta_stats
.num_wr
++;
5899 oi
.clear_data_digest();
5905 case CEPH_OSD_OP_CREATE
:
5908 tracepoint(osd
, do_osd_op_pre_create
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5909 int flags
= le32_to_cpu(op
.flags
);
5910 if (obs
.exists
&& !oi
.is_whiteout() &&
5911 (flags
& CEPH_OSD_OP_FLAG_EXCL
)) {
5912 result
= -EEXIST
; /* this is an exclusive create */
5914 if (osd_op
.indata
.length()) {
5915 bufferlist::iterator p
= osd_op
.indata
.begin();
5918 ::decode(category
, p
);
5920 catch (buffer::error
& e
) {
5924 // category is no longer implemented.
5927 maybe_create_new_object(ctx
);
5934 case CEPH_OSD_OP_TRIMTRUNC
:
5935 op
.extent
.offset
= op
.extent
.truncate_size
;
5938 case CEPH_OSD_OP_TRUNCATE
:
5939 tracepoint(osd
, do_osd_op_pre_truncate
, soid
.oid
.name
.c_str(), soid
.snap
.val
, oi
.size
, oi
.truncate_seq
, op
.extent
.offset
, op
.extent
.length
, op
.extent
.truncate_size
, op
.extent
.truncate_seq
);
5940 if (pool
.info
.requires_aligned_append()) {
5941 result
= -EOPNOTSUPP
;
5947 if (!obs
.exists
|| oi
.is_whiteout()) {
5948 dout(10) << " object dne, truncate is a no-op" << dendl
;
5952 if (op
.extent
.offset
> cct
->_conf
->osd_max_object_size
) {
5957 if (op
.extent
.truncate_seq
) {
5958 assert(op
.extent
.offset
== op
.extent
.truncate_size
);
5959 if (op
.extent
.truncate_seq
<= oi
.truncate_seq
) {
5960 dout(10) << " truncate seq " << op
.extent
.truncate_seq
<< " <= current " << oi
.truncate_seq
5961 << ", no-op" << dendl
;
5964 dout(10) << " truncate seq " << op
.extent
.truncate_seq
<< " > current " << oi
.truncate_seq
5965 << ", truncating" << dendl
;
5966 oi
.truncate_seq
= op
.extent
.truncate_seq
;
5967 oi
.truncate_size
= op
.extent
.truncate_size
;
5970 maybe_create_new_object(ctx
);
5971 t
->truncate(soid
, op
.extent
.offset
);
5972 if (oi
.size
> op
.extent
.offset
) {
5973 interval_set
<uint64_t> trim
;
5974 trim
.insert(op
.extent
.offset
, oi
.size
-op
.extent
.offset
);
5975 ctx
->modified_ranges
.union_of(trim
);
5977 if (op
.extent
.offset
!= oi
.size
) {
5978 ctx
->delta_stats
.num_bytes
-= oi
.size
;
5979 ctx
->delta_stats
.num_bytes
+= op
.extent
.offset
;
5980 oi
.size
= op
.extent
.offset
;
5982 ctx
->delta_stats
.num_wr
++;
5983 // do no set exists, or we will break above DELETE -> TRUNCATE munging.
5985 oi
.clear_data_digest();
5989 case CEPH_OSD_OP_DELETE
:
5991 tracepoint(osd
, do_osd_op_pre_delete
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5993 result
= _delete_oid(ctx
, false, ctx
->ignore_cache
);
5997 case CEPH_OSD_OP_WATCH
:
6000 tracepoint(osd
, do_osd_op_pre_watch
, soid
.oid
.name
.c_str(), soid
.snap
.val
,
6001 op
.watch
.cookie
, op
.watch
.op
);
6006 uint64_t cookie
= op
.watch
.cookie
;
6007 entity_name_t entity
= ctx
->reqid
.name
;
6008 ObjectContextRef obc
= ctx
->obc
;
6010 dout(10) << "watch " << ceph_osd_watch_op_name(op
.watch
.op
)
6011 << ": ctx->obc=" << (void *)obc
.get() << " cookie=" << cookie
6012 << " oi.version=" << oi
.version
.version
<< " ctx->at_version=" << ctx
->at_version
<< dendl
;
6013 dout(10) << "watch: oi.user_version=" << oi
.user_version
<< dendl
;
6014 dout(10) << "watch: peer_addr="
6015 << ctx
->op
->get_req()->get_connection()->get_peer_addr() << dendl
;
6017 uint32_t timeout
= cct
->_conf
->osd_client_watch_timeout
;
6018 if (op
.watch
.timeout
!= 0) {
6019 timeout
= op
.watch
.timeout
;
6022 watch_info_t
w(cookie
, timeout
,
6023 ctx
->op
->get_req()->get_connection()->get_peer_addr());
6024 if (op
.watch
.op
== CEPH_OSD_WATCH_OP_WATCH
||
6025 op
.watch
.op
== CEPH_OSD_WATCH_OP_LEGACY_WATCH
) {
6026 if (oi
.watchers
.count(make_pair(cookie
, entity
))) {
6027 dout(10) << " found existing watch " << w
<< " by " << entity
<< dendl
;
6029 dout(10) << " registered new watch " << w
<< " by " << entity
<< dendl
;
6030 oi
.watchers
[make_pair(cookie
, entity
)] = w
;
6031 t
->nop(soid
); // make sure update the object_info on disk!
6033 bool will_ping
= (op
.watch
.op
== CEPH_OSD_WATCH_OP_WATCH
);
6034 ctx
->watch_connects
.push_back(make_pair(w
, will_ping
));
6035 } else if (op
.watch
.op
== CEPH_OSD_WATCH_OP_RECONNECT
) {
6036 if (!oi
.watchers
.count(make_pair(cookie
, entity
))) {
6040 dout(10) << " found existing watch " << w
<< " by " << entity
<< dendl
;
6041 ctx
->watch_connects
.push_back(make_pair(w
, true));
6042 } else if (op
.watch
.op
== CEPH_OSD_WATCH_OP_PING
) {
6043 /* Note: WATCH with PING doesn't cause may_write() to return true,
6044 * so if there is nothing else in the transaction, this is going
6045 * to run do_osd_op_effects, but not write out a log entry */
6046 if (!oi
.watchers
.count(make_pair(cookie
, entity
))) {
6050 map
<pair
<uint64_t,entity_name_t
>,WatchRef
>::iterator p
=
6051 obc
->watchers
.find(make_pair(cookie
, entity
));
6052 if (p
== obc
->watchers
.end() ||
6053 !p
->second
->is_connected()) {
6054 // client needs to reconnect
6055 result
= -ETIMEDOUT
;
6058 dout(10) << " found existing watch " << w
<< " by " << entity
<< dendl
;
6059 p
->second
->got_ping(ceph_clock_now());
6061 } else if (op
.watch
.op
== CEPH_OSD_WATCH_OP_UNWATCH
) {
6062 map
<pair
<uint64_t, entity_name_t
>, watch_info_t
>::iterator oi_iter
=
6063 oi
.watchers
.find(make_pair(cookie
, entity
));
6064 if (oi_iter
!= oi
.watchers
.end()) {
6065 dout(10) << " removed watch " << oi_iter
->second
<< " by "
6067 oi
.watchers
.erase(oi_iter
);
6068 t
->nop(soid
); // update oi on disk
6069 ctx
->watch_disconnects
.push_back(
6070 watch_disconnect_t(cookie
, entity
, false));
6072 dout(10) << " can't remove: no watch by " << entity
<< dendl
;
6078 case CEPH_OSD_OP_CACHE_PIN
:
6079 tracepoint(osd
, do_osd_op_pre_cache_pin
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6080 if ((!pool
.info
.is_tier() ||
6081 pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
)) {
6083 dout(10) << " pin object is only allowed on the cache tier " << dendl
;
6088 if (!obs
.exists
|| oi
.is_whiteout()) {
6093 if (!oi
.is_cache_pinned()) {
6094 oi
.set_flag(object_info_t::FLAG_CACHE_PIN
);
6096 ctx
->delta_stats
.num_objects_pinned
++;
6097 ctx
->delta_stats
.num_wr
++;
6103 case CEPH_OSD_OP_CACHE_UNPIN
:
6104 tracepoint(osd
, do_osd_op_pre_cache_unpin
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6105 if ((!pool
.info
.is_tier() ||
6106 pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
)) {
6108 dout(10) << " pin object is only allowed on the cache tier " << dendl
;
6113 if (!obs
.exists
|| oi
.is_whiteout()) {
6118 if (oi
.is_cache_pinned()) {
6119 oi
.clear_flag(object_info_t::FLAG_CACHE_PIN
);
6121 ctx
->delta_stats
.num_objects_pinned
--;
6122 ctx
->delta_stats
.num_wr
++;
6128 case CEPH_OSD_OP_SET_REDIRECT
:
6131 if (pool
.info
.is_tier()) {
6139 if (get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
6140 result
= -EOPNOTSUPP
;
6144 object_t target_name
;
6145 object_locator_t target_oloc
;
6146 snapid_t target_snapid
= (uint64_t)op
.copy_from
.snapid
;
6147 version_t target_version
= op
.copy_from
.src_version
;
6149 ::decode(target_name
, bp
);
6150 ::decode(target_oloc
, bp
);
6152 catch (buffer::error
& e
) {
6157 get_osdmap()->object_locator_to_pg(target_name
, target_oloc
, raw_pg
);
6158 hobject_t
target(target_name
, target_oloc
.key
, target_snapid
,
6159 raw_pg
.ps(), raw_pg
.pool(),
6160 target_oloc
.nspace
);
6161 if (target
== soid
) {
6162 dout(20) << " set-redirect self is invalid" << dendl
;
6166 oi
.set_flag(object_info_t::FLAG_MANIFEST
);
6167 oi
.manifest
.redirect_target
= target
;
6168 oi
.manifest
.type
= object_manifest_t::TYPE_REDIRECT
;
6169 t
->truncate(soid
, 0);
6170 if (oi
.is_omap() && pool
.info
.supports_omap()) {
6171 t
->omap_clear(soid
);
6172 obs
.oi
.clear_omap_digest();
6173 obs
.oi
.clear_flag(object_info_t::FLAG_OMAP
);
6175 ctx
->delta_stats
.num_bytes
-= oi
.size
;
6178 oi
.user_version
= target_version
;
6179 ctx
->user_at_version
= target_version
;
6181 map
<string
,bufferlist
> rmattrs
;
6182 result
= getattrs_maybe_cache(ctx
->obc
,
6188 map
<string
, bufferlist
>::iterator iter
;
6189 for (iter
= rmattrs
.begin(); iter
!= rmattrs
.end(); ++iter
) {
6190 const string
& name
= iter
->first
;
6191 t
->rmattr(soid
, name
);
6193 dout(10) << "set-redirect oid:" << oi
.soid
<< " user_version: " << oi
.user_version
<< dendl
;
6198 // -- object attrs --
6200 case CEPH_OSD_OP_SETXATTR
:
6203 if (cct
->_conf
->osd_max_attr_size
> 0 &&
6204 op
.xattr
.value_len
> cct
->_conf
->osd_max_attr_size
) {
6205 tracepoint(osd
, do_osd_op_pre_setxattr
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???");
6209 unsigned max_name_len
= MIN(osd
->store
->get_max_attr_name_length(),
6210 cct
->_conf
->osd_max_attr_name_len
);
6211 if (op
.xattr
.name_len
> max_name_len
) {
6212 result
= -ENAMETOOLONG
;
6215 maybe_create_new_object(ctx
);
6217 bp
.copy(op
.xattr
.name_len
, aname
);
6218 tracepoint(osd
, do_osd_op_pre_setxattr
, soid
.oid
.name
.c_str(), soid
.snap
.val
, aname
.c_str());
6219 string name
= "_" + aname
;
6221 bp
.copy(op
.xattr
.value_len
, bl
);
6222 t
->setattr(soid
, name
, bl
);
6223 ctx
->delta_stats
.num_wr
++;
6227 case CEPH_OSD_OP_RMXATTR
:
6231 bp
.copy(op
.xattr
.name_len
, aname
);
6232 tracepoint(osd
, do_osd_op_pre_rmxattr
, soid
.oid
.name
.c_str(), soid
.snap
.val
, aname
.c_str());
6233 if (!obs
.exists
|| oi
.is_whiteout()) {
6237 string name
= "_" + aname
;
6238 t
->rmattr(soid
, name
);
6239 ctx
->delta_stats
.num_wr
++;
6244 // -- fancy writers --
6245 case CEPH_OSD_OP_APPEND
:
6247 tracepoint(osd
, do_osd_op_pre_append
, soid
.oid
.name
.c_str(), soid
.snap
.val
, oi
.size
, oi
.truncate_seq
, op
.extent
.offset
, op
.extent
.length
, op
.extent
.truncate_size
, op
.extent
.truncate_seq
);
6248 // just do it inline; this works because we are happy to execute
6249 // fancy op on replicas as well.
6250 vector
<OSDOp
> nops(1);
6251 OSDOp
& newop
= nops
[0];
6252 newop
.op
.op
= CEPH_OSD_OP_WRITE
;
6253 newop
.op
.extent
.offset
= oi
.size
;
6254 newop
.op
.extent
.length
= op
.extent
.length
;
6255 newop
.op
.extent
.truncate_seq
= oi
.truncate_seq
;
6256 newop
.indata
= osd_op
.indata
;
6257 result
= do_osd_ops(ctx
, nops
);
6258 osd_op
.outdata
.claim(newop
.outdata
);
6262 case CEPH_OSD_OP_STARTSYNC
:
6263 tracepoint(osd
, do_osd_op_pre_startsync
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6268 // -- trivial map --
6269 case CEPH_OSD_OP_TMAPGET
:
6270 tracepoint(osd
, do_osd_op_pre_tmapget
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6271 if (pool
.info
.require_rollback()) {
6272 result
= -EOPNOTSUPP
;
6276 vector
<OSDOp
> nops(1);
6277 OSDOp
& newop
= nops
[0];
6278 newop
.op
.op
= CEPH_OSD_OP_SYNC_READ
;
6279 newop
.op
.extent
.offset
= 0;
6280 newop
.op
.extent
.length
= 0;
6281 do_osd_ops(ctx
, nops
);
6282 osd_op
.outdata
.claim(newop
.outdata
);
6286 case CEPH_OSD_OP_TMAPPUT
:
6287 tracepoint(osd
, do_osd_op_pre_tmapput
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6288 if (pool
.info
.require_rollback()) {
6289 result
= -EOPNOTSUPP
;
6293 //_dout_lock.Lock();
6294 //osd_op.data.hexdump(*_dout);
6295 //_dout_lock.Unlock();
6297 // verify sort order
6298 bool unsorted
= false;
6301 ::decode(header
, bp
);
6308 dout(10) << "tmapput key " << key
<< dendl
;
6311 if (key
< last_key
) {
6312 dout(10) << "TMAPPUT is unordered; resorting" << dendl
;
6321 vector
<OSDOp
> nops(1);
6322 OSDOp
& newop
= nops
[0];
6323 newop
.op
.op
= CEPH_OSD_OP_WRITEFULL
;
6324 newop
.op
.extent
.offset
= 0;
6325 newop
.op
.extent
.length
= osd_op
.indata
.length();
6326 newop
.indata
= osd_op
.indata
;
6329 bp
= osd_op
.indata
.begin();
6331 map
<string
, bufferlist
> m
;
6332 ::decode(header
, bp
);
6336 ::encode(header
, newbl
);
6338 newop
.indata
= newbl
;
6340 result
= do_osd_ops(ctx
, nops
);
6341 assert(result
== 0);
6345 case CEPH_OSD_OP_TMAPUP
:
6346 tracepoint(osd
, do_osd_op_pre_tmapup
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6347 if (pool
.info
.require_rollback()) {
6348 result
= -EOPNOTSUPP
;
6352 result
= do_tmapup(ctx
, bp
, osd_op
);
6355 case CEPH_OSD_OP_TMAP2OMAP
:
6357 tracepoint(osd
, do_osd_op_pre_tmap2omap
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6358 result
= do_tmap2omap(ctx
, op
.tmap2omap
.flags
);
6362 case CEPH_OSD_OP_OMAPGETKEYS
:
6366 uint64_t max_return
;
6368 ::decode(start_after
, bp
);
6369 ::decode(max_return
, bp
);
6371 catch (buffer::error
& e
) {
6373 tracepoint(osd
, do_osd_op_pre_omapgetkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???", 0);
6376 if (max_return
> cct
->_conf
->osd_max_omap_entries_per_request
) {
6377 max_return
= cct
->_conf
->osd_max_omap_entries_per_request
;
6379 tracepoint(osd
, do_osd_op_pre_omapgetkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
, start_after
.c_str(), max_return
);
6383 bool truncated
= false;
6385 ObjectMap::ObjectMapIterator iter
= osd
->store
->get_omap_iterator(
6386 coll
, ghobject_t(soid
)
6389 iter
->upper_bound(start_after
);
6390 for (num
= 0; iter
->valid(); ++num
, iter
->next(false)) {
6391 if (num
>= max_return
||
6392 bl
.length() >= cct
->_conf
->osd_max_omap_bytes_per_request
) {
6396 ::encode(iter
->key(), bl
);
6398 } // else return empty out_set
6399 ::encode(num
, osd_op
.outdata
);
6400 osd_op
.outdata
.claim_append(bl
);
6401 ::encode(truncated
, osd_op
.outdata
);
6402 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(osd_op
.outdata
.length(), 10);
6403 ctx
->delta_stats
.num_rd
++;
6407 case CEPH_OSD_OP_OMAPGETVALS
:
6411 uint64_t max_return
;
6412 string filter_prefix
;
6414 ::decode(start_after
, bp
);
6415 ::decode(max_return
, bp
);
6416 ::decode(filter_prefix
, bp
);
6418 catch (buffer::error
& e
) {
6420 tracepoint(osd
, do_osd_op_pre_omapgetvals
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???", 0, "???");
6423 if (max_return
> cct
->_conf
->osd_max_omap_entries_per_request
) {
6424 max_return
= cct
->_conf
->osd_max_omap_entries_per_request
;
6426 tracepoint(osd
, do_osd_op_pre_omapgetvals
, soid
.oid
.name
.c_str(), soid
.snap
.val
, start_after
.c_str(), max_return
, filter_prefix
.c_str());
6429 bool truncated
= false;
6432 ObjectMap::ObjectMapIterator iter
= osd
->store
->get_omap_iterator(
6433 coll
, ghobject_t(soid
)
6439 iter
->upper_bound(start_after
);
6440 if (filter_prefix
> start_after
) iter
->lower_bound(filter_prefix
);
6443 iter
->key().substr(0, filter_prefix
.size()) == filter_prefix
;
6444 ++num
, iter
->next(false)) {
6445 dout(20) << "Found key " << iter
->key() << dendl
;
6446 if (num
>= max_return
||
6447 bl
.length() >= cct
->_conf
->osd_max_omap_bytes_per_request
) {
6451 ::encode(iter
->key(), bl
);
6452 ::encode(iter
->value(), bl
);
6454 } // else return empty out_set
6455 ::encode(num
, osd_op
.outdata
);
6456 osd_op
.outdata
.claim_append(bl
);
6457 ::encode(truncated
, osd_op
.outdata
);
6458 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(osd_op
.outdata
.length(), 10);
6459 ctx
->delta_stats
.num_rd
++;
6463 case CEPH_OSD_OP_OMAPGETHEADER
:
6464 tracepoint(osd
, do_osd_op_pre_omapgetheader
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6465 if (!oi
.is_omap()) {
6466 // return empty header
6471 osd
->store
->omap_get_header(ch
, ghobject_t(soid
), &osd_op
.outdata
);
6472 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(osd_op
.outdata
.length(), 10);
6473 ctx
->delta_stats
.num_rd
++;
6477 case CEPH_OSD_OP_OMAPGETVALSBYKEYS
:
6480 set
<string
> keys_to_get
;
6482 ::decode(keys_to_get
, bp
);
6484 catch (buffer::error
& e
) {
6486 tracepoint(osd
, do_osd_op_pre_omapgetvalsbykeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???");
6489 tracepoint(osd
, do_osd_op_pre_omapgetvalsbykeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
, list_entries(keys_to_get
).c_str());
6490 map
<string
, bufferlist
> out
;
6492 osd
->store
->omap_get_values(ch
, ghobject_t(soid
), keys_to_get
, &out
);
6493 } // else return empty omap entries
6494 ::encode(out
, osd_op
.outdata
);
6495 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(osd_op
.outdata
.length(), 10);
6496 ctx
->delta_stats
.num_rd
++;
6500 case CEPH_OSD_OP_OMAP_CMP
:
6503 if (!obs
.exists
|| oi
.is_whiteout()) {
6505 tracepoint(osd
, do_osd_op_pre_omap_cmp
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???");
6508 map
<string
, pair
<bufferlist
, int> > assertions
;
6510 ::decode(assertions
, bp
);
6512 catch (buffer::error
& e
) {
6514 tracepoint(osd
, do_osd_op_pre_omap_cmp
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???");
6517 tracepoint(osd
, do_osd_op_pre_omap_cmp
, soid
.oid
.name
.c_str(), soid
.snap
.val
, list_keys(assertions
).c_str());
6519 map
<string
, bufferlist
> out
;
6523 for (map
<string
, pair
<bufferlist
, int> >::iterator i
= assertions
.begin();
6524 i
!= assertions
.end();
6526 to_get
.insert(i
->first
);
6527 int r
= osd
->store
->omap_get_values(ch
, ghobject_t(soid
),
6533 } // else leave out empty
6535 //Should set num_rd_kb based on encode length of map
6536 ctx
->delta_stats
.num_rd
++;
6540 for (map
<string
, pair
<bufferlist
, int> >::iterator i
= assertions
.begin();
6541 i
!= assertions
.end();
6543 auto out_entry
= out
.find(i
->first
);
6544 bufferlist
&bl
= (out_entry
!= out
.end()) ?
6545 out_entry
->second
: empty
;
6546 switch (i
->second
.second
) {
6547 case CEPH_OSD_CMPXATTR_OP_EQ
:
6548 if (!(bl
== i
->second
.first
)) {
6552 case CEPH_OSD_CMPXATTR_OP_LT
:
6553 if (!(bl
< i
->second
.first
)) {
6557 case CEPH_OSD_CMPXATTR_OP_GT
:
6558 if (!(bl
> i
->second
.first
)) {
6576 case CEPH_OSD_OP_OMAPSETVALS
:
6577 if (!pool
.info
.supports_omap()) {
6578 result
= -EOPNOTSUPP
;
6579 tracepoint(osd
, do_osd_op_pre_omapsetvals
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6584 maybe_create_new_object(ctx
);
6585 bufferlist to_set_bl
;
6587 decode_str_str_map_to_bl(bp
, &to_set_bl
);
6589 catch (buffer::error
& e
) {
6591 tracepoint(osd
, do_osd_op_pre_omapsetvals
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6594 tracepoint(osd
, do_osd_op_pre_omapsetvals
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6595 if (cct
->_conf
->subsys
.should_gather(dout_subsys
, 20)) {
6596 dout(20) << "setting vals: " << dendl
;
6597 map
<string
,bufferlist
> to_set
;
6598 bufferlist::iterator pt
= to_set_bl
.begin();
6599 ::decode(to_set
, pt
);
6600 for (map
<string
, bufferlist
>::iterator i
= to_set
.begin();
6603 dout(20) << "\t" << i
->first
<< dendl
;
6606 t
->omap_setkeys(soid
, to_set_bl
);
6607 ctx
->delta_stats
.num_wr
++;
6609 obs
.oi
.set_flag(object_info_t::FLAG_OMAP
);
6610 obs
.oi
.clear_omap_digest();
6613 case CEPH_OSD_OP_OMAPSETHEADER
:
6614 tracepoint(osd
, do_osd_op_pre_omapsetheader
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6615 if (!pool
.info
.supports_omap()) {
6616 result
= -EOPNOTSUPP
;
6621 maybe_create_new_object(ctx
);
6622 t
->omap_setheader(soid
, osd_op
.indata
);
6623 ctx
->delta_stats
.num_wr
++;
6625 obs
.oi
.set_flag(object_info_t::FLAG_OMAP
);
6626 obs
.oi
.clear_omap_digest();
6629 case CEPH_OSD_OP_OMAPCLEAR
:
6630 tracepoint(osd
, do_osd_op_pre_omapclear
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6631 if (!pool
.info
.supports_omap()) {
6632 result
= -EOPNOTSUPP
;
6637 if (!obs
.exists
|| oi
.is_whiteout()) {
6642 t
->omap_clear(soid
);
6643 ctx
->delta_stats
.num_wr
++;
6644 obs
.oi
.clear_omap_digest();
6645 obs
.oi
.clear_flag(object_info_t::FLAG_OMAP
);
6650 case CEPH_OSD_OP_OMAPRMKEYS
:
6651 if (!pool
.info
.supports_omap()) {
6652 result
= -EOPNOTSUPP
;
6653 tracepoint(osd
, do_osd_op_pre_omaprmkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6658 if (!obs
.exists
|| oi
.is_whiteout()) {
6660 tracepoint(osd
, do_osd_op_pre_omaprmkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6663 bufferlist to_rm_bl
;
6665 decode_str_set_to_bl(bp
, &to_rm_bl
);
6667 catch (buffer::error
& e
) {
6669 tracepoint(osd
, do_osd_op_pre_omaprmkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6672 tracepoint(osd
, do_osd_op_pre_omaprmkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6673 t
->omap_rmkeys(soid
, to_rm_bl
);
6674 ctx
->delta_stats
.num_wr
++;
6676 obs
.oi
.clear_omap_digest();
6679 case CEPH_OSD_OP_COPY_GET
:
6681 tracepoint(osd
, do_osd_op_pre_copy_get
, soid
.oid
.name
.c_str(),
6683 if (op_finisher
== nullptr) {
6684 result
= do_copy_get(ctx
, bp
, osd_op
, ctx
->obc
);
6686 result
= op_finisher
->execute();
6690 case CEPH_OSD_OP_COPY_FROM
:
6694 object_locator_t src_oloc
;
6695 snapid_t src_snapid
= (uint64_t)op
.copy_from
.snapid
;
6696 version_t src_version
= op
.copy_from
.src_version
;
6698 ::decode(src_name
, bp
);
6699 ::decode(src_oloc
, bp
);
6701 catch (buffer::error
& e
) {
6704 do_osd_op_pre_copy_from
,
6705 soid
.oid
.name
.c_str(),
6717 do_osd_op_pre_copy_from
,
6718 soid
.oid
.name
.c_str(),
6720 src_name
.name
.c_str(),
6722 src_oloc
.key
.c_str(),
6723 src_oloc
.nspace
.c_str(),
6727 if (op_finisher
== nullptr) {
6730 get_osdmap()->object_locator_to_pg(src_name
, src_oloc
, raw_pg
);
6731 hobject_t
src(src_name
, src_oloc
.key
, src_snapid
,
6732 raw_pg
.ps(), raw_pg
.pool(),
6735 dout(20) << " copy from self is invalid" << dendl
;
6739 CopyFromCallback
*cb
= new CopyFromCallback(ctx
, osd_op
);
6740 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
6741 new CopyFromFinisher(cb
));
6742 start_copy(cb
, ctx
->obc
, src
, src_oloc
, src_version
,
6745 op
.copy_from
.src_fadvise_flags
,
6747 result
= -EINPROGRESS
;
6750 result
= op_finisher
->execute();
6751 assert(result
== 0);
6753 // COPY_FROM cannot be executed multiple times -- it must restart
6754 ctx
->op_finishers
.erase(ctx
->current_osd_subop_num
);
6760 tracepoint(osd
, do_osd_op_pre_unknown
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.op
, ceph_osd_op_name(op
.op
));
6761 dout(1) << "unrecognized osd op " << op
.op
6762 << " " << ceph_osd_op_name(op
.op
)
6764 result
= -EOPNOTSUPP
;
6768 osd_op
.rval
= result
;
6769 tracepoint(osd
, do_osd_op_post
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.op
, ceph_osd_op_name(op
.op
), op
.flags
, result
);
6770 if (result
< 0 && (op
.flags
& CEPH_OSD_OP_FLAG_FAILOK
))
6779 int PrimaryLogPG::_get_tmap(OpContext
*ctx
, bufferlist
*header
, bufferlist
*vals
)
6781 if (ctx
->new_obs
.oi
.size
== 0) {
6782 dout(20) << "unable to get tmap for zero sized " << ctx
->new_obs
.oi
.soid
<< dendl
;
6785 vector
<OSDOp
> nops(1);
6786 OSDOp
&newop
= nops
[0];
6787 newop
.op
.op
= CEPH_OSD_OP_TMAPGET
;
6788 do_osd_ops(ctx
, nops
);
6790 bufferlist::iterator i
= newop
.outdata
.begin();
6791 ::decode(*header
, i
);
6792 (*vals
).substr_of(newop
.outdata
, i
.get_off(), i
.get_remaining());
6794 dout(20) << "unsuccessful at decoding tmap for " << ctx
->new_obs
.oi
.soid
6798 dout(20) << "successful at decoding tmap for " << ctx
->new_obs
.oi
.soid
6803 int PrimaryLogPG::_verify_no_head_clones(const hobject_t
& soid
,
6806 // verify that all clones have been evicted
6807 dout(20) << __func__
<< " verifying clones are absent "
6809 for (vector
<snapid_t
>::const_iterator p
= ss
.clones
.begin();
6810 p
!= ss
.clones
.end();
6812 hobject_t clone_oid
= soid
;
6813 clone_oid
.snap
= *p
;
6814 if (is_missing_object(clone_oid
))
6816 ObjectContextRef clone_obc
= get_object_context(clone_oid
, false);
6817 if (clone_obc
&& clone_obc
->obs
.exists
) {
6818 dout(10) << __func__
<< " cannot evict head before clone "
6819 << clone_oid
<< dendl
;
6822 if (copy_ops
.count(clone_oid
)) {
6823 dout(10) << __func__
<< " cannot evict head, pending promote on clone "
6824 << clone_oid
<< dendl
;
6831 inline int PrimaryLogPG::_delete_oid(
6833 bool no_whiteout
, // no whiteouts, no matter what.
6834 bool try_no_whiteout
) // try not to whiteout
6836 SnapSet
& snapset
= ctx
->new_snapset
;
6837 ObjectState
& obs
= ctx
->new_obs
;
6838 object_info_t
& oi
= obs
.oi
;
6839 const hobject_t
& soid
= oi
.soid
;
6840 PGTransaction
* t
= ctx
->op_t
.get();
6842 // cache: cache: set whiteout on delete?
6843 bool whiteout
= false;
6844 if (pool
.info
.cache_mode
!= pg_pool_t::CACHEMODE_NONE
6846 && !try_no_whiteout
) {
6850 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_LUMINOUS
) {
6852 // in luminous or later, we can't delete the head if there are
6853 // clones. we trust the caller passing no_whiteout has already
6854 // verified they don't exist.
6855 if (!snapset
.clones
.empty() ||
6856 (!ctx
->snapc
.snaps
.empty() && ctx
->snapc
.snaps
[0] > snapset
.seq
)) {
6858 dout(20) << __func__
<< " has or will have clones but no_whiteout=1"
6861 dout(20) << __func__
<< " has or will have clones; will whiteout"
6869 dout(20) << __func__
<< " " << soid
<< " whiteout=" << (int)whiteout
6870 << " no_whiteout=" << (int)no_whiteout
6871 << " try_no_whiteout=" << (int)try_no_whiteout
6873 if (!obs
.exists
|| (obs
.oi
.is_whiteout() && whiteout
))
6879 interval_set
<uint64_t> ch
;
6880 ch
.insert(0, oi
.size
);
6881 ctx
->modified_ranges
.union_of(ch
);
6884 ctx
->delta_stats
.num_wr
++;
6885 if (soid
.is_snap()) {
6886 assert(ctx
->obc
->ssc
->snapset
.clone_overlap
.count(soid
.snap
));
6887 ctx
->delta_stats
.num_bytes
-= ctx
->obc
->ssc
->snapset
.get_clone_bytes(soid
.snap
);
6889 ctx
->delta_stats
.num_bytes
-= oi
.size
;
6894 // disconnect all watchers
6895 for (map
<pair
<uint64_t, entity_name_t
>, watch_info_t
>::iterator p
=
6896 oi
.watchers
.begin();
6897 p
!= oi
.watchers
.end();
6899 dout(20) << __func__
<< " will disconnect watcher " << p
->first
<< dendl
;
6900 ctx
->watch_disconnects
.push_back(
6901 watch_disconnect_t(p
->first
.first
, p
->first
.second
, true));
6903 oi
.watchers
.clear();
6906 dout(20) << __func__
<< " setting whiteout on " << soid
<< dendl
;
6907 oi
.set_flag(object_info_t::FLAG_WHITEOUT
);
6908 ctx
->delta_stats
.num_whiteouts
++;
6910 osd
->logger
->inc(l_osd_tier_whiteout
);
6915 ctx
->delta_stats
.num_objects
--;
6917 ctx
->delta_stats
.num_object_clones
--;
6918 if (oi
.is_whiteout()) {
6919 dout(20) << __func__
<< " deleting whiteout on " << soid
<< dendl
;
6920 ctx
->delta_stats
.num_whiteouts
--;
6921 oi
.clear_flag(object_info_t::FLAG_WHITEOUT
);
6923 if (oi
.is_cache_pinned()) {
6924 ctx
->delta_stats
.num_objects_pinned
--;
6926 if ((legacy
|| snapset
.is_legacy()) && soid
.is_head()) {
6927 snapset
.head_exists
= false;
6933 int PrimaryLogPG::_rollback_to(OpContext
*ctx
, ceph_osd_op
& op
)
6935 SnapSet
& snapset
= ctx
->new_snapset
;
6936 ObjectState
& obs
= ctx
->new_obs
;
6937 object_info_t
& oi
= obs
.oi
;
6938 const hobject_t
& soid
= oi
.soid
;
6939 PGTransaction
* t
= ctx
->op_t
.get();
6940 snapid_t snapid
= (uint64_t)op
.snap
.snapid
;
6941 hobject_t missing_oid
;
6943 dout(10) << "_rollback_to " << soid
<< " snapid " << snapid
<< dendl
;
6945 ObjectContextRef rollback_to
;
6946 int ret
= find_object_context(
6947 hobject_t(soid
.oid
, soid
.get_key(), snapid
, soid
.get_hash(), info
.pgid
.pool(),
6948 soid
.get_namespace()),
6949 &rollback_to
, false, false, &missing_oid
);
6950 if (ret
== -EAGAIN
) {
6951 /* clone must be missing */
6952 assert(is_degraded_or_backfilling_object(missing_oid
));
6953 dout(20) << "_rollback_to attempted to roll back to a missing or backfilling clone "
6954 << missing_oid
<< " (requested snapid: ) " << snapid
<< dendl
;
6955 block_write_on_degraded_snap(missing_oid
, ctx
->op
);
6959 ObjectContextRef promote_obc
;
6960 cache_result_t tier_mode_result
;
6961 if (obs
.exists
&& obs
.oi
.has_manifest()) {
6963 maybe_handle_manifest_detail(
6969 maybe_handle_cache_detail(
6979 switch (tier_mode_result
) {
6980 case cache_result_t::NOOP
:
6982 case cache_result_t::BLOCKED_PROMOTE
:
6983 assert(promote_obc
);
6984 block_write_on_snap_rollback(soid
, promote_obc
, ctx
->op
);
6986 case cache_result_t::BLOCKED_FULL
:
6987 block_write_on_full_cache(soid
, ctx
->op
);
6990 assert(0 == "must promote was set, other values are not valid");
6995 if (ret
== -ENOENT
|| (rollback_to
&& rollback_to
->obs
.oi
.is_whiteout())) {
6996 // there's no snapshot here, or there's no object.
6997 // if there's no snapshot, we delete the object; otherwise, do nothing.
6998 dout(20) << "_rollback_to deleting head on " << soid
.oid
6999 << " because got ENOENT|whiteout on find_object_context" << dendl
;
7000 if (ctx
->obc
->obs
.oi
.watchers
.size()) {
7001 // Cannot delete an object with watchers
7004 _delete_oid(ctx
, false, false);
7008 // ummm....huh? It *can't* return anything else at time of writing.
7009 assert(0 == "unexpected error code in _rollback_to");
7010 } else { //we got our context, let's use it to do the rollback!
7011 hobject_t
& rollback_to_sobject
= rollback_to
->obs
.oi
.soid
;
7012 if (is_degraded_or_backfilling_object(rollback_to_sobject
)) {
7013 dout(20) << "_rollback_to attempted to roll back to a degraded object "
7014 << rollback_to_sobject
<< " (requested snapid: ) " << snapid
<< dendl
;
7015 block_write_on_degraded_snap(rollback_to_sobject
, ctx
->op
);
7017 } else if (rollback_to
->obs
.oi
.soid
.snap
== CEPH_NOSNAP
) {
7018 // rolling back to the head; we just need to clone it.
7021 /* 1) Delete current head
7022 * 2) Clone correct snapshot into head
7023 * 3) Calculate clone_overlaps by following overlaps
7024 * forward from rollback snapshot */
7025 dout(10) << "_rollback_to deleting " << soid
.oid
7026 << " and rolling back to old snap" << dendl
;
7031 t
->clone(soid
, rollback_to_sobject
);
7032 snapset
.head_exists
= true;
7033 t
->add_obc(rollback_to
);
7035 map
<snapid_t
, interval_set
<uint64_t> >::iterator iter
=
7036 snapset
.clone_overlap
.lower_bound(snapid
);
7037 interval_set
<uint64_t> overlaps
= iter
->second
;
7038 assert(iter
!= snapset
.clone_overlap
.end());
7040 iter
!= snapset
.clone_overlap
.end();
7042 overlaps
.intersection_of(iter
->second
);
7044 if (obs
.oi
.size
> 0) {
7045 interval_set
<uint64_t> modified
;
7046 modified
.insert(0, obs
.oi
.size
);
7047 overlaps
.intersection_of(modified
);
7048 modified
.subtract(overlaps
);
7049 ctx
->modified_ranges
.union_of(modified
);
7052 // Adjust the cached objectcontext
7053 maybe_create_new_object(ctx
, true);
7054 ctx
->delta_stats
.num_bytes
-= obs
.oi
.size
;
7055 ctx
->delta_stats
.num_bytes
+= rollback_to
->obs
.oi
.size
;
7056 obs
.oi
.size
= rollback_to
->obs
.oi
.size
;
7057 if (rollback_to
->obs
.oi
.is_data_digest())
7058 obs
.oi
.set_data_digest(rollback_to
->obs
.oi
.data_digest
);
7060 obs
.oi
.clear_data_digest();
7061 if (rollback_to
->obs
.oi
.is_omap_digest())
7062 obs
.oi
.set_omap_digest(rollback_to
->obs
.oi
.omap_digest
);
7064 obs
.oi
.clear_omap_digest();
7066 if (rollback_to
->obs
.oi
.is_omap()) {
7067 dout(10) << __func__
<< " setting omap flag on " << obs
.oi
.soid
<< dendl
;
7068 obs
.oi
.set_flag(object_info_t::FLAG_OMAP
);
7070 dout(10) << __func__
<< " clearing omap flag on " << obs
.oi
.soid
<< dendl
;
7071 obs
.oi
.clear_flag(object_info_t::FLAG_OMAP
);
7074 snapset
.head_exists
= true;
7080 void PrimaryLogPG::_make_clone(
7083 ObjectContextRef obc
,
7084 const hobject_t
& head
, const hobject_t
& coid
,
7088 ::encode(*poi
, bv
, get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
7090 t
->clone(coid
, head
);
7091 setattr_maybe_cache(obc
, ctx
, t
, OI_ATTR
, bv
);
7092 rmattr_maybe_cache(obc
, ctx
, t
, SS_ATTR
);
7095 void PrimaryLogPG::make_writeable(OpContext
*ctx
)
7097 const hobject_t
& soid
= ctx
->obs
->oi
.soid
;
7098 SnapContext
& snapc
= ctx
->snapc
;
7101 assert(soid
.snap
== CEPH_NOSNAP
);
7102 dout(20) << "make_writeable " << soid
<< " snapset=" << ctx
->new_snapset
7103 << " snapc=" << snapc
<< dendl
;
7105 bool was_dirty
= ctx
->obc
->obs
.oi
.is_dirty();
7106 if (ctx
->new_obs
.exists
) {
7107 // we will mark the object dirty
7108 if (ctx
->undirty
&& was_dirty
) {
7109 dout(20) << " clearing DIRTY flag" << dendl
;
7110 assert(ctx
->new_obs
.oi
.is_dirty());
7111 ctx
->new_obs
.oi
.clear_flag(object_info_t::FLAG_DIRTY
);
7112 --ctx
->delta_stats
.num_objects_dirty
;
7113 osd
->logger
->inc(l_osd_tier_clean
);
7114 } else if (!was_dirty
&& !ctx
->undirty
) {
7115 dout(20) << " setting DIRTY flag" << dendl
;
7116 ctx
->new_obs
.oi
.set_flag(object_info_t::FLAG_DIRTY
);
7117 ++ctx
->delta_stats
.num_objects_dirty
;
7118 osd
->logger
->inc(l_osd_tier_dirty
);
7122 dout(20) << " deletion, decrementing num_dirty and clearing flag" << dendl
;
7123 ctx
->new_obs
.oi
.clear_flag(object_info_t::FLAG_DIRTY
);
7124 --ctx
->delta_stats
.num_objects_dirty
;
7128 if ((ctx
->new_obs
.exists
&&
7129 ctx
->new_obs
.oi
.is_omap()) &&
7130 (!ctx
->obc
->obs
.exists
||
7131 !ctx
->obc
->obs
.oi
.is_omap())) {
7132 ++ctx
->delta_stats
.num_objects_omap
;
7134 if ((!ctx
->new_obs
.exists
||
7135 !ctx
->new_obs
.oi
.is_omap()) &&
7136 (ctx
->obc
->obs
.exists
&&
7137 ctx
->obc
->obs
.oi
.is_omap())) {
7138 --ctx
->delta_stats
.num_objects_omap
;
7142 if (ctx
->new_snapset
.seq
> snapc
.seq
) {
7143 snapc
.seq
= ctx
->new_snapset
.seq
;
7144 snapc
.snaps
= ctx
->new_snapset
.snaps
;
7145 filter_snapc(snapc
.snaps
);
7146 dout(10) << " using newer snapc " << snapc
<< dendl
;
7149 if ((ctx
->obs
->exists
&& !ctx
->obs
->oi
.is_whiteout()) && // head exist(ed)
7150 snapc
.snaps
.size() && // there are snaps
7151 !ctx
->cache_evict
&&
7152 snapc
.snaps
[0] > ctx
->new_snapset
.seq
) { // existing object is old
7154 hobject_t coid
= soid
;
7155 coid
.snap
= snapc
.seq
;
7158 for (l
=1; l
<snapc
.snaps
.size() && snapc
.snaps
[l
] > ctx
->new_snapset
.seq
; l
++) ;
7160 vector
<snapid_t
> snaps(l
);
7161 for (unsigned i
=0; i
<l
; i
++)
7162 snaps
[i
] = snapc
.snaps
[i
];
7165 object_info_t
static_snap_oi(coid
);
7166 object_info_t
*snap_oi
;
7168 ctx
->clone_obc
= object_contexts
.lookup_or_create(static_snap_oi
.soid
);
7169 ctx
->clone_obc
->destructor_callback
= new C_PG_ObjectContext(this, ctx
->clone_obc
.get());
7170 ctx
->clone_obc
->obs
.oi
= static_snap_oi
;
7171 ctx
->clone_obc
->obs
.exists
= true;
7172 ctx
->clone_obc
->ssc
= ctx
->obc
->ssc
;
7173 ctx
->clone_obc
->ssc
->ref
++;
7174 if (pool
.info
.require_rollback())
7175 ctx
->clone_obc
->attr_cache
= ctx
->obc
->attr_cache
;
7176 snap_oi
= &ctx
->clone_obc
->obs
.oi
;
7177 bool got
= ctx
->lock_manager
.get_write_greedy(
7182 dout(20) << " got greedy write on clone_obc " << *ctx
->clone_obc
<< dendl
;
7184 snap_oi
= &static_snap_oi
;
7186 snap_oi
->version
= ctx
->at_version
;
7187 snap_oi
->prior_version
= ctx
->obs
->oi
.version
;
7188 snap_oi
->copy_user_bits(ctx
->obs
->oi
);
7190 bool legacy
= ctx
->new_snapset
.is_legacy() ||
7191 get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
;
7193 snap_oi
->legacy_snaps
= snaps
;
7196 _make_clone(ctx
, ctx
->op_t
.get(), ctx
->clone_obc
, soid
, coid
, snap_oi
);
7198 ctx
->delta_stats
.num_objects
++;
7199 if (snap_oi
->is_dirty()) {
7200 ctx
->delta_stats
.num_objects_dirty
++;
7201 osd
->logger
->inc(l_osd_tier_dirty
);
7203 if (snap_oi
->is_omap())
7204 ctx
->delta_stats
.num_objects_omap
++;
7205 if (snap_oi
->is_cache_pinned())
7206 ctx
->delta_stats
.num_objects_pinned
++;
7207 ctx
->delta_stats
.num_object_clones
++;
7208 ctx
->new_snapset
.clones
.push_back(coid
.snap
);
7209 ctx
->new_snapset
.clone_size
[coid
.snap
] = ctx
->obs
->oi
.size
;
7211 ctx
->new_snapset
.clone_snaps
[coid
.snap
] = snaps
;
7214 // clone_overlap should contain an entry for each clone
7215 // (an empty interval_set if there is no overlap)
7216 ctx
->new_snapset
.clone_overlap
[coid
.snap
];
7217 if (ctx
->obs
->oi
.size
)
7218 ctx
->new_snapset
.clone_overlap
[coid
.snap
].insert(0, ctx
->obs
->oi
.size
);
7221 dout(10) << " cloning v " << ctx
->obs
->oi
.version
7222 << " to " << coid
<< " v " << ctx
->at_version
7223 << " snaps=" << snaps
7224 << " snapset=" << ctx
->new_snapset
<< dendl
;
7225 ctx
->log
.push_back(pg_log_entry_t(pg_log_entry_t::CLONE
, coid
, ctx
->at_version
,
7226 ctx
->obs
->oi
.version
,
7227 ctx
->obs
->oi
.user_version
,
7228 osd_reqid_t(), ctx
->new_obs
.oi
.mtime
, 0));
7229 ::encode(snaps
, ctx
->log
.back().snaps
);
7231 ctx
->at_version
.version
++;
7234 // update most recent clone_overlap and usage stats
7235 if (ctx
->new_snapset
.clones
.size() > 0) {
7236 /* we need to check whether the most recent clone exists, if it's been evicted,
7237 * it's not included in the stats */
7238 hobject_t last_clone_oid
= soid
;
7239 last_clone_oid
.snap
= ctx
->new_snapset
.clone_overlap
.rbegin()->first
;
7240 if (is_present_clone(last_clone_oid
)) {
7241 interval_set
<uint64_t> &newest_overlap
= ctx
->new_snapset
.clone_overlap
.rbegin()->second
;
7242 ctx
->modified_ranges
.intersection_of(newest_overlap
);
7243 // modified_ranges is still in use by the clone
7244 add_interval_usage(ctx
->modified_ranges
, ctx
->delta_stats
);
7245 newest_overlap
.subtract(ctx
->modified_ranges
);
7249 // update snapset with latest snap context
7250 ctx
->new_snapset
.seq
= snapc
.seq
;
7251 ctx
->new_snapset
.snaps
= snapc
.snaps
;
7252 if (get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
7253 // pessimistic assumption that this is a net-new legacy SnapSet
7254 ctx
->delta_stats
.num_legacy_snapsets
++;
7255 ctx
->new_snapset
.head_exists
= ctx
->new_obs
.exists
;
7256 } else if (ctx
->new_snapset
.is_legacy()) {
7257 ctx
->new_snapset
.head_exists
= ctx
->new_obs
.exists
;
7259 dout(20) << "make_writeable " << soid
7260 << " done, snapset=" << ctx
->new_snapset
<< dendl
;
7264 void PrimaryLogPG::write_update_size_and_usage(object_stat_sum_t
& delta_stats
, object_info_t
& oi
,
7265 interval_set
<uint64_t>& modified
, uint64_t offset
,
7266 uint64_t length
, bool write_full
)
7268 interval_set
<uint64_t> ch
;
7271 ch
.insert(0, oi
.size
);
7273 ch
.insert(offset
, length
);
7274 modified
.union_of(ch
);
7275 if (write_full
|| offset
+ length
> oi
.size
) {
7276 uint64_t new_size
= offset
+ length
;
7277 delta_stats
.num_bytes
-= oi
.size
;
7278 delta_stats
.num_bytes
+= new_size
;
7281 delta_stats
.num_wr
++;
7282 delta_stats
.num_wr_kb
+= SHIFT_ROUND_UP(length
, 10);
7285 void PrimaryLogPG::add_interval_usage(interval_set
<uint64_t>& s
, object_stat_sum_t
& delta_stats
)
7287 for (interval_set
<uint64_t>::const_iterator p
= s
.begin(); p
!= s
.end(); ++p
) {
7288 delta_stats
.num_bytes
+= p
.get_len();
7292 void PrimaryLogPG::complete_disconnect_watches(
7293 ObjectContextRef obc
,
7294 const list
<watch_disconnect_t
> &to_disconnect
)
7296 for (list
<watch_disconnect_t
>::const_iterator i
=
7297 to_disconnect
.begin();
7298 i
!= to_disconnect
.end();
7300 pair
<uint64_t, entity_name_t
> watcher(i
->cookie
, i
->name
);
7301 auto watchers_entry
= obc
->watchers
.find(watcher
);
7302 if (watchers_entry
!= obc
->watchers
.end()) {
7303 WatchRef watch
= watchers_entry
->second
;
7304 dout(10) << "do_osd_op_effects disconnect watcher " << watcher
<< dendl
;
7305 obc
->watchers
.erase(watcher
);
7306 watch
->remove(i
->send_disconnect
);
7308 dout(10) << "do_osd_op_effects disconnect failed to find watcher "
7309 << watcher
<< dendl
;
7314 void PrimaryLogPG::do_osd_op_effects(OpContext
*ctx
, const ConnectionRef
& conn
)
7316 entity_name_t entity
= ctx
->reqid
.name
;
7317 dout(15) << "do_osd_op_effects " << entity
<< " con " << conn
.get() << dendl
;
7319 // disconnects first
7320 complete_disconnect_watches(ctx
->obc
, ctx
->watch_disconnects
);
7324 boost::intrusive_ptr
<Session
> session((Session
*)conn
->get_priv());
7327 session
->put(); // get_priv() takes a ref, and so does the intrusive_ptr
7329 for (list
<pair
<watch_info_t
,bool> >::iterator i
= ctx
->watch_connects
.begin();
7330 i
!= ctx
->watch_connects
.end();
7332 pair
<uint64_t, entity_name_t
> watcher(i
->first
.cookie
, entity
);
7333 dout(15) << "do_osd_op_effects applying watch connect on session "
7334 << session
.get() << " watcher " << watcher
<< dendl
;
7336 if (ctx
->obc
->watchers
.count(watcher
)) {
7337 dout(15) << "do_osd_op_effects found existing watch watcher " << watcher
7339 watch
= ctx
->obc
->watchers
[watcher
];
7341 dout(15) << "do_osd_op_effects new watcher " << watcher
7343 watch
= Watch::makeWatchRef(
7344 this, osd
, ctx
->obc
, i
->first
.timeout_seconds
,
7345 i
->first
.cookie
, entity
, conn
->get_peer_addr());
7346 ctx
->obc
->watchers
.insert(
7351 watch
->connect(conn
, i
->second
);
7354 for (list
<notify_info_t
>::iterator p
= ctx
->notifies
.begin();
7355 p
!= ctx
->notifies
.end();
7357 dout(10) << "do_osd_op_effects, notify " << *p
<< dendl
;
7358 ConnectionRef
conn(ctx
->op
->get_req()->get_connection());
7360 Notify::makeNotifyRef(
7362 ctx
->reqid
.name
.num(),
7367 ctx
->obc
->obs
.oi
.user_version
,
7369 for (map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator i
=
7370 ctx
->obc
->watchers
.begin();
7371 i
!= ctx
->obc
->watchers
.end();
7373 dout(10) << "starting notify on watch " << i
->first
<< dendl
;
7374 i
->second
->start_notify(notif
);
7379 for (list
<OpContext::NotifyAck
>::iterator p
= ctx
->notify_acks
.begin();
7380 p
!= ctx
->notify_acks
.end();
7382 if (p
->watch_cookie
)
7383 dout(10) << "notify_ack " << make_pair(p
->watch_cookie
.get(), p
->notify_id
) << dendl
;
7385 dout(10) << "notify_ack " << make_pair("NULL", p
->notify_id
) << dendl
;
7386 for (map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator i
=
7387 ctx
->obc
->watchers
.begin();
7388 i
!= ctx
->obc
->watchers
.end();
7390 if (i
->first
.second
!= entity
) continue;
7391 if (p
->watch_cookie
&&
7392 p
->watch_cookie
.get() != i
->first
.first
) continue;
7393 dout(10) << "acking notify on watch " << i
->first
<< dendl
;
7394 i
->second
->notify_ack(p
->notify_id
, p
->reply_bl
);
7399 hobject_t
PrimaryLogPG::generate_temp_object(const hobject_t
& target
)
7402 ss
<< "temp_" << info
.pgid
<< "_" << get_role()
7403 << "_" << osd
->monc
->get_global_id() << "_" << (++temp_seq
);
7404 hobject_t hoid
= target
.make_temp_hobject(ss
.str());
7405 dout(20) << __func__
<< " " << hoid
<< dendl
;
7409 hobject_t
PrimaryLogPG::get_temp_recovery_object(
7410 const hobject_t
& target
,
7414 ss
<< "temp_recovering_" << info
.pgid
// (note this includes the shardid)
7416 << "_" << info
.history
.same_interval_since
7417 << "_" << target
.snap
;
7418 // pgid + version + interval + snapid is unique, and short
7419 hobject_t hoid
= target
.make_temp_hobject(ss
.str());
7420 dout(20) << __func__
<< " " << hoid
<< dendl
;
7424 int PrimaryLogPG::prepare_transaction(OpContext
*ctx
)
7426 assert(!ctx
->ops
->empty());
7428 const hobject_t
& soid
= ctx
->obs
->oi
.soid
;
7430 // valid snap context?
7431 if (!ctx
->snapc
.is_valid()) {
7432 dout(10) << " invalid snapc " << ctx
->snapc
<< dendl
;
7436 // prepare the actual mutation
7437 int result
= do_osd_ops(ctx
, *ctx
->ops
);
7439 if (ctx
->op
->may_write() &&
7440 get_osdmap()->require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
7441 // need to save the error code in the pg log, to detect dup ops,
7442 // but do nothing else
7443 ctx
->update_log_only
= true;
7448 // read-op? write-op noop? done?
7449 if (ctx
->op_t
->empty() && !ctx
->modify
) {
7450 unstable_stats
.add(ctx
->delta_stats
);
7451 if (ctx
->op
->may_write() &&
7452 get_osdmap()->require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
7453 ctx
->update_log_only
= true;
7459 if ((ctx
->delta_stats
.num_bytes
> 0 ||
7460 ctx
->delta_stats
.num_objects
> 0) && // FIXME: keys?
7461 (pool
.info
.has_flag(pg_pool_t::FLAG_FULL
) ||
7462 get_osdmap()->test_flag(CEPH_OSDMAP_FULL
))) {
7463 const MOSDOp
*m
= static_cast<const MOSDOp
*>(ctx
->op
->get_req());
7464 if (ctx
->reqid
.name
.is_mds() || // FIXME: ignore MDS for now
7465 m
->has_flag(CEPH_OSD_FLAG_FULL_FORCE
)) {
7466 dout(20) << __func__
<< " full, but proceeding due to FULL_FORCE or MDS"
7468 } else if (m
->has_flag(CEPH_OSD_FLAG_FULL_TRY
)) {
7469 // they tried, they failed.
7470 dout(20) << __func__
<< " full, replying to FULL_TRY op" << dendl
;
7471 return pool
.info
.has_flag(pg_pool_t::FLAG_FULL
) ? -EDQUOT
: -ENOSPC
;
7474 dout(20) << __func__
<< " full, dropping request (bad client)" << dendl
;
7479 // clone, if necessary
7480 if (soid
.snap
== CEPH_NOSNAP
)
7481 make_writeable(ctx
);
7484 ctx
->new_obs
.exists
? pg_log_entry_t::MODIFY
:
7485 pg_log_entry_t::DELETE
);
7490 void PrimaryLogPG::finish_ctx(OpContext
*ctx
, int log_op_type
, bool maintain_ssc
)
7492 const hobject_t
& soid
= ctx
->obs
->oi
.soid
;
7493 dout(20) << __func__
<< " " << soid
<< " " << ctx
7494 << " op " << pg_log_entry_t::get_op_name(log_op_type
)
7496 utime_t now
= ceph_clock_now();
7501 if (soid
.snap
== CEPH_NOSNAP
&& maintain_ssc
) {
7502 ::encode(ctx
->new_snapset
, bss
);
7503 assert(ctx
->new_obs
.exists
== ctx
->new_snapset
.head_exists
||
7504 !ctx
->new_snapset
.is_legacy());
7506 if (ctx
->new_obs
.exists
) {
7507 if (!ctx
->obs
->exists
) {
7508 if (ctx
->snapset_obc
&& ctx
->snapset_obc
->obs
.exists
) {
7509 hobject_t snapoid
= soid
.get_snapdir();
7510 dout(10) << " removing unneeded snapdir " << snapoid
<< dendl
;
7511 ctx
->log
.push_back(pg_log_entry_t(pg_log_entry_t::DELETE
, snapoid
,
7513 ctx
->snapset_obc
->obs
.oi
.version
,
7514 0, osd_reqid_t(), ctx
->mtime
, 0));
7515 ctx
->op_t
->remove(snapoid
);
7517 ctx
->at_version
.version
++;
7519 ctx
->snapset_obc
->obs
.exists
= false;
7522 } else if (!ctx
->new_snapset
.clones
.empty() &&
7523 !ctx
->cache_evict
&&
7524 !ctx
->new_snapset
.head_exists
&&
7525 (!ctx
->snapset_obc
|| !ctx
->snapset_obc
->obs
.exists
)) {
7526 // save snapset on _snap
7527 hobject_t
snapoid(soid
.oid
, soid
.get_key(), CEPH_SNAPDIR
, soid
.get_hash(),
7528 info
.pgid
.pool(), soid
.get_namespace());
7529 dout(10) << " final snapset " << ctx
->new_snapset
7530 << " in " << snapoid
<< dendl
;
7531 assert(get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
);
7532 ctx
->log
.push_back(pg_log_entry_t(pg_log_entry_t::MODIFY
, snapoid
,
7535 0, osd_reqid_t(), ctx
->mtime
, 0));
7537 if (!ctx
->snapset_obc
)
7538 ctx
->snapset_obc
= get_object_context(snapoid
, true);
7540 if (ctx
->lock_type
== ObjectContext::RWState::RWWRITE
) {
7541 got
= ctx
->lock_manager
.get_write_greedy(
7546 assert(ctx
->lock_type
== ObjectContext::RWState::RWEXCL
);
7547 got
= ctx
->lock_manager
.get_lock_type(
7548 ObjectContext::RWState::RWEXCL
,
7554 dout(20) << " got greedy write on snapset_obc " << *ctx
->snapset_obc
<< dendl
;
7555 ctx
->snapset_obc
->obs
.exists
= true;
7556 ctx
->snapset_obc
->obs
.oi
.version
= ctx
->at_version
;
7557 ctx
->snapset_obc
->obs
.oi
.last_reqid
= ctx
->reqid
;
7558 ctx
->snapset_obc
->obs
.oi
.mtime
= ctx
->mtime
;
7559 ctx
->snapset_obc
->obs
.oi
.local_mtime
= now
;
7561 map
<string
, bufferlist
> attrs
;
7562 bufferlist
bv(sizeof(ctx
->new_obs
.oi
));
7563 ::encode(ctx
->snapset_obc
->obs
.oi
, bv
,
7564 get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
7565 ctx
->op_t
->create(snapoid
);
7566 attrs
[OI_ATTR
].claim(bv
);
7567 attrs
[SS_ATTR
].claim(bss
);
7568 setattrs_maybe_cache(ctx
->snapset_obc
, ctx
, ctx
->op_t
.get(), attrs
);
7569 ctx
->at_version
.version
++;
7573 // finish and log the op.
7574 if (ctx
->user_modify
) {
7575 // update the user_version for any modify ops, except for the watch op
7576 ctx
->user_at_version
= MAX(info
.last_user_version
, ctx
->new_obs
.oi
.user_version
) + 1;
7577 /* In order for new clients and old clients to interoperate properly
7578 * when exchanging versions, we need to lower bound the user_version
7579 * (which our new clients pay proper attention to)
7580 * by the at_version (which is all the old clients can ever see). */
7581 if (ctx
->at_version
.version
> ctx
->user_at_version
)
7582 ctx
->user_at_version
= ctx
->at_version
.version
;
7583 ctx
->new_obs
.oi
.user_version
= ctx
->user_at_version
;
7585 ctx
->bytes_written
= ctx
->op_t
->get_bytes_written();
7587 if (ctx
->new_obs
.exists
) {
7588 // on the head object
7589 ctx
->new_obs
.oi
.version
= ctx
->at_version
;
7590 ctx
->new_obs
.oi
.prior_version
= ctx
->obs
->oi
.version
;
7591 ctx
->new_obs
.oi
.last_reqid
= ctx
->reqid
;
7592 if (ctx
->mtime
!= utime_t()) {
7593 ctx
->new_obs
.oi
.mtime
= ctx
->mtime
;
7594 dout(10) << " set mtime to " << ctx
->new_obs
.oi
.mtime
<< dendl
;
7595 ctx
->new_obs
.oi
.local_mtime
= now
;
7597 dout(10) << " mtime unchanged at " << ctx
->new_obs
.oi
.mtime
<< dendl
;
7600 map
<string
, bufferlist
> attrs
;
7601 bufferlist
bv(sizeof(ctx
->new_obs
.oi
));
7602 ::encode(ctx
->new_obs
.oi
, bv
,
7603 get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
7604 attrs
[OI_ATTR
].claim(bv
);
7606 if (soid
.snap
== CEPH_NOSNAP
) {
7607 dout(10) << " final snapset " << ctx
->new_snapset
7608 << " in " << soid
<< dendl
;
7609 attrs
[SS_ATTR
].claim(bss
);
7611 dout(10) << " no snapset (this is a clone)" << dendl
;
7613 ctx
->op_t
->setattrs(soid
, attrs
);
7615 ctx
->new_obs
.oi
= object_info_t(ctx
->obc
->obs
.oi
.soid
);
7618 bool legacy_snapset
= ctx
->new_snapset
.is_legacy() ||
7619 get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
;
7622 ctx
->log
.push_back(pg_log_entry_t(log_op_type
, soid
, ctx
->at_version
,
7623 ctx
->obs
->oi
.version
,
7624 ctx
->user_at_version
, ctx
->reqid
,
7626 if (soid
.snap
< CEPH_NOSNAP
) {
7627 switch (log_op_type
) {
7628 case pg_log_entry_t::MODIFY
:
7629 case pg_log_entry_t::PROMOTE
:
7630 case pg_log_entry_t::CLEAN
:
7631 if (legacy_snapset
) {
7632 dout(20) << __func__
<< " encoding legacy_snaps "
7633 << ctx
->new_obs
.oi
.legacy_snaps
7635 ::encode(ctx
->new_obs
.oi
.legacy_snaps
, ctx
->log
.back().snaps
);
7637 dout(20) << __func__
<< " encoding snaps from " << ctx
->new_snapset
7639 ::encode(ctx
->new_snapset
.clone_snaps
[soid
.snap
], ctx
->log
.back().snaps
);
7647 if (!ctx
->extra_reqids
.empty()) {
7648 dout(20) << __func__
<< " extra_reqids " << ctx
->extra_reqids
<< dendl
;
7649 ctx
->log
.back().extra_reqids
.swap(ctx
->extra_reqids
);
7652 // apply new object state.
7653 ctx
->obc
->obs
= ctx
->new_obs
;
7655 if (soid
.is_head() && !ctx
->obc
->obs
.exists
&&
7656 (!maintain_ssc
|| ctx
->cache_evict
)) {
7657 ctx
->obc
->ssc
->exists
= false;
7658 ctx
->obc
->ssc
->snapset
= SnapSet();
7660 ctx
->obc
->ssc
->exists
= true;
7661 ctx
->obc
->ssc
->snapset
= ctx
->new_snapset
;
7665 void PrimaryLogPG::apply_stats(
7666 const hobject_t
&soid
,
7667 const object_stat_sum_t
&delta_stats
) {
7669 info
.stats
.stats
.add(delta_stats
);
7671 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
7672 i
!= backfill_targets
.end();
7675 pg_info_t
& pinfo
= peer_info
[bt
];
7676 if (soid
<= pinfo
.last_backfill
)
7677 pinfo
.stats
.stats
.add(delta_stats
);
7678 else if (soid
<= last_backfill_started
)
7679 pending_backfill_updates
[soid
].stats
.add(delta_stats
);
7682 if (is_primary() && scrubber
.active
) {
7683 if (soid
< scrubber
.start
) {
7684 dout(20) << __func__
<< " " << soid
<< " < [" << scrubber
.start
7685 << "," << scrubber
.end
<< ")" << dendl
;
7686 scrub_cstat
.add(delta_stats
);
7688 dout(20) << __func__
<< " " << soid
<< " >= [" << scrubber
.start
7689 << "," << scrubber
.end
<< ")" << dendl
;
7694 void PrimaryLogPG::complete_read_ctx(int result
, OpContext
*ctx
)
7696 const MOSDOp
*m
= static_cast<const MOSDOp
*>(ctx
->op
->get_req());
7697 assert(ctx
->async_reads_complete());
7699 for (vector
<OSDOp
>::iterator p
= ctx
->ops
->begin();
7700 p
!= ctx
->ops
->end() && result
>= 0; ++p
) {
7701 if (p
->rval
< 0 && !(p
->op
.flags
& CEPH_OSD_OP_FLAG_FAILOK
)) {
7705 ctx
->bytes_read
+= p
->outdata
.length();
7707 ctx
->reply
->claim_op_out_data(*ctx
->ops
);
7708 ctx
->reply
->get_header().data_off
= (ctx
->data_off
? *ctx
->data_off
: 0);
7710 MOSDOpReply
*reply
= ctx
->reply
;
7711 ctx
->reply
= nullptr;
7714 if (!ctx
->ignore_log_op_stats
) {
7716 publish_stats_to_osd();
7719 // on read, return the current object version
7721 reply
->set_reply_versions(eversion_t(), ctx
->obs
->oi
.user_version
);
7723 reply
->set_reply_versions(eversion_t(), ctx
->user_at_version
);
7725 } else if (result
== -ENOENT
) {
7726 // on ENOENT, set a floor for what the next user version will be.
7727 reply
->set_enoent_reply_versions(info
.last_update
, info
.last_user_version
);
7730 reply
->set_result(result
);
7731 reply
->add_flags(CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
7732 osd
->send_message_osd_client(reply
, m
->get_connection());
7736 // ========================================================================
7739 struct C_Copyfrom
: public Context
{
7742 epoch_t last_peering_reset
;
7744 PrimaryLogPG::CopyOpRef cop
;
7745 C_Copyfrom(PrimaryLogPG
*p
, hobject_t o
, epoch_t lpr
,
7746 const PrimaryLogPG::CopyOpRef
& c
)
7747 : pg(p
), oid(o
), last_peering_reset(lpr
),
7750 void finish(int r
) override
{
7751 if (r
== -ECANCELED
)
7754 if (last_peering_reset
== pg
->get_last_peering_reset()) {
7755 pg
->process_copy_chunk(oid
, tid
, r
);
7761 struct C_CopyFrom_AsyncReadCb
: public Context
{
7763 object_copy_data_t reply_obj
;
7766 C_CopyFrom_AsyncReadCb(OSDOp
*osd_op
, uint64_t features
) :
7767 osd_op(osd_op
), features(features
), len(0) {}
7768 void finish(int r
) override
{
7775 assert(len
<= reply_obj
.data
.length());
7777 bl
.substr_of(reply_obj
.data
, 0, len
);
7778 reply_obj
.data
.swap(bl
);
7779 ::encode(reply_obj
, osd_op
->outdata
, features
);
7783 int PrimaryLogPG::do_copy_get(OpContext
*ctx
, bufferlist::iterator
& bp
,
7784 OSDOp
& osd_op
, ObjectContextRef
&obc
)
7786 object_info_t
& oi
= obc
->obs
.oi
;
7787 hobject_t
& soid
= oi
.soid
;
7789 object_copy_cursor_t cursor
;
7792 ::decode(cursor
, bp
);
7793 ::decode(out_max
, bp
);
7795 catch (buffer::error
& e
) {
7800 const MOSDOp
*op
= reinterpret_cast<const MOSDOp
*>(ctx
->op
->get_req());
7801 uint64_t features
= op
->get_features();
7803 bool async_read_started
= false;
7804 object_copy_data_t _reply_obj
;
7805 C_CopyFrom_AsyncReadCb
*cb
= NULL
;
7806 if (pool
.info
.require_rollback()) {
7807 cb
= new C_CopyFrom_AsyncReadCb(&osd_op
, features
);
7809 object_copy_data_t
&reply_obj
= cb
? cb
->reply_obj
: _reply_obj
;
7811 reply_obj
.size
= oi
.size
;
7812 reply_obj
.mtime
= oi
.mtime
;
7814 if (soid
.snap
< CEPH_NOSNAP
) {
7815 if (obc
->ssc
->snapset
.is_legacy()) {
7816 reply_obj
.snaps
= oi
.legacy_snaps
;
7818 auto p
= obc
->ssc
->snapset
.clone_snaps
.find(soid
.snap
);
7819 assert(p
!= obc
->ssc
->snapset
.clone_snaps
.end()); // warn?
7820 reply_obj
.snaps
= p
->second
;
7823 reply_obj
.snap_seq
= obc
->ssc
->snapset
.seq
;
7825 if (oi
.is_data_digest()) {
7826 reply_obj
.flags
|= object_copy_data_t::FLAG_DATA_DIGEST
;
7827 reply_obj
.data_digest
= oi
.data_digest
;
7829 if (oi
.is_omap_digest()) {
7830 reply_obj
.flags
|= object_copy_data_t::FLAG_OMAP_DIGEST
;
7831 reply_obj
.omap_digest
= oi
.omap_digest
;
7833 reply_obj
.truncate_seq
= oi
.truncate_seq
;
7834 reply_obj
.truncate_size
= oi
.truncate_size
;
7837 map
<string
,bufferlist
>& out_attrs
= reply_obj
.attrs
;
7838 if (!cursor
.attr_complete
) {
7839 result
= getattrs_maybe_cache(
7849 cursor
.attr_complete
= true;
7850 dout(20) << " got attrs" << dendl
;
7853 int64_t left
= out_max
- osd_op
.outdata
.length();
7856 bufferlist
& bl
= reply_obj
.data
;
7857 if (left
> 0 && !cursor
.data_complete
) {
7858 if (cursor
.data_offset
< oi
.size
) {
7859 uint64_t max_read
= MIN(oi
.size
- cursor
.data_offset
, (uint64_t)left
);
7861 async_read_started
= true;
7862 ctx
->pending_async_reads
.push_back(
7864 boost::make_tuple(cursor
.data_offset
, max_read
, osd_op
.op
.flags
),
7865 make_pair(&bl
, cb
)));
7868 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
7869 new ReadFinisher(osd_op
));
7870 result
= -EINPROGRESS
;
7872 dout(10) << __func__
<< ": async_read noted for " << soid
<< dendl
;
7874 result
= pgbackend
->objects_read_sync(
7875 oi
.soid
, cursor
.data_offset
, max_read
, osd_op
.op
.flags
, &bl
);
7880 cursor
.data_offset
+= max_read
;
7882 if (cursor
.data_offset
== oi
.size
) {
7883 cursor
.data_complete
= true;
7884 dout(20) << " got data" << dendl
;
7886 assert(cursor
.data_offset
<= oi
.size
);
7890 uint32_t omap_keys
= 0;
7891 if (!pool
.info
.supports_omap() || !oi
.is_omap()) {
7892 cursor
.omap_complete
= true;
7894 if (left
> 0 && !cursor
.omap_complete
) {
7895 assert(cursor
.data_complete
);
7896 if (cursor
.omap_offset
.empty()) {
7897 osd
->store
->omap_get_header(ch
, ghobject_t(oi
.soid
),
7898 &reply_obj
.omap_header
);
7900 bufferlist omap_data
;
7901 ObjectMap::ObjectMapIterator iter
=
7902 osd
->store
->get_omap_iterator(coll
, ghobject_t(oi
.soid
));
7904 iter
->upper_bound(cursor
.omap_offset
);
7905 for (; iter
->valid(); iter
->next(false)) {
7907 ::encode(iter
->key(), omap_data
);
7908 ::encode(iter
->value(), omap_data
);
7909 left
-= iter
->key().length() + 4 + iter
->value().length() + 4;
7914 ::encode(omap_keys
, reply_obj
.omap_data
);
7915 reply_obj
.omap_data
.claim_append(omap_data
);
7917 if (iter
->valid()) {
7918 cursor
.omap_offset
= iter
->key();
7920 cursor
.omap_complete
= true;
7921 dout(20) << " got omap" << dendl
;
7926 if (cursor
.is_complete()) {
7927 // include reqids only in the final step. this is a bit fragile
7929 pg_log
.get_log().get_object_reqids(ctx
->obc
->obs
.oi
.soid
, 10, &reply_obj
.reqids
);
7930 dout(20) << " got reqids" << dendl
;
7933 dout(20) << " cursor.is_complete=" << cursor
.is_complete()
7934 << " " << out_attrs
.size() << " attrs"
7935 << " " << bl
.length() << " bytes"
7936 << " " << reply_obj
.omap_header
.length() << " omap header bytes"
7937 << " " << reply_obj
.omap_data
.length() << " omap data bytes in "
7938 << omap_keys
<< " keys"
7939 << " " << reply_obj
.reqids
.size() << " reqids"
7941 reply_obj
.cursor
= cursor
;
7942 if (!async_read_started
) {
7943 ::encode(reply_obj
, osd_op
.outdata
, features
);
7945 if (cb
&& !async_read_started
) {
7955 void PrimaryLogPG::fill_in_copy_get_noent(OpRequestRef
& op
, hobject_t oid
,
7958 // NOTE: we take non-const ref here for claim_op_out_data below; we must
7959 // be careful not to modify anything else that will upset a racing
7961 MOSDOp
*m
= static_cast<MOSDOp
*>(op
->get_nonconst_req());
7962 uint64_t features
= m
->get_features();
7963 object_copy_data_t reply_obj
;
7965 pg_log
.get_log().get_object_reqids(oid
, 10, &reply_obj
.reqids
);
7966 dout(20) << __func__
<< " got reqids " << reply_obj
.reqids
<< dendl
;
7967 ::encode(reply_obj
, osd_op
.outdata
, features
);
7968 osd_op
.rval
= -ENOENT
;
7969 MOSDOpReply
*reply
= new MOSDOpReply(m
, 0, get_osdmap()->get_epoch(), 0, false);
7970 reply
->claim_op_out_data(m
->ops
);
7971 reply
->set_result(-ENOENT
);
7972 reply
->add_flags(CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
7973 osd
->send_message_osd_client(reply
, m
->get_connection());
7976 void PrimaryLogPG::start_copy(CopyCallback
*cb
, ObjectContextRef obc
,
7977 hobject_t src
, object_locator_t oloc
,
7978 version_t version
, unsigned flags
,
7979 bool mirror_snapset
,
7980 unsigned src_obj_fadvise_flags
,
7981 unsigned dest_obj_fadvise_flags
)
7983 const hobject_t
& dest
= obc
->obs
.oi
.soid
;
7984 dout(10) << __func__
<< " " << dest
7985 << " from " << src
<< " " << oloc
<< " v" << version
7986 << " flags " << flags
7987 << (mirror_snapset
? " mirror_snapset" : "")
7990 assert(!mirror_snapset
|| (src
.snap
== CEPH_NOSNAP
||
7991 src
.snap
== CEPH_SNAPDIR
));
7993 // cancel a previous in-progress copy?
7994 if (copy_ops
.count(dest
)) {
7995 // FIXME: if the src etc match, we could avoid restarting from the
7997 CopyOpRef cop
= copy_ops
[dest
];
7998 cancel_copy(cop
, false);
8001 CopyOpRef
cop(std::make_shared
<CopyOp
>(cb
, obc
, src
, oloc
, version
, flags
,
8002 mirror_snapset
, src_obj_fadvise_flags
,
8003 dest_obj_fadvise_flags
));
8004 copy_ops
[dest
] = cop
;
8007 _copy_some(obc
, cop
);
8010 void PrimaryLogPG::_copy_some(ObjectContextRef obc
, CopyOpRef cop
)
8012 dout(10) << __func__
<< " " << obc
<< " " << cop
<< dendl
;
8015 if (cop
->flags
& CEPH_OSD_COPY_FROM_FLAG_FLUSH
)
8016 flags
|= CEPH_OSD_FLAG_FLUSH
;
8017 if (cop
->flags
& CEPH_OSD_COPY_FROM_FLAG_IGNORE_CACHE
)
8018 flags
|= CEPH_OSD_FLAG_IGNORE_CACHE
;
8019 if (cop
->flags
& CEPH_OSD_COPY_FROM_FLAG_IGNORE_OVERLAY
)
8020 flags
|= CEPH_OSD_FLAG_IGNORE_OVERLAY
;
8021 if (cop
->flags
& CEPH_OSD_COPY_FROM_FLAG_MAP_SNAP_CLONE
)
8022 flags
|= CEPH_OSD_FLAG_MAP_SNAP_CLONE
;
8023 if (cop
->flags
& CEPH_OSD_COPY_FROM_FLAG_RWORDERED
)
8024 flags
|= CEPH_OSD_FLAG_RWORDERED
;
8026 C_GatherBuilder
gather(cct
);
8028 if (cop
->cursor
.is_initial() && cop
->mirror_snapset
) {
8030 assert(cop
->src
.snap
== CEPH_NOSNAP
);
8032 op
.list_snaps(&cop
->results
.snapset
, NULL
);
8033 ceph_tid_t tid
= osd
->objecter
->read(cop
->src
.oid
, cop
->oloc
, op
,
8035 flags
, gather
.new_sub(), NULL
);
8036 cop
->objecter_tid2
= tid
;
8040 if (cop
->results
.user_version
) {
8041 op
.assert_version(cop
->results
.user_version
);
8043 // we should learn the version after the first chunk, if we didn't know
8045 assert(cop
->cursor
.is_initial());
8047 op
.copy_get(&cop
->cursor
, get_copy_chunk_size(),
8048 &cop
->results
.object_size
, &cop
->results
.mtime
,
8049 &cop
->attrs
, &cop
->data
, &cop
->omap_header
, &cop
->omap_data
,
8050 &cop
->results
.snaps
, &cop
->results
.snap_seq
,
8051 &cop
->results
.flags
,
8052 &cop
->results
.source_data_digest
,
8053 &cop
->results
.source_omap_digest
,
8054 &cop
->results
.reqids
,
8055 &cop
->results
.truncate_seq
,
8056 &cop
->results
.truncate_size
,
8058 op
.set_last_op_flags(cop
->src_obj_fadvise_flags
);
8060 C_Copyfrom
*fin
= new C_Copyfrom(this, obc
->obs
.oi
.soid
,
8061 get_last_peering_reset(), cop
);
8062 gather
.set_finisher(new C_OnFinisher(fin
,
8063 &osd
->objecter_finisher
));
8065 ceph_tid_t tid
= osd
->objecter
->read(cop
->src
.oid
, cop
->oloc
, op
,
8066 cop
->src
.snap
, NULL
,
8069 // discover the object version if we don't know it yet
8070 cop
->results
.user_version
? NULL
: &cop
->results
.user_version
);
8072 cop
->objecter_tid
= tid
;
8076 void PrimaryLogPG::process_copy_chunk(hobject_t oid
, ceph_tid_t tid
, int r
)
8078 dout(10) << __func__
<< " " << oid
<< " tid " << tid
8079 << " " << cpp_strerror(r
) << dendl
;
8080 map
<hobject_t
,CopyOpRef
>::iterator p
= copy_ops
.find(oid
);
8081 if (p
== copy_ops
.end()) {
8082 dout(10) << __func__
<< " no copy_op found" << dendl
;
8085 CopyOpRef cop
= p
->second
;
8086 if (tid
!= cop
->objecter_tid
) {
8087 dout(10) << __func__
<< " tid " << tid
<< " != cop " << cop
8088 << " tid " << cop
->objecter_tid
<< dendl
;
8092 if (cop
->omap_data
.length() || cop
->omap_header
.length())
8093 cop
->results
.has_omap
= true;
8095 if (r
>= 0 && !pool
.info
.supports_omap() &&
8096 (cop
->omap_data
.length() || cop
->omap_header
.length())) {
8099 cop
->objecter_tid
= 0;
8100 cop
->objecter_tid2
= 0; // assume this ordered before us (if it happened)
8101 ObjectContextRef
& cobc
= cop
->obc
;
8106 assert(cop
->rval
>= 0);
8108 if (oid
.snap
< CEPH_NOSNAP
&& !cop
->results
.snaps
.empty()) {
8109 // verify snap hasn't been deleted
8110 vector
<snapid_t
>::iterator p
= cop
->results
.snaps
.begin();
8111 while (p
!= cop
->results
.snaps
.end()) {
8112 if (pool
.info
.is_removed_snap(*p
)) {
8113 dout(10) << __func__
<< " clone snap " << *p
<< " has been deleted"
8115 for (vector
<snapid_t
>::iterator q
= p
+ 1;
8116 q
!= cop
->results
.snaps
.end();
8119 cop
->results
.snaps
.resize(cop
->results
.snaps
.size() - 1);
8124 if (cop
->results
.snaps
.empty()) {
8125 dout(10) << __func__
<< " no more snaps for " << oid
<< dendl
;
8131 assert(cop
->rval
>= 0);
8133 if (!cop
->temp_cursor
.data_complete
) {
8134 cop
->results
.data_digest
= cop
->data
.crc32c(cop
->results
.data_digest
);
8136 if (pool
.info
.supports_omap() && !cop
->temp_cursor
.omap_complete
) {
8137 if (cop
->omap_header
.length()) {
8138 cop
->results
.omap_digest
=
8139 cop
->omap_header
.crc32c(cop
->results
.omap_digest
);
8141 if (cop
->omap_data
.length()) {
8143 keys
.substr_of(cop
->omap_data
, 4, cop
->omap_data
.length() - 4);
8144 cop
->results
.omap_digest
= keys
.crc32c(cop
->results
.omap_digest
);
8148 if (!cop
->temp_cursor
.attr_complete
) {
8149 for (map
<string
,bufferlist
>::iterator p
= cop
->attrs
.begin();
8150 p
!= cop
->attrs
.end();
8152 cop
->results
.attrs
[string("_") + p
->first
] = p
->second
;
8157 if (!cop
->cursor
.is_complete()) {
8158 // write out what we have so far
8159 if (cop
->temp_cursor
.is_initial()) {
8160 assert(!cop
->results
.started_temp_obj
);
8161 cop
->results
.started_temp_obj
= true;
8162 cop
->results
.temp_oid
= generate_temp_object(oid
);
8163 dout(20) << __func__
<< " using temp " << cop
->results
.temp_oid
<< dendl
;
8165 ObjectContextRef tempobc
= get_object_context(cop
->results
.temp_oid
, true);
8166 OpContextUPtr ctx
= simple_opc_create(tempobc
);
8167 if (cop
->temp_cursor
.is_initial()) {
8168 ctx
->new_temp_oid
= cop
->results
.temp_oid
;
8170 _write_copy_chunk(cop
, ctx
->op_t
.get());
8171 simple_opc_submit(std::move(ctx
));
8172 dout(10) << __func__
<< " fetching more" << dendl
;
8173 _copy_some(cobc
, cop
);
8178 if (cop
->results
.is_data_digest() || cop
->results
.is_omap_digest()) {
8179 dout(20) << __func__
<< std::hex
8180 << " got digest: rx data 0x" << cop
->results
.data_digest
8181 << " omap 0x" << cop
->results
.omap_digest
8182 << ", source: data 0x" << cop
->results
.source_data_digest
8183 << " omap 0x" << cop
->results
.source_omap_digest
8185 << " flags " << cop
->results
.flags
8188 if (cop
->results
.is_data_digest() &&
8189 cop
->results
.data_digest
!= cop
->results
.source_data_digest
) {
8190 derr
<< __func__
<< std::hex
<< " data digest 0x" << cop
->results
.data_digest
8191 << " != source 0x" << cop
->results
.source_data_digest
<< std::dec
8193 osd
->clog
->error() << info
.pgid
<< " copy from " << cop
->src
8194 << " to " << cop
->obc
->obs
.oi
.soid
<< std::hex
8195 << " data digest 0x" << cop
->results
.data_digest
8196 << " != source 0x" << cop
->results
.source_data_digest
8201 if (cop
->results
.is_omap_digest() &&
8202 cop
->results
.omap_digest
!= cop
->results
.source_omap_digest
) {
8203 derr
<< __func__
<< std::hex
8204 << " omap digest 0x" << cop
->results
.omap_digest
8205 << " != source 0x" << cop
->results
.source_omap_digest
8206 << std::dec
<< dendl
;
8207 osd
->clog
->error() << info
.pgid
<< " copy from " << cop
->src
8208 << " to " << cop
->obc
->obs
.oi
.soid
<< std::hex
8209 << " omap digest 0x" << cop
->results
.omap_digest
8210 << " != source 0x" << cop
->results
.source_omap_digest
8215 if (cct
->_conf
->osd_debug_inject_copyfrom_error
) {
8216 derr
<< __func__
<< " injecting copyfrom failure" << dendl
;
8221 cop
->results
.fill_in_final_tx
= std::function
<void(PGTransaction
*)>(
8222 [this, &cop
/* avoid ref cycle */](PGTransaction
*t
) {
8223 ObjectState
& obs
= cop
->obc
->obs
;
8224 if (cop
->temp_cursor
.is_initial()) {
8225 dout(20) << "fill_in_final_tx: writing "
8226 << "directly to final object" << dendl
;
8227 // write directly to final object
8228 cop
->results
.temp_oid
= obs
.oi
.soid
;
8229 _write_copy_chunk(cop
, t
);
8231 // finish writing to temp object, then move into place
8232 dout(20) << "fill_in_final_tx: writing to temp object" << dendl
;
8233 _write_copy_chunk(cop
, t
);
8234 t
->rename(obs
.oi
.soid
, cop
->results
.temp_oid
);
8236 t
->setattrs(obs
.oi
.soid
, cop
->results
.attrs
);
8239 dout(20) << __func__
<< " success; committing" << dendl
;
8242 dout(20) << __func__
<< " complete r = " << cpp_strerror(r
) << dendl
;
8243 CopyCallbackResults
results(r
, &cop
->results
);
8244 cop
->cb
->complete(results
);
8246 copy_ops
.erase(cobc
->obs
.oi
.soid
);
8249 if (r
< 0 && cop
->results
.started_temp_obj
) {
8250 dout(10) << __func__
<< " deleting partial temp object "
8251 << cop
->results
.temp_oid
<< dendl
;
8252 ObjectContextRef tempobc
= get_object_context(cop
->results
.temp_oid
, true);
8253 OpContextUPtr ctx
= simple_opc_create(tempobc
);
8254 ctx
->op_t
->remove(cop
->results
.temp_oid
);
8255 ctx
->discard_temp_oid
= cop
->results
.temp_oid
;
8256 simple_opc_submit(std::move(ctx
));
8259 // cancel and requeue proxy ops on this object
8261 for (map
<ceph_tid_t
, ProxyReadOpRef
>::iterator it
= proxyread_ops
.begin();
8262 it
!= proxyread_ops
.end();) {
8263 if (it
->second
->soid
== cobc
->obs
.oi
.soid
) {
8264 cancel_proxy_read((it
++)->second
);
8269 for (map
<ceph_tid_t
, ProxyWriteOpRef
>::iterator it
= proxywrite_ops
.begin();
8270 it
!= proxywrite_ops
.end();) {
8271 if (it
->second
->soid
== cobc
->obs
.oi
.soid
) {
8272 cancel_proxy_write((it
++)->second
);
8277 kick_proxy_ops_blocked(cobc
->obs
.oi
.soid
);
8280 kick_object_context_blocked(cobc
);
8283 void PrimaryLogPG::_write_copy_chunk(CopyOpRef cop
, PGTransaction
*t
)
8285 dout(20) << __func__
<< " " << cop
8286 << " " << cop
->attrs
.size() << " attrs"
8287 << " " << cop
->data
.length() << " bytes"
8288 << " " << cop
->omap_header
.length() << " omap header bytes"
8289 << " " << cop
->omap_data
.length() << " omap data bytes"
8291 if (!cop
->temp_cursor
.attr_complete
) {
8292 t
->create(cop
->results
.temp_oid
);
8294 if (!cop
->temp_cursor
.data_complete
) {
8295 assert(cop
->data
.length() + cop
->temp_cursor
.data_offset
==
8296 cop
->cursor
.data_offset
);
8297 if (pool
.info
.requires_aligned_append() &&
8298 !cop
->cursor
.data_complete
) {
8300 * Trim off the unaligned bit at the end, we'll adjust cursor.data_offset
8301 * to pick it up on the next pass.
8303 assert(cop
->temp_cursor
.data_offset
%
8304 pool
.info
.required_alignment() == 0);
8305 if (cop
->data
.length() % pool
.info
.required_alignment() != 0) {
8307 cop
->data
.length() % pool
.info
.required_alignment();
8309 bl
.substr_of(cop
->data
, 0, cop
->data
.length() - to_trim
);
8311 cop
->cursor
.data_offset
-= to_trim
;
8312 assert(cop
->data
.length() + cop
->temp_cursor
.data_offset
==
8313 cop
->cursor
.data_offset
);
8316 if (cop
->data
.length()) {
8318 cop
->results
.temp_oid
,
8319 cop
->temp_cursor
.data_offset
,
8322 cop
->dest_obj_fadvise_flags
);
8326 if (pool
.info
.supports_omap()) {
8327 if (!cop
->temp_cursor
.omap_complete
) {
8328 if (cop
->omap_header
.length()) {
8330 cop
->results
.temp_oid
,
8332 cop
->omap_header
.clear();
8334 if (cop
->omap_data
.length()) {
8335 map
<string
,bufferlist
> omap
;
8336 bufferlist::iterator p
= cop
->omap_data
.begin();
8338 t
->omap_setkeys(cop
->results
.temp_oid
, omap
);
8339 cop
->omap_data
.clear();
8343 assert(cop
->omap_header
.length() == 0);
8344 assert(cop
->omap_data
.length() == 0);
8346 cop
->temp_cursor
= cop
->cursor
;
8349 void PrimaryLogPG::finish_copyfrom(CopyFromCallback
*cb
)
8351 OpContext
*ctx
= cb
->ctx
;
8352 dout(20) << "finish_copyfrom on " << ctx
->obs
->oi
.soid
<< dendl
;
8354 ObjectState
& obs
= ctx
->new_obs
;
8356 dout(20) << __func__
<< ": exists, removing" << dendl
;
8357 ctx
->op_t
->remove(obs
.oi
.soid
);
8359 ctx
->delta_stats
.num_objects
++;
8362 if (cb
->is_temp_obj_used()) {
8363 ctx
->discard_temp_oid
= cb
->results
->temp_oid
;
8365 cb
->results
->fill_in_final_tx(ctx
->op_t
.get());
8367 // CopyFromCallback fills this in for us
8368 obs
.oi
.user_version
= ctx
->user_at_version
;
8370 obs
.oi
.set_data_digest(cb
->results
->data_digest
);
8371 obs
.oi
.set_omap_digest(cb
->results
->omap_digest
);
8373 obs
.oi
.truncate_seq
= cb
->results
->truncate_seq
;
8374 obs
.oi
.truncate_size
= cb
->results
->truncate_size
;
8376 ctx
->extra_reqids
= cb
->results
->reqids
;
8378 // cache: clear whiteout?
8379 if (obs
.oi
.is_whiteout()) {
8380 dout(10) << __func__
<< " clearing whiteout on " << obs
.oi
.soid
<< dendl
;
8381 obs
.oi
.clear_flag(object_info_t::FLAG_WHITEOUT
);
8382 --ctx
->delta_stats
.num_whiteouts
;
8385 if (cb
->results
->has_omap
) {
8386 dout(10) << __func__
<< " setting omap flag on " << obs
.oi
.soid
<< dendl
;
8387 obs
.oi
.set_flag(object_info_t::FLAG_OMAP
);
8389 dout(10) << __func__
<< " clearing omap flag on " << obs
.oi
.soid
<< dendl
;
8390 obs
.oi
.clear_flag(object_info_t::FLAG_OMAP
);
8393 interval_set
<uint64_t> ch
;
8394 if (obs
.oi
.size
> 0)
8395 ch
.insert(0, obs
.oi
.size
);
8396 ctx
->modified_ranges
.union_of(ch
);
8398 if (cb
->get_data_size() != obs
.oi
.size
) {
8399 ctx
->delta_stats
.num_bytes
-= obs
.oi
.size
;
8400 obs
.oi
.size
= cb
->get_data_size();
8401 ctx
->delta_stats
.num_bytes
+= obs
.oi
.size
;
8403 ctx
->delta_stats
.num_wr
++;
8404 ctx
->delta_stats
.num_wr_kb
+= SHIFT_ROUND_UP(obs
.oi
.size
, 10);
8406 osd
->logger
->inc(l_osd_copyfrom
);
8409 void PrimaryLogPG::finish_promote(int r
, CopyResults
*results
,
8410 ObjectContextRef obc
)
8412 const hobject_t
& soid
= obc
->obs
.oi
.soid
;
8413 dout(10) << __func__
<< " " << soid
<< " r=" << r
8414 << " uv" << results
->user_version
<< dendl
;
8416 if (r
== -ECANCELED
) {
8420 if (r
!= -ENOENT
&& soid
.is_snap()) {
8421 if (results
->snaps
.empty()) {
8422 // we must have read "snap" content from the head object in
8423 // the base pool. use snap_seq to construct what snaps should
8424 // be for this clone (what is was before we evicted the clean
8425 // clone from this pool, and what it will be when we flush and
8426 // the clone eventually happens in the base pool).
8427 SnapSet
& snapset
= obc
->ssc
->snapset
;
8428 vector
<snapid_t
>::iterator p
= snapset
.snaps
.begin();
8429 while (p
!= snapset
.snaps
.end() && *p
> soid
.snap
)
8431 while (p
!= snapset
.snaps
.end() && *p
> results
->snap_seq
) {
8432 results
->snaps
.push_back(*p
);
8437 dout(20) << __func__
<< " snaps " << results
->snaps
<< dendl
;
8438 filter_snapc(results
->snaps
);
8440 dout(20) << __func__
<< " filtered snaps " << results
->snaps
<< dendl
;
8441 if (results
->snaps
.empty()) {
8442 dout(20) << __func__
8443 << " snaps are empty, clone is invalid,"
8444 << " setting r to ENOENT" << dendl
;
8449 if (r
< 0 && results
->started_temp_obj
) {
8450 dout(10) << __func__
<< " abort; will clean up partial work" << dendl
;
8451 ObjectContextRef tempobc
= get_object_context(results
->temp_oid
, false);
8453 OpContextUPtr ctx
= simple_opc_create(tempobc
);
8454 ctx
->op_t
->remove(results
->temp_oid
);
8455 simple_opc_submit(std::move(ctx
));
8456 results
->started_temp_obj
= false;
8459 if (r
== -ENOENT
&& soid
.is_snap()) {
8460 dout(10) << __func__
8461 << ": enoent while trying to promote clone, " << soid
8462 << " must have been trimmed, removing from snapset"
8464 hobject_t
head(soid
.get_head());
8465 ObjectContextRef obc
= get_object_context(head
, false);
8468 OpContextUPtr tctx
= simple_opc_create(obc
);
8469 tctx
->at_version
= get_next_version();
8470 filter_snapc(tctx
->new_snapset
.snaps
);
8471 vector
<snapid_t
> new_clones
;
8472 map
<snapid_t
, vector
<snapid_t
>> new_clone_snaps
;
8473 for (vector
<snapid_t
>::iterator i
= tctx
->new_snapset
.clones
.begin();
8474 i
!= tctx
->new_snapset
.clones
.end();
8476 if (*i
!= soid
.snap
) {
8477 new_clones
.push_back(*i
);
8478 auto p
= tctx
->new_snapset
.clone_snaps
.find(*i
);
8479 if (p
!= tctx
->new_snapset
.clone_snaps
.end()) {
8480 new_clone_snaps
[*i
] = p
->second
;
8484 tctx
->new_snapset
.clones
.swap(new_clones
);
8485 tctx
->new_snapset
.clone_overlap
.erase(soid
.snap
);
8486 tctx
->new_snapset
.clone_size
.erase(soid
.snap
);
8487 tctx
->new_snapset
.clone_snaps
.swap(new_clone_snaps
);
8489 // take RWWRITE lock for duration of our local write. ignore starvation.
8490 if (!tctx
->lock_manager
.take_write_lock(
8493 assert(0 == "problem!");
8495 dout(20) << __func__
<< " took lock on obc, " << obc
->rwstate
<< dendl
;
8497 finish_ctx(tctx
.get(), pg_log_entry_t::PROMOTE
);
8499 simple_opc_submit(std::move(tctx
));
8503 bool whiteout
= false;
8505 assert(soid
.snap
== CEPH_NOSNAP
); // snap case is above
8506 dout(10) << __func__
<< " whiteout " << soid
<< dendl
;
8510 if (r
< 0 && !whiteout
) {
8511 derr
<< __func__
<< " unexpected promote error " << cpp_strerror(r
) << dendl
;
8512 // pass error to everyone blocked on this object
8513 // FIXME: this is pretty sloppy, but at this point we got
8514 // something unexpected and don't have many other options.
8515 map
<hobject_t
,list
<OpRequestRef
>>::iterator blocked_iter
=
8516 waiting_for_blocked_object
.find(soid
);
8517 if (blocked_iter
!= waiting_for_blocked_object
.end()) {
8518 while (!blocked_iter
->second
.empty()) {
8519 osd
->reply_op_error(blocked_iter
->second
.front(), r
);
8520 blocked_iter
->second
.pop_front();
8522 waiting_for_blocked_object
.erase(blocked_iter
);
8527 osd
->promote_finish(results
->object_size
);
8529 OpContextUPtr tctx
= simple_opc_create(obc
);
8530 tctx
->at_version
= get_next_version();
8532 ++tctx
->delta_stats
.num_objects
;
8533 if (soid
.snap
< CEPH_NOSNAP
)
8534 ++tctx
->delta_stats
.num_object_clones
;
8535 tctx
->new_obs
.exists
= true;
8537 tctx
->extra_reqids
= results
->reqids
;
8539 bool legacy_snapset
= tctx
->new_snapset
.is_legacy() ||
8540 get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
;
8543 // create a whiteout
8544 tctx
->op_t
->create(soid
);
8545 tctx
->new_obs
.oi
.set_flag(object_info_t::FLAG_WHITEOUT
);
8546 ++tctx
->delta_stats
.num_whiteouts
;
8547 dout(20) << __func__
<< " creating whiteout on " << soid
<< dendl
;
8548 osd
->logger
->inc(l_osd_tier_whiteout
);
8550 if (results
->has_omap
) {
8551 dout(10) << __func__
<< " setting omap flag on " << soid
<< dendl
;
8552 tctx
->new_obs
.oi
.set_flag(object_info_t::FLAG_OMAP
);
8553 ++tctx
->delta_stats
.num_objects_omap
;
8556 results
->fill_in_final_tx(tctx
->op_t
.get());
8557 if (results
->started_temp_obj
) {
8558 tctx
->discard_temp_oid
= results
->temp_oid
;
8560 tctx
->new_obs
.oi
.size
= results
->object_size
;
8561 tctx
->new_obs
.oi
.user_version
= results
->user_version
;
8562 // Don't care src object whether have data or omap digest
8563 if (results
->object_size
)
8564 tctx
->new_obs
.oi
.set_data_digest(results
->data_digest
);
8565 if (results
->has_omap
)
8566 tctx
->new_obs
.oi
.set_omap_digest(results
->omap_digest
);
8567 tctx
->new_obs
.oi
.truncate_seq
= results
->truncate_seq
;
8568 tctx
->new_obs
.oi
.truncate_size
= results
->truncate_size
;
8570 if (soid
.snap
!= CEPH_NOSNAP
) {
8571 if (legacy_snapset
) {
8572 tctx
->new_obs
.oi
.legacy_snaps
= results
->snaps
;
8573 assert(!tctx
->new_obs
.oi
.legacy_snaps
.empty());
8575 // it's already in the snapset
8576 assert(obc
->ssc
->snapset
.clone_snaps
.count(soid
.snap
));
8578 assert(obc
->ssc
->snapset
.clone_size
.count(soid
.snap
));
8579 assert(obc
->ssc
->snapset
.clone_size
[soid
.snap
] ==
8580 results
->object_size
);
8581 assert(obc
->ssc
->snapset
.clone_overlap
.count(soid
.snap
));
8583 tctx
->delta_stats
.num_bytes
+= obc
->ssc
->snapset
.get_clone_bytes(soid
.snap
);
8585 tctx
->delta_stats
.num_bytes
+= results
->object_size
;
8589 if (results
->mirror_snapset
) {
8590 assert(tctx
->new_obs
.oi
.soid
.snap
== CEPH_NOSNAP
);
8591 tctx
->new_snapset
.from_snap_set(
8593 get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
);
8595 tctx
->new_snapset
.head_exists
= true;
8596 dout(20) << __func__
<< " new_snapset " << tctx
->new_snapset
<< dendl
;
8598 // take RWWRITE lock for duration of our local write. ignore starvation.
8599 if (!tctx
->lock_manager
.take_write_lock(
8602 assert(0 == "problem!");
8604 dout(20) << __func__
<< " took lock on obc, " << obc
->rwstate
<< dendl
;
8606 finish_ctx(tctx
.get(), pg_log_entry_t::PROMOTE
);
8608 simple_opc_submit(std::move(tctx
));
8610 osd
->logger
->inc(l_osd_tier_promote
);
8613 agent_state
->is_idle())
8614 agent_choose_mode();
8617 void PrimaryLogPG::cancel_copy(CopyOpRef cop
, bool requeue
)
8619 dout(10) << __func__
<< " " << cop
->obc
->obs
.oi
.soid
8620 << " from " << cop
->src
<< " " << cop
->oloc
8621 << " v" << cop
->results
.user_version
<< dendl
;
8623 // cancel objecter op, if we can
8624 if (cop
->objecter_tid
) {
8625 osd
->objecter
->op_cancel(cop
->objecter_tid
, -ECANCELED
);
8626 cop
->objecter_tid
= 0;
8627 if (cop
->objecter_tid2
) {
8628 osd
->objecter
->op_cancel(cop
->objecter_tid2
, -ECANCELED
);
8629 cop
->objecter_tid2
= 0;
8633 copy_ops
.erase(cop
->obc
->obs
.oi
.soid
);
8634 cop
->obc
->stop_block();
8636 kick_object_context_blocked(cop
->obc
);
8637 cop
->results
.should_requeue
= requeue
;
8638 CopyCallbackResults
result(-ECANCELED
, &cop
->results
);
8639 cop
->cb
->complete(result
);
8641 // There may still be an objecter callback referencing this copy op.
8642 // That callback will not need the obc since it's been canceled, and
8643 // we need the obc reference to go away prior to flush.
8644 cop
->obc
= ObjectContextRef();
8647 void PrimaryLogPG::cancel_copy_ops(bool requeue
)
8649 dout(10) << __func__
<< dendl
;
8650 map
<hobject_t
,CopyOpRef
>::iterator p
= copy_ops
.begin();
8651 while (p
!= copy_ops
.end()) {
8652 // requeue this op? can I queue up all of them?
8653 cancel_copy((p
++)->second
, requeue
);
8658 // ========================================================================
8661 // Flush a dirty object in the cache tier by writing it back to the
8662 // base tier. The sequence looks like:
8664 // * send a copy-from operation to the base tier to copy the current
8665 // version of the object
8666 // * base tier will pull the object via (perhaps multiple) copy-get(s)
8667 // * on completion, we check if the object has been modified. if so,
8668 // just reply with -EAGAIN.
8669 // * try to take a write lock so we can clear the dirty flag. if this
8670 // fails, wait and retry
8671 // * start a repop that clears the bit.
8673 // If we have to wait, we will retry by coming back through the
8674 // start_flush method. We check if a flush is already in progress
8675 // and, if so, try to finish it by rechecking the version and trying
8676 // to clear the dirty bit.
8678 // In order for the cache-flush (a write op) to not block the copy-get
8679 // from reading the object, the client *must* set the SKIPRWLOCKS
8682 // NOTE: normally writes are strictly ordered for the client, but
8683 // flushes are special in that they can be reordered with respect to
8684 // other writes. In particular, we can't have a flush request block
8685 // an update to the cache pool object!
8687 struct C_Flush
: public Context
{
8690 epoch_t last_peering_reset
;
8693 C_Flush(PrimaryLogPG
*p
, hobject_t o
, epoch_t lpr
)
8694 : pg(p
), oid(o
), last_peering_reset(lpr
),
8695 tid(0), start(ceph_clock_now())
8697 void finish(int r
) override
{
8698 if (r
== -ECANCELED
)
8701 if (last_peering_reset
== pg
->get_last_peering_reset()) {
8702 pg
->finish_flush(oid
, tid
, r
);
8703 pg
->osd
->logger
->tinc(l_osd_tier_flush_lat
, ceph_clock_now() - start
);
8709 int PrimaryLogPG::start_flush(
8710 OpRequestRef op
, ObjectContextRef obc
,
8711 bool blocking
, hobject_t
*pmissing
,
8712 boost::optional
<std::function
<void()>> &&on_flush
)
8714 const object_info_t
& oi
= obc
->obs
.oi
;
8715 const hobject_t
& soid
= oi
.soid
;
8716 dout(10) << __func__
<< " " << soid
8717 << " v" << oi
.version
8718 << " uv" << oi
.user_version
8719 << " " << (blocking
? "blocking" : "non-blocking/best-effort")
8722 // get a filtered snapset, need to remove removed snaps
8723 SnapSet snapset
= obc
->ssc
->snapset
.get_filtered(pool
.info
);
8725 // verify there are no (older) check for dirty clones
8727 dout(20) << " snapset " << snapset
<< dendl
;
8728 vector
<snapid_t
>::reverse_iterator p
= snapset
.clones
.rbegin();
8729 while (p
!= snapset
.clones
.rend() && *p
>= soid
.snap
)
8731 if (p
!= snapset
.clones
.rend()) {
8732 hobject_t next
= soid
;
8734 assert(next
.snap
< soid
.snap
);
8735 if (pg_log
.get_missing().is_missing(next
)) {
8736 dout(10) << __func__
<< " missing clone is " << next
<< dendl
;
8741 ObjectContextRef older_obc
= get_object_context(next
, false);
8743 dout(20) << __func__
<< " next oldest clone is " << older_obc
->obs
.oi
8745 if (older_obc
->obs
.oi
.is_dirty()) {
8746 dout(10) << __func__
<< " next oldest clone is dirty: "
8747 << older_obc
->obs
.oi
<< dendl
;
8751 dout(20) << __func__
<< " next oldest clone " << next
8752 << " is not present; implicitly clean" << dendl
;
8755 dout(20) << __func__
<< " no older clones" << dendl
;
8762 map
<hobject_t
,FlushOpRef
>::iterator p
= flush_ops
.find(soid
);
8763 if (p
!= flush_ops
.end()) {
8764 FlushOpRef fop
= p
->second
;
8765 if (fop
->op
== op
) {
8766 // we couldn't take the write lock on a cache-try-flush before;
8767 // now we are trying again for the lock.
8768 return try_flush_mark_clean(fop
);
8770 if (fop
->flushed_version
== obc
->obs
.oi
.user_version
&&
8771 (fop
->blocking
|| !blocking
)) {
8772 // nonblocking can join anything
8773 // blocking can only join a blocking flush
8774 dout(20) << __func__
<< " piggybacking on existing flush " << dendl
;
8776 fop
->dup_ops
.push_back(op
);
8777 return -EAGAIN
; // clean up this ctx; op will retry later
8780 // cancel current flush since it will fail anyway, or because we
8781 // are blocking and the existing flush is nonblocking.
8782 dout(20) << __func__
<< " canceling previous flush; it will fail" << dendl
;
8784 osd
->reply_op_error(fop
->op
, -EBUSY
);
8785 while (!fop
->dup_ops
.empty()) {
8786 osd
->reply_op_error(fop
->dup_ops
.front(), -EBUSY
);
8787 fop
->dup_ops
.pop_front();
8789 cancel_flush(fop
, false);
8793 * In general, we need to send a delete and a copyfrom.
8794 * Consider snapc 10:[10, 9, 8, 4, 3, 2]:[10(10, 9), 4(4,3,2)]
8795 * where 4 is marked as clean. To flush 10, we have to:
8796 * 1) delete 4:[4,3,2] -- Logically, the object does not exist after 4
8797 * 2) copyfrom 8:[8,4,3,2] -- flush object after snap 8
8799 * There is a complicating case. Supposed there had been a clone 7
8800 * for snaps [7, 6] which has been trimmed since they no longer exist.
8801 * In the base pool, we'd have 5:[4,3,2]:[4(4,3,2)]+head. When we submit
8802 * the delete, the snap will be promoted to 5, and the head will become
8803 * a snapdir. When the copy-from goes through, we'll end up with
8804 * 8:[8,4,3,2]:[4(4,3,2)]+head.
8806 * Another complication is the case where there is an interval change
8807 * after doing the delete and the flush but before marking the object
8808 * clean. We'll happily delete head and then recreate it at the same
8809 * sequence number, which works out ok.
8812 SnapContext snapc
, dsnapc
;
8813 if (snapset
.seq
!= 0) {
8814 if (soid
.snap
== CEPH_NOSNAP
) {
8815 snapc
.seq
= snapset
.seq
;
8816 snapc
.snaps
= snapset
.snaps
;
8818 snapid_t min_included_snap
;
8819 if (snapset
.is_legacy()) {
8820 min_included_snap
= oi
.legacy_snaps
.back();
8822 auto p
= snapset
.clone_snaps
.find(soid
.snap
);
8823 assert(p
!= snapset
.clone_snaps
.end());
8824 min_included_snap
= p
->second
.back();
8826 snapc
= snapset
.get_ssc_as_of(min_included_snap
- 1);
8829 snapid_t prev_snapc
= 0;
8830 for (vector
<snapid_t
>::reverse_iterator citer
= snapset
.clones
.rbegin();
8831 citer
!= snapset
.clones
.rend();
8833 if (*citer
< soid
.snap
) {
8834 prev_snapc
= *citer
;
8839 dsnapc
= snapset
.get_ssc_as_of(prev_snapc
);
8842 object_locator_t
base_oloc(soid
);
8843 base_oloc
.pool
= pool
.info
.tier_of
;
8845 if (dsnapc
.seq
< snapc
.seq
) {
8848 osd
->objecter
->mutate(
8853 ceph::real_clock::from_ceph_timespec(oi
.mtime
),
8854 (CEPH_OSD_FLAG_IGNORE_OVERLAY
|
8855 CEPH_OSD_FLAG_ENFORCE_SNAPC
),
8856 NULL
/* no callback, we'll rely on the ordering w.r.t the next op */);
8859 FlushOpRef
fop(std::make_shared
<FlushOp
>());
8861 fop
->flushed_version
= oi
.user_version
;
8862 fop
->blocking
= blocking
;
8863 fop
->on_flush
= std::move(on_flush
);
8867 if (oi
.is_whiteout()) {
8868 fop
->removal
= true;
8871 object_locator_t
oloc(soid
);
8872 o
.copy_from(soid
.oid
.name
, soid
.snap
, oloc
, oi
.user_version
,
8873 CEPH_OSD_COPY_FROM_FLAG_FLUSH
|
8874 CEPH_OSD_COPY_FROM_FLAG_IGNORE_OVERLAY
|
8875 CEPH_OSD_COPY_FROM_FLAG_IGNORE_CACHE
|
8876 CEPH_OSD_COPY_FROM_FLAG_MAP_SNAP_CLONE
,
8877 LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL
|LIBRADOS_OP_FLAG_FADVISE_NOCACHE
);
8879 //mean the base tier don't cache data after this
8880 if (agent_state
&& agent_state
->evict_mode
!= TierAgentState::EVICT_MODE_FULL
)
8881 o
.set_last_op_flags(LIBRADOS_OP_FLAG_FADVISE_DONTNEED
);
8883 C_Flush
*fin
= new C_Flush(this, soid
, get_last_peering_reset());
8885 ceph_tid_t tid
= osd
->objecter
->mutate(
8886 soid
.oid
, base_oloc
, o
, snapc
,
8887 ceph::real_clock::from_ceph_timespec(oi
.mtime
),
8888 CEPH_OSD_FLAG_IGNORE_OVERLAY
| CEPH_OSD_FLAG_ENFORCE_SNAPC
,
8889 new C_OnFinisher(fin
,
8890 &osd
->objecter_finisher
));
8891 /* we're under the pg lock and fin->finish() is grabbing that */
8893 fop
->objecter_tid
= tid
;
8895 flush_ops
[soid
] = fop
;
8896 info
.stats
.stats
.sum
.num_flush
++;
8897 info
.stats
.stats
.sum
.num_flush_kb
+= SHIFT_ROUND_UP(oi
.size
, 10);
8898 return -EINPROGRESS
;
8901 void PrimaryLogPG::finish_flush(hobject_t oid
, ceph_tid_t tid
, int r
)
8903 dout(10) << __func__
<< " " << oid
<< " tid " << tid
8904 << " " << cpp_strerror(r
) << dendl
;
8905 map
<hobject_t
,FlushOpRef
>::iterator p
= flush_ops
.find(oid
);
8906 if (p
== flush_ops
.end()) {
8907 dout(10) << __func__
<< " no flush_op found" << dendl
;
8910 FlushOpRef fop
= p
->second
;
8911 if (tid
!= fop
->objecter_tid
) {
8912 dout(10) << __func__
<< " tid " << tid
<< " != fop " << fop
8913 << " tid " << fop
->objecter_tid
<< dendl
;
8916 ObjectContextRef obc
= fop
->obc
;
8917 fop
->objecter_tid
= 0;
8919 if (r
< 0 && !(r
== -ENOENT
&& fop
->removal
)) {
8921 osd
->reply_op_error(fop
->op
, -EBUSY
);
8922 if (fop
->blocking
) {
8924 kick_object_context_blocked(obc
);
8927 if (!fop
->dup_ops
.empty()) {
8928 dout(20) << __func__
<< " requeueing dups" << dendl
;
8929 requeue_ops(fop
->dup_ops
);
8931 if (fop
->on_flush
) {
8932 (*(fop
->on_flush
))();
8933 fop
->on_flush
= boost::none
;
8935 flush_ops
.erase(oid
);
8939 r
= try_flush_mark_clean(fop
);
8940 if (r
== -EBUSY
&& fop
->op
) {
8941 osd
->reply_op_error(fop
->op
, r
);
8945 int PrimaryLogPG::try_flush_mark_clean(FlushOpRef fop
)
8947 ObjectContextRef obc
= fop
->obc
;
8948 const hobject_t
& oid
= obc
->obs
.oi
.soid
;
8950 if (fop
->blocking
) {
8952 kick_object_context_blocked(obc
);
8955 if (fop
->flushed_version
!= obc
->obs
.oi
.user_version
||
8957 if (obc
->obs
.exists
)
8958 dout(10) << __func__
<< " flushed_version " << fop
->flushed_version
8959 << " != current " << obc
->obs
.oi
.user_version
8962 dout(10) << __func__
<< " object no longer exists" << dendl
;
8964 if (!fop
->dup_ops
.empty()) {
8965 dout(20) << __func__
<< " requeueing dups" << dendl
;
8966 requeue_ops(fop
->dup_ops
);
8968 if (fop
->on_flush
) {
8969 (*(fop
->on_flush
))();
8970 fop
->on_flush
= boost::none
;
8972 flush_ops
.erase(oid
);
8974 osd
->logger
->inc(l_osd_tier_flush_fail
);
8976 osd
->logger
->inc(l_osd_tier_try_flush_fail
);
8980 if (!fop
->blocking
&&
8981 scrubber
.write_blocked_by_scrub(oid
)) {
8983 dout(10) << __func__
<< " blocked by scrub" << dendl
;
8984 requeue_op(fop
->op
);
8985 requeue_ops(fop
->dup_ops
);
8986 return -EAGAIN
; // will retry
8988 osd
->logger
->inc(l_osd_tier_try_flush_fail
);
8989 cancel_flush(fop
, false);
8994 // successfully flushed, can we evict this object?
8995 if (!fop
->op
&& agent_state
->evict_mode
!= TierAgentState::EVICT_MODE_IDLE
&&
8996 agent_maybe_evict(obc
, true)) {
8997 osd
->logger
->inc(l_osd_tier_clean
);
8998 if (fop
->on_flush
) {
8999 (*(fop
->on_flush
))();
9000 fop
->on_flush
= boost::none
;
9002 flush_ops
.erase(oid
);
9006 dout(10) << __func__
<< " clearing DIRTY flag for " << oid
<< dendl
;
9007 OpContextUPtr ctx
= simple_opc_create(fop
->obc
);
9009 // successfully flushed; can we clear the dirty bit?
9010 // try to take the lock manually, since we don't
9012 if (ctx
->lock_manager
.get_lock_type(
9013 ObjectContext::RWState::RWWRITE
,
9017 dout(20) << __func__
<< " took write lock" << dendl
;
9018 } else if (fop
->op
) {
9019 dout(10) << __func__
<< " waiting on write lock" << dendl
;
9020 close_op_ctx(ctx
.release());
9021 requeue_op(fop
->op
);
9022 requeue_ops(fop
->dup_ops
);
9023 return -EAGAIN
; // will retry
9025 dout(10) << __func__
<< " failed write lock, no op; failing" << dendl
;
9026 close_op_ctx(ctx
.release());
9027 osd
->logger
->inc(l_osd_tier_try_flush_fail
);
9028 cancel_flush(fop
, false);
9032 if (fop
->on_flush
) {
9033 ctx
->register_on_finish(*(fop
->on_flush
));
9034 fop
->on_flush
= boost::none
;
9037 ctx
->at_version
= get_next_version();
9039 ctx
->new_obs
= obc
->obs
;
9040 ctx
->new_obs
.oi
.clear_flag(object_info_t::FLAG_DIRTY
);
9041 --ctx
->delta_stats
.num_objects_dirty
;
9043 finish_ctx(ctx
.get(), pg_log_entry_t::CLEAN
);
9045 osd
->logger
->inc(l_osd_tier_clean
);
9047 if (!fop
->dup_ops
.empty() || fop
->op
) {
9048 dout(20) << __func__
<< " requeueing for " << ctx
->at_version
<< dendl
;
9049 list
<OpRequestRef
> ls
;
9051 ls
.push_back(fop
->op
);
9052 ls
.splice(ls
.end(), fop
->dup_ops
);
9056 simple_opc_submit(std::move(ctx
));
9058 flush_ops
.erase(oid
);
9061 osd
->logger
->inc(l_osd_tier_flush
);
9063 osd
->logger
->inc(l_osd_tier_try_flush
);
9065 return -EINPROGRESS
;
9068 void PrimaryLogPG::cancel_flush(FlushOpRef fop
, bool requeue
)
9070 dout(10) << __func__
<< " " << fop
->obc
->obs
.oi
.soid
<< " tid "
9071 << fop
->objecter_tid
<< dendl
;
9072 if (fop
->objecter_tid
) {
9073 osd
->objecter
->op_cancel(fop
->objecter_tid
, -ECANCELED
);
9074 fop
->objecter_tid
= 0;
9076 if (fop
->blocking
) {
9077 fop
->obc
->stop_block();
9078 kick_object_context_blocked(fop
->obc
);
9082 requeue_op(fop
->op
);
9083 requeue_ops(fop
->dup_ops
);
9085 if (fop
->on_flush
) {
9086 (*(fop
->on_flush
))();
9087 fop
->on_flush
= boost::none
;
9089 flush_ops
.erase(fop
->obc
->obs
.oi
.soid
);
9092 void PrimaryLogPG::cancel_flush_ops(bool requeue
)
9094 dout(10) << __func__
<< dendl
;
9095 map
<hobject_t
,FlushOpRef
>::iterator p
= flush_ops
.begin();
9096 while (p
!= flush_ops
.end()) {
9097 cancel_flush((p
++)->second
, requeue
);
9101 bool PrimaryLogPG::is_present_clone(hobject_t coid
)
9103 if (!pool
.info
.allow_incomplete_clones())
9105 if (is_missing_object(coid
))
9107 ObjectContextRef obc
= get_object_context(coid
, false);
9108 return obc
&& obc
->obs
.exists
;
9111 // ========================================================================
9114 class C_OSD_RepopApplied
: public Context
{
9116 boost::intrusive_ptr
<PrimaryLogPG::RepGather
> repop
;
9118 C_OSD_RepopApplied(PrimaryLogPG
*pg
, PrimaryLogPG::RepGather
*repop
)
9119 : pg(pg
), repop(repop
) {}
9120 void finish(int) override
{
9121 pg
->repop_all_applied(repop
.get());
9126 void PrimaryLogPG::repop_all_applied(RepGather
*repop
)
9128 dout(10) << __func__
<< ": repop tid " << repop
->rep_tid
<< " all applied "
9130 assert(!repop
->applies_with_commit
);
9131 repop
->all_applied
= true;
9132 if (!repop
->rep_aborted
) {
9137 class C_OSD_RepopCommit
: public Context
{
9139 boost::intrusive_ptr
<PrimaryLogPG::RepGather
> repop
;
9141 C_OSD_RepopCommit(PrimaryLogPG
*pg
, PrimaryLogPG::RepGather
*repop
)
9142 : pg(pg
), repop(repop
) {}
9143 void finish(int) override
{
9144 pg
->repop_all_committed(repop
.get());
9148 void PrimaryLogPG::repop_all_committed(RepGather
*repop
)
9150 dout(10) << __func__
<< ": repop tid " << repop
->rep_tid
<< " all committed "
9152 repop
->all_committed
= true;
9153 if (repop
->applies_with_commit
) {
9154 assert(!repop
->all_applied
);
9155 repop
->all_applied
= true;
9158 if (!repop
->rep_aborted
) {
9159 if (repop
->v
!= eversion_t()) {
9160 last_update_ondisk
= repop
->v
;
9161 last_complete_ondisk
= repop
->pg_local_last_complete
;
9167 void PrimaryLogPG::op_applied(const eversion_t
&applied_version
)
9169 dout(10) << "op_applied version " << applied_version
<< dendl
;
9170 if (applied_version
== eversion_t())
9172 assert(applied_version
> last_update_applied
);
9173 assert(applied_version
<= info
.last_update
);
9174 last_update_applied
= applied_version
;
9176 if (scrubber
.active
) {
9177 if (last_update_applied
>= scrubber
.subset_last_update
) {
9178 if (ops_blocked_by_scrub()) {
9179 requeue_scrub(true);
9181 requeue_scrub(false);
9186 assert(scrubber
.start
== scrubber
.end
);
9189 if (scrubber
.active_rep_scrub
) {
9190 if (last_update_applied
>= static_cast<const MOSDRepScrub
*>(
9191 scrubber
.active_rep_scrub
->get_req())->scrub_to
) {
9194 PGQueueable(scrubber
.active_rep_scrub
, get_osdmap()->get_epoch()));
9195 scrubber
.active_rep_scrub
= OpRequestRef();
9201 void PrimaryLogPG::eval_repop(RepGather
*repop
)
9203 const MOSDOp
*m
= NULL
;
9205 m
= static_cast<const MOSDOp
*>(repop
->op
->get_req());
9208 dout(10) << "eval_repop " << *repop
9209 << (repop
->rep_done
? " DONE" : "")
9212 dout(10) << "eval_repop " << *repop
<< " (no op)"
9213 << (repop
->rep_done
? " DONE" : "")
9216 if (repop
->rep_done
)
9220 if (repop
->all_committed
) {
9221 dout(10) << " commit: " << *repop
<< dendl
;
9222 for (auto p
= repop
->on_committed
.begin();
9223 p
!= repop
->on_committed
.end();
9224 repop
->on_committed
.erase(p
++)) {
9227 // send dup commits, in order
9228 if (waiting_for_ondisk
.count(repop
->v
)) {
9229 assert(waiting_for_ondisk
.begin()->first
== repop
->v
);
9230 for (list
<pair
<OpRequestRef
, version_t
> >::iterator i
=
9231 waiting_for_ondisk
[repop
->v
].begin();
9232 i
!= waiting_for_ondisk
[repop
->v
].end();
9234 osd
->reply_op_error(i
->first
, repop
->r
, repop
->v
,
9237 waiting_for_ondisk
.erase(repop
->v
);
9242 if (repop
->all_applied
) {
9243 if (repop
->applies_with_commit
) {
9244 assert(repop
->on_applied
.empty());
9246 dout(10) << " applied: " << *repop
<< " " << dendl
;
9247 for (auto p
= repop
->on_applied
.begin();
9248 p
!= repop
->on_applied
.end();
9249 repop
->on_applied
.erase(p
++)) {
9255 if (repop
->all_applied
&& repop
->all_committed
) {
9256 repop
->rep_done
= true;
9258 publish_stats_to_osd();
9259 calc_min_last_complete_ondisk();
9261 dout(10) << " removing " << *repop
<< dendl
;
9262 assert(!repop_queue
.empty());
9263 dout(20) << " q front is " << *repop_queue
.front() << dendl
;
9264 if (repop_queue
.front() != repop
) {
9265 if (!repop
->applies_with_commit
) {
9266 dout(0) << " removing " << *repop
<< dendl
;
9267 dout(0) << " q front is " << *repop_queue
.front() << dendl
;
9268 assert(repop_queue
.front() == repop
);
9271 RepGather
*to_remove
= nullptr;
9272 while (!repop_queue
.empty() &&
9273 (to_remove
= repop_queue
.front())->rep_done
) {
9274 repop_queue
.pop_front();
9275 for (auto p
= to_remove
->on_success
.begin();
9276 p
!= to_remove
->on_success
.end();
9277 to_remove
->on_success
.erase(p
++)) {
9280 remove_repop(to_remove
);
9286 void PrimaryLogPG::issue_repop(RepGather
*repop
, OpContext
*ctx
)
9289 const hobject_t
& soid
= ctx
->obs
->oi
.soid
;
9290 dout(7) << "issue_repop rep_tid " << repop
->rep_tid
9294 repop
->v
= ctx
->at_version
;
9295 if (ctx
->at_version
> eversion_t()) {
9296 for (set
<pg_shard_t
>::iterator i
= actingbackfill
.begin();
9297 i
!= actingbackfill
.end();
9299 if (*i
== get_primary()) continue;
9300 pg_info_t
&pinfo
= peer_info
[*i
];
9301 // keep peer_info up to date
9302 if (pinfo
.last_complete
== pinfo
.last_update
)
9303 pinfo
.last_complete
= ctx
->at_version
;
9304 pinfo
.last_update
= ctx
->at_version
;
9308 ctx
->obc
->ondisk_write_lock();
9310 bool unlock_snapset_obc
= false;
9311 ctx
->op_t
->add_obc(ctx
->obc
);
9312 if (ctx
->clone_obc
) {
9313 ctx
->clone_obc
->ondisk_write_lock();
9314 ctx
->op_t
->add_obc(ctx
->clone_obc
);
9316 if (ctx
->snapset_obc
&& ctx
->snapset_obc
->obs
.oi
.soid
!=
9317 ctx
->obc
->obs
.oi
.soid
) {
9318 ctx
->snapset_obc
->ondisk_write_lock();
9319 unlock_snapset_obc
= true;
9320 ctx
->op_t
->add_obc(ctx
->snapset_obc
);
9323 Context
*on_all_commit
= new C_OSD_RepopCommit(this, repop
);
9324 Context
*on_all_applied
= new C_OSD_RepopApplied(this, repop
);
9325 Context
*onapplied_sync
= new C_OSD_OndiskWriteUnlock(
9328 unlock_snapset_obc
? ctx
->snapset_obc
: ObjectContextRef());
9329 if (!(ctx
->log
.empty())) {
9330 assert(ctx
->at_version
>= projected_last_update
);
9331 projected_last_update
= ctx
->at_version
;
9333 for (auto &&entry
: ctx
->log
) {
9334 projected_log
.add(entry
);
9336 pgbackend
->submit_transaction(
9340 std::move(ctx
->op_t
),
9342 min_last_complete_ondisk
,
9344 ctx
->updated_hset_history
,
9353 PrimaryLogPG::RepGather
*PrimaryLogPG::new_repop(
9354 OpContext
*ctx
, ObjectContextRef obc
,
9358 dout(10) << "new_repop rep_tid " << rep_tid
<< " on " << *ctx
->op
->get_req() << dendl
;
9360 dout(10) << "new_repop rep_tid " << rep_tid
<< " (no op)" << dendl
;
9362 RepGather
*repop
= new RepGather(
9363 ctx
, rep_tid
, info
.last_complete
, false);
9365 repop
->start
= ceph_clock_now();
9367 repop_queue
.push_back(&repop
->queue_item
);
9370 osd
->logger
->inc(l_osd_op_wip
);
9372 dout(10) << __func__
<< ": " << *repop
<< dendl
;
9376 boost::intrusive_ptr
<PrimaryLogPG::RepGather
> PrimaryLogPG::new_repop(
9379 ObcLockManager
&&manager
,
9381 boost::optional
<std::function
<void(void)> > &&on_complete
)
9383 RepGather
*repop
= new RepGather(
9386 std::move(on_complete
),
9393 repop
->start
= ceph_clock_now();
9395 repop_queue
.push_back(&repop
->queue_item
);
9397 osd
->logger
->inc(l_osd_op_wip
);
9399 dout(10) << __func__
<< ": " << *repop
<< dendl
;
9400 return boost::intrusive_ptr
<RepGather
>(repop
);
9403 void PrimaryLogPG::remove_repop(RepGather
*repop
)
9405 dout(20) << __func__
<< " " << *repop
<< dendl
;
9407 for (auto p
= repop
->on_finish
.begin();
9408 p
!= repop
->on_finish
.end();
9409 repop
->on_finish
.erase(p
++)) {
9413 release_object_locks(
9414 repop
->lock_manager
);
9417 osd
->logger
->dec(l_osd_op_wip
);
9420 PrimaryLogPG::OpContextUPtr
PrimaryLogPG::simple_opc_create(ObjectContextRef obc
)
9422 dout(20) << __func__
<< " " << obc
->obs
.oi
.soid
<< dendl
;
9423 ceph_tid_t rep_tid
= osd
->get_tid();
9424 osd_reqid_t
reqid(osd
->get_cluster_msgr_name(), 0, rep_tid
);
9425 OpContextUPtr
ctx(new OpContext(OpRequestRef(), reqid
, nullptr, obc
, this));
9426 ctx
->op_t
.reset(new PGTransaction());
9427 ctx
->mtime
= ceph_clock_now();
9431 void PrimaryLogPG::simple_opc_submit(OpContextUPtr ctx
)
9433 RepGather
*repop
= new_repop(ctx
.get(), ctx
->obc
, ctx
->reqid
.tid
);
9434 dout(20) << __func__
<< " " << repop
<< dendl
;
9435 issue_repop(repop
, ctx
.get());
9442 void PrimaryLogPG::submit_log_entries(
9443 const mempool::osd_pglog::list
<pg_log_entry_t
> &entries
,
9444 ObcLockManager
&&manager
,
9445 boost::optional
<std::function
<void(void)> > &&_on_complete
,
9449 dout(10) << __func__
<< " " << entries
<< dendl
;
9450 assert(is_primary());
9453 if (!entries
.empty()) {
9454 assert(entries
.rbegin()->version
>= projected_last_update
);
9455 version
= projected_last_update
= entries
.rbegin()->version
;
9458 boost::intrusive_ptr
<RepGather
> repop
;
9459 boost::optional
<std::function
<void(void)> > on_complete
;
9460 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_JEWEL
) {
9466 std::move(_on_complete
));
9468 on_complete
= std::move(_on_complete
);
9471 pgbackend
->call_write_ordered(
9472 [this, entries
, repop
, on_complete
]() {
9473 ObjectStore::Transaction t
;
9474 eversion_t old_last_update
= info
.last_update
;
9475 merge_new_log_entries(entries
, t
);
9478 set
<pg_shard_t
> waiting_on
;
9479 for (set
<pg_shard_t
>::const_iterator i
= actingbackfill
.begin();
9480 i
!= actingbackfill
.end();
9482 pg_shard_t
peer(*i
);
9483 if (peer
== pg_whoami
) continue;
9484 assert(peer_missing
.count(peer
));
9485 assert(peer_info
.count(peer
));
9486 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_JEWEL
) {
9488 MOSDPGUpdateLogMissing
*m
= new MOSDPGUpdateLogMissing(
9490 spg_t(info
.pgid
.pgid
, i
->shard
),
9492 get_osdmap()->get_epoch(),
9495 osd
->send_message_osd_cluster(
9496 peer
.osd
, m
, get_osdmap()->get_epoch());
9497 waiting_on
.insert(peer
);
9499 MOSDPGLog
*m
= new MOSDPGLog(
9500 peer
.shard
, pg_whoami
.shard
,
9501 info
.last_update
.epoch
,
9503 m
->log
.log
= entries
;
9504 m
->log
.tail
= old_last_update
;
9505 m
->log
.head
= info
.last_update
;
9506 osd
->send_message_osd_cluster(
9507 peer
.osd
, m
, get_osdmap()->get_epoch());
9510 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_JEWEL
) {
9511 ceph_tid_t rep_tid
= repop
->rep_tid
;
9512 waiting_on
.insert(pg_whoami
);
9513 log_entry_update_waiting_on
.insert(
9516 LogUpdateCtx
{std::move(repop
), std::move(waiting_on
)}
9518 struct OnComplete
: public Context
{
9526 : pg(pg
), rep_tid(rep_tid
), epoch(epoch
) {}
9527 void finish(int) override
{
9529 if (!pg
->pg_has_reset_since(epoch
)) {
9530 auto it
= pg
->log_entry_update_waiting_on
.find(rep_tid
);
9531 assert(it
!= pg
->log_entry_update_waiting_on
.end());
9532 auto it2
= it
->second
.waiting_on
.find(pg
->pg_whoami
);
9533 assert(it2
!= it
->second
.waiting_on
.end());
9534 it
->second
.waiting_on
.erase(it2
);
9535 if (it
->second
.waiting_on
.empty()) {
9536 pg
->repop_all_committed(it
->second
.repop
.get());
9537 pg
->log_entry_update_waiting_on
.erase(it
);
9543 t
.register_on_commit(
9544 new OnComplete
{this, rep_tid
, get_osdmap()->get_epoch()});
9547 struct OnComplete
: public Context
{
9549 std::function
<void(void)> on_complete
;
9553 const std::function
<void(void)> &on_complete
,
9556 on_complete(std::move(on_complete
)),
9558 void finish(int) override
{
9560 if (!pg
->pg_has_reset_since(epoch
))
9565 t
.register_on_complete(
9567 this, *on_complete
, get_osdmap()->get_epoch()
9571 t
.register_on_applied(
9572 new C_OSD_OnApplied
{this, get_osdmap()->get_epoch(), info
.last_update
});
9573 int r
= osd
->store
->queue_transaction(osr
.get(), std::move(t
), NULL
);
9578 void PrimaryLogPG::cancel_log_updates()
9580 // get rid of all the LogUpdateCtx so their references to repops are
9582 log_entry_update_waiting_on
.clear();
9585 // -------------------------------------------------------
9587 void PrimaryLogPG::get_watchers(list
<obj_watch_item_t
> &pg_watchers
)
9589 pair
<hobject_t
, ObjectContextRef
> i
;
9590 while (object_contexts
.get_next(i
.first
, &i
)) {
9591 ObjectContextRef
obc(i
.second
);
9592 get_obc_watchers(obc
, pg_watchers
);
9596 void PrimaryLogPG::get_obc_watchers(ObjectContextRef obc
, list
<obj_watch_item_t
> &pg_watchers
)
9598 for (map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator j
=
9599 obc
->watchers
.begin();
9600 j
!= obc
->watchers
.end();
9602 obj_watch_item_t owi
;
9604 owi
.obj
= obc
->obs
.oi
.soid
;
9605 owi
.wi
.addr
= j
->second
->get_peer_addr();
9606 owi
.wi
.name
= j
->second
->get_entity();
9607 owi
.wi
.cookie
= j
->second
->get_cookie();
9608 owi
.wi
.timeout_seconds
= j
->second
->get_timeout();
9610 dout(30) << "watch: Found oid=" << owi
.obj
<< " addr=" << owi
.wi
.addr
9611 << " name=" << owi
.wi
.name
<< " cookie=" << owi
.wi
.cookie
<< dendl
;
9613 pg_watchers
.push_back(owi
);
9617 void PrimaryLogPG::check_blacklisted_watchers()
9619 dout(20) << "PrimaryLogPG::check_blacklisted_watchers for pg " << get_pgid() << dendl
;
9620 pair
<hobject_t
, ObjectContextRef
> i
;
9621 while (object_contexts
.get_next(i
.first
, &i
))
9622 check_blacklisted_obc_watchers(i
.second
);
9625 void PrimaryLogPG::check_blacklisted_obc_watchers(ObjectContextRef obc
)
9627 dout(20) << "PrimaryLogPG::check_blacklisted_obc_watchers for obc " << obc
->obs
.oi
.soid
<< dendl
;
9628 for (map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator k
=
9629 obc
->watchers
.begin();
9630 k
!= obc
->watchers
.end();
9632 //Advance iterator now so handle_watch_timeout() can erase element
9633 map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator j
= k
++;
9634 dout(30) << "watch: Found " << j
->second
->get_entity() << " cookie " << j
->second
->get_cookie() << dendl
;
9635 entity_addr_t ea
= j
->second
->get_peer_addr();
9636 dout(30) << "watch: Check entity_addr_t " << ea
<< dendl
;
9637 if (get_osdmap()->is_blacklisted(ea
)) {
9638 dout(10) << "watch: Found blacklisted watcher for " << ea
<< dendl
;
9639 assert(j
->second
->get_pg() == this);
9640 j
->second
->unregister_cb();
9641 handle_watch_timeout(j
->second
);
9646 void PrimaryLogPG::populate_obc_watchers(ObjectContextRef obc
)
9648 assert(is_active());
9649 assert((recovering
.count(obc
->obs
.oi
.soid
) ||
9650 !is_missing_object(obc
->obs
.oi
.soid
)) ||
9651 (pg_log
.get_log().objects
.count(obc
->obs
.oi
.soid
) && // or this is a revert... see recover_primary()
9652 pg_log
.get_log().objects
.find(obc
->obs
.oi
.soid
)->second
->op
==
9653 pg_log_entry_t::LOST_REVERT
&&
9654 pg_log
.get_log().objects
.find(obc
->obs
.oi
.soid
)->second
->reverting_to
==
9655 obc
->obs
.oi
.version
));
9657 dout(10) << "populate_obc_watchers " << obc
->obs
.oi
.soid
<< dendl
;
9658 assert(obc
->watchers
.empty());
9659 // populate unconnected_watchers
9660 for (map
<pair
<uint64_t, entity_name_t
>, watch_info_t
>::iterator p
=
9661 obc
->obs
.oi
.watchers
.begin();
9662 p
!= obc
->obs
.oi
.watchers
.end();
9664 utime_t expire
= info
.stats
.last_became_active
;
9665 expire
+= p
->second
.timeout_seconds
;
9666 dout(10) << " unconnected watcher " << p
->first
<< " will expire " << expire
<< dendl
;
9668 Watch::makeWatchRef(
9669 this, osd
, obc
, p
->second
.timeout_seconds
, p
->first
.first
,
9670 p
->first
.second
, p
->second
.addr
));
9671 watch
->disconnect();
9672 obc
->watchers
.insert(
9674 make_pair(p
->first
.first
, p
->first
.second
),
9677 // Look for watchers from blacklisted clients and drop
9678 check_blacklisted_obc_watchers(obc
);
9681 void PrimaryLogPG::handle_watch_timeout(WatchRef watch
)
9683 ObjectContextRef obc
= watch
->get_obc(); // handle_watch_timeout owns this ref
9684 dout(10) << "handle_watch_timeout obc " << obc
<< dendl
;
9687 dout(10) << "handle_watch_timeout not active, no-op" << dendl
;
9690 if (is_degraded_or_backfilling_object(obc
->obs
.oi
.soid
)) {
9691 callbacks_for_degraded_object
[obc
->obs
.oi
.soid
].push_back(
9692 watch
->get_delayed_cb()
9694 dout(10) << "handle_watch_timeout waiting for degraded on obj "
9700 if (scrubber
.write_blocked_by_scrub(obc
->obs
.oi
.soid
)) {
9701 dout(10) << "handle_watch_timeout waiting for scrub on obj "
9704 scrubber
.add_callback(
9705 watch
->get_delayed_cb() // This callback!
9710 OpContextUPtr ctx
= simple_opc_create(obc
);
9711 ctx
->at_version
= get_next_version();
9713 object_info_t
& oi
= ctx
->new_obs
.oi
;
9714 oi
.watchers
.erase(make_pair(watch
->get_cookie(),
9715 watch
->get_entity()));
9717 list
<watch_disconnect_t
> watch_disconnects
= {
9718 watch_disconnect_t(watch
->get_cookie(), watch
->get_entity(), true)
9720 ctx
->register_on_success(
9721 [this, obc
, watch_disconnects
]() {
9722 complete_disconnect_watches(obc
, watch_disconnects
);
9726 PGTransaction
*t
= ctx
->op_t
.get();
9727 ctx
->log
.push_back(pg_log_entry_t(pg_log_entry_t::MODIFY
, obc
->obs
.oi
.soid
,
9731 osd_reqid_t(), ctx
->mtime
, 0));
9733 oi
.prior_version
= obc
->obs
.oi
.version
;
9734 oi
.version
= ctx
->at_version
;
9736 ::encode(oi
, bl
, get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
9737 t
->setattr(obc
->obs
.oi
.soid
, OI_ATTR
, bl
);
9739 // apply new object state.
9740 ctx
->obc
->obs
= ctx
->new_obs
;
9742 // no ctx->delta_stats
9743 simple_opc_submit(std::move(ctx
));
9746 ObjectContextRef
PrimaryLogPG::create_object_context(const object_info_t
& oi
,
9747 SnapSetContext
*ssc
)
9749 ObjectContextRef
obc(object_contexts
.lookup_or_create(oi
.soid
));
9750 assert(obc
->destructor_callback
== NULL
);
9751 obc
->destructor_callback
= new C_PG_ObjectContext(this, obc
.get());
9753 obc
->obs
.exists
= false;
9756 register_snapset_context(ssc
);
9757 dout(10) << "create_object_context " << (void*)obc
.get() << " " << oi
.soid
<< " " << dendl
;
9759 populate_obc_watchers(obc
);
9763 ObjectContextRef
PrimaryLogPG::get_object_context(
9764 const hobject_t
& soid
,
9766 const map
<string
, bufferlist
> *attrs
)
9769 attrs
|| !pg_log
.get_missing().is_missing(soid
) ||
9770 // or this is a revert... see recover_primary()
9771 (pg_log
.get_log().objects
.count(soid
) &&
9772 pg_log
.get_log().objects
.find(soid
)->second
->op
==
9773 pg_log_entry_t::LOST_REVERT
));
9774 ObjectContextRef obc
= object_contexts
.lookup(soid
);
9775 osd
->logger
->inc(l_osd_object_ctx_cache_total
);
9777 osd
->logger
->inc(l_osd_object_ctx_cache_hit
);
9778 dout(10) << __func__
<< ": found obc in cache: " << obc
9781 dout(10) << __func__
<< ": obc NOT found in cache: " << soid
<< dendl
;
9785 assert(attrs
->count(OI_ATTR
));
9786 bv
= attrs
->find(OI_ATTR
)->second
;
9788 int r
= pgbackend
->objects_get_attr(soid
, OI_ATTR
, &bv
);
9791 dout(10) << __func__
<< ": no obc for soid "
9792 << soid
<< " and !can_create"
9794 return ObjectContextRef(); // -ENOENT!
9797 dout(10) << __func__
<< ": no obc for soid "
9798 << soid
<< " but can_create"
9801 object_info_t
oi(soid
);
9802 SnapSetContext
*ssc
= get_snapset_context(
9803 soid
, true, 0, false);
9805 obc
= create_object_context(oi
, ssc
);
9806 dout(10) << __func__
<< ": " << obc
<< " " << soid
9807 << " " << obc
->rwstate
9808 << " oi: " << obc
->obs
.oi
9809 << " ssc: " << obc
->ssc
9810 << " snapset: " << obc
->ssc
->snapset
<< dendl
;
9817 bufferlist::iterator bliter
= bv
.begin();
9818 ::decode(oi
, bliter
);
9820 dout(0) << __func__
<< ": obc corrupt: " << soid
<< dendl
;
9821 return ObjectContextRef(); // -ENOENT!
9824 assert(oi
.soid
.pool
== (int64_t)info
.pgid
.pool());
9826 obc
= object_contexts
.lookup_or_create(oi
.soid
);
9827 obc
->destructor_callback
= new C_PG_ObjectContext(this, obc
.get());
9829 obc
->obs
.exists
= true;
9831 obc
->ssc
= get_snapset_context(
9833 soid
.has_snapset() ? attrs
: 0);
9836 populate_obc_watchers(obc
);
9838 if (pool
.info
.require_rollback()) {
9840 obc
->attr_cache
= *attrs
;
9842 int r
= pgbackend
->objects_get_attrs(
9849 dout(10) << __func__
<< ": creating obc from disk: " << obc
9853 // XXX: Caller doesn't expect this
9854 if (obc
->ssc
== NULL
) {
9855 derr
<< __func__
<< ": obc->ssc not available, not returning context" << dendl
;
9856 return ObjectContextRef(); // -ENOENT!
9859 dout(10) << __func__
<< ": " << obc
<< " " << soid
9860 << " " << obc
->rwstate
9861 << " oi: " << obc
->obs
.oi
9862 << " exists: " << (int)obc
->obs
.exists
9863 << " ssc: " << obc
->ssc
9864 << " snapset: " << obc
->ssc
->snapset
<< dendl
;
9868 void PrimaryLogPG::context_registry_on_change()
9870 pair
<hobject_t
, ObjectContextRef
> i
;
9871 while (object_contexts
.get_next(i
.first
, &i
)) {
9872 ObjectContextRef
obc(i
.second
);
9874 for (map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator j
=
9875 obc
->watchers
.begin();
9876 j
!= obc
->watchers
.end();
9877 obc
->watchers
.erase(j
++)) {
9878 j
->second
->discard();
9886 * If we return an error, and set *pmissing, then promoting that
9889 * If we return -EAGAIN, we will always set *pmissing to the missing
9890 * object to wait for.
9892 * If we return an error but do not set *pmissing, then we know the
9893 * object does not exist.
9895 int PrimaryLogPG::find_object_context(const hobject_t
& oid
,
9896 ObjectContextRef
*pobc
,
9898 bool map_snapid_to_clone
,
9899 hobject_t
*pmissing
)
9902 assert(oid
.pool
== static_cast<int64_t>(info
.pgid
.pool()));
9904 if (oid
.snap
== CEPH_NOSNAP
) {
9905 ObjectContextRef obc
= get_object_context(oid
, can_create
);
9911 dout(10) << "find_object_context " << oid
9913 << " oi=" << obc
->obs
.oi
9920 hobject_t head
= oid
.get_head();
9922 // want the snapdir?
9923 if (oid
.snap
== CEPH_SNAPDIR
) {
9924 // return head or snapdir, whichever exists.
9925 ObjectContextRef headobc
= get_object_context(head
, can_create
);
9926 ObjectContextRef obc
= headobc
;
9927 if (!obc
|| !obc
->obs
.exists
)
9928 obc
= get_object_context(oid
, can_create
);
9929 if (!obc
|| !obc
->obs
.exists
) {
9930 // if we have neither, we would want to promote the head.
9934 *pobc
= headobc
; // may be null
9937 dout(10) << "find_object_context " << oid
9939 << " oi=" << obc
->obs
.oi
9943 // always populate ssc for SNAPDIR...
9945 obc
->ssc
= get_snapset_context(
9951 if (!map_snapid_to_clone
&& pool
.info
.is_removed_snap(oid
.snap
)) {
9952 dout(10) << __func__
<< " snap " << oid
.snap
<< " is removed" << dendl
;
9956 SnapSetContext
*ssc
= get_snapset_context(oid
, can_create
);
9957 if (!ssc
|| !(ssc
->exists
|| can_create
)) {
9958 dout(20) << __func__
<< " " << oid
<< " no snapset" << dendl
;
9960 *pmissing
= head
; // start by getting the head
9962 put_snapset_context(ssc
);
9966 if (map_snapid_to_clone
) {
9967 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
9968 << " snapset " << ssc
->snapset
9969 << " map_snapid_to_clone=true" << dendl
;
9970 if (oid
.snap
> ssc
->snapset
.seq
) {
9971 // already must be readable
9972 ObjectContextRef obc
= get_object_context(head
, false);
9973 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
9974 << " snapset " << ssc
->snapset
9975 << " maps to head" << dendl
;
9977 put_snapset_context(ssc
);
9978 return (obc
&& obc
->obs
.exists
) ? 0 : -ENOENT
;
9980 vector
<snapid_t
>::const_iterator citer
= std::find(
9981 ssc
->snapset
.clones
.begin(),
9982 ssc
->snapset
.clones
.end(),
9984 if (citer
== ssc
->snapset
.clones
.end()) {
9985 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
9986 << " snapset " << ssc
->snapset
9987 << " maps to nothing" << dendl
;
9988 put_snapset_context(ssc
);
9992 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
9993 << " snapset " << ssc
->snapset
9994 << " maps to " << oid
<< dendl
;
9996 if (pg_log
.get_missing().is_missing(oid
)) {
9997 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
9998 << " snapset " << ssc
->snapset
9999 << " " << oid
<< " is missing" << dendl
;
10002 put_snapset_context(ssc
);
10006 ObjectContextRef obc
= get_object_context(oid
, false);
10007 if (!obc
|| !obc
->obs
.exists
) {
10008 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
10009 << " snapset " << ssc
->snapset
10010 << " " << oid
<< " is not present" << dendl
;
10013 put_snapset_context(ssc
);
10016 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
10017 << " snapset " << ssc
->snapset
10018 << " " << oid
<< " HIT" << dendl
;
10020 put_snapset_context(ssc
);
10023 ceph_abort(); //unreachable
10026 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
10027 << " snapset " << ssc
->snapset
<< dendl
;
10030 if (oid
.snap
> ssc
->snapset
.seq
) {
10031 if (ssc
->snapset
.head_exists
) {
10032 ObjectContextRef obc
= get_object_context(head
, false);
10033 dout(10) << "find_object_context " << head
10034 << " want " << oid
.snap
<< " > snapset seq " << ssc
->snapset
.seq
10035 << " -- HIT " << obc
->obs
10040 assert(ssc
== obc
->ssc
);
10041 put_snapset_context(ssc
);
10046 dout(10) << "find_object_context " << head
10047 << " want " << oid
.snap
<< " > snapset seq " << ssc
->snapset
.seq
10048 << " but head dne -- DNE"
10050 put_snapset_context(ssc
);
10054 // which clone would it be?
10056 while (k
< ssc
->snapset
.clones
.size() &&
10057 ssc
->snapset
.clones
[k
] < oid
.snap
)
10059 if (k
== ssc
->snapset
.clones
.size()) {
10060 dout(10) << "find_object_context no clones with last >= oid.snap "
10061 << oid
.snap
<< " -- DNE" << dendl
;
10062 put_snapset_context(ssc
);
10065 hobject_t
soid(oid
.oid
, oid
.get_key(), ssc
->snapset
.clones
[k
], oid
.get_hash(),
10066 info
.pgid
.pool(), oid
.get_namespace());
10068 if (pg_log
.get_missing().is_missing(soid
)) {
10069 dout(20) << "find_object_context " << soid
<< " missing, try again later"
10073 put_snapset_context(ssc
);
10077 ObjectContextRef obc
= get_object_context(soid
, false);
10078 if (!obc
|| !obc
->obs
.exists
) {
10081 put_snapset_context(ssc
);
10082 if (is_degraded_or_backfilling_object(soid
)) {
10083 dout(20) << __func__
<< " clone is degraded or backfilling " << soid
<< dendl
;
10086 dout(20) << __func__
<< " missing clone " << soid
<< dendl
;
10094 assert(obc
->ssc
== ssc
);
10095 put_snapset_context(ssc
);
10100 dout(20) << "find_object_context " << soid
10101 << " snapset " << obc
->ssc
->snapset
10102 << " legacy_snaps " << obc
->obs
.oi
.legacy_snaps
10104 snapid_t first
, last
;
10105 if (obc
->ssc
->snapset
.is_legacy()) {
10106 first
= obc
->obs
.oi
.legacy_snaps
.back();
10107 last
= obc
->obs
.oi
.legacy_snaps
.front();
10109 auto p
= obc
->ssc
->snapset
.clone_snaps
.find(soid
.snap
);
10110 assert(p
!= obc
->ssc
->snapset
.clone_snaps
.end());
10111 first
= p
->second
.back();
10112 last
= p
->second
.front();
10114 if (first
<= oid
.snap
) {
10115 dout(20) << "find_object_context " << soid
<< " [" << first
<< "," << last
10116 << "] contains " << oid
.snap
<< " -- HIT " << obc
->obs
<< dendl
;
10120 dout(20) << "find_object_context " << soid
<< " [" << first
<< "," << last
10121 << "] does not contain " << oid
.snap
<< " -- DNE" << dendl
;
10126 void PrimaryLogPG::object_context_destructor_callback(ObjectContext
*obc
)
10129 put_snapset_context(obc
->ssc
);
10132 void PrimaryLogPG::add_object_context_to_pg_stat(ObjectContextRef obc
, pg_stat_t
*pgstat
)
10134 object_info_t
& oi
= obc
->obs
.oi
;
10136 dout(10) << "add_object_context_to_pg_stat " << oi
.soid
<< dendl
;
10137 object_stat_sum_t stat
;
10139 stat
.num_bytes
+= oi
.size
;
10141 if (oi
.soid
.snap
!= CEPH_SNAPDIR
)
10142 stat
.num_objects
++;
10144 stat
.num_objects_dirty
++;
10145 if (oi
.is_whiteout())
10146 stat
.num_whiteouts
++;
10148 stat
.num_objects_omap
++;
10149 if (oi
.is_cache_pinned())
10150 stat
.num_objects_pinned
++;
10152 if (oi
.soid
.snap
&& oi
.soid
.snap
!= CEPH_NOSNAP
&& oi
.soid
.snap
!= CEPH_SNAPDIR
) {
10153 stat
.num_object_clones
++;
10156 obc
->ssc
= get_snapset_context(oi
.soid
, false);
10159 // subtract off clone overlap
10160 if (obc
->ssc
->snapset
.clone_overlap
.count(oi
.soid
.snap
)) {
10161 interval_set
<uint64_t>& o
= obc
->ssc
->snapset
.clone_overlap
[oi
.soid
.snap
];
10162 for (interval_set
<uint64_t>::const_iterator r
= o
.begin();
10165 stat
.num_bytes
-= r
.get_len();
10171 pgstat
->stats
.sum
.add(stat
);
10174 void PrimaryLogPG::kick_object_context_blocked(ObjectContextRef obc
)
10176 const hobject_t
& soid
= obc
->obs
.oi
.soid
;
10177 if (obc
->is_blocked()) {
10178 dout(10) << __func__
<< " " << soid
<< " still blocked" << dendl
;
10182 map
<hobject_t
, list
<OpRequestRef
>>::iterator p
= waiting_for_blocked_object
.find(soid
);
10183 if (p
!= waiting_for_blocked_object
.end()) {
10184 list
<OpRequestRef
>& ls
= p
->second
;
10185 dout(10) << __func__
<< " " << soid
<< " requeuing " << ls
.size() << " requests" << dendl
;
10187 waiting_for_blocked_object
.erase(p
);
10190 map
<hobject_t
, ObjectContextRef
>::iterator i
=
10191 objects_blocked_on_snap_promotion
.find(obc
->obs
.oi
.soid
.get_head());
10192 if (i
!= objects_blocked_on_snap_promotion
.end()) {
10193 assert(i
->second
== obc
);
10194 objects_blocked_on_snap_promotion
.erase(i
);
10197 if (obc
->requeue_scrub_on_unblock
) {
10198 obc
->requeue_scrub_on_unblock
= false;
10203 SnapSetContext
*PrimaryLogPG::get_snapset_context(
10204 const hobject_t
& oid
,
10206 const map
<string
, bufferlist
> *attrs
,
10209 Mutex::Locker
l(snapset_contexts_lock
);
10210 SnapSetContext
*ssc
;
10211 map
<hobject_t
, SnapSetContext
*>::iterator p
= snapset_contexts
.find(
10212 oid
.get_snapdir());
10213 if (p
!= snapset_contexts
.end()) {
10214 if (can_create
|| p
->second
->exists
) {
10223 if (!(oid
.is_head() && !oid_existed
))
10224 r
= pgbackend
->objects_get_attr(oid
.get_head(), SS_ATTR
, &bv
);
10227 if (!(oid
.is_snapdir() && !oid_existed
))
10228 r
= pgbackend
->objects_get_attr(oid
.get_snapdir(), SS_ATTR
, &bv
);
10229 if (r
< 0 && !can_create
)
10233 assert(attrs
->count(SS_ATTR
));
10234 bv
= attrs
->find(SS_ATTR
)->second
;
10236 ssc
= new SnapSetContext(oid
.get_snapdir());
10237 _register_snapset_context(ssc
);
10239 bufferlist::iterator bvp
= bv
.begin();
10241 ssc
->snapset
.decode(bvp
);
10242 } catch (buffer::error
& e
) {
10243 dout(0) << __func__
<< " Can't decode snapset: " << e
<< dendl
;
10246 ssc
->exists
= true;
10248 ssc
->exists
= false;
10256 void PrimaryLogPG::put_snapset_context(SnapSetContext
*ssc
)
10258 Mutex::Locker
l(snapset_contexts_lock
);
10260 if (ssc
->ref
== 0) {
10261 if (ssc
->registered
)
10262 snapset_contexts
.erase(ssc
->oid
);
10267 /** pull - request object from a peer
10272 * NONE - didn't pull anything
10273 * YES - pulled what the caller wanted
10274 * OTHER - needed to pull something else first (_head or _snapdir)
10276 enum { PULL_NONE
, PULL_OTHER
, PULL_YES
};
10278 int PrimaryLogPG::recover_missing(
10279 const hobject_t
&soid
, eversion_t v
,
10281 PGBackend::RecoveryHandle
*h
)
10283 if (missing_loc
.is_unfound(soid
)) {
10284 dout(7) << "pull " << soid
10286 << " but it is unfound" << dendl
;
10290 if (missing_loc
.is_deleted(soid
)) {
10291 start_recovery_op(soid
);
10292 assert(!recovering
.count(soid
));
10293 recovering
.insert(make_pair(soid
, ObjectContextRef()));
10294 epoch_t cur_epoch
= get_osdmap()->get_epoch();
10295 remove_missing_object(soid
, v
, new FunctionContext(
10298 if (!pg_has_reset_since(cur_epoch
)) {
10299 bool object_missing
= false;
10300 for (const auto& shard
: actingbackfill
) {
10301 if (shard
== pg_whoami
)
10303 if (peer_missing
[shard
].is_missing(soid
)) {
10304 dout(20) << __func__
<< ": soid " << soid
<< " needs to be deleted from replica " << shard
<< dendl
;
10305 object_missing
= true;
10309 if (!object_missing
) {
10310 object_stat_sum_t stat_diff
;
10311 stat_diff
.num_objects_recovered
= 1;
10312 on_global_recover(soid
, stat_diff
, true);
10314 auto recovery_handle
= pgbackend
->open_recovery_op();
10315 pgbackend
->recover_delete_object(soid
, v
, recovery_handle
);
10316 pgbackend
->run_recovery_op(recovery_handle
, priority
);
10324 // is this a snapped object? if so, consult the snapset.. we may not need the entire object!
10325 ObjectContextRef obc
;
10326 ObjectContextRef head_obc
;
10327 if (soid
.snap
&& soid
.snap
< CEPH_NOSNAP
) {
10328 // do we have the head and/or snapdir?
10329 hobject_t head
= soid
.get_head();
10330 if (pg_log
.get_missing().is_missing(head
)) {
10331 if (recovering
.count(head
)) {
10332 dout(10) << " missing but already recovering head " << head
<< dendl
;
10335 int r
= recover_missing(
10336 head
, pg_log
.get_missing().get_items().find(head
)->second
.need
, priority
,
10338 if (r
!= PULL_NONE
)
10343 head
= soid
.get_snapdir();
10344 if (pg_log
.get_missing().is_missing(head
)) {
10345 if (recovering
.count(head
)) {
10346 dout(10) << " missing but already recovering snapdir " << head
<< dendl
;
10349 int r
= recover_missing(
10350 head
, pg_log
.get_missing().get_items().find(head
)->second
.need
, priority
,
10352 if (r
!= PULL_NONE
)
10358 // we must have one or the other
10359 head_obc
= get_object_context(
10364 head_obc
= get_object_context(
10365 soid
.get_snapdir(),
10370 start_recovery_op(soid
);
10371 assert(!recovering
.count(soid
));
10372 recovering
.insert(make_pair(soid
, obc
));
10373 int r
= pgbackend
->recover_object(
10379 // This is only a pull which shouldn't return an error
10384 void PrimaryLogPG::send_remove_op(
10385 const hobject_t
& oid
, eversion_t v
, pg_shard_t peer
)
10387 ceph_tid_t tid
= osd
->get_tid();
10388 osd_reqid_t
rid(osd
->get_cluster_msgr_name(), 0, tid
);
10390 dout(10) << "send_remove_op " << oid
<< " from osd." << peer
10391 << " tid " << tid
<< dendl
;
10393 MOSDSubOp
*subop
= new MOSDSubOp(
10394 rid
, pg_whoami
, spg_t(info
.pgid
.pgid
, peer
.shard
),
10395 oid
, CEPH_OSD_FLAG_ACK
,
10396 get_osdmap()->get_epoch(), tid
, v
);
10397 subop
->ops
= vector
<OSDOp
>(1);
10398 subop
->ops
[0].op
.op
= CEPH_OSD_OP_DELETE
;
10400 osd
->send_message_osd_cluster(peer
.osd
, subop
, get_osdmap()->get_epoch());
10403 void PrimaryLogPG::remove_missing_object(const hobject_t
&soid
,
10404 eversion_t v
, Context
*on_complete
)
10406 dout(20) << __func__
<< " " << soid
<< " " << v
<< dendl
;
10407 assert(on_complete
!= nullptr);
10409 ObjectStore::Transaction t
;
10410 remove_snap_mapped_object(t
, soid
);
10412 ObjectRecoveryInfo recovery_info
;
10413 recovery_info
.soid
= soid
;
10414 recovery_info
.version
= v
;
10416 epoch_t cur_epoch
= get_osdmap()->get_epoch();
10417 t
.register_on_complete(new FunctionContext(
10420 if (!pg_has_reset_since(cur_epoch
)) {
10421 ObjectStore::Transaction t2
;
10422 on_local_recover(soid
, recovery_info
, ObjectContextRef(), true, &t2
);
10423 t2
.register_on_complete(on_complete
);
10424 int r
= osd
->store
->queue_transaction(osr
.get(), std::move(t2
), nullptr);
10429 on_complete
->complete(-EAGAIN
);
10432 int r
= osd
->store
->queue_transaction(osr
.get(), std::move(t
), nullptr);
10436 void PrimaryLogPG::finish_degraded_object(const hobject_t
& oid
)
10438 dout(10) << "finish_degraded_object " << oid
<< dendl
;
10439 if (callbacks_for_degraded_object
.count(oid
)) {
10440 list
<Context
*> contexts
;
10441 contexts
.swap(callbacks_for_degraded_object
[oid
]);
10442 callbacks_for_degraded_object
.erase(oid
);
10443 for (list
<Context
*>::iterator i
= contexts
.begin();
10444 i
!= contexts
.end();
10449 map
<hobject_t
, snapid_t
>::iterator i
= objects_blocked_on_degraded_snap
.find(
10451 if (i
!= objects_blocked_on_degraded_snap
.end() &&
10452 i
->second
== oid
.snap
)
10453 objects_blocked_on_degraded_snap
.erase(i
);
10456 void PrimaryLogPG::_committed_pushed_object(
10457 epoch_t epoch
, eversion_t last_complete
)
10460 if (!pg_has_reset_since(epoch
)) {
10461 dout(10) << "_committed_pushed_object last_complete " << last_complete
<< " now ondisk" << dendl
;
10462 last_complete_ondisk
= last_complete
;
10464 if (last_complete_ondisk
== info
.last_update
) {
10465 if (!is_primary()) {
10466 // Either we are a replica or backfill target.
10467 // we are fully up to date. tell the primary!
10468 osd
->send_message_osd_cluster(
10471 get_osdmap()->get_epoch(),
10472 spg_t(info
.pgid
.pgid
, get_primary().shard
),
10473 last_complete_ondisk
),
10474 get_osdmap()->get_epoch());
10476 calc_min_last_complete_ondisk();
10481 dout(10) << "_committed_pushed_object pg has changed, not touching last_complete_ondisk" << dendl
;
10487 void PrimaryLogPG::_applied_recovered_object(ObjectContextRef obc
)
10490 dout(20) << __func__
<< dendl
;
10492 dout(20) << "obc = " << *obc
<< dendl
;
10494 assert(active_pushes
>= 1);
10497 // requeue an active chunky scrub waiting on recovery ops
10498 if (!deleting
&& active_pushes
== 0
10499 && scrubber
.is_chunky_scrub_active()) {
10500 if (ops_blocked_by_scrub()) {
10501 requeue_scrub(true);
10503 requeue_scrub(false);
10509 void PrimaryLogPG::_applied_recovered_object_replica()
10512 dout(20) << __func__
<< dendl
;
10513 assert(active_pushes
>= 1);
10516 // requeue an active chunky scrub waiting on recovery ops
10517 if (!deleting
&& active_pushes
== 0 &&
10518 scrubber
.active_rep_scrub
&& static_cast<const MOSDRepScrub
*>(
10519 scrubber
.active_rep_scrub
->get_req())->chunky
) {
10522 PGQueueable(scrubber
.active_rep_scrub
, get_osdmap()->get_epoch()));
10523 scrubber
.active_rep_scrub
= OpRequestRef();
10528 void PrimaryLogPG::recover_got(hobject_t oid
, eversion_t v
)
10530 dout(10) << "got missing " << oid
<< " v " << v
<< dendl
;
10531 pg_log
.recover_got(oid
, v
, info
);
10532 if (pg_log
.get_log().complete_to
!= pg_log
.get_log().log
.end()) {
10533 dout(10) << "last_complete now " << info
.last_complete
10534 << " log.complete_to " << pg_log
.get_log().complete_to
->version
10537 dout(10) << "last_complete now " << info
.last_complete
10538 << " log.complete_to at end" << dendl
;
10539 //below is not true in the repair case.
10540 //assert(missing.num_missing() == 0); // otherwise, complete_to was wrong.
10541 assert(info
.last_complete
== info
.last_update
);
10545 void PrimaryLogPG::primary_failed(const hobject_t
&soid
)
10547 list
<pg_shard_t
> fl
= { pg_whoami
};
10548 failed_push(fl
, soid
);
10551 void PrimaryLogPG::failed_push(const list
<pg_shard_t
> &from
, const hobject_t
&soid
)
10553 dout(20) << __func__
<< ": " << soid
<< dendl
;
10554 assert(recovering
.count(soid
));
10555 auto obc
= recovering
[soid
];
10557 list
<OpRequestRef
> blocked_ops
;
10558 obc
->drop_recovery_read(&blocked_ops
);
10559 requeue_ops(blocked_ops
);
10561 recovering
.erase(soid
);
10562 for (auto&& i
: from
)
10563 missing_loc
.remove_location(soid
, i
);
10564 dout(0) << __func__
<< " " << soid
<< " from shard " << from
10565 << ", reps on " << missing_loc
.get_locations(soid
)
10566 << " unfound? " << missing_loc
.is_unfound(soid
) << dendl
;
10567 finish_recovery_op(soid
); // close out this attempt,
10570 void PrimaryLogPG::sub_op_remove(OpRequestRef op
)
10572 const MOSDSubOp
*m
= static_cast<const MOSDSubOp
*>(op
->get_req());
10573 assert(m
->get_type() == MSG_OSD_SUBOP
);
10574 dout(7) << "sub_op_remove " << m
->poid
<< dendl
;
10576 op
->mark_started();
10578 ObjectStore::Transaction t
;
10579 remove_snap_mapped_object(t
, m
->poid
);
10580 int r
= osd
->store
->queue_transaction(osr
.get(), std::move(t
), NULL
);
10584 eversion_t
PrimaryLogPG::pick_newest_available(const hobject_t
& oid
)
10587 pg_missing_item pmi
;
10588 bool is_missing
= pg_log
.get_missing().is_missing(oid
, &pmi
);
10589 assert(is_missing
);
10591 dout(10) << "pick_newest_available " << oid
<< " " << v
<< " on osd." << osd
->whoami
<< " (local)" << dendl
;
10593 assert(!actingbackfill
.empty());
10594 for (set
<pg_shard_t
>::iterator i
= actingbackfill
.begin();
10595 i
!= actingbackfill
.end();
10597 if (*i
== get_primary()) continue;
10598 pg_shard_t peer
= *i
;
10599 if (!peer_missing
[peer
].is_missing(oid
)) {
10602 eversion_t h
= peer_missing
[peer
].get_items().at(oid
).have
;
10603 dout(10) << "pick_newest_available " << oid
<< " " << h
<< " on osd." << peer
<< dendl
;
10608 dout(10) << "pick_newest_available " << oid
<< " " << v
<< " (newest)" << dendl
;
10612 void PrimaryLogPG::do_update_log_missing(OpRequestRef
&op
)
10614 const MOSDPGUpdateLogMissing
*m
= static_cast<const MOSDPGUpdateLogMissing
*>(
10616 assert(m
->get_type() == MSG_OSD_PG_UPDATE_LOG_MISSING
);
10617 ObjectStore::Transaction t
;
10618 append_log_entries_update_missing(m
->entries
, t
);
10620 Context
*complete
= new FunctionContext(
10622 const MOSDPGUpdateLogMissing
*msg
= static_cast<const MOSDPGUpdateLogMissing
*>(
10625 if (!pg_has_reset_since(msg
->get_epoch())) {
10626 MOSDPGUpdateLogMissingReply
*reply
=
10627 new MOSDPGUpdateLogMissingReply(
10628 spg_t(info
.pgid
.pgid
, primary_shard().shard
),
10633 reply
->set_priority(CEPH_MSG_PRIO_HIGH
);
10634 msg
->get_connection()->send_message(reply
);
10639 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
10640 t
.register_on_commit(complete
);
10642 /* Hack to work around the fact that ReplicatedBackend sends
10643 * ack+commit if commit happens first
10645 * This behavior is no longer necessary, but we preserve it so old
10646 * primaries can keep their repops in order */
10647 if (pool
.info
.ec_pool()) {
10648 t
.register_on_complete(complete
);
10650 t
.register_on_commit(complete
);
10653 t
.register_on_applied(
10654 new C_OSD_OnApplied
{this, get_osdmap()->get_epoch(), info
.last_update
});
10655 int tr
= osd
->store
->queue_transaction(
10662 void PrimaryLogPG::do_update_log_missing_reply(OpRequestRef
&op
)
10664 const MOSDPGUpdateLogMissingReply
*m
=
10665 static_cast<const MOSDPGUpdateLogMissingReply
*>(
10667 dout(20) << __func__
<< " got reply from "
10668 << m
->get_from() << dendl
;
10670 auto it
= log_entry_update_waiting_on
.find(m
->get_tid());
10671 if (it
!= log_entry_update_waiting_on
.end()) {
10672 if (it
->second
.waiting_on
.count(m
->get_from())) {
10673 it
->second
.waiting_on
.erase(m
->get_from());
10676 << info
.pgid
<< " got reply "
10677 << *m
<< " from shard we are not waiting for "
10681 if (it
->second
.waiting_on
.empty()) {
10682 repop_all_committed(it
->second
.repop
.get());
10683 log_entry_update_waiting_on
.erase(it
);
10687 << info
.pgid
<< " got reply "
10688 << *m
<< " on unknown tid " << m
->get_tid();
10692 /* Mark all unfound objects as lost.
10694 void PrimaryLogPG::mark_all_unfound_lost(
10699 dout(3) << __func__
<< " " << pg_log_entry_t::get_op_name(what
) << dendl
;
10700 list
<hobject_t
> oids
;
10702 dout(30) << __func__
<< ": log before:\n";
10703 pg_log
.get_log().print(*_dout
);
10706 mempool::osd_pglog::list
<pg_log_entry_t
> log_entries
;
10708 utime_t mtime
= ceph_clock_now();
10709 map
<hobject_t
, pg_missing_item
>::const_iterator m
=
10710 missing_loc
.get_needs_recovery().begin();
10711 map
<hobject_t
, pg_missing_item
>::const_iterator mend
=
10712 missing_loc
.get_needs_recovery().end();
10714 ObcLockManager manager
;
10715 eversion_t v
= get_next_version();
10716 v
.epoch
= get_osdmap()->get_epoch();
10717 uint64_t num_unfound
= missing_loc
.num_unfound();
10718 while (m
!= mend
) {
10719 const hobject_t
&oid(m
->first
);
10720 if (!missing_loc
.is_unfound(oid
)) {
10721 // We only care about unfound objects
10726 ObjectContextRef obc
;
10730 case pg_log_entry_t::LOST_MARK
:
10731 assert(0 == "actually, not implemented yet!");
10734 case pg_log_entry_t::LOST_REVERT
:
10735 prev
= pick_newest_available(oid
);
10736 if (prev
> eversion_t()) {
10739 pg_log_entry_t::LOST_REVERT
, oid
, v
,
10740 m
->second
.need
, 0, osd_reqid_t(), mtime
, 0);
10741 e
.reverting_to
= prev
;
10742 e
.mark_unrollbackable();
10743 log_entries
.push_back(e
);
10744 dout(10) << e
<< dendl
;
10746 // we are now missing the new version; recovery code will sort it out.
10752 case pg_log_entry_t::LOST_DELETE
:
10754 pg_log_entry_t
e(pg_log_entry_t::LOST_DELETE
, oid
, v
, m
->second
.need
,
10755 0, osd_reqid_t(), mtime
, 0);
10756 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_JEWEL
) {
10757 if (pool
.info
.require_rollback()) {
10758 e
.mod_desc
.try_rmobject(v
.version
);
10760 e
.mark_unrollbackable();
10762 } // otherwise, just do what we used to do
10763 dout(10) << e
<< dendl
;
10764 log_entries
.push_back(e
);
10765 oids
.push_back(oid
);
10777 info
.stats
.stats_invalid
= true;
10779 submit_log_entries(
10781 std::move(manager
),
10782 boost::optional
<std::function
<void(void)> >(
10783 [this, oids
, con
, num_unfound
, tid
]() {
10784 if (perform_deletes_during_peering()) {
10785 for (auto oid
: oids
) {
10786 // clear old locations - merge_new_log_entries will have
10787 // handled rebuilding missing_loc for each of these
10788 // objects if we have the RECOVERY_DELETES flag
10789 missing_loc
.recovered(oid
);
10793 for (auto& p
: waiting_for_unreadable_object
) {
10794 release_backoffs(p
.first
);
10796 requeue_object_waiters(waiting_for_unreadable_object
);
10800 ss
<< "pg has " << num_unfound
10801 << " objects unfound and apparently lost marking";
10802 string rs
= ss
.str();
10803 dout(0) << "do_command r=" << 0 << " " << rs
<< dendl
;
10804 osd
->clog
->info() << rs
;
10806 MCommandReply
*reply
= new MCommandReply(0, rs
);
10807 reply
->set_tid(tid
);
10808 con
->send_message(reply
);
10814 void PrimaryLogPG::_split_into(pg_t child_pgid
, PG
*child
, unsigned split_bits
)
10816 assert(repop_queue
.empty());
10820 * pg status change notification
10823 void PrimaryLogPG::apply_and_flush_repops(bool requeue
)
10825 list
<OpRequestRef
> rq
;
10827 // apply all repops
10828 while (!repop_queue
.empty()) {
10829 RepGather
*repop
= repop_queue
.front();
10830 repop_queue
.pop_front();
10831 dout(10) << " canceling repop tid " << repop
->rep_tid
<< dendl
;
10832 repop
->rep_aborted
= true;
10833 repop
->on_applied
.clear();
10834 repop
->on_committed
.clear();
10835 repop
->on_success
.clear();
10839 dout(10) << " requeuing " << *repop
->op
->get_req() << dendl
;
10840 rq
.push_back(repop
->op
);
10841 repop
->op
= OpRequestRef();
10844 // also requeue any dups, interleaved into position
10845 map
<eversion_t
, list
<pair
<OpRequestRef
, version_t
> > >::iterator p
=
10846 waiting_for_ondisk
.find(repop
->v
);
10847 if (p
!= waiting_for_ondisk
.end()) {
10848 dout(10) << " also requeuing ondisk waiters " << p
->second
<< dendl
;
10849 for (list
<pair
<OpRequestRef
, version_t
> >::iterator i
=
10851 i
!= p
->second
.end();
10853 rq
.push_back(i
->first
);
10855 waiting_for_ondisk
.erase(p
);
10859 remove_repop(repop
);
10862 assert(repop_queue
.empty());
10866 if (!waiting_for_ondisk
.empty()) {
10867 for (map
<eversion_t
, list
<pair
<OpRequestRef
, version_t
> > >::iterator i
=
10868 waiting_for_ondisk
.begin();
10869 i
!= waiting_for_ondisk
.end();
10871 for (list
<pair
<OpRequestRef
, version_t
> >::iterator j
=
10873 j
!= i
->second
.end();
10875 derr
<< __func__
<< ": op " << *(j
->first
->get_req()) << " waiting on "
10876 << i
->first
<< dendl
;
10879 assert(waiting_for_ondisk
.empty());
10883 waiting_for_ondisk
.clear();
10886 void PrimaryLogPG::on_flushed()
10888 assert(flushes_in_progress
> 0);
10889 flushes_in_progress
--;
10890 if (flushes_in_progress
== 0) {
10891 requeue_ops(waiting_for_peered
);
10893 if (!is_peered() || !is_primary()) {
10894 pair
<hobject_t
, ObjectContextRef
> i
;
10895 while (object_contexts
.get_next(i
.first
, &i
)) {
10896 derr
<< "on_flushed: object " << i
.first
<< " obc still alive" << dendl
;
10898 assert(object_contexts
.empty());
10900 pgbackend
->on_flushed();
10903 void PrimaryLogPG::on_removal(ObjectStore::Transaction
*t
)
10905 dout(10) << "on_removal" << dendl
;
10907 // adjust info to backfill
10908 info
.set_last_backfill(hobject_t());
10909 pg_log
.reset_backfill();
10914 PGLogEntryHandler rollbacker
{this, t
};
10915 pg_log
.roll_forward(&rollbacker
);
10917 write_if_dirty(*t
);
10923 void PrimaryLogPG::clear_async_reads()
10925 dout(10) << __func__
<< dendl
;
10926 for(auto& i
: in_progress_async_reads
) {
10927 dout(10) << "clear ctx: "
10928 << "OpRequestRef " << i
.first
10929 << " OpContext " << i
.second
10931 close_op_ctx(i
.second
);
10935 void PrimaryLogPG::on_shutdown()
10937 dout(10) << "on_shutdown" << dendl
;
10939 // remove from queues
10940 osd
->pg_stat_queue_dequeue(this);
10941 osd
->peering_wq
.dequeue(this);
10943 // handles queue races
10946 if (recovery_queued
) {
10947 recovery_queued
= false;
10948 osd
->clear_queued_recovery(this);
10951 clear_scrub_reserved();
10952 scrub_clear_state();
10954 unreg_next_scrub();
10955 cancel_copy_ops(false);
10956 cancel_flush_ops(false);
10957 cancel_proxy_ops(false);
10958 apply_and_flush_repops(false);
10959 cancel_log_updates();
10960 // we must remove PGRefs, so do this this prior to release_backoffs() callers
10962 // clean up snap trim references
10963 snap_trimmer_machine
.process_event(Reset());
10965 pgbackend
->on_change();
10967 context_registry_on_change();
10968 object_contexts
.clear();
10970 clear_async_reads();
10972 osd
->remote_reserver
.cancel_reservation(info
.pgid
);
10973 osd
->local_reserver
.cancel_reservation(info
.pgid
);
10975 clear_primary_state();
10979 void PrimaryLogPG::on_activate()
10982 if (needs_recovery()) {
10983 dout(10) << "activate not all replicas are up-to-date, queueing recovery" << dendl
;
10984 queue_peering_event(
10986 std::make_shared
<CephPeeringEvt
>(
10987 get_osdmap()->get_epoch(),
10988 get_osdmap()->get_epoch(),
10990 } else if (needs_backfill()) {
10991 dout(10) << "activate queueing backfill" << dendl
;
10992 queue_peering_event(
10994 std::make_shared
<CephPeeringEvt
>(
10995 get_osdmap()->get_epoch(),
10996 get_osdmap()->get_epoch(),
10997 RequestBackfill())));
10999 dout(10) << "activate all replicas clean, no recovery" << dendl
;
11000 eio_errors_to_process
= false;
11001 queue_peering_event(
11003 std::make_shared
<CephPeeringEvt
>(
11004 get_osdmap()->get_epoch(),
11005 get_osdmap()->get_epoch(),
11006 AllReplicasRecovered())));
11009 publish_stats_to_osd();
11011 if (!backfill_targets
.empty()) {
11012 last_backfill_started
= earliest_backfill();
11013 new_backfill
= true;
11014 assert(!last_backfill_started
.is_max());
11015 dout(5) << "on activate: bft=" << backfill_targets
11016 << " from " << last_backfill_started
<< dendl
;
11017 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11018 i
!= backfill_targets
.end();
11020 dout(5) << "target shard " << *i
11021 << " from " << peer_info
[*i
].last_backfill
11030 void PrimaryLogPG::_on_new_interval()
11032 dout(20) << __func__
<< "checking missing set deletes flag. missing = " << pg_log
.get_missing() << dendl
;
11033 if (!pg_log
.get_missing().may_include_deletes
&&
11034 get_osdmap()->test_flag(CEPH_OSDMAP_RECOVERY_DELETES
)) {
11035 pg_log
.rebuild_missing_set_with_deletes(osd
->store
, coll
, info
);
11037 assert(pg_log
.get_missing().may_include_deletes
== get_osdmap()->test_flag(CEPH_OSDMAP_RECOVERY_DELETES
));
11040 void PrimaryLogPG::on_change(ObjectStore::Transaction
*t
)
11042 dout(10) << "on_change" << dendl
;
11044 if (hit_set
&& hit_set
->insert_count() == 0) {
11045 dout(20) << " discarding empty hit_set" << dendl
;
11049 if (recovery_queued
) {
11050 recovery_queued
= false;
11051 osd
->clear_queued_recovery(this);
11054 // requeue everything in the reverse order they should be
11056 requeue_ops(waiting_for_peered
);
11057 requeue_ops(waiting_for_active
);
11059 clear_scrub_reserved();
11061 cancel_copy_ops(is_primary());
11062 cancel_flush_ops(is_primary());
11063 cancel_proxy_ops(is_primary());
11065 // requeue object waiters
11066 for (auto& p
: waiting_for_unreadable_object
) {
11067 release_backoffs(p
.first
);
11069 if (is_primary()) {
11070 requeue_object_waiters(waiting_for_unreadable_object
);
11072 waiting_for_unreadable_object
.clear();
11074 for (map
<hobject_t
,list
<OpRequestRef
>>::iterator p
= waiting_for_degraded_object
.begin();
11075 p
!= waiting_for_degraded_object
.end();
11076 waiting_for_degraded_object
.erase(p
++)) {
11077 release_backoffs(p
->first
);
11079 requeue_ops(p
->second
);
11082 finish_degraded_object(p
->first
);
11085 // requeues waiting_for_scrub
11086 scrub_clear_state();
11088 for (auto p
= waiting_for_blocked_object
.begin();
11089 p
!= waiting_for_blocked_object
.end();
11090 waiting_for_blocked_object
.erase(p
++)) {
11092 requeue_ops(p
->second
);
11096 for (auto i
= callbacks_for_degraded_object
.begin();
11097 i
!= callbacks_for_degraded_object
.end();
11099 finish_degraded_object((i
++)->first
);
11101 assert(callbacks_for_degraded_object
.empty());
11103 if (is_primary()) {
11104 requeue_ops(waiting_for_cache_not_full
);
11106 waiting_for_cache_not_full
.clear();
11108 objects_blocked_on_cache_full
.clear();
11110 for (list
<pair
<OpRequestRef
, OpContext
*> >::iterator i
=
11111 in_progress_async_reads
.begin();
11112 i
!= in_progress_async_reads
.end();
11113 in_progress_async_reads
.erase(i
++)) {
11114 close_op_ctx(i
->second
);
11116 requeue_op(i
->first
);
11119 // this will requeue ops we were working on but didn't finish, and
11121 apply_and_flush_repops(is_primary());
11122 cancel_log_updates();
11124 // do this *after* apply_and_flush_repops so that we catch any newly
11125 // registered watches.
11126 context_registry_on_change();
11128 pgbackend
->on_change_cleanup(t
);
11129 scrubber
.cleanup_store(t
);
11130 pgbackend
->on_change();
11132 // clear snap_trimmer state
11133 snap_trimmer_machine
.process_event(Reset());
11135 debug_op_order
.clear();
11136 unstable_stats
.clear();
11138 // we don't want to cache object_contexts through the interval change
11139 // NOTE: we actually assert that all currently live references are dead
11140 // by the time the flush for the next interval completes.
11141 object_contexts
.clear();
11143 // should have been cleared above by finishing all of the degraded objects
11144 assert(objects_blocked_on_degraded_snap
.empty());
11147 void PrimaryLogPG::on_role_change()
11149 dout(10) << "on_role_change" << dendl
;
11150 if (get_role() != 0 && hit_set
) {
11151 dout(10) << " clearing hit set" << dendl
;
11156 void PrimaryLogPG::on_pool_change()
11158 dout(10) << __func__
<< dendl
;
11159 // requeue cache full waiters just in case the cache_mode is
11160 // changing away from writeback mode. note that if we are not
11161 // active the normal requeuing machinery is sufficient (and properly
11164 pool
.info
.cache_mode
!= pg_pool_t::CACHEMODE_WRITEBACK
&&
11165 !waiting_for_cache_not_full
.empty()) {
11166 dout(10) << __func__
<< " requeuing full waiters (not in writeback) "
11168 requeue_ops(waiting_for_cache_not_full
);
11169 objects_blocked_on_cache_full
.clear();
11175 // clear state. called on recovery completion AND cancellation.
11176 void PrimaryLogPG::_clear_recovery_state()
11178 missing_loc
.clear();
11179 #ifdef DEBUG_RECOVERY_OIDS
11180 recovering_oids
.clear();
11182 last_backfill_started
= hobject_t();
11183 set
<hobject_t
>::iterator i
= backfills_in_flight
.begin();
11184 while (i
!= backfills_in_flight
.end()) {
11185 assert(recovering
.count(*i
));
11186 backfills_in_flight
.erase(i
++);
11189 list
<OpRequestRef
> blocked_ops
;
11190 for (map
<hobject_t
, ObjectContextRef
>::iterator i
= recovering
.begin();
11191 i
!= recovering
.end();
11192 recovering
.erase(i
++)) {
11194 i
->second
->drop_recovery_read(&blocked_ops
);
11195 requeue_ops(blocked_ops
);
11198 assert(backfills_in_flight
.empty());
11199 pending_backfill_updates
.clear();
11200 assert(recovering
.empty());
11201 pgbackend
->clear_recovery_state();
11204 void PrimaryLogPG::cancel_pull(const hobject_t
&soid
)
11206 dout(20) << __func__
<< ": " << soid
<< dendl
;
11207 assert(recovering
.count(soid
));
11208 ObjectContextRef obc
= recovering
[soid
];
11210 list
<OpRequestRef
> blocked_ops
;
11211 obc
->drop_recovery_read(&blocked_ops
);
11212 requeue_ops(blocked_ops
);
11214 recovering
.erase(soid
);
11215 finish_recovery_op(soid
);
11216 release_backoffs(soid
);
11217 if (waiting_for_degraded_object
.count(soid
)) {
11218 dout(20) << " kicking degraded waiters on " << soid
<< dendl
;
11219 requeue_ops(waiting_for_degraded_object
[soid
]);
11220 waiting_for_degraded_object
.erase(soid
);
11222 if (waiting_for_unreadable_object
.count(soid
)) {
11223 dout(20) << " kicking unreadable waiters on " << soid
<< dendl
;
11224 requeue_ops(waiting_for_unreadable_object
[soid
]);
11225 waiting_for_unreadable_object
.erase(soid
);
11227 if (is_missing_object(soid
))
11228 pg_log
.set_last_requested(0); // get recover_primary to start over
11229 finish_degraded_object(soid
);
11232 void PrimaryLogPG::check_recovery_sources(const OSDMapRef
& osdmap
)
11235 * check that any peers we are planning to (or currently) pulling
11236 * objects from are dealt with.
11238 missing_loc
.check_recovery_sources(osdmap
);
11239 pgbackend
->check_recovery_sources(osdmap
);
11241 for (set
<pg_shard_t
>::iterator i
= peer_log_requested
.begin();
11242 i
!= peer_log_requested
.end();
11244 if (!osdmap
->is_up(i
->osd
)) {
11245 dout(10) << "peer_log_requested removing " << *i
<< dendl
;
11246 peer_log_requested
.erase(i
++);
11252 for (set
<pg_shard_t
>::iterator i
= peer_missing_requested
.begin();
11253 i
!= peer_missing_requested
.end();
11255 if (!osdmap
->is_up(i
->osd
)) {
11256 dout(10) << "peer_missing_requested removing " << *i
<< dendl
;
11257 peer_missing_requested
.erase(i
++);
11264 void PG::MissingLoc::check_recovery_sources(const OSDMapRef
& osdmap
)
11266 set
<pg_shard_t
> now_down
;
11267 for (set
<pg_shard_t
>::iterator p
= missing_loc_sources
.begin();
11268 p
!= missing_loc_sources
.end();
11270 if (osdmap
->is_up(p
->osd
)) {
11274 ldout(pg
->cct
, 10) << "check_recovery_sources source osd." << *p
<< " now down" << dendl
;
11275 now_down
.insert(*p
);
11276 missing_loc_sources
.erase(p
++);
11279 if (now_down
.empty()) {
11280 ldout(pg
->cct
, 10) << "check_recovery_sources no source osds (" << missing_loc_sources
<< ") went down" << dendl
;
11282 ldout(pg
->cct
, 10) << "check_recovery_sources sources osds " << now_down
<< " now down, remaining sources are "
11283 << missing_loc_sources
<< dendl
;
11285 // filter missing_loc
11286 map
<hobject_t
, set
<pg_shard_t
>>::iterator p
= missing_loc
.begin();
11287 while (p
!= missing_loc
.end()) {
11288 set
<pg_shard_t
>::iterator q
= p
->second
.begin();
11289 while (q
!= p
->second
.end())
11290 if (now_down
.count(*q
)) {
11291 p
->second
.erase(q
++);
11295 if (p
->second
.empty())
11296 missing_loc
.erase(p
++);
11304 bool PrimaryLogPG::start_recovery_ops(
11306 ThreadPool::TPHandle
&handle
,
11307 uint64_t *ops_started
)
11309 uint64_t& started
= *ops_started
;
11311 bool work_in_progress
= false;
11312 assert(is_primary());
11314 if (!state_test(PG_STATE_RECOVERING
) &&
11315 !state_test(PG_STATE_BACKFILL
)) {
11316 /* TODO: I think this case is broken and will make do_recovery()
11317 * unhappy since we're returning false */
11318 dout(10) << "recovery raced and were queued twice, ignoring!" << dendl
;
11322 const auto &missing
= pg_log
.get_missing();
11324 unsigned int num_missing
= missing
.num_missing();
11325 uint64_t num_unfound
= get_num_unfound();
11327 if (num_missing
== 0) {
11328 info
.last_complete
= info
.last_update
;
11331 if (num_missing
== num_unfound
) {
11332 // All of the missing objects we have are unfound.
11333 // Recover the replicas.
11334 started
= recover_replicas(max
, handle
);
11337 // We still have missing objects that we should grab from replicas.
11338 started
+= recover_primary(max
, handle
);
11340 if (!started
&& num_unfound
!= get_num_unfound()) {
11341 // second chance to recovery replicas
11342 started
= recover_replicas(max
, handle
);
11346 work_in_progress
= true;
11348 bool deferred_backfill
= false;
11349 if (recovering
.empty() &&
11350 state_test(PG_STATE_BACKFILL
) &&
11351 !backfill_targets
.empty() && started
< max
&&
11352 missing
.num_missing() == 0 &&
11353 waiting_on_backfill
.empty()) {
11354 if (get_osdmap()->test_flag(CEPH_OSDMAP_NOBACKFILL
)) {
11355 dout(10) << "deferring backfill due to NOBACKFILL" << dendl
;
11356 deferred_backfill
= true;
11357 } else if (get_osdmap()->test_flag(CEPH_OSDMAP_NOREBALANCE
) &&
11359 dout(10) << "deferring backfill due to NOREBALANCE" << dendl
;
11360 deferred_backfill
= true;
11361 } else if (!backfill_reserved
) {
11362 dout(10) << "deferring backfill due to !backfill_reserved" << dendl
;
11363 if (!backfill_reserving
) {
11364 dout(10) << "queueing RequestBackfill" << dendl
;
11365 backfill_reserving
= true;
11366 queue_peering_event(
11368 std::make_shared
<CephPeeringEvt
>(
11369 get_osdmap()->get_epoch(),
11370 get_osdmap()->get_epoch(),
11371 RequestBackfill())));
11373 deferred_backfill
= true;
11375 started
+= recover_backfill(max
- started
, handle
, &work_in_progress
);
11379 dout(10) << " started " << started
<< dendl
;
11380 osd
->logger
->inc(l_osd_rop
, started
);
11382 if (!recovering
.empty() ||
11383 work_in_progress
|| recovery_ops_active
> 0 || deferred_backfill
)
11384 return work_in_progress
;
11386 assert(recovering
.empty());
11387 assert(recovery_ops_active
== 0);
11389 dout(10) << __func__
<< " needs_recovery: "
11390 << missing_loc
.get_needs_recovery()
11392 dout(10) << __func__
<< " missing_loc: "
11393 << missing_loc
.get_missing_locs()
11395 int unfound
= get_num_unfound();
11397 dout(10) << " still have " << unfound
<< " unfound" << dendl
;
11398 return work_in_progress
;
11401 if (missing
.num_missing() > 0) {
11402 // this shouldn't happen!
11403 osd
->clog
->error() << info
.pgid
<< " Unexpected Error: recovery ending with "
11404 << missing
.num_missing() << ": " << missing
.get_items();
11405 return work_in_progress
;
11408 if (needs_recovery()) {
11409 // this shouldn't happen!
11410 // We already checked num_missing() so we must have missing replicas
11411 osd
->clog
->error() << info
.pgid
11412 << " Unexpected Error: recovery ending with missing replicas";
11413 return work_in_progress
;
11416 if (state_test(PG_STATE_RECOVERING
)) {
11417 state_clear(PG_STATE_RECOVERING
);
11418 state_clear(PG_STATE_FORCED_RECOVERY
);
11419 if (needs_backfill()) {
11420 dout(10) << "recovery done, queuing backfill" << dendl
;
11421 queue_peering_event(
11423 std::make_shared
<CephPeeringEvt
>(
11424 get_osdmap()->get_epoch(),
11425 get_osdmap()->get_epoch(),
11426 RequestBackfill())));
11428 dout(10) << "recovery done, no backfill" << dendl
;
11429 eio_errors_to_process
= false;
11430 state_clear(PG_STATE_FORCED_BACKFILL
);
11431 queue_peering_event(
11433 std::make_shared
<CephPeeringEvt
>(
11434 get_osdmap()->get_epoch(),
11435 get_osdmap()->get_epoch(),
11436 AllReplicasRecovered())));
11438 } else { // backfilling
11439 state_clear(PG_STATE_BACKFILL
);
11440 state_clear(PG_STATE_FORCED_BACKFILL
);
11441 state_clear(PG_STATE_FORCED_RECOVERY
);
11442 dout(10) << "recovery done, backfill done" << dendl
;
11443 eio_errors_to_process
= false;
11444 queue_peering_event(
11446 std::make_shared
<CephPeeringEvt
>(
11447 get_osdmap()->get_epoch(),
11448 get_osdmap()->get_epoch(),
11456 * do one recovery op.
11457 * return true if done, false if nothing left to do.
11459 uint64_t PrimaryLogPG::recover_primary(uint64_t max
, ThreadPool::TPHandle
&handle
)
11461 assert(is_primary());
11463 const auto &missing
= pg_log
.get_missing();
11465 dout(10) << "recover_primary recovering " << recovering
.size()
11466 << " in pg" << dendl
;
11467 dout(10) << "recover_primary " << missing
<< dendl
;
11468 dout(25) << "recover_primary " << missing
.get_items() << dendl
;
11471 pg_log_entry_t
*latest
= 0;
11472 unsigned started
= 0;
11475 PGBackend::RecoveryHandle
*h
= pgbackend
->open_recovery_op();
11476 map
<version_t
, hobject_t
>::const_iterator p
=
11477 missing
.get_rmissing().lower_bound(pg_log
.get_log().last_requested
);
11478 while (p
!= missing
.get_rmissing().end()) {
11479 handle
.reset_tp_timeout();
11481 version_t v
= p
->first
;
11483 if (pg_log
.get_log().objects
.count(p
->second
)) {
11484 latest
= pg_log
.get_log().objects
.find(p
->second
)->second
;
11485 assert(latest
->is_update() || latest
->is_delete());
11486 soid
= latest
->soid
;
11491 const pg_missing_item
& item
= missing
.get_items().find(p
->second
)->second
;
11494 hobject_t head
= soid
.get_head();
11496 eversion_t need
= item
.need
;
11498 dout(10) << "recover_primary "
11499 << soid
<< " " << item
.need
11500 << (missing
.is_missing(soid
) ? " (missing)":"")
11501 << (missing
.is_missing(head
) ? " (missing head)":"")
11502 << (recovering
.count(soid
) ? " (recovering)":"")
11503 << (recovering
.count(head
) ? " (recovering head)":"")
11507 switch (latest
->op
) {
11508 case pg_log_entry_t::CLONE
:
11510 * Handling for this special case removed for now, until we
11511 * can correctly construct an accurate SnapSet from the old
11516 case pg_log_entry_t::LOST_REVERT
:
11518 if (item
.have
== latest
->reverting_to
) {
11519 ObjectContextRef obc
= get_object_context(soid
, true);
11521 if (obc
->obs
.oi
.version
== latest
->version
) {
11522 // I'm already reverting
11523 dout(10) << " already reverting " << soid
<< dendl
;
11525 dout(10) << " reverting " << soid
<< " to " << latest
->prior_version
<< dendl
;
11526 obc
->ondisk_write_lock();
11527 obc
->obs
.oi
.version
= latest
->version
;
11529 ObjectStore::Transaction t
;
11531 obc
->obs
.oi
.encode(
11533 get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
11534 assert(!pool
.info
.require_rollback());
11535 t
.setattr(coll
, ghobject_t(soid
), OI_ATTR
, b2
);
11537 recover_got(soid
, latest
->version
);
11538 missing_loc
.add_location(soid
, pg_whoami
);
11542 osd
->store
->queue_transaction(osr
.get(), std::move(t
),
11543 new C_OSD_AppliedRecoveredObject(this, obc
),
11544 new C_OSD_CommittedPushedObject(
11546 get_osdmap()->get_epoch(),
11547 info
.last_complete
),
11548 new C_OSD_OndiskWriteUnlock(obc
));
11553 * Pull the old version of the object. Update missing_loc here to have the location
11554 * of the version we want.
11556 * This doesn't use the usual missing_loc paths, but that's okay:
11557 * - if we have it locally, we hit the case above, and go from there.
11558 * - if we don't, we always pass through this case during recovery and set up the location
11560 * - this way we don't need to mangle the missing code to be general about needing an old
11563 eversion_t alternate_need
= latest
->reverting_to
;
11564 dout(10) << " need to pull prior_version " << alternate_need
<< " for revert " << item
<< dendl
;
11566 for (map
<pg_shard_t
, pg_missing_t
>::iterator p
= peer_missing
.begin();
11567 p
!= peer_missing
.end();
11569 if (p
->second
.is_missing(soid
, need
) &&
11570 p
->second
.get_items().at(soid
).have
== alternate_need
) {
11571 missing_loc
.add_location(soid
, p
->first
);
11573 dout(10) << " will pull " << alternate_need
<< " or " << need
11574 << " from one of " << missing_loc
.get_locations(soid
)
11582 if (!recovering
.count(soid
)) {
11583 if (recovering
.count(head
)) {
11586 int r
= recover_missing(
11587 soid
, need
, get_recovery_op_priority(), h
);
11600 if (started
>= max
)
11605 // only advance last_requested if we haven't skipped anything
11607 pg_log
.set_last_requested(v
);
11610 pgbackend
->run_recovery_op(h
, get_recovery_op_priority());
11614 bool PrimaryLogPG::primary_error(
11615 const hobject_t
& soid
, eversion_t v
)
11617 pg_log
.missing_add(soid
, v
, eversion_t());
11618 pg_log
.set_last_requested(0);
11619 missing_loc
.remove_location(soid
, pg_whoami
);
11621 assert(!actingbackfill
.empty());
11622 for (set
<pg_shard_t
>::iterator i
= actingbackfill
.begin();
11623 i
!= actingbackfill
.end();
11625 if (*i
== get_primary()) continue;
11626 pg_shard_t peer
= *i
;
11627 if (!peer_missing
[peer
].is_missing(soid
, v
)) {
11628 missing_loc
.add_location(soid
, peer
);
11629 dout(10) << info
.pgid
<< " unexpectedly missing " << soid
<< " v" << v
11630 << ", there should be a copy on shard " << peer
<< dendl
;
11635 osd
->clog
->error() << info
.pgid
<< " missing primary copy of " << soid
<< ", unfound";
11637 osd
->clog
->error() << info
.pgid
<< " missing primary copy of " << soid
11638 << ", will try copies on " << missing_loc
.get_locations(soid
);
11642 int PrimaryLogPG::prep_object_replica_deletes(
11643 const hobject_t
& soid
, eversion_t v
,
11644 PGBackend::RecoveryHandle
*h
)
11646 assert(is_primary());
11647 dout(10) << __func__
<< ": on " << soid
<< dendl
;
11649 start_recovery_op(soid
);
11650 assert(!recovering
.count(soid
));
11651 recovering
.insert(make_pair(soid
, ObjectContextRef()));
11653 pgbackend
->recover_delete_object(soid
, v
, h
);
11657 int PrimaryLogPG::prep_object_replica_pushes(
11658 const hobject_t
& soid
, eversion_t v
,
11659 PGBackend::RecoveryHandle
*h
)
11661 assert(is_primary());
11662 dout(10) << __func__
<< ": on " << soid
<< dendl
;
11664 // NOTE: we know we will get a valid oloc off of disk here.
11665 ObjectContextRef obc
= get_object_context(soid
, false);
11667 primary_error(soid
, v
);
11671 if (!obc
->get_recovery_read()) {
11672 dout(20) << "recovery delayed on " << soid
11673 << "; could not get rw_manager lock" << dendl
;
11676 dout(20) << "recovery got recovery read lock on " << soid
11680 start_recovery_op(soid
);
11681 assert(!recovering
.count(soid
));
11682 recovering
.insert(make_pair(soid
, obc
));
11684 /* We need this in case there is an in progress write on the object. In fact,
11685 * the only possible write is an update to the xattr due to a lost_revert --
11686 * a client write would be blocked since the object is degraded.
11687 * In almost all cases, therefore, this lock should be uncontended.
11689 obc
->ondisk_read_lock();
11690 int r
= pgbackend
->recover_object(
11693 ObjectContextRef(),
11694 obc
, // has snapset context
11696 obc
->ondisk_read_unlock();
11698 dout(0) << __func__
<< " Error " << r
<< " on oid " << soid
<< dendl
;
11699 primary_failed(soid
);
11700 primary_error(soid
, v
);
11706 uint64_t PrimaryLogPG::recover_replicas(uint64_t max
, ThreadPool::TPHandle
&handle
)
11708 dout(10) << __func__
<< "(" << max
<< ")" << dendl
;
11709 uint64_t started
= 0;
11711 PGBackend::RecoveryHandle
*h
= pgbackend
->open_recovery_op();
11713 // this is FAR from an optimal recovery order. pretty lame, really.
11714 assert(!actingbackfill
.empty());
11715 for (set
<pg_shard_t
>::iterator i
= actingbackfill
.begin();
11716 i
!= actingbackfill
.end();
11718 if (*i
== get_primary()) continue;
11719 pg_shard_t peer
= *i
;
11720 map
<pg_shard_t
, pg_missing_t
>::const_iterator pm
= peer_missing
.find(peer
);
11721 assert(pm
!= peer_missing
.end());
11722 map
<pg_shard_t
, pg_info_t
>::const_iterator pi
= peer_info
.find(peer
);
11723 assert(pi
!= peer_info
.end());
11724 size_t m_sz
= pm
->second
.num_missing();
11726 dout(10) << " peer osd." << peer
<< " missing " << m_sz
<< " objects." << dendl
;
11727 dout(20) << " peer osd." << peer
<< " missing " << pm
->second
.get_items() << dendl
;
11730 const pg_missing_t
&m(pm
->second
);
11731 for (map
<version_t
, hobject_t
>::const_iterator p
= m
.get_rmissing().begin();
11732 p
!= m
.get_rmissing().end() && started
< max
;
11734 handle
.reset_tp_timeout();
11735 const hobject_t
soid(p
->second
);
11737 if (missing_loc
.is_unfound(soid
)) {
11738 dout(10) << __func__
<< ": " << soid
<< " still unfound" << dendl
;
11742 if (soid
> pi
->second
.last_backfill
) {
11743 if (!recovering
.count(soid
)) {
11744 derr
<< __func__
<< ": object " << soid
<< " last_backfill " << pi
->second
.last_backfill
<< dendl
;
11745 derr
<< __func__
<< ": object added to missing set for backfill, but "
11746 << "is not in recovering, error!" << dendl
;
11752 if (recovering
.count(soid
)) {
11753 dout(10) << __func__
<< ": already recovering " << soid
<< dendl
;
11757 if (missing_loc
.is_deleted(soid
)) {
11758 dout(10) << __func__
<< ": " << soid
<< " is a delete, removing" << dendl
;
11759 map
<hobject_t
,pg_missing_item
>::const_iterator r
= m
.get_items().find(soid
);
11760 started
+= prep_object_replica_deletes(soid
, r
->second
.need
, h
);
11764 if (soid
.is_snap() && pg_log
.get_missing().is_missing(soid
.get_head())) {
11765 dout(10) << __func__
<< ": " << soid
.get_head()
11766 << " still missing on primary" << dendl
;
11770 if (soid
.is_snap() && pg_log
.get_missing().is_missing(soid
.get_snapdir())) {
11771 dout(10) << __func__
<< ": " << soid
.get_snapdir()
11772 << " still missing on primary" << dendl
;
11776 if (pg_log
.get_missing().is_missing(soid
)) {
11777 dout(10) << __func__
<< ": " << soid
<< " still missing on primary" << dendl
;
11781 dout(10) << __func__
<< ": recover_object_replicas(" << soid
<< ")" << dendl
;
11782 map
<hobject_t
,pg_missing_item
>::const_iterator r
= m
.get_items().find(soid
);
11783 started
+= prep_object_replica_pushes(soid
, r
->second
.need
,
11788 pgbackend
->run_recovery_op(h
, get_recovery_op_priority());
11792 hobject_t
PrimaryLogPG::earliest_peer_backfill() const
11794 hobject_t e
= hobject_t::get_max();
11795 for (set
<pg_shard_t
>::const_iterator i
= backfill_targets
.begin();
11796 i
!= backfill_targets
.end();
11798 pg_shard_t peer
= *i
;
11799 map
<pg_shard_t
, BackfillInterval
>::const_iterator iter
=
11800 peer_backfill_info
.find(peer
);
11801 assert(iter
!= peer_backfill_info
.end());
11802 if (iter
->second
.begin
< e
)
11803 e
= iter
->second
.begin
;
11808 bool PrimaryLogPG::all_peer_done() const
11810 // Primary hasn't got any more objects
11811 assert(backfill_info
.empty());
11813 for (set
<pg_shard_t
>::const_iterator i
= backfill_targets
.begin();
11814 i
!= backfill_targets
.end();
11816 pg_shard_t bt
= *i
;
11817 map
<pg_shard_t
, BackfillInterval
>::const_iterator piter
=
11818 peer_backfill_info
.find(bt
);
11819 assert(piter
!= peer_backfill_info
.end());
11820 const BackfillInterval
& pbi
= piter
->second
;
11821 // See if peer has more to process
11822 if (!pbi
.extends_to_end() || !pbi
.empty())
11833 * backfilled: fully pushed to replica or present in replica's missing set (both
11834 * our copy and theirs).
11836 * All objects on a backfill_target in
11837 * [MIN,peer_backfill_info[backfill_target].begin) are valid; logically-removed
11838 * objects have been actually deleted and all logically-valid objects are replicated.
11839 * There may be PG objects in this interval yet to be backfilled.
11841 * All objects in PG in [MIN,backfill_info.begin) have been backfilled to all
11842 * backfill_targets. There may be objects on backfill_target(s) yet to be deleted.
11844 * For a backfill target, all objects < MIN(peer_backfill_info[target].begin,
11845 * backfill_info.begin) in PG are backfilled. No deleted objects in this
11846 * interval remain on the backfill target.
11848 * For a backfill target, all objects <= peer_info[target].last_backfill
11849 * have been backfilled to target
11851 * There *MAY* be missing/outdated objects between last_backfill_started and
11852 * MIN(peer_backfill_info[*].begin, backfill_info.begin) in the event that client
11853 * io created objects since the last scan. For this reason, we call
11854 * update_range() again before continuing backfill.
11856 uint64_t PrimaryLogPG::recover_backfill(
11858 ThreadPool::TPHandle
&handle
, bool *work_started
)
11860 dout(10) << "recover_backfill (" << max
<< ")"
11861 << " bft=" << backfill_targets
11862 << " last_backfill_started " << last_backfill_started
11863 << (new_backfill
? " new_backfill":"")
11865 assert(!backfill_targets
.empty());
11867 // Initialize from prior backfill state
11868 if (new_backfill
) {
11869 // on_activate() was called prior to getting here
11870 assert(last_backfill_started
== earliest_backfill());
11871 new_backfill
= false;
11873 // initialize BackfillIntervals
11874 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11875 i
!= backfill_targets
.end();
11877 peer_backfill_info
[*i
].reset(peer_info
[*i
].last_backfill
);
11879 backfill_info
.reset(last_backfill_started
);
11881 backfills_in_flight
.clear();
11882 pending_backfill_updates
.clear();
11885 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11886 i
!= backfill_targets
.end();
11888 dout(10) << "peer osd." << *i
11889 << " info " << peer_info
[*i
]
11890 << " interval " << peer_backfill_info
[*i
].begin
11891 << "-" << peer_backfill_info
[*i
].end
11892 << " " << peer_backfill_info
[*i
].objects
.size() << " objects"
11896 // update our local interval to cope with recent changes
11897 backfill_info
.begin
= last_backfill_started
;
11898 update_range(&backfill_info
, handle
);
11901 vector
<boost::tuple
<hobject_t
, eversion_t
, pg_shard_t
> > to_remove
;
11902 set
<hobject_t
> add_to_stat
;
11904 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11905 i
!= backfill_targets
.end();
11907 peer_backfill_info
[*i
].trim_to(
11908 std::max(peer_info
[*i
].last_backfill
, last_backfill_started
));
11910 backfill_info
.trim_to(last_backfill_started
);
11912 PGBackend::RecoveryHandle
*h
= pgbackend
->open_recovery_op();
11913 while (ops
< max
) {
11914 if (backfill_info
.begin
<= earliest_peer_backfill() &&
11915 !backfill_info
.extends_to_end() && backfill_info
.empty()) {
11916 hobject_t next
= backfill_info
.end
;
11917 backfill_info
.reset(next
);
11918 backfill_info
.end
= hobject_t::get_max();
11919 update_range(&backfill_info
, handle
);
11920 backfill_info
.trim();
11923 dout(20) << " my backfill interval " << backfill_info
<< dendl
;
11925 bool sent_scan
= false;
11926 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11927 i
!= backfill_targets
.end();
11929 pg_shard_t bt
= *i
;
11930 BackfillInterval
& pbi
= peer_backfill_info
[bt
];
11932 dout(20) << " peer shard " << bt
<< " backfill " << pbi
<< dendl
;
11933 if (pbi
.begin
<= backfill_info
.begin
&&
11934 !pbi
.extends_to_end() && pbi
.empty()) {
11935 dout(10) << " scanning peer osd." << bt
<< " from " << pbi
.end
<< dendl
;
11936 epoch_t e
= get_osdmap()->get_epoch();
11937 MOSDPGScan
*m
= new MOSDPGScan(
11938 MOSDPGScan::OP_SCAN_GET_DIGEST
, pg_whoami
, e
, last_peering_reset
,
11939 spg_t(info
.pgid
.pgid
, bt
.shard
),
11940 pbi
.end
, hobject_t());
11941 osd
->send_message_osd_cluster(bt
.osd
, m
, get_osdmap()->get_epoch());
11942 assert(waiting_on_backfill
.find(bt
) == waiting_on_backfill
.end());
11943 waiting_on_backfill
.insert(bt
);
11948 // Count simultaneous scans as a single op and let those complete
11951 start_recovery_op(hobject_t::get_max()); // XXX: was pbi.end
11955 if (backfill_info
.empty() && all_peer_done()) {
11956 dout(10) << " reached end for both local and all peers" << dendl
;
11960 // Get object within set of peers to operate on and
11961 // the set of targets for which that object applies.
11962 hobject_t check
= earliest_peer_backfill();
11964 if (check
< backfill_info
.begin
) {
11966 set
<pg_shard_t
> check_targets
;
11967 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11968 i
!= backfill_targets
.end();
11970 pg_shard_t bt
= *i
;
11971 BackfillInterval
& pbi
= peer_backfill_info
[bt
];
11972 if (pbi
.begin
== check
)
11973 check_targets
.insert(bt
);
11975 assert(!check_targets
.empty());
11977 dout(20) << " BACKFILL removing " << check
11978 << " from peers " << check_targets
<< dendl
;
11979 for (set
<pg_shard_t
>::iterator i
= check_targets
.begin();
11980 i
!= check_targets
.end();
11982 pg_shard_t bt
= *i
;
11983 BackfillInterval
& pbi
= peer_backfill_info
[bt
];
11984 assert(pbi
.begin
== check
);
11986 to_remove
.push_back(boost::make_tuple(check
, pbi
.objects
.begin()->second
, bt
));
11990 /* This requires a bit of explanation. We compare head against
11991 * last_backfill to determine whether to send an operation
11992 * to the replica. A single write operation can touch up to three
11993 * objects: head, the snapdir, and a new clone which sorts closer to
11994 * head than any existing clone. If last_backfill points at a clone,
11995 * the transaction won't be sent and all 3 must lie on the right side
11996 * of the line (i.e., we'll backfill them later). If last_backfill
11997 * points at snapdir, it sorts greater than head, so we send the
11998 * transaction which is correct because all three must lie to the left
12001 * If it points at head, we have a bit of an issue. If head actually
12002 * exists, no problem, because any transaction which touches snapdir
12003 * must end up creating it (and deleting head), so sending the
12004 * operation won't pose a problem -- we'll end up having to scan it,
12005 * but it'll end up being the right version so we won't bother to
12006 * rebackfill it. However, if head doesn't exist, any write on head
12007 * will remove snapdir. For a replicated pool, this isn't a problem,
12008 * ENOENT on remove isn't an issue and it's in backfill future anyway.
12009 * It only poses a problem for EC pools, because we never just delete
12010 * an object, we rename it into a rollback object. That operation
12011 * will end up crashing the osd with ENOENT. Tolerating the failure
12012 * wouldn't work either, even if snapdir exists, we'd be creating a
12013 * rollback object past the last_backfill line which wouldn't get
12014 * cleaned up (no rollback objects past the last_backfill line is an
12015 * existing important invariant). Thus, let's avoid the whole issue
12016 * by just not updating last_backfill_started here if head doesn't
12017 * exist and snapdir does. We aren't using up a recovery count here,
12018 * so we're going to recover snapdir immediately anyway. We'll only
12019 * fail "backward" if we fail to get the rw lock and that just means
12020 * we'll re-process this section of the hash space again.
12022 * I'm choosing this hack here because the really "correct" answer is
12023 * going to be to unify snapdir and head into a single object (a
12024 * snapdir is really just a confusing way to talk about head existing
12025 * as a whiteout), but doing that is going to be a somewhat larger
12028 * @see http://tracker.ceph.com/issues/17668
12030 if (!(check
.is_head() &&
12031 backfill_info
.begin
.is_snapdir() &&
12032 check
== backfill_info
.begin
.get_head()))
12033 last_backfill_started
= check
;
12035 // Don't increment ops here because deletions
12036 // are cheap and not replied to unlike real recovery_ops,
12037 // and we can't increment ops without requeueing ourself
12040 eversion_t
& obj_v
= backfill_info
.objects
.begin()->second
;
12042 vector
<pg_shard_t
> need_ver_targs
, missing_targs
, keep_ver_targs
, skip_targs
;
12043 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
12044 i
!= backfill_targets
.end();
12046 pg_shard_t bt
= *i
;
12047 BackfillInterval
& pbi
= peer_backfill_info
[bt
];
12048 // Find all check peers that have the wrong version
12049 if (check
== backfill_info
.begin
&& check
== pbi
.begin
) {
12050 if (pbi
.objects
.begin()->second
!= obj_v
) {
12051 need_ver_targs
.push_back(bt
);
12053 keep_ver_targs
.push_back(bt
);
12056 pg_info_t
& pinfo
= peer_info
[bt
];
12058 // Only include peers that we've caught up to their backfill line
12059 // otherwise, they only appear to be missing this object
12060 // because their pbi.begin > backfill_info.begin.
12061 if (backfill_info
.begin
> pinfo
.last_backfill
)
12062 missing_targs
.push_back(bt
);
12064 skip_targs
.push_back(bt
);
12068 if (!keep_ver_targs
.empty()) {
12069 // These peers have version obj_v
12070 dout(20) << " BACKFILL keeping " << check
12071 << " with ver " << obj_v
12072 << " on peers " << keep_ver_targs
<< dendl
;
12073 //assert(!waiting_for_degraded_object.count(check));
12075 if (!need_ver_targs
.empty() || !missing_targs
.empty()) {
12076 ObjectContextRef obc
= get_object_context(backfill_info
.begin
, false);
12078 if (obc
->get_recovery_read()) {
12079 if (!need_ver_targs
.empty()) {
12080 dout(20) << " BACKFILL replacing " << check
12081 << " with ver " << obj_v
12082 << " to peers " << need_ver_targs
<< dendl
;
12084 if (!missing_targs
.empty()) {
12085 dout(20) << " BACKFILL pushing " << backfill_info
.begin
12086 << " with ver " << obj_v
12087 << " to peers " << missing_targs
<< dendl
;
12089 vector
<pg_shard_t
> all_push
= need_ver_targs
;
12090 all_push
.insert(all_push
.end(), missing_targs
.begin(), missing_targs
.end());
12092 handle
.reset_tp_timeout();
12093 int r
= prep_backfill_object_push(backfill_info
.begin
, obj_v
, obc
, all_push
, h
);
12095 *work_started
= true;
12096 dout(0) << __func__
<< " Error " << r
<< " trying to backfill " << backfill_info
.begin
<< dendl
;
12101 *work_started
= true;
12102 dout(20) << "backfill blocking on " << backfill_info
.begin
12103 << "; could not get rw_manager lock" << dendl
;
12107 dout(20) << "need_ver_targs=" << need_ver_targs
12108 << " keep_ver_targs=" << keep_ver_targs
<< dendl
;
12109 dout(20) << "backfill_targets=" << backfill_targets
12110 << " missing_targs=" << missing_targs
12111 << " skip_targs=" << skip_targs
<< dendl
;
12113 last_backfill_started
= backfill_info
.begin
;
12114 add_to_stat
.insert(backfill_info
.begin
); // XXX: Only one for all pushes?
12115 backfill_info
.pop_front();
12116 vector
<pg_shard_t
> check_targets
= need_ver_targs
;
12117 check_targets
.insert(check_targets
.end(), keep_ver_targs
.begin(), keep_ver_targs
.end());
12118 for (vector
<pg_shard_t
>::iterator i
= check_targets
.begin();
12119 i
!= check_targets
.end();
12121 pg_shard_t bt
= *i
;
12122 BackfillInterval
& pbi
= peer_backfill_info
[bt
];
12128 hobject_t backfill_pos
=
12129 std::min(backfill_info
.begin
, earliest_peer_backfill());
12131 for (set
<hobject_t
>::iterator i
= add_to_stat
.begin();
12132 i
!= add_to_stat
.end();
12134 ObjectContextRef obc
= get_object_context(*i
, false);
12137 add_object_context_to_pg_stat(obc
, &stat
);
12138 pending_backfill_updates
[*i
] = stat
;
12140 if (HAVE_FEATURE(get_min_upacting_features(), SERVER_LUMINOUS
)) {
12141 map
<pg_shard_t
,MOSDPGBackfillRemove
*> reqs
;
12142 for (unsigned i
= 0; i
< to_remove
.size(); ++i
) {
12143 handle
.reset_tp_timeout();
12144 const hobject_t
& oid
= to_remove
[i
].get
<0>();
12145 eversion_t v
= to_remove
[i
].get
<1>();
12146 pg_shard_t peer
= to_remove
[i
].get
<2>();
12147 MOSDPGBackfillRemove
*m
;
12148 auto it
= reqs
.find(peer
);
12149 if (it
!= reqs
.end()) {
12152 m
= reqs
[peer
] = new MOSDPGBackfillRemove(
12153 spg_t(info
.pgid
.pgid
, peer
.shard
),
12154 get_osdmap()->get_epoch());
12156 m
->ls
.push_back(make_pair(oid
, v
));
12158 if (oid
<= last_backfill_started
)
12159 pending_backfill_updates
[oid
]; // add empty stat!
12161 for (auto p
: reqs
) {
12162 osd
->send_message_osd_cluster(p
.first
.osd
, p
.second
,
12163 get_osdmap()->get_epoch());
12166 // for jewel targets
12167 for (unsigned i
= 0; i
< to_remove
.size(); ++i
) {
12168 handle
.reset_tp_timeout();
12170 // ordered before any subsequent updates
12171 send_remove_op(to_remove
[i
].get
<0>(), to_remove
[i
].get
<1>(),
12172 to_remove
[i
].get
<2>());
12174 if (to_remove
[i
].get
<0>() <= last_backfill_started
)
12175 pending_backfill_updates
[to_remove
[i
].get
<0>()]; // add empty stat!
12179 pgbackend
->run_recovery_op(h
, get_recovery_op_priority());
12181 dout(5) << "backfill_pos is " << backfill_pos
<< dendl
;
12182 for (set
<hobject_t
>::iterator i
= backfills_in_flight
.begin();
12183 i
!= backfills_in_flight
.end();
12185 dout(20) << *i
<< " is still in flight" << dendl
;
12188 hobject_t next_backfill_to_complete
= backfills_in_flight
.empty() ?
12189 backfill_pos
: *(backfills_in_flight
.begin());
12190 hobject_t new_last_backfill
= earliest_backfill();
12191 dout(10) << "starting new_last_backfill at " << new_last_backfill
<< dendl
;
12192 for (map
<hobject_t
, pg_stat_t
>::iterator i
=
12193 pending_backfill_updates
.begin();
12194 i
!= pending_backfill_updates
.end() &&
12195 i
->first
< next_backfill_to_complete
;
12196 pending_backfill_updates
.erase(i
++)) {
12197 dout(20) << " pending_backfill_update " << i
->first
<< dendl
;
12198 assert(i
->first
> new_last_backfill
);
12199 for (set
<pg_shard_t
>::iterator j
= backfill_targets
.begin();
12200 j
!= backfill_targets
.end();
12202 pg_shard_t bt
= *j
;
12203 pg_info_t
& pinfo
= peer_info
[bt
];
12204 //Add stats to all peers that were missing object
12205 if (i
->first
> pinfo
.last_backfill
)
12206 pinfo
.stats
.add(i
->second
);
12208 new_last_backfill
= i
->first
;
12210 dout(10) << "possible new_last_backfill at " << new_last_backfill
<< dendl
;
12212 assert(!pending_backfill_updates
.empty() ||
12213 new_last_backfill
== last_backfill_started
);
12214 if (pending_backfill_updates
.empty() &&
12215 backfill_pos
.is_max()) {
12216 assert(backfills_in_flight
.empty());
12217 new_last_backfill
= backfill_pos
;
12218 last_backfill_started
= backfill_pos
;
12220 dout(10) << "final new_last_backfill at " << new_last_backfill
<< dendl
;
12222 // If new_last_backfill == MAX, then we will send OP_BACKFILL_FINISH to
12223 // all the backfill targets. Otherwise, we will move last_backfill up on
12224 // those targets need it and send OP_BACKFILL_PROGRESS to them.
12225 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
12226 i
!= backfill_targets
.end();
12228 pg_shard_t bt
= *i
;
12229 pg_info_t
& pinfo
= peer_info
[bt
];
12231 if (new_last_backfill
> pinfo
.last_backfill
) {
12232 pinfo
.set_last_backfill(new_last_backfill
);
12233 epoch_t e
= get_osdmap()->get_epoch();
12234 MOSDPGBackfill
*m
= NULL
;
12235 if (pinfo
.last_backfill
.is_max()) {
12236 m
= new MOSDPGBackfill(
12237 MOSDPGBackfill::OP_BACKFILL_FINISH
,
12239 last_peering_reset
,
12240 spg_t(info
.pgid
.pgid
, bt
.shard
));
12241 // Use default priority here, must match sub_op priority
12242 /* pinfo.stats might be wrong if we did log-based recovery on the
12243 * backfilled portion in addition to continuing backfill.
12245 pinfo
.stats
= info
.stats
;
12246 start_recovery_op(hobject_t::get_max());
12248 m
= new MOSDPGBackfill(
12249 MOSDPGBackfill::OP_BACKFILL_PROGRESS
,
12251 last_peering_reset
,
12252 spg_t(info
.pgid
.pgid
, bt
.shard
));
12253 // Use default priority here, must match sub_op priority
12255 m
->last_backfill
= pinfo
.last_backfill
;
12256 m
->stats
= pinfo
.stats
;
12257 osd
->send_message_osd_cluster(bt
.osd
, m
, get_osdmap()->get_epoch());
12258 dout(10) << " peer " << bt
12259 << " num_objects now " << pinfo
.stats
.stats
.sum
.num_objects
12260 << " / " << info
.stats
.stats
.sum
.num_objects
<< dendl
;
12265 *work_started
= true;
12269 int PrimaryLogPG::prep_backfill_object_push(
12270 hobject_t oid
, eversion_t v
,
12271 ObjectContextRef obc
,
12272 vector
<pg_shard_t
> peers
,
12273 PGBackend::RecoveryHandle
*h
)
12275 dout(10) << __func__
<< " " << oid
<< " v " << v
<< " to peers " << peers
<< dendl
;
12276 assert(!peers
.empty());
12278 backfills_in_flight
.insert(oid
);
12279 for (unsigned int i
= 0 ; i
< peers
.size(); ++i
) {
12280 map
<pg_shard_t
, pg_missing_t
>::iterator bpm
= peer_missing
.find(peers
[i
]);
12281 assert(bpm
!= peer_missing
.end());
12282 bpm
->second
.add(oid
, eversion_t(), eversion_t(), false);
12285 assert(!recovering
.count(oid
));
12287 start_recovery_op(oid
);
12288 recovering
.insert(make_pair(oid
, obc
));
12290 // We need to take the read_lock here in order to flush in-progress writes
12291 obc
->ondisk_read_lock();
12292 int r
= pgbackend
->recover_object(
12295 ObjectContextRef(),
12298 obc
->ondisk_read_unlock();
12300 dout(0) << __func__
<< " Error " << r
<< " on oid " << oid
<< dendl
;
12301 primary_failed(oid
);
12302 primary_error(oid
, v
);
12303 backfills_in_flight
.erase(oid
);
12304 missing_loc
.add_missing(oid
, v
, eversion_t());
12309 void PrimaryLogPG::update_range(
12310 BackfillInterval
*bi
,
12311 ThreadPool::TPHandle
&handle
)
12313 int local_min
= cct
->_conf
->osd_backfill_scan_min
;
12314 int local_max
= cct
->_conf
->osd_backfill_scan_max
;
12316 if (bi
->version
< info
.log_tail
) {
12317 dout(10) << __func__
<< ": bi is old, rescanning local backfill_info"
12319 if (last_update_applied
>= info
.log_tail
) {
12320 bi
->version
= last_update_applied
;
12323 bi
->version
= info
.last_update
;
12325 scan_range(local_min
, local_max
, bi
, handle
);
12328 if (bi
->version
>= projected_last_update
) {
12329 dout(10) << __func__
<< ": bi is current " << dendl
;
12330 assert(bi
->version
== projected_last_update
);
12331 } else if (bi
->version
>= info
.log_tail
) {
12332 if (pg_log
.get_log().empty() && projected_log
.empty()) {
12333 /* Because we don't move log_tail on split, the log might be
12334 * empty even if log_tail != last_update. However, the only
12335 * way to get here with an empty log is if log_tail is actually
12336 * eversion_t(), because otherwise the entry which changed
12337 * last_update since the last scan would have to be present.
12339 assert(bi
->version
== eversion_t());
12343 dout(10) << __func__
<< ": bi is old, (" << bi
->version
12344 << ") can be updated with log to projected_last_update "
12345 << projected_last_update
<< dendl
;
12347 auto func
= [&](const pg_log_entry_t
&e
) {
12348 dout(10) << __func__
<< ": updating from version " << e
.version
12350 const hobject_t
&soid
= e
.soid
;
12351 if (soid
>= bi
->begin
&&
12353 if (e
.is_update()) {
12354 dout(10) << __func__
<< ": " << e
.soid
<< " updated to version "
12355 << e
.version
<< dendl
;
12356 bi
->objects
.erase(e
.soid
);
12357 bi
->objects
.insert(
12361 } else if (e
.is_delete()) {
12362 dout(10) << __func__
<< ": " << e
.soid
<< " removed" << dendl
;
12363 bi
->objects
.erase(e
.soid
);
12367 dout(10) << "scanning pg log first" << dendl
;
12368 pg_log
.get_log().scan_log_after(bi
->version
, func
);
12369 dout(10) << "scanning projected log" << dendl
;
12370 projected_log
.scan_log_after(bi
->version
, func
);
12371 bi
->version
= projected_last_update
;
12373 assert(0 == "scan_range should have raised bi->version past log_tail");
12377 void PrimaryLogPG::scan_range(
12378 int min
, int max
, BackfillInterval
*bi
,
12379 ThreadPool::TPHandle
&handle
)
12381 assert(is_locked());
12382 dout(10) << "scan_range from " << bi
->begin
<< dendl
;
12383 bi
->clear_objects();
12385 vector
<hobject_t
> ls
;
12387 int r
= pgbackend
->objects_list_partial(bi
->begin
, min
, max
, &ls
, &bi
->end
);
12389 dout(10) << " got " << ls
.size() << " items, next " << bi
->end
<< dendl
;
12390 dout(20) << ls
<< dendl
;
12392 for (vector
<hobject_t
>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
) {
12393 handle
.reset_tp_timeout();
12394 ObjectContextRef obc
;
12396 obc
= object_contexts
.lookup(*p
);
12398 bi
->objects
[*p
] = obc
->obs
.oi
.version
;
12399 dout(20) << " " << *p
<< " " << obc
->obs
.oi
.version
<< dendl
;
12402 int r
= pgbackend
->objects_get_attr(*p
, OI_ATTR
, &bl
);
12404 /* If the object does not exist here, it must have been removed
12405 * between the collection_list_partial and here. This can happen
12406 * for the first item in the range, which is usually last_backfill.
12412 object_info_t
oi(bl
);
12413 bi
->objects
[*p
] = oi
.version
;
12414 dout(20) << " " << *p
<< " " << oi
.version
<< dendl
;
12422 * verifies that stray objects have been deleted
12424 void PrimaryLogPG::check_local()
12426 dout(10) << __func__
<< dendl
;
12428 assert(info
.last_update
>= pg_log
.get_tail()); // otherwise we need some help!
12430 if (!cct
->_conf
->osd_debug_verify_stray_on_activate
)
12433 // just scan the log.
12434 set
<hobject_t
> did
;
12435 for (list
<pg_log_entry_t
>::const_reverse_iterator p
= pg_log
.get_log().log
.rbegin();
12436 p
!= pg_log
.get_log().log
.rend();
12438 if (did
.count(p
->soid
))
12440 did
.insert(p
->soid
);
12442 if (p
->is_delete() && !is_missing_object(p
->soid
)) {
12443 dout(10) << " checking " << p
->soid
12444 << " at " << p
->version
<< dendl
;
12446 int r
= osd
->store
->stat(
12448 ghobject_t(p
->soid
, ghobject_t::NO_GEN
, pg_whoami
.shard
),
12450 if (r
!= -ENOENT
) {
12451 derr
<< __func__
<< " " << p
->soid
<< " exists, but should have been "
12452 << "deleted" << dendl
;
12453 assert(0 == "erroneously present object");
12456 // ignore old(+missing) objects
12463 // ===========================
12466 hobject_t
PrimaryLogPG::get_hit_set_current_object(utime_t stamp
)
12469 ss
<< "hit_set_" << info
.pgid
.pgid
<< "_current_" << stamp
;
12470 hobject_t
hoid(sobject_t(ss
.str(), CEPH_NOSNAP
), "",
12471 info
.pgid
.ps(), info
.pgid
.pool(),
12472 cct
->_conf
->osd_hit_set_namespace
);
12473 dout(20) << __func__
<< " " << hoid
<< dendl
;
12477 hobject_t
PrimaryLogPG::get_hit_set_archive_object(utime_t start
,
12482 ss
<< "hit_set_" << info
.pgid
.pgid
<< "_archive_";
12484 start
.gmtime(ss
) << "_";
12487 start
.localtime(ss
) << "_";
12490 hobject_t
hoid(sobject_t(ss
.str(), CEPH_NOSNAP
), "",
12491 info
.pgid
.ps(), info
.pgid
.pool(),
12492 cct
->_conf
->osd_hit_set_namespace
);
12493 dout(20) << __func__
<< " " << hoid
<< dendl
;
12497 void PrimaryLogPG::hit_set_clear()
12499 dout(20) << __func__
<< dendl
;
12501 hit_set_start_stamp
= utime_t();
12504 void PrimaryLogPG::hit_set_setup()
12506 if (!is_active() ||
12512 if (is_active() && is_primary() &&
12513 (!pool
.info
.hit_set_count
||
12514 !pool
.info
.hit_set_period
||
12515 pool
.info
.hit_set_params
.get_type() == HitSet::TYPE_NONE
)) {
12518 // only primary is allowed to remove all the hit set objects
12519 hit_set_remove_all();
12523 // FIXME: discard any previous data for now
12526 // include any writes we know about from the pg log. this doesn't
12527 // capture reads, but it is better than nothing!
12528 hit_set_apply_log();
12531 void PrimaryLogPG::hit_set_remove_all()
12533 // If any archives are degraded we skip this
12534 for (list
<pg_hit_set_info_t
>::iterator p
= info
.hit_set
.history
.begin();
12535 p
!= info
.hit_set
.history
.end();
12537 hobject_t aoid
= get_hit_set_archive_object(p
->begin
, p
->end
, p
->using_gmt
);
12539 // Once we hit a degraded object just skip
12540 if (is_degraded_or_backfilling_object(aoid
))
12542 if (scrubber
.write_blocked_by_scrub(aoid
))
12546 if (!info
.hit_set
.history
.empty()) {
12547 list
<pg_hit_set_info_t
>::reverse_iterator p
= info
.hit_set
.history
.rbegin();
12548 assert(p
!= info
.hit_set
.history
.rend());
12549 hobject_t oid
= get_hit_set_archive_object(p
->begin
, p
->end
, p
->using_gmt
);
12550 assert(!is_degraded_or_backfilling_object(oid
));
12551 ObjectContextRef obc
= get_object_context(oid
, false);
12554 OpContextUPtr ctx
= simple_opc_create(obc
);
12555 ctx
->at_version
= get_next_version();
12556 ctx
->updated_hset_history
= info
.hit_set
;
12557 utime_t now
= ceph_clock_now();
12559 hit_set_trim(ctx
, 0);
12560 simple_opc_submit(std::move(ctx
));
12563 info
.hit_set
= pg_hit_set_history_t();
12565 agent_state
->discard_hit_sets();
12569 void PrimaryLogPG::hit_set_create()
12571 utime_t now
= ceph_clock_now();
12572 // make a copy of the params to modify
12573 HitSet::Params
params(pool
.info
.hit_set_params
);
12575 dout(20) << __func__
<< " " << params
<< dendl
;
12576 if (pool
.info
.hit_set_params
.get_type() == HitSet::TYPE_BLOOM
) {
12577 BloomHitSet::Params
*p
=
12578 static_cast<BloomHitSet::Params
*>(params
.impl
.get());
12580 // convert false positive rate so it holds up across the full period
12581 p
->set_fpp(p
->get_fpp() / pool
.info
.hit_set_count
);
12582 if (p
->get_fpp() <= 0.0)
12583 p
->set_fpp(.01); // fpp cannot be zero!
12585 // if we don't have specified size, estimate target size based on the
12587 if (p
->target_size
== 0 && hit_set
) {
12588 utime_t dur
= now
- hit_set_start_stamp
;
12589 unsigned unique
= hit_set
->approx_unique_insert_count();
12590 dout(20) << __func__
<< " previous set had approx " << unique
12591 << " unique items over " << dur
<< " seconds" << dendl
;
12592 p
->target_size
= (double)unique
* (double)pool
.info
.hit_set_period
12595 if (p
->target_size
<
12596 static_cast<uint64_t>(cct
->_conf
->osd_hit_set_min_size
))
12597 p
->target_size
= cct
->_conf
->osd_hit_set_min_size
;
12600 > static_cast<uint64_t>(cct
->_conf
->osd_hit_set_max_size
))
12601 p
->target_size
= cct
->_conf
->osd_hit_set_max_size
;
12603 p
->seed
= now
.sec();
12605 dout(10) << __func__
<< " target_size " << p
->target_size
12606 << " fpp " << p
->get_fpp() << dendl
;
12608 hit_set
.reset(new HitSet(params
));
12609 hit_set_start_stamp
= now
;
12613 * apply log entries to set
12615 * this would only happen after peering, to at least capture writes
12616 * during an interval that was potentially lost.
12618 bool PrimaryLogPG::hit_set_apply_log()
12623 eversion_t to
= info
.last_update
;
12624 eversion_t from
= info
.hit_set
.current_last_update
;
12626 dout(20) << __func__
<< " no update" << dendl
;
12630 dout(20) << __func__
<< " " << to
<< " .. " << info
.last_update
<< dendl
;
12631 list
<pg_log_entry_t
>::const_reverse_iterator p
= pg_log
.get_log().log
.rbegin();
12632 while (p
!= pg_log
.get_log().log
.rend() && p
->version
> to
)
12634 while (p
!= pg_log
.get_log().log
.rend() && p
->version
> from
) {
12635 hit_set
->insert(p
->soid
);
12642 void PrimaryLogPG::hit_set_persist()
12644 dout(10) << __func__
<< dendl
;
12646 unsigned max
= pool
.info
.hit_set_count
;
12648 utime_t now
= ceph_clock_now();
12651 // If any archives are degraded we skip this persist request
12652 // account for the additional entry being added below
12653 for (list
<pg_hit_set_info_t
>::iterator p
= info
.hit_set
.history
.begin();
12654 p
!= info
.hit_set
.history
.end();
12656 hobject_t aoid
= get_hit_set_archive_object(p
->begin
, p
->end
, p
->using_gmt
);
12658 // Once we hit a degraded object just skip further trim
12659 if (is_degraded_or_backfilling_object(aoid
))
12661 if (scrubber
.write_blocked_by_scrub(aoid
))
12665 // If backfill is in progress and we could possibly overlap with the
12666 // hit_set_* objects, back off. Since these all have
12667 // hobject_t::hash set to pgid.ps(), and those sort first, we can
12668 // look just at that. This is necessary because our transactions
12669 // may include a modify of the new hit_set *and* a delete of the
12670 // old one, and this may span the backfill boundary.
12671 for (set
<pg_shard_t
>::iterator p
= backfill_targets
.begin();
12672 p
!= backfill_targets
.end();
12674 assert(peer_info
.count(*p
));
12675 const pg_info_t
& pi
= peer_info
[*p
];
12676 if (pi
.last_backfill
== hobject_t() ||
12677 pi
.last_backfill
.get_hash() == info
.pgid
.ps()) {
12678 dout(10) << __func__
<< " backfill target osd." << *p
12679 << " last_backfill has not progressed past pgid ps"
12686 pg_hit_set_info_t new_hset
= pg_hit_set_info_t(pool
.info
.use_gmt_hitset
);
12687 new_hset
.begin
= hit_set_start_stamp
;
12688 new_hset
.end
= now
;
12689 oid
= get_hit_set_archive_object(
12692 new_hset
.using_gmt
);
12694 // If the current object is degraded we skip this persist request
12695 if (scrubber
.write_blocked_by_scrub(oid
))
12699 ::encode(*hit_set
, bl
);
12700 dout(20) << __func__
<< " archive " << oid
<< dendl
;
12703 agent_state
->add_hit_set(new_hset
.begin
, hit_set
);
12704 uint32_t size
= agent_state
->hit_set_map
.size();
12705 if (size
>= pool
.info
.hit_set_count
) {
12706 size
= pool
.info
.hit_set_count
> 0 ? pool
.info
.hit_set_count
- 1: 0;
12708 hit_set_in_memory_trim(size
);
12711 ObjectContextRef obc
= get_object_context(oid
, true);
12712 OpContextUPtr ctx
= simple_opc_create(obc
);
12714 ctx
->at_version
= get_next_version();
12715 ctx
->updated_hset_history
= info
.hit_set
;
12716 pg_hit_set_history_t
&updated_hit_set_hist
= *(ctx
->updated_hset_history
);
12718 updated_hit_set_hist
.current_last_update
= info
.last_update
;
12719 new_hset
.version
= ctx
->at_version
;
12721 updated_hit_set_hist
.history
.push_back(new_hset
);
12724 // fabricate an object_info_t and SnapSet
12725 obc
->obs
.oi
.version
= ctx
->at_version
;
12726 obc
->obs
.oi
.mtime
= now
;
12727 obc
->obs
.oi
.size
= bl
.length();
12728 obc
->obs
.exists
= true;
12729 obc
->obs
.oi
.set_data_digest(bl
.crc32c(-1));
12731 ctx
->new_obs
= obc
->obs
;
12733 obc
->ssc
->snapset
.head_exists
= true;
12734 ctx
->new_snapset
= obc
->ssc
->snapset
;
12736 ctx
->delta_stats
.num_objects
++;
12737 ctx
->delta_stats
.num_objects_hit_set_archive
++;
12738 ctx
->delta_stats
.num_bytes
+= bl
.length();
12739 ctx
->delta_stats
.num_bytes_hit_set_archive
+= bl
.length();
12742 ::encode(ctx
->new_snapset
, bss
);
12743 bufferlist
boi(sizeof(ctx
->new_obs
.oi
));
12744 ::encode(ctx
->new_obs
.oi
, boi
,
12745 get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
12747 ctx
->op_t
->create(oid
);
12749 ctx
->op_t
->write(oid
, 0, bl
.length(), bl
, 0);
12751 map
<string
, bufferlist
> attrs
;
12752 attrs
[OI_ATTR
].claim(boi
);
12753 attrs
[SS_ATTR
].claim(bss
);
12754 setattrs_maybe_cache(ctx
->obc
, ctx
.get(), ctx
->op_t
.get(), attrs
);
12755 ctx
->log
.push_back(
12757 pg_log_entry_t::MODIFY
,
12767 hit_set_trim(ctx
, max
);
12769 simple_opc_submit(std::move(ctx
));
12772 void PrimaryLogPG::hit_set_trim(OpContextUPtr
&ctx
, unsigned max
)
12774 assert(ctx
->updated_hset_history
);
12775 pg_hit_set_history_t
&updated_hit_set_hist
=
12776 *(ctx
->updated_hset_history
);
12777 for (unsigned num
= updated_hit_set_hist
.history
.size(); num
> max
; --num
) {
12778 list
<pg_hit_set_info_t
>::iterator p
= updated_hit_set_hist
.history
.begin();
12779 assert(p
!= updated_hit_set_hist
.history
.end());
12780 hobject_t oid
= get_hit_set_archive_object(p
->begin
, p
->end
, p
->using_gmt
);
12782 assert(!is_degraded_or_backfilling_object(oid
));
12784 dout(20) << __func__
<< " removing " << oid
<< dendl
;
12785 ++ctx
->at_version
.version
;
12786 ctx
->log
.push_back(
12787 pg_log_entry_t(pg_log_entry_t::DELETE
,
12796 ctx
->op_t
->remove(oid
);
12797 updated_hit_set_hist
.history
.pop_front();
12799 ObjectContextRef obc
= get_object_context(oid
, false);
12801 --ctx
->delta_stats
.num_objects
;
12802 --ctx
->delta_stats
.num_objects_hit_set_archive
;
12803 ctx
->delta_stats
.num_bytes
-= obc
->obs
.oi
.size
;
12804 ctx
->delta_stats
.num_bytes_hit_set_archive
-= obc
->obs
.oi
.size
;
12808 void PrimaryLogPG::hit_set_in_memory_trim(uint32_t max_in_memory
)
12810 while (agent_state
->hit_set_map
.size() > max_in_memory
) {
12811 agent_state
->remove_oldest_hit_set();
12816 // =======================================
12819 void PrimaryLogPG::agent_setup()
12821 assert(is_locked());
12822 if (!is_active() ||
12824 pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
||
12825 pool
.info
.tier_of
< 0 ||
12826 !get_osdmap()->have_pg_pool(pool
.info
.tier_of
)) {
12830 if (!agent_state
) {
12831 agent_state
.reset(new TierAgentState
);
12833 // choose random starting position
12834 agent_state
->position
= hobject_t();
12835 agent_state
->position
.pool
= info
.pgid
.pool();
12836 agent_state
->position
.set_hash(pool
.info
.get_random_pg_position(
12839 agent_state
->start
= agent_state
->position
;
12841 dout(10) << __func__
<< " allocated new state, position "
12842 << agent_state
->position
<< dendl
;
12844 dout(10) << __func__
<< " keeping existing state" << dendl
;
12847 if (info
.stats
.stats_invalid
) {
12848 osd
->clog
->warn() << "pg " << info
.pgid
<< " has invalid (post-split) stats; must scrub before tier agent can activate";
12851 agent_choose_mode();
12854 void PrimaryLogPG::agent_clear()
12857 agent_state
.reset(NULL
);
12860 // Return false if no objects operated on since start of object hash space
12861 bool PrimaryLogPG::agent_work(int start_max
, int agent_flush_quota
)
12864 if (!agent_state
) {
12865 dout(10) << __func__
<< " no agent state, stopping" << dendl
;
12872 if (agent_state
->is_idle()) {
12873 dout(10) << __func__
<< " idle, stopping" << dendl
;
12878 osd
->logger
->inc(l_osd_agent_wake
);
12880 dout(10) << __func__
12881 << " max " << start_max
12882 << ", flush " << agent_state
->get_flush_mode_name()
12883 << ", evict " << agent_state
->get_evict_mode_name()
12884 << ", pos " << agent_state
->position
12886 assert(is_primary());
12887 assert(is_active());
12889 agent_load_hit_sets();
12891 const pg_pool_t
*base_pool
= get_osdmap()->get_pg_pool(pool
.info
.tier_of
);
12895 int ls_max
= cct
->_conf
->osd_pool_default_cache_max_evict_check_size
;
12897 // list some objects. this conveniently lists clones (oldest to
12898 // newest) before heads... the same order we want to flush in.
12900 // NOTE: do not flush the Sequencer. we will assume that the
12901 // listing we get back is imprecise.
12902 vector
<hobject_t
> ls
;
12904 int r
= pgbackend
->objects_list_partial(agent_state
->position
, ls_min
, ls_max
,
12907 dout(20) << __func__
<< " got " << ls
.size() << " objects" << dendl
;
12909 for (vector
<hobject_t
>::iterator p
= ls
.begin();
12912 if (p
->nspace
== cct
->_conf
->osd_hit_set_namespace
) {
12913 dout(20) << __func__
<< " skip (hit set) " << *p
<< dendl
;
12914 osd
->logger
->inc(l_osd_agent_skip
);
12917 if (is_degraded_or_backfilling_object(*p
)) {
12918 dout(20) << __func__
<< " skip (degraded) " << *p
<< dendl
;
12919 osd
->logger
->inc(l_osd_agent_skip
);
12922 if (is_missing_object(p
->get_head())) {
12923 dout(20) << __func__
<< " skip (missing head) " << *p
<< dendl
;
12924 osd
->logger
->inc(l_osd_agent_skip
);
12927 ObjectContextRef obc
= get_object_context(*p
, false, NULL
);
12929 // we didn't flush; we may miss something here.
12930 dout(20) << __func__
<< " skip (no obc) " << *p
<< dendl
;
12931 osd
->logger
->inc(l_osd_agent_skip
);
12934 if (!obc
->obs
.exists
) {
12935 dout(20) << __func__
<< " skip (dne) " << obc
->obs
.oi
.soid
<< dendl
;
12936 osd
->logger
->inc(l_osd_agent_skip
);
12939 if (scrubber
.write_blocked_by_scrub(obc
->obs
.oi
.soid
)) {
12940 dout(20) << __func__
<< " skip (scrubbing) " << obc
->obs
.oi
<< dendl
;
12941 osd
->logger
->inc(l_osd_agent_skip
);
12944 if (obc
->is_blocked()) {
12945 dout(20) << __func__
<< " skip (blocked) " << obc
->obs
.oi
<< dendl
;
12946 osd
->logger
->inc(l_osd_agent_skip
);
12949 if (obc
->is_request_pending()) {
12950 dout(20) << __func__
<< " skip (request pending) " << obc
->obs
.oi
<< dendl
;
12951 osd
->logger
->inc(l_osd_agent_skip
);
12955 // be careful flushing omap to an EC pool.
12956 if (!base_pool
->supports_omap() &&
12957 obc
->obs
.oi
.is_omap()) {
12958 dout(20) << __func__
<< " skip (omap to EC) " << obc
->obs
.oi
<< dendl
;
12959 osd
->logger
->inc(l_osd_agent_skip
);
12963 if (agent_state
->evict_mode
!= TierAgentState::EVICT_MODE_IDLE
&&
12964 agent_maybe_evict(obc
, false))
12966 else if (agent_state
->flush_mode
!= TierAgentState::FLUSH_MODE_IDLE
&&
12967 agent_flush_quota
> 0 && agent_maybe_flush(obc
)) {
12969 --agent_flush_quota
;
12971 if (started
>= start_max
) {
12972 // If finishing early, set "next" to the next object
12973 if (++p
!= ls
.end())
12979 if (++agent_state
->hist_age
> cct
->_conf
->osd_agent_hist_halflife
) {
12980 dout(20) << __func__
<< " resetting atime and temp histograms" << dendl
;
12981 agent_state
->hist_age
= 0;
12982 agent_state
->temp_hist
.decay();
12985 // Total objects operated on so far
12986 int total_started
= agent_state
->started
+ started
;
12987 bool need_delay
= false;
12989 dout(20) << __func__
<< " start pos " << agent_state
->position
12990 << " next start pos " << next
12991 << " started " << total_started
<< dendl
;
12993 // See if we've made a full pass over the object hash space
12994 // This might check at most ls_max objects a second time to notice that
12995 // we've checked every objects at least once.
12996 if (agent_state
->position
< agent_state
->start
&&
12997 next
>= agent_state
->start
) {
12998 dout(20) << __func__
<< " wrap around " << agent_state
->start
<< dendl
;
12999 if (total_started
== 0)
13003 agent_state
->start
= next
;
13005 agent_state
->started
= total_started
;
13007 // See if we are starting from beginning
13009 agent_state
->position
= hobject_t();
13011 agent_state
->position
= next
;
13013 // Discard old in memory HitSets
13014 hit_set_in_memory_trim(pool
.info
.hit_set_count
);
13017 assert(agent_state
->delaying
== false);
13022 agent_choose_mode();
13027 void PrimaryLogPG::agent_load_hit_sets()
13029 if (agent_state
->evict_mode
== TierAgentState::EVICT_MODE_IDLE
) {
13033 if (agent_state
->hit_set_map
.size() < info
.hit_set
.history
.size()) {
13034 dout(10) << __func__
<< dendl
;
13035 for (list
<pg_hit_set_info_t
>::iterator p
= info
.hit_set
.history
.begin();
13036 p
!= info
.hit_set
.history
.end(); ++p
) {
13037 if (agent_state
->hit_set_map
.count(p
->begin
.sec()) == 0) {
13038 dout(10) << __func__
<< " loading " << p
->begin
<< "-"
13039 << p
->end
<< dendl
;
13040 if (!pool
.info
.is_replicated()) {
13041 // FIXME: EC not supported here yet
13042 derr
<< __func__
<< " on non-replicated pool" << dendl
;
13046 hobject_t oid
= get_hit_set_archive_object(p
->begin
, p
->end
, p
->using_gmt
);
13047 if (is_unreadable_object(oid
)) {
13048 dout(10) << __func__
<< " unreadable " << oid
<< ", waiting" << dendl
;
13052 ObjectContextRef obc
= get_object_context(oid
, false);
13054 derr
<< __func__
<< ": could not load hitset " << oid
<< dendl
;
13060 obc
->ondisk_read_lock();
13061 int r
= osd
->store
->read(ch
, ghobject_t(oid
), 0, 0, bl
);
13063 obc
->ondisk_read_unlock();
13065 HitSetRef
hs(new HitSet
);
13066 bufferlist::iterator pbl
= bl
.begin();
13067 ::decode(*hs
, pbl
);
13068 agent_state
->add_hit_set(p
->begin
.sec(), hs
);
13074 bool PrimaryLogPG::agent_maybe_flush(ObjectContextRef
& obc
)
13076 if (!obc
->obs
.oi
.is_dirty()) {
13077 dout(20) << __func__
<< " skip (clean) " << obc
->obs
.oi
<< dendl
;
13078 osd
->logger
->inc(l_osd_agent_skip
);
13081 if (obc
->obs
.oi
.is_cache_pinned()) {
13082 dout(20) << __func__
<< " skip (cache_pinned) " << obc
->obs
.oi
<< dendl
;
13083 osd
->logger
->inc(l_osd_agent_skip
);
13087 utime_t now
= ceph_clock_now();
13088 utime_t ob_local_mtime
;
13089 if (obc
->obs
.oi
.local_mtime
!= utime_t()) {
13090 ob_local_mtime
= obc
->obs
.oi
.local_mtime
;
13092 ob_local_mtime
= obc
->obs
.oi
.mtime
;
13094 bool evict_mode_full
=
13095 (agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
);
13096 if (!evict_mode_full
&&
13097 obc
->obs
.oi
.soid
.snap
== CEPH_NOSNAP
&& // snaps immutable; don't delay
13098 (ob_local_mtime
+ utime_t(pool
.info
.cache_min_flush_age
, 0) > now
)) {
13099 dout(20) << __func__
<< " skip (too young) " << obc
->obs
.oi
<< dendl
;
13100 osd
->logger
->inc(l_osd_agent_skip
);
13104 if (osd
->agent_is_active_oid(obc
->obs
.oi
.soid
)) {
13105 dout(20) << __func__
<< " skip (flushing) " << obc
->obs
.oi
<< dendl
;
13106 osd
->logger
->inc(l_osd_agent_skip
);
13110 dout(10) << __func__
<< " flushing " << obc
->obs
.oi
<< dendl
;
13112 // FIXME: flush anything dirty, regardless of what distribution of
13115 hobject_t oid
= obc
->obs
.oi
.soid
;
13116 osd
->agent_start_op(oid
);
13117 // no need to capture a pg ref, can't outlive fop or ctx
13118 std::function
<void()> on_flush
= [this, oid
]() {
13119 osd
->agent_finish_op(oid
);
13122 int result
= start_flush(
13123 OpRequestRef(), obc
, false, NULL
,
13125 if (result
!= -EINPROGRESS
) {
13127 dout(10) << __func__
<< " start_flush() failed " << obc
->obs
.oi
13128 << " with " << result
<< dendl
;
13129 osd
->logger
->inc(l_osd_agent_skip
);
13133 osd
->logger
->inc(l_osd_agent_flush
);
13137 bool PrimaryLogPG::agent_maybe_evict(ObjectContextRef
& obc
, bool after_flush
)
13139 const hobject_t
& soid
= obc
->obs
.oi
.soid
;
13140 if (!after_flush
&& obc
->obs
.oi
.is_dirty()) {
13141 dout(20) << __func__
<< " skip (dirty) " << obc
->obs
.oi
<< dendl
;
13144 if (!obc
->obs
.oi
.watchers
.empty()) {
13145 dout(20) << __func__
<< " skip (watchers) " << obc
->obs
.oi
<< dendl
;
13148 if (obc
->is_blocked()) {
13149 dout(20) << __func__
<< " skip (blocked) " << obc
->obs
.oi
<< dendl
;
13152 if (obc
->obs
.oi
.is_cache_pinned()) {
13153 dout(20) << __func__
<< " skip (cache_pinned) " << obc
->obs
.oi
<< dendl
;
13157 if (soid
.snap
== CEPH_NOSNAP
) {
13158 int result
= _verify_no_head_clones(soid
, obc
->ssc
->snapset
);
13160 dout(20) << __func__
<< " skip (clones) " << obc
->obs
.oi
<< dendl
;
13165 if (agent_state
->evict_mode
!= TierAgentState::EVICT_MODE_FULL
) {
13166 // is this object old than cache_min_evict_age?
13167 utime_t now
= ceph_clock_now();
13168 utime_t ob_local_mtime
;
13169 if (obc
->obs
.oi
.local_mtime
!= utime_t()) {
13170 ob_local_mtime
= obc
->obs
.oi
.local_mtime
;
13172 ob_local_mtime
= obc
->obs
.oi
.mtime
;
13174 if (ob_local_mtime
+ utime_t(pool
.info
.cache_min_evict_age
, 0) > now
) {
13175 dout(20) << __func__
<< " skip (too young) " << obc
->obs
.oi
<< dendl
;
13176 osd
->logger
->inc(l_osd_agent_skip
);
13179 // is this object old and/or cold enough?
13181 uint64_t temp_upper
= 0, temp_lower
= 0;
13183 agent_estimate_temp(soid
, &temp
);
13184 agent_state
->temp_hist
.add(temp
);
13185 agent_state
->temp_hist
.get_position_micro(temp
, &temp_lower
, &temp_upper
);
13187 dout(20) << __func__
13188 << " temp " << temp
13189 << " pos " << temp_lower
<< "-" << temp_upper
13190 << ", evict_effort " << agent_state
->evict_effort
13192 dout(30) << "agent_state:\n";
13193 Formatter
*f
= Formatter::create("");
13194 f
->open_object_section("agent_state");
13195 agent_state
->dump(f
);
13196 f
->close_section();
13201 if (1000000 - temp_upper
>= agent_state
->evict_effort
)
13205 dout(10) << __func__
<< " evicting " << obc
->obs
.oi
<< dendl
;
13206 OpContextUPtr ctx
= simple_opc_create(obc
);
13208 if (!ctx
->lock_manager
.get_lock_type(
13209 ObjectContext::RWState::RWWRITE
,
13213 close_op_ctx(ctx
.release());
13214 dout(20) << __func__
<< " skip (cannot get lock) " << obc
->obs
.oi
<< dendl
;
13218 osd
->agent_start_evict_op();
13219 ctx
->register_on_finish(
13221 osd
->agent_finish_evict_op();
13224 ctx
->at_version
= get_next_version();
13225 assert(ctx
->new_obs
.exists
);
13226 int r
= _delete_oid(ctx
.get(), true, false);
13227 if (obc
->obs
.oi
.is_omap())
13228 ctx
->delta_stats
.num_objects_omap
--;
13229 ctx
->delta_stats
.num_evict
++;
13230 ctx
->delta_stats
.num_evict_kb
+= SHIFT_ROUND_UP(obc
->obs
.oi
.size
, 10);
13231 if (obc
->obs
.oi
.is_dirty())
13232 --ctx
->delta_stats
.num_objects_dirty
;
13234 finish_ctx(ctx
.get(), pg_log_entry_t::DELETE
, false);
13235 simple_opc_submit(std::move(ctx
));
13236 osd
->logger
->inc(l_osd_tier_evict
);
13237 osd
->logger
->inc(l_osd_agent_evict
);
13241 void PrimaryLogPG::agent_stop()
13243 dout(20) << __func__
<< dendl
;
13244 if (agent_state
&& !agent_state
->is_idle()) {
13245 agent_state
->evict_mode
= TierAgentState::EVICT_MODE_IDLE
;
13246 agent_state
->flush_mode
= TierAgentState::FLUSH_MODE_IDLE
;
13247 osd
->agent_disable_pg(this, agent_state
->evict_effort
);
13251 void PrimaryLogPG::agent_delay()
13253 dout(20) << __func__
<< dendl
;
13254 if (agent_state
&& !agent_state
->is_idle()) {
13255 assert(agent_state
->delaying
== false);
13256 agent_state
->delaying
= true;
13257 osd
->agent_disable_pg(this, agent_state
->evict_effort
);
13261 void PrimaryLogPG::agent_choose_mode_restart()
13263 dout(20) << __func__
<< dendl
;
13265 if (agent_state
&& agent_state
->delaying
) {
13266 agent_state
->delaying
= false;
13267 agent_choose_mode(true);
13272 bool PrimaryLogPG::agent_choose_mode(bool restart
, OpRequestRef op
)
13274 bool requeued
= false;
13275 // Let delay play out
13276 if (agent_state
->delaying
) {
13277 dout(20) << __func__
<< this << " delaying, ignored" << dendl
;
13281 TierAgentState::flush_mode_t flush_mode
= TierAgentState::FLUSH_MODE_IDLE
;
13282 TierAgentState::evict_mode_t evict_mode
= TierAgentState::EVICT_MODE_IDLE
;
13283 unsigned evict_effort
= 0;
13285 if (info
.stats
.stats_invalid
) {
13286 // idle; stats can't be trusted until we scrub.
13287 dout(20) << __func__
<< " stats invalid (post-split), idle" << dendl
;
13292 uint64_t divisor
= pool
.info
.get_pg_num_divisor(info
.pgid
.pgid
);
13293 assert(divisor
> 0);
13295 // adjust (effective) user objects down based on the number
13296 // of HitSet objects, which should not count toward our total since
13297 // they cannot be flushed.
13298 uint64_t unflushable
= info
.stats
.stats
.sum
.num_objects_hit_set_archive
;
13300 // also exclude omap objects if ec backing pool
13301 const pg_pool_t
*base_pool
= get_osdmap()->get_pg_pool(pool
.info
.tier_of
);
13303 if (!base_pool
->supports_omap())
13304 unflushable
+= info
.stats
.stats
.sum
.num_objects_omap
;
13306 uint64_t num_user_objects
= info
.stats
.stats
.sum
.num_objects
;
13307 if (num_user_objects
> unflushable
)
13308 num_user_objects
-= unflushable
;
13310 num_user_objects
= 0;
13312 uint64_t num_user_bytes
= info
.stats
.stats
.sum
.num_bytes
;
13313 uint64_t unflushable_bytes
= info
.stats
.stats
.sum
.num_bytes_hit_set_archive
;
13314 num_user_bytes
-= unflushable_bytes
;
13315 uint64_t num_overhead_bytes
= osd
->store
->estimate_objects_overhead(num_user_objects
);
13316 num_user_bytes
+= num_overhead_bytes
;
13318 // also reduce the num_dirty by num_objects_omap
13319 int64_t num_dirty
= info
.stats
.stats
.sum
.num_objects_dirty
;
13320 if (!base_pool
->supports_omap()) {
13321 if (num_dirty
> info
.stats
.stats
.sum
.num_objects_omap
)
13322 num_dirty
-= info
.stats
.stats
.sum
.num_objects_omap
;
13327 dout(10) << __func__
13329 << TierAgentState::get_flush_mode_name(agent_state
->flush_mode
)
13331 << TierAgentState::get_evict_mode_name(agent_state
->evict_mode
)
13332 << " num_objects: " << info
.stats
.stats
.sum
.num_objects
13333 << " num_bytes: " << info
.stats
.stats
.sum
.num_bytes
13334 << " num_objects_dirty: " << info
.stats
.stats
.sum
.num_objects_dirty
13335 << " num_objects_omap: " << info
.stats
.stats
.sum
.num_objects_omap
13336 << " num_dirty: " << num_dirty
13337 << " num_user_objects: " << num_user_objects
13338 << " num_user_bytes: " << num_user_bytes
13339 << " num_overhead_bytes: " << num_overhead_bytes
13340 << " pool.info.target_max_bytes: " << pool
.info
.target_max_bytes
13341 << " pool.info.target_max_objects: " << pool
.info
.target_max_objects
13344 // get dirty, full ratios
13345 uint64_t dirty_micro
= 0;
13346 uint64_t full_micro
= 0;
13347 if (pool
.info
.target_max_bytes
&& num_user_objects
> 0) {
13348 uint64_t avg_size
= num_user_bytes
/ num_user_objects
;
13350 num_dirty
* avg_size
* 1000000 /
13351 MAX(pool
.info
.target_max_bytes
/ divisor
, 1);
13353 num_user_objects
* avg_size
* 1000000 /
13354 MAX(pool
.info
.target_max_bytes
/ divisor
, 1);
13356 if (pool
.info
.target_max_objects
> 0) {
13357 uint64_t dirty_objects_micro
=
13358 num_dirty
* 1000000 /
13359 MAX(pool
.info
.target_max_objects
/ divisor
, 1);
13360 if (dirty_objects_micro
> dirty_micro
)
13361 dirty_micro
= dirty_objects_micro
;
13362 uint64_t full_objects_micro
=
13363 num_user_objects
* 1000000 /
13364 MAX(pool
.info
.target_max_objects
/ divisor
, 1);
13365 if (full_objects_micro
> full_micro
)
13366 full_micro
= full_objects_micro
;
13368 dout(20) << __func__
<< " dirty " << ((float)dirty_micro
/ 1000000.0)
13369 << " full " << ((float)full_micro
/ 1000000.0)
13373 uint64_t flush_target
= pool
.info
.cache_target_dirty_ratio_micro
;
13374 uint64_t flush_high_target
= pool
.info
.cache_target_dirty_high_ratio_micro
;
13375 uint64_t flush_slop
= (float)flush_target
* cct
->_conf
->osd_agent_slop
;
13376 if (restart
|| agent_state
->flush_mode
== TierAgentState::FLUSH_MODE_IDLE
) {
13377 flush_target
+= flush_slop
;
13378 flush_high_target
+= flush_slop
;
13380 flush_target
-= MIN(flush_target
, flush_slop
);
13381 flush_high_target
-= MIN(flush_high_target
, flush_slop
);
13384 if (dirty_micro
> flush_high_target
) {
13385 flush_mode
= TierAgentState::FLUSH_MODE_HIGH
;
13386 } else if (dirty_micro
> flush_target
) {
13387 flush_mode
= TierAgentState::FLUSH_MODE_LOW
;
13391 uint64_t evict_target
= pool
.info
.cache_target_full_ratio_micro
;
13392 uint64_t evict_slop
= (float)evict_target
* cct
->_conf
->osd_agent_slop
;
13393 if (restart
|| agent_state
->evict_mode
== TierAgentState::EVICT_MODE_IDLE
)
13394 evict_target
+= evict_slop
;
13396 evict_target
-= MIN(evict_target
, evict_slop
);
13398 if (full_micro
> 1000000) {
13399 // evict anything clean
13400 evict_mode
= TierAgentState::EVICT_MODE_FULL
;
13401 evict_effort
= 1000000;
13402 } else if (full_micro
> evict_target
) {
13403 // set effort in [0..1] range based on where we are between
13404 evict_mode
= TierAgentState::EVICT_MODE_SOME
;
13405 uint64_t over
= full_micro
- evict_target
;
13406 uint64_t span
= 1000000 - evict_target
;
13407 evict_effort
= MAX(over
* 1000000 / span
,
13408 (unsigned)(1000000.0 * cct
->_conf
->osd_agent_min_evict_effort
));
13410 // quantize effort to avoid too much reordering in the agent_queue.
13411 uint64_t inc
= cct
->_conf
->osd_agent_quantize_effort
* 1000000;
13413 uint64_t was
= evict_effort
;
13414 evict_effort
-= evict_effort
% inc
;
13415 if (evict_effort
< inc
)
13416 evict_effort
= inc
;
13417 assert(evict_effort
>= inc
&& evict_effort
<= 1000000);
13418 dout(30) << __func__
<< " evict_effort " << was
<< " quantized by " << inc
<< " to " << evict_effort
<< dendl
;
13423 bool old_idle
= agent_state
->is_idle();
13424 if (flush_mode
!= agent_state
->flush_mode
) {
13425 dout(5) << __func__
<< " flush_mode "
13426 << TierAgentState::get_flush_mode_name(agent_state
->flush_mode
)
13428 << TierAgentState::get_flush_mode_name(flush_mode
)
13430 if (flush_mode
== TierAgentState::FLUSH_MODE_HIGH
) {
13431 osd
->agent_inc_high_count();
13432 info
.stats
.stats
.sum
.num_flush_mode_high
= 1;
13433 } else if (flush_mode
== TierAgentState::FLUSH_MODE_LOW
) {
13434 info
.stats
.stats
.sum
.num_flush_mode_low
= 1;
13436 if (agent_state
->flush_mode
== TierAgentState::FLUSH_MODE_HIGH
) {
13437 osd
->agent_dec_high_count();
13438 info
.stats
.stats
.sum
.num_flush_mode_high
= 0;
13439 } else if (agent_state
->flush_mode
== TierAgentState::FLUSH_MODE_LOW
) {
13440 info
.stats
.stats
.sum
.num_flush_mode_low
= 0;
13442 agent_state
->flush_mode
= flush_mode
;
13444 if (evict_mode
!= agent_state
->evict_mode
) {
13445 dout(5) << __func__
<< " evict_mode "
13446 << TierAgentState::get_evict_mode_name(agent_state
->evict_mode
)
13448 << TierAgentState::get_evict_mode_name(evict_mode
)
13450 if (agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
&&
13454 requeue_ops(waiting_for_active
);
13455 requeue_ops(waiting_for_scrub
);
13456 requeue_ops(waiting_for_cache_not_full
);
13457 objects_blocked_on_cache_full
.clear();
13460 if (evict_mode
== TierAgentState::EVICT_MODE_SOME
) {
13461 info
.stats
.stats
.sum
.num_evict_mode_some
= 1;
13462 } else if (evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
13463 info
.stats
.stats
.sum
.num_evict_mode_full
= 1;
13465 if (agent_state
->evict_mode
== TierAgentState::EVICT_MODE_SOME
) {
13466 info
.stats
.stats
.sum
.num_evict_mode_some
= 0;
13467 } else if (agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
13468 info
.stats
.stats
.sum
.num_evict_mode_full
= 0;
13470 agent_state
->evict_mode
= evict_mode
;
13472 uint64_t old_effort
= agent_state
->evict_effort
;
13473 if (evict_effort
!= agent_state
->evict_effort
) {
13474 dout(5) << __func__
<< " evict_effort "
13475 << ((float)agent_state
->evict_effort
/ 1000000.0)
13477 << ((float)evict_effort
/ 1000000.0)
13479 agent_state
->evict_effort
= evict_effort
;
13482 // NOTE: we are using evict_effort as a proxy for *all* agent effort
13483 // (including flush). This is probably fine (they should be
13484 // correlated) but it is not precisely correct.
13485 if (agent_state
->is_idle()) {
13486 if (!restart
&& !old_idle
) {
13487 osd
->agent_disable_pg(this, old_effort
);
13490 if (restart
|| old_idle
) {
13491 osd
->agent_enable_pg(this, agent_state
->evict_effort
);
13492 } else if (old_effort
!= agent_state
->evict_effort
) {
13493 osd
->agent_adjust_pg(this, old_effort
, agent_state
->evict_effort
);
13499 void PrimaryLogPG::agent_estimate_temp(const hobject_t
& oid
, int *temp
)
13504 if (hit_set
->contains(oid
))
13507 int last_n
= pool
.info
.hit_set_search_last_n
;
13508 for (map
<time_t,HitSetRef
>::reverse_iterator p
=
13509 agent_state
->hit_set_map
.rbegin(); last_n
> 0 &&
13510 p
!= agent_state
->hit_set_map
.rend(); ++p
, ++i
) {
13511 if (p
->second
->contains(oid
)) {
13512 *temp
+= pool
.info
.get_grade(i
);
13518 // Dup op detection
13520 bool PrimaryLogPG::already_complete(eversion_t v
)
13522 dout(20) << __func__
<< ": " << v
<< dendl
;
13523 for (xlist
<RepGather
*>::iterator i
= repop_queue
.begin();
13526 dout(20) << __func__
<< ": " << **i
<< dendl
;
13527 // skip copy from temp object ops
13528 if ((*i
)->v
== eversion_t()) {
13529 dout(20) << __func__
<< ": " << **i
13530 << " version is empty" << dendl
;
13534 dout(20) << __func__
<< ": " << **i
13535 << " (*i)->v past v" << dendl
;
13538 if (!(*i
)->all_committed
) {
13539 dout(20) << __func__
<< ": " << **i
13540 << " not committed, returning false"
13545 dout(20) << __func__
<< ": returning true" << dendl
;
13549 bool PrimaryLogPG::already_ack(eversion_t v
)
13551 dout(20) << __func__
<< ": " << v
<< dendl
;
13552 for (xlist
<RepGather
*>::iterator i
= repop_queue
.begin();
13555 // skip copy from temp object ops
13556 if ((*i
)->v
== eversion_t()) {
13557 dout(20) << __func__
<< ": " << **i
13558 << " version is empty" << dendl
;
13562 dout(20) << __func__
<< ": " << **i
13563 << " (*i)->v past v" << dendl
;
13566 if (!(*i
)->all_applied
) {
13567 dout(20) << __func__
<< ": " << **i
13568 << " not applied, returning false"
13573 dout(20) << __func__
<< ": returning true" << dendl
;
13578 // ==========================================================================================
13582 bool PrimaryLogPG::_range_available_for_scrub(
13583 const hobject_t
&begin
, const hobject_t
&end
)
13585 pair
<hobject_t
, ObjectContextRef
> next
;
13586 next
.second
= object_contexts
.lookup(begin
);
13587 next
.first
= begin
;
13589 while (more
&& next
.first
< end
) {
13590 if (next
.second
&& next
.second
->is_blocked()) {
13591 next
.second
->requeue_scrub_on_unblock
= true;
13592 dout(10) << __func__
<< ": scrub delayed, "
13593 << next
.first
<< " is blocked"
13597 more
= object_contexts
.get_next(next
.first
, &next
);
13602 static bool doing_clones(const boost::optional
<SnapSet
> &snapset
,
13603 const vector
<snapid_t
>::reverse_iterator
&curclone
) {
13604 return snapset
&& curclone
!= snapset
.get().clones
.rend();
13607 void PrimaryLogPG::log_missing(unsigned missing
,
13608 const boost::optional
<hobject_t
> &head
,
13609 LogChannelRef clog
,
13613 bool allow_incomplete_clones
)
13616 if (allow_incomplete_clones
) {
13617 dout(20) << func
<< " " << mode
<< " " << pgid
<< " " << head
.get()
13618 << " skipped " << missing
<< " clone(s) in cache tier" << dendl
;
13620 clog
->info() << mode
<< " " << pgid
<< " " << head
.get()
13621 << " " << missing
<< " missing clone(s)";
13625 unsigned PrimaryLogPG::process_clones_to(const boost::optional
<hobject_t
> &head
,
13626 const boost::optional
<SnapSet
> &snapset
,
13627 LogChannelRef clog
,
13630 bool allow_incomplete_clones
,
13631 boost::optional
<snapid_t
> target
,
13632 vector
<snapid_t
>::reverse_iterator
*curclone
,
13633 inconsistent_snapset_wrapper
&e
)
13637 unsigned missing
= 0;
13639 // NOTE: clones are in descending order, thus **curclone > target test here
13640 hobject_t
next_clone(head
.get());
13641 while(doing_clones(snapset
, *curclone
) && (!target
|| **curclone
> *target
)) {
13643 // it is okay to be missing one or more clones in a cache tier.
13644 // skip higher-numbered clones in the list.
13645 if (!allow_incomplete_clones
) {
13646 next_clone
.snap
= **curclone
;
13647 clog
->error() << mode
<< " " << pgid
<< " " << head
.get()
13648 << " expected clone " << next_clone
<< " " << missing
13650 ++scrubber
.shallow_errors
;
13651 e
.set_clone_missing(next_clone
.snap
);
13653 // Clones are descending
13660 * Validate consistency of the object info and snap sets.
13662 * We are sort of comparing 2 lists. The main loop is on objmap.objects. But
13663 * the comparison of the objects is against multiple snapset.clones. There are
13664 * multiple clone lists and in between lists we expect head or snapdir.
13670 * obj1 snap 1 head/snapdir, unexpected obj1 snap 1
13671 * obj2 head head/snapdir, head ok
13672 * [SnapSet clones 6 4 2 1]
13673 * obj2 snap 7 obj2 snap 6, unexpected obj2 snap 7
13674 * obj2 snap 6 obj2 snap 6, match
13675 * obj2 snap 4 obj2 snap 4, match
13676 * obj3 head obj2 snap 2 (expected), obj2 snap 1 (expected), head ok
13677 * [Snapset clones 3 1]
13678 * obj3 snap 3 obj3 snap 3 match
13679 * obj3 snap 1 obj3 snap 1 match
13680 * obj4 snapdir head/snapdir, snapdir ok
13681 * [Snapset clones 4]
13682 * EOL obj4 snap 4, (expected)
13684 void PrimaryLogPG::scrub_snapshot_metadata(
13685 ScrubMap
&scrubmap
,
13686 const map
<hobject_t
, pair
<uint32_t, uint32_t>> &missing_digest
)
13688 dout(10) << __func__
<< dendl
;
13690 coll_t
c(info
.pgid
);
13691 bool repair
= state_test(PG_STATE_REPAIR
);
13692 bool deep_scrub
= state_test(PG_STATE_DEEP_SCRUB
);
13693 const char *mode
= (repair
? "repair": (deep_scrub
? "deep-scrub" : "scrub"));
13694 boost::optional
<snapid_t
> all_clones
; // Unspecified snapid_t or boost::none
13696 /// snapsets to repair
13697 map
<hobject_t
,SnapSet
> snapset_to_repair
;
13699 // traverse in reverse order.
13700 boost::optional
<hobject_t
> head
;
13701 boost::optional
<SnapSet
> snapset
; // If initialized so will head (above)
13702 vector
<snapid_t
>::reverse_iterator curclone
; // Defined only if snapset initialized
13703 unsigned missing
= 0;
13704 inconsistent_snapset_wrapper soid_error
, head_error
;
13706 bufferlist last_data
;
13708 for (map
<hobject_t
,ScrubMap::object
>::reverse_iterator
13709 p
= scrubmap
.objects
.rbegin(); p
!= scrubmap
.objects
.rend(); ++p
) {
13710 const hobject_t
& soid
= p
->first
;
13711 soid_error
= inconsistent_snapset_wrapper
{soid
};
13712 object_stat_sum_t stat
;
13713 boost::optional
<object_info_t
> oi
;
13715 if (!soid
.is_snapdir())
13716 stat
.num_objects
++;
13718 if (soid
.nspace
== cct
->_conf
->osd_hit_set_namespace
)
13719 stat
.num_objects_hit_set_archive
++;
13721 if (soid
.is_snap()) {
13723 stat
.num_object_clones
++;
13727 if (p
->second
.attrs
.count(OI_ATTR
) == 0) {
13729 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13730 << " no '" << OI_ATTR
<< "' attr";
13731 ++scrubber
.shallow_errors
;
13732 soid_error
.set_oi_attr_missing();
13735 bv
.push_back(p
->second
.attrs
[OI_ATTR
]);
13737 oi
= object_info_t(); // Initialize optional<> before decode into it
13738 oi
.get().decode(bv
);
13739 } catch (buffer::error
& e
) {
13741 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13742 << " can't decode '" << OI_ATTR
<< "' attr " << e
.what();
13743 ++scrubber
.shallow_errors
;
13744 soid_error
.set_oi_attr_corrupted();
13745 soid_error
.set_oi_attr_missing(); // Not available too
13750 if (pgbackend
->be_get_ondisk_size(oi
->size
) != p
->second
.size
) {
13751 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13752 << " on disk size (" << p
->second
.size
13753 << ") does not match object info size ("
13754 << oi
->size
<< ") adjusted for ondisk to ("
13755 << pgbackend
->be_get_ondisk_size(oi
->size
)
13757 soid_error
.set_size_mismatch();
13758 ++scrubber
.shallow_errors
;
13761 dout(20) << mode
<< " " << soid
<< " " << oi
.get() << dendl
;
13763 // A clone num_bytes will be added later when we have snapset
13764 if (!soid
.is_snap()) {
13765 stat
.num_bytes
+= oi
->size
;
13767 if (soid
.nspace
== cct
->_conf
->osd_hit_set_namespace
)
13768 stat
.num_bytes_hit_set_archive
+= oi
->size
;
13770 if (!soid
.is_snapdir()) {
13771 if (oi
->is_dirty())
13772 ++stat
.num_objects_dirty
;
13773 if (oi
->is_whiteout())
13774 ++stat
.num_whiteouts
;
13776 ++stat
.num_objects_omap
;
13777 if (oi
->is_cache_pinned())
13778 ++stat
.num_objects_pinned
;
13781 // pessimistic assumption that this object might contain a
13783 stat
.num_legacy_snapsets
++;
13786 // Check for any problems while processing clones
13787 if (doing_clones(snapset
, curclone
)) {
13788 boost::optional
<snapid_t
> target
;
13789 // Expecting an object with snap for current head
13790 if (soid
.has_snapset() || soid
.get_head() != head
->get_head()) {
13792 dout(10) << __func__
<< " " << mode
<< " " << info
.pgid
<< " new object "
13793 << soid
<< " while processing " << head
.get() << dendl
;
13795 target
= all_clones
;
13797 assert(soid
.is_snap());
13798 target
= soid
.snap
;
13801 // Log any clones we were expecting to be there up to target
13802 // This will set missing, but will be a no-op if snap.soid == *curclone.
13803 missing
+= process_clones_to(head
, snapset
, osd
->clog
, info
.pgid
, mode
,
13804 pool
.info
.allow_incomplete_clones(), target
, &curclone
,
13808 // Check doing_clones() again in case we ran process_clones_to()
13809 if (doing_clones(snapset
, curclone
)) {
13810 // A head/snapdir would have processed all clones above
13811 // or all greater than *curclone.
13812 assert(soid
.is_snap() && *curclone
<= soid
.snap
);
13814 // After processing above clone snap should match the expected curclone
13815 expected
= (*curclone
== soid
.snap
);
13817 // If we aren't doing clones any longer, then expecting head/snapdir
13818 expected
= soid
.has_snapset();
13821 // If we couldn't read the head's snapset, just ignore clones
13822 if (head
&& !snapset
) {
13823 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13824 << " clone ignored due to missing snapset";
13826 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13827 << " is an unexpected clone";
13829 ++scrubber
.shallow_errors
;
13830 soid_error
.set_headless();
13831 scrubber
.store
->add_snap_error(pool
.id
, soid_error
);
13832 if (head
&& soid
.get_head() == head
->get_head())
13833 head_error
.set_clone(soid
.snap
);
13838 if (soid
.has_snapset()) {
13841 log_missing(missing
, head
, osd
->clog
, info
.pgid
, __func__
, mode
,
13842 pool
.info
.allow_incomplete_clones());
13845 // Save previous head error information
13846 if (head
&& head_error
.errors
)
13847 scrubber
.store
->add_snap_error(pool
.id
, head_error
);
13848 // Set this as a new head object
13851 head_error
= soid_error
;
13853 dout(20) << __func__
<< " " << mode
<< " new head " << head
<< dendl
;
13855 if (p
->second
.attrs
.count(SS_ATTR
) == 0) {
13856 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13857 << " no '" << SS_ATTR
<< "' attr";
13858 ++scrubber
.shallow_errors
;
13859 snapset
= boost::none
;
13860 head_error
.set_ss_attr_missing();
13863 bl
.push_back(p
->second
.attrs
[SS_ATTR
]);
13864 bufferlist::iterator blp
= bl
.begin();
13866 snapset
= SnapSet(); // Initialize optional<> before decoding into it
13867 ::decode(snapset
.get(), blp
);
13868 } catch (buffer::error
& e
) {
13869 snapset
= boost::none
;
13870 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13871 << " can't decode '" << SS_ATTR
<< "' attr " << e
.what();
13872 ++scrubber
.shallow_errors
;
13873 head_error
.set_ss_attr_corrupted();
13878 // what will be next?
13879 curclone
= snapset
->clones
.rbegin();
13881 if (!snapset
->clones
.empty()) {
13882 dout(20) << " snapset " << snapset
.get() << dendl
;
13883 if (snapset
->seq
== 0) {
13884 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13885 << " snaps.seq not set";
13886 ++scrubber
.shallow_errors
;
13887 head_error
.set_snapset_mismatch();
13891 if (soid
.is_head() && !snapset
->head_exists
) {
13892 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13893 << " snapset.head_exists=false, but head exists";
13894 ++scrubber
.shallow_errors
;
13895 head_error
.set_head_mismatch();
13897 if (soid
.is_snapdir() && snapset
->head_exists
) {
13898 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13899 << " snapset.head_exists=true, but snapdir exists";
13900 ++scrubber
.shallow_errors
;
13901 head_error
.set_head_mismatch();
13904 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_LUMINOUS
) {
13905 if (soid
.is_snapdir()) {
13906 dout(10) << " will move snapset to head from " << soid
<< dendl
;
13907 snapset_to_repair
[soid
.get_head()] = *snapset
;
13908 } else if (snapset
->is_legacy()) {
13909 dout(10) << " will convert legacy snapset on " << soid
<< " " << *snapset
13911 snapset_to_repair
[soid
.get_head()] = *snapset
;
13914 stat
.num_legacy_snapsets
++;
13917 // pessimistic assumption that this object might contain a
13919 stat
.num_legacy_snapsets
++;
13922 assert(soid
.is_snap());
13925 assert(soid
.snap
== *curclone
);
13927 dout(20) << __func__
<< " " << mode
<< " matched clone " << soid
<< dendl
;
13929 if (snapset
->clone_size
.count(soid
.snap
) == 0) {
13930 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13931 << " is missing in clone_size";
13932 ++scrubber
.shallow_errors
;
13933 soid_error
.set_size_mismatch();
13935 if (oi
&& oi
->size
!= snapset
->clone_size
[soid
.snap
]) {
13936 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13937 << " size " << oi
->size
<< " != clone_size "
13938 << snapset
->clone_size
[*curclone
];
13939 ++scrubber
.shallow_errors
;
13940 soid_error
.set_size_mismatch();
13943 if (snapset
->clone_overlap
.count(soid
.snap
) == 0) {
13944 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13945 << " is missing in clone_overlap";
13946 ++scrubber
.shallow_errors
;
13947 soid_error
.set_size_mismatch();
13949 // This checking is based on get_clone_bytes(). The first 2 asserts
13950 // can't happen because we know we have a clone_size and
13951 // a clone_overlap. Now we check that the interval_set won't
13952 // cause the last assert.
13953 uint64_t size
= snapset
->clone_size
.find(soid
.snap
)->second
;
13954 const interval_set
<uint64_t> &overlap
=
13955 snapset
->clone_overlap
.find(soid
.snap
)->second
;
13956 bool bad_interval_set
= false;
13957 for (interval_set
<uint64_t>::const_iterator i
= overlap
.begin();
13958 i
!= overlap
.end(); ++i
) {
13959 if (size
< i
.get_len()) {
13960 bad_interval_set
= true;
13963 size
-= i
.get_len();
13966 if (bad_interval_set
) {
13967 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13968 << " bad interval_set in clone_overlap";
13969 ++scrubber
.shallow_errors
;
13970 soid_error
.set_size_mismatch();
13972 stat
.num_bytes
+= snapset
->get_clone_bytes(soid
.snap
);
13977 // migrate legacy_snaps to snapset?
13978 auto p
= snapset_to_repair
.find(soid
.get_head());
13979 if (p
!= snapset_to_repair
.end()) {
13980 if (!oi
|| oi
->legacy_snaps
.empty()) {
13981 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13982 << " has no oi or legacy_snaps; cannot convert "
13984 ++scrubber
.shallow_errors
;
13986 dout(20) << __func__
<< " copying legacy_snaps " << oi
->legacy_snaps
13987 << " to snapset " << p
->second
<< dendl
;
13988 p
->second
.clone_snaps
[soid
.snap
] = oi
->legacy_snaps
;
13994 if (soid_error
.errors
)
13995 scrubber
.store
->add_snap_error(pool
.id
, soid_error
);
13998 scrub_cstat
.add(stat
);
14001 if (doing_clones(snapset
, curclone
)) {
14002 dout(10) << __func__
<< " " << mode
<< " " << info
.pgid
14003 << " No more objects while processing " << head
.get() << dendl
;
14005 missing
+= process_clones_to(head
, snapset
, osd
->clog
, info
.pgid
, mode
,
14006 pool
.info
.allow_incomplete_clones(), all_clones
, &curclone
,
14009 // There could be missing found by the test above or even
14010 // before dropping out of the loop for the last head.
14012 log_missing(missing
, head
, osd
->clog
, info
.pgid
, __func__
,
14013 mode
, pool
.info
.allow_incomplete_clones());
14015 if (head
&& head_error
.errors
)
14016 scrubber
.store
->add_snap_error(pool
.id
, head_error
);
14018 for (map
<hobject_t
,pair
<uint32_t,uint32_t>>::const_iterator p
=
14019 missing_digest
.begin();
14020 p
!= missing_digest
.end();
14022 if (p
->first
.is_snapdir())
14024 dout(10) << __func__
<< " recording digests for " << p
->first
<< dendl
;
14025 ObjectContextRef obc
= get_object_context(p
->first
, false);
14027 osd
->clog
->error() << info
.pgid
<< " " << mode
14028 << " cannot get object context for object "
14031 } else if (obc
->obs
.oi
.soid
!= p
->first
) {
14032 osd
->clog
->error() << info
.pgid
<< " " << mode
14033 << " object " << p
->first
14034 << " has a valid oi attr with a mismatched name, "
14035 << " obc->obs.oi.soid: " << obc
->obs
.oi
.soid
;
14038 OpContextUPtr ctx
= simple_opc_create(obc
);
14039 ctx
->at_version
= get_next_version();
14040 ctx
->mtime
= utime_t(); // do not update mtime
14041 ctx
->new_obs
.oi
.set_data_digest(p
->second
.first
);
14042 ctx
->new_obs
.oi
.set_omap_digest(p
->second
.second
);
14043 finish_ctx(ctx
.get(), pg_log_entry_t::MODIFY
);
14045 ctx
->register_on_success(
14047 dout(20) << "updating scrub digest" << dendl
;
14048 if (--scrubber
.num_digest_updates_pending
== 0) {
14053 simple_opc_submit(std::move(ctx
));
14054 ++scrubber
.num_digest_updates_pending
;
14056 for (auto& p
: snapset_to_repair
) {
14057 // cache pools may not have the clones, which means we won't know
14058 // what snaps they have. fake out the clone_snaps entries anyway (with
14059 // blank snap lists).
14060 p
.second
.head_exists
= true;
14061 if (pool
.info
.allow_incomplete_clones()) {
14062 for (auto s
: p
.second
.clones
) {
14063 if (p
.second
.clone_snaps
.count(s
) == 0) {
14064 dout(10) << __func__
<< " " << p
.first
<< " faking clone_snaps for "
14066 p
.second
.clone_snaps
[s
];
14070 if (p
.second
.clones
.size() != p
.second
.clone_snaps
.size() ||
14071 p
.second
.is_legacy()) {
14072 // this happens if we encounter other errors above, like a missing
14074 dout(10) << __func__
<< " not writing snapset to " << p
.first
14075 << " snapset " << p
.second
<< " clones " << p
.second
.clones
14076 << "; didn't convert fully" << dendl
;
14077 scrub_cstat
.sum
.num_legacy_snapsets
++;
14080 dout(10) << __func__
<< " writing snapset to " << p
.first
14081 << " " << p
.second
<< dendl
;
14082 ObjectContextRef obc
= get_object_context(p
.first
, true);
14084 osd
->clog
->error() << info
.pgid
<< " " << mode
14085 << " cannot get object context for object "
14088 } else if (obc
->obs
.oi
.soid
!= p
.first
) {
14089 osd
->clog
->error() << info
.pgid
<< " " << mode
14090 << " object " << p
.first
14091 << " has a valid oi attr with a mismatched name, "
14092 << " obc->obs.oi.soid: " << obc
->obs
.oi
.soid
;
14095 ObjectContextRef snapset_obc
;
14096 if (!obc
->obs
.exists
) {
14097 snapset_obc
= get_object_context(p
.first
.get_snapdir(), false);
14098 if (!snapset_obc
) {
14099 osd
->clog
->error() << info
.pgid
<< " " << mode
14100 << " cannot get object context for "
14101 << p
.first
.get_snapdir();
14105 OpContextUPtr ctx
= simple_opc_create(obc
);
14106 PGTransaction
*t
= ctx
->op_t
.get();
14107 ctx
->snapset_obc
= snapset_obc
;
14108 ctx
->at_version
= get_next_version();
14109 ctx
->mtime
= utime_t(); // do not update mtime
14110 ctx
->new_snapset
= p
.second
;
14111 if (!ctx
->new_obs
.exists
) {
14112 dout(20) << __func__
<< " making " << p
.first
<< " a whiteout" << dendl
;
14113 ctx
->new_obs
.exists
= true;
14114 ctx
->new_snapset
.head_exists
= true;
14115 ctx
->new_obs
.oi
.set_flag(object_info_t::FLAG_WHITEOUT
);
14116 ++ctx
->delta_stats
.num_whiteouts
;
14117 ++ctx
->delta_stats
.num_objects
;
14118 t
->create(p
.first
);
14119 if (p
.first
< scrubber
.start
) {
14120 dout(20) << __func__
<< " kludging around update outside of scrub range"
14123 scrub_cstat
.add(ctx
->delta_stats
);
14126 dout(20) << __func__
<< " final snapset " << ctx
->new_snapset
<< dendl
;
14127 assert(!ctx
->new_snapset
.is_legacy());
14128 finish_ctx(ctx
.get(), pg_log_entry_t::MODIFY
);
14129 ctx
->register_on_success(
14131 dout(20) << "updating snapset" << dendl
;
14132 if (--scrubber
.num_digest_updates_pending
== 0) {
14137 simple_opc_submit(std::move(ctx
));
14138 ++scrubber
.num_digest_updates_pending
;
14141 dout(10) << __func__
<< " (" << mode
<< ") finish" << dendl
;
14144 void PrimaryLogPG::_scrub_clear_state()
14146 scrub_cstat
= object_stat_collection_t();
14149 void PrimaryLogPG::_scrub_finish()
14151 bool repair
= state_test(PG_STATE_REPAIR
);
14152 bool deep_scrub
= state_test(PG_STATE_DEEP_SCRUB
);
14153 const char *mode
= (repair
? "repair": (deep_scrub
? "deep-scrub" : "scrub"));
14155 if (info
.stats
.stats_invalid
) {
14156 info
.stats
.stats
= scrub_cstat
;
14157 info
.stats
.stats_invalid
= false;
14160 agent_choose_mode();
14163 dout(10) << mode
<< " got "
14164 << scrub_cstat
.sum
.num_objects
<< "/" << info
.stats
.stats
.sum
.num_objects
<< " objects, "
14165 << scrub_cstat
.sum
.num_object_clones
<< "/" << info
.stats
.stats
.sum
.num_object_clones
<< " clones, "
14166 << scrub_cstat
.sum
.num_objects_dirty
<< "/" << info
.stats
.stats
.sum
.num_objects_dirty
<< " dirty, "
14167 << scrub_cstat
.sum
.num_objects_omap
<< "/" << info
.stats
.stats
.sum
.num_objects_omap
<< " omap, "
14168 << scrub_cstat
.sum
.num_objects_pinned
<< "/" << info
.stats
.stats
.sum
.num_objects_pinned
<< " pinned, "
14169 << scrub_cstat
.sum
.num_objects_hit_set_archive
<< "/" << info
.stats
.stats
.sum
.num_objects_hit_set_archive
<< " hit_set_archive, "
14170 << scrub_cstat
.sum
.num_bytes
<< "/" << info
.stats
.stats
.sum
.num_bytes
<< " bytes, "
14171 << scrub_cstat
.sum
.num_bytes_hit_set_archive
<< "/" << info
.stats
.stats
.sum
.num_bytes_hit_set_archive
<< " hit_set_archive bytes."
14174 if (scrub_cstat
.sum
.num_objects
!= info
.stats
.stats
.sum
.num_objects
||
14175 scrub_cstat
.sum
.num_object_clones
!= info
.stats
.stats
.sum
.num_object_clones
||
14176 (scrub_cstat
.sum
.num_objects_dirty
!= info
.stats
.stats
.sum
.num_objects_dirty
&&
14177 !info
.stats
.dirty_stats_invalid
) ||
14178 (scrub_cstat
.sum
.num_objects_omap
!= info
.stats
.stats
.sum
.num_objects_omap
&&
14179 !info
.stats
.omap_stats_invalid
) ||
14180 (scrub_cstat
.sum
.num_objects_pinned
!= info
.stats
.stats
.sum
.num_objects_pinned
&&
14181 !info
.stats
.pin_stats_invalid
) ||
14182 (scrub_cstat
.sum
.num_objects_hit_set_archive
!= info
.stats
.stats
.sum
.num_objects_hit_set_archive
&&
14183 !info
.stats
.hitset_stats_invalid
) ||
14184 (scrub_cstat
.sum
.num_bytes_hit_set_archive
!= info
.stats
.stats
.sum
.num_bytes_hit_set_archive
&&
14185 !info
.stats
.hitset_bytes_stats_invalid
) ||
14186 scrub_cstat
.sum
.num_whiteouts
!= info
.stats
.stats
.sum
.num_whiteouts
||
14187 scrub_cstat
.sum
.num_bytes
!= info
.stats
.stats
.sum
.num_bytes
) {
14188 osd
->clog
->error() << info
.pgid
<< " " << mode
14189 << " stat mismatch, got "
14190 << scrub_cstat
.sum
.num_objects
<< "/" << info
.stats
.stats
.sum
.num_objects
<< " objects, "
14191 << scrub_cstat
.sum
.num_object_clones
<< "/" << info
.stats
.stats
.sum
.num_object_clones
<< " clones, "
14192 << scrub_cstat
.sum
.num_objects_dirty
<< "/" << info
.stats
.stats
.sum
.num_objects_dirty
<< " dirty, "
14193 << scrub_cstat
.sum
.num_objects_omap
<< "/" << info
.stats
.stats
.sum
.num_objects_omap
<< " omap, "
14194 << scrub_cstat
.sum
.num_objects_pinned
<< "/" << info
.stats
.stats
.sum
.num_objects_pinned
<< " pinned, "
14195 << scrub_cstat
.sum
.num_objects_hit_set_archive
<< "/" << info
.stats
.stats
.sum
.num_objects_hit_set_archive
<< " hit_set_archive, "
14196 << scrub_cstat
.sum
.num_whiteouts
<< "/" << info
.stats
.stats
.sum
.num_whiteouts
<< " whiteouts, "
14197 << scrub_cstat
.sum
.num_bytes
<< "/" << info
.stats
.stats
.sum
.num_bytes
<< " bytes, "
14198 << scrub_cstat
.sum
.num_bytes_hit_set_archive
<< "/" << info
.stats
.stats
.sum
.num_bytes_hit_set_archive
<< " hit_set_archive bytes.";
14199 ++scrubber
.shallow_errors
;
14203 info
.stats
.stats
= scrub_cstat
;
14204 info
.stats
.dirty_stats_invalid
= false;
14205 info
.stats
.omap_stats_invalid
= false;
14206 info
.stats
.hitset_stats_invalid
= false;
14207 info
.stats
.hitset_bytes_stats_invalid
= false;
14208 publish_stats_to_osd();
14211 } else if (scrub_cstat
.sum
.num_legacy_snapsets
!=
14212 info
.stats
.stats
.sum
.num_legacy_snapsets
) {
14213 osd
->clog
->info() << info
.pgid
<< " " << mode
<< " updated num_legacy_snapsets"
14214 << " from " << info
.stats
.stats
.sum
.num_legacy_snapsets
14215 << " -> " << scrub_cstat
.sum
.num_legacy_snapsets
<< "\n";
14216 info
.stats
.stats
.sum
.num_legacy_snapsets
= scrub_cstat
.sum
.num_legacy_snapsets
;
14217 publish_stats_to_osd();
14220 // Clear object context cache to get repair information
14222 object_contexts
.clear();
14225 bool PrimaryLogPG::check_osdmap_full(const set
<pg_shard_t
> &missing_on
)
14227 return osd
->check_osdmap_full(missing_on
);
14230 int PrimaryLogPG::rep_repair_primary_object(const hobject_t
& soid
, OpRequestRef op
)
14232 // Only supports replicated pools
14233 assert(!pool
.info
.require_rollback());
14234 assert(is_primary());
14236 dout(10) << __func__
<< " " << soid
14237 << " peers osd.{" << actingbackfill
<< "}" << dendl
;
14240 block_for_clean(soid
, op
);
14244 assert(!pg_log
.get_missing().is_missing(soid
));
14248 int r
= get_pgbackend()->objects_get_attr(soid
, OI_ATTR
, &bv
);
14250 // Leave v and try to repair without a version, getting attr failed
14251 dout(0) << __func__
<< ": Need version of replica, objects_get_attr failed: "
14252 << soid
<< " error=" << r
<< dendl
;
14254 bufferlist::iterator bliter
= bv
.begin();
14255 ::decode(oi
, bliter
);
14258 // Leave v as default constructed. This will fail when sent to older OSDs, but
14259 // not much worse than failing here.
14260 dout(0) << __func__
<< ": Need version of replica, bad object_info_t: " << soid
<< dendl
;
14263 missing_loc
.add_missing(soid
, v
, eversion_t());
14264 if (primary_error(soid
, v
)) {
14265 dout(0) << __func__
<< " No other replicas available for " << soid
<< dendl
;
14266 // XXX: If we knew that there is no down osd which could include this
14267 // object, it would be nice if we could return EIO here.
14268 // If a "never fail" flag was available, that could be used
14269 // for rbd to NOT return EIO until object marked lost.
14271 // Drop through to save this op in case an osd comes up with the object.
14274 // Restart the op after object becomes readable again
14275 waiting_for_unreadable_object
[soid
].push_back(op
);
14276 op
->mark_delayed("waiting for missing object");
14278 if (!eio_errors_to_process
) {
14279 eio_errors_to_process
= true;
14280 assert(is_clean());
14281 queue_peering_event(
14283 std::make_shared
<CephPeeringEvt
>(
14284 get_osdmap()->get_epoch(),
14285 get_osdmap()->get_epoch(),
14288 // A prior error must have already cleared clean state and queued recovery
14289 // or a map change has triggered re-peering.
14290 // Not inlining the recovery by calling maybe_kick_recovery(soid);
14291 dout(5) << __func__
<< ": Read error on " << soid
<< ", but already seen errors" << dendl
;
14297 /*---SnapTrimmer Logging---*/
14299 #define dout_prefix *_dout << pg->gen_prefix()
14301 void PrimaryLogPG::SnapTrimmer::log_enter(const char *state_name
)
14303 ldout(pg
->cct
, 20) << "enter " << state_name
<< dendl
;
14306 void PrimaryLogPG::SnapTrimmer::log_exit(const char *state_name
, utime_t enter_time
)
14308 ldout(pg
->cct
, 20) << "exit " << state_name
<< dendl
;
14311 /*---SnapTrimmer states---*/
14313 #define dout_prefix (*_dout << context< SnapTrimmer >().pg->gen_prefix() \
14314 << "SnapTrimmer state<" << get_state_name() << ">: ")
14317 PrimaryLogPG::NotTrimming::NotTrimming(my_context ctx
)
14319 NamedState(context
< SnapTrimmer
>().pg
, "NotTrimming")
14321 context
< SnapTrimmer
>().log_enter(state_name
);
14324 void PrimaryLogPG::NotTrimming::exit()
14326 context
< SnapTrimmer
>().log_exit(state_name
, enter_time
);
14329 boost::statechart::result
PrimaryLogPG::NotTrimming::react(const KickTrim
&)
14331 PrimaryLogPG
*pg
= context
< SnapTrimmer
>().pg
;
14332 ldout(pg
->cct
, 10) << "NotTrimming react KickTrim" << dendl
;
14334 if (!(pg
->is_primary() && pg
->is_active())) {
14335 ldout(pg
->cct
, 10) << "NotTrimming not primary or active" << dendl
;
14336 return discard_event();
14338 if (!pg
->is_clean() ||
14339 pg
->snap_trimq
.empty()) {
14340 ldout(pg
->cct
, 10) << "NotTrimming not clean or nothing to trim" << dendl
;
14341 return discard_event();
14343 if (pg
->scrubber
.active
) {
14344 ldout(pg
->cct
, 10) << " scrubbing, will requeue snap_trimmer after" << dendl
;
14345 return transit
< WaitScrub
>();
14347 return transit
< Trimming
>();
14351 boost::statechart::result
PrimaryLogPG::WaitReservation::react(const SnapTrimReserved
&)
14353 PrimaryLogPG
*pg
= context
< SnapTrimmer
>().pg
;
14354 ldout(pg
->cct
, 10) << "WaitReservation react SnapTrimReserved" << dendl
;
14357 if (!context
< SnapTrimmer
>().can_trim()) {
14358 post_event(KickTrim());
14359 return transit
< NotTrimming
>();
14362 context
<Trimming
>().snap_to_trim
= pg
->snap_trimq
.range_start();
14363 ldout(pg
->cct
, 10) << "NotTrimming: trimming "
14364 << pg
->snap_trimq
.range_start()
14366 return transit
< AwaitAsyncWork
>();
14369 /* AwaitAsyncWork */
14370 PrimaryLogPG::AwaitAsyncWork::AwaitAsyncWork(my_context ctx
)
14372 NamedState(context
< SnapTrimmer
>().pg
, "Trimming/AwaitAsyncWork")
14374 auto *pg
= context
< SnapTrimmer
>().pg
;
14375 context
< SnapTrimmer
>().log_enter(state_name
);
14376 context
< SnapTrimmer
>().pg
->osd
->queue_for_snap_trim(pg
);
14377 pg
->state_set(PG_STATE_SNAPTRIM
);
14378 pg
->state_clear(PG_STATE_SNAPTRIM_ERROR
);
14379 pg
->publish_stats_to_osd();
14382 boost::statechart::result
PrimaryLogPG::AwaitAsyncWork::react(const DoSnapWork
&)
14384 PrimaryLogPGRef pg
= context
< SnapTrimmer
>().pg
;
14385 snapid_t snap_to_trim
= context
<Trimming
>().snap_to_trim
;
14386 auto &in_flight
= context
<Trimming
>().in_flight
;
14387 assert(in_flight
.empty());
14389 assert(pg
->is_primary() && pg
->is_active());
14390 if (!context
< SnapTrimmer
>().can_trim()) {
14391 ldout(pg
->cct
, 10) << "something changed, reverting to NotTrimming" << dendl
;
14392 post_event(KickTrim());
14393 return transit
< NotTrimming
>();
14396 ldout(pg
->cct
, 10) << "AwaitAsyncWork: trimming snap " << snap_to_trim
<< dendl
;
14398 vector
<hobject_t
> to_trim
;
14399 unsigned max
= pg
->cct
->_conf
->osd_pg_max_concurrent_snap_trims
;
14400 to_trim
.reserve(max
);
14401 int r
= pg
->snap_mapper
.get_next_objects_to_trim(
14405 if (r
!= 0 && r
!= -ENOENT
) {
14406 lderr(pg
->cct
) << "get_next_objects_to_trim returned "
14407 << cpp_strerror(r
) << dendl
;
14408 assert(0 == "get_next_objects_to_trim returned an invalid code");
14409 } else if (r
== -ENOENT
) {
14411 ldout(pg
->cct
, 10) << "got ENOENT" << dendl
;
14413 ldout(pg
->cct
, 10) << "adding snap " << snap_to_trim
14414 << " to purged_snaps"
14416 pg
->info
.purged_snaps
.insert(snap_to_trim
);
14417 pg
->snap_trimq
.erase(snap_to_trim
);
14418 ldout(pg
->cct
, 10) << "purged_snaps now "
14419 << pg
->info
.purged_snaps
<< ", snap_trimq now "
14420 << pg
->snap_trimq
<< dendl
;
14422 ObjectStore::Transaction t
;
14423 pg
->dirty_big_info
= true;
14424 pg
->write_if_dirty(t
);
14425 int tr
= pg
->osd
->store
->queue_transaction(pg
->osr
.get(), std::move(t
), NULL
);
14428 pg
->share_pg_info();
14429 post_event(KickTrim());
14430 return transit
< NotTrimming
>();
14432 assert(!to_trim
.empty());
14434 for (auto &&object
: to_trim
) {
14436 ldout(pg
->cct
, 10) << "AwaitAsyncWork react trimming " << object
<< dendl
;
14438 int error
= pg
->trim_object(in_flight
.empty(), object
, &ctx
);
14440 if (error
== -ENOLCK
) {
14441 ldout(pg
->cct
, 10) << "could not get write lock on obj "
14442 << object
<< dendl
;
14444 pg
->state_set(PG_STATE_SNAPTRIM_ERROR
);
14445 ldout(pg
->cct
, 10) << "Snaptrim error=" << error
<< dendl
;
14447 if (!in_flight
.empty()) {
14448 ldout(pg
->cct
, 10) << "letting the ones we already started finish" << dendl
;
14449 return transit
< WaitRepops
>();
14451 if (error
== -ENOLCK
) {
14452 ldout(pg
->cct
, 10) << "waiting for it to clear"
14454 return transit
< WaitRWLock
>();
14456 return transit
< NotTrimming
>();
14460 in_flight
.insert(object
);
14461 ctx
->register_on_success(
14462 [pg
, object
, &in_flight
]() {
14463 assert(in_flight
.find(object
) != in_flight
.end());
14464 in_flight
.erase(object
);
14465 if (in_flight
.empty()) {
14466 if (pg
->state_test(PG_STATE_SNAPTRIM_ERROR
)) {
14467 pg
->snap_trimmer_machine
.process_event(Reset());
14469 pg
->snap_trimmer_machine
.process_event(RepopsComplete());
14474 pg
->simple_opc_submit(std::move(ctx
));
14477 return transit
< WaitRepops
>();
14480 void PrimaryLogPG::setattr_maybe_cache(
14481 ObjectContextRef obc
,
14487 t
->setattr(obc
->obs
.oi
.soid
, key
, val
);
14490 void PrimaryLogPG::setattrs_maybe_cache(
14491 ObjectContextRef obc
,
14494 map
<string
, bufferlist
> &attrs
)
14496 t
->setattrs(obc
->obs
.oi
.soid
, attrs
);
14499 void PrimaryLogPG::rmattr_maybe_cache(
14500 ObjectContextRef obc
,
14505 t
->rmattr(obc
->obs
.oi
.soid
, key
);
14508 int PrimaryLogPG::getattr_maybe_cache(
14509 ObjectContextRef obc
,
14513 if (pool
.info
.require_rollback()) {
14514 map
<string
, bufferlist
>::iterator i
= obc
->attr_cache
.find(key
);
14515 if (i
!= obc
->attr_cache
.end()) {
14523 return pgbackend
->objects_get_attr(obc
->obs
.oi
.soid
, key
, val
);
14526 int PrimaryLogPG::getattrs_maybe_cache(
14527 ObjectContextRef obc
,
14528 map
<string
, bufferlist
> *out
,
14532 if (pool
.info
.require_rollback()) {
14534 *out
= obc
->attr_cache
;
14536 r
= pgbackend
->objects_get_attrs(obc
->obs
.oi
.soid
, out
);
14538 if (out
&& user_only
) {
14539 map
<string
, bufferlist
> tmp
;
14540 for (map
<string
, bufferlist
>::iterator i
= out
->begin();
14543 if (i
->first
.size() > 1 && i
->first
[0] == '_')
14544 tmp
[i
->first
.substr(1, i
->first
.size())].claim(i
->second
);
14551 bool PrimaryLogPG::check_failsafe_full(ostream
&ss
) {
14552 return osd
->check_failsafe_full(ss
);
14555 void intrusive_ptr_add_ref(PrimaryLogPG
*pg
) { pg
->get("intptr"); }
14556 void intrusive_ptr_release(PrimaryLogPG
*pg
) { pg
->put("intptr"); }
14558 #ifdef PG_DEBUG_REFS
14559 uint64_t get_with_id(PrimaryLogPG
*pg
) { return pg
->get_with_id(); }
14560 void put_with_id(PrimaryLogPG
*pg
, uint64_t id
) { return pg
->put_with_id(id
); }
14563 void intrusive_ptr_add_ref(PrimaryLogPG::RepGather
*repop
) { repop
->get(); }
14564 void intrusive_ptr_release(PrimaryLogPG::RepGather
*repop
) { repop
->put(); }