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");
1658 osd
->request_osdmap_update(op
->min_epoch
);
1662 if (can_discard_request(op
)) {
1667 const Message
*m
= op
->get_req();
1668 if (m
->get_connection()->has_feature(CEPH_FEATURE_RADOS_BACKOFF
)) {
1669 SessionRef session
= static_cast<Session
*>(m
->get_connection()->get_priv());
1672 session
->put(); // get_priv takes a ref, and so does the SessionRef
1674 if (op
->get_req()->get_type() == CEPH_MSG_OSD_OP
) {
1675 if (session
->check_backoff(cct
, info
.pgid
,
1676 info
.pgid
.pgid
.get_hobj_start(), m
)) {
1683 (!is_active() && is_peered());
1684 if (g_conf
->osd_backoff_on_peering
&& !backoff
) {
1690 add_pg_backoff(session
);
1694 // pg backoff acks at pg-level
1695 if (op
->get_req()->get_type() == CEPH_MSG_OSD_BACKOFF
) {
1696 const MOSDBackoff
*ba
= static_cast<const MOSDBackoff
*>(m
);
1697 if (ba
->begin
!= ba
->end
) {
1704 if (flushes_in_progress
> 0) {
1705 dout(20) << flushes_in_progress
1706 << " flushes_in_progress pending "
1707 << "waiting for active on " << op
<< dendl
;
1708 waiting_for_peered
.push_back(op
);
1709 op
->mark_delayed("waiting for peered");
1714 // Delay unless PGBackend says it's ok
1715 if (pgbackend
->can_handle_while_inactive(op
)) {
1716 bool handled
= pgbackend
->handle_message(op
);
1720 waiting_for_peered
.push_back(op
);
1721 op
->mark_delayed("waiting for peered");
1726 assert(is_peered() && flushes_in_progress
== 0);
1727 if (pgbackend
->handle_message(op
))
1730 switch (op
->get_req()->get_type()) {
1731 case CEPH_MSG_OSD_OP
:
1732 case CEPH_MSG_OSD_BACKOFF
:
1734 dout(20) << " peered, not active, waiting for active on " << op
<< dendl
;
1735 waiting_for_active
.push_back(op
);
1736 op
->mark_delayed("waiting for active");
1739 switch (op
->get_req()->get_type()) {
1740 case CEPH_MSG_OSD_OP
:
1741 // verify client features
1742 if ((pool
.info
.has_tiers() || pool
.info
.is_tier()) &&
1743 !op
->has_feature(CEPH_FEATURE_OSD_CACHEPOOL
)) {
1744 osd
->reply_op_error(op
, -EOPNOTSUPP
);
1749 case CEPH_MSG_OSD_BACKOFF
:
1750 // object-level backoff acks handled in osdop context
1760 case MSG_OSD_SUBOPREPLY
:
1761 do_sub_op_reply(op
);
1764 case MSG_OSD_PG_SCAN
:
1765 do_scan(op
, handle
);
1768 case MSG_OSD_PG_BACKFILL
:
1772 case MSG_OSD_PG_BACKFILL_REMOVE
:
1773 do_backfill_remove(op
);
1776 case MSG_OSD_SCRUB_RESERVE
:
1778 const MOSDScrubReserve
*m
=
1779 static_cast<const MOSDScrubReserve
*>(op
->get_req());
1781 case MOSDScrubReserve::REQUEST
:
1782 handle_scrub_reserve_request(op
);
1784 case MOSDScrubReserve::GRANT
:
1785 handle_scrub_reserve_grant(op
, m
->from
);
1787 case MOSDScrubReserve::REJECT
:
1788 handle_scrub_reserve_reject(op
, m
->from
);
1790 case MOSDScrubReserve::RELEASE
:
1791 handle_scrub_reserve_release(op
);
1797 case MSG_OSD_REP_SCRUB
:
1798 replica_scrub(op
, handle
);
1801 case MSG_OSD_REP_SCRUBMAP
:
1802 do_replica_scrub_map(op
);
1805 case MSG_OSD_PG_UPDATE_LOG_MISSING
:
1806 do_update_log_missing(op
);
1809 case MSG_OSD_PG_UPDATE_LOG_MISSING_REPLY
:
1810 do_update_log_missing_reply(op
);
1814 assert(0 == "bad message type in do_request");
1818 hobject_t
PrimaryLogPG::earliest_backfill() const
1820 hobject_t e
= hobject_t::get_max();
1821 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
1822 i
!= backfill_targets
.end();
1825 map
<pg_shard_t
, pg_info_t
>::const_iterator iter
= peer_info
.find(bt
);
1826 assert(iter
!= peer_info
.end());
1827 if (iter
->second
.last_backfill
< e
)
1828 e
= iter
->second
.last_backfill
;
1833 /** do_op - do an op
1834 * pg lock will be held (if multithreaded)
1835 * osd_lock NOT held.
1837 void PrimaryLogPG::do_op(OpRequestRef
& op
)
1840 // NOTE: take a non-const pointer here; we must be careful not to
1841 // change anything that will break other reads on m (operator<<).
1842 MOSDOp
*m
= static_cast<MOSDOp
*>(op
->get_nonconst_req());
1843 assert(m
->get_type() == CEPH_MSG_OSD_OP
);
1844 if (m
->finish_decode()) {
1845 op
->reset_desc(); // for TrackedOp
1849 dout(20) << __func__
<< ": op " << *m
<< dendl
;
1851 hobject_t head
= m
->get_hobj();
1852 head
.snap
= CEPH_NOSNAP
;
1854 if (!info
.pgid
.pgid
.contains(
1855 info
.pgid
.pgid
.get_split_bits(pool
.info
.get_pg_num()), head
)) {
1856 derr
<< __func__
<< " " << info
.pgid
.pgid
<< " does not contain "
1857 << head
<< " pg_num " << pool
.info
.get_pg_num() << " hash "
1858 << std::hex
<< head
.get_hash() << std::dec
<< dendl
;
1859 osd
->clog
->warn() << info
.pgid
.pgid
<< " does not contain " << head
1861 assert(!cct
->_conf
->osd_debug_misdirected_ops
);
1866 m
->get_connection()->has_feature(CEPH_FEATURE_RADOS_BACKOFF
);
1869 session
= static_cast<Session
*>(m
->get_connection()->get_priv());
1870 if (!session
.get()) {
1871 dout(10) << __func__
<< " no session" << dendl
;
1874 session
->put(); // get_priv() takes a ref, and so does the intrusive_ptr
1876 if (session
->check_backoff(cct
, info
.pgid
, head
, m
)) {
1881 if (m
->has_flag(CEPH_OSD_FLAG_PARALLELEXEC
)) {
1883 dout(20) << __func__
<< ": PARALLELEXEC not implemented " << *m
<< dendl
;
1884 osd
->reply_op_error(op
, -EINVAL
);
1888 if (op
->rmw_flags
== 0) {
1889 int r
= osd
->osd
->init_op_flags(op
);
1891 osd
->reply_op_error(op
, r
);
1896 if ((m
->get_flags() & (CEPH_OSD_FLAG_BALANCE_READS
|
1897 CEPH_OSD_FLAG_LOCALIZE_READS
)) &&
1899 !(op
->may_write() || op
->may_cache())) {
1900 // balanced reads; any replica will do
1901 if (!(is_primary() || is_replica())) {
1902 osd
->handle_misdirected_op(this, op
);
1906 // normal case; must be primary
1907 if (!is_primary()) {
1908 osd
->handle_misdirected_op(this, op
);
1913 if (!op_has_sufficient_caps(op
)) {
1914 osd
->reply_op_error(op
, -EPERM
);
1918 if (op
->includes_pg_op()) {
1919 return do_pg_op(op
);
1922 // object name too long?
1923 if (m
->get_oid().name
.size() > cct
->_conf
->osd_max_object_name_len
) {
1924 dout(4) << "do_op name is longer than "
1925 << cct
->_conf
->osd_max_object_name_len
1926 << " bytes" << dendl
;
1927 osd
->reply_op_error(op
, -ENAMETOOLONG
);
1930 if (m
->get_hobj().get_key().size() > cct
->_conf
->osd_max_object_name_len
) {
1931 dout(4) << "do_op locator is longer than "
1932 << cct
->_conf
->osd_max_object_name_len
1933 << " bytes" << dendl
;
1934 osd
->reply_op_error(op
, -ENAMETOOLONG
);
1937 if (m
->get_hobj().nspace
.size() > cct
->_conf
->osd_max_object_namespace_len
) {
1938 dout(4) << "do_op namespace is longer than "
1939 << cct
->_conf
->osd_max_object_namespace_len
1940 << " bytes" << dendl
;
1941 osd
->reply_op_error(op
, -ENAMETOOLONG
);
1945 if (int r
= osd
->store
->validate_hobject_key(head
)) {
1946 dout(4) << "do_op object " << head
<< " invalid for backing store: "
1948 osd
->reply_op_error(op
, r
);
1953 if (get_osdmap()->is_blacklisted(m
->get_source_addr())) {
1954 dout(10) << "do_op " << m
->get_source_addr() << " is blacklisted" << dendl
;
1955 osd
->reply_op_error(op
, -EBLACKLISTED
);
1959 // order this op as a write?
1960 bool write_ordered
= op
->rwordered();
1962 // discard due to cluster full transition? (we discard any op that
1963 // originates before the cluster or pool is marked full; the client
1964 // will resend after the full flag is removed or if they expect the
1965 // op to succeed despite being full). The except is FULL_FORCE and
1966 // FULL_TRY ops, which there is no reason to discard because they
1967 // bypass all full checks anyway. If this op isn't write or
1968 // read-ordered, we skip.
1969 // FIXME: we exclude mds writes for now.
1970 if (write_ordered
&& !(m
->get_source().is_mds() ||
1971 m
->has_flag(CEPH_OSD_FLAG_FULL_TRY
) ||
1972 m
->has_flag(CEPH_OSD_FLAG_FULL_FORCE
)) &&
1973 info
.history
.last_epoch_marked_full
> m
->get_map_epoch()) {
1974 dout(10) << __func__
<< " discarding op sent before full " << m
<< " "
1978 // mds should have stopped writing before this point.
1979 // We can't allow OSD to become non-startable even if mds
1980 // could be writing as part of file removals.
1982 if (write_ordered
&& osd
->check_failsafe_full(ss
)) {
1983 dout(10) << __func__
<< " fail-safe full check failed, dropping request"
1988 int64_t poolid
= get_pgid().pool();
1989 if (op
->may_write()) {
1991 const pg_pool_t
*pi
= get_osdmap()->get_pg_pool(poolid
);
1997 if (m
->get_snapid() != CEPH_NOSNAP
) {
1998 dout(20) << __func__
<< ": write to clone not valid " << *m
<< dendl
;
1999 osd
->reply_op_error(op
, -EINVAL
);
2004 if (cct
->_conf
->osd_max_write_size
&&
2005 m
->get_data_len() > cct
->_conf
->osd_max_write_size
<< 20) {
2006 // journal can't hold commit!
2007 derr
<< "do_op msg data len " << m
->get_data_len()
2008 << " > osd_max_write_size " << (cct
->_conf
->osd_max_write_size
<< 20)
2009 << " on " << *m
<< dendl
;
2010 osd
->reply_op_error(op
, -OSD_WRITETOOBIG
);
2015 dout(10) << "do_op " << *m
2016 << (op
->may_write() ? " may_write" : "")
2017 << (op
->may_read() ? " may_read" : "")
2018 << (op
->may_cache() ? " may_cache" : "")
2019 << " -> " << (write_ordered
? "write-ordered" : "read-ordered")
2020 << " flags " << ceph_osd_flag_string(m
->get_flags())
2024 if (is_unreadable_object(head
)) {
2025 if (!is_primary()) {
2026 osd
->reply_op_error(op
, -EAGAIN
);
2030 (g_conf
->osd_backoff_on_degraded
||
2031 (g_conf
->osd_backoff_on_unfound
&& missing_loc
.is_unfound(head
)))) {
2032 add_backoff(session
, head
, head
);
2033 maybe_kick_recovery(head
);
2035 wait_for_unreadable_object(head
, op
);
2041 if (write_ordered
&& is_degraded_or_backfilling_object(head
)) {
2042 if (can_backoff
&& g_conf
->osd_backoff_on_degraded
) {
2043 add_backoff(session
, head
, head
);
2045 wait_for_degraded_object(head
, op
);
2050 if (write_ordered
&&
2051 scrubber
.write_blocked_by_scrub(head
)) {
2052 dout(20) << __func__
<< ": waiting for scrub" << dendl
;
2053 waiting_for_scrub
.push_back(op
);
2054 op
->mark_delayed("waiting for scrub");
2059 map
<hobject_t
, snapid_t
>::iterator blocked_iter
=
2060 objects_blocked_on_degraded_snap
.find(head
);
2061 if (write_ordered
&& blocked_iter
!= objects_blocked_on_degraded_snap
.end()) {
2062 hobject_t
to_wait_on(head
);
2063 to_wait_on
.snap
= blocked_iter
->second
;
2064 wait_for_degraded_object(to_wait_on
, op
);
2067 map
<hobject_t
, ObjectContextRef
>::iterator blocked_snap_promote_iter
=
2068 objects_blocked_on_snap_promotion
.find(head
);
2069 if (write_ordered
&&
2070 blocked_snap_promote_iter
!= objects_blocked_on_snap_promotion
.end()) {
2071 wait_for_blocked_object(
2072 blocked_snap_promote_iter
->second
->obs
.oi
.soid
,
2076 if (write_ordered
&& objects_blocked_on_cache_full
.count(head
)) {
2077 block_write_on_full_cache(head
, op
);
2082 hobject_t snapdir
= head
.get_snapdir();
2084 if (is_unreadable_object(snapdir
)) {
2085 wait_for_unreadable_object(snapdir
, op
);
2090 if (write_ordered
&& is_degraded_or_backfilling_object(snapdir
)) {
2091 wait_for_degraded_object(snapdir
, op
);
2096 if (op
->may_write() || op
->may_cache()) {
2097 // warning: we will get back *a* request for this reqid, but not
2098 // necessarily the most recent. this happens with flush and
2099 // promote ops, but we can't possible have both in our log where
2100 // the original request is still not stable on disk, so for our
2101 // purposes here it doesn't matter which one we get.
2103 version_t user_version
;
2104 int return_code
= 0;
2105 bool got
= check_in_progress_op(
2106 m
->get_reqid(), &version
, &user_version
, &return_code
);
2108 dout(3) << __func__
<< " dup " << m
->get_reqid()
2109 << " version " << version
<< dendl
;
2110 if (already_complete(version
)) {
2111 osd
->reply_op_error(op
, return_code
, version
, user_version
);
2113 dout(10) << " waiting for " << version
<< " to commit" << dendl
;
2114 // always queue ondisk waiters, so that we can requeue if needed
2115 waiting_for_ondisk
[version
].push_back(make_pair(op
, user_version
));
2116 op
->mark_delayed("waiting for ondisk");
2122 ObjectContextRef obc
;
2123 bool can_create
= op
->may_write() || op
->may_cache();
2124 hobject_t missing_oid
;
2125 const hobject_t
& oid
= m
->get_hobj();
2127 // io blocked on obc?
2128 if (!m
->has_flag(CEPH_OSD_FLAG_FLUSH
) &&
2129 maybe_await_blocked_snapset(oid
, op
)) {
2133 int r
= find_object_context(
2134 oid
, &obc
, can_create
,
2135 m
->has_flag(CEPH_OSD_FLAG_MAP_SNAP_CLONE
),
2139 // If we're not the primary of this OSD, we just return -EAGAIN. Otherwise,
2140 // we have to wait for the object.
2142 // missing the specific snap we need; requeue and wait.
2143 assert(!op
->may_write()); // only happens on a read/cache
2144 wait_for_unreadable_object(missing_oid
, op
);
2147 } else if (r
== 0) {
2148 if (is_unreadable_object(obc
->obs
.oi
.soid
)) {
2149 dout(10) << __func__
<< ": clone " << obc
->obs
.oi
.soid
2150 << " is unreadable, waiting" << dendl
;
2151 wait_for_unreadable_object(obc
->obs
.oi
.soid
, op
);
2155 // degraded object? (the check above was for head; this could be a clone)
2156 if (write_ordered
&&
2157 obc
->obs
.oi
.soid
.snap
!= CEPH_NOSNAP
&&
2158 is_degraded_or_backfilling_object(obc
->obs
.oi
.soid
)) {
2159 dout(10) << __func__
<< ": clone " << obc
->obs
.oi
.soid
2160 << " is degraded, waiting" << dendl
;
2161 wait_for_degraded_object(obc
->obs
.oi
.soid
, op
);
2166 bool in_hit_set
= false;
2169 if (obc
->obs
.oi
.soid
!= hobject_t() && hit_set
->contains(obc
->obs
.oi
.soid
))
2172 if (missing_oid
!= hobject_t() && hit_set
->contains(missing_oid
))
2175 if (!op
->hitset_inserted
) {
2176 hit_set
->insert(oid
);
2177 op
->hitset_inserted
= true;
2178 if (hit_set
->is_full() ||
2179 hit_set_start_stamp
+ pool
.info
.hit_set_period
<= m
->get_recv_stamp()) {
2186 if (agent_choose_mode(false, op
))
2190 if (obc
.get() && obc
->obs
.exists
&& obc
->obs
.oi
.has_manifest()) {
2191 if (maybe_handle_manifest(op
,
2197 if (maybe_handle_cache(op
,
2206 if (r
&& (r
!= -ENOENT
|| !obc
)) {
2207 // copy the reqids for copy get on ENOENT
2209 (m
->ops
[0].op
.op
== CEPH_OSD_OP_COPY_GET
)) {
2210 fill_in_copy_get_noent(op
, oid
, m
->ops
[0]);
2213 dout(20) << __func__
<< ": find_object_context got error " << r
<< dendl
;
2214 if (op
->may_write() &&
2215 get_osdmap()->require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
2216 record_write_error(op
, oid
, nullptr, r
);
2218 osd
->reply_op_error(op
, r
);
2223 // make sure locator is consistent
2224 object_locator_t
oloc(obc
->obs
.oi
.soid
);
2225 if (m
->get_object_locator() != oloc
) {
2226 dout(10) << " provided locator " << m
->get_object_locator()
2227 << " != object's " << obc
->obs
.oi
.soid
<< dendl
;
2228 osd
->clog
->warn() << "bad locator " << m
->get_object_locator()
2229 << " on object " << oloc
2233 // io blocked on obc?
2234 if (obc
->is_blocked() &&
2235 !m
->has_flag(CEPH_OSD_FLAG_FLUSH
)) {
2236 wait_for_blocked_object(obc
->obs
.oi
.soid
, op
);
2240 dout(25) << __func__
<< " oi " << obc
->obs
.oi
<< dendl
;
2242 for (vector
<OSDOp
>::iterator p
= m
->ops
.begin(); p
!= m
->ops
.end(); ++p
) {
2245 // make sure LIST_SNAPS is on CEPH_SNAPDIR and nothing else
2246 if (osd_op
.op
.op
== CEPH_OSD_OP_LIST_SNAPS
&&
2247 m
->get_snapid() != CEPH_SNAPDIR
) {
2248 dout(10) << "LIST_SNAPS with incorrect context" << dendl
;
2249 osd
->reply_op_error(op
, -EINVAL
);
2254 OpContext
*ctx
= new OpContext(op
, m
->get_reqid(), &m
->ops
, obc
, this);
2256 if (!obc
->obs
.exists
)
2257 ctx
->snapset_obc
= get_object_context(obc
->obs
.oi
.soid
.get_snapdir(), false);
2259 /* Due to obc caching, we might have a cached non-existent snapset_obc
2260 * for the snapdir. If so, we can ignore it. Subsequent parts of the
2261 * do_op pipeline make decisions based on whether snapset_obc is
2264 if (ctx
->snapset_obc
&& !ctx
->snapset_obc
->obs
.exists
)
2265 ctx
->snapset_obc
= ObjectContextRef();
2267 if (m
->has_flag(CEPH_OSD_FLAG_SKIPRWLOCKS
)) {
2268 dout(20) << __func__
<< ": skipping rw locks" << dendl
;
2269 } else if (m
->get_flags() & CEPH_OSD_FLAG_FLUSH
) {
2270 dout(20) << __func__
<< ": part of flush, will ignore write lock" << dendl
;
2272 // verify there is in fact a flush in progress
2273 // FIXME: we could make this a stronger test.
2274 map
<hobject_t
,FlushOpRef
>::iterator p
= flush_ops
.find(obc
->obs
.oi
.soid
);
2275 if (p
== flush_ops
.end()) {
2276 dout(10) << __func__
<< " no flush in progress, aborting" << dendl
;
2277 reply_ctx(ctx
, -EINVAL
);
2280 } else if (!get_rw_locks(write_ordered
, ctx
)) {
2281 dout(20) << __func__
<< " waiting for rw locks " << dendl
;
2282 op
->mark_delayed("waiting for rw locks");
2286 dout(20) << __func__
<< " obc " << *obc
<< dendl
;
2289 dout(20) << __func__
<< " returned an error: " << r
<< dendl
;
2291 if (op
->may_write() &&
2292 get_osdmap()->require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
2293 record_write_error(op
, oid
, nullptr, r
);
2295 osd
->reply_op_error(op
, r
);
2300 if (m
->has_flag(CEPH_OSD_FLAG_IGNORE_CACHE
)) {
2301 ctx
->ignore_cache
= true;
2304 if ((op
->may_read()) && (obc
->obs
.oi
.is_lost())) {
2305 // This object is lost. Reading from it returns an error.
2306 dout(20) << __func__
<< ": object " << obc
->obs
.oi
.soid
2307 << " is lost" << dendl
;
2308 reply_ctx(ctx
, -ENFILE
);
2311 if (!op
->may_write() &&
2313 (!obc
->obs
.exists
||
2314 ((m
->get_snapid() != CEPH_SNAPDIR
) &&
2315 obc
->obs
.oi
.is_whiteout()))) {
2316 // copy the reqids for copy get on ENOENT
2317 if (m
->ops
[0].op
.op
== CEPH_OSD_OP_COPY_GET
) {
2318 fill_in_copy_get_noent(op
, oid
, m
->ops
[0]);
2322 reply_ctx(ctx
, -ENOENT
);
2329 utime_t prepare_latency
= ceph_clock_now();
2330 prepare_latency
-= op
->get_dequeued_time();
2331 osd
->logger
->tinc(l_osd_op_prepare_lat
, prepare_latency
);
2332 if (op
->may_read() && op
->may_write()) {
2333 osd
->logger
->tinc(l_osd_op_rw_prepare_lat
, prepare_latency
);
2334 } else if (op
->may_read()) {
2335 osd
->logger
->tinc(l_osd_op_r_prepare_lat
, prepare_latency
);
2336 } else if (op
->may_write() || op
->may_cache()) {
2337 osd
->logger
->tinc(l_osd_op_w_prepare_lat
, prepare_latency
);
2340 // force recovery of the oldest missing object if too many logs
2341 maybe_force_recovery();
2343 PrimaryLogPG::cache_result_t
PrimaryLogPG::maybe_handle_manifest_detail(
2346 ObjectContextRef obc
)
2348 if (static_cast<const MOSDOp
*>(op
->get_req())->get_flags() &
2349 CEPH_OSD_FLAG_IGNORE_REDIRECT
) {
2350 dout(20) << __func__
<< ": ignoring redirect due to flag" << dendl
;
2351 return cache_result_t::NOOP
;
2355 dout(10) << __func__
<< " " << obc
->obs
.oi
<< " "
2356 << (obc
->obs
.exists
? "exists" : "DNE")
2359 // if it is write-ordered and blocked, stop now
2360 if (obc
.get() && obc
->is_blocked() && write_ordered
) {
2361 // we're already doing something with this object
2362 dout(20) << __func__
<< " blocked on " << obc
->obs
.oi
.soid
<< dendl
;
2363 return cache_result_t::NOOP
;
2366 vector
<OSDOp
> ops
= static_cast<const MOSDOp
*>(op
->get_req())->ops
;
2367 for (vector
<OSDOp
>::iterator p
= ops
.begin(); p
!= ops
.end(); ++p
) {
2369 ceph_osd_op
& op
= osd_op
.op
;
2370 if (op
.op
== CEPH_OSD_OP_SET_REDIRECT
) {
2371 return cache_result_t::NOOP
;
2375 switch (obc
->obs
.oi
.manifest
.type
) {
2376 case object_manifest_t::TYPE_REDIRECT
:
2377 if (op
->may_write() || write_ordered
) {
2378 do_proxy_write(op
, obc
->obs
.oi
.soid
, obc
);
2380 do_proxy_read(op
, obc
);
2382 return cache_result_t::HANDLED_PROXY
;
2383 case object_manifest_t::TYPE_CHUNKED
:
2385 assert(0 == "unrecognized manifest type");
2388 return cache_result_t::NOOP
;
2391 void PrimaryLogPG::record_write_error(OpRequestRef op
, const hobject_t
&soid
,
2392 MOSDOpReply
*orig_reply
, int r
)
2394 dout(20) << __func__
<< " r=" << r
<< dendl
;
2395 assert(op
->may_write());
2396 const osd_reqid_t
&reqid
= static_cast<const MOSDOp
*>(op
->get_req())->get_reqid();
2397 ObjectContextRef obc
;
2398 mempool::osd_pglog::list
<pg_log_entry_t
> entries
;
2399 entries
.push_back(pg_log_entry_t(pg_log_entry_t::ERROR
, soid
,
2400 get_next_version(), eversion_t(), 0,
2401 reqid
, utime_t(), r
));
2406 boost::intrusive_ptr
<MOSDOpReply
> orig_reply
;
2411 MOSDOpReply
*orig_reply
,
2414 orig_reply(orig_reply
, false /* take over ref */), r(r
)
2417 ldpp_dout(pg
, 20) << "finished " << __func__
<< " r=" << r
<< dendl
;
2418 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
2419 int flags
= m
->get_flags() & (CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
2420 MOSDOpReply
*reply
= orig_reply
.detach();
2421 if (reply
== nullptr) {
2422 reply
= new MOSDOpReply(m
, r
, pg
->get_osdmap()->get_epoch(),
2425 ldpp_dout(pg
, 10) << " sending commit on " << *m
<< " " << reply
<< dendl
;
2426 pg
->osd
->send_message_osd_client(reply
, m
->get_connection());
2430 ObcLockManager lock_manager
;
2433 std::move(lock_manager
),
2434 boost::optional
<std::function
<void(void)> >(
2435 OnComplete(this, op
, orig_reply
, r
)),
2440 PrimaryLogPG::cache_result_t
PrimaryLogPG::maybe_handle_cache_detail(
2443 ObjectContextRef obc
,
2444 int r
, hobject_t missing_oid
,
2447 ObjectContextRef
*promote_obc
)
2451 op
->get_req()->get_type() == CEPH_MSG_OSD_OP
&&
2452 (static_cast<const MOSDOp
*>(op
->get_req())->get_flags() &
2453 CEPH_OSD_FLAG_IGNORE_CACHE
)) {
2454 dout(20) << __func__
<< ": ignoring cache due to flag" << dendl
;
2455 return cache_result_t::NOOP
;
2457 // return quickly if caching is not enabled
2458 if (pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
)
2459 return cache_result_t::NOOP
;
2461 must_promote
= must_promote
|| op
->need_promote();
2464 dout(25) << __func__
<< " " << obc
->obs
.oi
<< " "
2465 << (obc
->obs
.exists
? "exists" : "DNE")
2466 << " missing_oid " << missing_oid
2467 << " must_promote " << (int)must_promote
2468 << " in_hit_set " << (int)in_hit_set
2471 dout(25) << __func__
<< " (no obc)"
2472 << " missing_oid " << missing_oid
2473 << " must_promote " << (int)must_promote
2474 << " in_hit_set " << (int)in_hit_set
2477 // if it is write-ordered and blocked, stop now
2478 if (obc
.get() && obc
->is_blocked() && write_ordered
) {
2479 // we're already doing something with this object
2480 dout(20) << __func__
<< " blocked on " << obc
->obs
.oi
.soid
<< dendl
;
2481 return cache_result_t::NOOP
;
2484 if (r
== -ENOENT
&& missing_oid
== hobject_t()) {
2485 // we know this object is logically absent (e.g., an undefined clone)
2486 return cache_result_t::NOOP
;
2489 if (obc
.get() && obc
->obs
.exists
) {
2490 osd
->logger
->inc(l_osd_op_cache_hit
);
2491 return cache_result_t::NOOP
;
2494 if (missing_oid
== hobject_t() && obc
.get()) {
2495 missing_oid
= obc
->obs
.oi
.soid
;
2498 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
2499 const object_locator_t oloc
= m
->get_object_locator();
2501 if (op
->need_skip_handle_cache()) {
2502 return cache_result_t::NOOP
;
2505 // older versions do not proxy the feature bits.
2506 bool can_proxy_write
= get_osdmap()->get_up_osd_features() &
2507 CEPH_FEATURE_OSD_PROXY_WRITE_FEATURES
;
2508 OpRequestRef promote_op
;
2510 switch (pool
.info
.cache_mode
) {
2511 case pg_pool_t::CACHEMODE_WRITEBACK
:
2513 agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
2514 if (!op
->may_write() && !op
->may_cache() &&
2515 !write_ordered
&& !must_promote
) {
2516 dout(20) << __func__
<< " cache pool full, proxying read" << dendl
;
2518 return cache_result_t::HANDLED_PROXY
;
2520 dout(20) << __func__
<< " cache pool full, waiting" << dendl
;
2521 block_write_on_full_cache(missing_oid
, op
);
2522 return cache_result_t::BLOCKED_FULL
;
2525 if (must_promote
|| (!hit_set
&& !op
->need_skip_promote())) {
2526 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2527 return cache_result_t::BLOCKED_PROMOTE
;
2530 if (op
->may_write() || op
->may_cache()) {
2531 if (can_proxy_write
) {
2532 do_proxy_write(op
, missing_oid
);
2534 // promote if can't proxy the write
2535 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2536 return cache_result_t::BLOCKED_PROMOTE
;
2540 if (!op
->need_skip_promote() &&
2541 maybe_promote(obc
, missing_oid
, oloc
, in_hit_set
,
2542 pool
.info
.min_write_recency_for_promote
,
2545 return cache_result_t::BLOCKED_PROMOTE
;
2547 return cache_result_t::HANDLED_PROXY
;
2551 // Avoid duplicate promotion
2552 if (obc
.get() && obc
->is_blocked()) {
2555 return cache_result_t::BLOCKED_PROMOTE
;
2559 if (!op
->need_skip_promote()) {
2560 (void)maybe_promote(obc
, missing_oid
, oloc
, in_hit_set
,
2561 pool
.info
.min_read_recency_for_promote
,
2562 promote_op
, promote_obc
);
2565 return cache_result_t::HANDLED_PROXY
;
2567 assert(0 == "unreachable");
2568 return cache_result_t::NOOP
;
2570 case pg_pool_t::CACHEMODE_FORWARD
:
2571 // FIXME: this mode allows requests to be reordered.
2572 do_cache_redirect(op
);
2573 return cache_result_t::HANDLED_REDIRECT
;
2575 case pg_pool_t::CACHEMODE_READONLY
:
2576 // TODO: clean this case up
2577 if (!obc
.get() && r
== -ENOENT
) {
2578 // we don't have the object and op's a read
2579 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2580 return cache_result_t::BLOCKED_PROMOTE
;
2582 if (!r
) { // it must be a write
2583 do_cache_redirect(op
);
2584 return cache_result_t::HANDLED_REDIRECT
;
2586 // crap, there was a failure of some kind
2587 return cache_result_t::NOOP
;
2589 case pg_pool_t::CACHEMODE_READFORWARD
:
2590 // Do writeback to the cache tier for writes
2591 if (op
->may_write() || write_ordered
|| must_promote
) {
2593 agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
2594 dout(20) << __func__
<< " cache pool full, waiting" << dendl
;
2595 block_write_on_full_cache(missing_oid
, op
);
2596 return cache_result_t::BLOCKED_FULL
;
2598 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2599 return cache_result_t::BLOCKED_PROMOTE
;
2602 // If it is a read, we can read, we need to forward it
2603 do_cache_redirect(op
);
2604 return cache_result_t::HANDLED_REDIRECT
;
2606 case pg_pool_t::CACHEMODE_PROXY
:
2607 if (!must_promote
) {
2608 if (op
->may_write() || op
->may_cache() || write_ordered
) {
2609 if (can_proxy_write
) {
2610 do_proxy_write(op
, missing_oid
);
2611 return cache_result_t::HANDLED_PROXY
;
2615 return cache_result_t::HANDLED_PROXY
;
2618 // ugh, we're forced to promote.
2620 agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
2621 dout(20) << __func__
<< " cache pool full, waiting" << dendl
;
2622 block_write_on_full_cache(missing_oid
, op
);
2623 return cache_result_t::BLOCKED_FULL
;
2625 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2626 return cache_result_t::BLOCKED_PROMOTE
;
2628 case pg_pool_t::CACHEMODE_READPROXY
:
2629 // Do writeback to the cache tier for writes
2630 if (op
->may_write() || write_ordered
|| must_promote
) {
2632 agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
2633 dout(20) << __func__
<< " cache pool full, waiting" << dendl
;
2634 block_write_on_full_cache(missing_oid
, op
);
2635 return cache_result_t::BLOCKED_FULL
;
2637 promote_object(obc
, missing_oid
, oloc
, op
, promote_obc
);
2638 return cache_result_t::BLOCKED_PROMOTE
;
2641 // If it is a read, we can read, we need to proxy it
2643 return cache_result_t::HANDLED_PROXY
;
2646 assert(0 == "unrecognized cache_mode");
2648 return cache_result_t::NOOP
;
2651 bool PrimaryLogPG::maybe_promote(ObjectContextRef obc
,
2652 const hobject_t
& missing_oid
,
2653 const object_locator_t
& oloc
,
2656 OpRequestRef promote_op
,
2657 ObjectContextRef
*promote_obc
)
2659 dout(20) << __func__
<< " missing_oid " << missing_oid
2660 << " in_hit_set " << in_hit_set
<< dendl
;
2666 // Check if in the current hit set
2676 unsigned count
= (int)in_hit_set
;
2678 // Check if in other hit sets
2679 const hobject_t
& oid
= obc
.get() ? obc
->obs
.oi
.soid
: missing_oid
;
2680 for (map
<time_t,HitSetRef
>::reverse_iterator itor
=
2681 agent_state
->hit_set_map
.rbegin();
2682 itor
!= agent_state
->hit_set_map
.rend();
2684 if (!itor
->second
->contains(oid
)) {
2688 if (count
>= recency
) {
2693 if (count
>= recency
) {
2696 return false; // not promoting
2701 if (osd
->promote_throttle()) {
2702 dout(10) << __func__
<< " promote throttled" << dendl
;
2705 promote_object(obc
, missing_oid
, oloc
, promote_op
, promote_obc
);
2709 void PrimaryLogPG::do_cache_redirect(OpRequestRef op
)
2711 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
2712 int flags
= m
->get_flags() & (CEPH_OSD_FLAG_ACK
|CEPH_OSD_FLAG_ONDISK
);
2713 MOSDOpReply
*reply
= new MOSDOpReply(m
, -ENOENT
,
2714 get_osdmap()->get_epoch(), flags
, false);
2715 request_redirect_t
redir(m
->get_object_locator(), pool
.info
.tier_of
);
2716 reply
->set_redirect(redir
);
2717 dout(10) << "sending redirect to pool " << pool
.info
.tier_of
<< " for op "
2719 m
->get_connection()->send_message(reply
);
2723 struct C_ProxyRead
: public Context
{
2726 epoch_t last_peering_reset
;
2728 PrimaryLogPG::ProxyReadOpRef prdop
;
2730 C_ProxyRead(PrimaryLogPG
*p
, hobject_t o
, epoch_t lpr
,
2731 const PrimaryLogPG::ProxyReadOpRef
& prd
)
2732 : pg(p
), oid(o
), last_peering_reset(lpr
),
2733 tid(0), prdop(prd
), start(ceph_clock_now())
2735 void finish(int r
) override
{
2736 if (prdop
->canceled
)
2739 if (prdop
->canceled
) {
2743 if (last_peering_reset
== pg
->get_last_peering_reset()) {
2744 pg
->finish_proxy_read(oid
, tid
, r
);
2745 pg
->osd
->logger
->tinc(l_osd_tier_r_lat
, ceph_clock_now() - start
);
2751 void PrimaryLogPG::do_proxy_read(OpRequestRef op
, ObjectContextRef obc
)
2753 // NOTE: non-const here because the ProxyReadOp needs mutable refs to
2754 // stash the result in the request's OSDOp vector
2755 MOSDOp
*m
= static_cast<MOSDOp
*>(op
->get_nonconst_req());
2756 object_locator_t oloc
;
2758 /* extensible tier */
2759 if (obc
&& obc
->obs
.exists
&& obc
->obs
.oi
.has_manifest()) {
2760 switch (obc
->obs
.oi
.manifest
.type
) {
2761 case object_manifest_t::TYPE_REDIRECT
:
2762 oloc
= object_locator_t(obc
->obs
.oi
.manifest
.redirect_target
);
2763 soid
= obc
->obs
.oi
.manifest
.redirect_target
;
2765 case object_manifest_t::TYPE_CHUNKED
:
2767 assert(0 == "unrecognized manifest type");
2771 soid
= m
->get_hobj();
2772 oloc
= object_locator_t(m
->get_object_locator());
2773 oloc
.pool
= pool
.info
.tier_of
;
2775 unsigned flags
= CEPH_OSD_FLAG_IGNORE_CACHE
| CEPH_OSD_FLAG_IGNORE_OVERLAY
;
2777 // pass through some original flags that make sense.
2778 // - leave out redirection and balancing flags since we are
2779 // already proxying through the primary
2780 // - leave off read/write/exec flags that are derived from the op
2781 flags
|= m
->get_flags() & (CEPH_OSD_FLAG_RWORDERED
|
2782 CEPH_OSD_FLAG_ORDERSNAP
|
2783 CEPH_OSD_FLAG_ENFORCE_SNAPC
|
2784 CEPH_OSD_FLAG_MAP_SNAP_CLONE
);
2786 dout(10) << __func__
<< " Start proxy read for " << *m
<< dendl
;
2788 ProxyReadOpRef
prdop(std::make_shared
<ProxyReadOp
>(op
, soid
, m
->ops
));
2790 ObjectOperation obj_op
;
2791 obj_op
.dup(prdop
->ops
);
2793 if (pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_WRITEBACK
&&
2794 (agent_state
&& agent_state
->evict_mode
!= TierAgentState::EVICT_MODE_FULL
)) {
2795 for (unsigned i
= 0; i
< obj_op
.ops
.size(); i
++) {
2796 ceph_osd_op op
= obj_op
.ops
[i
].op
;
2798 case CEPH_OSD_OP_READ
:
2799 case CEPH_OSD_OP_SYNC_READ
:
2800 case CEPH_OSD_OP_SPARSE_READ
:
2801 case CEPH_OSD_OP_CHECKSUM
:
2802 case CEPH_OSD_OP_CMPEXT
:
2803 op
.flags
= (op
.flags
| CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL
) &
2804 ~(CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
| CEPH_OSD_OP_FLAG_FADVISE_NOCACHE
);
2809 C_ProxyRead
*fin
= new C_ProxyRead(this, soid
, get_last_peering_reset(),
2811 ceph_tid_t tid
= osd
->objecter
->read(
2812 soid
.oid
, oloc
, obj_op
,
2813 m
->get_snapid(), NULL
,
2814 flags
, new C_OnFinisher(fin
, &osd
->objecter_finisher
),
2815 &prdop
->user_version
,
2816 &prdop
->data_offset
,
2819 prdop
->objecter_tid
= tid
;
2820 proxyread_ops
[tid
] = prdop
;
2821 in_progress_proxy_ops
[soid
].push_back(op
);
2824 void PrimaryLogPG::finish_proxy_read(hobject_t oid
, ceph_tid_t tid
, int r
)
2826 dout(10) << __func__
<< " " << oid
<< " tid " << tid
2827 << " " << cpp_strerror(r
) << dendl
;
2829 map
<ceph_tid_t
, ProxyReadOpRef
>::iterator p
= proxyread_ops
.find(tid
);
2830 if (p
== proxyread_ops
.end()) {
2831 dout(10) << __func__
<< " no proxyread_op found" << dendl
;
2834 ProxyReadOpRef prdop
= p
->second
;
2835 if (tid
!= prdop
->objecter_tid
) {
2836 dout(10) << __func__
<< " tid " << tid
<< " != prdop " << prdop
2837 << " tid " << prdop
->objecter_tid
<< dendl
;
2840 if (oid
!= prdop
->soid
) {
2841 dout(10) << __func__
<< " oid " << oid
<< " != prdop " << prdop
2842 << " soid " << prdop
->soid
<< dendl
;
2845 proxyread_ops
.erase(tid
);
2847 map
<hobject_t
, list
<OpRequestRef
>>::iterator q
= in_progress_proxy_ops
.find(oid
);
2848 if (q
== in_progress_proxy_ops
.end()) {
2849 dout(10) << __func__
<< " no in_progress_proxy_ops found" << dendl
;
2852 assert(q
->second
.size());
2853 list
<OpRequestRef
>::iterator it
= std::find(q
->second
.begin(),
2856 assert(it
!= q
->second
.end());
2857 OpRequestRef op
= *it
;
2858 q
->second
.erase(it
);
2859 if (q
->second
.size() == 0) {
2860 in_progress_proxy_ops
.erase(oid
);
2863 osd
->logger
->inc(l_osd_tier_proxy_read
);
2865 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
2866 OpContext
*ctx
= new OpContext(op
, m
->get_reqid(), &prdop
->ops
, this);
2867 ctx
->reply
= new MOSDOpReply(m
, 0, get_osdmap()->get_epoch(), 0, false);
2868 ctx
->user_at_version
= prdop
->user_version
;
2869 ctx
->data_off
= prdop
->data_offset
;
2870 ctx
->ignore_log_op_stats
= true;
2871 complete_read_ctx(r
, ctx
);
2874 void PrimaryLogPG::kick_proxy_ops_blocked(hobject_t
& soid
)
2876 map
<hobject_t
, list
<OpRequestRef
>>::iterator p
= in_progress_proxy_ops
.find(soid
);
2877 if (p
== in_progress_proxy_ops
.end())
2880 list
<OpRequestRef
>& ls
= p
->second
;
2881 dout(10) << __func__
<< " " << soid
<< " requeuing " << ls
.size() << " requests" << dendl
;
2883 in_progress_proxy_ops
.erase(p
);
2886 void PrimaryLogPG::cancel_proxy_read(ProxyReadOpRef prdop
)
2888 dout(10) << __func__
<< " " << prdop
->soid
<< dendl
;
2889 prdop
->canceled
= true;
2891 // cancel objecter op, if we can
2892 if (prdop
->objecter_tid
) {
2893 osd
->objecter
->op_cancel(prdop
->objecter_tid
, -ECANCELED
);
2894 for (uint32_t i
= 0; i
< prdop
->ops
.size(); i
++) {
2895 prdop
->ops
[i
].outdata
.clear();
2897 proxyread_ops
.erase(prdop
->objecter_tid
);
2898 prdop
->objecter_tid
= 0;
2902 void PrimaryLogPG::cancel_proxy_ops(bool requeue
)
2904 dout(10) << __func__
<< dendl
;
2906 // cancel proxy reads
2907 map
<ceph_tid_t
, ProxyReadOpRef
>::iterator p
= proxyread_ops
.begin();
2908 while (p
!= proxyread_ops
.end()) {
2909 cancel_proxy_read((p
++)->second
);
2912 // cancel proxy writes
2913 map
<ceph_tid_t
, ProxyWriteOpRef
>::iterator q
= proxywrite_ops
.begin();
2914 while (q
!= proxywrite_ops
.end()) {
2915 cancel_proxy_write((q
++)->second
);
2919 map
<hobject_t
, list
<OpRequestRef
>>::iterator p
=
2920 in_progress_proxy_ops
.begin();
2921 while (p
!= in_progress_proxy_ops
.end()) {
2922 list
<OpRequestRef
>& ls
= p
->second
;
2923 dout(10) << __func__
<< " " << p
->first
<< " requeuing " << ls
.size()
2924 << " requests" << dendl
;
2926 in_progress_proxy_ops
.erase(p
++);
2929 in_progress_proxy_ops
.clear();
2933 struct C_ProxyWrite_Commit
: public Context
{
2936 epoch_t last_peering_reset
;
2938 PrimaryLogPG::ProxyWriteOpRef pwop
;
2939 C_ProxyWrite_Commit(PrimaryLogPG
*p
, hobject_t o
, epoch_t lpr
,
2940 const PrimaryLogPG::ProxyWriteOpRef
& pw
)
2941 : pg(p
), oid(o
), last_peering_reset(lpr
),
2944 void finish(int r
) override
{
2948 if (pwop
->canceled
) {
2952 if (last_peering_reset
== pg
->get_last_peering_reset()) {
2953 pg
->finish_proxy_write(oid
, tid
, r
);
2959 void PrimaryLogPG::do_proxy_write(OpRequestRef op
, const hobject_t
& missing_oid
, ObjectContextRef obc
)
2961 // NOTE: non-const because ProxyWriteOp takes a mutable ref
2962 MOSDOp
*m
= static_cast<MOSDOp
*>(op
->get_nonconst_req());
2963 object_locator_t oloc
;
2964 SnapContext
snapc(m
->get_snap_seq(), m
->get_snaps());
2966 /* extensible tier */
2967 if (obc
&& obc
->obs
.exists
&& obc
->obs
.oi
.has_manifest()) {
2968 switch (obc
->obs
.oi
.manifest
.type
) {
2969 case object_manifest_t::TYPE_REDIRECT
:
2970 oloc
= object_locator_t(obc
->obs
.oi
.manifest
.redirect_target
);
2971 soid
= obc
->obs
.oi
.manifest
.redirect_target
;
2973 case object_manifest_t::TYPE_CHUNKED
:
2975 assert(0 == "unrecognized manifest type");
2979 soid
= m
->get_hobj();
2980 oloc
= object_locator_t(m
->get_object_locator());
2981 oloc
.pool
= pool
.info
.tier_of
;
2984 unsigned flags
= CEPH_OSD_FLAG_IGNORE_CACHE
| CEPH_OSD_FLAG_IGNORE_OVERLAY
;
2985 if (!(op
->may_write() || op
->may_cache())) {
2986 flags
|= CEPH_OSD_FLAG_RWORDERED
;
2988 dout(10) << __func__
<< " Start proxy write for " << *m
<< dendl
;
2990 ProxyWriteOpRef
pwop(std::make_shared
<ProxyWriteOp
>(op
, soid
, m
->ops
, m
->get_reqid()));
2991 pwop
->ctx
= new OpContext(op
, m
->get_reqid(), &pwop
->ops
, this);
2992 pwop
->mtime
= m
->get_mtime();
2994 ObjectOperation obj_op
;
2995 obj_op
.dup(pwop
->ops
);
2997 C_ProxyWrite_Commit
*fin
= new C_ProxyWrite_Commit(
2998 this, soid
, get_last_peering_reset(), pwop
);
2999 ceph_tid_t tid
= osd
->objecter
->mutate(
3000 soid
.oid
, oloc
, obj_op
, snapc
,
3001 ceph::real_clock::from_ceph_timespec(pwop
->mtime
),
3002 flags
, new C_OnFinisher(fin
, &osd
->objecter_finisher
),
3003 &pwop
->user_version
, pwop
->reqid
);
3005 pwop
->objecter_tid
= tid
;
3006 proxywrite_ops
[tid
] = pwop
;
3007 in_progress_proxy_ops
[soid
].push_back(op
);
3010 void PrimaryLogPG::finish_proxy_write(hobject_t oid
, ceph_tid_t tid
, int r
)
3012 dout(10) << __func__
<< " " << oid
<< " tid " << tid
3013 << " " << cpp_strerror(r
) << dendl
;
3015 map
<ceph_tid_t
, ProxyWriteOpRef
>::iterator p
= proxywrite_ops
.find(tid
);
3016 if (p
== proxywrite_ops
.end()) {
3017 dout(10) << __func__
<< " no proxywrite_op found" << dendl
;
3020 ProxyWriteOpRef pwop
= p
->second
;
3021 assert(tid
== pwop
->objecter_tid
);
3022 assert(oid
== pwop
->soid
);
3024 proxywrite_ops
.erase(tid
);
3026 map
<hobject_t
, list
<OpRequestRef
> >::iterator q
= in_progress_proxy_ops
.find(oid
);
3027 if (q
== in_progress_proxy_ops
.end()) {
3028 dout(10) << __func__
<< " no in_progress_proxy_ops found" << dendl
;
3033 list
<OpRequestRef
>& in_progress_op
= q
->second
;
3034 assert(in_progress_op
.size());
3035 list
<OpRequestRef
>::iterator it
= std::find(in_progress_op
.begin(),
3036 in_progress_op
.end(),
3038 assert(it
!= in_progress_op
.end());
3039 in_progress_op
.erase(it
);
3040 if (in_progress_op
.size() == 0) {
3041 in_progress_proxy_ops
.erase(oid
);
3044 osd
->logger
->inc(l_osd_tier_proxy_write
);
3046 const MOSDOp
*m
= static_cast<const MOSDOp
*>(pwop
->op
->get_req());
3049 if (!pwop
->sent_reply
) {
3051 MOSDOpReply
*reply
= pwop
->ctx
->reply
;
3053 pwop
->ctx
->reply
= NULL
;
3055 reply
= new MOSDOpReply(m
, r
, get_osdmap()->get_epoch(), 0, true);
3056 reply
->set_reply_versions(eversion_t(), pwop
->user_version
);
3058 reply
->add_flags(CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
3059 dout(10) << " sending commit on " << pwop
<< " " << reply
<< dendl
;
3060 osd
->send_message_osd_client(reply
, m
->get_connection());
3061 pwop
->sent_reply
= true;
3062 pwop
->ctx
->op
->mark_commit_sent();
3069 void PrimaryLogPG::cancel_proxy_write(ProxyWriteOpRef pwop
)
3071 dout(10) << __func__
<< " " << pwop
->soid
<< dendl
;
3072 pwop
->canceled
= true;
3074 // cancel objecter op, if we can
3075 if (pwop
->objecter_tid
) {
3076 osd
->objecter
->op_cancel(pwop
->objecter_tid
, -ECANCELED
);
3079 proxywrite_ops
.erase(pwop
->objecter_tid
);
3080 pwop
->objecter_tid
= 0;
3084 class PromoteCallback
: public PrimaryLogPG::CopyCallback
{
3085 ObjectContextRef obc
;
3089 PromoteCallback(ObjectContextRef obc_
, PrimaryLogPG
*pg_
)
3092 start(ceph_clock_now()) {}
3094 void finish(PrimaryLogPG::CopyCallbackResults results
) override
{
3095 PrimaryLogPG::CopyResults
*results_data
= results
.get
<1>();
3096 int r
= results
.get
<0>();
3097 pg
->finish_promote(r
, results_data
, obc
);
3098 pg
->osd
->logger
->tinc(l_osd_tier_promote_lat
, ceph_clock_now() - start
);
3102 void PrimaryLogPG::promote_object(ObjectContextRef obc
,
3103 const hobject_t
& missing_oid
,
3104 const object_locator_t
& oloc
,
3106 ObjectContextRef
*promote_obc
)
3108 hobject_t hoid
= obc
? obc
->obs
.oi
.soid
: missing_oid
;
3109 assert(hoid
!= hobject_t());
3110 if (scrubber
.write_blocked_by_scrub(hoid
)) {
3111 dout(10) << __func__
<< " " << hoid
3112 << " blocked by scrub" << dendl
;
3114 waiting_for_scrub
.push_back(op
);
3115 op
->mark_delayed("waiting for scrub");
3116 dout(10) << __func__
<< " " << hoid
3117 << " placing op in waiting_for_scrub" << dendl
;
3119 dout(10) << __func__
<< " " << hoid
3120 << " no op, dropping on the floor" << dendl
;
3124 if (!obc
) { // we need to create an ObjectContext
3125 assert(missing_oid
!= hobject_t());
3126 obc
= get_object_context(missing_oid
, true);
3132 * Before promote complete, if there are proxy-reads for the object,
3133 * for this case we don't use DONTNEED.
3135 unsigned src_fadvise_flags
= LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL
;
3136 map
<hobject_t
, list
<OpRequestRef
>>::iterator q
= in_progress_proxy_ops
.find(obc
->obs
.oi
.soid
);
3137 if (q
== in_progress_proxy_ops
.end()) {
3138 src_fadvise_flags
|= LIBRADOS_OP_FLAG_FADVISE_DONTNEED
;
3141 PromoteCallback
*cb
= new PromoteCallback(obc
, this);
3142 object_locator_t my_oloc
= oloc
;
3143 my_oloc
.pool
= pool
.info
.tier_of
;
3145 unsigned flags
= CEPH_OSD_COPY_FROM_FLAG_IGNORE_OVERLAY
|
3146 CEPH_OSD_COPY_FROM_FLAG_IGNORE_CACHE
|
3147 CEPH_OSD_COPY_FROM_FLAG_MAP_SNAP_CLONE
|
3148 CEPH_OSD_COPY_FROM_FLAG_RWORDERED
;
3149 start_copy(cb
, obc
, obc
->obs
.oi
.soid
, my_oloc
, 0, flags
,
3150 obc
->obs
.oi
.soid
.snap
== CEPH_NOSNAP
,
3151 src_fadvise_flags
, 0);
3153 assert(obc
->is_blocked());
3156 wait_for_blocked_object(obc
->obs
.oi
.soid
, op
);
3157 info
.stats
.stats
.sum
.num_promote
++;
3160 void PrimaryLogPG::execute_ctx(OpContext
*ctx
)
3163 dout(10) << __func__
<< " " << ctx
<< dendl
;
3164 ctx
->reset_obs(ctx
->obc
);
3165 ctx
->update_log_only
= false; // reset in case finish_copyfrom() is re-running execute_ctx
3166 OpRequestRef op
= ctx
->op
;
3167 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
3168 ObjectContextRef obc
= ctx
->obc
;
3169 const hobject_t
& soid
= obc
->obs
.oi
.soid
;
3171 // this method must be idempotent since we may call it several times
3172 // before we finally apply the resulting transaction.
3173 ctx
->op_t
.reset(new PGTransaction
);
3175 if (op
->may_write() || op
->may_cache()) {
3177 if (!(m
->has_flag(CEPH_OSD_FLAG_ENFORCE_SNAPC
)) &&
3178 pool
.info
.is_pool_snaps_mode()) {
3180 ctx
->snapc
= pool
.snapc
;
3182 // client specified snapc
3183 ctx
->snapc
.seq
= m
->get_snap_seq();
3184 ctx
->snapc
.snaps
= m
->get_snaps();
3185 filter_snapc(ctx
->snapc
.snaps
);
3187 if ((m
->has_flag(CEPH_OSD_FLAG_ORDERSNAP
)) &&
3188 ctx
->snapc
.seq
< obc
->ssc
->snapset
.seq
) {
3189 dout(10) << " ORDERSNAP flag set and snapc seq " << ctx
->snapc
.seq
3190 << " < snapset seq " << obc
->ssc
->snapset
.seq
3191 << " on " << obc
->obs
.oi
.soid
<< dendl
;
3192 reply_ctx(ctx
, -EOLDSNAPC
);
3197 ctx
->at_version
= get_next_version();
3198 ctx
->mtime
= m
->get_mtime();
3200 dout(10) << __func__
<< " " << soid
<< " " << *ctx
->ops
3201 << " ov " << obc
->obs
.oi
.version
<< " av " << ctx
->at_version
3202 << " snapc " << ctx
->snapc
3203 << " snapset " << obc
->ssc
->snapset
3206 dout(10) << __func__
<< " " << soid
<< " " << *ctx
->ops
3207 << " ov " << obc
->obs
.oi
.version
3211 if (!ctx
->user_at_version
)
3212 ctx
->user_at_version
= obc
->obs
.oi
.user_version
;
3213 dout(30) << __func__
<< " user_at_version " << ctx
->user_at_version
<< dendl
;
3215 if (op
->may_read()) {
3216 dout(10) << " taking ondisk_read_lock" << dendl
;
3217 obc
->ondisk_read_lock();
3222 osd_reqid_t reqid
= ctx
->op
->get_reqid();
3224 tracepoint(osd
, prepare_tx_enter
, reqid
.name
._type
,
3225 reqid
.name
._num
, reqid
.tid
, reqid
.inc
);
3228 int result
= prepare_transaction(ctx
);
3232 osd_reqid_t reqid
= ctx
->op
->get_reqid();
3234 tracepoint(osd
, prepare_tx_exit
, reqid
.name
._type
,
3235 reqid
.name
._num
, reqid
.tid
, reqid
.inc
);
3238 if (op
->may_read()) {
3239 dout(10) << " dropping ondisk_read_lock" << dendl
;
3240 obc
->ondisk_read_unlock();
3243 bool pending_async_reads
= !ctx
->pending_async_reads
.empty();
3244 if (result
== -EINPROGRESS
|| pending_async_reads
) {
3246 if (pending_async_reads
) {
3247 in_progress_async_reads
.push_back(make_pair(op
, ctx
));
3248 ctx
->start_async_reads(this);
3253 if (result
== -EAGAIN
) {
3254 // clean up after the ctx
3259 bool successful_write
= !ctx
->op_t
->empty() && op
->may_write() && result
>= 0;
3260 // prepare the reply
3261 ctx
->reply
= new MOSDOpReply(m
, 0, get_osdmap()->get_epoch(), 0,
3264 // Write operations aren't allowed to return a data payload because
3265 // we can't do so reliably. If the client has to resend the request
3266 // and it has already been applied, we will return 0 with no
3267 // payload. Non-deterministic behavior is no good. However, it is
3268 // possible to construct an operation that does a read, does a guard
3269 // check (e.g., CMPXATTR), and then a write. Then we either succeed
3270 // with the write, or return a CMPXATTR and the read value.
3271 if (successful_write
) {
3272 // write. normalize the result code.
3273 dout(20) << " zeroing write result code " << result
<< dendl
;
3276 ctx
->reply
->set_result(result
);
3279 if ((ctx
->op_t
->empty() || result
< 0) && !ctx
->update_log_only
) {
3280 // finish side-effects
3282 do_osd_op_effects(ctx
, m
->get_connection());
3284 complete_read_ctx(result
, ctx
);
3288 ctx
->reply
->set_reply_versions(ctx
->at_version
, ctx
->user_at_version
);
3290 assert(op
->may_write() || op
->may_cache());
3295 // verify that we are doing this in order?
3296 if (cct
->_conf
->osd_debug_op_order
&& m
->get_source().is_client() &&
3297 !pool
.info
.is_tier() && !pool
.info
.has_tiers()) {
3298 map
<client_t
,ceph_tid_t
>& cm
= debug_op_order
[obc
->obs
.oi
.soid
];
3299 ceph_tid_t t
= m
->get_tid();
3300 client_t n
= m
->get_source().num();
3301 map
<client_t
,ceph_tid_t
>::iterator p
= cm
.find(n
);
3302 if (p
== cm
.end()) {
3303 dout(20) << " op order client." << n
<< " tid " << t
<< " (first)" << dendl
;
3306 dout(20) << " op order client." << n
<< " tid " << t
<< " last was " << p
->second
<< dendl
;
3307 if (p
->second
> t
) {
3308 derr
<< "bad op order, already applied " << p
->second
<< " > this " << t
<< dendl
;
3309 assert(0 == "out of order op");
3315 if (ctx
->update_log_only
) {
3317 do_osd_op_effects(ctx
, m
->get_connection());
3319 dout(20) << __func__
<< " update_log_only -- result=" << result
<< dendl
;
3320 // save just what we need from ctx
3321 MOSDOpReply
*reply
= ctx
->reply
;
3322 ctx
->reply
= nullptr;
3323 reply
->claim_op_out_data(*ctx
->ops
);
3324 reply
->get_header().data_off
= (ctx
->data_off
? *ctx
->data_off
: 0);
3327 if (result
== -ENOENT
) {
3328 reply
->set_enoent_reply_versions(info
.last_update
,
3329 info
.last_user_version
);
3331 reply
->add_flags(CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
3332 // append to pg log for dup detection - don't save buffers for now
3333 record_write_error(op
, soid
, reply
, result
);
3337 // no need to capture PG ref, repop cancel will handle that
3338 // Can capture the ctx by pointer, it's owned by the repop
3339 ctx
->register_on_commit(
3345 if (m
&& !ctx
->sent_reply
) {
3346 MOSDOpReply
*reply
= ctx
->reply
;
3348 ctx
->reply
= nullptr;
3350 reply
= new MOSDOpReply(m
, 0, get_osdmap()->get_epoch(), 0, true);
3351 reply
->set_reply_versions(ctx
->at_version
,
3352 ctx
->user_at_version
);
3354 reply
->add_flags(CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
3355 dout(10) << " sending reply on " << *m
<< " " << reply
<< dendl
;
3356 osd
->send_message_osd_client(reply
, m
->get_connection());
3357 ctx
->sent_reply
= true;
3358 ctx
->op
->mark_commit_sent();
3361 ctx
->register_on_success(
3365 ctx
->op
? ctx
->op
->get_req()->get_connection() :
3368 ctx
->register_on_finish(
3373 // issue replica writes
3374 ceph_tid_t rep_tid
= osd
->get_tid();
3376 RepGather
*repop
= new_repop(ctx
, obc
, rep_tid
);
3378 issue_repop(repop
, ctx
);
3383 void PrimaryLogPG::close_op_ctx(OpContext
*ctx
) {
3384 release_object_locks(ctx
->lock_manager
);
3388 for (auto p
= ctx
->on_finish
.begin(); p
!= ctx
->on_finish
.end();
3389 ctx
->on_finish
.erase(p
++)) {
3395 void PrimaryLogPG::reply_ctx(OpContext
*ctx
, int r
)
3398 osd
->reply_op_error(ctx
->op
, r
);
3402 void PrimaryLogPG::reply_ctx(OpContext
*ctx
, int r
, eversion_t v
, version_t uv
)
3405 osd
->reply_op_error(ctx
->op
, r
, v
, uv
);
3409 void PrimaryLogPG::log_op_stats(OpContext
*ctx
)
3411 OpRequestRef op
= ctx
->op
;
3412 const MOSDOp
*m
= static_cast<const MOSDOp
*>(op
->get_req());
3414 utime_t now
= ceph_clock_now();
3415 utime_t latency
= now
;
3416 latency
-= ctx
->op
->get_req()->get_recv_stamp();
3417 utime_t process_latency
= now
;
3418 process_latency
-= ctx
->op
->get_dequeued_time();
3420 uint64_t inb
= ctx
->bytes_written
;
3421 uint64_t outb
= ctx
->bytes_read
;
3423 osd
->logger
->inc(l_osd_op
);
3425 osd
->logger
->inc(l_osd_op_outb
, outb
);
3426 osd
->logger
->inc(l_osd_op_inb
, inb
);
3427 osd
->logger
->tinc(l_osd_op_lat
, latency
);
3428 osd
->logger
->tinc(l_osd_op_process_lat
, process_latency
);
3430 if (op
->may_read() && op
->may_write()) {
3431 osd
->logger
->inc(l_osd_op_rw
);
3432 osd
->logger
->inc(l_osd_op_rw_inb
, inb
);
3433 osd
->logger
->inc(l_osd_op_rw_outb
, outb
);
3434 osd
->logger
->tinc(l_osd_op_rw_lat
, latency
);
3435 osd
->logger
->hinc(l_osd_op_rw_lat_inb_hist
, latency
.to_nsec(), inb
);
3436 osd
->logger
->hinc(l_osd_op_rw_lat_outb_hist
, latency
.to_nsec(), outb
);
3437 osd
->logger
->tinc(l_osd_op_rw_process_lat
, process_latency
);
3438 } else if (op
->may_read()) {
3439 osd
->logger
->inc(l_osd_op_r
);
3440 osd
->logger
->inc(l_osd_op_r_outb
, outb
);
3441 osd
->logger
->tinc(l_osd_op_r_lat
, latency
);
3442 osd
->logger
->hinc(l_osd_op_r_lat_outb_hist
, latency
.to_nsec(), outb
);
3443 osd
->logger
->tinc(l_osd_op_r_process_lat
, process_latency
);
3444 } else if (op
->may_write() || op
->may_cache()) {
3445 osd
->logger
->inc(l_osd_op_w
);
3446 osd
->logger
->inc(l_osd_op_w_inb
, inb
);
3447 osd
->logger
->tinc(l_osd_op_w_lat
, latency
);
3448 osd
->logger
->hinc(l_osd_op_w_lat_inb_hist
, latency
.to_nsec(), inb
);
3449 osd
->logger
->tinc(l_osd_op_w_process_lat
, process_latency
);
3453 dout(15) << "log_op_stats " << *m
3456 << " lat " << latency
<< dendl
;
3459 void PrimaryLogPG::do_sub_op(OpRequestRef op
)
3461 const MOSDSubOp
*m
= static_cast<const MOSDSubOp
*>(op
->get_req());
3462 assert(have_same_or_newer_map(m
->map_epoch
));
3463 assert(m
->get_type() == MSG_OSD_SUBOP
);
3464 dout(15) << "do_sub_op " << *op
->get_req() << dendl
;
3467 waiting_for_peered
.push_back(op
);
3468 op
->mark_delayed("waiting for active");
3472 const OSDOp
*first
= NULL
;
3473 if (m
->ops
.size() >= 1) {
3478 switch (first
->op
.op
) {
3479 case CEPH_OSD_OP_DELETE
:
3482 case CEPH_OSD_OP_SCRUB_RESERVE
:
3483 handle_scrub_reserve_request(op
);
3485 case CEPH_OSD_OP_SCRUB_UNRESERVE
:
3486 handle_scrub_reserve_release(op
);
3488 case CEPH_OSD_OP_SCRUB_MAP
:
3489 sub_op_scrub_map(op
);
3495 void PrimaryLogPG::do_sub_op_reply(OpRequestRef op
)
3497 const MOSDSubOpReply
*r
= static_cast<const MOSDSubOpReply
*>(op
->get_req());
3498 assert(r
->get_type() == MSG_OSD_SUBOPREPLY
);
3499 if (r
->ops
.size() >= 1) {
3500 const OSDOp
& first
= r
->ops
[0];
3501 switch (first
.op
.op
) {
3502 case CEPH_OSD_OP_SCRUB_RESERVE
:
3504 pg_shard_t from
= r
->from
;
3505 bufferlist::iterator p
= const_cast<bufferlist
&>(r
->get_data()).begin();
3507 ::decode(reserved
, p
);
3509 handle_scrub_reserve_grant(op
, from
);
3511 handle_scrub_reserve_reject(op
, from
);
3519 void PrimaryLogPG::do_scan(
3521 ThreadPool::TPHandle
&handle
)
3523 const MOSDPGScan
*m
= static_cast<const MOSDPGScan
*>(op
->get_req());
3524 assert(m
->get_type() == MSG_OSD_PG_SCAN
);
3525 dout(10) << "do_scan " << *m
<< dendl
;
3530 case MOSDPGScan::OP_SCAN_GET_DIGEST
:
3533 if (osd
->check_backfill_full(ss
)) {
3534 dout(1) << __func__
<< ": Canceling backfill, " << ss
.str() << dendl
;
3535 queue_peering_event(
3537 std::make_shared
<CephPeeringEvt
>(
3538 get_osdmap()->get_epoch(),
3539 get_osdmap()->get_epoch(),
3540 BackfillTooFull())));
3544 BackfillInterval bi
;
3545 bi
.begin
= m
->begin
;
3546 // No need to flush, there won't be any in progress writes occuring
3549 cct
->_conf
->osd_backfill_scan_min
,
3550 cct
->_conf
->osd_backfill_scan_max
,
3553 MOSDPGScan
*reply
= new MOSDPGScan(
3554 MOSDPGScan::OP_SCAN_DIGEST
,
3556 get_osdmap()->get_epoch(), m
->query_epoch
,
3557 spg_t(info
.pgid
.pgid
, get_primary().shard
), bi
.begin
, bi
.end
);
3558 ::encode(bi
.objects
, reply
->get_data());
3559 osd
->send_message_osd_cluster(reply
, m
->get_connection());
3563 case MOSDPGScan::OP_SCAN_DIGEST
:
3565 pg_shard_t from
= m
->from
;
3567 // Check that from is in backfill_targets vector
3568 assert(is_backfill_targets(from
));
3570 BackfillInterval
& bi
= peer_backfill_info
[from
];
3571 bi
.begin
= m
->begin
;
3573 bufferlist::iterator p
= const_cast<bufferlist
&>(m
->get_data()).begin();
3575 // take care to preserve ordering!
3577 ::decode_noclear(bi
.objects
, p
);
3579 if (waiting_on_backfill
.erase(from
)) {
3580 if (waiting_on_backfill
.empty()) {
3581 assert(peer_backfill_info
.size() == backfill_targets
.size());
3582 finish_recovery_op(hobject_t::get_max());
3585 // we canceled backfill for a while due to a too full, and this
3586 // is an extra response from a non-too-full peer
3593 void PrimaryLogPG::do_backfill(OpRequestRef op
)
3595 const MOSDPGBackfill
*m
= static_cast<const MOSDPGBackfill
*>(op
->get_req());
3596 assert(m
->get_type() == MSG_OSD_PG_BACKFILL
);
3597 dout(10) << "do_backfill " << *m
<< dendl
;
3602 case MOSDPGBackfill::OP_BACKFILL_FINISH
:
3604 assert(cct
->_conf
->osd_kill_backfill_at
!= 1);
3606 MOSDPGBackfill
*reply
= new MOSDPGBackfill(
3607 MOSDPGBackfill::OP_BACKFILL_FINISH_ACK
,
3608 get_osdmap()->get_epoch(),
3610 spg_t(info
.pgid
.pgid
, get_primary().shard
));
3611 reply
->set_priority(get_recovery_op_priority());
3612 osd
->send_message_osd_cluster(reply
, m
->get_connection());
3613 queue_peering_event(
3615 std::make_shared
<CephPeeringEvt
>(
3616 get_osdmap()->get_epoch(),
3617 get_osdmap()->get_epoch(),
3622 case MOSDPGBackfill::OP_BACKFILL_PROGRESS
:
3624 assert(cct
->_conf
->osd_kill_backfill_at
!= 2);
3626 info
.set_last_backfill(m
->last_backfill
);
3627 info
.stats
= m
->stats
;
3629 ObjectStore::Transaction t
;
3632 int tr
= osd
->store
->queue_transaction(osr
.get(), std::move(t
), NULL
);
3637 case MOSDPGBackfill::OP_BACKFILL_FINISH_ACK
:
3639 assert(is_primary());
3640 assert(cct
->_conf
->osd_kill_backfill_at
!= 3);
3641 finish_recovery_op(hobject_t::get_max());
3647 void PrimaryLogPG::do_backfill_remove(OpRequestRef op
)
3649 const MOSDPGBackfillRemove
*m
= static_cast<const MOSDPGBackfillRemove
*>(
3651 assert(m
->get_type() == MSG_OSD_PG_BACKFILL_REMOVE
);
3652 dout(7) << __func__
<< " " << m
->ls
<< dendl
;
3656 ObjectStore::Transaction t
;
3657 for (auto& p
: m
->ls
) {
3658 remove_snap_mapped_object(t
, p
.first
);
3660 int r
= osd
->store
->queue_transaction(osr
.get(), std::move(t
), NULL
);
3664 int PrimaryLogPG::trim_object(
3665 bool first
, const hobject_t
&coid
, PrimaryLogPG::OpContextUPtr
*ctxp
)
3670 ObjectContextRef obc
= get_object_context(coid
, false, NULL
);
3671 if (!obc
|| !obc
->ssc
|| !obc
->ssc
->exists
) {
3672 osd
->clog
->error() << __func__
<< ": Can not trim " << coid
3673 << " repair needed " << (obc
? "(no obc->ssc or !exists)" : "(no obc)");
3678 coid
.oid
, coid
.get_key(),
3679 obc
->ssc
->snapset
.head_exists
? CEPH_NOSNAP
:CEPH_SNAPDIR
, coid
.get_hash(),
3680 info
.pgid
.pool(), coid
.get_namespace());
3681 ObjectContextRef snapset_obc
= get_object_context(snapoid
, false);
3683 osd
->clog
->error() << __func__
<< ": Can not trim " << coid
3684 << " repair needed, no snapset obc for " << snapoid
;
3688 SnapSet
& snapset
= obc
->ssc
->snapset
;
3690 bool legacy
= snapset
.is_legacy() ||
3691 get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
;
3693 object_info_t
&coi
= obc
->obs
.oi
;
3694 set
<snapid_t
> old_snaps
;
3696 old_snaps
.insert(coi
.legacy_snaps
.begin(), coi
.legacy_snaps
.end());
3698 auto p
= snapset
.clone_snaps
.find(coid
.snap
);
3699 if (p
== snapset
.clone_snaps
.end()) {
3700 osd
->clog
->error() << "No clone_snaps in snapset " << snapset
3701 << " for object " << coid
<< "\n";
3704 old_snaps
.insert(snapset
.clone_snaps
[coid
.snap
].begin(),
3705 snapset
.clone_snaps
[coid
.snap
].end());
3707 if (old_snaps
.empty()) {
3708 osd
->clog
->error() << "No object info snaps for object " << coid
;
3712 dout(10) << coid
<< " old_snaps " << old_snaps
3713 << " old snapset " << snapset
<< dendl
;
3714 if (snapset
.seq
== 0) {
3715 osd
->clog
->error() << "No snapset.seq for object " << coid
;
3719 set
<snapid_t
> new_snaps
;
3720 for (set
<snapid_t
>::iterator i
= old_snaps
.begin();
3721 i
!= old_snaps
.end();
3723 if (!pool
.info
.is_removed_snap(*i
))
3724 new_snaps
.insert(*i
);
3727 vector
<snapid_t
>::iterator p
= snapset
.clones
.end();
3729 if (new_snaps
.empty()) {
3730 p
= std::find(snapset
.clones
.begin(), snapset
.clones
.end(), coid
.snap
);
3731 if (p
== snapset
.clones
.end()) {
3732 osd
->clog
->error() << "Snap " << coid
.snap
<< " not in clones";
3737 OpContextUPtr ctx
= simple_opc_create(obc
);
3738 ctx
->snapset_obc
= snapset_obc
;
3740 if (!ctx
->lock_manager
.get_snaptrimmer_write(
3744 close_op_ctx(ctx
.release());
3745 dout(10) << __func__
<< ": Unable to get a wlock on " << coid
<< dendl
;
3749 if (!ctx
->lock_manager
.get_snaptrimmer_write(
3753 close_op_ctx(ctx
.release());
3754 dout(10) << __func__
<< ": Unable to get a wlock on " << snapoid
<< dendl
;
3758 ctx
->at_version
= get_next_version();
3760 PGTransaction
*t
= ctx
->op_t
.get();
3762 if (new_snaps
.empty()) {
3764 dout(10) << coid
<< " snaps " << old_snaps
<< " -> "
3765 << new_snaps
<< " ... deleting" << dendl
;
3768 assert(p
!= snapset
.clones
.end());
3770 snapid_t last
= coid
.snap
;
3771 ctx
->delta_stats
.num_bytes
-= snapset
.get_clone_bytes(last
);
3773 if (p
!= snapset
.clones
.begin()) {
3774 // not the oldest... merge overlap into next older clone
3775 vector
<snapid_t
>::iterator n
= p
- 1;
3776 hobject_t prev_coid
= coid
;
3777 prev_coid
.snap
= *n
;
3778 bool adjust_prev_bytes
= is_present_clone(prev_coid
);
3780 if (adjust_prev_bytes
)
3781 ctx
->delta_stats
.num_bytes
-= snapset
.get_clone_bytes(*n
);
3783 snapset
.clone_overlap
[*n
].intersection_of(
3784 snapset
.clone_overlap
[*p
]);
3786 if (adjust_prev_bytes
)
3787 ctx
->delta_stats
.num_bytes
+= snapset
.get_clone_bytes(*n
);
3789 ctx
->delta_stats
.num_objects
--;
3791 ctx
->delta_stats
.num_objects_dirty
--;
3793 ctx
->delta_stats
.num_objects_omap
--;
3794 if (coi
.is_whiteout()) {
3795 dout(20) << __func__
<< " trimming whiteout on " << coid
<< dendl
;
3796 ctx
->delta_stats
.num_whiteouts
--;
3798 ctx
->delta_stats
.num_object_clones
--;
3799 if (coi
.is_cache_pinned())
3800 ctx
->delta_stats
.num_objects_pinned
--;
3801 obc
->obs
.exists
= false;
3803 snapset
.clones
.erase(p
);
3804 snapset
.clone_overlap
.erase(last
);
3805 snapset
.clone_size
.erase(last
);
3806 snapset
.clone_snaps
.erase(last
);
3810 pg_log_entry_t::DELETE
,
3813 ctx
->obs
->oi
.version
,
3825 coi
= object_info_t(coid
);
3827 ctx
->at_version
.version
++;
3829 // save adjusted snaps for this object
3830 dout(10) << coid
<< " snaps " << old_snaps
<< " -> " << new_snaps
<< dendl
;
3832 coi
.legacy_snaps
= vector
<snapid_t
>(new_snaps
.rbegin(), new_snaps
.rend());
3834 snapset
.clone_snaps
[coid
.snap
] = vector
<snapid_t
>(new_snaps
.rbegin(),
3836 // we still do a 'modify' event on this object just to trigger a
3837 // snapmapper.update ... :(
3840 coi
.prior_version
= coi
.version
;
3841 coi
.version
= ctx
->at_version
;
3843 ::encode(coi
, bl
, get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
3844 t
->setattr(coid
, OI_ATTR
, bl
);
3848 pg_log_entry_t::MODIFY
,
3857 ctx
->at_version
.version
++;
3865 // save head snapset
3866 dout(10) << coid
<< " new snapset " << snapset
<< " on "
3867 << snapset_obc
->obs
.oi
<< dendl
;
3868 if (snapset
.clones
.empty() &&
3869 (!snapset
.head_exists
||
3870 (snapset_obc
->obs
.oi
.is_whiteout() &&
3871 !(snapset_obc
->obs
.oi
.is_dirty() && pool
.info
.is_tier()) &&
3872 !snapset_obc
->obs
.oi
.is_cache_pinned()))) {
3873 // NOTE: this arguably constitutes minor interference with the
3874 // tiering agent if this is a cache tier since a snap trim event
3875 // is effectively evicting a whiteout we might otherwise want to
3877 dout(10) << coid
<< " removing " << snapoid
<< dendl
;
3880 pg_log_entry_t::DELETE
,
3883 ctx
->snapset_obc
->obs
.oi
.version
,
3889 if (snapoid
.is_head()) {
3890 derr
<< "removing snap head" << dendl
;
3891 object_info_t
& oi
= ctx
->snapset_obc
->obs
.oi
;
3892 ctx
->delta_stats
.num_objects
--;
3893 if (oi
.is_dirty()) {
3894 ctx
->delta_stats
.num_objects_dirty
--;
3897 ctx
->delta_stats
.num_objects_omap
--;
3898 if (oi
.is_whiteout()) {
3899 dout(20) << __func__
<< " trimming whiteout on " << oi
.soid
<< dendl
;
3900 ctx
->delta_stats
.num_whiteouts
--;
3902 if (oi
.is_cache_pinned()) {
3903 ctx
->delta_stats
.num_objects_pinned
--;
3906 ctx
->snapset_obc
->obs
.exists
= false;
3907 ctx
->snapset_obc
->obs
.oi
= object_info_t(snapoid
);
3910 dout(10) << coid
<< " filtering snapset on " << snapoid
<< dendl
;
3911 snapset
.filter(pool
.info
);
3912 dout(10) << coid
<< " writing updated snapset on " << snapoid
3913 << ", snapset is " << snapset
<< dendl
;
3916 pg_log_entry_t::MODIFY
,
3919 ctx
->snapset_obc
->obs
.oi
.version
,
3926 ctx
->snapset_obc
->obs
.oi
.prior_version
=
3927 ctx
->snapset_obc
->obs
.oi
.version
;
3928 ctx
->snapset_obc
->obs
.oi
.version
= ctx
->at_version
;
3930 map
<string
, bufferlist
> attrs
;
3932 ::encode(snapset
, bl
);
3933 attrs
[SS_ATTR
].claim(bl
);
3936 ::encode(ctx
->snapset_obc
->obs
.oi
, bl
,
3937 get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
3938 attrs
[OI_ATTR
].claim(bl
);
3939 t
->setattrs(snapoid
, attrs
);
3942 *ctxp
= std::move(ctx
);
3946 void PrimaryLogPG::kick_snap_trim()
3948 assert(is_active());
3949 assert(is_primary());
3950 if (is_clean() && !snap_trimq
.empty()) {
3951 dout(10) << __func__
<< ": clean and snaps to trim, kicking" << dendl
;
3952 snap_trimmer_machine
.process_event(KickTrim());
3956 void PrimaryLogPG::snap_trimmer_scrub_complete()
3958 if (is_primary() && is_active() && is_clean()) {
3959 assert(!snap_trimq
.empty());
3960 snap_trimmer_machine
.process_event(ScrubComplete());
3964 void PrimaryLogPG::snap_trimmer(epoch_t queued
)
3966 if (deleting
|| pg_has_reset_since(queued
)) {
3970 assert(is_primary());
3972 dout(10) << "snap_trimmer posting" << dendl
;
3973 snap_trimmer_machine
.process_event(DoSnapWork());
3974 dout(10) << "snap_trimmer complete" << dendl
;
3978 int PrimaryLogPG::do_xattr_cmp_u64(int op
, __u64 v1
, bufferlist
& xattr
)
3982 string
v2s(xattr
.c_str(), xattr
.length());
3984 v2
= strtoull(v2s
.c_str(), NULL
, 10);
3988 dout(20) << "do_xattr_cmp_u64 '" << v1
<< "' vs '" << v2
<< "' op " << op
<< dendl
;
3991 case CEPH_OSD_CMPXATTR_OP_EQ
:
3993 case CEPH_OSD_CMPXATTR_OP_NE
:
3995 case CEPH_OSD_CMPXATTR_OP_GT
:
3997 case CEPH_OSD_CMPXATTR_OP_GTE
:
3999 case CEPH_OSD_CMPXATTR_OP_LT
:
4001 case CEPH_OSD_CMPXATTR_OP_LTE
:
4008 int PrimaryLogPG::do_xattr_cmp_str(int op
, string
& v1s
, bufferlist
& xattr
)
4010 string
v2s(xattr
.c_str(), xattr
.length());
4012 dout(20) << "do_xattr_cmp_str '" << v1s
<< "' vs '" << v2s
<< "' op " << op
<< dendl
;
4015 case CEPH_OSD_CMPXATTR_OP_EQ
:
4016 return (v1s
.compare(v2s
) == 0);
4017 case CEPH_OSD_CMPXATTR_OP_NE
:
4018 return (v1s
.compare(v2s
) != 0);
4019 case CEPH_OSD_CMPXATTR_OP_GT
:
4020 return (v1s
.compare(v2s
) > 0);
4021 case CEPH_OSD_CMPXATTR_OP_GTE
:
4022 return (v1s
.compare(v2s
) >= 0);
4023 case CEPH_OSD_CMPXATTR_OP_LT
:
4024 return (v1s
.compare(v2s
) < 0);
4025 case CEPH_OSD_CMPXATTR_OP_LTE
:
4026 return (v1s
.compare(v2s
) <= 0);
4032 int PrimaryLogPG::do_writesame(OpContext
*ctx
, OSDOp
& osd_op
)
4034 ceph_osd_op
& op
= osd_op
.op
;
4035 vector
<OSDOp
> write_ops(1);
4036 OSDOp
& write_op
= write_ops
[0];
4037 uint64_t write_length
= op
.writesame
.length
;
4043 if (!op
.writesame
.data_length
|| write_length
% op
.writesame
.data_length
)
4046 if (op
.writesame
.data_length
!= osd_op
.indata
.length()) {
4047 derr
<< "invalid length ws data length " << op
.writesame
.data_length
<< " actual len " << osd_op
.indata
.length() << dendl
;
4051 while (write_length
) {
4052 write_op
.indata
.append(osd_op
.indata
);
4053 write_length
-= op
.writesame
.data_length
;
4056 write_op
.op
.op
= CEPH_OSD_OP_WRITE
;
4057 write_op
.op
.extent
.offset
= op
.writesame
.offset
;
4058 write_op
.op
.extent
.length
= op
.writesame
.length
;
4059 result
= do_osd_ops(ctx
, write_ops
);
4061 derr
<< "do_writesame do_osd_ops failed " << result
<< dendl
;
4066 // ========================================================================
4067 // low level osd ops
4069 int PrimaryLogPG::do_tmap2omap(OpContext
*ctx
, unsigned flags
)
4071 dout(20) << " convert tmap to omap for " << ctx
->new_obs
.oi
.soid
<< dendl
;
4072 bufferlist header
, vals
;
4073 int r
= _get_tmap(ctx
, &header
, &vals
);
4075 if (r
== -ENODATA
&& (flags
& CEPH_OSD_TMAP2OMAP_NULLOK
))
4080 vector
<OSDOp
> ops(3);
4082 ops
[0].op
.op
= CEPH_OSD_OP_TRUNCATE
;
4083 ops
[0].op
.extent
.offset
= 0;
4084 ops
[0].op
.extent
.length
= 0;
4086 ops
[1].op
.op
= CEPH_OSD_OP_OMAPSETHEADER
;
4087 ops
[1].indata
.claim(header
);
4089 ops
[2].op
.op
= CEPH_OSD_OP_OMAPSETVALS
;
4090 ops
[2].indata
.claim(vals
);
4092 return do_osd_ops(ctx
, ops
);
4095 int PrimaryLogPG::do_tmapup_slow(OpContext
*ctx
, bufferlist::iterator
& bp
, OSDOp
& osd_op
,
4100 map
<string
, bufferlist
> m
;
4102 bufferlist::iterator p
= bl
.begin();
4103 ::decode(header
, p
);
4115 case CEPH_OSD_TMAP_SET
: // insert key
4123 case CEPH_OSD_TMAP_RM
: // remove key
4125 if (!m
.count(key
)) {
4130 case CEPH_OSD_TMAP_RMSLOPPY
: // remove key
4134 case CEPH_OSD_TMAP_HDR
: // update header
4136 ::decode(header
, bp
);
4146 ::encode(header
, obl
);
4150 vector
<OSDOp
> nops(1);
4151 OSDOp
& newop
= nops
[0];
4152 newop
.op
.op
= CEPH_OSD_OP_WRITEFULL
;
4153 newop
.op
.extent
.offset
= 0;
4154 newop
.op
.extent
.length
= obl
.length();
4156 do_osd_ops(ctx
, nops
);
4157 osd_op
.outdata
.claim(newop
.outdata
);
4161 int PrimaryLogPG::do_tmapup(OpContext
*ctx
, bufferlist::iterator
& bp
, OSDOp
& osd_op
)
4163 bufferlist::iterator orig_bp
= bp
;
4166 dout(10) << "tmapup is a no-op" << dendl
;
4168 // read the whole object
4169 vector
<OSDOp
> nops(1);
4170 OSDOp
& newop
= nops
[0];
4171 newop
.op
.op
= CEPH_OSD_OP_READ
;
4172 newop
.op
.extent
.offset
= 0;
4173 newop
.op
.extent
.length
= 0;
4174 result
= do_osd_ops(ctx
, nops
);
4176 dout(10) << "tmapup read " << newop
.outdata
.length() << dendl
;
4178 dout(30) << " starting is \n";
4179 newop
.outdata
.hexdump(*_dout
);
4182 bufferlist::iterator ip
= newop
.outdata
.begin();
4185 dout(30) << "the update command is: \n";
4186 osd_op
.indata
.hexdump(*_dout
);
4192 if (newop
.outdata
.length()) {
4193 ::decode(header
, ip
);
4194 ::decode(nkeys
, ip
);
4196 dout(10) << "tmapup header " << header
.length() << dendl
;
4198 if (!bp
.end() && *bp
== CEPH_OSD_TMAP_HDR
) {
4200 ::decode(header
, bp
);
4201 dout(10) << "tmapup new header " << header
.length() << dendl
;
4204 ::encode(header
, obl
);
4206 dout(20) << "tmapup initial nkeys " << nkeys
<< dendl
;
4209 bufferlist newkeydata
;
4210 string nextkey
, last_in_key
;
4212 bool have_next
= false;
4215 ::decode(nextkey
, ip
);
4216 ::decode(nextval
, ip
);
4218 while (!bp
.end() && !result
) {
4225 catch (buffer::error
& e
) {
4228 if (key
< last_in_key
) {
4229 dout(5) << "tmapup warning: key '" << key
<< "' < previous key '" << last_in_key
4230 << "', falling back to an inefficient (unsorted) update" << dendl
;
4232 return do_tmapup_slow(ctx
, bp
, osd_op
, newop
.outdata
);
4236 dout(10) << "tmapup op " << (int)op
<< " key " << key
<< dendl
;
4238 // skip existing intervening keys
4239 bool key_exists
= false;
4240 while (have_next
&& !key_exists
) {
4241 dout(20) << " (have_next=" << have_next
<< " nextkey=" << nextkey
<< ")" << dendl
;
4244 if (nextkey
< key
) {
4246 ::encode(nextkey
, newkeydata
);
4247 ::encode(nextval
, newkeydata
);
4248 dout(20) << " keep " << nextkey
<< " " << nextval
.length() << dendl
;
4250 // don't copy; discard old value. and stop.
4251 dout(20) << " drop " << nextkey
<< " " << nextval
.length() << dendl
;
4256 ::decode(nextkey
, ip
);
4257 ::decode(nextval
, ip
);
4263 if (op
== CEPH_OSD_TMAP_SET
) {
4268 catch (buffer::error
& e
) {
4271 ::encode(key
, newkeydata
);
4272 ::encode(val
, newkeydata
);
4273 dout(20) << " set " << key
<< " " << val
.length() << dendl
;
4275 } else if (op
== CEPH_OSD_TMAP_CREATE
) {
4283 catch (buffer::error
& e
) {
4286 ::encode(key
, newkeydata
);
4287 ::encode(val
, newkeydata
);
4288 dout(20) << " create " << key
<< " " << val
.length() << dendl
;
4290 } else if (op
== CEPH_OSD_TMAP_RM
) {
4295 } else if (op
== CEPH_OSD_TMAP_RMSLOPPY
) {
4298 dout(10) << " invalid tmap op " << (int)op
<< dendl
;
4305 ::encode(nextkey
, newkeydata
);
4306 ::encode(nextval
, newkeydata
);
4307 dout(20) << " keep " << nextkey
<< " " << nextval
.length() << dendl
;
4311 rest
.substr_of(newop
.outdata
, ip
.get_off(), newop
.outdata
.length() - ip
.get_off());
4312 dout(20) << " keep trailing " << rest
.length()
4313 << " at " << newkeydata
.length() << dendl
;
4314 newkeydata
.claim_append(rest
);
4317 // encode final key count + key data
4318 dout(20) << "tmapup final nkeys " << nkeys
<< dendl
;
4319 ::encode(nkeys
, obl
);
4320 obl
.claim_append(newkeydata
);
4323 dout(30) << " final is \n";
4324 obl
.hexdump(*_dout
);
4328 bufferlist::iterator tp
= obl
.begin();
4331 map
<string
,bufferlist
> d
;
4334 dout(0) << " **** debug sanity check, looks ok ****" << dendl
;
4339 dout(20) << "tmapput write " << obl
.length() << dendl
;
4340 newop
.op
.op
= CEPH_OSD_OP_WRITEFULL
;
4341 newop
.op
.extent
.offset
= 0;
4342 newop
.op
.extent
.length
= obl
.length();
4344 do_osd_ops(ctx
, nops
);
4345 osd_op
.outdata
.claim(newop
.outdata
);
4351 static int check_offset_and_length(uint64_t offset
, uint64_t length
, uint64_t max
)
4353 if (offset
>= max
||
4355 offset
+ length
> max
)
4361 struct FillInVerifyExtent
: public Context
{
4364 bufferlist
*outdatap
;
4365 boost::optional
<uint32_t> maybe_crc
;
4370 FillInVerifyExtent(ceph_le64
*r
, int32_t *rv
, bufferlist
*blp
,
4371 boost::optional
<uint32_t> mc
, uint64_t size
,
4372 OSDService
*osd
, hobject_t soid
, __le32 flags
) :
4373 r(r
), rval(rv
), outdatap(blp
), maybe_crc(mc
),
4374 size(size
), osd(osd
), soid(soid
), flags(flags
) {}
4375 void finish(int len
) override
{
4383 // whole object? can we verify the checksum?
4384 if (maybe_crc
&& *r
== size
) {
4385 uint32_t crc
= outdatap
->crc32c(-1);
4386 if (maybe_crc
!= crc
) {
4387 osd
->clog
->error() << std::hex
<< " full-object read crc 0x" << crc
4388 << " != expected 0x" << *maybe_crc
4389 << std::dec
<< " on " << soid
;
4390 if (!(flags
& CEPH_OSD_OP_FLAG_FAILOK
)) {
4399 struct ToSparseReadResult
: public Context
{
4401 bufferlist
* data_bl
;
4402 uint64_t data_offset
;
4404 ToSparseReadResult(int* result
, bufferlist
* bl
, uint64_t offset
,
4406 : result(result
), data_bl(bl
), data_offset(offset
),len(len
) {}
4407 void finish(int r
) override
{
4415 map
<uint64_t, uint64_t> extents
= {{data_offset
, r
}};
4416 ::encode(extents
, outdata
);
4417 ::encode_destructively(*data_bl
, outdata
);
4418 data_bl
->swap(outdata
);
4422 template<typename V
>
4423 static string
list_keys(const map
<string
, V
>& m
) {
4425 for (typename map
<string
, V
>::const_iterator itr
= m
.begin(); itr
!= m
.end(); ++itr
) {
4429 s
.append(itr
->first
);
4434 template<typename T
>
4435 static string
list_entries(const T
& m
) {
4437 for (typename
T::const_iterator itr
= m
.begin(); itr
!= m
.end(); ++itr
) {
4446 void PrimaryLogPG::maybe_create_new_object(
4448 bool ignore_transaction
)
4450 ObjectState
& obs
= ctx
->new_obs
;
4452 ctx
->delta_stats
.num_objects
++;
4454 assert(!obs
.oi
.is_whiteout());
4455 obs
.oi
.new_object();
4456 if (!ignore_transaction
)
4457 ctx
->op_t
->create(obs
.oi
.soid
);
4458 } else if (obs
.oi
.is_whiteout()) {
4459 dout(10) << __func__
<< " clearing whiteout on " << obs
.oi
.soid
<< dendl
;
4460 ctx
->new_obs
.oi
.clear_flag(object_info_t::FLAG_WHITEOUT
);
4461 --ctx
->delta_stats
.num_whiteouts
;
4465 struct ReadFinisher
: public PrimaryLogPG::OpFinisher
{
4468 ReadFinisher(OSDOp
& osd_op
) : osd_op(osd_op
) {
4471 int execute() override
{
4476 struct C_ChecksumRead
: public Context
{
4477 PrimaryLogPG
*primary_log_pg
;
4479 Checksummer::CSumType csum_type
;
4480 bufferlist init_value_bl
;
4481 ceph_le64 read_length
;
4483 Context
*fill_extent_ctx
;
4485 C_ChecksumRead(PrimaryLogPG
*primary_log_pg
, OSDOp
&osd_op
,
4486 Checksummer::CSumType csum_type
, bufferlist
&&init_value_bl
,
4487 boost::optional
<uint32_t> maybe_crc
, uint64_t size
,
4488 OSDService
*osd
, hobject_t soid
, __le32 flags
)
4489 : primary_log_pg(primary_log_pg
), osd_op(osd_op
),
4490 csum_type(csum_type
), init_value_bl(std::move(init_value_bl
)),
4491 fill_extent_ctx(new FillInVerifyExtent(&read_length
, &osd_op
.rval
,
4492 &read_bl
, maybe_crc
, size
,
4493 osd
, soid
, flags
)) {
4495 ~C_ChecksumRead() override
{
4496 delete fill_extent_ctx
;
4499 void finish(int r
) override
{
4500 fill_extent_ctx
->complete(r
);
4501 fill_extent_ctx
= nullptr;
4503 if (osd_op
.rval
>= 0) {
4504 bufferlist::iterator init_value_bl_it
= init_value_bl
.begin();
4505 osd_op
.rval
= primary_log_pg
->finish_checksum(osd_op
, csum_type
,
4506 &init_value_bl_it
, read_bl
);
4511 int PrimaryLogPG::do_checksum(OpContext
*ctx
, OSDOp
& osd_op
,
4512 bufferlist::iterator
*bl_it
)
4514 dout(20) << __func__
<< dendl
;
4516 auto& op
= osd_op
.op
;
4517 if (op
.checksum
.chunk_size
> 0) {
4518 if (op
.checksum
.length
== 0) {
4519 dout(10) << __func__
<< ": length required when chunk size provided"
4523 if (op
.checksum
.length
% op
.checksum
.chunk_size
!= 0) {
4524 dout(10) << __func__
<< ": length not aligned to chunk size" << dendl
;
4529 auto& oi
= ctx
->new_obs
.oi
;
4530 if (op
.checksum
.offset
== 0 && op
.checksum
.length
== 0) {
4531 // zeroed offset+length implies checksum whole object
4532 op
.checksum
.length
= oi
.size
;
4533 } else if (op
.checksum
.offset
+ op
.checksum
.length
> oi
.size
) {
4537 Checksummer::CSumType csum_type
;
4538 switch (op
.checksum
.type
) {
4539 case CEPH_OSD_CHECKSUM_OP_TYPE_XXHASH32
:
4540 csum_type
= Checksummer::CSUM_XXHASH32
;
4542 case CEPH_OSD_CHECKSUM_OP_TYPE_XXHASH64
:
4543 csum_type
= Checksummer::CSUM_XXHASH64
;
4545 case CEPH_OSD_CHECKSUM_OP_TYPE_CRC32C
:
4546 csum_type
= Checksummer::CSUM_CRC32C
;
4549 dout(10) << __func__
<< ": unknown crc type ("
4550 << static_cast<uint32_t>(op
.checksum
.type
) << ")" << dendl
;
4554 size_t csum_init_value_size
= Checksummer::get_csum_init_value_size(csum_type
);
4555 if (bl_it
->get_remaining() < csum_init_value_size
) {
4556 dout(10) << __func__
<< ": init value not provided" << dendl
;
4560 bufferlist init_value_bl
;
4561 init_value_bl
.substr_of(bl_it
->get_bl(), bl_it
->get_off(),
4562 csum_init_value_size
);
4563 bl_it
->advance(csum_init_value_size
);
4565 if (pool
.info
.require_rollback() && op
.checksum
.length
> 0) {
4566 // If there is a data digest and it is possible we are reading
4567 // entire object, pass the digest.
4568 boost::optional
<uint32_t> maybe_crc
;
4569 if (oi
.is_data_digest() && op
.checksum
.offset
== 0 &&
4570 op
.checksum
.length
>= oi
.size
) {
4571 maybe_crc
= oi
.data_digest
;
4575 auto& soid
= oi
.soid
;
4576 auto checksum_ctx
= new C_ChecksumRead(this, osd_op
, csum_type
,
4577 std::move(init_value_bl
), maybe_crc
,
4578 oi
.size
, osd
, soid
, op
.flags
);
4580 ctx
->pending_async_reads
.push_back({
4581 {op
.checksum
.offset
, op
.checksum
.length
, op
.flags
},
4582 {&checksum_ctx
->read_bl
, checksum_ctx
}});
4584 dout(10) << __func__
<< ": async_read noted for " << soid
<< dendl
;
4585 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
4586 new ReadFinisher(osd_op
));
4587 return -EINPROGRESS
;
4591 std::vector
<OSDOp
> read_ops(1);
4592 auto& read_op
= read_ops
[0];
4593 if (op
.checksum
.length
> 0) {
4594 read_op
.op
.op
= CEPH_OSD_OP_READ
;
4595 read_op
.op
.flags
= op
.flags
;
4596 read_op
.op
.extent
.offset
= op
.checksum
.offset
;
4597 read_op
.op
.extent
.length
= op
.checksum
.length
;
4598 read_op
.op
.extent
.truncate_size
= 0;
4599 read_op
.op
.extent
.truncate_seq
= 0;
4601 int r
= do_osd_ops(ctx
, read_ops
);
4603 derr
<< __func__
<< ": do_osd_ops failed: " << cpp_strerror(r
) << dendl
;
4608 bufferlist::iterator init_value_bl_it
= init_value_bl
.begin();
4609 return finish_checksum(osd_op
, csum_type
, &init_value_bl_it
,
4613 int PrimaryLogPG::finish_checksum(OSDOp
& osd_op
,
4614 Checksummer::CSumType csum_type
,
4615 bufferlist::iterator
*init_value_bl_it
,
4616 const bufferlist
&read_bl
) {
4617 dout(20) << __func__
<< dendl
;
4619 auto& op
= osd_op
.op
;
4621 if (op
.checksum
.length
> 0 && read_bl
.length() != op
.checksum
.length
) {
4622 derr
<< __func__
<< ": bytes read " << read_bl
.length() << " != "
4623 << op
.checksum
.length
<< dendl
;
4627 size_t csum_chunk_size
= (op
.checksum
.chunk_size
!= 0 ?
4628 op
.checksum
.chunk_size
: read_bl
.length());
4629 uint32_t csum_count
= (csum_chunk_size
> 0 ?
4630 read_bl
.length() / csum_chunk_size
: 0);
4633 bufferptr csum_data
;
4634 if (csum_count
> 0) {
4635 size_t csum_value_size
= Checksummer::get_csum_value_size(csum_type
);
4636 csum_data
= buffer::create(csum_value_size
* csum_count
);
4638 csum
.append(csum_data
);
4640 switch (csum_type
) {
4641 case Checksummer::CSUM_XXHASH32
:
4643 Checksummer::xxhash32::init_value_t init_value
;
4644 ::decode(init_value
, *init_value_bl_it
);
4645 Checksummer::calculate
<Checksummer::xxhash32
>(
4646 init_value
, csum_chunk_size
, 0, read_bl
.length(), read_bl
,
4650 case Checksummer::CSUM_XXHASH64
:
4652 Checksummer::xxhash64::init_value_t init_value
;
4653 ::decode(init_value
, *init_value_bl_it
);
4654 Checksummer::calculate
<Checksummer::xxhash64
>(
4655 init_value
, csum_chunk_size
, 0, read_bl
.length(), read_bl
,
4659 case Checksummer::CSUM_CRC32C
:
4661 Checksummer::crc32c::init_value_t init_value
;
4662 ::decode(init_value
, *init_value_bl_it
);
4663 Checksummer::calculate
<Checksummer::crc32c
>(
4664 init_value
, csum_chunk_size
, 0, read_bl
.length(), read_bl
,
4673 ::encode(csum_count
, osd_op
.outdata
);
4674 osd_op
.outdata
.claim_append(csum
);
4678 struct C_ExtentCmpRead
: public Context
{
4679 PrimaryLogPG
*primary_log_pg
;
4681 ceph_le64 read_length
;
4683 Context
*fill_extent_ctx
;
4685 C_ExtentCmpRead(PrimaryLogPG
*primary_log_pg
, OSDOp
&osd_op
,
4686 boost::optional
<uint32_t> maybe_crc
, uint64_t size
,
4687 OSDService
*osd
, hobject_t soid
, __le32 flags
)
4688 : primary_log_pg(primary_log_pg
), osd_op(osd_op
),
4689 fill_extent_ctx(new FillInVerifyExtent(&read_length
, &osd_op
.rval
,
4690 &read_bl
, maybe_crc
, size
,
4691 osd
, soid
, flags
)) {
4693 ~C_ExtentCmpRead() override
{
4694 delete fill_extent_ctx
;
4697 void finish(int r
) override
{
4701 delete fill_extent_ctx
;
4703 fill_extent_ctx
->complete(r
);
4705 fill_extent_ctx
= nullptr;
4707 if (osd_op
.rval
>= 0) {
4708 osd_op
.rval
= primary_log_pg
->finish_extent_cmp(osd_op
, read_bl
);
4713 int PrimaryLogPG::do_extent_cmp(OpContext
*ctx
, OSDOp
& osd_op
)
4715 dout(20) << __func__
<< dendl
;
4716 ceph_osd_op
& op
= osd_op
.op
;
4718 if (!ctx
->obs
->exists
|| ctx
->obs
->oi
.is_whiteout()) {
4719 dout(20) << __func__
<< " object DNE" << dendl
;
4720 return finish_extent_cmp(osd_op
, {});
4721 } else if (pool
.info
.require_rollback()) {
4722 // If there is a data digest and it is possible we are reading
4723 // entire object, pass the digest.
4724 auto& oi
= ctx
->new_obs
.oi
;
4725 boost::optional
<uint32_t> maybe_crc
;
4726 if (oi
.is_data_digest() && op
.checksum
.offset
== 0 &&
4727 op
.checksum
.length
>= oi
.size
) {
4728 maybe_crc
= oi
.data_digest
;
4732 auto& soid
= oi
.soid
;
4733 auto extent_cmp_ctx
= new C_ExtentCmpRead(this, osd_op
, maybe_crc
, oi
.size
,
4734 osd
, soid
, op
.flags
);
4735 ctx
->pending_async_reads
.push_back({
4736 {op
.extent
.offset
, op
.extent
.length
, op
.flags
},
4737 {&extent_cmp_ctx
->read_bl
, extent_cmp_ctx
}});
4739 dout(10) << __func__
<< ": async_read noted for " << soid
<< dendl
;
4741 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
4742 new ReadFinisher(osd_op
));
4743 return -EINPROGRESS
;
4747 vector
<OSDOp
> read_ops(1);
4748 OSDOp
& read_op
= read_ops
[0];
4750 read_op
.op
.op
= CEPH_OSD_OP_SYNC_READ
;
4751 read_op
.op
.extent
.offset
= op
.extent
.offset
;
4752 read_op
.op
.extent
.length
= op
.extent
.length
;
4753 read_op
.op
.extent
.truncate_seq
= op
.extent
.truncate_seq
;
4754 read_op
.op
.extent
.truncate_size
= op
.extent
.truncate_size
;
4756 int result
= do_osd_ops(ctx
, read_ops
);
4758 derr
<< __func__
<< " failed " << result
<< dendl
;
4761 return finish_extent_cmp(osd_op
, read_op
.outdata
);
4764 int PrimaryLogPG::finish_extent_cmp(OSDOp
& osd_op
, const bufferlist
&read_bl
)
4766 for (uint64_t idx
= 0; idx
< osd_op
.indata
.length(); ++idx
) {
4767 char read_byte
= (idx
< read_bl
.length() ? read_bl
[idx
] : 0);
4768 if (osd_op
.indata
[idx
] != read_byte
) {
4769 return (-MAX_ERRNO
- idx
);
4776 int PrimaryLogPG::do_read(OpContext
*ctx
, OSDOp
& osd_op
) {
4777 dout(20) << __func__
<< dendl
;
4778 auto& op
= osd_op
.op
;
4779 auto& oi
= ctx
->new_obs
.oi
;
4780 auto& soid
= oi
.soid
;
4781 __u32 seq
= oi
.truncate_seq
;
4782 uint64_t size
= oi
.size
;
4783 bool trimmed_read
= false;
4785 // are we beyond truncate_size?
4786 if ( (seq
< op
.extent
.truncate_seq
) &&
4787 (op
.extent
.offset
+ op
.extent
.length
> op
.extent
.truncate_size
) )
4788 size
= op
.extent
.truncate_size
;
4790 if (op
.extent
.length
== 0) //length is zero mean read the whole object
4791 op
.extent
.length
= size
;
4793 if (op
.extent
.offset
>= size
) {
4794 op
.extent
.length
= 0;
4795 trimmed_read
= true;
4796 } else if (op
.extent
.offset
+ op
.extent
.length
> size
) {
4797 op
.extent
.length
= size
- op
.extent
.offset
;
4798 trimmed_read
= true;
4801 // read into a buffer
4803 if (trimmed_read
&& op
.extent
.length
== 0) {
4804 // read size was trimmed to zero and it is expected to do nothing
4805 // a read operation of 0 bytes does *not* do nothing, this is why
4806 // the trimmed_read boolean is needed
4807 } else if (pool
.info
.require_rollback()) {
4808 boost::optional
<uint32_t> maybe_crc
;
4809 // If there is a data digest and it is possible we are reading
4810 // entire object, pass the digest. FillInVerifyExtent will
4811 // will check the oi.size again.
4812 if (oi
.is_data_digest() && op
.extent
.offset
== 0 &&
4813 op
.extent
.length
>= oi
.size
)
4814 maybe_crc
= oi
.data_digest
;
4815 ctx
->pending_async_reads
.push_back(
4817 boost::make_tuple(op
.extent
.offset
, op
.extent
.length
, op
.flags
),
4818 make_pair(&osd_op
.outdata
,
4819 new FillInVerifyExtent(&op
.extent
.length
, &osd_op
.rval
,
4820 &osd_op
.outdata
, maybe_crc
, oi
.size
,
4821 osd
, soid
, op
.flags
))));
4822 dout(10) << " async_read noted for " << soid
<< dendl
;
4824 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
4825 new ReadFinisher(osd_op
));
4827 int r
= pgbackend
->objects_read_sync(
4828 soid
, op
.extent
.offset
, op
.extent
.length
, op
.flags
, &osd_op
.outdata
);
4830 r
= rep_repair_primary_object(soid
, ctx
->op
);
4833 op
.extent
.length
= r
;
4836 op
.extent
.length
= 0;
4838 dout(10) << " read got " << r
<< " / " << op
.extent
.length
4839 << " bytes from obj " << soid
<< dendl
;
4841 // whole object? can we verify the checksum?
4842 if (op
.extent
.length
== oi
.size
&& oi
.is_data_digest()) {
4843 uint32_t crc
= osd_op
.outdata
.crc32c(-1);
4844 if (oi
.data_digest
!= crc
) {
4845 osd
->clog
->error() << info
.pgid
<< std::hex
4846 << " full-object read crc 0x" << crc
4847 << " != expected 0x" << oi
.data_digest
4848 << std::dec
<< " on " << soid
;
4849 // FIXME fall back to replica or something?
4855 // XXX the op.extent.length is the requested length for async read
4856 // On error this length is changed to 0 after the error comes back.
4857 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(op
.extent
.length
, 10);
4858 ctx
->delta_stats
.num_rd
++;
4862 int PrimaryLogPG::do_sparse_read(OpContext
*ctx
, OSDOp
& osd_op
) {
4863 dout(20) << __func__
<< dendl
;
4864 auto& op
= osd_op
.op
;
4865 auto& oi
= ctx
->new_obs
.oi
;
4866 auto& soid
= oi
.soid
;
4868 if (op
.extent
.truncate_seq
) {
4869 dout(0) << "sparse_read does not support truncation sequence " << dendl
;
4874 if (pool
.info
.ec_pool()) {
4875 // translate sparse read to a normal one if not supported
4876 uint64_t offset
= op
.extent
.offset
;
4877 uint64_t length
= op
.extent
.length
;
4878 if (offset
> oi
.size
) {
4880 } else if (offset
+ length
> oi
.size
) {
4881 length
= oi
.size
- offset
;
4885 ctx
->pending_async_reads
.push_back(
4887 boost::make_tuple(offset
, length
, op
.flags
),
4890 new ToSparseReadResult(&osd_op
.rval
, &osd_op
.outdata
, offset
,
4891 &op
.extent
.length
))));
4892 dout(10) << " async_read (was sparse_read) noted for " << soid
<< dendl
;
4894 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
4895 new ReadFinisher(osd_op
));
4897 dout(10) << " sparse read ended up empty for " << soid
<< dendl
;
4898 map
<uint64_t, uint64_t> extents
;
4899 ::encode(extents
, osd_op
.outdata
);
4902 // read into a buffer
4903 map
<uint64_t, uint64_t> m
;
4904 uint32_t total_read
= 0;
4905 int r
= osd
->store
->fiemap(ch
, ghobject_t(soid
, ghobject_t::NO_GEN
,
4907 op
.extent
.offset
, op
.extent
.length
, m
);
4912 map
<uint64_t, uint64_t>::iterator miter
;
4914 uint64_t last
= op
.extent
.offset
;
4915 for (miter
= m
.begin(); miter
!= m
.end(); ++miter
) {
4917 if (cct
->_conf
->osd_verify_sparse_read_holes
&&
4918 last
< miter
->first
) {
4920 uint64_t len
= miter
->first
- last
;
4921 r
= pgbackend
->objects_read_sync(soid
, last
, len
, op
.flags
, &t
);
4923 osd
->clog
->error() << coll
<< " " << soid
4924 << " sparse-read failed to read: "
4926 } else if (!t
.is_zero()) {
4927 osd
->clog
->error() << coll
<< " " << soid
4928 << " sparse-read found data in hole "
4929 << last
<< "~" << len
;
4934 r
= pgbackend
->objects_read_sync(soid
, miter
->first
, miter
->second
,
4937 r
= rep_repair_primary_object(soid
, ctx
->op
);
4943 // this is usually happen when we get extent that exceeds the actual file
4945 if (r
< (int)miter
->second
)
4948 dout(10) << "sparse-read " << miter
->first
<< "@" << miter
->second
4950 data_bl
.claim_append(tmpbl
);
4951 last
= miter
->first
+ r
;
4958 // verify trailing hole?
4959 if (cct
->_conf
->osd_verify_sparse_read_holes
) {
4960 uint64_t end
= MIN(op
.extent
.offset
+ op
.extent
.length
, oi
.size
);
4963 uint64_t len
= end
- last
;
4964 r
= pgbackend
->objects_read_sync(soid
, last
, len
, op
.flags
, &t
);
4966 osd
->clog
->error() << coll
<< " " << soid
4967 << " sparse-read failed to read: " << r
;
4968 } else if (!t
.is_zero()) {
4969 osd
->clog
->error() << coll
<< " " << soid
4970 << " sparse-read found data in hole "
4971 << last
<< "~" << len
;
4976 // Why SPARSE_READ need checksum? In fact, librbd always use sparse-read.
4977 // Maybe at first, there is no much whole objects. With continued use, more
4978 // and more whole object exist. So from this point, for spare-read add
4979 // checksum make sense.
4980 if (total_read
== oi
.size
&& oi
.is_data_digest()) {
4981 uint32_t crc
= data_bl
.crc32c(-1);
4982 if (oi
.data_digest
!= crc
) {
4983 osd
->clog
->error() << info
.pgid
<< std::hex
4984 << " full-object read crc 0x" << crc
4985 << " != expected 0x" << oi
.data_digest
4986 << std::dec
<< " on " << soid
;
4987 // FIXME fall back to replica or something?
4992 op
.extent
.length
= total_read
;
4994 ::encode(m
, osd_op
.outdata
); // re-encode since it might be modified
4995 ::encode_destructively(data_bl
, osd_op
.outdata
);
4997 dout(10) << " sparse_read got " << total_read
<< " bytes from object "
5001 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(op
.extent
.length
, 10);
5002 ctx
->delta_stats
.num_rd
++;
5006 int PrimaryLogPG::do_osd_ops(OpContext
*ctx
, vector
<OSDOp
>& ops
)
5009 SnapSetContext
*ssc
= ctx
->obc
->ssc
;
5010 ObjectState
& obs
= ctx
->new_obs
;
5011 object_info_t
& oi
= obs
.oi
;
5012 const hobject_t
& soid
= oi
.soid
;
5014 PGTransaction
* t
= ctx
->op_t
.get();
5016 dout(10) << "do_osd_op " << soid
<< " " << ops
<< dendl
;
5018 ctx
->current_osd_subop_num
= 0;
5019 for (vector
<OSDOp
>::iterator p
= ops
.begin(); p
!= ops
.end(); ++p
, ctx
->current_osd_subop_num
++) {
5021 ceph_osd_op
& op
= osd_op
.op
;
5023 OpFinisher
* op_finisher
= nullptr;
5025 auto op_finisher_it
= ctx
->op_finishers
.find(ctx
->current_osd_subop_num
);
5026 if (op_finisher_it
!= ctx
->op_finishers
.end()) {
5027 op_finisher
= op_finisher_it
->second
.get();
5031 // TODO: check endianness (__le32 vs uint32_t, etc.)
5032 // The fields in ceph_osd_op are little-endian (according to the definition in rados.h),
5033 // but the code in this function seems to treat them as native-endian. What should the
5035 tracepoint(osd
, do_osd_op_pre
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.op
, ceph_osd_op_name(op
.op
), op
.flags
);
5037 dout(10) << "do_osd_op " << osd_op
<< dendl
;
5039 bufferlist::iterator bp
= osd_op
.indata
.begin();
5041 // user-visible modifcation?
5043 // non user-visible modifications
5044 case CEPH_OSD_OP_WATCH
:
5045 case CEPH_OSD_OP_CACHE_EVICT
:
5046 case CEPH_OSD_OP_CACHE_FLUSH
:
5047 case CEPH_OSD_OP_CACHE_TRY_FLUSH
:
5048 case CEPH_OSD_OP_UNDIRTY
:
5049 case CEPH_OSD_OP_COPY_FROM
: // we handle user_version update explicitly
5050 case CEPH_OSD_OP_CACHE_PIN
:
5051 case CEPH_OSD_OP_CACHE_UNPIN
:
5052 case CEPH_OSD_OP_SET_REDIRECT
:
5055 if (op
.op
& CEPH_OSD_OP_MODE_WR
)
5056 ctx
->user_modify
= true;
5059 // munge -1 truncate to 0 truncate
5060 if (ceph_osd_op_uses_extent(op
.op
) &&
5061 op
.extent
.truncate_seq
== 1 &&
5062 op
.extent
.truncate_size
== (-1ULL)) {
5063 op
.extent
.truncate_size
= 0;
5064 op
.extent
.truncate_seq
= 0;
5067 // munge ZERO -> TRUNCATE? (don't munge to DELETE or we risk hosing attributes)
5068 if (op
.op
== CEPH_OSD_OP_ZERO
&&
5070 op
.extent
.offset
< cct
->_conf
->osd_max_object_size
&&
5071 op
.extent
.length
>= 1 &&
5072 op
.extent
.length
<= cct
->_conf
->osd_max_object_size
&&
5073 op
.extent
.offset
+ op
.extent
.length
>= oi
.size
) {
5074 if (op
.extent
.offset
>= oi
.size
) {
5078 dout(10) << " munging ZERO " << op
.extent
.offset
<< "~" << op
.extent
.length
5079 << " -> TRUNCATE " << op
.extent
.offset
<< " (old size is " << oi
.size
<< ")" << dendl
;
5080 op
.op
= CEPH_OSD_OP_TRUNCATE
;
5087 case CEPH_OSD_OP_CMPEXT
:
5089 tracepoint(osd
, do_osd_op_pre_extent_cmp
, soid
.oid
.name
.c_str(),
5090 soid
.snap
.val
, oi
.size
, oi
.truncate_seq
, op
.extent
.offset
,
5091 op
.extent
.length
, op
.extent
.truncate_size
,
5092 op
.extent
.truncate_seq
);
5094 if (op_finisher
== nullptr) {
5095 result
= do_extent_cmp(ctx
, osd_op
);
5097 result
= op_finisher
->execute();
5101 case CEPH_OSD_OP_SYNC_READ
:
5102 if (pool
.info
.require_rollback()) {
5103 result
= -EOPNOTSUPP
;
5107 case CEPH_OSD_OP_READ
:
5109 tracepoint(osd
, do_osd_op_pre_read
, soid
.oid
.name
.c_str(),
5110 soid
.snap
.val
, oi
.size
, oi
.truncate_seq
, op
.extent
.offset
,
5111 op
.extent
.length
, op
.extent
.truncate_size
,
5112 op
.extent
.truncate_seq
);
5113 if (op_finisher
== nullptr) {
5114 if (!ctx
->data_off
) {
5115 ctx
->data_off
= op
.extent
.offset
;
5117 result
= do_read(ctx
, osd_op
);
5119 result
= op_finisher
->execute();
5123 case CEPH_OSD_OP_CHECKSUM
:
5126 tracepoint(osd
, do_osd_op_pre_checksum
, soid
.oid
.name
.c_str(),
5127 soid
.snap
.val
, oi
.size
, oi
.truncate_seq
, op
.checksum
.type
,
5128 op
.checksum
.offset
, op
.checksum
.length
,
5129 op
.checksum
.chunk_size
);
5131 if (op_finisher
== nullptr) {
5132 result
= do_checksum(ctx
, osd_op
, &bp
);
5134 result
= op_finisher
->execute();
5140 case CEPH_OSD_OP_MAPEXT
:
5141 tracepoint(osd
, do_osd_op_pre_mapext
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.extent
.offset
, op
.extent
.length
);
5142 if (pool
.info
.require_rollback()) {
5143 result
= -EOPNOTSUPP
;
5148 // read into a buffer
5150 int r
= osd
->store
->fiemap(ch
, ghobject_t(soid
, ghobject_t::NO_GEN
,
5152 op
.extent
.offset
, op
.extent
.length
, bl
);
5153 osd_op
.outdata
.claim(bl
);
5157 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(bl
.length(), 10);
5158 ctx
->delta_stats
.num_rd
++;
5159 dout(10) << " map_extents done on object " << soid
<< dendl
;
5164 case CEPH_OSD_OP_SPARSE_READ
:
5165 tracepoint(osd
, do_osd_op_pre_sparse_read
, soid
.oid
.name
.c_str(),
5166 soid
.snap
.val
, oi
.size
, oi
.truncate_seq
, op
.extent
.offset
,
5167 op
.extent
.length
, op
.extent
.truncate_size
,
5168 op
.extent
.truncate_seq
);
5169 if (op_finisher
== nullptr) {
5170 result
= do_sparse_read(ctx
, osd_op
);
5172 result
= op_finisher
->execute();
5176 case CEPH_OSD_OP_CALL
:
5178 string cname
, mname
;
5181 bp
.copy(op
.cls
.class_len
, cname
);
5182 bp
.copy(op
.cls
.method_len
, mname
);
5183 bp
.copy(op
.cls
.indata_len
, indata
);
5184 } catch (buffer::error
& e
) {
5185 dout(10) << "call unable to decode class + method + indata" << dendl
;
5186 dout(30) << "in dump: ";
5187 osd_op
.indata
.hexdump(*_dout
);
5190 tracepoint(osd
, do_osd_op_pre_call
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???", "???");
5193 tracepoint(osd
, do_osd_op_pre_call
, soid
.oid
.name
.c_str(), soid
.snap
.val
, cname
.c_str(), mname
.c_str());
5195 ClassHandler::ClassData
*cls
;
5196 result
= osd
->class_handler
->open_class(cname
, &cls
);
5197 assert(result
== 0); // init_op_flags() already verified this works.
5199 ClassHandler::ClassMethod
*method
= cls
->get_method(mname
.c_str());
5201 dout(10) << "call method " << cname
<< "." << mname
<< " does not exist" << dendl
;
5202 result
= -EOPNOTSUPP
;
5206 int flags
= method
->get_flags();
5207 if (flags
& CLS_METHOD_WR
)
5208 ctx
->user_modify
= true;
5211 dout(10) << "call method " << cname
<< "." << mname
<< dendl
;
5212 int prev_rd
= ctx
->num_read
;
5213 int prev_wr
= ctx
->num_write
;
5214 result
= method
->exec((cls_method_context_t
)&ctx
, indata
, outdata
);
5216 if (ctx
->num_read
> prev_rd
&& !(flags
& CLS_METHOD_RD
)) {
5217 derr
<< "method " << cname
<< "." << mname
<< " tried to read object but is not marked RD" << dendl
;
5221 if (ctx
->num_write
> prev_wr
&& !(flags
& CLS_METHOD_WR
)) {
5222 derr
<< "method " << cname
<< "." << mname
<< " tried to update object but is not marked WR" << dendl
;
5227 dout(10) << "method called response length=" << outdata
.length() << dendl
;
5228 op
.extent
.length
= outdata
.length();
5229 osd_op
.outdata
.claim_append(outdata
);
5230 dout(30) << "out dump: ";
5231 osd_op
.outdata
.hexdump(*_dout
);
5236 case CEPH_OSD_OP_STAT
:
5237 // note: stat does not require RD
5239 tracepoint(osd
, do_osd_op_pre_stat
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5241 if (obs
.exists
&& !oi
.is_whiteout()) {
5242 ::encode(oi
.size
, osd_op
.outdata
);
5243 ::encode(oi
.mtime
, osd_op
.outdata
);
5244 dout(10) << "stat oi has " << oi
.size
<< " " << oi
.mtime
<< dendl
;
5247 dout(10) << "stat oi object does not exist" << dendl
;
5250 ctx
->delta_stats
.num_rd
++;
5254 case CEPH_OSD_OP_ISDIRTY
:
5257 tracepoint(osd
, do_osd_op_pre_isdirty
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5258 bool is_dirty
= obs
.oi
.is_dirty();
5259 ::encode(is_dirty
, osd_op
.outdata
);
5260 ctx
->delta_stats
.num_rd
++;
5265 case CEPH_OSD_OP_UNDIRTY
:
5268 tracepoint(osd
, do_osd_op_pre_undirty
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5269 if (oi
.is_dirty()) {
5270 ctx
->undirty
= true; // see make_writeable()
5272 ctx
->delta_stats
.num_wr
++;
5278 case CEPH_OSD_OP_CACHE_TRY_FLUSH
:
5281 tracepoint(osd
, do_osd_op_pre_try_flush
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5282 if (ctx
->lock_type
!= ObjectContext::RWState::RWNONE
) {
5283 dout(10) << "cache-try-flush without SKIPRWLOCKS flag set" << dendl
;
5287 if (pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
) {
5295 if (oi
.is_cache_pinned()) {
5296 dout(10) << "cache-try-flush on a pinned object, consider unpin this object first" << dendl
;
5300 if (oi
.is_dirty()) {
5301 result
= start_flush(ctx
->op
, ctx
->obc
, false, NULL
, boost::none
);
5302 if (result
== -EINPROGRESS
)
5310 case CEPH_OSD_OP_CACHE_FLUSH
:
5313 tracepoint(osd
, do_osd_op_pre_cache_flush
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5314 if (ctx
->lock_type
== ObjectContext::RWState::RWNONE
) {
5315 dout(10) << "cache-flush with SKIPRWLOCKS flag set" << dendl
;
5319 if (pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
) {
5327 if (oi
.is_cache_pinned()) {
5328 dout(10) << "cache-flush on a pinned object, consider unpin this object first" << dendl
;
5333 if (oi
.is_dirty()) {
5334 result
= start_flush(ctx
->op
, ctx
->obc
, true, &missing
, boost::none
);
5335 if (result
== -EINPROGRESS
)
5340 // Check special return value which has set missing_return
5341 if (result
== -ENOENT
) {
5342 dout(10) << __func__
<< " CEPH_OSD_OP_CACHE_FLUSH got ENOENT" << dendl
;
5343 assert(!missing
.is_min());
5344 wait_for_unreadable_object(missing
, ctx
->op
);
5345 // Error code which is used elsewhere when wait_for_unreadable_object() is used
5351 case CEPH_OSD_OP_CACHE_EVICT
:
5354 tracepoint(osd
, do_osd_op_pre_cache_evict
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5355 if (pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
) {
5363 if (oi
.is_cache_pinned()) {
5364 dout(10) << "cache-evict on a pinned object, consider unpin this object first" << dendl
;
5368 if (oi
.is_dirty()) {
5372 if (!oi
.watchers
.empty()) {
5376 if (soid
.snap
== CEPH_NOSNAP
) {
5377 result
= _verify_no_head_clones(soid
, ssc
->snapset
);
5381 result
= _delete_oid(ctx
, true, false);
5383 // mark that this is a cache eviction to avoid triggering normal
5384 // make_writeable() clone or snapdir object creation in finish_ctx()
5385 ctx
->cache_evict
= true;
5387 osd
->logger
->inc(l_osd_tier_evict
);
5391 case CEPH_OSD_OP_GETXATTR
:
5395 bp
.copy(op
.xattr
.name_len
, aname
);
5396 tracepoint(osd
, do_osd_op_pre_getxattr
, soid
.oid
.name
.c_str(), soid
.snap
.val
, aname
.c_str());
5397 string name
= "_" + aname
;
5398 int r
= getattr_maybe_cache(
5403 op
.xattr
.value_len
= osd_op
.outdata
.length();
5405 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(osd_op
.outdata
.length(), 10);
5409 ctx
->delta_stats
.num_rd
++;
5413 case CEPH_OSD_OP_GETXATTRS
:
5416 tracepoint(osd
, do_osd_op_pre_getxattrs
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5417 map
<string
, bufferlist
> out
;
5418 result
= getattrs_maybe_cache(
5425 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(bl
.length(), 10);
5426 ctx
->delta_stats
.num_rd
++;
5427 osd_op
.outdata
.claim_append(bl
);
5431 case CEPH_OSD_OP_CMPXATTR
:
5435 bp
.copy(op
.xattr
.name_len
, aname
);
5436 tracepoint(osd
, do_osd_op_pre_cmpxattr
, soid
.oid
.name
.c_str(), soid
.snap
.val
, aname
.c_str());
5437 string name
= "_" + aname
;
5438 name
[op
.xattr
.name_len
+ 1] = 0;
5441 result
= getattr_maybe_cache(
5445 if (result
< 0 && result
!= -EEXIST
&& result
!= -ENODATA
)
5448 ctx
->delta_stats
.num_rd
++;
5449 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(xattr
.length(), 10);
5451 switch (op
.xattr
.cmp_mode
) {
5452 case CEPH_OSD_CMPXATTR_MODE_STRING
:
5455 bp
.copy(op
.xattr
.value_len
, val
);
5456 val
[op
.xattr
.value_len
] = 0;
5457 dout(10) << "CEPH_OSD_OP_CMPXATTR name=" << name
<< " val=" << val
5458 << " op=" << (int)op
.xattr
.cmp_op
<< " mode=" << (int)op
.xattr
.cmp_mode
<< dendl
;
5459 result
= do_xattr_cmp_str(op
.xattr
.cmp_op
, val
, xattr
);
5463 case CEPH_OSD_CMPXATTR_MODE_U64
:
5467 ::decode(u64val
, bp
);
5469 catch (buffer::error
& e
) {
5473 dout(10) << "CEPH_OSD_OP_CMPXATTR name=" << name
<< " val=" << u64val
5474 << " op=" << (int)op
.xattr
.cmp_op
<< " mode=" << (int)op
.xattr
.cmp_mode
<< dendl
;
5475 result
= do_xattr_cmp_u64(op
.xattr
.cmp_op
, u64val
, xattr
);
5480 dout(10) << "bad cmp mode " << (int)op
.xattr
.cmp_mode
<< dendl
;
5485 dout(10) << "comparison returned false" << dendl
;
5486 result
= -ECANCELED
;
5490 dout(10) << "comparison returned " << result
<< " " << cpp_strerror(-result
) << dendl
;
5494 dout(10) << "comparison returned true" << dendl
;
5498 case CEPH_OSD_OP_ASSERT_VER
:
5501 uint64_t ver
= op
.assert_ver
.ver
;
5502 tracepoint(osd
, do_osd_op_pre_assert_ver
, soid
.oid
.name
.c_str(), soid
.snap
.val
, ver
);
5505 else if (ver
< oi
.user_version
)
5507 else if (ver
> oi
.user_version
)
5508 result
= -EOVERFLOW
;
5512 case CEPH_OSD_OP_LIST_WATCHERS
:
5515 tracepoint(osd
, do_osd_op_pre_list_watchers
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5516 obj_list_watch_response_t resp
;
5518 map
<pair
<uint64_t, entity_name_t
>, watch_info_t
>::const_iterator oi_iter
;
5519 for (oi_iter
= oi
.watchers
.begin(); oi_iter
!= oi
.watchers
.end();
5521 dout(20) << "key cookie=" << oi_iter
->first
.first
5522 << " entity=" << oi_iter
->first
.second
<< " "
5523 << oi_iter
->second
<< dendl
;
5524 assert(oi_iter
->first
.first
== oi_iter
->second
.cookie
);
5525 assert(oi_iter
->first
.second
.is_client());
5527 watch_item_t
wi(oi_iter
->first
.second
, oi_iter
->second
.cookie
,
5528 oi_iter
->second
.timeout_seconds
, oi_iter
->second
.addr
);
5529 resp
.entries
.push_back(wi
);
5532 resp
.encode(osd_op
.outdata
, ctx
->get_features());
5535 ctx
->delta_stats
.num_rd
++;
5539 case CEPH_OSD_OP_LIST_SNAPS
:
5542 tracepoint(osd
, do_osd_op_pre_list_snaps
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5543 obj_list_snap_response_t resp
;
5546 ssc
= ctx
->obc
->ssc
= get_snapset_context(soid
, false);
5550 int clonecount
= ssc
->snapset
.clones
.size();
5551 if (ssc
->snapset
.head_exists
)
5553 resp
.clones
.reserve(clonecount
);
5554 for (auto clone_iter
= ssc
->snapset
.clones
.begin();
5555 clone_iter
!= ssc
->snapset
.clones
.end(); ++clone_iter
) {
5557 ci
.cloneid
= *clone_iter
;
5559 hobject_t clone_oid
= soid
;
5560 clone_oid
.snap
= *clone_iter
;
5562 if (!ssc
->snapset
.is_legacy()) {
5563 auto p
= ssc
->snapset
.clone_snaps
.find(*clone_iter
);
5564 if (p
== ssc
->snapset
.clone_snaps
.end()) {
5565 osd
->clog
->error() << "osd." << osd
->whoami
5566 << ": inconsistent clone_snaps found for oid "
5567 << soid
<< " clone " << *clone_iter
5568 << " snapset " << ssc
->snapset
;
5572 for (auto q
= p
->second
.rbegin(); q
!= p
->second
.rend(); ++q
) {
5573 ci
.snaps
.push_back(*q
);
5576 /* No need to take a lock here. We are only inspecting state cached on
5577 * in the ObjectContext, so we aren't performing an actual read unless
5578 * the clone obc is not already loaded (in which case, it cannot have
5579 * an in progress write). We also do not risk exposing uncommitted
5580 * state since we do have a read lock on the head object or snapdir,
5581 * which we would have to write lock in order to make user visible
5582 * modifications to the snapshot state (snap trim related mutations
5583 * are not user visible).
5585 if (is_missing_object(clone_oid
)) {
5586 dout(20) << "LIST_SNAPS " << clone_oid
<< " missing" << dendl
;
5587 wait_for_unreadable_object(clone_oid
, ctx
->op
);
5592 ObjectContextRef clone_obc
= get_object_context(clone_oid
, false);
5594 if (maybe_handle_cache(
5595 ctx
->op
, true, clone_obc
, -ENOENT
, clone_oid
, true)) {
5596 // promoting the clone
5599 osd
->clog
->error() << "osd." << osd
->whoami
5600 << ": missing clone " << clone_oid
5603 // should not happen
5608 for (vector
<snapid_t
>::reverse_iterator p
=
5609 clone_obc
->obs
.oi
.legacy_snaps
.rbegin();
5610 p
!= clone_obc
->obs
.oi
.legacy_snaps
.rend();
5612 ci
.snaps
.push_back(*p
);
5616 dout(20) << " clone " << *clone_iter
<< " snaps " << ci
.snaps
<< dendl
;
5618 map
<snapid_t
, interval_set
<uint64_t> >::const_iterator coi
;
5619 coi
= ssc
->snapset
.clone_overlap
.find(ci
.cloneid
);
5620 if (coi
== ssc
->snapset
.clone_overlap
.end()) {
5621 osd
->clog
->error() << "osd." << osd
->whoami
5622 << ": inconsistent clone_overlap found for oid "
5623 << soid
<< " clone " << *clone_iter
;
5627 const interval_set
<uint64_t> &o
= coi
->second
;
5628 ci
.overlap
.reserve(o
.num_intervals());
5629 for (interval_set
<uint64_t>::const_iterator r
= o
.begin();
5630 r
!= o
.end(); ++r
) {
5631 ci
.overlap
.push_back(pair
<uint64_t,uint64_t>(r
.get_start(),
5635 map
<snapid_t
, uint64_t>::const_iterator si
;
5636 si
= ssc
->snapset
.clone_size
.find(ci
.cloneid
);
5637 if (si
== ssc
->snapset
.clone_size
.end()) {
5638 osd
->clog
->error() << "osd." << osd
->whoami
5639 << ": inconsistent clone_size found for oid "
5640 << soid
<< " clone " << *clone_iter
;
5644 ci
.size
= si
->second
;
5646 resp
.clones
.push_back(ci
);
5651 if (ssc
->snapset
.head_exists
&&
5652 !ctx
->obc
->obs
.oi
.is_whiteout()) {
5655 ci
.cloneid
= CEPH_NOSNAP
;
5657 //Size for HEAD is oi.size
5660 resp
.clones
.push_back(ci
);
5662 resp
.seq
= ssc
->snapset
.seq
;
5664 resp
.encode(osd_op
.outdata
);
5667 ctx
->delta_stats
.num_rd
++;
5671 case CEPH_OSD_OP_NOTIFY
:
5678 uint32_t ver
; // obsolete
5680 ::decode(timeout
, bp
);
5682 } catch (const buffer::error
&e
) {
5685 tracepoint(osd
, do_osd_op_pre_notify
, soid
.oid
.name
.c_str(), soid
.snap
.val
, timeout
);
5687 timeout
= cct
->_conf
->osd_default_notify_timeout
;
5690 n
.timeout
= timeout
;
5691 n
.notify_id
= osd
->get_next_id(get_osdmap()->get_epoch());
5692 n
.cookie
= op
.watch
.cookie
;
5694 ctx
->notifies
.push_back(n
);
5696 // return our unique notify id to the client
5697 ::encode(n
.notify_id
, osd_op
.outdata
);
5701 case CEPH_OSD_OP_NOTIFY_ACK
:
5705 uint64_t notify_id
= 0;
5706 uint64_t watch_cookie
= 0;
5707 ::decode(notify_id
, bp
);
5708 ::decode(watch_cookie
, bp
);
5709 bufferlist reply_bl
;
5711 ::decode(reply_bl
, bp
);
5713 tracepoint(osd
, do_osd_op_pre_notify_ack
, soid
.oid
.name
.c_str(), soid
.snap
.val
, notify_id
, watch_cookie
, "Y");
5714 OpContext::NotifyAck
ack(notify_id
, watch_cookie
, reply_bl
);
5715 ctx
->notify_acks
.push_back(ack
);
5716 } catch (const buffer::error
&e
) {
5717 tracepoint(osd
, do_osd_op_pre_notify_ack
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.watch
.cookie
, 0, "N");
5718 OpContext::NotifyAck
ack(
5719 // op.watch.cookie is actually the notify_id for historical reasons
5722 ctx
->notify_acks
.push_back(ack
);
5727 case CEPH_OSD_OP_SETALLOCHINT
:
5730 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
);
5731 maybe_create_new_object(ctx
);
5732 oi
.expected_object_size
= op
.alloc_hint
.expected_object_size
;
5733 oi
.expected_write_size
= op
.alloc_hint
.expected_write_size
;
5734 oi
.alloc_hint_flags
= op
.alloc_hint
.flags
;
5735 t
->set_alloc_hint(soid
, op
.alloc_hint
.expected_object_size
,
5736 op
.alloc_hint
.expected_write_size
,
5737 op
.alloc_hint
.flags
);
5738 ctx
->delta_stats
.num_wr
++;
5746 // -- object data --
5748 case CEPH_OSD_OP_WRITE
:
5751 __u32 seq
= oi
.truncate_seq
;
5752 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
);
5753 if (op
.extent
.length
!= osd_op
.indata
.length()) {
5758 if (pool
.info
.has_flag(pg_pool_t::FLAG_WRITE_FADVISE_DONTNEED
))
5759 op
.flags
= op
.flags
| CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
;
5761 if (pool
.info
.requires_aligned_append() &&
5762 (op
.extent
.offset
% pool
.info
.required_alignment() != 0)) {
5763 result
= -EOPNOTSUPP
;
5768 if (pool
.info
.requires_aligned_append() && op
.extent
.offset
) {
5769 result
= -EOPNOTSUPP
;
5772 } else if (op
.extent
.offset
!= oi
.size
&&
5773 pool
.info
.requires_aligned_append()) {
5774 result
= -EOPNOTSUPP
;
5778 if (seq
&& (seq
> op
.extent
.truncate_seq
) &&
5779 (op
.extent
.offset
+ op
.extent
.length
> oi
.size
)) {
5780 // old write, arrived after trimtrunc
5781 op
.extent
.length
= (op
.extent
.offset
> oi
.size
? 0 : oi
.size
- op
.extent
.offset
);
5782 dout(10) << " old truncate_seq " << op
.extent
.truncate_seq
<< " < current " << seq
5783 << ", adjusting write length to " << op
.extent
.length
<< dendl
;
5785 t
.substr_of(osd_op
.indata
, 0, op
.extent
.length
);
5786 osd_op
.indata
.swap(t
);
5788 if (op
.extent
.truncate_seq
> seq
) {
5789 // write arrives before trimtrunc
5790 if (obs
.exists
&& !oi
.is_whiteout()) {
5791 dout(10) << " truncate_seq " << op
.extent
.truncate_seq
<< " > current " << seq
5792 << ", truncating to " << op
.extent
.truncate_size
<< dendl
;
5793 t
->truncate(soid
, op
.extent
.truncate_size
);
5794 oi
.truncate_seq
= op
.extent
.truncate_seq
;
5795 oi
.truncate_size
= op
.extent
.truncate_size
;
5796 if (op
.extent
.truncate_size
!= oi
.size
) {
5797 ctx
->delta_stats
.num_bytes
-= oi
.size
;
5798 ctx
->delta_stats
.num_bytes
+= op
.extent
.truncate_size
;
5799 oi
.size
= op
.extent
.truncate_size
;
5802 dout(10) << " truncate_seq " << op
.extent
.truncate_seq
<< " > current " << seq
5803 << ", but object is new" << dendl
;
5804 oi
.truncate_seq
= op
.extent
.truncate_seq
;
5805 oi
.truncate_size
= op
.extent
.truncate_size
;
5808 result
= check_offset_and_length(op
.extent
.offset
, op
.extent
.length
, cct
->_conf
->osd_max_object_size
);
5812 maybe_create_new_object(ctx
);
5814 if (op
.extent
.length
== 0) {
5815 if (op
.extent
.offset
> oi
.size
) {
5817 soid
, op
.extent
.offset
);
5823 soid
, op
.extent
.offset
, op
.extent
.length
, osd_op
.indata
, op
.flags
);
5826 if (op
.extent
.offset
== 0 && op
.extent
.length
>= oi
.size
)
5827 obs
.oi
.set_data_digest(osd_op
.indata
.crc32c(-1));
5828 else if (op
.extent
.offset
== oi
.size
&& obs
.oi
.is_data_digest())
5829 obs
.oi
.set_data_digest(osd_op
.indata
.crc32c(obs
.oi
.data_digest
));
5831 obs
.oi
.clear_data_digest();
5832 write_update_size_and_usage(ctx
->delta_stats
, oi
, ctx
->modified_ranges
,
5833 op
.extent
.offset
, op
.extent
.length
);
5838 case CEPH_OSD_OP_WRITEFULL
:
5840 { // write full object
5841 tracepoint(osd
, do_osd_op_pre_writefull
, soid
.oid
.name
.c_str(), soid
.snap
.val
, oi
.size
, 0, op
.extent
.length
);
5843 if (op
.extent
.length
!= osd_op
.indata
.length()) {
5847 result
= check_offset_and_length(0, op
.extent
.length
, cct
->_conf
->osd_max_object_size
);
5851 if (pool
.info
.has_flag(pg_pool_t::FLAG_WRITE_FADVISE_DONTNEED
))
5852 op
.flags
= op
.flags
| CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
;
5854 maybe_create_new_object(ctx
);
5855 if (pool
.info
.require_rollback()) {
5856 t
->truncate(soid
, 0);
5857 } else if (obs
.exists
&& op
.extent
.length
< oi
.size
) {
5858 t
->truncate(soid
, op
.extent
.length
);
5860 if (op
.extent
.length
) {
5861 t
->write(soid
, 0, op
.extent
.length
, osd_op
.indata
, op
.flags
);
5863 obs
.oi
.set_data_digest(osd_op
.indata
.crc32c(-1));
5865 write_update_size_and_usage(ctx
->delta_stats
, oi
, ctx
->modified_ranges
,
5866 0, op
.extent
.length
, true);
5870 case CEPH_OSD_OP_WRITESAME
:
5872 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
);
5873 result
= do_writesame(ctx
, osd_op
);
5876 case CEPH_OSD_OP_ROLLBACK
:
5878 tracepoint(osd
, do_osd_op_pre_rollback
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5879 result
= _rollback_to(ctx
, op
);
5882 case CEPH_OSD_OP_ZERO
:
5883 tracepoint(osd
, do_osd_op_pre_zero
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.extent
.offset
, op
.extent
.length
);
5884 if (pool
.info
.requires_aligned_append()) {
5885 result
= -EOPNOTSUPP
;
5890 result
= check_offset_and_length(op
.extent
.offset
, op
.extent
.length
, cct
->_conf
->osd_max_object_size
);
5893 assert(op
.extent
.length
);
5894 if (obs
.exists
&& !oi
.is_whiteout()) {
5895 t
->zero(soid
, op
.extent
.offset
, op
.extent
.length
);
5896 interval_set
<uint64_t> ch
;
5897 ch
.insert(op
.extent
.offset
, op
.extent
.length
);
5898 ctx
->modified_ranges
.union_of(ch
);
5899 ctx
->delta_stats
.num_wr
++;
5900 oi
.clear_data_digest();
5906 case CEPH_OSD_OP_CREATE
:
5909 tracepoint(osd
, do_osd_op_pre_create
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5910 int flags
= le32_to_cpu(op
.flags
);
5911 if (obs
.exists
&& !oi
.is_whiteout() &&
5912 (flags
& CEPH_OSD_OP_FLAG_EXCL
)) {
5913 result
= -EEXIST
; /* this is an exclusive create */
5915 if (osd_op
.indata
.length()) {
5916 bufferlist::iterator p
= osd_op
.indata
.begin();
5919 ::decode(category
, p
);
5921 catch (buffer::error
& e
) {
5925 // category is no longer implemented.
5928 maybe_create_new_object(ctx
);
5935 case CEPH_OSD_OP_TRIMTRUNC
:
5936 op
.extent
.offset
= op
.extent
.truncate_size
;
5939 case CEPH_OSD_OP_TRUNCATE
:
5940 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
);
5941 if (pool
.info
.requires_aligned_append()) {
5942 result
= -EOPNOTSUPP
;
5948 if (!obs
.exists
|| oi
.is_whiteout()) {
5949 dout(10) << " object dne, truncate is a no-op" << dendl
;
5953 if (op
.extent
.offset
> cct
->_conf
->osd_max_object_size
) {
5958 if (op
.extent
.truncate_seq
) {
5959 assert(op
.extent
.offset
== op
.extent
.truncate_size
);
5960 if (op
.extent
.truncate_seq
<= oi
.truncate_seq
) {
5961 dout(10) << " truncate seq " << op
.extent
.truncate_seq
<< " <= current " << oi
.truncate_seq
5962 << ", no-op" << dendl
;
5965 dout(10) << " truncate seq " << op
.extent
.truncate_seq
<< " > current " << oi
.truncate_seq
5966 << ", truncating" << dendl
;
5967 oi
.truncate_seq
= op
.extent
.truncate_seq
;
5968 oi
.truncate_size
= op
.extent
.truncate_size
;
5971 maybe_create_new_object(ctx
);
5972 t
->truncate(soid
, op
.extent
.offset
);
5973 if (oi
.size
> op
.extent
.offset
) {
5974 interval_set
<uint64_t> trim
;
5975 trim
.insert(op
.extent
.offset
, oi
.size
-op
.extent
.offset
);
5976 ctx
->modified_ranges
.union_of(trim
);
5978 if (op
.extent
.offset
!= oi
.size
) {
5979 ctx
->delta_stats
.num_bytes
-= oi
.size
;
5980 ctx
->delta_stats
.num_bytes
+= op
.extent
.offset
;
5981 oi
.size
= op
.extent
.offset
;
5983 ctx
->delta_stats
.num_wr
++;
5984 // do no set exists, or we will break above DELETE -> TRUNCATE munging.
5986 oi
.clear_data_digest();
5990 case CEPH_OSD_OP_DELETE
:
5992 tracepoint(osd
, do_osd_op_pre_delete
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
5994 result
= _delete_oid(ctx
, false, ctx
->ignore_cache
);
5998 case CEPH_OSD_OP_WATCH
:
6001 tracepoint(osd
, do_osd_op_pre_watch
, soid
.oid
.name
.c_str(), soid
.snap
.val
,
6002 op
.watch
.cookie
, op
.watch
.op
);
6007 uint64_t cookie
= op
.watch
.cookie
;
6008 entity_name_t entity
= ctx
->reqid
.name
;
6009 ObjectContextRef obc
= ctx
->obc
;
6011 dout(10) << "watch " << ceph_osd_watch_op_name(op
.watch
.op
)
6012 << ": ctx->obc=" << (void *)obc
.get() << " cookie=" << cookie
6013 << " oi.version=" << oi
.version
.version
<< " ctx->at_version=" << ctx
->at_version
<< dendl
;
6014 dout(10) << "watch: oi.user_version=" << oi
.user_version
<< dendl
;
6015 dout(10) << "watch: peer_addr="
6016 << ctx
->op
->get_req()->get_connection()->get_peer_addr() << dendl
;
6018 uint32_t timeout
= cct
->_conf
->osd_client_watch_timeout
;
6019 if (op
.watch
.timeout
!= 0) {
6020 timeout
= op
.watch
.timeout
;
6023 watch_info_t
w(cookie
, timeout
,
6024 ctx
->op
->get_req()->get_connection()->get_peer_addr());
6025 if (op
.watch
.op
== CEPH_OSD_WATCH_OP_WATCH
||
6026 op
.watch
.op
== CEPH_OSD_WATCH_OP_LEGACY_WATCH
) {
6027 if (oi
.watchers
.count(make_pair(cookie
, entity
))) {
6028 dout(10) << " found existing watch " << w
<< " by " << entity
<< dendl
;
6030 dout(10) << " registered new watch " << w
<< " by " << entity
<< dendl
;
6031 oi
.watchers
[make_pair(cookie
, entity
)] = w
;
6032 t
->nop(soid
); // make sure update the object_info on disk!
6034 bool will_ping
= (op
.watch
.op
== CEPH_OSD_WATCH_OP_WATCH
);
6035 ctx
->watch_connects
.push_back(make_pair(w
, will_ping
));
6036 } else if (op
.watch
.op
== CEPH_OSD_WATCH_OP_RECONNECT
) {
6037 if (!oi
.watchers
.count(make_pair(cookie
, entity
))) {
6041 dout(10) << " found existing watch " << w
<< " by " << entity
<< dendl
;
6042 ctx
->watch_connects
.push_back(make_pair(w
, true));
6043 } else if (op
.watch
.op
== CEPH_OSD_WATCH_OP_PING
) {
6044 /* Note: WATCH with PING doesn't cause may_write() to return true,
6045 * so if there is nothing else in the transaction, this is going
6046 * to run do_osd_op_effects, but not write out a log entry */
6047 if (!oi
.watchers
.count(make_pair(cookie
, entity
))) {
6051 map
<pair
<uint64_t,entity_name_t
>,WatchRef
>::iterator p
=
6052 obc
->watchers
.find(make_pair(cookie
, entity
));
6053 if (p
== obc
->watchers
.end() ||
6054 !p
->second
->is_connected()) {
6055 // client needs to reconnect
6056 result
= -ETIMEDOUT
;
6059 dout(10) << " found existing watch " << w
<< " by " << entity
<< dendl
;
6060 p
->second
->got_ping(ceph_clock_now());
6062 } else if (op
.watch
.op
== CEPH_OSD_WATCH_OP_UNWATCH
) {
6063 map
<pair
<uint64_t, entity_name_t
>, watch_info_t
>::iterator oi_iter
=
6064 oi
.watchers
.find(make_pair(cookie
, entity
));
6065 if (oi_iter
!= oi
.watchers
.end()) {
6066 dout(10) << " removed watch " << oi_iter
->second
<< " by "
6068 oi
.watchers
.erase(oi_iter
);
6069 t
->nop(soid
); // update oi on disk
6070 ctx
->watch_disconnects
.push_back(
6071 watch_disconnect_t(cookie
, entity
, false));
6073 dout(10) << " can't remove: no watch by " << entity
<< dendl
;
6079 case CEPH_OSD_OP_CACHE_PIN
:
6080 tracepoint(osd
, do_osd_op_pre_cache_pin
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6081 if ((!pool
.info
.is_tier() ||
6082 pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
)) {
6084 dout(10) << " pin object is only allowed on the cache tier " << dendl
;
6089 if (!obs
.exists
|| oi
.is_whiteout()) {
6094 if (!oi
.is_cache_pinned()) {
6095 oi
.set_flag(object_info_t::FLAG_CACHE_PIN
);
6097 ctx
->delta_stats
.num_objects_pinned
++;
6098 ctx
->delta_stats
.num_wr
++;
6104 case CEPH_OSD_OP_CACHE_UNPIN
:
6105 tracepoint(osd
, do_osd_op_pre_cache_unpin
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6106 if ((!pool
.info
.is_tier() ||
6107 pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
)) {
6109 dout(10) << " pin object is only allowed on the cache tier " << dendl
;
6114 if (!obs
.exists
|| oi
.is_whiteout()) {
6119 if (oi
.is_cache_pinned()) {
6120 oi
.clear_flag(object_info_t::FLAG_CACHE_PIN
);
6122 ctx
->delta_stats
.num_objects_pinned
--;
6123 ctx
->delta_stats
.num_wr
++;
6129 case CEPH_OSD_OP_SET_REDIRECT
:
6132 if (pool
.info
.is_tier()) {
6140 if (get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
6141 result
= -EOPNOTSUPP
;
6145 object_t target_name
;
6146 object_locator_t target_oloc
;
6147 snapid_t target_snapid
= (uint64_t)op
.copy_from
.snapid
;
6148 version_t target_version
= op
.copy_from
.src_version
;
6150 ::decode(target_name
, bp
);
6151 ::decode(target_oloc
, bp
);
6153 catch (buffer::error
& e
) {
6158 get_osdmap()->object_locator_to_pg(target_name
, target_oloc
, raw_pg
);
6159 hobject_t
target(target_name
, target_oloc
.key
, target_snapid
,
6160 raw_pg
.ps(), raw_pg
.pool(),
6161 target_oloc
.nspace
);
6162 if (target
== soid
) {
6163 dout(20) << " set-redirect self is invalid" << dendl
;
6167 oi
.set_flag(object_info_t::FLAG_MANIFEST
);
6168 oi
.manifest
.redirect_target
= target
;
6169 oi
.manifest
.type
= object_manifest_t::TYPE_REDIRECT
;
6170 t
->truncate(soid
, 0);
6171 if (oi
.is_omap() && pool
.info
.supports_omap()) {
6172 t
->omap_clear(soid
);
6173 obs
.oi
.clear_omap_digest();
6174 obs
.oi
.clear_flag(object_info_t::FLAG_OMAP
);
6176 ctx
->delta_stats
.num_bytes
-= oi
.size
;
6179 oi
.user_version
= target_version
;
6180 ctx
->user_at_version
= target_version
;
6182 map
<string
,bufferlist
> rmattrs
;
6183 result
= getattrs_maybe_cache(ctx
->obc
,
6189 map
<string
, bufferlist
>::iterator iter
;
6190 for (iter
= rmattrs
.begin(); iter
!= rmattrs
.end(); ++iter
) {
6191 const string
& name
= iter
->first
;
6192 t
->rmattr(soid
, name
);
6194 dout(10) << "set-redirect oid:" << oi
.soid
<< " user_version: " << oi
.user_version
<< dendl
;
6199 // -- object attrs --
6201 case CEPH_OSD_OP_SETXATTR
:
6204 if (cct
->_conf
->osd_max_attr_size
> 0 &&
6205 op
.xattr
.value_len
> cct
->_conf
->osd_max_attr_size
) {
6206 tracepoint(osd
, do_osd_op_pre_setxattr
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???");
6210 unsigned max_name_len
= MIN(osd
->store
->get_max_attr_name_length(),
6211 cct
->_conf
->osd_max_attr_name_len
);
6212 if (op
.xattr
.name_len
> max_name_len
) {
6213 result
= -ENAMETOOLONG
;
6216 maybe_create_new_object(ctx
);
6218 bp
.copy(op
.xattr
.name_len
, aname
);
6219 tracepoint(osd
, do_osd_op_pre_setxattr
, soid
.oid
.name
.c_str(), soid
.snap
.val
, aname
.c_str());
6220 string name
= "_" + aname
;
6222 bp
.copy(op
.xattr
.value_len
, bl
);
6223 t
->setattr(soid
, name
, bl
);
6224 ctx
->delta_stats
.num_wr
++;
6228 case CEPH_OSD_OP_RMXATTR
:
6232 bp
.copy(op
.xattr
.name_len
, aname
);
6233 tracepoint(osd
, do_osd_op_pre_rmxattr
, soid
.oid
.name
.c_str(), soid
.snap
.val
, aname
.c_str());
6234 if (!obs
.exists
|| oi
.is_whiteout()) {
6238 string name
= "_" + aname
;
6239 t
->rmattr(soid
, name
);
6240 ctx
->delta_stats
.num_wr
++;
6245 // -- fancy writers --
6246 case CEPH_OSD_OP_APPEND
:
6248 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
);
6249 // just do it inline; this works because we are happy to execute
6250 // fancy op on replicas as well.
6251 vector
<OSDOp
> nops(1);
6252 OSDOp
& newop
= nops
[0];
6253 newop
.op
.op
= CEPH_OSD_OP_WRITE
;
6254 newop
.op
.extent
.offset
= oi
.size
;
6255 newop
.op
.extent
.length
= op
.extent
.length
;
6256 newop
.op
.extent
.truncate_seq
= oi
.truncate_seq
;
6257 newop
.indata
= osd_op
.indata
;
6258 result
= do_osd_ops(ctx
, nops
);
6259 osd_op
.outdata
.claim(newop
.outdata
);
6263 case CEPH_OSD_OP_STARTSYNC
:
6264 tracepoint(osd
, do_osd_op_pre_startsync
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6269 // -- trivial map --
6270 case CEPH_OSD_OP_TMAPGET
:
6271 tracepoint(osd
, do_osd_op_pre_tmapget
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6272 if (pool
.info
.require_rollback()) {
6273 result
= -EOPNOTSUPP
;
6277 vector
<OSDOp
> nops(1);
6278 OSDOp
& newop
= nops
[0];
6279 newop
.op
.op
= CEPH_OSD_OP_SYNC_READ
;
6280 newop
.op
.extent
.offset
= 0;
6281 newop
.op
.extent
.length
= 0;
6282 do_osd_ops(ctx
, nops
);
6283 osd_op
.outdata
.claim(newop
.outdata
);
6287 case CEPH_OSD_OP_TMAPPUT
:
6288 tracepoint(osd
, do_osd_op_pre_tmapput
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6289 if (pool
.info
.require_rollback()) {
6290 result
= -EOPNOTSUPP
;
6294 //_dout_lock.Lock();
6295 //osd_op.data.hexdump(*_dout);
6296 //_dout_lock.Unlock();
6298 // verify sort order
6299 bool unsorted
= false;
6302 ::decode(header
, bp
);
6309 dout(10) << "tmapput key " << key
<< dendl
;
6312 if (key
< last_key
) {
6313 dout(10) << "TMAPPUT is unordered; resorting" << dendl
;
6322 vector
<OSDOp
> nops(1);
6323 OSDOp
& newop
= nops
[0];
6324 newop
.op
.op
= CEPH_OSD_OP_WRITEFULL
;
6325 newop
.op
.extent
.offset
= 0;
6326 newop
.op
.extent
.length
= osd_op
.indata
.length();
6327 newop
.indata
= osd_op
.indata
;
6330 bp
= osd_op
.indata
.begin();
6332 map
<string
, bufferlist
> m
;
6333 ::decode(header
, bp
);
6337 ::encode(header
, newbl
);
6339 newop
.indata
= newbl
;
6341 result
= do_osd_ops(ctx
, nops
);
6342 assert(result
== 0);
6346 case CEPH_OSD_OP_TMAPUP
:
6347 tracepoint(osd
, do_osd_op_pre_tmapup
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6348 if (pool
.info
.require_rollback()) {
6349 result
= -EOPNOTSUPP
;
6353 result
= do_tmapup(ctx
, bp
, osd_op
);
6356 case CEPH_OSD_OP_TMAP2OMAP
:
6358 tracepoint(osd
, do_osd_op_pre_tmap2omap
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6359 result
= do_tmap2omap(ctx
, op
.tmap2omap
.flags
);
6363 case CEPH_OSD_OP_OMAPGETKEYS
:
6367 uint64_t max_return
;
6369 ::decode(start_after
, bp
);
6370 ::decode(max_return
, bp
);
6372 catch (buffer::error
& e
) {
6374 tracepoint(osd
, do_osd_op_pre_omapgetkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???", 0);
6377 if (max_return
> cct
->_conf
->osd_max_omap_entries_per_request
) {
6378 max_return
= cct
->_conf
->osd_max_omap_entries_per_request
;
6380 tracepoint(osd
, do_osd_op_pre_omapgetkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
, start_after
.c_str(), max_return
);
6384 bool truncated
= false;
6386 ObjectMap::ObjectMapIterator iter
= osd
->store
->get_omap_iterator(
6387 coll
, ghobject_t(soid
)
6390 iter
->upper_bound(start_after
);
6391 for (num
= 0; iter
->valid(); ++num
, iter
->next(false)) {
6392 if (num
>= max_return
||
6393 bl
.length() >= cct
->_conf
->osd_max_omap_bytes_per_request
) {
6397 ::encode(iter
->key(), bl
);
6399 } // else return empty out_set
6400 ::encode(num
, osd_op
.outdata
);
6401 osd_op
.outdata
.claim_append(bl
);
6402 ::encode(truncated
, osd_op
.outdata
);
6403 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(osd_op
.outdata
.length(), 10);
6404 ctx
->delta_stats
.num_rd
++;
6408 case CEPH_OSD_OP_OMAPGETVALS
:
6412 uint64_t max_return
;
6413 string filter_prefix
;
6415 ::decode(start_after
, bp
);
6416 ::decode(max_return
, bp
);
6417 ::decode(filter_prefix
, bp
);
6419 catch (buffer::error
& e
) {
6421 tracepoint(osd
, do_osd_op_pre_omapgetvals
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???", 0, "???");
6424 if (max_return
> cct
->_conf
->osd_max_omap_entries_per_request
) {
6425 max_return
= cct
->_conf
->osd_max_omap_entries_per_request
;
6427 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());
6430 bool truncated
= false;
6433 ObjectMap::ObjectMapIterator iter
= osd
->store
->get_omap_iterator(
6434 coll
, ghobject_t(soid
)
6440 iter
->upper_bound(start_after
);
6441 if (filter_prefix
> start_after
) iter
->lower_bound(filter_prefix
);
6444 iter
->key().substr(0, filter_prefix
.size()) == filter_prefix
;
6445 ++num
, iter
->next(false)) {
6446 dout(20) << "Found key " << iter
->key() << dendl
;
6447 if (num
>= max_return
||
6448 bl
.length() >= cct
->_conf
->osd_max_omap_bytes_per_request
) {
6452 ::encode(iter
->key(), bl
);
6453 ::encode(iter
->value(), bl
);
6455 } // else return empty out_set
6456 ::encode(num
, osd_op
.outdata
);
6457 osd_op
.outdata
.claim_append(bl
);
6458 ::encode(truncated
, osd_op
.outdata
);
6459 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(osd_op
.outdata
.length(), 10);
6460 ctx
->delta_stats
.num_rd
++;
6464 case CEPH_OSD_OP_OMAPGETHEADER
:
6465 tracepoint(osd
, do_osd_op_pre_omapgetheader
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6466 if (!oi
.is_omap()) {
6467 // return empty header
6472 osd
->store
->omap_get_header(ch
, ghobject_t(soid
), &osd_op
.outdata
);
6473 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(osd_op
.outdata
.length(), 10);
6474 ctx
->delta_stats
.num_rd
++;
6478 case CEPH_OSD_OP_OMAPGETVALSBYKEYS
:
6481 set
<string
> keys_to_get
;
6483 ::decode(keys_to_get
, bp
);
6485 catch (buffer::error
& e
) {
6487 tracepoint(osd
, do_osd_op_pre_omapgetvalsbykeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???");
6490 tracepoint(osd
, do_osd_op_pre_omapgetvalsbykeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
, list_entries(keys_to_get
).c_str());
6491 map
<string
, bufferlist
> out
;
6493 osd
->store
->omap_get_values(ch
, ghobject_t(soid
), keys_to_get
, &out
);
6494 } // else return empty omap entries
6495 ::encode(out
, osd_op
.outdata
);
6496 ctx
->delta_stats
.num_rd_kb
+= SHIFT_ROUND_UP(osd_op
.outdata
.length(), 10);
6497 ctx
->delta_stats
.num_rd
++;
6501 case CEPH_OSD_OP_OMAP_CMP
:
6504 if (!obs
.exists
|| oi
.is_whiteout()) {
6506 tracepoint(osd
, do_osd_op_pre_omap_cmp
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???");
6509 map
<string
, pair
<bufferlist
, int> > assertions
;
6511 ::decode(assertions
, bp
);
6513 catch (buffer::error
& e
) {
6515 tracepoint(osd
, do_osd_op_pre_omap_cmp
, soid
.oid
.name
.c_str(), soid
.snap
.val
, "???");
6518 tracepoint(osd
, do_osd_op_pre_omap_cmp
, soid
.oid
.name
.c_str(), soid
.snap
.val
, list_keys(assertions
).c_str());
6520 map
<string
, bufferlist
> out
;
6524 for (map
<string
, pair
<bufferlist
, int> >::iterator i
= assertions
.begin();
6525 i
!= assertions
.end();
6527 to_get
.insert(i
->first
);
6528 int r
= osd
->store
->omap_get_values(ch
, ghobject_t(soid
),
6534 } // else leave out empty
6536 //Should set num_rd_kb based on encode length of map
6537 ctx
->delta_stats
.num_rd
++;
6541 for (map
<string
, pair
<bufferlist
, int> >::iterator i
= assertions
.begin();
6542 i
!= assertions
.end();
6544 auto out_entry
= out
.find(i
->first
);
6545 bufferlist
&bl
= (out_entry
!= out
.end()) ?
6546 out_entry
->second
: empty
;
6547 switch (i
->second
.second
) {
6548 case CEPH_OSD_CMPXATTR_OP_EQ
:
6549 if (!(bl
== i
->second
.first
)) {
6553 case CEPH_OSD_CMPXATTR_OP_LT
:
6554 if (!(bl
< i
->second
.first
)) {
6558 case CEPH_OSD_CMPXATTR_OP_GT
:
6559 if (!(bl
> i
->second
.first
)) {
6577 case CEPH_OSD_OP_OMAPSETVALS
:
6578 if (!pool
.info
.supports_omap()) {
6579 result
= -EOPNOTSUPP
;
6580 tracepoint(osd
, do_osd_op_pre_omapsetvals
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6585 maybe_create_new_object(ctx
);
6586 bufferlist to_set_bl
;
6588 decode_str_str_map_to_bl(bp
, &to_set_bl
);
6590 catch (buffer::error
& e
) {
6592 tracepoint(osd
, do_osd_op_pre_omapsetvals
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6595 tracepoint(osd
, do_osd_op_pre_omapsetvals
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6596 if (cct
->_conf
->subsys
.should_gather(dout_subsys
, 20)) {
6597 dout(20) << "setting vals: " << dendl
;
6598 map
<string
,bufferlist
> to_set
;
6599 bufferlist::iterator pt
= to_set_bl
.begin();
6600 ::decode(to_set
, pt
);
6601 for (map
<string
, bufferlist
>::iterator i
= to_set
.begin();
6604 dout(20) << "\t" << i
->first
<< dendl
;
6607 t
->omap_setkeys(soid
, to_set_bl
);
6608 ctx
->delta_stats
.num_wr
++;
6610 obs
.oi
.set_flag(object_info_t::FLAG_OMAP
);
6611 obs
.oi
.clear_omap_digest();
6614 case CEPH_OSD_OP_OMAPSETHEADER
:
6615 tracepoint(osd
, do_osd_op_pre_omapsetheader
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6616 if (!pool
.info
.supports_omap()) {
6617 result
= -EOPNOTSUPP
;
6622 maybe_create_new_object(ctx
);
6623 t
->omap_setheader(soid
, osd_op
.indata
);
6624 ctx
->delta_stats
.num_wr
++;
6626 obs
.oi
.set_flag(object_info_t::FLAG_OMAP
);
6627 obs
.oi
.clear_omap_digest();
6630 case CEPH_OSD_OP_OMAPCLEAR
:
6631 tracepoint(osd
, do_osd_op_pre_omapclear
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6632 if (!pool
.info
.supports_omap()) {
6633 result
= -EOPNOTSUPP
;
6638 if (!obs
.exists
|| oi
.is_whiteout()) {
6643 t
->omap_clear(soid
);
6644 ctx
->delta_stats
.num_wr
++;
6645 obs
.oi
.clear_omap_digest();
6646 obs
.oi
.clear_flag(object_info_t::FLAG_OMAP
);
6651 case CEPH_OSD_OP_OMAPRMKEYS
:
6652 if (!pool
.info
.supports_omap()) {
6653 result
= -EOPNOTSUPP
;
6654 tracepoint(osd
, do_osd_op_pre_omaprmkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6659 if (!obs
.exists
|| oi
.is_whiteout()) {
6661 tracepoint(osd
, do_osd_op_pre_omaprmkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6664 bufferlist to_rm_bl
;
6666 decode_str_set_to_bl(bp
, &to_rm_bl
);
6668 catch (buffer::error
& e
) {
6670 tracepoint(osd
, do_osd_op_pre_omaprmkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6673 tracepoint(osd
, do_osd_op_pre_omaprmkeys
, soid
.oid
.name
.c_str(), soid
.snap
.val
);
6674 t
->omap_rmkeys(soid
, to_rm_bl
);
6675 ctx
->delta_stats
.num_wr
++;
6677 obs
.oi
.clear_omap_digest();
6680 case CEPH_OSD_OP_COPY_GET
:
6682 tracepoint(osd
, do_osd_op_pre_copy_get
, soid
.oid
.name
.c_str(),
6684 if (op_finisher
== nullptr) {
6685 result
= do_copy_get(ctx
, bp
, osd_op
, ctx
->obc
);
6687 result
= op_finisher
->execute();
6691 case CEPH_OSD_OP_COPY_FROM
:
6695 object_locator_t src_oloc
;
6696 snapid_t src_snapid
= (uint64_t)op
.copy_from
.snapid
;
6697 version_t src_version
= op
.copy_from
.src_version
;
6699 ::decode(src_name
, bp
);
6700 ::decode(src_oloc
, bp
);
6702 catch (buffer::error
& e
) {
6705 do_osd_op_pre_copy_from
,
6706 soid
.oid
.name
.c_str(),
6718 do_osd_op_pre_copy_from
,
6719 soid
.oid
.name
.c_str(),
6721 src_name
.name
.c_str(),
6723 src_oloc
.key
.c_str(),
6724 src_oloc
.nspace
.c_str(),
6728 if (op_finisher
== nullptr) {
6731 get_osdmap()->object_locator_to_pg(src_name
, src_oloc
, raw_pg
);
6732 hobject_t
src(src_name
, src_oloc
.key
, src_snapid
,
6733 raw_pg
.ps(), raw_pg
.pool(),
6736 dout(20) << " copy from self is invalid" << dendl
;
6740 CopyFromCallback
*cb
= new CopyFromCallback(ctx
, osd_op
);
6741 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
6742 new CopyFromFinisher(cb
));
6743 start_copy(cb
, ctx
->obc
, src
, src_oloc
, src_version
,
6746 op
.copy_from
.src_fadvise_flags
,
6748 result
= -EINPROGRESS
;
6751 result
= op_finisher
->execute();
6752 assert(result
== 0);
6754 // COPY_FROM cannot be executed multiple times -- it must restart
6755 ctx
->op_finishers
.erase(ctx
->current_osd_subop_num
);
6761 tracepoint(osd
, do_osd_op_pre_unknown
, soid
.oid
.name
.c_str(), soid
.snap
.val
, op
.op
, ceph_osd_op_name(op
.op
));
6762 dout(1) << "unrecognized osd op " << op
.op
6763 << " " << ceph_osd_op_name(op
.op
)
6765 result
= -EOPNOTSUPP
;
6769 osd_op
.rval
= result
;
6770 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
);
6771 if (result
< 0 && (op
.flags
& CEPH_OSD_OP_FLAG_FAILOK
))
6780 int PrimaryLogPG::_get_tmap(OpContext
*ctx
, bufferlist
*header
, bufferlist
*vals
)
6782 if (ctx
->new_obs
.oi
.size
== 0) {
6783 dout(20) << "unable to get tmap for zero sized " << ctx
->new_obs
.oi
.soid
<< dendl
;
6786 vector
<OSDOp
> nops(1);
6787 OSDOp
&newop
= nops
[0];
6788 newop
.op
.op
= CEPH_OSD_OP_TMAPGET
;
6789 do_osd_ops(ctx
, nops
);
6791 bufferlist::iterator i
= newop
.outdata
.begin();
6792 ::decode(*header
, i
);
6793 (*vals
).substr_of(newop
.outdata
, i
.get_off(), i
.get_remaining());
6795 dout(20) << "unsuccessful at decoding tmap for " << ctx
->new_obs
.oi
.soid
6799 dout(20) << "successful at decoding tmap for " << ctx
->new_obs
.oi
.soid
6804 int PrimaryLogPG::_verify_no_head_clones(const hobject_t
& soid
,
6807 // verify that all clones have been evicted
6808 dout(20) << __func__
<< " verifying clones are absent "
6810 for (vector
<snapid_t
>::const_iterator p
= ss
.clones
.begin();
6811 p
!= ss
.clones
.end();
6813 hobject_t clone_oid
= soid
;
6814 clone_oid
.snap
= *p
;
6815 if (is_missing_object(clone_oid
))
6817 ObjectContextRef clone_obc
= get_object_context(clone_oid
, false);
6818 if (clone_obc
&& clone_obc
->obs
.exists
) {
6819 dout(10) << __func__
<< " cannot evict head before clone "
6820 << clone_oid
<< dendl
;
6823 if (copy_ops
.count(clone_oid
)) {
6824 dout(10) << __func__
<< " cannot evict head, pending promote on clone "
6825 << clone_oid
<< dendl
;
6832 inline int PrimaryLogPG::_delete_oid(
6834 bool no_whiteout
, // no whiteouts, no matter what.
6835 bool try_no_whiteout
) // try not to whiteout
6837 SnapSet
& snapset
= ctx
->new_snapset
;
6838 ObjectState
& obs
= ctx
->new_obs
;
6839 object_info_t
& oi
= obs
.oi
;
6840 const hobject_t
& soid
= oi
.soid
;
6841 PGTransaction
* t
= ctx
->op_t
.get();
6843 // cache: cache: set whiteout on delete?
6844 bool whiteout
= false;
6845 if (pool
.info
.cache_mode
!= pg_pool_t::CACHEMODE_NONE
6847 && !try_no_whiteout
) {
6851 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_LUMINOUS
) {
6853 // in luminous or later, we can't delete the head if there are
6854 // clones. we trust the caller passing no_whiteout has already
6855 // verified they don't exist.
6856 if (!snapset
.clones
.empty() ||
6857 (!ctx
->snapc
.snaps
.empty() && ctx
->snapc
.snaps
[0] > snapset
.seq
)) {
6859 dout(20) << __func__
<< " has or will have clones but no_whiteout=1"
6862 dout(20) << __func__
<< " has or will have clones; will whiteout"
6870 dout(20) << __func__
<< " " << soid
<< " whiteout=" << (int)whiteout
6871 << " no_whiteout=" << (int)no_whiteout
6872 << " try_no_whiteout=" << (int)try_no_whiteout
6874 if (!obs
.exists
|| (obs
.oi
.is_whiteout() && whiteout
))
6880 interval_set
<uint64_t> ch
;
6881 ch
.insert(0, oi
.size
);
6882 ctx
->modified_ranges
.union_of(ch
);
6885 ctx
->delta_stats
.num_wr
++;
6886 if (soid
.is_snap()) {
6887 assert(ctx
->obc
->ssc
->snapset
.clone_overlap
.count(soid
.snap
));
6888 ctx
->delta_stats
.num_bytes
-= ctx
->obc
->ssc
->snapset
.get_clone_bytes(soid
.snap
);
6890 ctx
->delta_stats
.num_bytes
-= oi
.size
;
6895 // disconnect all watchers
6896 for (map
<pair
<uint64_t, entity_name_t
>, watch_info_t
>::iterator p
=
6897 oi
.watchers
.begin();
6898 p
!= oi
.watchers
.end();
6900 dout(20) << __func__
<< " will disconnect watcher " << p
->first
<< dendl
;
6901 ctx
->watch_disconnects
.push_back(
6902 watch_disconnect_t(p
->first
.first
, p
->first
.second
, true));
6904 oi
.watchers
.clear();
6907 dout(20) << __func__
<< " setting whiteout on " << soid
<< dendl
;
6908 oi
.set_flag(object_info_t::FLAG_WHITEOUT
);
6909 ctx
->delta_stats
.num_whiteouts
++;
6911 osd
->logger
->inc(l_osd_tier_whiteout
);
6916 ctx
->delta_stats
.num_objects
--;
6918 ctx
->delta_stats
.num_object_clones
--;
6919 if (oi
.is_whiteout()) {
6920 dout(20) << __func__
<< " deleting whiteout on " << soid
<< dendl
;
6921 ctx
->delta_stats
.num_whiteouts
--;
6922 oi
.clear_flag(object_info_t::FLAG_WHITEOUT
);
6924 if (oi
.is_cache_pinned()) {
6925 ctx
->delta_stats
.num_objects_pinned
--;
6927 if ((legacy
|| snapset
.is_legacy()) && soid
.is_head()) {
6928 snapset
.head_exists
= false;
6934 int PrimaryLogPG::_rollback_to(OpContext
*ctx
, ceph_osd_op
& op
)
6936 SnapSet
& snapset
= ctx
->new_snapset
;
6937 ObjectState
& obs
= ctx
->new_obs
;
6938 object_info_t
& oi
= obs
.oi
;
6939 const hobject_t
& soid
= oi
.soid
;
6940 PGTransaction
* t
= ctx
->op_t
.get();
6941 snapid_t snapid
= (uint64_t)op
.snap
.snapid
;
6942 hobject_t missing_oid
;
6944 dout(10) << "_rollback_to " << soid
<< " snapid " << snapid
<< dendl
;
6946 ObjectContextRef rollback_to
;
6947 int ret
= find_object_context(
6948 hobject_t(soid
.oid
, soid
.get_key(), snapid
, soid
.get_hash(), info
.pgid
.pool(),
6949 soid
.get_namespace()),
6950 &rollback_to
, false, false, &missing_oid
);
6951 if (ret
== -EAGAIN
) {
6952 /* clone must be missing */
6953 assert(is_degraded_or_backfilling_object(missing_oid
));
6954 dout(20) << "_rollback_to attempted to roll back to a missing or backfilling clone "
6955 << missing_oid
<< " (requested snapid: ) " << snapid
<< dendl
;
6956 block_write_on_degraded_snap(missing_oid
, ctx
->op
);
6960 ObjectContextRef promote_obc
;
6961 cache_result_t tier_mode_result
;
6962 if (obs
.exists
&& obs
.oi
.has_manifest()) {
6964 maybe_handle_manifest_detail(
6970 maybe_handle_cache_detail(
6980 switch (tier_mode_result
) {
6981 case cache_result_t::NOOP
:
6983 case cache_result_t::BLOCKED_PROMOTE
:
6984 assert(promote_obc
);
6985 block_write_on_snap_rollback(soid
, promote_obc
, ctx
->op
);
6987 case cache_result_t::BLOCKED_FULL
:
6988 block_write_on_full_cache(soid
, ctx
->op
);
6991 assert(0 == "must promote was set, other values are not valid");
6996 if (ret
== -ENOENT
|| (rollback_to
&& rollback_to
->obs
.oi
.is_whiteout())) {
6997 // there's no snapshot here, or there's no object.
6998 // if there's no snapshot, we delete the object; otherwise, do nothing.
6999 dout(20) << "_rollback_to deleting head on " << soid
.oid
7000 << " because got ENOENT|whiteout on find_object_context" << dendl
;
7001 if (ctx
->obc
->obs
.oi
.watchers
.size()) {
7002 // Cannot delete an object with watchers
7005 _delete_oid(ctx
, false, false);
7009 // ummm....huh? It *can't* return anything else at time of writing.
7010 assert(0 == "unexpected error code in _rollback_to");
7011 } else { //we got our context, let's use it to do the rollback!
7012 hobject_t
& rollback_to_sobject
= rollback_to
->obs
.oi
.soid
;
7013 if (is_degraded_or_backfilling_object(rollback_to_sobject
)) {
7014 dout(20) << "_rollback_to attempted to roll back to a degraded object "
7015 << rollback_to_sobject
<< " (requested snapid: ) " << snapid
<< dendl
;
7016 block_write_on_degraded_snap(rollback_to_sobject
, ctx
->op
);
7018 } else if (rollback_to
->obs
.oi
.soid
.snap
== CEPH_NOSNAP
) {
7019 // rolling back to the head; we just need to clone it.
7022 /* 1) Delete current head
7023 * 2) Clone correct snapshot into head
7024 * 3) Calculate clone_overlaps by following overlaps
7025 * forward from rollback snapshot */
7026 dout(10) << "_rollback_to deleting " << soid
.oid
7027 << " and rolling back to old snap" << dendl
;
7032 t
->clone(soid
, rollback_to_sobject
);
7033 snapset
.head_exists
= true;
7034 t
->add_obc(rollback_to
);
7036 map
<snapid_t
, interval_set
<uint64_t> >::iterator iter
=
7037 snapset
.clone_overlap
.lower_bound(snapid
);
7038 interval_set
<uint64_t> overlaps
= iter
->second
;
7039 assert(iter
!= snapset
.clone_overlap
.end());
7041 iter
!= snapset
.clone_overlap
.end();
7043 overlaps
.intersection_of(iter
->second
);
7045 if (obs
.oi
.size
> 0) {
7046 interval_set
<uint64_t> modified
;
7047 modified
.insert(0, obs
.oi
.size
);
7048 overlaps
.intersection_of(modified
);
7049 modified
.subtract(overlaps
);
7050 ctx
->modified_ranges
.union_of(modified
);
7053 // Adjust the cached objectcontext
7054 maybe_create_new_object(ctx
, true);
7055 ctx
->delta_stats
.num_bytes
-= obs
.oi
.size
;
7056 ctx
->delta_stats
.num_bytes
+= rollback_to
->obs
.oi
.size
;
7057 obs
.oi
.size
= rollback_to
->obs
.oi
.size
;
7058 if (rollback_to
->obs
.oi
.is_data_digest())
7059 obs
.oi
.set_data_digest(rollback_to
->obs
.oi
.data_digest
);
7061 obs
.oi
.clear_data_digest();
7062 if (rollback_to
->obs
.oi
.is_omap_digest())
7063 obs
.oi
.set_omap_digest(rollback_to
->obs
.oi
.omap_digest
);
7065 obs
.oi
.clear_omap_digest();
7067 if (rollback_to
->obs
.oi
.is_omap()) {
7068 dout(10) << __func__
<< " setting omap flag on " << obs
.oi
.soid
<< dendl
;
7069 obs
.oi
.set_flag(object_info_t::FLAG_OMAP
);
7071 dout(10) << __func__
<< " clearing omap flag on " << obs
.oi
.soid
<< dendl
;
7072 obs
.oi
.clear_flag(object_info_t::FLAG_OMAP
);
7075 snapset
.head_exists
= true;
7081 void PrimaryLogPG::_make_clone(
7084 ObjectContextRef obc
,
7085 const hobject_t
& head
, const hobject_t
& coid
,
7089 ::encode(*poi
, bv
, get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
7091 t
->clone(coid
, head
);
7092 setattr_maybe_cache(obc
, ctx
, t
, OI_ATTR
, bv
);
7093 rmattr_maybe_cache(obc
, ctx
, t
, SS_ATTR
);
7096 void PrimaryLogPG::make_writeable(OpContext
*ctx
)
7098 const hobject_t
& soid
= ctx
->obs
->oi
.soid
;
7099 SnapContext
& snapc
= ctx
->snapc
;
7102 assert(soid
.snap
== CEPH_NOSNAP
);
7103 dout(20) << "make_writeable " << soid
<< " snapset=" << ctx
->new_snapset
7104 << " snapc=" << snapc
<< dendl
;
7106 bool was_dirty
= ctx
->obc
->obs
.oi
.is_dirty();
7107 if (ctx
->new_obs
.exists
) {
7108 // we will mark the object dirty
7109 if (ctx
->undirty
&& was_dirty
) {
7110 dout(20) << " clearing DIRTY flag" << dendl
;
7111 assert(ctx
->new_obs
.oi
.is_dirty());
7112 ctx
->new_obs
.oi
.clear_flag(object_info_t::FLAG_DIRTY
);
7113 --ctx
->delta_stats
.num_objects_dirty
;
7114 osd
->logger
->inc(l_osd_tier_clean
);
7115 } else if (!was_dirty
&& !ctx
->undirty
) {
7116 dout(20) << " setting DIRTY flag" << dendl
;
7117 ctx
->new_obs
.oi
.set_flag(object_info_t::FLAG_DIRTY
);
7118 ++ctx
->delta_stats
.num_objects_dirty
;
7119 osd
->logger
->inc(l_osd_tier_dirty
);
7123 dout(20) << " deletion, decrementing num_dirty and clearing flag" << dendl
;
7124 ctx
->new_obs
.oi
.clear_flag(object_info_t::FLAG_DIRTY
);
7125 --ctx
->delta_stats
.num_objects_dirty
;
7129 if ((ctx
->new_obs
.exists
&&
7130 ctx
->new_obs
.oi
.is_omap()) &&
7131 (!ctx
->obc
->obs
.exists
||
7132 !ctx
->obc
->obs
.oi
.is_omap())) {
7133 ++ctx
->delta_stats
.num_objects_omap
;
7135 if ((!ctx
->new_obs
.exists
||
7136 !ctx
->new_obs
.oi
.is_omap()) &&
7137 (ctx
->obc
->obs
.exists
&&
7138 ctx
->obc
->obs
.oi
.is_omap())) {
7139 --ctx
->delta_stats
.num_objects_omap
;
7143 if (ctx
->new_snapset
.seq
> snapc
.seq
) {
7144 snapc
.seq
= ctx
->new_snapset
.seq
;
7145 snapc
.snaps
= ctx
->new_snapset
.snaps
;
7146 filter_snapc(snapc
.snaps
);
7147 dout(10) << " using newer snapc " << snapc
<< dendl
;
7150 if ((ctx
->obs
->exists
&& !ctx
->obs
->oi
.is_whiteout()) && // head exist(ed)
7151 snapc
.snaps
.size() && // there are snaps
7152 !ctx
->cache_evict
&&
7153 snapc
.snaps
[0] > ctx
->new_snapset
.seq
) { // existing object is old
7155 hobject_t coid
= soid
;
7156 coid
.snap
= snapc
.seq
;
7159 for (l
=1; l
<snapc
.snaps
.size() && snapc
.snaps
[l
] > ctx
->new_snapset
.seq
; l
++) ;
7161 vector
<snapid_t
> snaps(l
);
7162 for (unsigned i
=0; i
<l
; i
++)
7163 snaps
[i
] = snapc
.snaps
[i
];
7166 object_info_t
static_snap_oi(coid
);
7167 object_info_t
*snap_oi
;
7169 ctx
->clone_obc
= object_contexts
.lookup_or_create(static_snap_oi
.soid
);
7170 ctx
->clone_obc
->destructor_callback
= new C_PG_ObjectContext(this, ctx
->clone_obc
.get());
7171 ctx
->clone_obc
->obs
.oi
= static_snap_oi
;
7172 ctx
->clone_obc
->obs
.exists
= true;
7173 ctx
->clone_obc
->ssc
= ctx
->obc
->ssc
;
7174 ctx
->clone_obc
->ssc
->ref
++;
7175 if (pool
.info
.require_rollback())
7176 ctx
->clone_obc
->attr_cache
= ctx
->obc
->attr_cache
;
7177 snap_oi
= &ctx
->clone_obc
->obs
.oi
;
7178 bool got
= ctx
->lock_manager
.get_write_greedy(
7183 dout(20) << " got greedy write on clone_obc " << *ctx
->clone_obc
<< dendl
;
7185 snap_oi
= &static_snap_oi
;
7187 snap_oi
->version
= ctx
->at_version
;
7188 snap_oi
->prior_version
= ctx
->obs
->oi
.version
;
7189 snap_oi
->copy_user_bits(ctx
->obs
->oi
);
7191 bool legacy
= ctx
->new_snapset
.is_legacy() ||
7192 get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
;
7194 snap_oi
->legacy_snaps
= snaps
;
7197 _make_clone(ctx
, ctx
->op_t
.get(), ctx
->clone_obc
, soid
, coid
, snap_oi
);
7199 ctx
->delta_stats
.num_objects
++;
7200 if (snap_oi
->is_dirty()) {
7201 ctx
->delta_stats
.num_objects_dirty
++;
7202 osd
->logger
->inc(l_osd_tier_dirty
);
7204 if (snap_oi
->is_omap())
7205 ctx
->delta_stats
.num_objects_omap
++;
7206 if (snap_oi
->is_cache_pinned())
7207 ctx
->delta_stats
.num_objects_pinned
++;
7208 ctx
->delta_stats
.num_object_clones
++;
7209 ctx
->new_snapset
.clones
.push_back(coid
.snap
);
7210 ctx
->new_snapset
.clone_size
[coid
.snap
] = ctx
->obs
->oi
.size
;
7212 ctx
->new_snapset
.clone_snaps
[coid
.snap
] = snaps
;
7215 // clone_overlap should contain an entry for each clone
7216 // (an empty interval_set if there is no overlap)
7217 ctx
->new_snapset
.clone_overlap
[coid
.snap
];
7218 if (ctx
->obs
->oi
.size
)
7219 ctx
->new_snapset
.clone_overlap
[coid
.snap
].insert(0, ctx
->obs
->oi
.size
);
7222 dout(10) << " cloning v " << ctx
->obs
->oi
.version
7223 << " to " << coid
<< " v " << ctx
->at_version
7224 << " snaps=" << snaps
7225 << " snapset=" << ctx
->new_snapset
<< dendl
;
7226 ctx
->log
.push_back(pg_log_entry_t(pg_log_entry_t::CLONE
, coid
, ctx
->at_version
,
7227 ctx
->obs
->oi
.version
,
7228 ctx
->obs
->oi
.user_version
,
7229 osd_reqid_t(), ctx
->new_obs
.oi
.mtime
, 0));
7230 ::encode(snaps
, ctx
->log
.back().snaps
);
7232 ctx
->at_version
.version
++;
7235 // update most recent clone_overlap and usage stats
7236 if (ctx
->new_snapset
.clones
.size() > 0) {
7237 /* we need to check whether the most recent clone exists, if it's been evicted,
7238 * it's not included in the stats */
7239 hobject_t last_clone_oid
= soid
;
7240 last_clone_oid
.snap
= ctx
->new_snapset
.clone_overlap
.rbegin()->first
;
7241 if (is_present_clone(last_clone_oid
)) {
7242 interval_set
<uint64_t> &newest_overlap
= ctx
->new_snapset
.clone_overlap
.rbegin()->second
;
7243 ctx
->modified_ranges
.intersection_of(newest_overlap
);
7244 // modified_ranges is still in use by the clone
7245 add_interval_usage(ctx
->modified_ranges
, ctx
->delta_stats
);
7246 newest_overlap
.subtract(ctx
->modified_ranges
);
7250 // update snapset with latest snap context
7251 ctx
->new_snapset
.seq
= snapc
.seq
;
7252 ctx
->new_snapset
.snaps
= snapc
.snaps
;
7253 if (get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
7254 // pessimistic assumption that this is a net-new legacy SnapSet
7255 ctx
->delta_stats
.num_legacy_snapsets
++;
7256 ctx
->new_snapset
.head_exists
= ctx
->new_obs
.exists
;
7257 } else if (ctx
->new_snapset
.is_legacy()) {
7258 ctx
->new_snapset
.head_exists
= ctx
->new_obs
.exists
;
7260 dout(20) << "make_writeable " << soid
7261 << " done, snapset=" << ctx
->new_snapset
<< dendl
;
7265 void PrimaryLogPG::write_update_size_and_usage(object_stat_sum_t
& delta_stats
, object_info_t
& oi
,
7266 interval_set
<uint64_t>& modified
, uint64_t offset
,
7267 uint64_t length
, bool write_full
)
7269 interval_set
<uint64_t> ch
;
7272 ch
.insert(0, oi
.size
);
7274 ch
.insert(offset
, length
);
7275 modified
.union_of(ch
);
7276 if (write_full
|| offset
+ length
> oi
.size
) {
7277 uint64_t new_size
= offset
+ length
;
7278 delta_stats
.num_bytes
-= oi
.size
;
7279 delta_stats
.num_bytes
+= new_size
;
7282 delta_stats
.num_wr
++;
7283 delta_stats
.num_wr_kb
+= SHIFT_ROUND_UP(length
, 10);
7286 void PrimaryLogPG::add_interval_usage(interval_set
<uint64_t>& s
, object_stat_sum_t
& delta_stats
)
7288 for (interval_set
<uint64_t>::const_iterator p
= s
.begin(); p
!= s
.end(); ++p
) {
7289 delta_stats
.num_bytes
+= p
.get_len();
7293 void PrimaryLogPG::complete_disconnect_watches(
7294 ObjectContextRef obc
,
7295 const list
<watch_disconnect_t
> &to_disconnect
)
7297 for (list
<watch_disconnect_t
>::const_iterator i
=
7298 to_disconnect
.begin();
7299 i
!= to_disconnect
.end();
7301 pair
<uint64_t, entity_name_t
> watcher(i
->cookie
, i
->name
);
7302 auto watchers_entry
= obc
->watchers
.find(watcher
);
7303 if (watchers_entry
!= obc
->watchers
.end()) {
7304 WatchRef watch
= watchers_entry
->second
;
7305 dout(10) << "do_osd_op_effects disconnect watcher " << watcher
<< dendl
;
7306 obc
->watchers
.erase(watcher
);
7307 watch
->remove(i
->send_disconnect
);
7309 dout(10) << "do_osd_op_effects disconnect failed to find watcher "
7310 << watcher
<< dendl
;
7315 void PrimaryLogPG::do_osd_op_effects(OpContext
*ctx
, const ConnectionRef
& conn
)
7317 entity_name_t entity
= ctx
->reqid
.name
;
7318 dout(15) << "do_osd_op_effects " << entity
<< " con " << conn
.get() << dendl
;
7320 // disconnects first
7321 complete_disconnect_watches(ctx
->obc
, ctx
->watch_disconnects
);
7325 boost::intrusive_ptr
<Session
> session((Session
*)conn
->get_priv());
7328 session
->put(); // get_priv() takes a ref, and so does the intrusive_ptr
7330 for (list
<pair
<watch_info_t
,bool> >::iterator i
= ctx
->watch_connects
.begin();
7331 i
!= ctx
->watch_connects
.end();
7333 pair
<uint64_t, entity_name_t
> watcher(i
->first
.cookie
, entity
);
7334 dout(15) << "do_osd_op_effects applying watch connect on session "
7335 << session
.get() << " watcher " << watcher
<< dendl
;
7337 if (ctx
->obc
->watchers
.count(watcher
)) {
7338 dout(15) << "do_osd_op_effects found existing watch watcher " << watcher
7340 watch
= ctx
->obc
->watchers
[watcher
];
7342 dout(15) << "do_osd_op_effects new watcher " << watcher
7344 watch
= Watch::makeWatchRef(
7345 this, osd
, ctx
->obc
, i
->first
.timeout_seconds
,
7346 i
->first
.cookie
, entity
, conn
->get_peer_addr());
7347 ctx
->obc
->watchers
.insert(
7352 watch
->connect(conn
, i
->second
);
7355 for (list
<notify_info_t
>::iterator p
= ctx
->notifies
.begin();
7356 p
!= ctx
->notifies
.end();
7358 dout(10) << "do_osd_op_effects, notify " << *p
<< dendl
;
7359 ConnectionRef
conn(ctx
->op
->get_req()->get_connection());
7361 Notify::makeNotifyRef(
7363 ctx
->reqid
.name
.num(),
7368 ctx
->obc
->obs
.oi
.user_version
,
7370 for (map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator i
=
7371 ctx
->obc
->watchers
.begin();
7372 i
!= ctx
->obc
->watchers
.end();
7374 dout(10) << "starting notify on watch " << i
->first
<< dendl
;
7375 i
->second
->start_notify(notif
);
7380 for (list
<OpContext::NotifyAck
>::iterator p
= ctx
->notify_acks
.begin();
7381 p
!= ctx
->notify_acks
.end();
7383 if (p
->watch_cookie
)
7384 dout(10) << "notify_ack " << make_pair(p
->watch_cookie
.get(), p
->notify_id
) << dendl
;
7386 dout(10) << "notify_ack " << make_pair("NULL", p
->notify_id
) << dendl
;
7387 for (map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator i
=
7388 ctx
->obc
->watchers
.begin();
7389 i
!= ctx
->obc
->watchers
.end();
7391 if (i
->first
.second
!= entity
) continue;
7392 if (p
->watch_cookie
&&
7393 p
->watch_cookie
.get() != i
->first
.first
) continue;
7394 dout(10) << "acking notify on watch " << i
->first
<< dendl
;
7395 i
->second
->notify_ack(p
->notify_id
, p
->reply_bl
);
7400 hobject_t
PrimaryLogPG::generate_temp_object(const hobject_t
& target
)
7403 ss
<< "temp_" << info
.pgid
<< "_" << get_role()
7404 << "_" << osd
->monc
->get_global_id() << "_" << (++temp_seq
);
7405 hobject_t hoid
= target
.make_temp_hobject(ss
.str());
7406 dout(20) << __func__
<< " " << hoid
<< dendl
;
7410 hobject_t
PrimaryLogPG::get_temp_recovery_object(
7411 const hobject_t
& target
,
7415 ss
<< "temp_recovering_" << info
.pgid
// (note this includes the shardid)
7417 << "_" << info
.history
.same_interval_since
7418 << "_" << target
.snap
;
7419 // pgid + version + interval + snapid is unique, and short
7420 hobject_t hoid
= target
.make_temp_hobject(ss
.str());
7421 dout(20) << __func__
<< " " << hoid
<< dendl
;
7425 int PrimaryLogPG::prepare_transaction(OpContext
*ctx
)
7427 assert(!ctx
->ops
->empty());
7429 const hobject_t
& soid
= ctx
->obs
->oi
.soid
;
7431 // valid snap context?
7432 if (!ctx
->snapc
.is_valid()) {
7433 dout(10) << " invalid snapc " << ctx
->snapc
<< dendl
;
7437 // prepare the actual mutation
7438 int result
= do_osd_ops(ctx
, *ctx
->ops
);
7440 if (ctx
->op
->may_write() &&
7441 get_osdmap()->require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
7442 // need to save the error code in the pg log, to detect dup ops,
7443 // but do nothing else
7444 ctx
->update_log_only
= true;
7449 // read-op? write-op noop? done?
7450 if (ctx
->op_t
->empty() && !ctx
->modify
) {
7451 unstable_stats
.add(ctx
->delta_stats
);
7452 if (ctx
->op
->may_write() &&
7453 get_osdmap()->require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
7454 ctx
->update_log_only
= true;
7460 if ((ctx
->delta_stats
.num_bytes
> 0 ||
7461 ctx
->delta_stats
.num_objects
> 0) && // FIXME: keys?
7462 (pool
.info
.has_flag(pg_pool_t::FLAG_FULL
) ||
7463 get_osdmap()->test_flag(CEPH_OSDMAP_FULL
))) {
7464 const MOSDOp
*m
= static_cast<const MOSDOp
*>(ctx
->op
->get_req());
7465 if (ctx
->reqid
.name
.is_mds() || // FIXME: ignore MDS for now
7466 m
->has_flag(CEPH_OSD_FLAG_FULL_FORCE
)) {
7467 dout(20) << __func__
<< " full, but proceeding due to FULL_FORCE or MDS"
7469 } else if (m
->has_flag(CEPH_OSD_FLAG_FULL_TRY
)) {
7470 // they tried, they failed.
7471 dout(20) << __func__
<< " full, replying to FULL_TRY op" << dendl
;
7472 return pool
.info
.has_flag(pg_pool_t::FLAG_FULL
) ? -EDQUOT
: -ENOSPC
;
7475 dout(20) << __func__
<< " full, dropping request (bad client)" << dendl
;
7480 // clone, if necessary
7481 if (soid
.snap
== CEPH_NOSNAP
)
7482 make_writeable(ctx
);
7485 ctx
->new_obs
.exists
? pg_log_entry_t::MODIFY
:
7486 pg_log_entry_t::DELETE
);
7491 void PrimaryLogPG::finish_ctx(OpContext
*ctx
, int log_op_type
, bool maintain_ssc
)
7493 const hobject_t
& soid
= ctx
->obs
->oi
.soid
;
7494 dout(20) << __func__
<< " " << soid
<< " " << ctx
7495 << " op " << pg_log_entry_t::get_op_name(log_op_type
)
7497 utime_t now
= ceph_clock_now();
7502 if (soid
.snap
== CEPH_NOSNAP
&& maintain_ssc
) {
7503 ::encode(ctx
->new_snapset
, bss
);
7504 assert(ctx
->new_obs
.exists
== ctx
->new_snapset
.head_exists
||
7505 !ctx
->new_snapset
.is_legacy());
7507 if (ctx
->new_obs
.exists
) {
7508 if (!ctx
->obs
->exists
) {
7509 if (ctx
->snapset_obc
&& ctx
->snapset_obc
->obs
.exists
) {
7510 hobject_t snapoid
= soid
.get_snapdir();
7511 dout(10) << " removing unneeded snapdir " << snapoid
<< dendl
;
7512 ctx
->log
.push_back(pg_log_entry_t(pg_log_entry_t::DELETE
, snapoid
,
7514 ctx
->snapset_obc
->obs
.oi
.version
,
7515 0, osd_reqid_t(), ctx
->mtime
, 0));
7516 ctx
->op_t
->remove(snapoid
);
7518 ctx
->at_version
.version
++;
7520 ctx
->snapset_obc
->obs
.exists
= false;
7523 } else if (!ctx
->new_snapset
.clones
.empty() &&
7524 !ctx
->cache_evict
&&
7525 !ctx
->new_snapset
.head_exists
&&
7526 (!ctx
->snapset_obc
|| !ctx
->snapset_obc
->obs
.exists
)) {
7527 // save snapset on _snap
7528 hobject_t
snapoid(soid
.oid
, soid
.get_key(), CEPH_SNAPDIR
, soid
.get_hash(),
7529 info
.pgid
.pool(), soid
.get_namespace());
7530 dout(10) << " final snapset " << ctx
->new_snapset
7531 << " in " << snapoid
<< dendl
;
7532 assert(get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
);
7533 ctx
->log
.push_back(pg_log_entry_t(pg_log_entry_t::MODIFY
, snapoid
,
7536 0, osd_reqid_t(), ctx
->mtime
, 0));
7538 if (!ctx
->snapset_obc
)
7539 ctx
->snapset_obc
= get_object_context(snapoid
, true);
7541 if (ctx
->lock_type
== ObjectContext::RWState::RWWRITE
) {
7542 got
= ctx
->lock_manager
.get_write_greedy(
7547 assert(ctx
->lock_type
== ObjectContext::RWState::RWEXCL
);
7548 got
= ctx
->lock_manager
.get_lock_type(
7549 ObjectContext::RWState::RWEXCL
,
7555 dout(20) << " got greedy write on snapset_obc " << *ctx
->snapset_obc
<< dendl
;
7556 ctx
->snapset_obc
->obs
.exists
= true;
7557 ctx
->snapset_obc
->obs
.oi
.version
= ctx
->at_version
;
7558 ctx
->snapset_obc
->obs
.oi
.last_reqid
= ctx
->reqid
;
7559 ctx
->snapset_obc
->obs
.oi
.mtime
= ctx
->mtime
;
7560 ctx
->snapset_obc
->obs
.oi
.local_mtime
= now
;
7562 map
<string
, bufferlist
> attrs
;
7563 bufferlist
bv(sizeof(ctx
->new_obs
.oi
));
7564 ::encode(ctx
->snapset_obc
->obs
.oi
, bv
,
7565 get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
7566 ctx
->op_t
->create(snapoid
);
7567 attrs
[OI_ATTR
].claim(bv
);
7568 attrs
[SS_ATTR
].claim(bss
);
7569 setattrs_maybe_cache(ctx
->snapset_obc
, ctx
, ctx
->op_t
.get(), attrs
);
7570 ctx
->at_version
.version
++;
7574 // finish and log the op.
7575 if (ctx
->user_modify
) {
7576 // update the user_version for any modify ops, except for the watch op
7577 ctx
->user_at_version
= MAX(info
.last_user_version
, ctx
->new_obs
.oi
.user_version
) + 1;
7578 /* In order for new clients and old clients to interoperate properly
7579 * when exchanging versions, we need to lower bound the user_version
7580 * (which our new clients pay proper attention to)
7581 * by the at_version (which is all the old clients can ever see). */
7582 if (ctx
->at_version
.version
> ctx
->user_at_version
)
7583 ctx
->user_at_version
= ctx
->at_version
.version
;
7584 ctx
->new_obs
.oi
.user_version
= ctx
->user_at_version
;
7586 ctx
->bytes_written
= ctx
->op_t
->get_bytes_written();
7588 if (ctx
->new_obs
.exists
) {
7589 // on the head object
7590 ctx
->new_obs
.oi
.version
= ctx
->at_version
;
7591 ctx
->new_obs
.oi
.prior_version
= ctx
->obs
->oi
.version
;
7592 ctx
->new_obs
.oi
.last_reqid
= ctx
->reqid
;
7593 if (ctx
->mtime
!= utime_t()) {
7594 ctx
->new_obs
.oi
.mtime
= ctx
->mtime
;
7595 dout(10) << " set mtime to " << ctx
->new_obs
.oi
.mtime
<< dendl
;
7596 ctx
->new_obs
.oi
.local_mtime
= now
;
7598 dout(10) << " mtime unchanged at " << ctx
->new_obs
.oi
.mtime
<< dendl
;
7601 map
<string
, bufferlist
> attrs
;
7602 bufferlist
bv(sizeof(ctx
->new_obs
.oi
));
7603 ::encode(ctx
->new_obs
.oi
, bv
,
7604 get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
7605 attrs
[OI_ATTR
].claim(bv
);
7607 if (soid
.snap
== CEPH_NOSNAP
) {
7608 dout(10) << " final snapset " << ctx
->new_snapset
7609 << " in " << soid
<< dendl
;
7610 attrs
[SS_ATTR
].claim(bss
);
7612 dout(10) << " no snapset (this is a clone)" << dendl
;
7614 ctx
->op_t
->setattrs(soid
, attrs
);
7616 ctx
->new_obs
.oi
= object_info_t(ctx
->obc
->obs
.oi
.soid
);
7619 bool legacy_snapset
= ctx
->new_snapset
.is_legacy() ||
7620 get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
;
7623 ctx
->log
.push_back(pg_log_entry_t(log_op_type
, soid
, ctx
->at_version
,
7624 ctx
->obs
->oi
.version
,
7625 ctx
->user_at_version
, ctx
->reqid
,
7627 if (soid
.snap
< CEPH_NOSNAP
) {
7628 switch (log_op_type
) {
7629 case pg_log_entry_t::MODIFY
:
7630 case pg_log_entry_t::PROMOTE
:
7631 case pg_log_entry_t::CLEAN
:
7632 if (legacy_snapset
) {
7633 dout(20) << __func__
<< " encoding legacy_snaps "
7634 << ctx
->new_obs
.oi
.legacy_snaps
7636 ::encode(ctx
->new_obs
.oi
.legacy_snaps
, ctx
->log
.back().snaps
);
7638 dout(20) << __func__
<< " encoding snaps from " << ctx
->new_snapset
7640 ::encode(ctx
->new_snapset
.clone_snaps
[soid
.snap
], ctx
->log
.back().snaps
);
7648 if (!ctx
->extra_reqids
.empty()) {
7649 dout(20) << __func__
<< " extra_reqids " << ctx
->extra_reqids
<< dendl
;
7650 ctx
->log
.back().extra_reqids
.swap(ctx
->extra_reqids
);
7653 // apply new object state.
7654 ctx
->obc
->obs
= ctx
->new_obs
;
7656 if (soid
.is_head() && !ctx
->obc
->obs
.exists
&&
7657 (!maintain_ssc
|| ctx
->cache_evict
)) {
7658 ctx
->obc
->ssc
->exists
= false;
7659 ctx
->obc
->ssc
->snapset
= SnapSet();
7661 ctx
->obc
->ssc
->exists
= true;
7662 ctx
->obc
->ssc
->snapset
= ctx
->new_snapset
;
7666 void PrimaryLogPG::apply_stats(
7667 const hobject_t
&soid
,
7668 const object_stat_sum_t
&delta_stats
) {
7670 info
.stats
.stats
.add(delta_stats
);
7672 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
7673 i
!= backfill_targets
.end();
7676 pg_info_t
& pinfo
= peer_info
[bt
];
7677 if (soid
<= pinfo
.last_backfill
)
7678 pinfo
.stats
.stats
.add(delta_stats
);
7679 else if (soid
<= last_backfill_started
)
7680 pending_backfill_updates
[soid
].stats
.add(delta_stats
);
7683 if (is_primary() && scrubber
.active
) {
7684 if (soid
< scrubber
.start
) {
7685 dout(20) << __func__
<< " " << soid
<< " < [" << scrubber
.start
7686 << "," << scrubber
.end
<< ")" << dendl
;
7687 scrub_cstat
.add(delta_stats
);
7689 dout(20) << __func__
<< " " << soid
<< " >= [" << scrubber
.start
7690 << "," << scrubber
.end
<< ")" << dendl
;
7695 void PrimaryLogPG::complete_read_ctx(int result
, OpContext
*ctx
)
7697 const MOSDOp
*m
= static_cast<const MOSDOp
*>(ctx
->op
->get_req());
7698 assert(ctx
->async_reads_complete());
7700 for (vector
<OSDOp
>::iterator p
= ctx
->ops
->begin();
7701 p
!= ctx
->ops
->end() && result
>= 0; ++p
) {
7702 if (p
->rval
< 0 && !(p
->op
.flags
& CEPH_OSD_OP_FLAG_FAILOK
)) {
7706 ctx
->bytes_read
+= p
->outdata
.length();
7708 ctx
->reply
->claim_op_out_data(*ctx
->ops
);
7709 ctx
->reply
->get_header().data_off
= (ctx
->data_off
? *ctx
->data_off
: 0);
7711 MOSDOpReply
*reply
= ctx
->reply
;
7712 ctx
->reply
= nullptr;
7715 if (!ctx
->ignore_log_op_stats
) {
7717 publish_stats_to_osd();
7720 // on read, return the current object version
7722 reply
->set_reply_versions(eversion_t(), ctx
->obs
->oi
.user_version
);
7724 reply
->set_reply_versions(eversion_t(), ctx
->user_at_version
);
7726 } else if (result
== -ENOENT
) {
7727 // on ENOENT, set a floor for what the next user version will be.
7728 reply
->set_enoent_reply_versions(info
.last_update
, info
.last_user_version
);
7731 reply
->set_result(result
);
7732 reply
->add_flags(CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
7733 osd
->send_message_osd_client(reply
, m
->get_connection());
7737 // ========================================================================
7740 struct C_Copyfrom
: public Context
{
7743 epoch_t last_peering_reset
;
7745 PrimaryLogPG::CopyOpRef cop
;
7746 C_Copyfrom(PrimaryLogPG
*p
, hobject_t o
, epoch_t lpr
,
7747 const PrimaryLogPG::CopyOpRef
& c
)
7748 : pg(p
), oid(o
), last_peering_reset(lpr
),
7751 void finish(int r
) override
{
7752 if (r
== -ECANCELED
)
7755 if (last_peering_reset
== pg
->get_last_peering_reset()) {
7756 pg
->process_copy_chunk(oid
, tid
, r
);
7762 struct C_CopyFrom_AsyncReadCb
: public Context
{
7764 object_copy_data_t reply_obj
;
7767 C_CopyFrom_AsyncReadCb(OSDOp
*osd_op
, uint64_t features
) :
7768 osd_op(osd_op
), features(features
), len(0) {}
7769 void finish(int r
) override
{
7776 assert(len
<= reply_obj
.data
.length());
7778 bl
.substr_of(reply_obj
.data
, 0, len
);
7779 reply_obj
.data
.swap(bl
);
7780 ::encode(reply_obj
, osd_op
->outdata
, features
);
7784 int PrimaryLogPG::do_copy_get(OpContext
*ctx
, bufferlist::iterator
& bp
,
7785 OSDOp
& osd_op
, ObjectContextRef
&obc
)
7787 object_info_t
& oi
= obc
->obs
.oi
;
7788 hobject_t
& soid
= oi
.soid
;
7790 object_copy_cursor_t cursor
;
7793 ::decode(cursor
, bp
);
7794 ::decode(out_max
, bp
);
7796 catch (buffer::error
& e
) {
7801 const MOSDOp
*op
= reinterpret_cast<const MOSDOp
*>(ctx
->op
->get_req());
7802 uint64_t features
= op
->get_features();
7804 bool async_read_started
= false;
7805 object_copy_data_t _reply_obj
;
7806 C_CopyFrom_AsyncReadCb
*cb
= NULL
;
7807 if (pool
.info
.require_rollback()) {
7808 cb
= new C_CopyFrom_AsyncReadCb(&osd_op
, features
);
7810 object_copy_data_t
&reply_obj
= cb
? cb
->reply_obj
: _reply_obj
;
7812 reply_obj
.size
= oi
.size
;
7813 reply_obj
.mtime
= oi
.mtime
;
7815 if (soid
.snap
< CEPH_NOSNAP
) {
7816 if (obc
->ssc
->snapset
.is_legacy()) {
7817 reply_obj
.snaps
= oi
.legacy_snaps
;
7819 auto p
= obc
->ssc
->snapset
.clone_snaps
.find(soid
.snap
);
7820 assert(p
!= obc
->ssc
->snapset
.clone_snaps
.end()); // warn?
7821 reply_obj
.snaps
= p
->second
;
7824 reply_obj
.snap_seq
= obc
->ssc
->snapset
.seq
;
7826 if (oi
.is_data_digest()) {
7827 reply_obj
.flags
|= object_copy_data_t::FLAG_DATA_DIGEST
;
7828 reply_obj
.data_digest
= oi
.data_digest
;
7830 if (oi
.is_omap_digest()) {
7831 reply_obj
.flags
|= object_copy_data_t::FLAG_OMAP_DIGEST
;
7832 reply_obj
.omap_digest
= oi
.omap_digest
;
7834 reply_obj
.truncate_seq
= oi
.truncate_seq
;
7835 reply_obj
.truncate_size
= oi
.truncate_size
;
7838 map
<string
,bufferlist
>& out_attrs
= reply_obj
.attrs
;
7839 if (!cursor
.attr_complete
) {
7840 result
= getattrs_maybe_cache(
7850 cursor
.attr_complete
= true;
7851 dout(20) << " got attrs" << dendl
;
7854 int64_t left
= out_max
- osd_op
.outdata
.length();
7857 bufferlist
& bl
= reply_obj
.data
;
7858 if (left
> 0 && !cursor
.data_complete
) {
7859 if (cursor
.data_offset
< oi
.size
) {
7860 uint64_t max_read
= MIN(oi
.size
- cursor
.data_offset
, (uint64_t)left
);
7862 async_read_started
= true;
7863 ctx
->pending_async_reads
.push_back(
7865 boost::make_tuple(cursor
.data_offset
, max_read
, osd_op
.op
.flags
),
7866 make_pair(&bl
, cb
)));
7869 ctx
->op_finishers
[ctx
->current_osd_subop_num
].reset(
7870 new ReadFinisher(osd_op
));
7871 result
= -EINPROGRESS
;
7873 dout(10) << __func__
<< ": async_read noted for " << soid
<< dendl
;
7875 result
= pgbackend
->objects_read_sync(
7876 oi
.soid
, cursor
.data_offset
, max_read
, osd_op
.op
.flags
, &bl
);
7881 cursor
.data_offset
+= max_read
;
7883 if (cursor
.data_offset
== oi
.size
) {
7884 cursor
.data_complete
= true;
7885 dout(20) << " got data" << dendl
;
7887 assert(cursor
.data_offset
<= oi
.size
);
7891 uint32_t omap_keys
= 0;
7892 if (!pool
.info
.supports_omap() || !oi
.is_omap()) {
7893 cursor
.omap_complete
= true;
7895 if (left
> 0 && !cursor
.omap_complete
) {
7896 assert(cursor
.data_complete
);
7897 if (cursor
.omap_offset
.empty()) {
7898 osd
->store
->omap_get_header(ch
, ghobject_t(oi
.soid
),
7899 &reply_obj
.omap_header
);
7901 bufferlist omap_data
;
7902 ObjectMap::ObjectMapIterator iter
=
7903 osd
->store
->get_omap_iterator(coll
, ghobject_t(oi
.soid
));
7905 iter
->upper_bound(cursor
.omap_offset
);
7906 for (; iter
->valid(); iter
->next(false)) {
7908 ::encode(iter
->key(), omap_data
);
7909 ::encode(iter
->value(), omap_data
);
7910 left
-= iter
->key().length() + 4 + iter
->value().length() + 4;
7915 ::encode(omap_keys
, reply_obj
.omap_data
);
7916 reply_obj
.omap_data
.claim_append(omap_data
);
7918 if (iter
->valid()) {
7919 cursor
.omap_offset
= iter
->key();
7921 cursor
.omap_complete
= true;
7922 dout(20) << " got omap" << dendl
;
7927 if (cursor
.is_complete()) {
7928 // include reqids only in the final step. this is a bit fragile
7930 pg_log
.get_log().get_object_reqids(ctx
->obc
->obs
.oi
.soid
, 10, &reply_obj
.reqids
);
7931 dout(20) << " got reqids" << dendl
;
7934 dout(20) << " cursor.is_complete=" << cursor
.is_complete()
7935 << " " << out_attrs
.size() << " attrs"
7936 << " " << bl
.length() << " bytes"
7937 << " " << reply_obj
.omap_header
.length() << " omap header bytes"
7938 << " " << reply_obj
.omap_data
.length() << " omap data bytes in "
7939 << omap_keys
<< " keys"
7940 << " " << reply_obj
.reqids
.size() << " reqids"
7942 reply_obj
.cursor
= cursor
;
7943 if (!async_read_started
) {
7944 ::encode(reply_obj
, osd_op
.outdata
, features
);
7946 if (cb
&& !async_read_started
) {
7956 void PrimaryLogPG::fill_in_copy_get_noent(OpRequestRef
& op
, hobject_t oid
,
7959 // NOTE: we take non-const ref here for claim_op_out_data below; we must
7960 // be careful not to modify anything else that will upset a racing
7962 MOSDOp
*m
= static_cast<MOSDOp
*>(op
->get_nonconst_req());
7963 uint64_t features
= m
->get_features();
7964 object_copy_data_t reply_obj
;
7966 pg_log
.get_log().get_object_reqids(oid
, 10, &reply_obj
.reqids
);
7967 dout(20) << __func__
<< " got reqids " << reply_obj
.reqids
<< dendl
;
7968 ::encode(reply_obj
, osd_op
.outdata
, features
);
7969 osd_op
.rval
= -ENOENT
;
7970 MOSDOpReply
*reply
= new MOSDOpReply(m
, 0, get_osdmap()->get_epoch(), 0, false);
7971 reply
->claim_op_out_data(m
->ops
);
7972 reply
->set_result(-ENOENT
);
7973 reply
->add_flags(CEPH_OSD_FLAG_ACK
| CEPH_OSD_FLAG_ONDISK
);
7974 osd
->send_message_osd_client(reply
, m
->get_connection());
7977 void PrimaryLogPG::start_copy(CopyCallback
*cb
, ObjectContextRef obc
,
7978 hobject_t src
, object_locator_t oloc
,
7979 version_t version
, unsigned flags
,
7980 bool mirror_snapset
,
7981 unsigned src_obj_fadvise_flags
,
7982 unsigned dest_obj_fadvise_flags
)
7984 const hobject_t
& dest
= obc
->obs
.oi
.soid
;
7985 dout(10) << __func__
<< " " << dest
7986 << " from " << src
<< " " << oloc
<< " v" << version
7987 << " flags " << flags
7988 << (mirror_snapset
? " mirror_snapset" : "")
7991 assert(!mirror_snapset
|| (src
.snap
== CEPH_NOSNAP
||
7992 src
.snap
== CEPH_SNAPDIR
));
7994 // cancel a previous in-progress copy?
7995 if (copy_ops
.count(dest
)) {
7996 // FIXME: if the src etc match, we could avoid restarting from the
7998 CopyOpRef cop
= copy_ops
[dest
];
7999 cancel_copy(cop
, false);
8002 CopyOpRef
cop(std::make_shared
<CopyOp
>(cb
, obc
, src
, oloc
, version
, flags
,
8003 mirror_snapset
, src_obj_fadvise_flags
,
8004 dest_obj_fadvise_flags
));
8005 copy_ops
[dest
] = cop
;
8008 _copy_some(obc
, cop
);
8011 void PrimaryLogPG::_copy_some(ObjectContextRef obc
, CopyOpRef cop
)
8013 dout(10) << __func__
<< " " << obc
<< " " << cop
<< dendl
;
8016 if (cop
->flags
& CEPH_OSD_COPY_FROM_FLAG_FLUSH
)
8017 flags
|= CEPH_OSD_FLAG_FLUSH
;
8018 if (cop
->flags
& CEPH_OSD_COPY_FROM_FLAG_IGNORE_CACHE
)
8019 flags
|= CEPH_OSD_FLAG_IGNORE_CACHE
;
8020 if (cop
->flags
& CEPH_OSD_COPY_FROM_FLAG_IGNORE_OVERLAY
)
8021 flags
|= CEPH_OSD_FLAG_IGNORE_OVERLAY
;
8022 if (cop
->flags
& CEPH_OSD_COPY_FROM_FLAG_MAP_SNAP_CLONE
)
8023 flags
|= CEPH_OSD_FLAG_MAP_SNAP_CLONE
;
8024 if (cop
->flags
& CEPH_OSD_COPY_FROM_FLAG_RWORDERED
)
8025 flags
|= CEPH_OSD_FLAG_RWORDERED
;
8027 C_GatherBuilder
gather(cct
);
8029 if (cop
->cursor
.is_initial() && cop
->mirror_snapset
) {
8031 assert(cop
->src
.snap
== CEPH_NOSNAP
);
8033 op
.list_snaps(&cop
->results
.snapset
, NULL
);
8034 ceph_tid_t tid
= osd
->objecter
->read(cop
->src
.oid
, cop
->oloc
, op
,
8036 flags
, gather
.new_sub(), NULL
);
8037 cop
->objecter_tid2
= tid
;
8041 if (cop
->results
.user_version
) {
8042 op
.assert_version(cop
->results
.user_version
);
8044 // we should learn the version after the first chunk, if we didn't know
8046 assert(cop
->cursor
.is_initial());
8048 op
.copy_get(&cop
->cursor
, get_copy_chunk_size(),
8049 &cop
->results
.object_size
, &cop
->results
.mtime
,
8050 &cop
->attrs
, &cop
->data
, &cop
->omap_header
, &cop
->omap_data
,
8051 &cop
->results
.snaps
, &cop
->results
.snap_seq
,
8052 &cop
->results
.flags
,
8053 &cop
->results
.source_data_digest
,
8054 &cop
->results
.source_omap_digest
,
8055 &cop
->results
.reqids
,
8056 &cop
->results
.truncate_seq
,
8057 &cop
->results
.truncate_size
,
8059 op
.set_last_op_flags(cop
->src_obj_fadvise_flags
);
8061 C_Copyfrom
*fin
= new C_Copyfrom(this, obc
->obs
.oi
.soid
,
8062 get_last_peering_reset(), cop
);
8063 gather
.set_finisher(new C_OnFinisher(fin
,
8064 &osd
->objecter_finisher
));
8066 ceph_tid_t tid
= osd
->objecter
->read(cop
->src
.oid
, cop
->oloc
, op
,
8067 cop
->src
.snap
, NULL
,
8070 // discover the object version if we don't know it yet
8071 cop
->results
.user_version
? NULL
: &cop
->results
.user_version
);
8073 cop
->objecter_tid
= tid
;
8077 void PrimaryLogPG::process_copy_chunk(hobject_t oid
, ceph_tid_t tid
, int r
)
8079 dout(10) << __func__
<< " " << oid
<< " tid " << tid
8080 << " " << cpp_strerror(r
) << dendl
;
8081 map
<hobject_t
,CopyOpRef
>::iterator p
= copy_ops
.find(oid
);
8082 if (p
== copy_ops
.end()) {
8083 dout(10) << __func__
<< " no copy_op found" << dendl
;
8086 CopyOpRef cop
= p
->second
;
8087 if (tid
!= cop
->objecter_tid
) {
8088 dout(10) << __func__
<< " tid " << tid
<< " != cop " << cop
8089 << " tid " << cop
->objecter_tid
<< dendl
;
8093 if (cop
->omap_data
.length() || cop
->omap_header
.length())
8094 cop
->results
.has_omap
= true;
8096 if (r
>= 0 && !pool
.info
.supports_omap() &&
8097 (cop
->omap_data
.length() || cop
->omap_header
.length())) {
8100 cop
->objecter_tid
= 0;
8101 cop
->objecter_tid2
= 0; // assume this ordered before us (if it happened)
8102 ObjectContextRef
& cobc
= cop
->obc
;
8107 assert(cop
->rval
>= 0);
8109 if (oid
.snap
< CEPH_NOSNAP
&& !cop
->results
.snaps
.empty()) {
8110 // verify snap hasn't been deleted
8111 vector
<snapid_t
>::iterator p
= cop
->results
.snaps
.begin();
8112 while (p
!= cop
->results
.snaps
.end()) {
8113 if (pool
.info
.is_removed_snap(*p
)) {
8114 dout(10) << __func__
<< " clone snap " << *p
<< " has been deleted"
8116 for (vector
<snapid_t
>::iterator q
= p
+ 1;
8117 q
!= cop
->results
.snaps
.end();
8120 cop
->results
.snaps
.resize(cop
->results
.snaps
.size() - 1);
8125 if (cop
->results
.snaps
.empty()) {
8126 dout(10) << __func__
<< " no more snaps for " << oid
<< dendl
;
8132 assert(cop
->rval
>= 0);
8134 if (!cop
->temp_cursor
.data_complete
) {
8135 cop
->results
.data_digest
= cop
->data
.crc32c(cop
->results
.data_digest
);
8137 if (pool
.info
.supports_omap() && !cop
->temp_cursor
.omap_complete
) {
8138 if (cop
->omap_header
.length()) {
8139 cop
->results
.omap_digest
=
8140 cop
->omap_header
.crc32c(cop
->results
.omap_digest
);
8142 if (cop
->omap_data
.length()) {
8144 keys
.substr_of(cop
->omap_data
, 4, cop
->omap_data
.length() - 4);
8145 cop
->results
.omap_digest
= keys
.crc32c(cop
->results
.omap_digest
);
8149 if (!cop
->temp_cursor
.attr_complete
) {
8150 for (map
<string
,bufferlist
>::iterator p
= cop
->attrs
.begin();
8151 p
!= cop
->attrs
.end();
8153 cop
->results
.attrs
[string("_") + p
->first
] = p
->second
;
8158 if (!cop
->cursor
.is_complete()) {
8159 // write out what we have so far
8160 if (cop
->temp_cursor
.is_initial()) {
8161 assert(!cop
->results
.started_temp_obj
);
8162 cop
->results
.started_temp_obj
= true;
8163 cop
->results
.temp_oid
= generate_temp_object(oid
);
8164 dout(20) << __func__
<< " using temp " << cop
->results
.temp_oid
<< dendl
;
8166 ObjectContextRef tempobc
= get_object_context(cop
->results
.temp_oid
, true);
8167 OpContextUPtr ctx
= simple_opc_create(tempobc
);
8168 if (cop
->temp_cursor
.is_initial()) {
8169 ctx
->new_temp_oid
= cop
->results
.temp_oid
;
8171 _write_copy_chunk(cop
, ctx
->op_t
.get());
8172 simple_opc_submit(std::move(ctx
));
8173 dout(10) << __func__
<< " fetching more" << dendl
;
8174 _copy_some(cobc
, cop
);
8179 if (cop
->results
.is_data_digest() || cop
->results
.is_omap_digest()) {
8180 dout(20) << __func__
<< std::hex
8181 << " got digest: rx data 0x" << cop
->results
.data_digest
8182 << " omap 0x" << cop
->results
.omap_digest
8183 << ", source: data 0x" << cop
->results
.source_data_digest
8184 << " omap 0x" << cop
->results
.source_omap_digest
8186 << " flags " << cop
->results
.flags
8189 if (cop
->results
.is_data_digest() &&
8190 cop
->results
.data_digest
!= cop
->results
.source_data_digest
) {
8191 derr
<< __func__
<< std::hex
<< " data digest 0x" << cop
->results
.data_digest
8192 << " != source 0x" << cop
->results
.source_data_digest
<< std::dec
8194 osd
->clog
->error() << info
.pgid
<< " copy from " << cop
->src
8195 << " to " << cop
->obc
->obs
.oi
.soid
<< std::hex
8196 << " data digest 0x" << cop
->results
.data_digest
8197 << " != source 0x" << cop
->results
.source_data_digest
8202 if (cop
->results
.is_omap_digest() &&
8203 cop
->results
.omap_digest
!= cop
->results
.source_omap_digest
) {
8204 derr
<< __func__
<< std::hex
8205 << " omap digest 0x" << cop
->results
.omap_digest
8206 << " != source 0x" << cop
->results
.source_omap_digest
8207 << std::dec
<< dendl
;
8208 osd
->clog
->error() << info
.pgid
<< " copy from " << cop
->src
8209 << " to " << cop
->obc
->obs
.oi
.soid
<< std::hex
8210 << " omap digest 0x" << cop
->results
.omap_digest
8211 << " != source 0x" << cop
->results
.source_omap_digest
8216 if (cct
->_conf
->osd_debug_inject_copyfrom_error
) {
8217 derr
<< __func__
<< " injecting copyfrom failure" << dendl
;
8222 cop
->results
.fill_in_final_tx
= std::function
<void(PGTransaction
*)>(
8223 [this, &cop
/* avoid ref cycle */](PGTransaction
*t
) {
8224 ObjectState
& obs
= cop
->obc
->obs
;
8225 if (cop
->temp_cursor
.is_initial()) {
8226 dout(20) << "fill_in_final_tx: writing "
8227 << "directly to final object" << dendl
;
8228 // write directly to final object
8229 cop
->results
.temp_oid
= obs
.oi
.soid
;
8230 _write_copy_chunk(cop
, t
);
8232 // finish writing to temp object, then move into place
8233 dout(20) << "fill_in_final_tx: writing to temp object" << dendl
;
8234 _write_copy_chunk(cop
, t
);
8235 t
->rename(obs
.oi
.soid
, cop
->results
.temp_oid
);
8237 t
->setattrs(obs
.oi
.soid
, cop
->results
.attrs
);
8240 dout(20) << __func__
<< " success; committing" << dendl
;
8243 dout(20) << __func__
<< " complete r = " << cpp_strerror(r
) << dendl
;
8244 CopyCallbackResults
results(r
, &cop
->results
);
8245 cop
->cb
->complete(results
);
8247 copy_ops
.erase(cobc
->obs
.oi
.soid
);
8250 if (r
< 0 && cop
->results
.started_temp_obj
) {
8251 dout(10) << __func__
<< " deleting partial temp object "
8252 << cop
->results
.temp_oid
<< dendl
;
8253 ObjectContextRef tempobc
= get_object_context(cop
->results
.temp_oid
, true);
8254 OpContextUPtr ctx
= simple_opc_create(tempobc
);
8255 ctx
->op_t
->remove(cop
->results
.temp_oid
);
8256 ctx
->discard_temp_oid
= cop
->results
.temp_oid
;
8257 simple_opc_submit(std::move(ctx
));
8260 // cancel and requeue proxy ops on this object
8262 for (map
<ceph_tid_t
, ProxyReadOpRef
>::iterator it
= proxyread_ops
.begin();
8263 it
!= proxyread_ops
.end();) {
8264 if (it
->second
->soid
== cobc
->obs
.oi
.soid
) {
8265 cancel_proxy_read((it
++)->second
);
8270 for (map
<ceph_tid_t
, ProxyWriteOpRef
>::iterator it
= proxywrite_ops
.begin();
8271 it
!= proxywrite_ops
.end();) {
8272 if (it
->second
->soid
== cobc
->obs
.oi
.soid
) {
8273 cancel_proxy_write((it
++)->second
);
8278 kick_proxy_ops_blocked(cobc
->obs
.oi
.soid
);
8281 kick_object_context_blocked(cobc
);
8284 void PrimaryLogPG::_write_copy_chunk(CopyOpRef cop
, PGTransaction
*t
)
8286 dout(20) << __func__
<< " " << cop
8287 << " " << cop
->attrs
.size() << " attrs"
8288 << " " << cop
->data
.length() << " bytes"
8289 << " " << cop
->omap_header
.length() << " omap header bytes"
8290 << " " << cop
->omap_data
.length() << " omap data bytes"
8292 if (!cop
->temp_cursor
.attr_complete
) {
8293 t
->create(cop
->results
.temp_oid
);
8295 if (!cop
->temp_cursor
.data_complete
) {
8296 assert(cop
->data
.length() + cop
->temp_cursor
.data_offset
==
8297 cop
->cursor
.data_offset
);
8298 if (pool
.info
.requires_aligned_append() &&
8299 !cop
->cursor
.data_complete
) {
8301 * Trim off the unaligned bit at the end, we'll adjust cursor.data_offset
8302 * to pick it up on the next pass.
8304 assert(cop
->temp_cursor
.data_offset
%
8305 pool
.info
.required_alignment() == 0);
8306 if (cop
->data
.length() % pool
.info
.required_alignment() != 0) {
8308 cop
->data
.length() % pool
.info
.required_alignment();
8310 bl
.substr_of(cop
->data
, 0, cop
->data
.length() - to_trim
);
8312 cop
->cursor
.data_offset
-= to_trim
;
8313 assert(cop
->data
.length() + cop
->temp_cursor
.data_offset
==
8314 cop
->cursor
.data_offset
);
8317 if (cop
->data
.length()) {
8319 cop
->results
.temp_oid
,
8320 cop
->temp_cursor
.data_offset
,
8323 cop
->dest_obj_fadvise_flags
);
8327 if (pool
.info
.supports_omap()) {
8328 if (!cop
->temp_cursor
.omap_complete
) {
8329 if (cop
->omap_header
.length()) {
8331 cop
->results
.temp_oid
,
8333 cop
->omap_header
.clear();
8335 if (cop
->omap_data
.length()) {
8336 map
<string
,bufferlist
> omap
;
8337 bufferlist::iterator p
= cop
->omap_data
.begin();
8339 t
->omap_setkeys(cop
->results
.temp_oid
, omap
);
8340 cop
->omap_data
.clear();
8344 assert(cop
->omap_header
.length() == 0);
8345 assert(cop
->omap_data
.length() == 0);
8347 cop
->temp_cursor
= cop
->cursor
;
8350 void PrimaryLogPG::finish_copyfrom(CopyFromCallback
*cb
)
8352 OpContext
*ctx
= cb
->ctx
;
8353 dout(20) << "finish_copyfrom on " << ctx
->obs
->oi
.soid
<< dendl
;
8355 ObjectState
& obs
= ctx
->new_obs
;
8357 dout(20) << __func__
<< ": exists, removing" << dendl
;
8358 ctx
->op_t
->remove(obs
.oi
.soid
);
8360 ctx
->delta_stats
.num_objects
++;
8363 if (cb
->is_temp_obj_used()) {
8364 ctx
->discard_temp_oid
= cb
->results
->temp_oid
;
8366 cb
->results
->fill_in_final_tx(ctx
->op_t
.get());
8368 // CopyFromCallback fills this in for us
8369 obs
.oi
.user_version
= ctx
->user_at_version
;
8371 obs
.oi
.set_data_digest(cb
->results
->data_digest
);
8372 obs
.oi
.set_omap_digest(cb
->results
->omap_digest
);
8374 obs
.oi
.truncate_seq
= cb
->results
->truncate_seq
;
8375 obs
.oi
.truncate_size
= cb
->results
->truncate_size
;
8377 ctx
->extra_reqids
= cb
->results
->reqids
;
8379 // cache: clear whiteout?
8380 if (obs
.oi
.is_whiteout()) {
8381 dout(10) << __func__
<< " clearing whiteout on " << obs
.oi
.soid
<< dendl
;
8382 obs
.oi
.clear_flag(object_info_t::FLAG_WHITEOUT
);
8383 --ctx
->delta_stats
.num_whiteouts
;
8386 if (cb
->results
->has_omap
) {
8387 dout(10) << __func__
<< " setting omap flag on " << obs
.oi
.soid
<< dendl
;
8388 obs
.oi
.set_flag(object_info_t::FLAG_OMAP
);
8390 dout(10) << __func__
<< " clearing omap flag on " << obs
.oi
.soid
<< dendl
;
8391 obs
.oi
.clear_flag(object_info_t::FLAG_OMAP
);
8394 interval_set
<uint64_t> ch
;
8395 if (obs
.oi
.size
> 0)
8396 ch
.insert(0, obs
.oi
.size
);
8397 ctx
->modified_ranges
.union_of(ch
);
8399 if (cb
->get_data_size() != obs
.oi
.size
) {
8400 ctx
->delta_stats
.num_bytes
-= obs
.oi
.size
;
8401 obs
.oi
.size
= cb
->get_data_size();
8402 ctx
->delta_stats
.num_bytes
+= obs
.oi
.size
;
8404 ctx
->delta_stats
.num_wr
++;
8405 ctx
->delta_stats
.num_wr_kb
+= SHIFT_ROUND_UP(obs
.oi
.size
, 10);
8407 osd
->logger
->inc(l_osd_copyfrom
);
8410 void PrimaryLogPG::finish_promote(int r
, CopyResults
*results
,
8411 ObjectContextRef obc
)
8413 const hobject_t
& soid
= obc
->obs
.oi
.soid
;
8414 dout(10) << __func__
<< " " << soid
<< " r=" << r
8415 << " uv" << results
->user_version
<< dendl
;
8417 if (r
== -ECANCELED
) {
8421 if (r
!= -ENOENT
&& soid
.is_snap()) {
8422 if (results
->snaps
.empty()) {
8423 // we must have read "snap" content from the head object in
8424 // the base pool. use snap_seq to construct what snaps should
8425 // be for this clone (what is was before we evicted the clean
8426 // clone from this pool, and what it will be when we flush and
8427 // the clone eventually happens in the base pool).
8428 SnapSet
& snapset
= obc
->ssc
->snapset
;
8429 vector
<snapid_t
>::iterator p
= snapset
.snaps
.begin();
8430 while (p
!= snapset
.snaps
.end() && *p
> soid
.snap
)
8432 while (p
!= snapset
.snaps
.end() && *p
> results
->snap_seq
) {
8433 results
->snaps
.push_back(*p
);
8438 dout(20) << __func__
<< " snaps " << results
->snaps
<< dendl
;
8439 filter_snapc(results
->snaps
);
8441 dout(20) << __func__
<< " filtered snaps " << results
->snaps
<< dendl
;
8442 if (results
->snaps
.empty()) {
8443 dout(20) << __func__
8444 << " snaps are empty, clone is invalid,"
8445 << " setting r to ENOENT" << dendl
;
8450 if (r
< 0 && results
->started_temp_obj
) {
8451 dout(10) << __func__
<< " abort; will clean up partial work" << dendl
;
8452 ObjectContextRef tempobc
= get_object_context(results
->temp_oid
, false);
8454 OpContextUPtr ctx
= simple_opc_create(tempobc
);
8455 ctx
->op_t
->remove(results
->temp_oid
);
8456 simple_opc_submit(std::move(ctx
));
8457 results
->started_temp_obj
= false;
8460 if (r
== -ENOENT
&& soid
.is_snap()) {
8461 dout(10) << __func__
8462 << ": enoent while trying to promote clone, " << soid
8463 << " must have been trimmed, removing from snapset"
8465 hobject_t
head(soid
.get_head());
8466 ObjectContextRef obc
= get_object_context(head
, false);
8469 OpContextUPtr tctx
= simple_opc_create(obc
);
8470 tctx
->at_version
= get_next_version();
8471 filter_snapc(tctx
->new_snapset
.snaps
);
8472 vector
<snapid_t
> new_clones
;
8473 map
<snapid_t
, vector
<snapid_t
>> new_clone_snaps
;
8474 for (vector
<snapid_t
>::iterator i
= tctx
->new_snapset
.clones
.begin();
8475 i
!= tctx
->new_snapset
.clones
.end();
8477 if (*i
!= soid
.snap
) {
8478 new_clones
.push_back(*i
);
8479 auto p
= tctx
->new_snapset
.clone_snaps
.find(*i
);
8480 if (p
!= tctx
->new_snapset
.clone_snaps
.end()) {
8481 new_clone_snaps
[*i
] = p
->second
;
8485 tctx
->new_snapset
.clones
.swap(new_clones
);
8486 tctx
->new_snapset
.clone_overlap
.erase(soid
.snap
);
8487 tctx
->new_snapset
.clone_size
.erase(soid
.snap
);
8488 tctx
->new_snapset
.clone_snaps
.swap(new_clone_snaps
);
8490 // take RWWRITE lock for duration of our local write. ignore starvation.
8491 if (!tctx
->lock_manager
.take_write_lock(
8494 assert(0 == "problem!");
8496 dout(20) << __func__
<< " took lock on obc, " << obc
->rwstate
<< dendl
;
8498 finish_ctx(tctx
.get(), pg_log_entry_t::PROMOTE
);
8500 simple_opc_submit(std::move(tctx
));
8504 bool whiteout
= false;
8506 assert(soid
.snap
== CEPH_NOSNAP
); // snap case is above
8507 dout(10) << __func__
<< " whiteout " << soid
<< dendl
;
8511 if (r
< 0 && !whiteout
) {
8512 derr
<< __func__
<< " unexpected promote error " << cpp_strerror(r
) << dendl
;
8513 // pass error to everyone blocked on this object
8514 // FIXME: this is pretty sloppy, but at this point we got
8515 // something unexpected and don't have many other options.
8516 map
<hobject_t
,list
<OpRequestRef
>>::iterator blocked_iter
=
8517 waiting_for_blocked_object
.find(soid
);
8518 if (blocked_iter
!= waiting_for_blocked_object
.end()) {
8519 while (!blocked_iter
->second
.empty()) {
8520 osd
->reply_op_error(blocked_iter
->second
.front(), r
);
8521 blocked_iter
->second
.pop_front();
8523 waiting_for_blocked_object
.erase(blocked_iter
);
8528 osd
->promote_finish(results
->object_size
);
8530 OpContextUPtr tctx
= simple_opc_create(obc
);
8531 tctx
->at_version
= get_next_version();
8533 ++tctx
->delta_stats
.num_objects
;
8534 if (soid
.snap
< CEPH_NOSNAP
)
8535 ++tctx
->delta_stats
.num_object_clones
;
8536 tctx
->new_obs
.exists
= true;
8538 tctx
->extra_reqids
= results
->reqids
;
8540 bool legacy_snapset
= tctx
->new_snapset
.is_legacy() ||
8541 get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
;
8544 // create a whiteout
8545 tctx
->op_t
->create(soid
);
8546 tctx
->new_obs
.oi
.set_flag(object_info_t::FLAG_WHITEOUT
);
8547 ++tctx
->delta_stats
.num_whiteouts
;
8548 dout(20) << __func__
<< " creating whiteout on " << soid
<< dendl
;
8549 osd
->logger
->inc(l_osd_tier_whiteout
);
8551 if (results
->has_omap
) {
8552 dout(10) << __func__
<< " setting omap flag on " << soid
<< dendl
;
8553 tctx
->new_obs
.oi
.set_flag(object_info_t::FLAG_OMAP
);
8554 ++tctx
->delta_stats
.num_objects_omap
;
8557 results
->fill_in_final_tx(tctx
->op_t
.get());
8558 if (results
->started_temp_obj
) {
8559 tctx
->discard_temp_oid
= results
->temp_oid
;
8561 tctx
->new_obs
.oi
.size
= results
->object_size
;
8562 tctx
->new_obs
.oi
.user_version
= results
->user_version
;
8563 // Don't care src object whether have data or omap digest
8564 if (results
->object_size
)
8565 tctx
->new_obs
.oi
.set_data_digest(results
->data_digest
);
8566 if (results
->has_omap
)
8567 tctx
->new_obs
.oi
.set_omap_digest(results
->omap_digest
);
8568 tctx
->new_obs
.oi
.truncate_seq
= results
->truncate_seq
;
8569 tctx
->new_obs
.oi
.truncate_size
= results
->truncate_size
;
8571 if (soid
.snap
!= CEPH_NOSNAP
) {
8572 if (legacy_snapset
) {
8573 tctx
->new_obs
.oi
.legacy_snaps
= results
->snaps
;
8574 assert(!tctx
->new_obs
.oi
.legacy_snaps
.empty());
8576 // it's already in the snapset
8577 assert(obc
->ssc
->snapset
.clone_snaps
.count(soid
.snap
));
8579 assert(obc
->ssc
->snapset
.clone_size
.count(soid
.snap
));
8580 assert(obc
->ssc
->snapset
.clone_size
[soid
.snap
] ==
8581 results
->object_size
);
8582 assert(obc
->ssc
->snapset
.clone_overlap
.count(soid
.snap
));
8584 tctx
->delta_stats
.num_bytes
+= obc
->ssc
->snapset
.get_clone_bytes(soid
.snap
);
8586 tctx
->delta_stats
.num_bytes
+= results
->object_size
;
8590 if (results
->mirror_snapset
) {
8591 assert(tctx
->new_obs
.oi
.soid
.snap
== CEPH_NOSNAP
);
8592 tctx
->new_snapset
.from_snap_set(
8594 get_osdmap()->require_osd_release
< CEPH_RELEASE_LUMINOUS
);
8596 tctx
->new_snapset
.head_exists
= true;
8597 dout(20) << __func__
<< " new_snapset " << tctx
->new_snapset
<< dendl
;
8599 // take RWWRITE lock for duration of our local write. ignore starvation.
8600 if (!tctx
->lock_manager
.take_write_lock(
8603 assert(0 == "problem!");
8605 dout(20) << __func__
<< " took lock on obc, " << obc
->rwstate
<< dendl
;
8607 finish_ctx(tctx
.get(), pg_log_entry_t::PROMOTE
);
8609 simple_opc_submit(std::move(tctx
));
8611 osd
->logger
->inc(l_osd_tier_promote
);
8614 agent_state
->is_idle())
8615 agent_choose_mode();
8618 void PrimaryLogPG::cancel_copy(CopyOpRef cop
, bool requeue
)
8620 dout(10) << __func__
<< " " << cop
->obc
->obs
.oi
.soid
8621 << " from " << cop
->src
<< " " << cop
->oloc
8622 << " v" << cop
->results
.user_version
<< dendl
;
8624 // cancel objecter op, if we can
8625 if (cop
->objecter_tid
) {
8626 osd
->objecter
->op_cancel(cop
->objecter_tid
, -ECANCELED
);
8627 cop
->objecter_tid
= 0;
8628 if (cop
->objecter_tid2
) {
8629 osd
->objecter
->op_cancel(cop
->objecter_tid2
, -ECANCELED
);
8630 cop
->objecter_tid2
= 0;
8634 copy_ops
.erase(cop
->obc
->obs
.oi
.soid
);
8635 cop
->obc
->stop_block();
8637 kick_object_context_blocked(cop
->obc
);
8638 cop
->results
.should_requeue
= requeue
;
8639 CopyCallbackResults
result(-ECANCELED
, &cop
->results
);
8640 cop
->cb
->complete(result
);
8642 // There may still be an objecter callback referencing this copy op.
8643 // That callback will not need the obc since it's been canceled, and
8644 // we need the obc reference to go away prior to flush.
8645 cop
->obc
= ObjectContextRef();
8648 void PrimaryLogPG::cancel_copy_ops(bool requeue
)
8650 dout(10) << __func__
<< dendl
;
8651 map
<hobject_t
,CopyOpRef
>::iterator p
= copy_ops
.begin();
8652 while (p
!= copy_ops
.end()) {
8653 // requeue this op? can I queue up all of them?
8654 cancel_copy((p
++)->second
, requeue
);
8659 // ========================================================================
8662 // Flush a dirty object in the cache tier by writing it back to the
8663 // base tier. The sequence looks like:
8665 // * send a copy-from operation to the base tier to copy the current
8666 // version of the object
8667 // * base tier will pull the object via (perhaps multiple) copy-get(s)
8668 // * on completion, we check if the object has been modified. if so,
8669 // just reply with -EAGAIN.
8670 // * try to take a write lock so we can clear the dirty flag. if this
8671 // fails, wait and retry
8672 // * start a repop that clears the bit.
8674 // If we have to wait, we will retry by coming back through the
8675 // start_flush method. We check if a flush is already in progress
8676 // and, if so, try to finish it by rechecking the version and trying
8677 // to clear the dirty bit.
8679 // In order for the cache-flush (a write op) to not block the copy-get
8680 // from reading the object, the client *must* set the SKIPRWLOCKS
8683 // NOTE: normally writes are strictly ordered for the client, but
8684 // flushes are special in that they can be reordered with respect to
8685 // other writes. In particular, we can't have a flush request block
8686 // an update to the cache pool object!
8688 struct C_Flush
: public Context
{
8691 epoch_t last_peering_reset
;
8694 C_Flush(PrimaryLogPG
*p
, hobject_t o
, epoch_t lpr
)
8695 : pg(p
), oid(o
), last_peering_reset(lpr
),
8696 tid(0), start(ceph_clock_now())
8698 void finish(int r
) override
{
8699 if (r
== -ECANCELED
)
8702 if (last_peering_reset
== pg
->get_last_peering_reset()) {
8703 pg
->finish_flush(oid
, tid
, r
);
8704 pg
->osd
->logger
->tinc(l_osd_tier_flush_lat
, ceph_clock_now() - start
);
8710 int PrimaryLogPG::start_flush(
8711 OpRequestRef op
, ObjectContextRef obc
,
8712 bool blocking
, hobject_t
*pmissing
,
8713 boost::optional
<std::function
<void()>> &&on_flush
)
8715 const object_info_t
& oi
= obc
->obs
.oi
;
8716 const hobject_t
& soid
= oi
.soid
;
8717 dout(10) << __func__
<< " " << soid
8718 << " v" << oi
.version
8719 << " uv" << oi
.user_version
8720 << " " << (blocking
? "blocking" : "non-blocking/best-effort")
8723 // get a filtered snapset, need to remove removed snaps
8724 SnapSet snapset
= obc
->ssc
->snapset
.get_filtered(pool
.info
);
8726 // verify there are no (older) check for dirty clones
8728 dout(20) << " snapset " << snapset
<< dendl
;
8729 vector
<snapid_t
>::reverse_iterator p
= snapset
.clones
.rbegin();
8730 while (p
!= snapset
.clones
.rend() && *p
>= soid
.snap
)
8732 if (p
!= snapset
.clones
.rend()) {
8733 hobject_t next
= soid
;
8735 assert(next
.snap
< soid
.snap
);
8736 if (pg_log
.get_missing().is_missing(next
)) {
8737 dout(10) << __func__
<< " missing clone is " << next
<< dendl
;
8742 ObjectContextRef older_obc
= get_object_context(next
, false);
8744 dout(20) << __func__
<< " next oldest clone is " << older_obc
->obs
.oi
8746 if (older_obc
->obs
.oi
.is_dirty()) {
8747 dout(10) << __func__
<< " next oldest clone is dirty: "
8748 << older_obc
->obs
.oi
<< dendl
;
8752 dout(20) << __func__
<< " next oldest clone " << next
8753 << " is not present; implicitly clean" << dendl
;
8756 dout(20) << __func__
<< " no older clones" << dendl
;
8763 map
<hobject_t
,FlushOpRef
>::iterator p
= flush_ops
.find(soid
);
8764 if (p
!= flush_ops
.end()) {
8765 FlushOpRef fop
= p
->second
;
8766 if (fop
->op
== op
) {
8767 // we couldn't take the write lock on a cache-try-flush before;
8768 // now we are trying again for the lock.
8769 return try_flush_mark_clean(fop
);
8771 if (fop
->flushed_version
== obc
->obs
.oi
.user_version
&&
8772 (fop
->blocking
|| !blocking
)) {
8773 // nonblocking can join anything
8774 // blocking can only join a blocking flush
8775 dout(20) << __func__
<< " piggybacking on existing flush " << dendl
;
8777 fop
->dup_ops
.push_back(op
);
8778 return -EAGAIN
; // clean up this ctx; op will retry later
8781 // cancel current flush since it will fail anyway, or because we
8782 // are blocking and the existing flush is nonblocking.
8783 dout(20) << __func__
<< " canceling previous flush; it will fail" << dendl
;
8785 osd
->reply_op_error(fop
->op
, -EBUSY
);
8786 while (!fop
->dup_ops
.empty()) {
8787 osd
->reply_op_error(fop
->dup_ops
.front(), -EBUSY
);
8788 fop
->dup_ops
.pop_front();
8790 cancel_flush(fop
, false);
8794 * In general, we need to send a delete and a copyfrom.
8795 * Consider snapc 10:[10, 9, 8, 4, 3, 2]:[10(10, 9), 4(4,3,2)]
8796 * where 4 is marked as clean. To flush 10, we have to:
8797 * 1) delete 4:[4,3,2] -- Logically, the object does not exist after 4
8798 * 2) copyfrom 8:[8,4,3,2] -- flush object after snap 8
8800 * There is a complicating case. Supposed there had been a clone 7
8801 * for snaps [7, 6] which has been trimmed since they no longer exist.
8802 * In the base pool, we'd have 5:[4,3,2]:[4(4,3,2)]+head. When we submit
8803 * the delete, the snap will be promoted to 5, and the head will become
8804 * a snapdir. When the copy-from goes through, we'll end up with
8805 * 8:[8,4,3,2]:[4(4,3,2)]+head.
8807 * Another complication is the case where there is an interval change
8808 * after doing the delete and the flush but before marking the object
8809 * clean. We'll happily delete head and then recreate it at the same
8810 * sequence number, which works out ok.
8813 SnapContext snapc
, dsnapc
;
8814 if (snapset
.seq
!= 0) {
8815 if (soid
.snap
== CEPH_NOSNAP
) {
8816 snapc
.seq
= snapset
.seq
;
8817 snapc
.snaps
= snapset
.snaps
;
8819 snapid_t min_included_snap
;
8820 if (snapset
.is_legacy()) {
8821 min_included_snap
= oi
.legacy_snaps
.back();
8823 auto p
= snapset
.clone_snaps
.find(soid
.snap
);
8824 assert(p
!= snapset
.clone_snaps
.end());
8825 min_included_snap
= p
->second
.back();
8827 snapc
= snapset
.get_ssc_as_of(min_included_snap
- 1);
8830 snapid_t prev_snapc
= 0;
8831 for (vector
<snapid_t
>::reverse_iterator citer
= snapset
.clones
.rbegin();
8832 citer
!= snapset
.clones
.rend();
8834 if (*citer
< soid
.snap
) {
8835 prev_snapc
= *citer
;
8840 dsnapc
= snapset
.get_ssc_as_of(prev_snapc
);
8843 object_locator_t
base_oloc(soid
);
8844 base_oloc
.pool
= pool
.info
.tier_of
;
8846 if (dsnapc
.seq
< snapc
.seq
) {
8849 osd
->objecter
->mutate(
8854 ceph::real_clock::from_ceph_timespec(oi
.mtime
),
8855 (CEPH_OSD_FLAG_IGNORE_OVERLAY
|
8856 CEPH_OSD_FLAG_ENFORCE_SNAPC
),
8857 NULL
/* no callback, we'll rely on the ordering w.r.t the next op */);
8860 FlushOpRef
fop(std::make_shared
<FlushOp
>());
8862 fop
->flushed_version
= oi
.user_version
;
8863 fop
->blocking
= blocking
;
8864 fop
->on_flush
= std::move(on_flush
);
8868 if (oi
.is_whiteout()) {
8869 fop
->removal
= true;
8872 object_locator_t
oloc(soid
);
8873 o
.copy_from(soid
.oid
.name
, soid
.snap
, oloc
, oi
.user_version
,
8874 CEPH_OSD_COPY_FROM_FLAG_FLUSH
|
8875 CEPH_OSD_COPY_FROM_FLAG_IGNORE_OVERLAY
|
8876 CEPH_OSD_COPY_FROM_FLAG_IGNORE_CACHE
|
8877 CEPH_OSD_COPY_FROM_FLAG_MAP_SNAP_CLONE
,
8878 LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL
|LIBRADOS_OP_FLAG_FADVISE_NOCACHE
);
8880 //mean the base tier don't cache data after this
8881 if (agent_state
&& agent_state
->evict_mode
!= TierAgentState::EVICT_MODE_FULL
)
8882 o
.set_last_op_flags(LIBRADOS_OP_FLAG_FADVISE_DONTNEED
);
8884 C_Flush
*fin
= new C_Flush(this, soid
, get_last_peering_reset());
8886 ceph_tid_t tid
= osd
->objecter
->mutate(
8887 soid
.oid
, base_oloc
, o
, snapc
,
8888 ceph::real_clock::from_ceph_timespec(oi
.mtime
),
8889 CEPH_OSD_FLAG_IGNORE_OVERLAY
| CEPH_OSD_FLAG_ENFORCE_SNAPC
,
8890 new C_OnFinisher(fin
,
8891 &osd
->objecter_finisher
));
8892 /* we're under the pg lock and fin->finish() is grabbing that */
8894 fop
->objecter_tid
= tid
;
8896 flush_ops
[soid
] = fop
;
8897 info
.stats
.stats
.sum
.num_flush
++;
8898 info
.stats
.stats
.sum
.num_flush_kb
+= SHIFT_ROUND_UP(oi
.size
, 10);
8899 return -EINPROGRESS
;
8902 void PrimaryLogPG::finish_flush(hobject_t oid
, ceph_tid_t tid
, int r
)
8904 dout(10) << __func__
<< " " << oid
<< " tid " << tid
8905 << " " << cpp_strerror(r
) << dendl
;
8906 map
<hobject_t
,FlushOpRef
>::iterator p
= flush_ops
.find(oid
);
8907 if (p
== flush_ops
.end()) {
8908 dout(10) << __func__
<< " no flush_op found" << dendl
;
8911 FlushOpRef fop
= p
->second
;
8912 if (tid
!= fop
->objecter_tid
) {
8913 dout(10) << __func__
<< " tid " << tid
<< " != fop " << fop
8914 << " tid " << fop
->objecter_tid
<< dendl
;
8917 ObjectContextRef obc
= fop
->obc
;
8918 fop
->objecter_tid
= 0;
8920 if (r
< 0 && !(r
== -ENOENT
&& fop
->removal
)) {
8922 osd
->reply_op_error(fop
->op
, -EBUSY
);
8923 if (fop
->blocking
) {
8925 kick_object_context_blocked(obc
);
8928 if (!fop
->dup_ops
.empty()) {
8929 dout(20) << __func__
<< " requeueing dups" << dendl
;
8930 requeue_ops(fop
->dup_ops
);
8932 if (fop
->on_flush
) {
8933 (*(fop
->on_flush
))();
8934 fop
->on_flush
= boost::none
;
8936 flush_ops
.erase(oid
);
8940 r
= try_flush_mark_clean(fop
);
8941 if (r
== -EBUSY
&& fop
->op
) {
8942 osd
->reply_op_error(fop
->op
, r
);
8946 int PrimaryLogPG::try_flush_mark_clean(FlushOpRef fop
)
8948 ObjectContextRef obc
= fop
->obc
;
8949 const hobject_t
& oid
= obc
->obs
.oi
.soid
;
8951 if (fop
->blocking
) {
8953 kick_object_context_blocked(obc
);
8956 if (fop
->flushed_version
!= obc
->obs
.oi
.user_version
||
8958 if (obc
->obs
.exists
)
8959 dout(10) << __func__
<< " flushed_version " << fop
->flushed_version
8960 << " != current " << obc
->obs
.oi
.user_version
8963 dout(10) << __func__
<< " object no longer exists" << dendl
;
8965 if (!fop
->dup_ops
.empty()) {
8966 dout(20) << __func__
<< " requeueing dups" << dendl
;
8967 requeue_ops(fop
->dup_ops
);
8969 if (fop
->on_flush
) {
8970 (*(fop
->on_flush
))();
8971 fop
->on_flush
= boost::none
;
8973 flush_ops
.erase(oid
);
8975 osd
->logger
->inc(l_osd_tier_flush_fail
);
8977 osd
->logger
->inc(l_osd_tier_try_flush_fail
);
8981 if (!fop
->blocking
&&
8982 scrubber
.write_blocked_by_scrub(oid
)) {
8984 dout(10) << __func__
<< " blocked by scrub" << dendl
;
8985 requeue_op(fop
->op
);
8986 requeue_ops(fop
->dup_ops
);
8987 return -EAGAIN
; // will retry
8989 osd
->logger
->inc(l_osd_tier_try_flush_fail
);
8990 cancel_flush(fop
, false);
8995 // successfully flushed, can we evict this object?
8996 if (!fop
->op
&& agent_state
->evict_mode
!= TierAgentState::EVICT_MODE_IDLE
&&
8997 agent_maybe_evict(obc
, true)) {
8998 osd
->logger
->inc(l_osd_tier_clean
);
8999 if (fop
->on_flush
) {
9000 (*(fop
->on_flush
))();
9001 fop
->on_flush
= boost::none
;
9003 flush_ops
.erase(oid
);
9007 dout(10) << __func__
<< " clearing DIRTY flag for " << oid
<< dendl
;
9008 OpContextUPtr ctx
= simple_opc_create(fop
->obc
);
9010 // successfully flushed; can we clear the dirty bit?
9011 // try to take the lock manually, since we don't
9013 if (ctx
->lock_manager
.get_lock_type(
9014 ObjectContext::RWState::RWWRITE
,
9018 dout(20) << __func__
<< " took write lock" << dendl
;
9019 } else if (fop
->op
) {
9020 dout(10) << __func__
<< " waiting on write lock" << dendl
;
9021 close_op_ctx(ctx
.release());
9022 requeue_op(fop
->op
);
9023 requeue_ops(fop
->dup_ops
);
9024 return -EAGAIN
; // will retry
9026 dout(10) << __func__
<< " failed write lock, no op; failing" << dendl
;
9027 close_op_ctx(ctx
.release());
9028 osd
->logger
->inc(l_osd_tier_try_flush_fail
);
9029 cancel_flush(fop
, false);
9033 if (fop
->on_flush
) {
9034 ctx
->register_on_finish(*(fop
->on_flush
));
9035 fop
->on_flush
= boost::none
;
9038 ctx
->at_version
= get_next_version();
9040 ctx
->new_obs
= obc
->obs
;
9041 ctx
->new_obs
.oi
.clear_flag(object_info_t::FLAG_DIRTY
);
9042 --ctx
->delta_stats
.num_objects_dirty
;
9044 finish_ctx(ctx
.get(), pg_log_entry_t::CLEAN
);
9046 osd
->logger
->inc(l_osd_tier_clean
);
9048 if (!fop
->dup_ops
.empty() || fop
->op
) {
9049 dout(20) << __func__
<< " requeueing for " << ctx
->at_version
<< dendl
;
9050 list
<OpRequestRef
> ls
;
9052 ls
.push_back(fop
->op
);
9053 ls
.splice(ls
.end(), fop
->dup_ops
);
9057 simple_opc_submit(std::move(ctx
));
9059 flush_ops
.erase(oid
);
9062 osd
->logger
->inc(l_osd_tier_flush
);
9064 osd
->logger
->inc(l_osd_tier_try_flush
);
9066 return -EINPROGRESS
;
9069 void PrimaryLogPG::cancel_flush(FlushOpRef fop
, bool requeue
)
9071 dout(10) << __func__
<< " " << fop
->obc
->obs
.oi
.soid
<< " tid "
9072 << fop
->objecter_tid
<< dendl
;
9073 if (fop
->objecter_tid
) {
9074 osd
->objecter
->op_cancel(fop
->objecter_tid
, -ECANCELED
);
9075 fop
->objecter_tid
= 0;
9077 if (fop
->blocking
) {
9078 fop
->obc
->stop_block();
9079 kick_object_context_blocked(fop
->obc
);
9083 requeue_op(fop
->op
);
9084 requeue_ops(fop
->dup_ops
);
9086 if (fop
->on_flush
) {
9087 (*(fop
->on_flush
))();
9088 fop
->on_flush
= boost::none
;
9090 flush_ops
.erase(fop
->obc
->obs
.oi
.soid
);
9093 void PrimaryLogPG::cancel_flush_ops(bool requeue
)
9095 dout(10) << __func__
<< dendl
;
9096 map
<hobject_t
,FlushOpRef
>::iterator p
= flush_ops
.begin();
9097 while (p
!= flush_ops
.end()) {
9098 cancel_flush((p
++)->second
, requeue
);
9102 bool PrimaryLogPG::is_present_clone(hobject_t coid
)
9104 if (!pool
.info
.allow_incomplete_clones())
9106 if (is_missing_object(coid
))
9108 ObjectContextRef obc
= get_object_context(coid
, false);
9109 return obc
&& obc
->obs
.exists
;
9112 // ========================================================================
9115 class C_OSD_RepopApplied
: public Context
{
9117 boost::intrusive_ptr
<PrimaryLogPG::RepGather
> repop
;
9119 C_OSD_RepopApplied(PrimaryLogPG
*pg
, PrimaryLogPG::RepGather
*repop
)
9120 : pg(pg
), repop(repop
) {}
9121 void finish(int) override
{
9122 pg
->repop_all_applied(repop
.get());
9127 void PrimaryLogPG::repop_all_applied(RepGather
*repop
)
9129 dout(10) << __func__
<< ": repop tid " << repop
->rep_tid
<< " all applied "
9131 assert(!repop
->applies_with_commit
);
9132 repop
->all_applied
= true;
9133 if (!repop
->rep_aborted
) {
9138 class C_OSD_RepopCommit
: public Context
{
9140 boost::intrusive_ptr
<PrimaryLogPG::RepGather
> repop
;
9142 C_OSD_RepopCommit(PrimaryLogPG
*pg
, PrimaryLogPG::RepGather
*repop
)
9143 : pg(pg
), repop(repop
) {}
9144 void finish(int) override
{
9145 pg
->repop_all_committed(repop
.get());
9149 void PrimaryLogPG::repop_all_committed(RepGather
*repop
)
9151 dout(10) << __func__
<< ": repop tid " << repop
->rep_tid
<< " all committed "
9153 repop
->all_committed
= true;
9154 if (repop
->applies_with_commit
) {
9155 assert(!repop
->all_applied
);
9156 repop
->all_applied
= true;
9159 if (!repop
->rep_aborted
) {
9160 if (repop
->v
!= eversion_t()) {
9161 last_update_ondisk
= repop
->v
;
9162 last_complete_ondisk
= repop
->pg_local_last_complete
;
9168 void PrimaryLogPG::op_applied(const eversion_t
&applied_version
)
9170 dout(10) << "op_applied version " << applied_version
<< dendl
;
9171 if (applied_version
== eversion_t())
9173 assert(applied_version
> last_update_applied
);
9174 assert(applied_version
<= info
.last_update
);
9175 last_update_applied
= applied_version
;
9177 if (scrubber
.active
) {
9178 if (last_update_applied
>= scrubber
.subset_last_update
) {
9179 if (ops_blocked_by_scrub()) {
9180 requeue_scrub(true);
9182 requeue_scrub(false);
9187 assert(scrubber
.start
== scrubber
.end
);
9190 if (scrubber
.active_rep_scrub
) {
9191 if (last_update_applied
>= static_cast<const MOSDRepScrub
*>(
9192 scrubber
.active_rep_scrub
->get_req())->scrub_to
) {
9195 PGQueueable(scrubber
.active_rep_scrub
, get_osdmap()->get_epoch()));
9196 scrubber
.active_rep_scrub
= OpRequestRef();
9202 void PrimaryLogPG::eval_repop(RepGather
*repop
)
9204 const MOSDOp
*m
= NULL
;
9206 m
= static_cast<const MOSDOp
*>(repop
->op
->get_req());
9209 dout(10) << "eval_repop " << *repop
9210 << (repop
->rep_done
? " DONE" : "")
9213 dout(10) << "eval_repop " << *repop
<< " (no op)"
9214 << (repop
->rep_done
? " DONE" : "")
9217 if (repop
->rep_done
)
9221 if (repop
->all_committed
) {
9222 dout(10) << " commit: " << *repop
<< dendl
;
9223 for (auto p
= repop
->on_committed
.begin();
9224 p
!= repop
->on_committed
.end();
9225 repop
->on_committed
.erase(p
++)) {
9228 // send dup commits, in order
9229 if (waiting_for_ondisk
.count(repop
->v
)) {
9230 assert(waiting_for_ondisk
.begin()->first
== repop
->v
);
9231 for (list
<pair
<OpRequestRef
, version_t
> >::iterator i
=
9232 waiting_for_ondisk
[repop
->v
].begin();
9233 i
!= waiting_for_ondisk
[repop
->v
].end();
9235 osd
->reply_op_error(i
->first
, repop
->r
, repop
->v
,
9238 waiting_for_ondisk
.erase(repop
->v
);
9243 if (repop
->all_applied
) {
9244 if (repop
->applies_with_commit
) {
9245 assert(repop
->on_applied
.empty());
9247 dout(10) << " applied: " << *repop
<< " " << dendl
;
9248 for (auto p
= repop
->on_applied
.begin();
9249 p
!= repop
->on_applied
.end();
9250 repop
->on_applied
.erase(p
++)) {
9256 if (repop
->all_applied
&& repop
->all_committed
) {
9257 repop
->rep_done
= true;
9259 publish_stats_to_osd();
9260 calc_min_last_complete_ondisk();
9262 dout(10) << " removing " << *repop
<< dendl
;
9263 assert(!repop_queue
.empty());
9264 dout(20) << " q front is " << *repop_queue
.front() << dendl
;
9265 if (repop_queue
.front() != repop
) {
9266 if (!repop
->applies_with_commit
) {
9267 dout(0) << " removing " << *repop
<< dendl
;
9268 dout(0) << " q front is " << *repop_queue
.front() << dendl
;
9269 assert(repop_queue
.front() == repop
);
9272 RepGather
*to_remove
= nullptr;
9273 while (!repop_queue
.empty() &&
9274 (to_remove
= repop_queue
.front())->rep_done
) {
9275 repop_queue
.pop_front();
9276 for (auto p
= to_remove
->on_success
.begin();
9277 p
!= to_remove
->on_success
.end();
9278 to_remove
->on_success
.erase(p
++)) {
9281 remove_repop(to_remove
);
9287 void PrimaryLogPG::issue_repop(RepGather
*repop
, OpContext
*ctx
)
9290 const hobject_t
& soid
= ctx
->obs
->oi
.soid
;
9291 dout(7) << "issue_repop rep_tid " << repop
->rep_tid
9295 repop
->v
= ctx
->at_version
;
9296 if (ctx
->at_version
> eversion_t()) {
9297 for (set
<pg_shard_t
>::iterator i
= actingbackfill
.begin();
9298 i
!= actingbackfill
.end();
9300 if (*i
== get_primary()) continue;
9301 pg_info_t
&pinfo
= peer_info
[*i
];
9302 // keep peer_info up to date
9303 if (pinfo
.last_complete
== pinfo
.last_update
)
9304 pinfo
.last_complete
= ctx
->at_version
;
9305 pinfo
.last_update
= ctx
->at_version
;
9309 ctx
->obc
->ondisk_write_lock();
9311 bool unlock_snapset_obc
= false;
9312 ctx
->op_t
->add_obc(ctx
->obc
);
9313 if (ctx
->clone_obc
) {
9314 ctx
->clone_obc
->ondisk_write_lock();
9315 ctx
->op_t
->add_obc(ctx
->clone_obc
);
9317 if (ctx
->snapset_obc
&& ctx
->snapset_obc
->obs
.oi
.soid
!=
9318 ctx
->obc
->obs
.oi
.soid
) {
9319 ctx
->snapset_obc
->ondisk_write_lock();
9320 unlock_snapset_obc
= true;
9321 ctx
->op_t
->add_obc(ctx
->snapset_obc
);
9324 Context
*on_all_commit
= new C_OSD_RepopCommit(this, repop
);
9325 Context
*on_all_applied
= new C_OSD_RepopApplied(this, repop
);
9326 Context
*onapplied_sync
= new C_OSD_OndiskWriteUnlock(
9329 unlock_snapset_obc
? ctx
->snapset_obc
: ObjectContextRef());
9330 if (!(ctx
->log
.empty())) {
9331 assert(ctx
->at_version
>= projected_last_update
);
9332 projected_last_update
= ctx
->at_version
;
9334 for (auto &&entry
: ctx
->log
) {
9335 projected_log
.add(entry
);
9337 pgbackend
->submit_transaction(
9341 std::move(ctx
->op_t
),
9343 min_last_complete_ondisk
,
9345 ctx
->updated_hset_history
,
9354 PrimaryLogPG::RepGather
*PrimaryLogPG::new_repop(
9355 OpContext
*ctx
, ObjectContextRef obc
,
9359 dout(10) << "new_repop rep_tid " << rep_tid
<< " on " << *ctx
->op
->get_req() << dendl
;
9361 dout(10) << "new_repop rep_tid " << rep_tid
<< " (no op)" << dendl
;
9363 RepGather
*repop
= new RepGather(
9364 ctx
, rep_tid
, info
.last_complete
, false);
9366 repop
->start
= ceph_clock_now();
9368 repop_queue
.push_back(&repop
->queue_item
);
9371 osd
->logger
->inc(l_osd_op_wip
);
9373 dout(10) << __func__
<< ": " << *repop
<< dendl
;
9377 boost::intrusive_ptr
<PrimaryLogPG::RepGather
> PrimaryLogPG::new_repop(
9380 ObcLockManager
&&manager
,
9382 boost::optional
<std::function
<void(void)> > &&on_complete
)
9384 RepGather
*repop
= new RepGather(
9387 std::move(on_complete
),
9394 repop
->start
= ceph_clock_now();
9396 repop_queue
.push_back(&repop
->queue_item
);
9398 osd
->logger
->inc(l_osd_op_wip
);
9400 dout(10) << __func__
<< ": " << *repop
<< dendl
;
9401 return boost::intrusive_ptr
<RepGather
>(repop
);
9404 void PrimaryLogPG::remove_repop(RepGather
*repop
)
9406 dout(20) << __func__
<< " " << *repop
<< dendl
;
9408 for (auto p
= repop
->on_finish
.begin();
9409 p
!= repop
->on_finish
.end();
9410 repop
->on_finish
.erase(p
++)) {
9414 release_object_locks(
9415 repop
->lock_manager
);
9418 osd
->logger
->dec(l_osd_op_wip
);
9421 PrimaryLogPG::OpContextUPtr
PrimaryLogPG::simple_opc_create(ObjectContextRef obc
)
9423 dout(20) << __func__
<< " " << obc
->obs
.oi
.soid
<< dendl
;
9424 ceph_tid_t rep_tid
= osd
->get_tid();
9425 osd_reqid_t
reqid(osd
->get_cluster_msgr_name(), 0, rep_tid
);
9426 OpContextUPtr
ctx(new OpContext(OpRequestRef(), reqid
, nullptr, obc
, this));
9427 ctx
->op_t
.reset(new PGTransaction());
9428 ctx
->mtime
= ceph_clock_now();
9432 void PrimaryLogPG::simple_opc_submit(OpContextUPtr ctx
)
9434 RepGather
*repop
= new_repop(ctx
.get(), ctx
->obc
, ctx
->reqid
.tid
);
9435 dout(20) << __func__
<< " " << repop
<< dendl
;
9436 issue_repop(repop
, ctx
.get());
9443 void PrimaryLogPG::submit_log_entries(
9444 const mempool::osd_pglog::list
<pg_log_entry_t
> &entries
,
9445 ObcLockManager
&&manager
,
9446 boost::optional
<std::function
<void(void)> > &&_on_complete
,
9450 dout(10) << __func__
<< " " << entries
<< dendl
;
9451 assert(is_primary());
9454 if (!entries
.empty()) {
9455 assert(entries
.rbegin()->version
>= projected_last_update
);
9456 version
= projected_last_update
= entries
.rbegin()->version
;
9459 boost::intrusive_ptr
<RepGather
> repop
;
9460 boost::optional
<std::function
<void(void)> > on_complete
;
9461 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_JEWEL
) {
9467 std::move(_on_complete
));
9469 on_complete
= std::move(_on_complete
);
9472 pgbackend
->call_write_ordered(
9473 [this, entries
, repop
, on_complete
]() {
9474 ObjectStore::Transaction t
;
9475 eversion_t old_last_update
= info
.last_update
;
9476 merge_new_log_entries(entries
, t
);
9479 set
<pg_shard_t
> waiting_on
;
9480 for (set
<pg_shard_t
>::const_iterator i
= actingbackfill
.begin();
9481 i
!= actingbackfill
.end();
9483 pg_shard_t
peer(*i
);
9484 if (peer
== pg_whoami
) continue;
9485 assert(peer_missing
.count(peer
));
9486 assert(peer_info
.count(peer
));
9487 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_JEWEL
) {
9489 MOSDPGUpdateLogMissing
*m
= new MOSDPGUpdateLogMissing(
9491 spg_t(info
.pgid
.pgid
, i
->shard
),
9493 get_osdmap()->get_epoch(),
9496 osd
->send_message_osd_cluster(
9497 peer
.osd
, m
, get_osdmap()->get_epoch());
9498 waiting_on
.insert(peer
);
9500 MOSDPGLog
*m
= new MOSDPGLog(
9501 peer
.shard
, pg_whoami
.shard
,
9502 info
.last_update
.epoch
,
9504 m
->log
.log
= entries
;
9505 m
->log
.tail
= old_last_update
;
9506 m
->log
.head
= info
.last_update
;
9507 osd
->send_message_osd_cluster(
9508 peer
.osd
, m
, get_osdmap()->get_epoch());
9511 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_JEWEL
) {
9512 ceph_tid_t rep_tid
= repop
->rep_tid
;
9513 waiting_on
.insert(pg_whoami
);
9514 log_entry_update_waiting_on
.insert(
9517 LogUpdateCtx
{std::move(repop
), std::move(waiting_on
)}
9519 struct OnComplete
: public Context
{
9527 : pg(pg
), rep_tid(rep_tid
), epoch(epoch
) {}
9528 void finish(int) override
{
9530 if (!pg
->pg_has_reset_since(epoch
)) {
9531 auto it
= pg
->log_entry_update_waiting_on
.find(rep_tid
);
9532 assert(it
!= pg
->log_entry_update_waiting_on
.end());
9533 auto it2
= it
->second
.waiting_on
.find(pg
->pg_whoami
);
9534 assert(it2
!= it
->second
.waiting_on
.end());
9535 it
->second
.waiting_on
.erase(it2
);
9536 if (it
->second
.waiting_on
.empty()) {
9537 pg
->repop_all_committed(it
->second
.repop
.get());
9538 pg
->log_entry_update_waiting_on
.erase(it
);
9544 t
.register_on_commit(
9545 new OnComplete
{this, rep_tid
, get_osdmap()->get_epoch()});
9548 struct OnComplete
: public Context
{
9550 std::function
<void(void)> on_complete
;
9554 const std::function
<void(void)> &on_complete
,
9557 on_complete(std::move(on_complete
)),
9559 void finish(int) override
{
9561 if (!pg
->pg_has_reset_since(epoch
))
9566 t
.register_on_complete(
9568 this, *on_complete
, get_osdmap()->get_epoch()
9572 t
.register_on_applied(
9573 new C_OSD_OnApplied
{this, get_osdmap()->get_epoch(), info
.last_update
});
9574 int r
= osd
->store
->queue_transaction(osr
.get(), std::move(t
), NULL
);
9579 void PrimaryLogPG::cancel_log_updates()
9581 // get rid of all the LogUpdateCtx so their references to repops are
9583 log_entry_update_waiting_on
.clear();
9586 // -------------------------------------------------------
9588 void PrimaryLogPG::get_watchers(list
<obj_watch_item_t
> &pg_watchers
)
9590 pair
<hobject_t
, ObjectContextRef
> i
;
9591 while (object_contexts
.get_next(i
.first
, &i
)) {
9592 ObjectContextRef
obc(i
.second
);
9593 get_obc_watchers(obc
, pg_watchers
);
9597 void PrimaryLogPG::get_obc_watchers(ObjectContextRef obc
, list
<obj_watch_item_t
> &pg_watchers
)
9599 for (map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator j
=
9600 obc
->watchers
.begin();
9601 j
!= obc
->watchers
.end();
9603 obj_watch_item_t owi
;
9605 owi
.obj
= obc
->obs
.oi
.soid
;
9606 owi
.wi
.addr
= j
->second
->get_peer_addr();
9607 owi
.wi
.name
= j
->second
->get_entity();
9608 owi
.wi
.cookie
= j
->second
->get_cookie();
9609 owi
.wi
.timeout_seconds
= j
->second
->get_timeout();
9611 dout(30) << "watch: Found oid=" << owi
.obj
<< " addr=" << owi
.wi
.addr
9612 << " name=" << owi
.wi
.name
<< " cookie=" << owi
.wi
.cookie
<< dendl
;
9614 pg_watchers
.push_back(owi
);
9618 void PrimaryLogPG::check_blacklisted_watchers()
9620 dout(20) << "PrimaryLogPG::check_blacklisted_watchers for pg " << get_pgid() << dendl
;
9621 pair
<hobject_t
, ObjectContextRef
> i
;
9622 while (object_contexts
.get_next(i
.first
, &i
))
9623 check_blacklisted_obc_watchers(i
.second
);
9626 void PrimaryLogPG::check_blacklisted_obc_watchers(ObjectContextRef obc
)
9628 dout(20) << "PrimaryLogPG::check_blacklisted_obc_watchers for obc " << obc
->obs
.oi
.soid
<< dendl
;
9629 for (map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator k
=
9630 obc
->watchers
.begin();
9631 k
!= obc
->watchers
.end();
9633 //Advance iterator now so handle_watch_timeout() can erase element
9634 map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator j
= k
++;
9635 dout(30) << "watch: Found " << j
->second
->get_entity() << " cookie " << j
->second
->get_cookie() << dendl
;
9636 entity_addr_t ea
= j
->second
->get_peer_addr();
9637 dout(30) << "watch: Check entity_addr_t " << ea
<< dendl
;
9638 if (get_osdmap()->is_blacklisted(ea
)) {
9639 dout(10) << "watch: Found blacklisted watcher for " << ea
<< dendl
;
9640 assert(j
->second
->get_pg() == this);
9641 j
->second
->unregister_cb();
9642 handle_watch_timeout(j
->second
);
9647 void PrimaryLogPG::populate_obc_watchers(ObjectContextRef obc
)
9649 assert(is_active());
9650 assert((recovering
.count(obc
->obs
.oi
.soid
) ||
9651 !is_missing_object(obc
->obs
.oi
.soid
)) ||
9652 (pg_log
.get_log().objects
.count(obc
->obs
.oi
.soid
) && // or this is a revert... see recover_primary()
9653 pg_log
.get_log().objects
.find(obc
->obs
.oi
.soid
)->second
->op
==
9654 pg_log_entry_t::LOST_REVERT
&&
9655 pg_log
.get_log().objects
.find(obc
->obs
.oi
.soid
)->second
->reverting_to
==
9656 obc
->obs
.oi
.version
));
9658 dout(10) << "populate_obc_watchers " << obc
->obs
.oi
.soid
<< dendl
;
9659 assert(obc
->watchers
.empty());
9660 // populate unconnected_watchers
9661 for (map
<pair
<uint64_t, entity_name_t
>, watch_info_t
>::iterator p
=
9662 obc
->obs
.oi
.watchers
.begin();
9663 p
!= obc
->obs
.oi
.watchers
.end();
9665 utime_t expire
= info
.stats
.last_became_active
;
9666 expire
+= p
->second
.timeout_seconds
;
9667 dout(10) << " unconnected watcher " << p
->first
<< " will expire " << expire
<< dendl
;
9669 Watch::makeWatchRef(
9670 this, osd
, obc
, p
->second
.timeout_seconds
, p
->first
.first
,
9671 p
->first
.second
, p
->second
.addr
));
9672 watch
->disconnect();
9673 obc
->watchers
.insert(
9675 make_pair(p
->first
.first
, p
->first
.second
),
9678 // Look for watchers from blacklisted clients and drop
9679 check_blacklisted_obc_watchers(obc
);
9682 void PrimaryLogPG::handle_watch_timeout(WatchRef watch
)
9684 ObjectContextRef obc
= watch
->get_obc(); // handle_watch_timeout owns this ref
9685 dout(10) << "handle_watch_timeout obc " << obc
<< dendl
;
9688 dout(10) << "handle_watch_timeout not active, no-op" << dendl
;
9691 if (is_degraded_or_backfilling_object(obc
->obs
.oi
.soid
)) {
9692 callbacks_for_degraded_object
[obc
->obs
.oi
.soid
].push_back(
9693 watch
->get_delayed_cb()
9695 dout(10) << "handle_watch_timeout waiting for degraded on obj "
9701 if (scrubber
.write_blocked_by_scrub(obc
->obs
.oi
.soid
)) {
9702 dout(10) << "handle_watch_timeout waiting for scrub on obj "
9705 scrubber
.add_callback(
9706 watch
->get_delayed_cb() // This callback!
9711 OpContextUPtr ctx
= simple_opc_create(obc
);
9712 ctx
->at_version
= get_next_version();
9714 object_info_t
& oi
= ctx
->new_obs
.oi
;
9715 oi
.watchers
.erase(make_pair(watch
->get_cookie(),
9716 watch
->get_entity()));
9718 list
<watch_disconnect_t
> watch_disconnects
= {
9719 watch_disconnect_t(watch
->get_cookie(), watch
->get_entity(), true)
9721 ctx
->register_on_success(
9722 [this, obc
, watch_disconnects
]() {
9723 complete_disconnect_watches(obc
, watch_disconnects
);
9727 PGTransaction
*t
= ctx
->op_t
.get();
9728 ctx
->log
.push_back(pg_log_entry_t(pg_log_entry_t::MODIFY
, obc
->obs
.oi
.soid
,
9732 osd_reqid_t(), ctx
->mtime
, 0));
9734 oi
.prior_version
= obc
->obs
.oi
.version
;
9735 oi
.version
= ctx
->at_version
;
9737 ::encode(oi
, bl
, get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
9738 t
->setattr(obc
->obs
.oi
.soid
, OI_ATTR
, bl
);
9740 // apply new object state.
9741 ctx
->obc
->obs
= ctx
->new_obs
;
9743 // no ctx->delta_stats
9744 simple_opc_submit(std::move(ctx
));
9747 ObjectContextRef
PrimaryLogPG::create_object_context(const object_info_t
& oi
,
9748 SnapSetContext
*ssc
)
9750 ObjectContextRef
obc(object_contexts
.lookup_or_create(oi
.soid
));
9751 assert(obc
->destructor_callback
== NULL
);
9752 obc
->destructor_callback
= new C_PG_ObjectContext(this, obc
.get());
9754 obc
->obs
.exists
= false;
9757 register_snapset_context(ssc
);
9758 dout(10) << "create_object_context " << (void*)obc
.get() << " " << oi
.soid
<< " " << dendl
;
9760 populate_obc_watchers(obc
);
9764 ObjectContextRef
PrimaryLogPG::get_object_context(
9765 const hobject_t
& soid
,
9767 const map
<string
, bufferlist
> *attrs
)
9770 attrs
|| !pg_log
.get_missing().is_missing(soid
) ||
9771 // or this is a revert... see recover_primary()
9772 (pg_log
.get_log().objects
.count(soid
) &&
9773 pg_log
.get_log().objects
.find(soid
)->second
->op
==
9774 pg_log_entry_t::LOST_REVERT
));
9775 ObjectContextRef obc
= object_contexts
.lookup(soid
);
9776 osd
->logger
->inc(l_osd_object_ctx_cache_total
);
9778 osd
->logger
->inc(l_osd_object_ctx_cache_hit
);
9779 dout(10) << __func__
<< ": found obc in cache: " << obc
9782 dout(10) << __func__
<< ": obc NOT found in cache: " << soid
<< dendl
;
9786 assert(attrs
->count(OI_ATTR
));
9787 bv
= attrs
->find(OI_ATTR
)->second
;
9789 int r
= pgbackend
->objects_get_attr(soid
, OI_ATTR
, &bv
);
9792 dout(10) << __func__
<< ": no obc for soid "
9793 << soid
<< " and !can_create"
9795 return ObjectContextRef(); // -ENOENT!
9798 dout(10) << __func__
<< ": no obc for soid "
9799 << soid
<< " but can_create"
9802 object_info_t
oi(soid
);
9803 SnapSetContext
*ssc
= get_snapset_context(
9804 soid
, true, 0, false);
9806 obc
= create_object_context(oi
, ssc
);
9807 dout(10) << __func__
<< ": " << obc
<< " " << soid
9808 << " " << obc
->rwstate
9809 << " oi: " << obc
->obs
.oi
9810 << " ssc: " << obc
->ssc
9811 << " snapset: " << obc
->ssc
->snapset
<< dendl
;
9818 bufferlist::iterator bliter
= bv
.begin();
9819 ::decode(oi
, bliter
);
9821 dout(0) << __func__
<< ": obc corrupt: " << soid
<< dendl
;
9822 return ObjectContextRef(); // -ENOENT!
9825 assert(oi
.soid
.pool
== (int64_t)info
.pgid
.pool());
9827 obc
= object_contexts
.lookup_or_create(oi
.soid
);
9828 obc
->destructor_callback
= new C_PG_ObjectContext(this, obc
.get());
9830 obc
->obs
.exists
= true;
9832 obc
->ssc
= get_snapset_context(
9834 soid
.has_snapset() ? attrs
: 0);
9837 populate_obc_watchers(obc
);
9839 if (pool
.info
.require_rollback()) {
9841 obc
->attr_cache
= *attrs
;
9843 int r
= pgbackend
->objects_get_attrs(
9850 dout(10) << __func__
<< ": creating obc from disk: " << obc
9854 // XXX: Caller doesn't expect this
9855 if (obc
->ssc
== NULL
) {
9856 derr
<< __func__
<< ": obc->ssc not available, not returning context" << dendl
;
9857 return ObjectContextRef(); // -ENOENT!
9860 dout(10) << __func__
<< ": " << obc
<< " " << soid
9861 << " " << obc
->rwstate
9862 << " oi: " << obc
->obs
.oi
9863 << " exists: " << (int)obc
->obs
.exists
9864 << " ssc: " << obc
->ssc
9865 << " snapset: " << obc
->ssc
->snapset
<< dendl
;
9869 void PrimaryLogPG::context_registry_on_change()
9871 pair
<hobject_t
, ObjectContextRef
> i
;
9872 while (object_contexts
.get_next(i
.first
, &i
)) {
9873 ObjectContextRef
obc(i
.second
);
9875 for (map
<pair
<uint64_t, entity_name_t
>, WatchRef
>::iterator j
=
9876 obc
->watchers
.begin();
9877 j
!= obc
->watchers
.end();
9878 obc
->watchers
.erase(j
++)) {
9879 j
->second
->discard();
9887 * If we return an error, and set *pmissing, then promoting that
9890 * If we return -EAGAIN, we will always set *pmissing to the missing
9891 * object to wait for.
9893 * If we return an error but do not set *pmissing, then we know the
9894 * object does not exist.
9896 int PrimaryLogPG::find_object_context(const hobject_t
& oid
,
9897 ObjectContextRef
*pobc
,
9899 bool map_snapid_to_clone
,
9900 hobject_t
*pmissing
)
9903 assert(oid
.pool
== static_cast<int64_t>(info
.pgid
.pool()));
9905 if (oid
.snap
== CEPH_NOSNAP
) {
9906 ObjectContextRef obc
= get_object_context(oid
, can_create
);
9912 dout(10) << "find_object_context " << oid
9914 << " oi=" << obc
->obs
.oi
9921 hobject_t head
= oid
.get_head();
9923 // want the snapdir?
9924 if (oid
.snap
== CEPH_SNAPDIR
) {
9925 // return head or snapdir, whichever exists.
9926 ObjectContextRef headobc
= get_object_context(head
, can_create
);
9927 ObjectContextRef obc
= headobc
;
9928 if (!obc
|| !obc
->obs
.exists
)
9929 obc
= get_object_context(oid
, can_create
);
9930 if (!obc
|| !obc
->obs
.exists
) {
9931 // if we have neither, we would want to promote the head.
9935 *pobc
= headobc
; // may be null
9938 dout(10) << "find_object_context " << oid
9940 << " oi=" << obc
->obs
.oi
9944 // always populate ssc for SNAPDIR...
9946 obc
->ssc
= get_snapset_context(
9952 if (!map_snapid_to_clone
&& pool
.info
.is_removed_snap(oid
.snap
)) {
9953 dout(10) << __func__
<< " snap " << oid
.snap
<< " is removed" << dendl
;
9957 SnapSetContext
*ssc
= get_snapset_context(oid
, can_create
);
9958 if (!ssc
|| !(ssc
->exists
|| can_create
)) {
9959 dout(20) << __func__
<< " " << oid
<< " no snapset" << dendl
;
9961 *pmissing
= head
; // start by getting the head
9963 put_snapset_context(ssc
);
9967 if (map_snapid_to_clone
) {
9968 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
9969 << " snapset " << ssc
->snapset
9970 << " map_snapid_to_clone=true" << dendl
;
9971 if (oid
.snap
> ssc
->snapset
.seq
) {
9972 // already must be readable
9973 ObjectContextRef obc
= get_object_context(head
, false);
9974 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
9975 << " snapset " << ssc
->snapset
9976 << " maps to head" << dendl
;
9978 put_snapset_context(ssc
);
9979 return (obc
&& obc
->obs
.exists
) ? 0 : -ENOENT
;
9981 vector
<snapid_t
>::const_iterator citer
= std::find(
9982 ssc
->snapset
.clones
.begin(),
9983 ssc
->snapset
.clones
.end(),
9985 if (citer
== ssc
->snapset
.clones
.end()) {
9986 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
9987 << " snapset " << ssc
->snapset
9988 << " maps to nothing" << dendl
;
9989 put_snapset_context(ssc
);
9993 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
9994 << " snapset " << ssc
->snapset
9995 << " maps to " << oid
<< dendl
;
9997 if (pg_log
.get_missing().is_missing(oid
)) {
9998 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
9999 << " snapset " << ssc
->snapset
10000 << " " << oid
<< " is missing" << dendl
;
10003 put_snapset_context(ssc
);
10007 ObjectContextRef obc
= get_object_context(oid
, false);
10008 if (!obc
|| !obc
->obs
.exists
) {
10009 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
10010 << " snapset " << ssc
->snapset
10011 << " " << oid
<< " is not present" << dendl
;
10014 put_snapset_context(ssc
);
10017 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
10018 << " snapset " << ssc
->snapset
10019 << " " << oid
<< " HIT" << dendl
;
10021 put_snapset_context(ssc
);
10024 ceph_abort(); //unreachable
10027 dout(10) << "find_object_context " << oid
<< " @" << oid
.snap
10028 << " snapset " << ssc
->snapset
<< dendl
;
10031 if (oid
.snap
> ssc
->snapset
.seq
) {
10032 if (ssc
->snapset
.head_exists
) {
10033 ObjectContextRef obc
= get_object_context(head
, false);
10034 dout(10) << "find_object_context " << head
10035 << " want " << oid
.snap
<< " > snapset seq " << ssc
->snapset
.seq
10036 << " -- HIT " << obc
->obs
10041 assert(ssc
== obc
->ssc
);
10042 put_snapset_context(ssc
);
10047 dout(10) << "find_object_context " << head
10048 << " want " << oid
.snap
<< " > snapset seq " << ssc
->snapset
.seq
10049 << " but head dne -- DNE"
10051 put_snapset_context(ssc
);
10055 // which clone would it be?
10057 while (k
< ssc
->snapset
.clones
.size() &&
10058 ssc
->snapset
.clones
[k
] < oid
.snap
)
10060 if (k
== ssc
->snapset
.clones
.size()) {
10061 dout(10) << "find_object_context no clones with last >= oid.snap "
10062 << oid
.snap
<< " -- DNE" << dendl
;
10063 put_snapset_context(ssc
);
10066 hobject_t
soid(oid
.oid
, oid
.get_key(), ssc
->snapset
.clones
[k
], oid
.get_hash(),
10067 info
.pgid
.pool(), oid
.get_namespace());
10069 if (pg_log
.get_missing().is_missing(soid
)) {
10070 dout(20) << "find_object_context " << soid
<< " missing, try again later"
10074 put_snapset_context(ssc
);
10078 ObjectContextRef obc
= get_object_context(soid
, false);
10079 if (!obc
|| !obc
->obs
.exists
) {
10082 put_snapset_context(ssc
);
10083 if (is_degraded_or_backfilling_object(soid
)) {
10084 dout(20) << __func__
<< " clone is degraded or backfilling " << soid
<< dendl
;
10087 dout(20) << __func__
<< " missing clone " << soid
<< dendl
;
10095 assert(obc
->ssc
== ssc
);
10096 put_snapset_context(ssc
);
10101 dout(20) << "find_object_context " << soid
10102 << " snapset " << obc
->ssc
->snapset
10103 << " legacy_snaps " << obc
->obs
.oi
.legacy_snaps
10105 snapid_t first
, last
;
10106 if (obc
->ssc
->snapset
.is_legacy()) {
10107 first
= obc
->obs
.oi
.legacy_snaps
.back();
10108 last
= obc
->obs
.oi
.legacy_snaps
.front();
10110 auto p
= obc
->ssc
->snapset
.clone_snaps
.find(soid
.snap
);
10111 assert(p
!= obc
->ssc
->snapset
.clone_snaps
.end());
10112 first
= p
->second
.back();
10113 last
= p
->second
.front();
10115 if (first
<= oid
.snap
) {
10116 dout(20) << "find_object_context " << soid
<< " [" << first
<< "," << last
10117 << "] contains " << oid
.snap
<< " -- HIT " << obc
->obs
<< dendl
;
10121 dout(20) << "find_object_context " << soid
<< " [" << first
<< "," << last
10122 << "] does not contain " << oid
.snap
<< " -- DNE" << dendl
;
10127 void PrimaryLogPG::object_context_destructor_callback(ObjectContext
*obc
)
10130 put_snapset_context(obc
->ssc
);
10133 void PrimaryLogPG::add_object_context_to_pg_stat(ObjectContextRef obc
, pg_stat_t
*pgstat
)
10135 object_info_t
& oi
= obc
->obs
.oi
;
10137 dout(10) << "add_object_context_to_pg_stat " << oi
.soid
<< dendl
;
10138 object_stat_sum_t stat
;
10140 stat
.num_bytes
+= oi
.size
;
10142 if (oi
.soid
.snap
!= CEPH_SNAPDIR
)
10143 stat
.num_objects
++;
10145 stat
.num_objects_dirty
++;
10146 if (oi
.is_whiteout())
10147 stat
.num_whiteouts
++;
10149 stat
.num_objects_omap
++;
10150 if (oi
.is_cache_pinned())
10151 stat
.num_objects_pinned
++;
10153 if (oi
.soid
.snap
&& oi
.soid
.snap
!= CEPH_NOSNAP
&& oi
.soid
.snap
!= CEPH_SNAPDIR
) {
10154 stat
.num_object_clones
++;
10157 obc
->ssc
= get_snapset_context(oi
.soid
, false);
10160 // subtract off clone overlap
10161 if (obc
->ssc
->snapset
.clone_overlap
.count(oi
.soid
.snap
)) {
10162 interval_set
<uint64_t>& o
= obc
->ssc
->snapset
.clone_overlap
[oi
.soid
.snap
];
10163 for (interval_set
<uint64_t>::const_iterator r
= o
.begin();
10166 stat
.num_bytes
-= r
.get_len();
10172 pgstat
->stats
.sum
.add(stat
);
10175 void PrimaryLogPG::kick_object_context_blocked(ObjectContextRef obc
)
10177 const hobject_t
& soid
= obc
->obs
.oi
.soid
;
10178 if (obc
->is_blocked()) {
10179 dout(10) << __func__
<< " " << soid
<< " still blocked" << dendl
;
10183 map
<hobject_t
, list
<OpRequestRef
>>::iterator p
= waiting_for_blocked_object
.find(soid
);
10184 if (p
!= waiting_for_blocked_object
.end()) {
10185 list
<OpRequestRef
>& ls
= p
->second
;
10186 dout(10) << __func__
<< " " << soid
<< " requeuing " << ls
.size() << " requests" << dendl
;
10188 waiting_for_blocked_object
.erase(p
);
10191 map
<hobject_t
, ObjectContextRef
>::iterator i
=
10192 objects_blocked_on_snap_promotion
.find(obc
->obs
.oi
.soid
.get_head());
10193 if (i
!= objects_blocked_on_snap_promotion
.end()) {
10194 assert(i
->second
== obc
);
10195 objects_blocked_on_snap_promotion
.erase(i
);
10198 if (obc
->requeue_scrub_on_unblock
) {
10199 obc
->requeue_scrub_on_unblock
= false;
10204 SnapSetContext
*PrimaryLogPG::get_snapset_context(
10205 const hobject_t
& oid
,
10207 const map
<string
, bufferlist
> *attrs
,
10210 Mutex::Locker
l(snapset_contexts_lock
);
10211 SnapSetContext
*ssc
;
10212 map
<hobject_t
, SnapSetContext
*>::iterator p
= snapset_contexts
.find(
10213 oid
.get_snapdir());
10214 if (p
!= snapset_contexts
.end()) {
10215 if (can_create
|| p
->second
->exists
) {
10224 if (!(oid
.is_head() && !oid_existed
))
10225 r
= pgbackend
->objects_get_attr(oid
.get_head(), SS_ATTR
, &bv
);
10228 if (!(oid
.is_snapdir() && !oid_existed
))
10229 r
= pgbackend
->objects_get_attr(oid
.get_snapdir(), SS_ATTR
, &bv
);
10230 if (r
< 0 && !can_create
)
10234 assert(attrs
->count(SS_ATTR
));
10235 bv
= attrs
->find(SS_ATTR
)->second
;
10237 ssc
= new SnapSetContext(oid
.get_snapdir());
10238 _register_snapset_context(ssc
);
10240 bufferlist::iterator bvp
= bv
.begin();
10242 ssc
->snapset
.decode(bvp
);
10243 } catch (buffer::error
& e
) {
10244 dout(0) << __func__
<< " Can't decode snapset: " << e
<< dendl
;
10247 ssc
->exists
= true;
10249 ssc
->exists
= false;
10257 void PrimaryLogPG::put_snapset_context(SnapSetContext
*ssc
)
10259 Mutex::Locker
l(snapset_contexts_lock
);
10261 if (ssc
->ref
== 0) {
10262 if (ssc
->registered
)
10263 snapset_contexts
.erase(ssc
->oid
);
10268 /** pull - request object from a peer
10273 * NONE - didn't pull anything
10274 * YES - pulled what the caller wanted
10275 * OTHER - needed to pull something else first (_head or _snapdir)
10277 enum { PULL_NONE
, PULL_OTHER
, PULL_YES
};
10279 int PrimaryLogPG::recover_missing(
10280 const hobject_t
&soid
, eversion_t v
,
10282 PGBackend::RecoveryHandle
*h
)
10284 if (missing_loc
.is_unfound(soid
)) {
10285 dout(7) << "pull " << soid
10287 << " but it is unfound" << dendl
;
10291 if (missing_loc
.is_deleted(soid
)) {
10292 start_recovery_op(soid
);
10293 assert(!recovering
.count(soid
));
10294 recovering
.insert(make_pair(soid
, ObjectContextRef()));
10295 epoch_t cur_epoch
= get_osdmap()->get_epoch();
10296 remove_missing_object(soid
, v
, new FunctionContext(
10299 if (!pg_has_reset_since(cur_epoch
)) {
10300 bool object_missing
= false;
10301 for (const auto& shard
: actingbackfill
) {
10302 if (shard
== pg_whoami
)
10304 if (peer_missing
[shard
].is_missing(soid
)) {
10305 dout(20) << __func__
<< ": soid " << soid
<< " needs to be deleted from replica " << shard
<< dendl
;
10306 object_missing
= true;
10310 if (!object_missing
) {
10311 object_stat_sum_t stat_diff
;
10312 stat_diff
.num_objects_recovered
= 1;
10313 on_global_recover(soid
, stat_diff
, true);
10315 auto recovery_handle
= pgbackend
->open_recovery_op();
10316 pgbackend
->recover_delete_object(soid
, v
, recovery_handle
);
10317 pgbackend
->run_recovery_op(recovery_handle
, priority
);
10325 // is this a snapped object? if so, consult the snapset.. we may not need the entire object!
10326 ObjectContextRef obc
;
10327 ObjectContextRef head_obc
;
10328 if (soid
.snap
&& soid
.snap
< CEPH_NOSNAP
) {
10329 // do we have the head and/or snapdir?
10330 hobject_t head
= soid
.get_head();
10331 if (pg_log
.get_missing().is_missing(head
)) {
10332 if (recovering
.count(head
)) {
10333 dout(10) << " missing but already recovering head " << head
<< dendl
;
10336 int r
= recover_missing(
10337 head
, pg_log
.get_missing().get_items().find(head
)->second
.need
, priority
,
10339 if (r
!= PULL_NONE
)
10344 head
= soid
.get_snapdir();
10345 if (pg_log
.get_missing().is_missing(head
)) {
10346 if (recovering
.count(head
)) {
10347 dout(10) << " missing but already recovering snapdir " << head
<< dendl
;
10350 int r
= recover_missing(
10351 head
, pg_log
.get_missing().get_items().find(head
)->second
.need
, priority
,
10353 if (r
!= PULL_NONE
)
10359 // we must have one or the other
10360 head_obc
= get_object_context(
10365 head_obc
= get_object_context(
10366 soid
.get_snapdir(),
10371 start_recovery_op(soid
);
10372 assert(!recovering
.count(soid
));
10373 recovering
.insert(make_pair(soid
, obc
));
10374 int r
= pgbackend
->recover_object(
10380 // This is only a pull which shouldn't return an error
10385 void PrimaryLogPG::send_remove_op(
10386 const hobject_t
& oid
, eversion_t v
, pg_shard_t peer
)
10388 ceph_tid_t tid
= osd
->get_tid();
10389 osd_reqid_t
rid(osd
->get_cluster_msgr_name(), 0, tid
);
10391 dout(10) << "send_remove_op " << oid
<< " from osd." << peer
10392 << " tid " << tid
<< dendl
;
10394 MOSDSubOp
*subop
= new MOSDSubOp(
10395 rid
, pg_whoami
, spg_t(info
.pgid
.pgid
, peer
.shard
),
10396 oid
, CEPH_OSD_FLAG_ACK
,
10397 get_osdmap()->get_epoch(), tid
, v
);
10398 subop
->ops
= vector
<OSDOp
>(1);
10399 subop
->ops
[0].op
.op
= CEPH_OSD_OP_DELETE
;
10401 osd
->send_message_osd_cluster(peer
.osd
, subop
, get_osdmap()->get_epoch());
10404 void PrimaryLogPG::remove_missing_object(const hobject_t
&soid
,
10405 eversion_t v
, Context
*on_complete
)
10407 dout(20) << __func__
<< " " << soid
<< " " << v
<< dendl
;
10408 assert(on_complete
!= nullptr);
10410 ObjectStore::Transaction t
;
10411 remove_snap_mapped_object(t
, soid
);
10413 ObjectRecoveryInfo recovery_info
;
10414 recovery_info
.soid
= soid
;
10415 recovery_info
.version
= v
;
10417 epoch_t cur_epoch
= get_osdmap()->get_epoch();
10418 t
.register_on_complete(new FunctionContext(
10421 if (!pg_has_reset_since(cur_epoch
)) {
10422 ObjectStore::Transaction t2
;
10423 on_local_recover(soid
, recovery_info
, ObjectContextRef(), true, &t2
);
10424 t2
.register_on_complete(on_complete
);
10425 int r
= osd
->store
->queue_transaction(osr
.get(), std::move(t2
), nullptr);
10430 on_complete
->complete(-EAGAIN
);
10433 int r
= osd
->store
->queue_transaction(osr
.get(), std::move(t
), nullptr);
10437 void PrimaryLogPG::finish_degraded_object(const hobject_t
& oid
)
10439 dout(10) << "finish_degraded_object " << oid
<< dendl
;
10440 if (callbacks_for_degraded_object
.count(oid
)) {
10441 list
<Context
*> contexts
;
10442 contexts
.swap(callbacks_for_degraded_object
[oid
]);
10443 callbacks_for_degraded_object
.erase(oid
);
10444 for (list
<Context
*>::iterator i
= contexts
.begin();
10445 i
!= contexts
.end();
10450 map
<hobject_t
, snapid_t
>::iterator i
= objects_blocked_on_degraded_snap
.find(
10452 if (i
!= objects_blocked_on_degraded_snap
.end() &&
10453 i
->second
== oid
.snap
)
10454 objects_blocked_on_degraded_snap
.erase(i
);
10457 void PrimaryLogPG::_committed_pushed_object(
10458 epoch_t epoch
, eversion_t last_complete
)
10461 if (!pg_has_reset_since(epoch
)) {
10462 dout(10) << "_committed_pushed_object last_complete " << last_complete
<< " now ondisk" << dendl
;
10463 last_complete_ondisk
= last_complete
;
10465 if (last_complete_ondisk
== info
.last_update
) {
10466 if (!is_primary()) {
10467 // Either we are a replica or backfill target.
10468 // we are fully up to date. tell the primary!
10469 osd
->send_message_osd_cluster(
10472 get_osdmap()->get_epoch(),
10473 spg_t(info
.pgid
.pgid
, get_primary().shard
),
10474 last_complete_ondisk
),
10475 get_osdmap()->get_epoch());
10477 calc_min_last_complete_ondisk();
10482 dout(10) << "_committed_pushed_object pg has changed, not touching last_complete_ondisk" << dendl
;
10488 void PrimaryLogPG::_applied_recovered_object(ObjectContextRef obc
)
10491 dout(20) << __func__
<< dendl
;
10493 dout(20) << "obc = " << *obc
<< dendl
;
10495 assert(active_pushes
>= 1);
10498 // requeue an active chunky scrub waiting on recovery ops
10499 if (!deleting
&& active_pushes
== 0
10500 && scrubber
.is_chunky_scrub_active()) {
10501 if (ops_blocked_by_scrub()) {
10502 requeue_scrub(true);
10504 requeue_scrub(false);
10510 void PrimaryLogPG::_applied_recovered_object_replica()
10513 dout(20) << __func__
<< dendl
;
10514 assert(active_pushes
>= 1);
10517 // requeue an active chunky scrub waiting on recovery ops
10518 if (!deleting
&& active_pushes
== 0 &&
10519 scrubber
.active_rep_scrub
&& static_cast<const MOSDRepScrub
*>(
10520 scrubber
.active_rep_scrub
->get_req())->chunky
) {
10523 PGQueueable(scrubber
.active_rep_scrub
, get_osdmap()->get_epoch()));
10524 scrubber
.active_rep_scrub
= OpRequestRef();
10529 void PrimaryLogPG::recover_got(hobject_t oid
, eversion_t v
)
10531 dout(10) << "got missing " << oid
<< " v " << v
<< dendl
;
10532 pg_log
.recover_got(oid
, v
, info
);
10533 if (pg_log
.get_log().complete_to
!= pg_log
.get_log().log
.end()) {
10534 dout(10) << "last_complete now " << info
.last_complete
10535 << " log.complete_to " << pg_log
.get_log().complete_to
->version
10538 dout(10) << "last_complete now " << info
.last_complete
10539 << " log.complete_to at end" << dendl
;
10540 //below is not true in the repair case.
10541 //assert(missing.num_missing() == 0); // otherwise, complete_to was wrong.
10542 assert(info
.last_complete
== info
.last_update
);
10546 void PrimaryLogPG::primary_failed(const hobject_t
&soid
)
10548 list
<pg_shard_t
> fl
= { pg_whoami
};
10549 failed_push(fl
, soid
);
10552 void PrimaryLogPG::failed_push(const list
<pg_shard_t
> &from
, const hobject_t
&soid
)
10554 dout(20) << __func__
<< ": " << soid
<< dendl
;
10555 assert(recovering
.count(soid
));
10556 auto obc
= recovering
[soid
];
10558 list
<OpRequestRef
> blocked_ops
;
10559 obc
->drop_recovery_read(&blocked_ops
);
10560 requeue_ops(blocked_ops
);
10562 recovering
.erase(soid
);
10563 for (auto&& i
: from
)
10564 missing_loc
.remove_location(soid
, i
);
10565 dout(0) << __func__
<< " " << soid
<< " from shard " << from
10566 << ", reps on " << missing_loc
.get_locations(soid
)
10567 << " unfound? " << missing_loc
.is_unfound(soid
) << dendl
;
10568 finish_recovery_op(soid
); // close out this attempt,
10571 void PrimaryLogPG::sub_op_remove(OpRequestRef op
)
10573 const MOSDSubOp
*m
= static_cast<const MOSDSubOp
*>(op
->get_req());
10574 assert(m
->get_type() == MSG_OSD_SUBOP
);
10575 dout(7) << "sub_op_remove " << m
->poid
<< dendl
;
10577 op
->mark_started();
10579 ObjectStore::Transaction t
;
10580 remove_snap_mapped_object(t
, m
->poid
);
10581 int r
= osd
->store
->queue_transaction(osr
.get(), std::move(t
), NULL
);
10585 eversion_t
PrimaryLogPG::pick_newest_available(const hobject_t
& oid
)
10588 pg_missing_item pmi
;
10589 bool is_missing
= pg_log
.get_missing().is_missing(oid
, &pmi
);
10590 assert(is_missing
);
10592 dout(10) << "pick_newest_available " << oid
<< " " << v
<< " on osd." << osd
->whoami
<< " (local)" << dendl
;
10594 assert(!actingbackfill
.empty());
10595 for (set
<pg_shard_t
>::iterator i
= actingbackfill
.begin();
10596 i
!= actingbackfill
.end();
10598 if (*i
== get_primary()) continue;
10599 pg_shard_t peer
= *i
;
10600 if (!peer_missing
[peer
].is_missing(oid
)) {
10603 eversion_t h
= peer_missing
[peer
].get_items().at(oid
).have
;
10604 dout(10) << "pick_newest_available " << oid
<< " " << h
<< " on osd." << peer
<< dendl
;
10609 dout(10) << "pick_newest_available " << oid
<< " " << v
<< " (newest)" << dendl
;
10613 void PrimaryLogPG::do_update_log_missing(OpRequestRef
&op
)
10615 const MOSDPGUpdateLogMissing
*m
= static_cast<const MOSDPGUpdateLogMissing
*>(
10617 assert(m
->get_type() == MSG_OSD_PG_UPDATE_LOG_MISSING
);
10618 ObjectStore::Transaction t
;
10619 append_log_entries_update_missing(m
->entries
, t
);
10621 Context
*complete
= new FunctionContext(
10623 const MOSDPGUpdateLogMissing
*msg
= static_cast<const MOSDPGUpdateLogMissing
*>(
10626 if (!pg_has_reset_since(msg
->get_epoch())) {
10627 MOSDPGUpdateLogMissingReply
*reply
=
10628 new MOSDPGUpdateLogMissingReply(
10629 spg_t(info
.pgid
.pgid
, primary_shard().shard
),
10634 reply
->set_priority(CEPH_MSG_PRIO_HIGH
);
10635 msg
->get_connection()->send_message(reply
);
10640 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
10641 t
.register_on_commit(complete
);
10643 /* Hack to work around the fact that ReplicatedBackend sends
10644 * ack+commit if commit happens first
10646 * This behavior is no longer necessary, but we preserve it so old
10647 * primaries can keep their repops in order */
10648 if (pool
.info
.ec_pool()) {
10649 t
.register_on_complete(complete
);
10651 t
.register_on_commit(complete
);
10654 t
.register_on_applied(
10655 new C_OSD_OnApplied
{this, get_osdmap()->get_epoch(), info
.last_update
});
10656 int tr
= osd
->store
->queue_transaction(
10663 void PrimaryLogPG::do_update_log_missing_reply(OpRequestRef
&op
)
10665 const MOSDPGUpdateLogMissingReply
*m
=
10666 static_cast<const MOSDPGUpdateLogMissingReply
*>(
10668 dout(20) << __func__
<< " got reply from "
10669 << m
->get_from() << dendl
;
10671 auto it
= log_entry_update_waiting_on
.find(m
->get_tid());
10672 if (it
!= log_entry_update_waiting_on
.end()) {
10673 if (it
->second
.waiting_on
.count(m
->get_from())) {
10674 it
->second
.waiting_on
.erase(m
->get_from());
10677 << info
.pgid
<< " got reply "
10678 << *m
<< " from shard we are not waiting for "
10682 if (it
->second
.waiting_on
.empty()) {
10683 repop_all_committed(it
->second
.repop
.get());
10684 log_entry_update_waiting_on
.erase(it
);
10688 << info
.pgid
<< " got reply "
10689 << *m
<< " on unknown tid " << m
->get_tid();
10693 /* Mark all unfound objects as lost.
10695 void PrimaryLogPG::mark_all_unfound_lost(
10700 dout(3) << __func__
<< " " << pg_log_entry_t::get_op_name(what
) << dendl
;
10701 list
<hobject_t
> oids
;
10703 dout(30) << __func__
<< ": log before:\n";
10704 pg_log
.get_log().print(*_dout
);
10707 mempool::osd_pglog::list
<pg_log_entry_t
> log_entries
;
10709 utime_t mtime
= ceph_clock_now();
10710 map
<hobject_t
, pg_missing_item
>::const_iterator m
=
10711 missing_loc
.get_needs_recovery().begin();
10712 map
<hobject_t
, pg_missing_item
>::const_iterator mend
=
10713 missing_loc
.get_needs_recovery().end();
10715 ObcLockManager manager
;
10716 eversion_t v
= get_next_version();
10717 v
.epoch
= get_osdmap()->get_epoch();
10718 uint64_t num_unfound
= missing_loc
.num_unfound();
10719 while (m
!= mend
) {
10720 const hobject_t
&oid(m
->first
);
10721 if (!missing_loc
.is_unfound(oid
)) {
10722 // We only care about unfound objects
10727 ObjectContextRef obc
;
10731 case pg_log_entry_t::LOST_MARK
:
10732 assert(0 == "actually, not implemented yet!");
10735 case pg_log_entry_t::LOST_REVERT
:
10736 prev
= pick_newest_available(oid
);
10737 if (prev
> eversion_t()) {
10740 pg_log_entry_t::LOST_REVERT
, oid
, v
,
10741 m
->second
.need
, 0, osd_reqid_t(), mtime
, 0);
10742 e
.reverting_to
= prev
;
10743 e
.mark_unrollbackable();
10744 log_entries
.push_back(e
);
10745 dout(10) << e
<< dendl
;
10747 // we are now missing the new version; recovery code will sort it out.
10753 case pg_log_entry_t::LOST_DELETE
:
10755 pg_log_entry_t
e(pg_log_entry_t::LOST_DELETE
, oid
, v
, m
->second
.need
,
10756 0, osd_reqid_t(), mtime
, 0);
10757 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_JEWEL
) {
10758 if (pool
.info
.require_rollback()) {
10759 e
.mod_desc
.try_rmobject(v
.version
);
10761 e
.mark_unrollbackable();
10763 } // otherwise, just do what we used to do
10764 dout(10) << e
<< dendl
;
10765 log_entries
.push_back(e
);
10766 oids
.push_back(oid
);
10778 info
.stats
.stats_invalid
= true;
10780 submit_log_entries(
10782 std::move(manager
),
10783 boost::optional
<std::function
<void(void)> >(
10784 [this, oids
, con
, num_unfound
, tid
]() {
10785 if (perform_deletes_during_peering()) {
10786 for (auto oid
: oids
) {
10787 // clear old locations - merge_new_log_entries will have
10788 // handled rebuilding missing_loc for each of these
10789 // objects if we have the RECOVERY_DELETES flag
10790 missing_loc
.recovered(oid
);
10794 for (auto& p
: waiting_for_unreadable_object
) {
10795 release_backoffs(p
.first
);
10797 requeue_object_waiters(waiting_for_unreadable_object
);
10801 ss
<< "pg has " << num_unfound
10802 << " objects unfound and apparently lost marking";
10803 string rs
= ss
.str();
10804 dout(0) << "do_command r=" << 0 << " " << rs
<< dendl
;
10805 osd
->clog
->info() << rs
;
10807 MCommandReply
*reply
= new MCommandReply(0, rs
);
10808 reply
->set_tid(tid
);
10809 con
->send_message(reply
);
10815 void PrimaryLogPG::_split_into(pg_t child_pgid
, PG
*child
, unsigned split_bits
)
10817 assert(repop_queue
.empty());
10821 * pg status change notification
10824 void PrimaryLogPG::apply_and_flush_repops(bool requeue
)
10826 list
<OpRequestRef
> rq
;
10828 // apply all repops
10829 while (!repop_queue
.empty()) {
10830 RepGather
*repop
= repop_queue
.front();
10831 repop_queue
.pop_front();
10832 dout(10) << " canceling repop tid " << repop
->rep_tid
<< dendl
;
10833 repop
->rep_aborted
= true;
10834 repop
->on_applied
.clear();
10835 repop
->on_committed
.clear();
10836 repop
->on_success
.clear();
10840 dout(10) << " requeuing " << *repop
->op
->get_req() << dendl
;
10841 rq
.push_back(repop
->op
);
10842 repop
->op
= OpRequestRef();
10845 // also requeue any dups, interleaved into position
10846 map
<eversion_t
, list
<pair
<OpRequestRef
, version_t
> > >::iterator p
=
10847 waiting_for_ondisk
.find(repop
->v
);
10848 if (p
!= waiting_for_ondisk
.end()) {
10849 dout(10) << " also requeuing ondisk waiters " << p
->second
<< dendl
;
10850 for (list
<pair
<OpRequestRef
, version_t
> >::iterator i
=
10852 i
!= p
->second
.end();
10854 rq
.push_back(i
->first
);
10856 waiting_for_ondisk
.erase(p
);
10860 remove_repop(repop
);
10863 assert(repop_queue
.empty());
10867 if (!waiting_for_ondisk
.empty()) {
10868 for (map
<eversion_t
, list
<pair
<OpRequestRef
, version_t
> > >::iterator i
=
10869 waiting_for_ondisk
.begin();
10870 i
!= waiting_for_ondisk
.end();
10872 for (list
<pair
<OpRequestRef
, version_t
> >::iterator j
=
10874 j
!= i
->second
.end();
10876 derr
<< __func__
<< ": op " << *(j
->first
->get_req()) << " waiting on "
10877 << i
->first
<< dendl
;
10880 assert(waiting_for_ondisk
.empty());
10884 waiting_for_ondisk
.clear();
10887 void PrimaryLogPG::on_flushed()
10889 assert(flushes_in_progress
> 0);
10890 flushes_in_progress
--;
10891 if (flushes_in_progress
== 0) {
10892 requeue_ops(waiting_for_peered
);
10894 if (!is_peered() || !is_primary()) {
10895 pair
<hobject_t
, ObjectContextRef
> i
;
10896 while (object_contexts
.get_next(i
.first
, &i
)) {
10897 derr
<< "on_flushed: object " << i
.first
<< " obc still alive" << dendl
;
10899 assert(object_contexts
.empty());
10901 pgbackend
->on_flushed();
10904 void PrimaryLogPG::on_removal(ObjectStore::Transaction
*t
)
10906 dout(10) << "on_removal" << dendl
;
10908 // adjust info to backfill
10909 info
.set_last_backfill(hobject_t());
10910 pg_log
.reset_backfill();
10915 PGLogEntryHandler rollbacker
{this, t
};
10916 pg_log
.roll_forward(&rollbacker
);
10918 write_if_dirty(*t
);
10924 void PrimaryLogPG::clear_async_reads()
10926 dout(10) << __func__
<< dendl
;
10927 for(auto& i
: in_progress_async_reads
) {
10928 dout(10) << "clear ctx: "
10929 << "OpRequestRef " << i
.first
10930 << " OpContext " << i
.second
10932 close_op_ctx(i
.second
);
10936 void PrimaryLogPG::on_shutdown()
10938 dout(10) << "on_shutdown" << dendl
;
10940 // remove from queues
10941 osd
->pg_stat_queue_dequeue(this);
10942 osd
->peering_wq
.dequeue(this);
10944 // handles queue races
10947 if (recovery_queued
) {
10948 recovery_queued
= false;
10949 osd
->clear_queued_recovery(this);
10952 clear_scrub_reserved();
10953 scrub_clear_state();
10955 unreg_next_scrub();
10956 cancel_copy_ops(false);
10957 cancel_flush_ops(false);
10958 cancel_proxy_ops(false);
10959 apply_and_flush_repops(false);
10960 cancel_log_updates();
10961 // we must remove PGRefs, so do this this prior to release_backoffs() callers
10963 // clean up snap trim references
10964 snap_trimmer_machine
.process_event(Reset());
10966 pgbackend
->on_change();
10968 context_registry_on_change();
10969 object_contexts
.clear();
10971 clear_async_reads();
10973 osd
->remote_reserver
.cancel_reservation(info
.pgid
);
10974 osd
->local_reserver
.cancel_reservation(info
.pgid
);
10976 clear_primary_state();
10980 void PrimaryLogPG::on_activate()
10983 if (needs_recovery()) {
10984 dout(10) << "activate not all replicas are up-to-date, queueing recovery" << dendl
;
10985 queue_peering_event(
10987 std::make_shared
<CephPeeringEvt
>(
10988 get_osdmap()->get_epoch(),
10989 get_osdmap()->get_epoch(),
10991 } else if (needs_backfill()) {
10992 dout(10) << "activate queueing backfill" << dendl
;
10993 queue_peering_event(
10995 std::make_shared
<CephPeeringEvt
>(
10996 get_osdmap()->get_epoch(),
10997 get_osdmap()->get_epoch(),
10998 RequestBackfill())));
11000 dout(10) << "activate all replicas clean, no recovery" << dendl
;
11001 eio_errors_to_process
= false;
11002 queue_peering_event(
11004 std::make_shared
<CephPeeringEvt
>(
11005 get_osdmap()->get_epoch(),
11006 get_osdmap()->get_epoch(),
11007 AllReplicasRecovered())));
11010 publish_stats_to_osd();
11012 if (!backfill_targets
.empty()) {
11013 last_backfill_started
= earliest_backfill();
11014 new_backfill
= true;
11015 assert(!last_backfill_started
.is_max());
11016 dout(5) << "on activate: bft=" << backfill_targets
11017 << " from " << last_backfill_started
<< dendl
;
11018 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11019 i
!= backfill_targets
.end();
11021 dout(5) << "target shard " << *i
11022 << " from " << peer_info
[*i
].last_backfill
11031 void PrimaryLogPG::_on_new_interval()
11033 dout(20) << __func__
<< "checking missing set deletes flag. missing = " << pg_log
.get_missing() << dendl
;
11034 if (!pg_log
.get_missing().may_include_deletes
&&
11035 get_osdmap()->test_flag(CEPH_OSDMAP_RECOVERY_DELETES
)) {
11036 pg_log
.rebuild_missing_set_with_deletes(osd
->store
, coll
, info
);
11038 assert(pg_log
.get_missing().may_include_deletes
== get_osdmap()->test_flag(CEPH_OSDMAP_RECOVERY_DELETES
));
11041 void PrimaryLogPG::on_change(ObjectStore::Transaction
*t
)
11043 dout(10) << "on_change" << dendl
;
11045 if (hit_set
&& hit_set
->insert_count() == 0) {
11046 dout(20) << " discarding empty hit_set" << dendl
;
11050 if (recovery_queued
) {
11051 recovery_queued
= false;
11052 osd
->clear_queued_recovery(this);
11055 // requeue everything in the reverse order they should be
11057 requeue_ops(waiting_for_peered
);
11058 requeue_ops(waiting_for_active
);
11060 clear_scrub_reserved();
11062 cancel_copy_ops(is_primary());
11063 cancel_flush_ops(is_primary());
11064 cancel_proxy_ops(is_primary());
11066 // requeue object waiters
11067 for (auto& p
: waiting_for_unreadable_object
) {
11068 release_backoffs(p
.first
);
11070 if (is_primary()) {
11071 requeue_object_waiters(waiting_for_unreadable_object
);
11073 waiting_for_unreadable_object
.clear();
11075 for (map
<hobject_t
,list
<OpRequestRef
>>::iterator p
= waiting_for_degraded_object
.begin();
11076 p
!= waiting_for_degraded_object
.end();
11077 waiting_for_degraded_object
.erase(p
++)) {
11078 release_backoffs(p
->first
);
11080 requeue_ops(p
->second
);
11083 finish_degraded_object(p
->first
);
11086 // requeues waiting_for_scrub
11087 scrub_clear_state();
11089 for (auto p
= waiting_for_blocked_object
.begin();
11090 p
!= waiting_for_blocked_object
.end();
11091 waiting_for_blocked_object
.erase(p
++)) {
11093 requeue_ops(p
->second
);
11097 for (auto i
= callbacks_for_degraded_object
.begin();
11098 i
!= callbacks_for_degraded_object
.end();
11100 finish_degraded_object((i
++)->first
);
11102 assert(callbacks_for_degraded_object
.empty());
11104 if (is_primary()) {
11105 requeue_ops(waiting_for_cache_not_full
);
11107 waiting_for_cache_not_full
.clear();
11109 objects_blocked_on_cache_full
.clear();
11111 for (list
<pair
<OpRequestRef
, OpContext
*> >::iterator i
=
11112 in_progress_async_reads
.begin();
11113 i
!= in_progress_async_reads
.end();
11114 in_progress_async_reads
.erase(i
++)) {
11115 close_op_ctx(i
->second
);
11117 requeue_op(i
->first
);
11120 // this will requeue ops we were working on but didn't finish, and
11122 apply_and_flush_repops(is_primary());
11123 cancel_log_updates();
11125 // do this *after* apply_and_flush_repops so that we catch any newly
11126 // registered watches.
11127 context_registry_on_change();
11129 pgbackend
->on_change_cleanup(t
);
11130 scrubber
.cleanup_store(t
);
11131 pgbackend
->on_change();
11133 // clear snap_trimmer state
11134 snap_trimmer_machine
.process_event(Reset());
11136 debug_op_order
.clear();
11137 unstable_stats
.clear();
11139 // we don't want to cache object_contexts through the interval change
11140 // NOTE: we actually assert that all currently live references are dead
11141 // by the time the flush for the next interval completes.
11142 object_contexts
.clear();
11144 // should have been cleared above by finishing all of the degraded objects
11145 assert(objects_blocked_on_degraded_snap
.empty());
11148 void PrimaryLogPG::on_role_change()
11150 dout(10) << "on_role_change" << dendl
;
11151 if (get_role() != 0 && hit_set
) {
11152 dout(10) << " clearing hit set" << dendl
;
11157 void PrimaryLogPG::on_pool_change()
11159 dout(10) << __func__
<< dendl
;
11160 // requeue cache full waiters just in case the cache_mode is
11161 // changing away from writeback mode. note that if we are not
11162 // active the normal requeuing machinery is sufficient (and properly
11165 pool
.info
.cache_mode
!= pg_pool_t::CACHEMODE_WRITEBACK
&&
11166 !waiting_for_cache_not_full
.empty()) {
11167 dout(10) << __func__
<< " requeuing full waiters (not in writeback) "
11169 requeue_ops(waiting_for_cache_not_full
);
11170 objects_blocked_on_cache_full
.clear();
11176 // clear state. called on recovery completion AND cancellation.
11177 void PrimaryLogPG::_clear_recovery_state()
11179 missing_loc
.clear();
11180 #ifdef DEBUG_RECOVERY_OIDS
11181 recovering_oids
.clear();
11183 last_backfill_started
= hobject_t();
11184 set
<hobject_t
>::iterator i
= backfills_in_flight
.begin();
11185 while (i
!= backfills_in_flight
.end()) {
11186 assert(recovering
.count(*i
));
11187 backfills_in_flight
.erase(i
++);
11190 list
<OpRequestRef
> blocked_ops
;
11191 for (map
<hobject_t
, ObjectContextRef
>::iterator i
= recovering
.begin();
11192 i
!= recovering
.end();
11193 recovering
.erase(i
++)) {
11195 i
->second
->drop_recovery_read(&blocked_ops
);
11196 requeue_ops(blocked_ops
);
11199 assert(backfills_in_flight
.empty());
11200 pending_backfill_updates
.clear();
11201 assert(recovering
.empty());
11202 pgbackend
->clear_recovery_state();
11205 void PrimaryLogPG::cancel_pull(const hobject_t
&soid
)
11207 dout(20) << __func__
<< ": " << soid
<< dendl
;
11208 assert(recovering
.count(soid
));
11209 ObjectContextRef obc
= recovering
[soid
];
11211 list
<OpRequestRef
> blocked_ops
;
11212 obc
->drop_recovery_read(&blocked_ops
);
11213 requeue_ops(blocked_ops
);
11215 recovering
.erase(soid
);
11216 finish_recovery_op(soid
);
11217 release_backoffs(soid
);
11218 if (waiting_for_degraded_object
.count(soid
)) {
11219 dout(20) << " kicking degraded waiters on " << soid
<< dendl
;
11220 requeue_ops(waiting_for_degraded_object
[soid
]);
11221 waiting_for_degraded_object
.erase(soid
);
11223 if (waiting_for_unreadable_object
.count(soid
)) {
11224 dout(20) << " kicking unreadable waiters on " << soid
<< dendl
;
11225 requeue_ops(waiting_for_unreadable_object
[soid
]);
11226 waiting_for_unreadable_object
.erase(soid
);
11228 if (is_missing_object(soid
))
11229 pg_log
.set_last_requested(0); // get recover_primary to start over
11230 finish_degraded_object(soid
);
11233 void PrimaryLogPG::check_recovery_sources(const OSDMapRef
& osdmap
)
11236 * check that any peers we are planning to (or currently) pulling
11237 * objects from are dealt with.
11239 missing_loc
.check_recovery_sources(osdmap
);
11240 pgbackend
->check_recovery_sources(osdmap
);
11242 for (set
<pg_shard_t
>::iterator i
= peer_log_requested
.begin();
11243 i
!= peer_log_requested
.end();
11245 if (!osdmap
->is_up(i
->osd
)) {
11246 dout(10) << "peer_log_requested removing " << *i
<< dendl
;
11247 peer_log_requested
.erase(i
++);
11253 for (set
<pg_shard_t
>::iterator i
= peer_missing_requested
.begin();
11254 i
!= peer_missing_requested
.end();
11256 if (!osdmap
->is_up(i
->osd
)) {
11257 dout(10) << "peer_missing_requested removing " << *i
<< dendl
;
11258 peer_missing_requested
.erase(i
++);
11265 void PG::MissingLoc::check_recovery_sources(const OSDMapRef
& osdmap
)
11267 set
<pg_shard_t
> now_down
;
11268 for (set
<pg_shard_t
>::iterator p
= missing_loc_sources
.begin();
11269 p
!= missing_loc_sources
.end();
11271 if (osdmap
->is_up(p
->osd
)) {
11275 ldout(pg
->cct
, 10) << "check_recovery_sources source osd." << *p
<< " now down" << dendl
;
11276 now_down
.insert(*p
);
11277 missing_loc_sources
.erase(p
++);
11280 if (now_down
.empty()) {
11281 ldout(pg
->cct
, 10) << "check_recovery_sources no source osds (" << missing_loc_sources
<< ") went down" << dendl
;
11283 ldout(pg
->cct
, 10) << "check_recovery_sources sources osds " << now_down
<< " now down, remaining sources are "
11284 << missing_loc_sources
<< dendl
;
11286 // filter missing_loc
11287 map
<hobject_t
, set
<pg_shard_t
>>::iterator p
= missing_loc
.begin();
11288 while (p
!= missing_loc
.end()) {
11289 set
<pg_shard_t
>::iterator q
= p
->second
.begin();
11290 while (q
!= p
->second
.end())
11291 if (now_down
.count(*q
)) {
11292 p
->second
.erase(q
++);
11296 if (p
->second
.empty())
11297 missing_loc
.erase(p
++);
11305 bool PrimaryLogPG::start_recovery_ops(
11307 ThreadPool::TPHandle
&handle
,
11308 uint64_t *ops_started
)
11310 uint64_t& started
= *ops_started
;
11312 bool work_in_progress
= false;
11313 assert(is_primary());
11315 if (!state_test(PG_STATE_RECOVERING
) &&
11316 !state_test(PG_STATE_BACKFILL
)) {
11317 /* TODO: I think this case is broken and will make do_recovery()
11318 * unhappy since we're returning false */
11319 dout(10) << "recovery raced and were queued twice, ignoring!" << dendl
;
11323 const auto &missing
= pg_log
.get_missing();
11325 unsigned int num_missing
= missing
.num_missing();
11326 uint64_t num_unfound
= get_num_unfound();
11328 if (num_missing
== 0) {
11329 info
.last_complete
= info
.last_update
;
11332 if (num_missing
== num_unfound
) {
11333 // All of the missing objects we have are unfound.
11334 // Recover the replicas.
11335 started
= recover_replicas(max
, handle
);
11338 // We still have missing objects that we should grab from replicas.
11339 started
+= recover_primary(max
, handle
);
11341 if (!started
&& num_unfound
!= get_num_unfound()) {
11342 // second chance to recovery replicas
11343 started
= recover_replicas(max
, handle
);
11347 work_in_progress
= true;
11349 bool deferred_backfill
= false;
11350 if (recovering
.empty() &&
11351 state_test(PG_STATE_BACKFILL
) &&
11352 !backfill_targets
.empty() && started
< max
&&
11353 missing
.num_missing() == 0 &&
11354 waiting_on_backfill
.empty()) {
11355 if (get_osdmap()->test_flag(CEPH_OSDMAP_NOBACKFILL
)) {
11356 dout(10) << "deferring backfill due to NOBACKFILL" << dendl
;
11357 deferred_backfill
= true;
11358 } else if (get_osdmap()->test_flag(CEPH_OSDMAP_NOREBALANCE
) &&
11360 dout(10) << "deferring backfill due to NOREBALANCE" << dendl
;
11361 deferred_backfill
= true;
11362 } else if (!backfill_reserved
) {
11363 dout(10) << "deferring backfill due to !backfill_reserved" << dendl
;
11364 if (!backfill_reserving
) {
11365 dout(10) << "queueing RequestBackfill" << dendl
;
11366 backfill_reserving
= true;
11367 queue_peering_event(
11369 std::make_shared
<CephPeeringEvt
>(
11370 get_osdmap()->get_epoch(),
11371 get_osdmap()->get_epoch(),
11372 RequestBackfill())));
11374 deferred_backfill
= true;
11376 started
+= recover_backfill(max
- started
, handle
, &work_in_progress
);
11380 dout(10) << " started " << started
<< dendl
;
11381 osd
->logger
->inc(l_osd_rop
, started
);
11383 if (!recovering
.empty() ||
11384 work_in_progress
|| recovery_ops_active
> 0 || deferred_backfill
)
11385 return work_in_progress
;
11387 assert(recovering
.empty());
11388 assert(recovery_ops_active
== 0);
11390 dout(10) << __func__
<< " needs_recovery: "
11391 << missing_loc
.get_needs_recovery()
11393 dout(10) << __func__
<< " missing_loc: "
11394 << missing_loc
.get_missing_locs()
11396 int unfound
= get_num_unfound();
11398 dout(10) << " still have " << unfound
<< " unfound" << dendl
;
11399 return work_in_progress
;
11402 if (missing
.num_missing() > 0) {
11403 // this shouldn't happen!
11404 osd
->clog
->error() << info
.pgid
<< " Unexpected Error: recovery ending with "
11405 << missing
.num_missing() << ": " << missing
.get_items();
11406 return work_in_progress
;
11409 if (needs_recovery()) {
11410 // this shouldn't happen!
11411 // We already checked num_missing() so we must have missing replicas
11412 osd
->clog
->error() << info
.pgid
11413 << " Unexpected Error: recovery ending with missing replicas";
11414 return work_in_progress
;
11417 if (state_test(PG_STATE_RECOVERING
)) {
11418 state_clear(PG_STATE_RECOVERING
);
11419 state_clear(PG_STATE_FORCED_RECOVERY
);
11420 if (needs_backfill()) {
11421 dout(10) << "recovery done, queuing backfill" << dendl
;
11422 queue_peering_event(
11424 std::make_shared
<CephPeeringEvt
>(
11425 get_osdmap()->get_epoch(),
11426 get_osdmap()->get_epoch(),
11427 RequestBackfill())));
11429 dout(10) << "recovery done, no backfill" << dendl
;
11430 eio_errors_to_process
= false;
11431 state_clear(PG_STATE_FORCED_BACKFILL
);
11432 queue_peering_event(
11434 std::make_shared
<CephPeeringEvt
>(
11435 get_osdmap()->get_epoch(),
11436 get_osdmap()->get_epoch(),
11437 AllReplicasRecovered())));
11439 } else { // backfilling
11440 state_clear(PG_STATE_BACKFILL
);
11441 state_clear(PG_STATE_FORCED_BACKFILL
);
11442 state_clear(PG_STATE_FORCED_RECOVERY
);
11443 dout(10) << "recovery done, backfill done" << dendl
;
11444 eio_errors_to_process
= false;
11445 queue_peering_event(
11447 std::make_shared
<CephPeeringEvt
>(
11448 get_osdmap()->get_epoch(),
11449 get_osdmap()->get_epoch(),
11457 * do one recovery op.
11458 * return true if done, false if nothing left to do.
11460 uint64_t PrimaryLogPG::recover_primary(uint64_t max
, ThreadPool::TPHandle
&handle
)
11462 assert(is_primary());
11464 const auto &missing
= pg_log
.get_missing();
11466 dout(10) << "recover_primary recovering " << recovering
.size()
11467 << " in pg" << dendl
;
11468 dout(10) << "recover_primary " << missing
<< dendl
;
11469 dout(25) << "recover_primary " << missing
.get_items() << dendl
;
11472 pg_log_entry_t
*latest
= 0;
11473 unsigned started
= 0;
11476 PGBackend::RecoveryHandle
*h
= pgbackend
->open_recovery_op();
11477 map
<version_t
, hobject_t
>::const_iterator p
=
11478 missing
.get_rmissing().lower_bound(pg_log
.get_log().last_requested
);
11479 while (p
!= missing
.get_rmissing().end()) {
11480 handle
.reset_tp_timeout();
11482 version_t v
= p
->first
;
11484 if (pg_log
.get_log().objects
.count(p
->second
)) {
11485 latest
= pg_log
.get_log().objects
.find(p
->second
)->second
;
11486 assert(latest
->is_update() || latest
->is_delete());
11487 soid
= latest
->soid
;
11492 const pg_missing_item
& item
= missing
.get_items().find(p
->second
)->second
;
11495 hobject_t head
= soid
.get_head();
11497 eversion_t need
= item
.need
;
11499 dout(10) << "recover_primary "
11500 << soid
<< " " << item
.need
11501 << (missing
.is_missing(soid
) ? " (missing)":"")
11502 << (missing
.is_missing(head
) ? " (missing head)":"")
11503 << (recovering
.count(soid
) ? " (recovering)":"")
11504 << (recovering
.count(head
) ? " (recovering head)":"")
11508 switch (latest
->op
) {
11509 case pg_log_entry_t::CLONE
:
11511 * Handling for this special case removed for now, until we
11512 * can correctly construct an accurate SnapSet from the old
11517 case pg_log_entry_t::LOST_REVERT
:
11519 if (item
.have
== latest
->reverting_to
) {
11520 ObjectContextRef obc
= get_object_context(soid
, true);
11522 if (obc
->obs
.oi
.version
== latest
->version
) {
11523 // I'm already reverting
11524 dout(10) << " already reverting " << soid
<< dendl
;
11526 dout(10) << " reverting " << soid
<< " to " << latest
->prior_version
<< dendl
;
11527 obc
->ondisk_write_lock();
11528 obc
->obs
.oi
.version
= latest
->version
;
11530 ObjectStore::Transaction t
;
11532 obc
->obs
.oi
.encode(
11534 get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
11535 assert(!pool
.info
.require_rollback());
11536 t
.setattr(coll
, ghobject_t(soid
), OI_ATTR
, b2
);
11538 recover_got(soid
, latest
->version
);
11539 missing_loc
.add_location(soid
, pg_whoami
);
11543 osd
->store
->queue_transaction(osr
.get(), std::move(t
),
11544 new C_OSD_AppliedRecoveredObject(this, obc
),
11545 new C_OSD_CommittedPushedObject(
11547 get_osdmap()->get_epoch(),
11548 info
.last_complete
),
11549 new C_OSD_OndiskWriteUnlock(obc
));
11554 * Pull the old version of the object. Update missing_loc here to have the location
11555 * of the version we want.
11557 * This doesn't use the usual missing_loc paths, but that's okay:
11558 * - if we have it locally, we hit the case above, and go from there.
11559 * - if we don't, we always pass through this case during recovery and set up the location
11561 * - this way we don't need to mangle the missing code to be general about needing an old
11564 eversion_t alternate_need
= latest
->reverting_to
;
11565 dout(10) << " need to pull prior_version " << alternate_need
<< " for revert " << item
<< dendl
;
11567 for (map
<pg_shard_t
, pg_missing_t
>::iterator p
= peer_missing
.begin();
11568 p
!= peer_missing
.end();
11570 if (p
->second
.is_missing(soid
, need
) &&
11571 p
->second
.get_items().at(soid
).have
== alternate_need
) {
11572 missing_loc
.add_location(soid
, p
->first
);
11574 dout(10) << " will pull " << alternate_need
<< " or " << need
11575 << " from one of " << missing_loc
.get_locations(soid
)
11583 if (!recovering
.count(soid
)) {
11584 if (recovering
.count(head
)) {
11587 int r
= recover_missing(
11588 soid
, need
, get_recovery_op_priority(), h
);
11601 if (started
>= max
)
11606 // only advance last_requested if we haven't skipped anything
11608 pg_log
.set_last_requested(v
);
11611 pgbackend
->run_recovery_op(h
, get_recovery_op_priority());
11615 bool PrimaryLogPG::primary_error(
11616 const hobject_t
& soid
, eversion_t v
)
11618 pg_log
.missing_add(soid
, v
, eversion_t());
11619 pg_log
.set_last_requested(0);
11620 missing_loc
.remove_location(soid
, pg_whoami
);
11622 assert(!actingbackfill
.empty());
11623 for (set
<pg_shard_t
>::iterator i
= actingbackfill
.begin();
11624 i
!= actingbackfill
.end();
11626 if (*i
== get_primary()) continue;
11627 pg_shard_t peer
= *i
;
11628 if (!peer_missing
[peer
].is_missing(soid
, v
)) {
11629 missing_loc
.add_location(soid
, peer
);
11630 dout(10) << info
.pgid
<< " unexpectedly missing " << soid
<< " v" << v
11631 << ", there should be a copy on shard " << peer
<< dendl
;
11636 osd
->clog
->error() << info
.pgid
<< " missing primary copy of " << soid
<< ", unfound";
11638 osd
->clog
->error() << info
.pgid
<< " missing primary copy of " << soid
11639 << ", will try copies on " << missing_loc
.get_locations(soid
);
11643 int PrimaryLogPG::prep_object_replica_deletes(
11644 const hobject_t
& soid
, eversion_t v
,
11645 PGBackend::RecoveryHandle
*h
)
11647 assert(is_primary());
11648 dout(10) << __func__
<< ": on " << soid
<< dendl
;
11650 start_recovery_op(soid
);
11651 assert(!recovering
.count(soid
));
11652 recovering
.insert(make_pair(soid
, ObjectContextRef()));
11654 pgbackend
->recover_delete_object(soid
, v
, h
);
11658 int PrimaryLogPG::prep_object_replica_pushes(
11659 const hobject_t
& soid
, eversion_t v
,
11660 PGBackend::RecoveryHandle
*h
)
11662 assert(is_primary());
11663 dout(10) << __func__
<< ": on " << soid
<< dendl
;
11665 // NOTE: we know we will get a valid oloc off of disk here.
11666 ObjectContextRef obc
= get_object_context(soid
, false);
11668 primary_error(soid
, v
);
11672 if (!obc
->get_recovery_read()) {
11673 dout(20) << "recovery delayed on " << soid
11674 << "; could not get rw_manager lock" << dendl
;
11677 dout(20) << "recovery got recovery read lock on " << soid
11681 start_recovery_op(soid
);
11682 assert(!recovering
.count(soid
));
11683 recovering
.insert(make_pair(soid
, obc
));
11685 /* We need this in case there is an in progress write on the object. In fact,
11686 * the only possible write is an update to the xattr due to a lost_revert --
11687 * a client write would be blocked since the object is degraded.
11688 * In almost all cases, therefore, this lock should be uncontended.
11690 obc
->ondisk_read_lock();
11691 int r
= pgbackend
->recover_object(
11694 ObjectContextRef(),
11695 obc
, // has snapset context
11697 obc
->ondisk_read_unlock();
11699 dout(0) << __func__
<< " Error " << r
<< " on oid " << soid
<< dendl
;
11700 primary_failed(soid
);
11701 primary_error(soid
, v
);
11707 uint64_t PrimaryLogPG::recover_replicas(uint64_t max
, ThreadPool::TPHandle
&handle
)
11709 dout(10) << __func__
<< "(" << max
<< ")" << dendl
;
11710 uint64_t started
= 0;
11712 PGBackend::RecoveryHandle
*h
= pgbackend
->open_recovery_op();
11714 // this is FAR from an optimal recovery order. pretty lame, really.
11715 assert(!actingbackfill
.empty());
11716 for (set
<pg_shard_t
>::iterator i
= actingbackfill
.begin();
11717 i
!= actingbackfill
.end();
11719 if (*i
== get_primary()) continue;
11720 pg_shard_t peer
= *i
;
11721 map
<pg_shard_t
, pg_missing_t
>::const_iterator pm
= peer_missing
.find(peer
);
11722 assert(pm
!= peer_missing
.end());
11723 map
<pg_shard_t
, pg_info_t
>::const_iterator pi
= peer_info
.find(peer
);
11724 assert(pi
!= peer_info
.end());
11725 size_t m_sz
= pm
->second
.num_missing();
11727 dout(10) << " peer osd." << peer
<< " missing " << m_sz
<< " objects." << dendl
;
11728 dout(20) << " peer osd." << peer
<< " missing " << pm
->second
.get_items() << dendl
;
11731 const pg_missing_t
&m(pm
->second
);
11732 for (map
<version_t
, hobject_t
>::const_iterator p
= m
.get_rmissing().begin();
11733 p
!= m
.get_rmissing().end() && started
< max
;
11735 handle
.reset_tp_timeout();
11736 const hobject_t
soid(p
->second
);
11738 if (missing_loc
.is_unfound(soid
)) {
11739 dout(10) << __func__
<< ": " << soid
<< " still unfound" << dendl
;
11743 if (soid
> pi
->second
.last_backfill
) {
11744 if (!recovering
.count(soid
)) {
11745 derr
<< __func__
<< ": object " << soid
<< " last_backfill " << pi
->second
.last_backfill
<< dendl
;
11746 derr
<< __func__
<< ": object added to missing set for backfill, but "
11747 << "is not in recovering, error!" << dendl
;
11753 if (recovering
.count(soid
)) {
11754 dout(10) << __func__
<< ": already recovering " << soid
<< dendl
;
11758 if (missing_loc
.is_deleted(soid
)) {
11759 dout(10) << __func__
<< ": " << soid
<< " is a delete, removing" << dendl
;
11760 map
<hobject_t
,pg_missing_item
>::const_iterator r
= m
.get_items().find(soid
);
11761 started
+= prep_object_replica_deletes(soid
, r
->second
.need
, h
);
11765 if (soid
.is_snap() && pg_log
.get_missing().is_missing(soid
.get_head())) {
11766 dout(10) << __func__
<< ": " << soid
.get_head()
11767 << " still missing on primary" << dendl
;
11771 if (soid
.is_snap() && pg_log
.get_missing().is_missing(soid
.get_snapdir())) {
11772 dout(10) << __func__
<< ": " << soid
.get_snapdir()
11773 << " still missing on primary" << dendl
;
11777 if (pg_log
.get_missing().is_missing(soid
)) {
11778 dout(10) << __func__
<< ": " << soid
<< " still missing on primary" << dendl
;
11782 dout(10) << __func__
<< ": recover_object_replicas(" << soid
<< ")" << dendl
;
11783 map
<hobject_t
,pg_missing_item
>::const_iterator r
= m
.get_items().find(soid
);
11784 started
+= prep_object_replica_pushes(soid
, r
->second
.need
,
11789 pgbackend
->run_recovery_op(h
, get_recovery_op_priority());
11793 hobject_t
PrimaryLogPG::earliest_peer_backfill() const
11795 hobject_t e
= hobject_t::get_max();
11796 for (set
<pg_shard_t
>::const_iterator i
= backfill_targets
.begin();
11797 i
!= backfill_targets
.end();
11799 pg_shard_t peer
= *i
;
11800 map
<pg_shard_t
, BackfillInterval
>::const_iterator iter
=
11801 peer_backfill_info
.find(peer
);
11802 assert(iter
!= peer_backfill_info
.end());
11803 if (iter
->second
.begin
< e
)
11804 e
= iter
->second
.begin
;
11809 bool PrimaryLogPG::all_peer_done() const
11811 // Primary hasn't got any more objects
11812 assert(backfill_info
.empty());
11814 for (set
<pg_shard_t
>::const_iterator i
= backfill_targets
.begin();
11815 i
!= backfill_targets
.end();
11817 pg_shard_t bt
= *i
;
11818 map
<pg_shard_t
, BackfillInterval
>::const_iterator piter
=
11819 peer_backfill_info
.find(bt
);
11820 assert(piter
!= peer_backfill_info
.end());
11821 const BackfillInterval
& pbi
= piter
->second
;
11822 // See if peer has more to process
11823 if (!pbi
.extends_to_end() || !pbi
.empty())
11834 * backfilled: fully pushed to replica or present in replica's missing set (both
11835 * our copy and theirs).
11837 * All objects on a backfill_target in
11838 * [MIN,peer_backfill_info[backfill_target].begin) are valid; logically-removed
11839 * objects have been actually deleted and all logically-valid objects are replicated.
11840 * There may be PG objects in this interval yet to be backfilled.
11842 * All objects in PG in [MIN,backfill_info.begin) have been backfilled to all
11843 * backfill_targets. There may be objects on backfill_target(s) yet to be deleted.
11845 * For a backfill target, all objects < MIN(peer_backfill_info[target].begin,
11846 * backfill_info.begin) in PG are backfilled. No deleted objects in this
11847 * interval remain on the backfill target.
11849 * For a backfill target, all objects <= peer_info[target].last_backfill
11850 * have been backfilled to target
11852 * There *MAY* be missing/outdated objects between last_backfill_started and
11853 * MIN(peer_backfill_info[*].begin, backfill_info.begin) in the event that client
11854 * io created objects since the last scan. For this reason, we call
11855 * update_range() again before continuing backfill.
11857 uint64_t PrimaryLogPG::recover_backfill(
11859 ThreadPool::TPHandle
&handle
, bool *work_started
)
11861 dout(10) << "recover_backfill (" << max
<< ")"
11862 << " bft=" << backfill_targets
11863 << " last_backfill_started " << last_backfill_started
11864 << (new_backfill
? " new_backfill":"")
11866 assert(!backfill_targets
.empty());
11868 // Initialize from prior backfill state
11869 if (new_backfill
) {
11870 // on_activate() was called prior to getting here
11871 assert(last_backfill_started
== earliest_backfill());
11872 new_backfill
= false;
11874 // initialize BackfillIntervals
11875 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11876 i
!= backfill_targets
.end();
11878 peer_backfill_info
[*i
].reset(peer_info
[*i
].last_backfill
);
11880 backfill_info
.reset(last_backfill_started
);
11882 backfills_in_flight
.clear();
11883 pending_backfill_updates
.clear();
11886 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11887 i
!= backfill_targets
.end();
11889 dout(10) << "peer osd." << *i
11890 << " info " << peer_info
[*i
]
11891 << " interval " << peer_backfill_info
[*i
].begin
11892 << "-" << peer_backfill_info
[*i
].end
11893 << " " << peer_backfill_info
[*i
].objects
.size() << " objects"
11897 // update our local interval to cope with recent changes
11898 backfill_info
.begin
= last_backfill_started
;
11899 update_range(&backfill_info
, handle
);
11902 vector
<boost::tuple
<hobject_t
, eversion_t
, pg_shard_t
> > to_remove
;
11903 set
<hobject_t
> add_to_stat
;
11905 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11906 i
!= backfill_targets
.end();
11908 peer_backfill_info
[*i
].trim_to(
11909 std::max(peer_info
[*i
].last_backfill
, last_backfill_started
));
11911 backfill_info
.trim_to(last_backfill_started
);
11913 PGBackend::RecoveryHandle
*h
= pgbackend
->open_recovery_op();
11914 while (ops
< max
) {
11915 if (backfill_info
.begin
<= earliest_peer_backfill() &&
11916 !backfill_info
.extends_to_end() && backfill_info
.empty()) {
11917 hobject_t next
= backfill_info
.end
;
11918 backfill_info
.reset(next
);
11919 backfill_info
.end
= hobject_t::get_max();
11920 update_range(&backfill_info
, handle
);
11921 backfill_info
.trim();
11924 dout(20) << " my backfill interval " << backfill_info
<< dendl
;
11926 bool sent_scan
= false;
11927 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11928 i
!= backfill_targets
.end();
11930 pg_shard_t bt
= *i
;
11931 BackfillInterval
& pbi
= peer_backfill_info
[bt
];
11933 dout(20) << " peer shard " << bt
<< " backfill " << pbi
<< dendl
;
11934 if (pbi
.begin
<= backfill_info
.begin
&&
11935 !pbi
.extends_to_end() && pbi
.empty()) {
11936 dout(10) << " scanning peer osd." << bt
<< " from " << pbi
.end
<< dendl
;
11937 epoch_t e
= get_osdmap()->get_epoch();
11938 MOSDPGScan
*m
= new MOSDPGScan(
11939 MOSDPGScan::OP_SCAN_GET_DIGEST
, pg_whoami
, e
, last_peering_reset
,
11940 spg_t(info
.pgid
.pgid
, bt
.shard
),
11941 pbi
.end
, hobject_t());
11942 osd
->send_message_osd_cluster(bt
.osd
, m
, get_osdmap()->get_epoch());
11943 assert(waiting_on_backfill
.find(bt
) == waiting_on_backfill
.end());
11944 waiting_on_backfill
.insert(bt
);
11949 // Count simultaneous scans as a single op and let those complete
11952 start_recovery_op(hobject_t::get_max()); // XXX: was pbi.end
11956 if (backfill_info
.empty() && all_peer_done()) {
11957 dout(10) << " reached end for both local and all peers" << dendl
;
11961 // Get object within set of peers to operate on and
11962 // the set of targets for which that object applies.
11963 hobject_t check
= earliest_peer_backfill();
11965 if (check
< backfill_info
.begin
) {
11967 set
<pg_shard_t
> check_targets
;
11968 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
11969 i
!= backfill_targets
.end();
11971 pg_shard_t bt
= *i
;
11972 BackfillInterval
& pbi
= peer_backfill_info
[bt
];
11973 if (pbi
.begin
== check
)
11974 check_targets
.insert(bt
);
11976 assert(!check_targets
.empty());
11978 dout(20) << " BACKFILL removing " << check
11979 << " from peers " << check_targets
<< dendl
;
11980 for (set
<pg_shard_t
>::iterator i
= check_targets
.begin();
11981 i
!= check_targets
.end();
11983 pg_shard_t bt
= *i
;
11984 BackfillInterval
& pbi
= peer_backfill_info
[bt
];
11985 assert(pbi
.begin
== check
);
11987 to_remove
.push_back(boost::make_tuple(check
, pbi
.objects
.begin()->second
, bt
));
11991 /* This requires a bit of explanation. We compare head against
11992 * last_backfill to determine whether to send an operation
11993 * to the replica. A single write operation can touch up to three
11994 * objects: head, the snapdir, and a new clone which sorts closer to
11995 * head than any existing clone. If last_backfill points at a clone,
11996 * the transaction won't be sent and all 3 must lie on the right side
11997 * of the line (i.e., we'll backfill them later). If last_backfill
11998 * points at snapdir, it sorts greater than head, so we send the
11999 * transaction which is correct because all three must lie to the left
12002 * If it points at head, we have a bit of an issue. If head actually
12003 * exists, no problem, because any transaction which touches snapdir
12004 * must end up creating it (and deleting head), so sending the
12005 * operation won't pose a problem -- we'll end up having to scan it,
12006 * but it'll end up being the right version so we won't bother to
12007 * rebackfill it. However, if head doesn't exist, any write on head
12008 * will remove snapdir. For a replicated pool, this isn't a problem,
12009 * ENOENT on remove isn't an issue and it's in backfill future anyway.
12010 * It only poses a problem for EC pools, because we never just delete
12011 * an object, we rename it into a rollback object. That operation
12012 * will end up crashing the osd with ENOENT. Tolerating the failure
12013 * wouldn't work either, even if snapdir exists, we'd be creating a
12014 * rollback object past the last_backfill line which wouldn't get
12015 * cleaned up (no rollback objects past the last_backfill line is an
12016 * existing important invariant). Thus, let's avoid the whole issue
12017 * by just not updating last_backfill_started here if head doesn't
12018 * exist and snapdir does. We aren't using up a recovery count here,
12019 * so we're going to recover snapdir immediately anyway. We'll only
12020 * fail "backward" if we fail to get the rw lock and that just means
12021 * we'll re-process this section of the hash space again.
12023 * I'm choosing this hack here because the really "correct" answer is
12024 * going to be to unify snapdir and head into a single object (a
12025 * snapdir is really just a confusing way to talk about head existing
12026 * as a whiteout), but doing that is going to be a somewhat larger
12029 * @see http://tracker.ceph.com/issues/17668
12031 if (!(check
.is_head() &&
12032 backfill_info
.begin
.is_snapdir() &&
12033 check
== backfill_info
.begin
.get_head()))
12034 last_backfill_started
= check
;
12036 // Don't increment ops here because deletions
12037 // are cheap and not replied to unlike real recovery_ops,
12038 // and we can't increment ops without requeueing ourself
12041 eversion_t
& obj_v
= backfill_info
.objects
.begin()->second
;
12043 vector
<pg_shard_t
> need_ver_targs
, missing_targs
, keep_ver_targs
, skip_targs
;
12044 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
12045 i
!= backfill_targets
.end();
12047 pg_shard_t bt
= *i
;
12048 BackfillInterval
& pbi
= peer_backfill_info
[bt
];
12049 // Find all check peers that have the wrong version
12050 if (check
== backfill_info
.begin
&& check
== pbi
.begin
) {
12051 if (pbi
.objects
.begin()->second
!= obj_v
) {
12052 need_ver_targs
.push_back(bt
);
12054 keep_ver_targs
.push_back(bt
);
12057 pg_info_t
& pinfo
= peer_info
[bt
];
12059 // Only include peers that we've caught up to their backfill line
12060 // otherwise, they only appear to be missing this object
12061 // because their pbi.begin > backfill_info.begin.
12062 if (backfill_info
.begin
> pinfo
.last_backfill
)
12063 missing_targs
.push_back(bt
);
12065 skip_targs
.push_back(bt
);
12069 if (!keep_ver_targs
.empty()) {
12070 // These peers have version obj_v
12071 dout(20) << " BACKFILL keeping " << check
12072 << " with ver " << obj_v
12073 << " on peers " << keep_ver_targs
<< dendl
;
12074 //assert(!waiting_for_degraded_object.count(check));
12076 if (!need_ver_targs
.empty() || !missing_targs
.empty()) {
12077 ObjectContextRef obc
= get_object_context(backfill_info
.begin
, false);
12079 if (obc
->get_recovery_read()) {
12080 if (!need_ver_targs
.empty()) {
12081 dout(20) << " BACKFILL replacing " << check
12082 << " with ver " << obj_v
12083 << " to peers " << need_ver_targs
<< dendl
;
12085 if (!missing_targs
.empty()) {
12086 dout(20) << " BACKFILL pushing " << backfill_info
.begin
12087 << " with ver " << obj_v
12088 << " to peers " << missing_targs
<< dendl
;
12090 vector
<pg_shard_t
> all_push
= need_ver_targs
;
12091 all_push
.insert(all_push
.end(), missing_targs
.begin(), missing_targs
.end());
12093 handle
.reset_tp_timeout();
12094 int r
= prep_backfill_object_push(backfill_info
.begin
, obj_v
, obc
, all_push
, h
);
12096 *work_started
= true;
12097 dout(0) << __func__
<< " Error " << r
<< " trying to backfill " << backfill_info
.begin
<< dendl
;
12102 *work_started
= true;
12103 dout(20) << "backfill blocking on " << backfill_info
.begin
12104 << "; could not get rw_manager lock" << dendl
;
12108 dout(20) << "need_ver_targs=" << need_ver_targs
12109 << " keep_ver_targs=" << keep_ver_targs
<< dendl
;
12110 dout(20) << "backfill_targets=" << backfill_targets
12111 << " missing_targs=" << missing_targs
12112 << " skip_targs=" << skip_targs
<< dendl
;
12114 last_backfill_started
= backfill_info
.begin
;
12115 add_to_stat
.insert(backfill_info
.begin
); // XXX: Only one for all pushes?
12116 backfill_info
.pop_front();
12117 vector
<pg_shard_t
> check_targets
= need_ver_targs
;
12118 check_targets
.insert(check_targets
.end(), keep_ver_targs
.begin(), keep_ver_targs
.end());
12119 for (vector
<pg_shard_t
>::iterator i
= check_targets
.begin();
12120 i
!= check_targets
.end();
12122 pg_shard_t bt
= *i
;
12123 BackfillInterval
& pbi
= peer_backfill_info
[bt
];
12129 hobject_t backfill_pos
=
12130 std::min(backfill_info
.begin
, earliest_peer_backfill());
12132 for (set
<hobject_t
>::iterator i
= add_to_stat
.begin();
12133 i
!= add_to_stat
.end();
12135 ObjectContextRef obc
= get_object_context(*i
, false);
12138 add_object_context_to_pg_stat(obc
, &stat
);
12139 pending_backfill_updates
[*i
] = stat
;
12141 if (HAVE_FEATURE(get_min_upacting_features(), SERVER_LUMINOUS
)) {
12142 map
<pg_shard_t
,MOSDPGBackfillRemove
*> reqs
;
12143 for (unsigned i
= 0; i
< to_remove
.size(); ++i
) {
12144 handle
.reset_tp_timeout();
12145 const hobject_t
& oid
= to_remove
[i
].get
<0>();
12146 eversion_t v
= to_remove
[i
].get
<1>();
12147 pg_shard_t peer
= to_remove
[i
].get
<2>();
12148 MOSDPGBackfillRemove
*m
;
12149 auto it
= reqs
.find(peer
);
12150 if (it
!= reqs
.end()) {
12153 m
= reqs
[peer
] = new MOSDPGBackfillRemove(
12154 spg_t(info
.pgid
.pgid
, peer
.shard
),
12155 get_osdmap()->get_epoch());
12157 m
->ls
.push_back(make_pair(oid
, v
));
12159 if (oid
<= last_backfill_started
)
12160 pending_backfill_updates
[oid
]; // add empty stat!
12162 for (auto p
: reqs
) {
12163 osd
->send_message_osd_cluster(p
.first
.osd
, p
.second
,
12164 get_osdmap()->get_epoch());
12167 // for jewel targets
12168 for (unsigned i
= 0; i
< to_remove
.size(); ++i
) {
12169 handle
.reset_tp_timeout();
12171 // ordered before any subsequent updates
12172 send_remove_op(to_remove
[i
].get
<0>(), to_remove
[i
].get
<1>(),
12173 to_remove
[i
].get
<2>());
12175 if (to_remove
[i
].get
<0>() <= last_backfill_started
)
12176 pending_backfill_updates
[to_remove
[i
].get
<0>()]; // add empty stat!
12180 pgbackend
->run_recovery_op(h
, get_recovery_op_priority());
12182 dout(5) << "backfill_pos is " << backfill_pos
<< dendl
;
12183 for (set
<hobject_t
>::iterator i
= backfills_in_flight
.begin();
12184 i
!= backfills_in_flight
.end();
12186 dout(20) << *i
<< " is still in flight" << dendl
;
12189 hobject_t next_backfill_to_complete
= backfills_in_flight
.empty() ?
12190 backfill_pos
: *(backfills_in_flight
.begin());
12191 hobject_t new_last_backfill
= earliest_backfill();
12192 dout(10) << "starting new_last_backfill at " << new_last_backfill
<< dendl
;
12193 for (map
<hobject_t
, pg_stat_t
>::iterator i
=
12194 pending_backfill_updates
.begin();
12195 i
!= pending_backfill_updates
.end() &&
12196 i
->first
< next_backfill_to_complete
;
12197 pending_backfill_updates
.erase(i
++)) {
12198 dout(20) << " pending_backfill_update " << i
->first
<< dendl
;
12199 assert(i
->first
> new_last_backfill
);
12200 for (set
<pg_shard_t
>::iterator j
= backfill_targets
.begin();
12201 j
!= backfill_targets
.end();
12203 pg_shard_t bt
= *j
;
12204 pg_info_t
& pinfo
= peer_info
[bt
];
12205 //Add stats to all peers that were missing object
12206 if (i
->first
> pinfo
.last_backfill
)
12207 pinfo
.stats
.add(i
->second
);
12209 new_last_backfill
= i
->first
;
12211 dout(10) << "possible new_last_backfill at " << new_last_backfill
<< dendl
;
12213 assert(!pending_backfill_updates
.empty() ||
12214 new_last_backfill
== last_backfill_started
);
12215 if (pending_backfill_updates
.empty() &&
12216 backfill_pos
.is_max()) {
12217 assert(backfills_in_flight
.empty());
12218 new_last_backfill
= backfill_pos
;
12219 last_backfill_started
= backfill_pos
;
12221 dout(10) << "final new_last_backfill at " << new_last_backfill
<< dendl
;
12223 // If new_last_backfill == MAX, then we will send OP_BACKFILL_FINISH to
12224 // all the backfill targets. Otherwise, we will move last_backfill up on
12225 // those targets need it and send OP_BACKFILL_PROGRESS to them.
12226 for (set
<pg_shard_t
>::iterator i
= backfill_targets
.begin();
12227 i
!= backfill_targets
.end();
12229 pg_shard_t bt
= *i
;
12230 pg_info_t
& pinfo
= peer_info
[bt
];
12232 if (new_last_backfill
> pinfo
.last_backfill
) {
12233 pinfo
.set_last_backfill(new_last_backfill
);
12234 epoch_t e
= get_osdmap()->get_epoch();
12235 MOSDPGBackfill
*m
= NULL
;
12236 if (pinfo
.last_backfill
.is_max()) {
12237 m
= new MOSDPGBackfill(
12238 MOSDPGBackfill::OP_BACKFILL_FINISH
,
12240 last_peering_reset
,
12241 spg_t(info
.pgid
.pgid
, bt
.shard
));
12242 // Use default priority here, must match sub_op priority
12243 /* pinfo.stats might be wrong if we did log-based recovery on the
12244 * backfilled portion in addition to continuing backfill.
12246 pinfo
.stats
= info
.stats
;
12247 start_recovery_op(hobject_t::get_max());
12249 m
= new MOSDPGBackfill(
12250 MOSDPGBackfill::OP_BACKFILL_PROGRESS
,
12252 last_peering_reset
,
12253 spg_t(info
.pgid
.pgid
, bt
.shard
));
12254 // Use default priority here, must match sub_op priority
12256 m
->last_backfill
= pinfo
.last_backfill
;
12257 m
->stats
= pinfo
.stats
;
12258 osd
->send_message_osd_cluster(bt
.osd
, m
, get_osdmap()->get_epoch());
12259 dout(10) << " peer " << bt
12260 << " num_objects now " << pinfo
.stats
.stats
.sum
.num_objects
12261 << " / " << info
.stats
.stats
.sum
.num_objects
<< dendl
;
12266 *work_started
= true;
12270 int PrimaryLogPG::prep_backfill_object_push(
12271 hobject_t oid
, eversion_t v
,
12272 ObjectContextRef obc
,
12273 vector
<pg_shard_t
> peers
,
12274 PGBackend::RecoveryHandle
*h
)
12276 dout(10) << __func__
<< " " << oid
<< " v " << v
<< " to peers " << peers
<< dendl
;
12277 assert(!peers
.empty());
12279 backfills_in_flight
.insert(oid
);
12280 for (unsigned int i
= 0 ; i
< peers
.size(); ++i
) {
12281 map
<pg_shard_t
, pg_missing_t
>::iterator bpm
= peer_missing
.find(peers
[i
]);
12282 assert(bpm
!= peer_missing
.end());
12283 bpm
->second
.add(oid
, eversion_t(), eversion_t(), false);
12286 assert(!recovering
.count(oid
));
12288 start_recovery_op(oid
);
12289 recovering
.insert(make_pair(oid
, obc
));
12291 // We need to take the read_lock here in order to flush in-progress writes
12292 obc
->ondisk_read_lock();
12293 int r
= pgbackend
->recover_object(
12296 ObjectContextRef(),
12299 obc
->ondisk_read_unlock();
12301 dout(0) << __func__
<< " Error " << r
<< " on oid " << oid
<< dendl
;
12302 primary_failed(oid
);
12303 primary_error(oid
, v
);
12304 backfills_in_flight
.erase(oid
);
12305 missing_loc
.add_missing(oid
, v
, eversion_t());
12310 void PrimaryLogPG::update_range(
12311 BackfillInterval
*bi
,
12312 ThreadPool::TPHandle
&handle
)
12314 int local_min
= cct
->_conf
->osd_backfill_scan_min
;
12315 int local_max
= cct
->_conf
->osd_backfill_scan_max
;
12317 if (bi
->version
< info
.log_tail
) {
12318 dout(10) << __func__
<< ": bi is old, rescanning local backfill_info"
12320 if (last_update_applied
>= info
.log_tail
) {
12321 bi
->version
= last_update_applied
;
12324 bi
->version
= info
.last_update
;
12326 scan_range(local_min
, local_max
, bi
, handle
);
12329 if (bi
->version
>= projected_last_update
) {
12330 dout(10) << __func__
<< ": bi is current " << dendl
;
12331 assert(bi
->version
== projected_last_update
);
12332 } else if (bi
->version
>= info
.log_tail
) {
12333 if (pg_log
.get_log().empty() && projected_log
.empty()) {
12334 /* Because we don't move log_tail on split, the log might be
12335 * empty even if log_tail != last_update. However, the only
12336 * way to get here with an empty log is if log_tail is actually
12337 * eversion_t(), because otherwise the entry which changed
12338 * last_update since the last scan would have to be present.
12340 assert(bi
->version
== eversion_t());
12344 dout(10) << __func__
<< ": bi is old, (" << bi
->version
12345 << ") can be updated with log to projected_last_update "
12346 << projected_last_update
<< dendl
;
12348 auto func
= [&](const pg_log_entry_t
&e
) {
12349 dout(10) << __func__
<< ": updating from version " << e
.version
12351 const hobject_t
&soid
= e
.soid
;
12352 if (soid
>= bi
->begin
&&
12354 if (e
.is_update()) {
12355 dout(10) << __func__
<< ": " << e
.soid
<< " updated to version "
12356 << e
.version
<< dendl
;
12357 bi
->objects
.erase(e
.soid
);
12358 bi
->objects
.insert(
12362 } else if (e
.is_delete()) {
12363 dout(10) << __func__
<< ": " << e
.soid
<< " removed" << dendl
;
12364 bi
->objects
.erase(e
.soid
);
12368 dout(10) << "scanning pg log first" << dendl
;
12369 pg_log
.get_log().scan_log_after(bi
->version
, func
);
12370 dout(10) << "scanning projected log" << dendl
;
12371 projected_log
.scan_log_after(bi
->version
, func
);
12372 bi
->version
= projected_last_update
;
12374 assert(0 == "scan_range should have raised bi->version past log_tail");
12378 void PrimaryLogPG::scan_range(
12379 int min
, int max
, BackfillInterval
*bi
,
12380 ThreadPool::TPHandle
&handle
)
12382 assert(is_locked());
12383 dout(10) << "scan_range from " << bi
->begin
<< dendl
;
12384 bi
->clear_objects();
12386 vector
<hobject_t
> ls
;
12388 int r
= pgbackend
->objects_list_partial(bi
->begin
, min
, max
, &ls
, &bi
->end
);
12390 dout(10) << " got " << ls
.size() << " items, next " << bi
->end
<< dendl
;
12391 dout(20) << ls
<< dendl
;
12393 for (vector
<hobject_t
>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
) {
12394 handle
.reset_tp_timeout();
12395 ObjectContextRef obc
;
12397 obc
= object_contexts
.lookup(*p
);
12399 bi
->objects
[*p
] = obc
->obs
.oi
.version
;
12400 dout(20) << " " << *p
<< " " << obc
->obs
.oi
.version
<< dendl
;
12403 int r
= pgbackend
->objects_get_attr(*p
, OI_ATTR
, &bl
);
12405 /* If the object does not exist here, it must have been removed
12406 * between the collection_list_partial and here. This can happen
12407 * for the first item in the range, which is usually last_backfill.
12413 object_info_t
oi(bl
);
12414 bi
->objects
[*p
] = oi
.version
;
12415 dout(20) << " " << *p
<< " " << oi
.version
<< dendl
;
12423 * verifies that stray objects have been deleted
12425 void PrimaryLogPG::check_local()
12427 dout(10) << __func__
<< dendl
;
12429 assert(info
.last_update
>= pg_log
.get_tail()); // otherwise we need some help!
12431 if (!cct
->_conf
->osd_debug_verify_stray_on_activate
)
12434 // just scan the log.
12435 set
<hobject_t
> did
;
12436 for (list
<pg_log_entry_t
>::const_reverse_iterator p
= pg_log
.get_log().log
.rbegin();
12437 p
!= pg_log
.get_log().log
.rend();
12439 if (did
.count(p
->soid
))
12441 did
.insert(p
->soid
);
12443 if (p
->is_delete() && !is_missing_object(p
->soid
)) {
12444 dout(10) << " checking " << p
->soid
12445 << " at " << p
->version
<< dendl
;
12447 int r
= osd
->store
->stat(
12449 ghobject_t(p
->soid
, ghobject_t::NO_GEN
, pg_whoami
.shard
),
12451 if (r
!= -ENOENT
) {
12452 derr
<< __func__
<< " " << p
->soid
<< " exists, but should have been "
12453 << "deleted" << dendl
;
12454 assert(0 == "erroneously present object");
12457 // ignore old(+missing) objects
12464 // ===========================
12467 hobject_t
PrimaryLogPG::get_hit_set_current_object(utime_t stamp
)
12470 ss
<< "hit_set_" << info
.pgid
.pgid
<< "_current_" << stamp
;
12471 hobject_t
hoid(sobject_t(ss
.str(), CEPH_NOSNAP
), "",
12472 info
.pgid
.ps(), info
.pgid
.pool(),
12473 cct
->_conf
->osd_hit_set_namespace
);
12474 dout(20) << __func__
<< " " << hoid
<< dendl
;
12478 hobject_t
PrimaryLogPG::get_hit_set_archive_object(utime_t start
,
12483 ss
<< "hit_set_" << info
.pgid
.pgid
<< "_archive_";
12485 start
.gmtime(ss
) << "_";
12488 start
.localtime(ss
) << "_";
12491 hobject_t
hoid(sobject_t(ss
.str(), CEPH_NOSNAP
), "",
12492 info
.pgid
.ps(), info
.pgid
.pool(),
12493 cct
->_conf
->osd_hit_set_namespace
);
12494 dout(20) << __func__
<< " " << hoid
<< dendl
;
12498 void PrimaryLogPG::hit_set_clear()
12500 dout(20) << __func__
<< dendl
;
12502 hit_set_start_stamp
= utime_t();
12505 void PrimaryLogPG::hit_set_setup()
12507 if (!is_active() ||
12513 if (is_active() && is_primary() &&
12514 (!pool
.info
.hit_set_count
||
12515 !pool
.info
.hit_set_period
||
12516 pool
.info
.hit_set_params
.get_type() == HitSet::TYPE_NONE
)) {
12519 // only primary is allowed to remove all the hit set objects
12520 hit_set_remove_all();
12524 // FIXME: discard any previous data for now
12527 // include any writes we know about from the pg log. this doesn't
12528 // capture reads, but it is better than nothing!
12529 hit_set_apply_log();
12532 void PrimaryLogPG::hit_set_remove_all()
12534 // If any archives are degraded we skip this
12535 for (list
<pg_hit_set_info_t
>::iterator p
= info
.hit_set
.history
.begin();
12536 p
!= info
.hit_set
.history
.end();
12538 hobject_t aoid
= get_hit_set_archive_object(p
->begin
, p
->end
, p
->using_gmt
);
12540 // Once we hit a degraded object just skip
12541 if (is_degraded_or_backfilling_object(aoid
))
12543 if (scrubber
.write_blocked_by_scrub(aoid
))
12547 if (!info
.hit_set
.history
.empty()) {
12548 list
<pg_hit_set_info_t
>::reverse_iterator p
= info
.hit_set
.history
.rbegin();
12549 assert(p
!= info
.hit_set
.history
.rend());
12550 hobject_t oid
= get_hit_set_archive_object(p
->begin
, p
->end
, p
->using_gmt
);
12551 assert(!is_degraded_or_backfilling_object(oid
));
12552 ObjectContextRef obc
= get_object_context(oid
, false);
12555 OpContextUPtr ctx
= simple_opc_create(obc
);
12556 ctx
->at_version
= get_next_version();
12557 ctx
->updated_hset_history
= info
.hit_set
;
12558 utime_t now
= ceph_clock_now();
12560 hit_set_trim(ctx
, 0);
12561 simple_opc_submit(std::move(ctx
));
12564 info
.hit_set
= pg_hit_set_history_t();
12566 agent_state
->discard_hit_sets();
12570 void PrimaryLogPG::hit_set_create()
12572 utime_t now
= ceph_clock_now();
12573 // make a copy of the params to modify
12574 HitSet::Params
params(pool
.info
.hit_set_params
);
12576 dout(20) << __func__
<< " " << params
<< dendl
;
12577 if (pool
.info
.hit_set_params
.get_type() == HitSet::TYPE_BLOOM
) {
12578 BloomHitSet::Params
*p
=
12579 static_cast<BloomHitSet::Params
*>(params
.impl
.get());
12581 // convert false positive rate so it holds up across the full period
12582 p
->set_fpp(p
->get_fpp() / pool
.info
.hit_set_count
);
12583 if (p
->get_fpp() <= 0.0)
12584 p
->set_fpp(.01); // fpp cannot be zero!
12586 // if we don't have specified size, estimate target size based on the
12588 if (p
->target_size
== 0 && hit_set
) {
12589 utime_t dur
= now
- hit_set_start_stamp
;
12590 unsigned unique
= hit_set
->approx_unique_insert_count();
12591 dout(20) << __func__
<< " previous set had approx " << unique
12592 << " unique items over " << dur
<< " seconds" << dendl
;
12593 p
->target_size
= (double)unique
* (double)pool
.info
.hit_set_period
12596 if (p
->target_size
<
12597 static_cast<uint64_t>(cct
->_conf
->osd_hit_set_min_size
))
12598 p
->target_size
= cct
->_conf
->osd_hit_set_min_size
;
12601 > static_cast<uint64_t>(cct
->_conf
->osd_hit_set_max_size
))
12602 p
->target_size
= cct
->_conf
->osd_hit_set_max_size
;
12604 p
->seed
= now
.sec();
12606 dout(10) << __func__
<< " target_size " << p
->target_size
12607 << " fpp " << p
->get_fpp() << dendl
;
12609 hit_set
.reset(new HitSet(params
));
12610 hit_set_start_stamp
= now
;
12614 * apply log entries to set
12616 * this would only happen after peering, to at least capture writes
12617 * during an interval that was potentially lost.
12619 bool PrimaryLogPG::hit_set_apply_log()
12624 eversion_t to
= info
.last_update
;
12625 eversion_t from
= info
.hit_set
.current_last_update
;
12627 dout(20) << __func__
<< " no update" << dendl
;
12631 dout(20) << __func__
<< " " << to
<< " .. " << info
.last_update
<< dendl
;
12632 list
<pg_log_entry_t
>::const_reverse_iterator p
= pg_log
.get_log().log
.rbegin();
12633 while (p
!= pg_log
.get_log().log
.rend() && p
->version
> to
)
12635 while (p
!= pg_log
.get_log().log
.rend() && p
->version
> from
) {
12636 hit_set
->insert(p
->soid
);
12643 void PrimaryLogPG::hit_set_persist()
12645 dout(10) << __func__
<< dendl
;
12647 unsigned max
= pool
.info
.hit_set_count
;
12649 utime_t now
= ceph_clock_now();
12652 // If any archives are degraded we skip this persist request
12653 // account for the additional entry being added below
12654 for (list
<pg_hit_set_info_t
>::iterator p
= info
.hit_set
.history
.begin();
12655 p
!= info
.hit_set
.history
.end();
12657 hobject_t aoid
= get_hit_set_archive_object(p
->begin
, p
->end
, p
->using_gmt
);
12659 // Once we hit a degraded object just skip further trim
12660 if (is_degraded_or_backfilling_object(aoid
))
12662 if (scrubber
.write_blocked_by_scrub(aoid
))
12666 // If backfill is in progress and we could possibly overlap with the
12667 // hit_set_* objects, back off. Since these all have
12668 // hobject_t::hash set to pgid.ps(), and those sort first, we can
12669 // look just at that. This is necessary because our transactions
12670 // may include a modify of the new hit_set *and* a delete of the
12671 // old one, and this may span the backfill boundary.
12672 for (set
<pg_shard_t
>::iterator p
= backfill_targets
.begin();
12673 p
!= backfill_targets
.end();
12675 assert(peer_info
.count(*p
));
12676 const pg_info_t
& pi
= peer_info
[*p
];
12677 if (pi
.last_backfill
== hobject_t() ||
12678 pi
.last_backfill
.get_hash() == info
.pgid
.ps()) {
12679 dout(10) << __func__
<< " backfill target osd." << *p
12680 << " last_backfill has not progressed past pgid ps"
12687 pg_hit_set_info_t new_hset
= pg_hit_set_info_t(pool
.info
.use_gmt_hitset
);
12688 new_hset
.begin
= hit_set_start_stamp
;
12689 new_hset
.end
= now
;
12690 oid
= get_hit_set_archive_object(
12693 new_hset
.using_gmt
);
12695 // If the current object is degraded we skip this persist request
12696 if (scrubber
.write_blocked_by_scrub(oid
))
12700 ::encode(*hit_set
, bl
);
12701 dout(20) << __func__
<< " archive " << oid
<< dendl
;
12704 agent_state
->add_hit_set(new_hset
.begin
, hit_set
);
12705 uint32_t size
= agent_state
->hit_set_map
.size();
12706 if (size
>= pool
.info
.hit_set_count
) {
12707 size
= pool
.info
.hit_set_count
> 0 ? pool
.info
.hit_set_count
- 1: 0;
12709 hit_set_in_memory_trim(size
);
12712 ObjectContextRef obc
= get_object_context(oid
, true);
12713 OpContextUPtr ctx
= simple_opc_create(obc
);
12715 ctx
->at_version
= get_next_version();
12716 ctx
->updated_hset_history
= info
.hit_set
;
12717 pg_hit_set_history_t
&updated_hit_set_hist
= *(ctx
->updated_hset_history
);
12719 updated_hit_set_hist
.current_last_update
= info
.last_update
;
12720 new_hset
.version
= ctx
->at_version
;
12722 updated_hit_set_hist
.history
.push_back(new_hset
);
12725 // fabricate an object_info_t and SnapSet
12726 obc
->obs
.oi
.version
= ctx
->at_version
;
12727 obc
->obs
.oi
.mtime
= now
;
12728 obc
->obs
.oi
.size
= bl
.length();
12729 obc
->obs
.exists
= true;
12730 obc
->obs
.oi
.set_data_digest(bl
.crc32c(-1));
12732 ctx
->new_obs
= obc
->obs
;
12734 obc
->ssc
->snapset
.head_exists
= true;
12735 ctx
->new_snapset
= obc
->ssc
->snapset
;
12737 ctx
->delta_stats
.num_objects
++;
12738 ctx
->delta_stats
.num_objects_hit_set_archive
++;
12739 ctx
->delta_stats
.num_bytes
+= bl
.length();
12740 ctx
->delta_stats
.num_bytes_hit_set_archive
+= bl
.length();
12743 ::encode(ctx
->new_snapset
, bss
);
12744 bufferlist
boi(sizeof(ctx
->new_obs
.oi
));
12745 ::encode(ctx
->new_obs
.oi
, boi
,
12746 get_osdmap()->get_features(CEPH_ENTITY_TYPE_OSD
, nullptr));
12748 ctx
->op_t
->create(oid
);
12750 ctx
->op_t
->write(oid
, 0, bl
.length(), bl
, 0);
12752 map
<string
, bufferlist
> attrs
;
12753 attrs
[OI_ATTR
].claim(boi
);
12754 attrs
[SS_ATTR
].claim(bss
);
12755 setattrs_maybe_cache(ctx
->obc
, ctx
.get(), ctx
->op_t
.get(), attrs
);
12756 ctx
->log
.push_back(
12758 pg_log_entry_t::MODIFY
,
12768 hit_set_trim(ctx
, max
);
12770 simple_opc_submit(std::move(ctx
));
12773 void PrimaryLogPG::hit_set_trim(OpContextUPtr
&ctx
, unsigned max
)
12775 assert(ctx
->updated_hset_history
);
12776 pg_hit_set_history_t
&updated_hit_set_hist
=
12777 *(ctx
->updated_hset_history
);
12778 for (unsigned num
= updated_hit_set_hist
.history
.size(); num
> max
; --num
) {
12779 list
<pg_hit_set_info_t
>::iterator p
= updated_hit_set_hist
.history
.begin();
12780 assert(p
!= updated_hit_set_hist
.history
.end());
12781 hobject_t oid
= get_hit_set_archive_object(p
->begin
, p
->end
, p
->using_gmt
);
12783 assert(!is_degraded_or_backfilling_object(oid
));
12785 dout(20) << __func__
<< " removing " << oid
<< dendl
;
12786 ++ctx
->at_version
.version
;
12787 ctx
->log
.push_back(
12788 pg_log_entry_t(pg_log_entry_t::DELETE
,
12797 ctx
->op_t
->remove(oid
);
12798 updated_hit_set_hist
.history
.pop_front();
12800 ObjectContextRef obc
= get_object_context(oid
, false);
12802 --ctx
->delta_stats
.num_objects
;
12803 --ctx
->delta_stats
.num_objects_hit_set_archive
;
12804 ctx
->delta_stats
.num_bytes
-= obc
->obs
.oi
.size
;
12805 ctx
->delta_stats
.num_bytes_hit_set_archive
-= obc
->obs
.oi
.size
;
12809 void PrimaryLogPG::hit_set_in_memory_trim(uint32_t max_in_memory
)
12811 while (agent_state
->hit_set_map
.size() > max_in_memory
) {
12812 agent_state
->remove_oldest_hit_set();
12817 // =======================================
12820 void PrimaryLogPG::agent_setup()
12822 assert(is_locked());
12823 if (!is_active() ||
12825 pool
.info
.cache_mode
== pg_pool_t::CACHEMODE_NONE
||
12826 pool
.info
.tier_of
< 0 ||
12827 !get_osdmap()->have_pg_pool(pool
.info
.tier_of
)) {
12831 if (!agent_state
) {
12832 agent_state
.reset(new TierAgentState
);
12834 // choose random starting position
12835 agent_state
->position
= hobject_t();
12836 agent_state
->position
.pool
= info
.pgid
.pool();
12837 agent_state
->position
.set_hash(pool
.info
.get_random_pg_position(
12840 agent_state
->start
= agent_state
->position
;
12842 dout(10) << __func__
<< " allocated new state, position "
12843 << agent_state
->position
<< dendl
;
12845 dout(10) << __func__
<< " keeping existing state" << dendl
;
12848 if (info
.stats
.stats_invalid
) {
12849 osd
->clog
->warn() << "pg " << info
.pgid
<< " has invalid (post-split) stats; must scrub before tier agent can activate";
12852 agent_choose_mode();
12855 void PrimaryLogPG::agent_clear()
12858 agent_state
.reset(NULL
);
12861 // Return false if no objects operated on since start of object hash space
12862 bool PrimaryLogPG::agent_work(int start_max
, int agent_flush_quota
)
12865 if (!agent_state
) {
12866 dout(10) << __func__
<< " no agent state, stopping" << dendl
;
12873 if (agent_state
->is_idle()) {
12874 dout(10) << __func__
<< " idle, stopping" << dendl
;
12879 osd
->logger
->inc(l_osd_agent_wake
);
12881 dout(10) << __func__
12882 << " max " << start_max
12883 << ", flush " << agent_state
->get_flush_mode_name()
12884 << ", evict " << agent_state
->get_evict_mode_name()
12885 << ", pos " << agent_state
->position
12887 assert(is_primary());
12888 assert(is_active());
12890 agent_load_hit_sets();
12892 const pg_pool_t
*base_pool
= get_osdmap()->get_pg_pool(pool
.info
.tier_of
);
12896 int ls_max
= cct
->_conf
->osd_pool_default_cache_max_evict_check_size
;
12898 // list some objects. this conveniently lists clones (oldest to
12899 // newest) before heads... the same order we want to flush in.
12901 // NOTE: do not flush the Sequencer. we will assume that the
12902 // listing we get back is imprecise.
12903 vector
<hobject_t
> ls
;
12905 int r
= pgbackend
->objects_list_partial(agent_state
->position
, ls_min
, ls_max
,
12908 dout(20) << __func__
<< " got " << ls
.size() << " objects" << dendl
;
12910 for (vector
<hobject_t
>::iterator p
= ls
.begin();
12913 if (p
->nspace
== cct
->_conf
->osd_hit_set_namespace
) {
12914 dout(20) << __func__
<< " skip (hit set) " << *p
<< dendl
;
12915 osd
->logger
->inc(l_osd_agent_skip
);
12918 if (is_degraded_or_backfilling_object(*p
)) {
12919 dout(20) << __func__
<< " skip (degraded) " << *p
<< dendl
;
12920 osd
->logger
->inc(l_osd_agent_skip
);
12923 if (is_missing_object(p
->get_head())) {
12924 dout(20) << __func__
<< " skip (missing head) " << *p
<< dendl
;
12925 osd
->logger
->inc(l_osd_agent_skip
);
12928 ObjectContextRef obc
= get_object_context(*p
, false, NULL
);
12930 // we didn't flush; we may miss something here.
12931 dout(20) << __func__
<< " skip (no obc) " << *p
<< dendl
;
12932 osd
->logger
->inc(l_osd_agent_skip
);
12935 if (!obc
->obs
.exists
) {
12936 dout(20) << __func__
<< " skip (dne) " << obc
->obs
.oi
.soid
<< dendl
;
12937 osd
->logger
->inc(l_osd_agent_skip
);
12940 if (scrubber
.write_blocked_by_scrub(obc
->obs
.oi
.soid
)) {
12941 dout(20) << __func__
<< " skip (scrubbing) " << obc
->obs
.oi
<< dendl
;
12942 osd
->logger
->inc(l_osd_agent_skip
);
12945 if (obc
->is_blocked()) {
12946 dout(20) << __func__
<< " skip (blocked) " << obc
->obs
.oi
<< dendl
;
12947 osd
->logger
->inc(l_osd_agent_skip
);
12950 if (obc
->is_request_pending()) {
12951 dout(20) << __func__
<< " skip (request pending) " << obc
->obs
.oi
<< dendl
;
12952 osd
->logger
->inc(l_osd_agent_skip
);
12956 // be careful flushing omap to an EC pool.
12957 if (!base_pool
->supports_omap() &&
12958 obc
->obs
.oi
.is_omap()) {
12959 dout(20) << __func__
<< " skip (omap to EC) " << obc
->obs
.oi
<< dendl
;
12960 osd
->logger
->inc(l_osd_agent_skip
);
12964 if (agent_state
->evict_mode
!= TierAgentState::EVICT_MODE_IDLE
&&
12965 agent_maybe_evict(obc
, false))
12967 else if (agent_state
->flush_mode
!= TierAgentState::FLUSH_MODE_IDLE
&&
12968 agent_flush_quota
> 0 && agent_maybe_flush(obc
)) {
12970 --agent_flush_quota
;
12972 if (started
>= start_max
) {
12973 // If finishing early, set "next" to the next object
12974 if (++p
!= ls
.end())
12980 if (++agent_state
->hist_age
> cct
->_conf
->osd_agent_hist_halflife
) {
12981 dout(20) << __func__
<< " resetting atime and temp histograms" << dendl
;
12982 agent_state
->hist_age
= 0;
12983 agent_state
->temp_hist
.decay();
12986 // Total objects operated on so far
12987 int total_started
= agent_state
->started
+ started
;
12988 bool need_delay
= false;
12990 dout(20) << __func__
<< " start pos " << agent_state
->position
12991 << " next start pos " << next
12992 << " started " << total_started
<< dendl
;
12994 // See if we've made a full pass over the object hash space
12995 // This might check at most ls_max objects a second time to notice that
12996 // we've checked every objects at least once.
12997 if (agent_state
->position
< agent_state
->start
&&
12998 next
>= agent_state
->start
) {
12999 dout(20) << __func__
<< " wrap around " << agent_state
->start
<< dendl
;
13000 if (total_started
== 0)
13004 agent_state
->start
= next
;
13006 agent_state
->started
= total_started
;
13008 // See if we are starting from beginning
13010 agent_state
->position
= hobject_t();
13012 agent_state
->position
= next
;
13014 // Discard old in memory HitSets
13015 hit_set_in_memory_trim(pool
.info
.hit_set_count
);
13018 assert(agent_state
->delaying
== false);
13023 agent_choose_mode();
13028 void PrimaryLogPG::agent_load_hit_sets()
13030 if (agent_state
->evict_mode
== TierAgentState::EVICT_MODE_IDLE
) {
13034 if (agent_state
->hit_set_map
.size() < info
.hit_set
.history
.size()) {
13035 dout(10) << __func__
<< dendl
;
13036 for (list
<pg_hit_set_info_t
>::iterator p
= info
.hit_set
.history
.begin();
13037 p
!= info
.hit_set
.history
.end(); ++p
) {
13038 if (agent_state
->hit_set_map
.count(p
->begin
.sec()) == 0) {
13039 dout(10) << __func__
<< " loading " << p
->begin
<< "-"
13040 << p
->end
<< dendl
;
13041 if (!pool
.info
.is_replicated()) {
13042 // FIXME: EC not supported here yet
13043 derr
<< __func__
<< " on non-replicated pool" << dendl
;
13047 hobject_t oid
= get_hit_set_archive_object(p
->begin
, p
->end
, p
->using_gmt
);
13048 if (is_unreadable_object(oid
)) {
13049 dout(10) << __func__
<< " unreadable " << oid
<< ", waiting" << dendl
;
13053 ObjectContextRef obc
= get_object_context(oid
, false);
13055 derr
<< __func__
<< ": could not load hitset " << oid
<< dendl
;
13061 obc
->ondisk_read_lock();
13062 int r
= osd
->store
->read(ch
, ghobject_t(oid
), 0, 0, bl
);
13064 obc
->ondisk_read_unlock();
13066 HitSetRef
hs(new HitSet
);
13067 bufferlist::iterator pbl
= bl
.begin();
13068 ::decode(*hs
, pbl
);
13069 agent_state
->add_hit_set(p
->begin
.sec(), hs
);
13075 bool PrimaryLogPG::agent_maybe_flush(ObjectContextRef
& obc
)
13077 if (!obc
->obs
.oi
.is_dirty()) {
13078 dout(20) << __func__
<< " skip (clean) " << obc
->obs
.oi
<< dendl
;
13079 osd
->logger
->inc(l_osd_agent_skip
);
13082 if (obc
->obs
.oi
.is_cache_pinned()) {
13083 dout(20) << __func__
<< " skip (cache_pinned) " << obc
->obs
.oi
<< dendl
;
13084 osd
->logger
->inc(l_osd_agent_skip
);
13088 utime_t now
= ceph_clock_now();
13089 utime_t ob_local_mtime
;
13090 if (obc
->obs
.oi
.local_mtime
!= utime_t()) {
13091 ob_local_mtime
= obc
->obs
.oi
.local_mtime
;
13093 ob_local_mtime
= obc
->obs
.oi
.mtime
;
13095 bool evict_mode_full
=
13096 (agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
);
13097 if (!evict_mode_full
&&
13098 obc
->obs
.oi
.soid
.snap
== CEPH_NOSNAP
&& // snaps immutable; don't delay
13099 (ob_local_mtime
+ utime_t(pool
.info
.cache_min_flush_age
, 0) > now
)) {
13100 dout(20) << __func__
<< " skip (too young) " << obc
->obs
.oi
<< dendl
;
13101 osd
->logger
->inc(l_osd_agent_skip
);
13105 if (osd
->agent_is_active_oid(obc
->obs
.oi
.soid
)) {
13106 dout(20) << __func__
<< " skip (flushing) " << obc
->obs
.oi
<< dendl
;
13107 osd
->logger
->inc(l_osd_agent_skip
);
13111 dout(10) << __func__
<< " flushing " << obc
->obs
.oi
<< dendl
;
13113 // FIXME: flush anything dirty, regardless of what distribution of
13116 hobject_t oid
= obc
->obs
.oi
.soid
;
13117 osd
->agent_start_op(oid
);
13118 // no need to capture a pg ref, can't outlive fop or ctx
13119 std::function
<void()> on_flush
= [this, oid
]() {
13120 osd
->agent_finish_op(oid
);
13123 int result
= start_flush(
13124 OpRequestRef(), obc
, false, NULL
,
13126 if (result
!= -EINPROGRESS
) {
13128 dout(10) << __func__
<< " start_flush() failed " << obc
->obs
.oi
13129 << " with " << result
<< dendl
;
13130 osd
->logger
->inc(l_osd_agent_skip
);
13134 osd
->logger
->inc(l_osd_agent_flush
);
13138 bool PrimaryLogPG::agent_maybe_evict(ObjectContextRef
& obc
, bool after_flush
)
13140 const hobject_t
& soid
= obc
->obs
.oi
.soid
;
13141 if (!after_flush
&& obc
->obs
.oi
.is_dirty()) {
13142 dout(20) << __func__
<< " skip (dirty) " << obc
->obs
.oi
<< dendl
;
13145 if (!obc
->obs
.oi
.watchers
.empty()) {
13146 dout(20) << __func__
<< " skip (watchers) " << obc
->obs
.oi
<< dendl
;
13149 if (obc
->is_blocked()) {
13150 dout(20) << __func__
<< " skip (blocked) " << obc
->obs
.oi
<< dendl
;
13153 if (obc
->obs
.oi
.is_cache_pinned()) {
13154 dout(20) << __func__
<< " skip (cache_pinned) " << obc
->obs
.oi
<< dendl
;
13158 if (soid
.snap
== CEPH_NOSNAP
) {
13159 int result
= _verify_no_head_clones(soid
, obc
->ssc
->snapset
);
13161 dout(20) << __func__
<< " skip (clones) " << obc
->obs
.oi
<< dendl
;
13166 if (agent_state
->evict_mode
!= TierAgentState::EVICT_MODE_FULL
) {
13167 // is this object old than cache_min_evict_age?
13168 utime_t now
= ceph_clock_now();
13169 utime_t ob_local_mtime
;
13170 if (obc
->obs
.oi
.local_mtime
!= utime_t()) {
13171 ob_local_mtime
= obc
->obs
.oi
.local_mtime
;
13173 ob_local_mtime
= obc
->obs
.oi
.mtime
;
13175 if (ob_local_mtime
+ utime_t(pool
.info
.cache_min_evict_age
, 0) > now
) {
13176 dout(20) << __func__
<< " skip (too young) " << obc
->obs
.oi
<< dendl
;
13177 osd
->logger
->inc(l_osd_agent_skip
);
13180 // is this object old and/or cold enough?
13182 uint64_t temp_upper
= 0, temp_lower
= 0;
13184 agent_estimate_temp(soid
, &temp
);
13185 agent_state
->temp_hist
.add(temp
);
13186 agent_state
->temp_hist
.get_position_micro(temp
, &temp_lower
, &temp_upper
);
13188 dout(20) << __func__
13189 << " temp " << temp
13190 << " pos " << temp_lower
<< "-" << temp_upper
13191 << ", evict_effort " << agent_state
->evict_effort
13193 dout(30) << "agent_state:\n";
13194 Formatter
*f
= Formatter::create("");
13195 f
->open_object_section("agent_state");
13196 agent_state
->dump(f
);
13197 f
->close_section();
13202 if (1000000 - temp_upper
>= agent_state
->evict_effort
)
13206 dout(10) << __func__
<< " evicting " << obc
->obs
.oi
<< dendl
;
13207 OpContextUPtr ctx
= simple_opc_create(obc
);
13209 if (!ctx
->lock_manager
.get_lock_type(
13210 ObjectContext::RWState::RWWRITE
,
13214 close_op_ctx(ctx
.release());
13215 dout(20) << __func__
<< " skip (cannot get lock) " << obc
->obs
.oi
<< dendl
;
13219 osd
->agent_start_evict_op();
13220 ctx
->register_on_finish(
13222 osd
->agent_finish_evict_op();
13225 ctx
->at_version
= get_next_version();
13226 assert(ctx
->new_obs
.exists
);
13227 int r
= _delete_oid(ctx
.get(), true, false);
13228 if (obc
->obs
.oi
.is_omap())
13229 ctx
->delta_stats
.num_objects_omap
--;
13230 ctx
->delta_stats
.num_evict
++;
13231 ctx
->delta_stats
.num_evict_kb
+= SHIFT_ROUND_UP(obc
->obs
.oi
.size
, 10);
13232 if (obc
->obs
.oi
.is_dirty())
13233 --ctx
->delta_stats
.num_objects_dirty
;
13235 finish_ctx(ctx
.get(), pg_log_entry_t::DELETE
, false);
13236 simple_opc_submit(std::move(ctx
));
13237 osd
->logger
->inc(l_osd_tier_evict
);
13238 osd
->logger
->inc(l_osd_agent_evict
);
13242 void PrimaryLogPG::agent_stop()
13244 dout(20) << __func__
<< dendl
;
13245 if (agent_state
&& !agent_state
->is_idle()) {
13246 agent_state
->evict_mode
= TierAgentState::EVICT_MODE_IDLE
;
13247 agent_state
->flush_mode
= TierAgentState::FLUSH_MODE_IDLE
;
13248 osd
->agent_disable_pg(this, agent_state
->evict_effort
);
13252 void PrimaryLogPG::agent_delay()
13254 dout(20) << __func__
<< dendl
;
13255 if (agent_state
&& !agent_state
->is_idle()) {
13256 assert(agent_state
->delaying
== false);
13257 agent_state
->delaying
= true;
13258 osd
->agent_disable_pg(this, agent_state
->evict_effort
);
13262 void PrimaryLogPG::agent_choose_mode_restart()
13264 dout(20) << __func__
<< dendl
;
13266 if (agent_state
&& agent_state
->delaying
) {
13267 agent_state
->delaying
= false;
13268 agent_choose_mode(true);
13273 bool PrimaryLogPG::agent_choose_mode(bool restart
, OpRequestRef op
)
13275 bool requeued
= false;
13276 // Let delay play out
13277 if (agent_state
->delaying
) {
13278 dout(20) << __func__
<< this << " delaying, ignored" << dendl
;
13282 TierAgentState::flush_mode_t flush_mode
= TierAgentState::FLUSH_MODE_IDLE
;
13283 TierAgentState::evict_mode_t evict_mode
= TierAgentState::EVICT_MODE_IDLE
;
13284 unsigned evict_effort
= 0;
13286 if (info
.stats
.stats_invalid
) {
13287 // idle; stats can't be trusted until we scrub.
13288 dout(20) << __func__
<< " stats invalid (post-split), idle" << dendl
;
13293 uint64_t divisor
= pool
.info
.get_pg_num_divisor(info
.pgid
.pgid
);
13294 assert(divisor
> 0);
13296 // adjust (effective) user objects down based on the number
13297 // of HitSet objects, which should not count toward our total since
13298 // they cannot be flushed.
13299 uint64_t unflushable
= info
.stats
.stats
.sum
.num_objects_hit_set_archive
;
13301 // also exclude omap objects if ec backing pool
13302 const pg_pool_t
*base_pool
= get_osdmap()->get_pg_pool(pool
.info
.tier_of
);
13304 if (!base_pool
->supports_omap())
13305 unflushable
+= info
.stats
.stats
.sum
.num_objects_omap
;
13307 uint64_t num_user_objects
= info
.stats
.stats
.sum
.num_objects
;
13308 if (num_user_objects
> unflushable
)
13309 num_user_objects
-= unflushable
;
13311 num_user_objects
= 0;
13313 uint64_t num_user_bytes
= info
.stats
.stats
.sum
.num_bytes
;
13314 uint64_t unflushable_bytes
= info
.stats
.stats
.sum
.num_bytes_hit_set_archive
;
13315 num_user_bytes
-= unflushable_bytes
;
13316 uint64_t num_overhead_bytes
= osd
->store
->estimate_objects_overhead(num_user_objects
);
13317 num_user_bytes
+= num_overhead_bytes
;
13319 // also reduce the num_dirty by num_objects_omap
13320 int64_t num_dirty
= info
.stats
.stats
.sum
.num_objects_dirty
;
13321 if (!base_pool
->supports_omap()) {
13322 if (num_dirty
> info
.stats
.stats
.sum
.num_objects_omap
)
13323 num_dirty
-= info
.stats
.stats
.sum
.num_objects_omap
;
13328 dout(10) << __func__
13330 << TierAgentState::get_flush_mode_name(agent_state
->flush_mode
)
13332 << TierAgentState::get_evict_mode_name(agent_state
->evict_mode
)
13333 << " num_objects: " << info
.stats
.stats
.sum
.num_objects
13334 << " num_bytes: " << info
.stats
.stats
.sum
.num_bytes
13335 << " num_objects_dirty: " << info
.stats
.stats
.sum
.num_objects_dirty
13336 << " num_objects_omap: " << info
.stats
.stats
.sum
.num_objects_omap
13337 << " num_dirty: " << num_dirty
13338 << " num_user_objects: " << num_user_objects
13339 << " num_user_bytes: " << num_user_bytes
13340 << " num_overhead_bytes: " << num_overhead_bytes
13341 << " pool.info.target_max_bytes: " << pool
.info
.target_max_bytes
13342 << " pool.info.target_max_objects: " << pool
.info
.target_max_objects
13345 // get dirty, full ratios
13346 uint64_t dirty_micro
= 0;
13347 uint64_t full_micro
= 0;
13348 if (pool
.info
.target_max_bytes
&& num_user_objects
> 0) {
13349 uint64_t avg_size
= num_user_bytes
/ num_user_objects
;
13351 num_dirty
* avg_size
* 1000000 /
13352 MAX(pool
.info
.target_max_bytes
/ divisor
, 1);
13354 num_user_objects
* avg_size
* 1000000 /
13355 MAX(pool
.info
.target_max_bytes
/ divisor
, 1);
13357 if (pool
.info
.target_max_objects
> 0) {
13358 uint64_t dirty_objects_micro
=
13359 num_dirty
* 1000000 /
13360 MAX(pool
.info
.target_max_objects
/ divisor
, 1);
13361 if (dirty_objects_micro
> dirty_micro
)
13362 dirty_micro
= dirty_objects_micro
;
13363 uint64_t full_objects_micro
=
13364 num_user_objects
* 1000000 /
13365 MAX(pool
.info
.target_max_objects
/ divisor
, 1);
13366 if (full_objects_micro
> full_micro
)
13367 full_micro
= full_objects_micro
;
13369 dout(20) << __func__
<< " dirty " << ((float)dirty_micro
/ 1000000.0)
13370 << " full " << ((float)full_micro
/ 1000000.0)
13374 uint64_t flush_target
= pool
.info
.cache_target_dirty_ratio_micro
;
13375 uint64_t flush_high_target
= pool
.info
.cache_target_dirty_high_ratio_micro
;
13376 uint64_t flush_slop
= (float)flush_target
* cct
->_conf
->osd_agent_slop
;
13377 if (restart
|| agent_state
->flush_mode
== TierAgentState::FLUSH_MODE_IDLE
) {
13378 flush_target
+= flush_slop
;
13379 flush_high_target
+= flush_slop
;
13381 flush_target
-= MIN(flush_target
, flush_slop
);
13382 flush_high_target
-= MIN(flush_high_target
, flush_slop
);
13385 if (dirty_micro
> flush_high_target
) {
13386 flush_mode
= TierAgentState::FLUSH_MODE_HIGH
;
13387 } else if (dirty_micro
> flush_target
) {
13388 flush_mode
= TierAgentState::FLUSH_MODE_LOW
;
13392 uint64_t evict_target
= pool
.info
.cache_target_full_ratio_micro
;
13393 uint64_t evict_slop
= (float)evict_target
* cct
->_conf
->osd_agent_slop
;
13394 if (restart
|| agent_state
->evict_mode
== TierAgentState::EVICT_MODE_IDLE
)
13395 evict_target
+= evict_slop
;
13397 evict_target
-= MIN(evict_target
, evict_slop
);
13399 if (full_micro
> 1000000) {
13400 // evict anything clean
13401 evict_mode
= TierAgentState::EVICT_MODE_FULL
;
13402 evict_effort
= 1000000;
13403 } else if (full_micro
> evict_target
) {
13404 // set effort in [0..1] range based on where we are between
13405 evict_mode
= TierAgentState::EVICT_MODE_SOME
;
13406 uint64_t over
= full_micro
- evict_target
;
13407 uint64_t span
= 1000000 - evict_target
;
13408 evict_effort
= MAX(over
* 1000000 / span
,
13409 (unsigned)(1000000.0 * cct
->_conf
->osd_agent_min_evict_effort
));
13411 // quantize effort to avoid too much reordering in the agent_queue.
13412 uint64_t inc
= cct
->_conf
->osd_agent_quantize_effort
* 1000000;
13414 uint64_t was
= evict_effort
;
13415 evict_effort
-= evict_effort
% inc
;
13416 if (evict_effort
< inc
)
13417 evict_effort
= inc
;
13418 assert(evict_effort
>= inc
&& evict_effort
<= 1000000);
13419 dout(30) << __func__
<< " evict_effort " << was
<< " quantized by " << inc
<< " to " << evict_effort
<< dendl
;
13424 bool old_idle
= agent_state
->is_idle();
13425 if (flush_mode
!= agent_state
->flush_mode
) {
13426 dout(5) << __func__
<< " flush_mode "
13427 << TierAgentState::get_flush_mode_name(agent_state
->flush_mode
)
13429 << TierAgentState::get_flush_mode_name(flush_mode
)
13431 if (flush_mode
== TierAgentState::FLUSH_MODE_HIGH
) {
13432 osd
->agent_inc_high_count();
13433 info
.stats
.stats
.sum
.num_flush_mode_high
= 1;
13434 } else if (flush_mode
== TierAgentState::FLUSH_MODE_LOW
) {
13435 info
.stats
.stats
.sum
.num_flush_mode_low
= 1;
13437 if (agent_state
->flush_mode
== TierAgentState::FLUSH_MODE_HIGH
) {
13438 osd
->agent_dec_high_count();
13439 info
.stats
.stats
.sum
.num_flush_mode_high
= 0;
13440 } else if (agent_state
->flush_mode
== TierAgentState::FLUSH_MODE_LOW
) {
13441 info
.stats
.stats
.sum
.num_flush_mode_low
= 0;
13443 agent_state
->flush_mode
= flush_mode
;
13445 if (evict_mode
!= agent_state
->evict_mode
) {
13446 dout(5) << __func__
<< " evict_mode "
13447 << TierAgentState::get_evict_mode_name(agent_state
->evict_mode
)
13449 << TierAgentState::get_evict_mode_name(evict_mode
)
13451 if (agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
&&
13455 requeue_ops(waiting_for_active
);
13456 requeue_ops(waiting_for_scrub
);
13457 requeue_ops(waiting_for_cache_not_full
);
13458 objects_blocked_on_cache_full
.clear();
13461 if (evict_mode
== TierAgentState::EVICT_MODE_SOME
) {
13462 info
.stats
.stats
.sum
.num_evict_mode_some
= 1;
13463 } else if (evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
13464 info
.stats
.stats
.sum
.num_evict_mode_full
= 1;
13466 if (agent_state
->evict_mode
== TierAgentState::EVICT_MODE_SOME
) {
13467 info
.stats
.stats
.sum
.num_evict_mode_some
= 0;
13468 } else if (agent_state
->evict_mode
== TierAgentState::EVICT_MODE_FULL
) {
13469 info
.stats
.stats
.sum
.num_evict_mode_full
= 0;
13471 agent_state
->evict_mode
= evict_mode
;
13473 uint64_t old_effort
= agent_state
->evict_effort
;
13474 if (evict_effort
!= agent_state
->evict_effort
) {
13475 dout(5) << __func__
<< " evict_effort "
13476 << ((float)agent_state
->evict_effort
/ 1000000.0)
13478 << ((float)evict_effort
/ 1000000.0)
13480 agent_state
->evict_effort
= evict_effort
;
13483 // NOTE: we are using evict_effort as a proxy for *all* agent effort
13484 // (including flush). This is probably fine (they should be
13485 // correlated) but it is not precisely correct.
13486 if (agent_state
->is_idle()) {
13487 if (!restart
&& !old_idle
) {
13488 osd
->agent_disable_pg(this, old_effort
);
13491 if (restart
|| old_idle
) {
13492 osd
->agent_enable_pg(this, agent_state
->evict_effort
);
13493 } else if (old_effort
!= agent_state
->evict_effort
) {
13494 osd
->agent_adjust_pg(this, old_effort
, agent_state
->evict_effort
);
13500 void PrimaryLogPG::agent_estimate_temp(const hobject_t
& oid
, int *temp
)
13505 if (hit_set
->contains(oid
))
13508 int last_n
= pool
.info
.hit_set_search_last_n
;
13509 for (map
<time_t,HitSetRef
>::reverse_iterator p
=
13510 agent_state
->hit_set_map
.rbegin(); last_n
> 0 &&
13511 p
!= agent_state
->hit_set_map
.rend(); ++p
, ++i
) {
13512 if (p
->second
->contains(oid
)) {
13513 *temp
+= pool
.info
.get_grade(i
);
13519 // Dup op detection
13521 bool PrimaryLogPG::already_complete(eversion_t v
)
13523 dout(20) << __func__
<< ": " << v
<< dendl
;
13524 for (xlist
<RepGather
*>::iterator i
= repop_queue
.begin();
13527 dout(20) << __func__
<< ": " << **i
<< dendl
;
13528 // skip copy from temp object ops
13529 if ((*i
)->v
== eversion_t()) {
13530 dout(20) << __func__
<< ": " << **i
13531 << " version is empty" << dendl
;
13535 dout(20) << __func__
<< ": " << **i
13536 << " (*i)->v past v" << dendl
;
13539 if (!(*i
)->all_committed
) {
13540 dout(20) << __func__
<< ": " << **i
13541 << " not committed, returning false"
13546 dout(20) << __func__
<< ": returning true" << dendl
;
13550 bool PrimaryLogPG::already_ack(eversion_t v
)
13552 dout(20) << __func__
<< ": " << v
<< dendl
;
13553 for (xlist
<RepGather
*>::iterator i
= repop_queue
.begin();
13556 // skip copy from temp object ops
13557 if ((*i
)->v
== eversion_t()) {
13558 dout(20) << __func__
<< ": " << **i
13559 << " version is empty" << dendl
;
13563 dout(20) << __func__
<< ": " << **i
13564 << " (*i)->v past v" << dendl
;
13567 if (!(*i
)->all_applied
) {
13568 dout(20) << __func__
<< ": " << **i
13569 << " not applied, returning false"
13574 dout(20) << __func__
<< ": returning true" << dendl
;
13579 // ==========================================================================================
13583 bool PrimaryLogPG::_range_available_for_scrub(
13584 const hobject_t
&begin
, const hobject_t
&end
)
13586 pair
<hobject_t
, ObjectContextRef
> next
;
13587 next
.second
= object_contexts
.lookup(begin
);
13588 next
.first
= begin
;
13590 while (more
&& next
.first
< end
) {
13591 if (next
.second
&& next
.second
->is_blocked()) {
13592 next
.second
->requeue_scrub_on_unblock
= true;
13593 dout(10) << __func__
<< ": scrub delayed, "
13594 << next
.first
<< " is blocked"
13598 more
= object_contexts
.get_next(next
.first
, &next
);
13603 static bool doing_clones(const boost::optional
<SnapSet
> &snapset
,
13604 const vector
<snapid_t
>::reverse_iterator
&curclone
) {
13605 return snapset
&& curclone
!= snapset
.get().clones
.rend();
13608 void PrimaryLogPG::log_missing(unsigned missing
,
13609 const boost::optional
<hobject_t
> &head
,
13610 LogChannelRef clog
,
13614 bool allow_incomplete_clones
)
13617 if (allow_incomplete_clones
) {
13618 dout(20) << func
<< " " << mode
<< " " << pgid
<< " " << head
.get()
13619 << " skipped " << missing
<< " clone(s) in cache tier" << dendl
;
13621 clog
->info() << mode
<< " " << pgid
<< " " << head
.get()
13622 << " " << missing
<< " missing clone(s)";
13626 unsigned PrimaryLogPG::process_clones_to(const boost::optional
<hobject_t
> &head
,
13627 const boost::optional
<SnapSet
> &snapset
,
13628 LogChannelRef clog
,
13631 bool allow_incomplete_clones
,
13632 boost::optional
<snapid_t
> target
,
13633 vector
<snapid_t
>::reverse_iterator
*curclone
,
13634 inconsistent_snapset_wrapper
&e
)
13638 unsigned missing
= 0;
13640 // NOTE: clones are in descending order, thus **curclone > target test here
13641 hobject_t
next_clone(head
.get());
13642 while(doing_clones(snapset
, *curclone
) && (!target
|| **curclone
> *target
)) {
13644 // it is okay to be missing one or more clones in a cache tier.
13645 // skip higher-numbered clones in the list.
13646 if (!allow_incomplete_clones
) {
13647 next_clone
.snap
= **curclone
;
13648 clog
->error() << mode
<< " " << pgid
<< " " << head
.get()
13649 << " expected clone " << next_clone
<< " " << missing
13651 ++scrubber
.shallow_errors
;
13652 e
.set_clone_missing(next_clone
.snap
);
13654 // Clones are descending
13661 * Validate consistency of the object info and snap sets.
13663 * We are sort of comparing 2 lists. The main loop is on objmap.objects. But
13664 * the comparison of the objects is against multiple snapset.clones. There are
13665 * multiple clone lists and in between lists we expect head or snapdir.
13671 * obj1 snap 1 head/snapdir, unexpected obj1 snap 1
13672 * obj2 head head/snapdir, head ok
13673 * [SnapSet clones 6 4 2 1]
13674 * obj2 snap 7 obj2 snap 6, unexpected obj2 snap 7
13675 * obj2 snap 6 obj2 snap 6, match
13676 * obj2 snap 4 obj2 snap 4, match
13677 * obj3 head obj2 snap 2 (expected), obj2 snap 1 (expected), head ok
13678 * [Snapset clones 3 1]
13679 * obj3 snap 3 obj3 snap 3 match
13680 * obj3 snap 1 obj3 snap 1 match
13681 * obj4 snapdir head/snapdir, snapdir ok
13682 * [Snapset clones 4]
13683 * EOL obj4 snap 4, (expected)
13685 void PrimaryLogPG::scrub_snapshot_metadata(
13686 ScrubMap
&scrubmap
,
13687 const map
<hobject_t
, pair
<uint32_t, uint32_t>> &missing_digest
)
13689 dout(10) << __func__
<< dendl
;
13691 coll_t
c(info
.pgid
);
13692 bool repair
= state_test(PG_STATE_REPAIR
);
13693 bool deep_scrub
= state_test(PG_STATE_DEEP_SCRUB
);
13694 const char *mode
= (repair
? "repair": (deep_scrub
? "deep-scrub" : "scrub"));
13695 boost::optional
<snapid_t
> all_clones
; // Unspecified snapid_t or boost::none
13697 /// snapsets to repair
13698 map
<hobject_t
,SnapSet
> snapset_to_repair
;
13700 // traverse in reverse order.
13701 boost::optional
<hobject_t
> head
;
13702 boost::optional
<SnapSet
> snapset
; // If initialized so will head (above)
13703 vector
<snapid_t
>::reverse_iterator curclone
; // Defined only if snapset initialized
13704 unsigned missing
= 0;
13705 inconsistent_snapset_wrapper soid_error
, head_error
;
13707 bufferlist last_data
;
13709 for (map
<hobject_t
,ScrubMap::object
>::reverse_iterator
13710 p
= scrubmap
.objects
.rbegin(); p
!= scrubmap
.objects
.rend(); ++p
) {
13711 const hobject_t
& soid
= p
->first
;
13712 soid_error
= inconsistent_snapset_wrapper
{soid
};
13713 object_stat_sum_t stat
;
13714 boost::optional
<object_info_t
> oi
;
13716 if (!soid
.is_snapdir())
13717 stat
.num_objects
++;
13719 if (soid
.nspace
== cct
->_conf
->osd_hit_set_namespace
)
13720 stat
.num_objects_hit_set_archive
++;
13722 if (soid
.is_snap()) {
13724 stat
.num_object_clones
++;
13728 if (p
->second
.attrs
.count(OI_ATTR
) == 0) {
13730 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13731 << " no '" << OI_ATTR
<< "' attr";
13732 ++scrubber
.shallow_errors
;
13733 soid_error
.set_oi_attr_missing();
13736 bv
.push_back(p
->second
.attrs
[OI_ATTR
]);
13738 oi
= object_info_t(); // Initialize optional<> before decode into it
13739 oi
.get().decode(bv
);
13740 } catch (buffer::error
& e
) {
13742 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13743 << " can't decode '" << OI_ATTR
<< "' attr " << e
.what();
13744 ++scrubber
.shallow_errors
;
13745 soid_error
.set_oi_attr_corrupted();
13746 soid_error
.set_oi_attr_missing(); // Not available too
13751 if (pgbackend
->be_get_ondisk_size(oi
->size
) != p
->second
.size
) {
13752 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13753 << " on disk size (" << p
->second
.size
13754 << ") does not match object info size ("
13755 << oi
->size
<< ") adjusted for ondisk to ("
13756 << pgbackend
->be_get_ondisk_size(oi
->size
)
13758 soid_error
.set_size_mismatch();
13759 ++scrubber
.shallow_errors
;
13762 dout(20) << mode
<< " " << soid
<< " " << oi
.get() << dendl
;
13764 // A clone num_bytes will be added later when we have snapset
13765 if (!soid
.is_snap()) {
13766 stat
.num_bytes
+= oi
->size
;
13768 if (soid
.nspace
== cct
->_conf
->osd_hit_set_namespace
)
13769 stat
.num_bytes_hit_set_archive
+= oi
->size
;
13771 if (!soid
.is_snapdir()) {
13772 if (oi
->is_dirty())
13773 ++stat
.num_objects_dirty
;
13774 if (oi
->is_whiteout())
13775 ++stat
.num_whiteouts
;
13777 ++stat
.num_objects_omap
;
13778 if (oi
->is_cache_pinned())
13779 ++stat
.num_objects_pinned
;
13782 // pessimistic assumption that this object might contain a
13784 stat
.num_legacy_snapsets
++;
13787 // Check for any problems while processing clones
13788 if (doing_clones(snapset
, curclone
)) {
13789 boost::optional
<snapid_t
> target
;
13790 // Expecting an object with snap for current head
13791 if (soid
.has_snapset() || soid
.get_head() != head
->get_head()) {
13793 dout(10) << __func__
<< " " << mode
<< " " << info
.pgid
<< " new object "
13794 << soid
<< " while processing " << head
.get() << dendl
;
13796 target
= all_clones
;
13798 assert(soid
.is_snap());
13799 target
= soid
.snap
;
13802 // Log any clones we were expecting to be there up to target
13803 // This will set missing, but will be a no-op if snap.soid == *curclone.
13804 missing
+= process_clones_to(head
, snapset
, osd
->clog
, info
.pgid
, mode
,
13805 pool
.info
.allow_incomplete_clones(), target
, &curclone
,
13809 // Check doing_clones() again in case we ran process_clones_to()
13810 if (doing_clones(snapset
, curclone
)) {
13811 // A head/snapdir would have processed all clones above
13812 // or all greater than *curclone.
13813 assert(soid
.is_snap() && *curclone
<= soid
.snap
);
13815 // After processing above clone snap should match the expected curclone
13816 expected
= (*curclone
== soid
.snap
);
13818 // If we aren't doing clones any longer, then expecting head/snapdir
13819 expected
= soid
.has_snapset();
13822 // If we couldn't read the head's snapset, just ignore clones
13823 if (head
&& !snapset
) {
13824 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13825 << " clone ignored due to missing snapset";
13827 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13828 << " is an unexpected clone";
13830 ++scrubber
.shallow_errors
;
13831 soid_error
.set_headless();
13832 scrubber
.store
->add_snap_error(pool
.id
, soid_error
);
13833 if (head
&& soid
.get_head() == head
->get_head())
13834 head_error
.set_clone(soid
.snap
);
13839 if (soid
.has_snapset()) {
13842 log_missing(missing
, head
, osd
->clog
, info
.pgid
, __func__
, mode
,
13843 pool
.info
.allow_incomplete_clones());
13846 // Save previous head error information
13847 if (head
&& head_error
.errors
)
13848 scrubber
.store
->add_snap_error(pool
.id
, head_error
);
13849 // Set this as a new head object
13852 head_error
= soid_error
;
13854 dout(20) << __func__
<< " " << mode
<< " new head " << head
<< dendl
;
13856 if (p
->second
.attrs
.count(SS_ATTR
) == 0) {
13857 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13858 << " no '" << SS_ATTR
<< "' attr";
13859 ++scrubber
.shallow_errors
;
13860 snapset
= boost::none
;
13861 head_error
.set_ss_attr_missing();
13864 bl
.push_back(p
->second
.attrs
[SS_ATTR
]);
13865 bufferlist::iterator blp
= bl
.begin();
13867 snapset
= SnapSet(); // Initialize optional<> before decoding into it
13868 ::decode(snapset
.get(), blp
);
13869 } catch (buffer::error
& e
) {
13870 snapset
= boost::none
;
13871 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13872 << " can't decode '" << SS_ATTR
<< "' attr " << e
.what();
13873 ++scrubber
.shallow_errors
;
13874 head_error
.set_ss_attr_corrupted();
13879 // what will be next?
13880 curclone
= snapset
->clones
.rbegin();
13882 if (!snapset
->clones
.empty()) {
13883 dout(20) << " snapset " << snapset
.get() << dendl
;
13884 if (snapset
->seq
== 0) {
13885 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13886 << " snaps.seq not set";
13887 ++scrubber
.shallow_errors
;
13888 head_error
.set_snapset_mismatch();
13892 if (soid
.is_head() && !snapset
->head_exists
) {
13893 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13894 << " snapset.head_exists=false, but head exists";
13895 ++scrubber
.shallow_errors
;
13896 head_error
.set_head_mismatch();
13897 // Fix head_exists locally so is_legacy() returns correctly
13898 snapset
->head_exists
= true;
13900 if (soid
.is_snapdir() && snapset
->head_exists
) {
13901 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13902 << " snapset.head_exists=true, but snapdir exists";
13903 ++scrubber
.shallow_errors
;
13904 head_error
.set_head_mismatch();
13905 // For symmetry fix this too, but probably doesn't matter
13906 snapset
->head_exists
= false;
13909 if (get_osdmap()->require_osd_release
>= CEPH_RELEASE_LUMINOUS
) {
13910 if (soid
.is_snapdir()) {
13911 dout(10) << " will move snapset to head from " << soid
<< dendl
;
13912 snapset_to_repair
[soid
.get_head()] = *snapset
;
13913 } else if (snapset
->is_legacy()) {
13914 dout(10) << " will convert legacy snapset on " << soid
<< " " << *snapset
13916 snapset_to_repair
[soid
.get_head()] = *snapset
;
13919 stat
.num_legacy_snapsets
++;
13922 // pessimistic assumption that this object might contain a
13924 stat
.num_legacy_snapsets
++;
13927 assert(soid
.is_snap());
13930 assert(soid
.snap
== *curclone
);
13932 dout(20) << __func__
<< " " << mode
<< " matched clone " << soid
<< dendl
;
13934 if (snapset
->clone_size
.count(soid
.snap
) == 0) {
13935 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13936 << " is missing in clone_size";
13937 ++scrubber
.shallow_errors
;
13938 soid_error
.set_size_mismatch();
13940 if (oi
&& oi
->size
!= snapset
->clone_size
[soid
.snap
]) {
13941 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13942 << " size " << oi
->size
<< " != clone_size "
13943 << snapset
->clone_size
[*curclone
];
13944 ++scrubber
.shallow_errors
;
13945 soid_error
.set_size_mismatch();
13948 if (snapset
->clone_overlap
.count(soid
.snap
) == 0) {
13949 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13950 << " is missing in clone_overlap";
13951 ++scrubber
.shallow_errors
;
13952 soid_error
.set_size_mismatch();
13954 // This checking is based on get_clone_bytes(). The first 2 asserts
13955 // can't happen because we know we have a clone_size and
13956 // a clone_overlap. Now we check that the interval_set won't
13957 // cause the last assert.
13958 uint64_t size
= snapset
->clone_size
.find(soid
.snap
)->second
;
13959 const interval_set
<uint64_t> &overlap
=
13960 snapset
->clone_overlap
.find(soid
.snap
)->second
;
13961 bool bad_interval_set
= false;
13962 for (interval_set
<uint64_t>::const_iterator i
= overlap
.begin();
13963 i
!= overlap
.end(); ++i
) {
13964 if (size
< i
.get_len()) {
13965 bad_interval_set
= true;
13968 size
-= i
.get_len();
13971 if (bad_interval_set
) {
13972 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13973 << " bad interval_set in clone_overlap";
13974 ++scrubber
.shallow_errors
;
13975 soid_error
.set_size_mismatch();
13977 stat
.num_bytes
+= snapset
->get_clone_bytes(soid
.snap
);
13982 // migrate legacy_snaps to snapset?
13983 auto p
= snapset_to_repair
.find(soid
.get_head());
13984 if (p
!= snapset_to_repair
.end()) {
13985 if (!oi
|| oi
->legacy_snaps
.empty()) {
13986 osd
->clog
->error() << mode
<< " " << info
.pgid
<< " " << soid
13987 << " has no oi or legacy_snaps; cannot convert "
13989 ++scrubber
.shallow_errors
;
13991 dout(20) << __func__
<< " copying legacy_snaps " << oi
->legacy_snaps
13992 << " to snapset " << p
->second
<< dendl
;
13993 p
->second
.clone_snaps
[soid
.snap
] = oi
->legacy_snaps
;
13999 if (soid_error
.errors
)
14000 scrubber
.store
->add_snap_error(pool
.id
, soid_error
);
14003 scrub_cstat
.add(stat
);
14006 if (doing_clones(snapset
, curclone
)) {
14007 dout(10) << __func__
<< " " << mode
<< " " << info
.pgid
14008 << " No more objects while processing " << head
.get() << dendl
;
14010 missing
+= process_clones_to(head
, snapset
, osd
->clog
, info
.pgid
, mode
,
14011 pool
.info
.allow_incomplete_clones(), all_clones
, &curclone
,
14014 // There could be missing found by the test above or even
14015 // before dropping out of the loop for the last head.
14017 log_missing(missing
, head
, osd
->clog
, info
.pgid
, __func__
,
14018 mode
, pool
.info
.allow_incomplete_clones());
14020 if (head
&& head_error
.errors
)
14021 scrubber
.store
->add_snap_error(pool
.id
, head_error
);
14023 for (map
<hobject_t
,pair
<uint32_t,uint32_t>>::const_iterator p
=
14024 missing_digest
.begin();
14025 p
!= missing_digest
.end();
14027 if (p
->first
.is_snapdir())
14029 dout(10) << __func__
<< " recording digests for " << p
->first
<< dendl
;
14030 ObjectContextRef obc
= get_object_context(p
->first
, false);
14032 osd
->clog
->error() << info
.pgid
<< " " << mode
14033 << " cannot get object context for object "
14036 } else if (obc
->obs
.oi
.soid
!= p
->first
) {
14037 osd
->clog
->error() << info
.pgid
<< " " << mode
14038 << " object " << p
->first
14039 << " has a valid oi attr with a mismatched name, "
14040 << " obc->obs.oi.soid: " << obc
->obs
.oi
.soid
;
14043 OpContextUPtr ctx
= simple_opc_create(obc
);
14044 ctx
->at_version
= get_next_version();
14045 ctx
->mtime
= utime_t(); // do not update mtime
14046 ctx
->new_obs
.oi
.set_data_digest(p
->second
.first
);
14047 ctx
->new_obs
.oi
.set_omap_digest(p
->second
.second
);
14048 finish_ctx(ctx
.get(), pg_log_entry_t::MODIFY
);
14050 ctx
->register_on_success(
14052 dout(20) << "updating scrub digest" << dendl
;
14053 if (--scrubber
.num_digest_updates_pending
== 0) {
14058 simple_opc_submit(std::move(ctx
));
14059 ++scrubber
.num_digest_updates_pending
;
14061 for (auto& p
: snapset_to_repair
) {
14062 // cache pools may not have the clones, which means we won't know
14063 // what snaps they have. fake out the clone_snaps entries anyway (with
14064 // blank snap lists).
14065 p
.second
.head_exists
= true;
14066 if (pool
.info
.allow_incomplete_clones()) {
14067 for (auto s
: p
.second
.clones
) {
14068 if (p
.second
.clone_snaps
.count(s
) == 0) {
14069 dout(10) << __func__
<< " " << p
.first
<< " faking clone_snaps for "
14071 p
.second
.clone_snaps
[s
];
14075 if (p
.second
.clones
.size() != p
.second
.clone_snaps
.size() ||
14076 p
.second
.is_legacy()) {
14077 // this happens if we encounter other errors above, like a missing
14079 dout(10) << __func__
<< " not writing snapset to " << p
.first
14080 << " snapset " << p
.second
<< " clones " << p
.second
.clones
14081 << "; didn't convert fully" << dendl
;
14082 scrub_cstat
.sum
.num_legacy_snapsets
++;
14085 dout(10) << __func__
<< " writing snapset to " << p
.first
14086 << " " << p
.second
<< dendl
;
14087 ObjectContextRef obc
= get_object_context(p
.first
, true);
14089 osd
->clog
->error() << info
.pgid
<< " " << mode
14090 << " cannot get object context for object "
14093 } else if (obc
->obs
.oi
.soid
!= p
.first
) {
14094 osd
->clog
->error() << info
.pgid
<< " " << mode
14095 << " object " << p
.first
14096 << " has a valid oi attr with a mismatched name, "
14097 << " obc->obs.oi.soid: " << obc
->obs
.oi
.soid
;
14100 ObjectContextRef snapset_obc
;
14101 if (!obc
->obs
.exists
) {
14102 snapset_obc
= get_object_context(p
.first
.get_snapdir(), false);
14103 if (!snapset_obc
) {
14104 osd
->clog
->error() << info
.pgid
<< " " << mode
14105 << " cannot get object context for "
14106 << p
.first
.get_snapdir();
14110 OpContextUPtr ctx
= simple_opc_create(obc
);
14111 PGTransaction
*t
= ctx
->op_t
.get();
14112 ctx
->snapset_obc
= snapset_obc
;
14113 ctx
->at_version
= get_next_version();
14114 ctx
->mtime
= utime_t(); // do not update mtime
14115 ctx
->new_snapset
= p
.second
;
14116 if (!ctx
->new_obs
.exists
) {
14117 dout(20) << __func__
<< " making " << p
.first
<< " a whiteout" << dendl
;
14118 ctx
->new_obs
.exists
= true;
14119 ctx
->new_snapset
.head_exists
= true;
14120 ctx
->new_obs
.oi
.set_flag(object_info_t::FLAG_WHITEOUT
);
14121 ++ctx
->delta_stats
.num_whiteouts
;
14122 ++ctx
->delta_stats
.num_objects
;
14123 t
->create(p
.first
);
14124 if (p
.first
< scrubber
.start
) {
14125 dout(20) << __func__
<< " kludging around update outside of scrub range"
14128 scrub_cstat
.add(ctx
->delta_stats
);
14131 dout(20) << __func__
<< " final snapset " << ctx
->new_snapset
<< dendl
;
14132 assert(!ctx
->new_snapset
.is_legacy());
14133 finish_ctx(ctx
.get(), pg_log_entry_t::MODIFY
);
14134 ctx
->register_on_success(
14136 dout(20) << "updating snapset" << dendl
;
14137 if (--scrubber
.num_digest_updates_pending
== 0) {
14142 simple_opc_submit(std::move(ctx
));
14143 ++scrubber
.num_digest_updates_pending
;
14146 dout(10) << __func__
<< " (" << mode
<< ") finish" << dendl
;
14149 void PrimaryLogPG::_scrub_clear_state()
14151 scrub_cstat
= object_stat_collection_t();
14154 void PrimaryLogPG::_scrub_finish()
14156 bool repair
= state_test(PG_STATE_REPAIR
);
14157 bool deep_scrub
= state_test(PG_STATE_DEEP_SCRUB
);
14158 const char *mode
= (repair
? "repair": (deep_scrub
? "deep-scrub" : "scrub"));
14160 if (info
.stats
.stats_invalid
) {
14161 info
.stats
.stats
= scrub_cstat
;
14162 info
.stats
.stats_invalid
= false;
14165 agent_choose_mode();
14168 dout(10) << mode
<< " got "
14169 << scrub_cstat
.sum
.num_objects
<< "/" << info
.stats
.stats
.sum
.num_objects
<< " objects, "
14170 << scrub_cstat
.sum
.num_object_clones
<< "/" << info
.stats
.stats
.sum
.num_object_clones
<< " clones, "
14171 << scrub_cstat
.sum
.num_objects_dirty
<< "/" << info
.stats
.stats
.sum
.num_objects_dirty
<< " dirty, "
14172 << scrub_cstat
.sum
.num_objects_omap
<< "/" << info
.stats
.stats
.sum
.num_objects_omap
<< " omap, "
14173 << scrub_cstat
.sum
.num_objects_pinned
<< "/" << info
.stats
.stats
.sum
.num_objects_pinned
<< " pinned, "
14174 << scrub_cstat
.sum
.num_objects_hit_set_archive
<< "/" << info
.stats
.stats
.sum
.num_objects_hit_set_archive
<< " hit_set_archive, "
14175 << scrub_cstat
.sum
.num_bytes
<< "/" << info
.stats
.stats
.sum
.num_bytes
<< " bytes, "
14176 << scrub_cstat
.sum
.num_bytes_hit_set_archive
<< "/" << info
.stats
.stats
.sum
.num_bytes_hit_set_archive
<< " hit_set_archive bytes."
14179 if (scrub_cstat
.sum
.num_objects
!= info
.stats
.stats
.sum
.num_objects
||
14180 scrub_cstat
.sum
.num_object_clones
!= info
.stats
.stats
.sum
.num_object_clones
||
14181 (scrub_cstat
.sum
.num_objects_dirty
!= info
.stats
.stats
.sum
.num_objects_dirty
&&
14182 !info
.stats
.dirty_stats_invalid
) ||
14183 (scrub_cstat
.sum
.num_objects_omap
!= info
.stats
.stats
.sum
.num_objects_omap
&&
14184 !info
.stats
.omap_stats_invalid
) ||
14185 (scrub_cstat
.sum
.num_objects_pinned
!= info
.stats
.stats
.sum
.num_objects_pinned
&&
14186 !info
.stats
.pin_stats_invalid
) ||
14187 (scrub_cstat
.sum
.num_objects_hit_set_archive
!= info
.stats
.stats
.sum
.num_objects_hit_set_archive
&&
14188 !info
.stats
.hitset_stats_invalid
) ||
14189 (scrub_cstat
.sum
.num_bytes_hit_set_archive
!= info
.stats
.stats
.sum
.num_bytes_hit_set_archive
&&
14190 !info
.stats
.hitset_bytes_stats_invalid
) ||
14191 scrub_cstat
.sum
.num_whiteouts
!= info
.stats
.stats
.sum
.num_whiteouts
||
14192 scrub_cstat
.sum
.num_bytes
!= info
.stats
.stats
.sum
.num_bytes
) {
14193 osd
->clog
->error() << info
.pgid
<< " " << mode
14194 << " stat mismatch, got "
14195 << scrub_cstat
.sum
.num_objects
<< "/" << info
.stats
.stats
.sum
.num_objects
<< " objects, "
14196 << scrub_cstat
.sum
.num_object_clones
<< "/" << info
.stats
.stats
.sum
.num_object_clones
<< " clones, "
14197 << scrub_cstat
.sum
.num_objects_dirty
<< "/" << info
.stats
.stats
.sum
.num_objects_dirty
<< " dirty, "
14198 << scrub_cstat
.sum
.num_objects_omap
<< "/" << info
.stats
.stats
.sum
.num_objects_omap
<< " omap, "
14199 << scrub_cstat
.sum
.num_objects_pinned
<< "/" << info
.stats
.stats
.sum
.num_objects_pinned
<< " pinned, "
14200 << scrub_cstat
.sum
.num_objects_hit_set_archive
<< "/" << info
.stats
.stats
.sum
.num_objects_hit_set_archive
<< " hit_set_archive, "
14201 << scrub_cstat
.sum
.num_whiteouts
<< "/" << info
.stats
.stats
.sum
.num_whiteouts
<< " whiteouts, "
14202 << scrub_cstat
.sum
.num_bytes
<< "/" << info
.stats
.stats
.sum
.num_bytes
<< " bytes, "
14203 << scrub_cstat
.sum
.num_bytes_hit_set_archive
<< "/" << info
.stats
.stats
.sum
.num_bytes_hit_set_archive
<< " hit_set_archive bytes.";
14204 ++scrubber
.shallow_errors
;
14208 info
.stats
.stats
= scrub_cstat
;
14209 info
.stats
.dirty_stats_invalid
= false;
14210 info
.stats
.omap_stats_invalid
= false;
14211 info
.stats
.hitset_stats_invalid
= false;
14212 info
.stats
.hitset_bytes_stats_invalid
= false;
14213 publish_stats_to_osd();
14216 } else if (scrub_cstat
.sum
.num_legacy_snapsets
!=
14217 info
.stats
.stats
.sum
.num_legacy_snapsets
) {
14218 osd
->clog
->info() << info
.pgid
<< " " << mode
<< " updated num_legacy_snapsets"
14219 << " from " << info
.stats
.stats
.sum
.num_legacy_snapsets
14220 << " -> " << scrub_cstat
.sum
.num_legacy_snapsets
<< "\n";
14221 info
.stats
.stats
.sum
.num_legacy_snapsets
= scrub_cstat
.sum
.num_legacy_snapsets
;
14222 publish_stats_to_osd();
14225 // Clear object context cache to get repair information
14227 object_contexts
.clear();
14230 bool PrimaryLogPG::check_osdmap_full(const set
<pg_shard_t
> &missing_on
)
14232 return osd
->check_osdmap_full(missing_on
);
14235 int PrimaryLogPG::rep_repair_primary_object(const hobject_t
& soid
, OpRequestRef op
)
14237 // Only supports replicated pools
14238 assert(!pool
.info
.require_rollback());
14239 assert(is_primary());
14241 dout(10) << __func__
<< " " << soid
14242 << " peers osd.{" << actingbackfill
<< "}" << dendl
;
14245 block_for_clean(soid
, op
);
14249 assert(!pg_log
.get_missing().is_missing(soid
));
14253 int r
= get_pgbackend()->objects_get_attr(soid
, OI_ATTR
, &bv
);
14255 // Leave v and try to repair without a version, getting attr failed
14256 dout(0) << __func__
<< ": Need version of replica, objects_get_attr failed: "
14257 << soid
<< " error=" << r
<< dendl
;
14259 bufferlist::iterator bliter
= bv
.begin();
14260 ::decode(oi
, bliter
);
14263 // Leave v as default constructed. This will fail when sent to older OSDs, but
14264 // not much worse than failing here.
14265 dout(0) << __func__
<< ": Need version of replica, bad object_info_t: " << soid
<< dendl
;
14268 missing_loc
.add_missing(soid
, v
, eversion_t());
14269 if (primary_error(soid
, v
)) {
14270 dout(0) << __func__
<< " No other replicas available for " << soid
<< dendl
;
14271 // XXX: If we knew that there is no down osd which could include this
14272 // object, it would be nice if we could return EIO here.
14273 // If a "never fail" flag was available, that could be used
14274 // for rbd to NOT return EIO until object marked lost.
14276 // Drop through to save this op in case an osd comes up with the object.
14279 // Restart the op after object becomes readable again
14280 waiting_for_unreadable_object
[soid
].push_back(op
);
14281 op
->mark_delayed("waiting for missing object");
14283 if (!eio_errors_to_process
) {
14284 eio_errors_to_process
= true;
14285 assert(is_clean());
14286 queue_peering_event(
14288 std::make_shared
<CephPeeringEvt
>(
14289 get_osdmap()->get_epoch(),
14290 get_osdmap()->get_epoch(),
14293 // A prior error must have already cleared clean state and queued recovery
14294 // or a map change has triggered re-peering.
14295 // Not inlining the recovery by calling maybe_kick_recovery(soid);
14296 dout(5) << __func__
<< ": Read error on " << soid
<< ", but already seen errors" << dendl
;
14302 /*---SnapTrimmer Logging---*/
14304 #define dout_prefix *_dout << pg->gen_prefix()
14306 void PrimaryLogPG::SnapTrimmer::log_enter(const char *state_name
)
14308 ldout(pg
->cct
, 20) << "enter " << state_name
<< dendl
;
14311 void PrimaryLogPG::SnapTrimmer::log_exit(const char *state_name
, utime_t enter_time
)
14313 ldout(pg
->cct
, 20) << "exit " << state_name
<< dendl
;
14316 /*---SnapTrimmer states---*/
14318 #define dout_prefix (*_dout << context< SnapTrimmer >().pg->gen_prefix() \
14319 << "SnapTrimmer state<" << get_state_name() << ">: ")
14322 PrimaryLogPG::NotTrimming::NotTrimming(my_context ctx
)
14324 NamedState(context
< SnapTrimmer
>().pg
, "NotTrimming")
14326 context
< SnapTrimmer
>().log_enter(state_name
);
14329 void PrimaryLogPG::NotTrimming::exit()
14331 context
< SnapTrimmer
>().log_exit(state_name
, enter_time
);
14334 boost::statechart::result
PrimaryLogPG::NotTrimming::react(const KickTrim
&)
14336 PrimaryLogPG
*pg
= context
< SnapTrimmer
>().pg
;
14337 ldout(pg
->cct
, 10) << "NotTrimming react KickTrim" << dendl
;
14339 if (!(pg
->is_primary() && pg
->is_active())) {
14340 ldout(pg
->cct
, 10) << "NotTrimming not primary or active" << dendl
;
14341 return discard_event();
14343 if (!pg
->is_clean() ||
14344 pg
->snap_trimq
.empty()) {
14345 ldout(pg
->cct
, 10) << "NotTrimming not clean or nothing to trim" << dendl
;
14346 return discard_event();
14348 if (pg
->scrubber
.active
) {
14349 ldout(pg
->cct
, 10) << " scrubbing, will requeue snap_trimmer after" << dendl
;
14350 return transit
< WaitScrub
>();
14352 return transit
< Trimming
>();
14356 boost::statechart::result
PrimaryLogPG::WaitReservation::react(const SnapTrimReserved
&)
14358 PrimaryLogPG
*pg
= context
< SnapTrimmer
>().pg
;
14359 ldout(pg
->cct
, 10) << "WaitReservation react SnapTrimReserved" << dendl
;
14362 if (!context
< SnapTrimmer
>().can_trim()) {
14363 post_event(KickTrim());
14364 return transit
< NotTrimming
>();
14367 context
<Trimming
>().snap_to_trim
= pg
->snap_trimq
.range_start();
14368 ldout(pg
->cct
, 10) << "NotTrimming: trimming "
14369 << pg
->snap_trimq
.range_start()
14371 return transit
< AwaitAsyncWork
>();
14374 /* AwaitAsyncWork */
14375 PrimaryLogPG::AwaitAsyncWork::AwaitAsyncWork(my_context ctx
)
14377 NamedState(context
< SnapTrimmer
>().pg
, "Trimming/AwaitAsyncWork")
14379 auto *pg
= context
< SnapTrimmer
>().pg
;
14380 context
< SnapTrimmer
>().log_enter(state_name
);
14381 context
< SnapTrimmer
>().pg
->osd
->queue_for_snap_trim(pg
);
14382 pg
->state_set(PG_STATE_SNAPTRIM
);
14383 pg
->state_clear(PG_STATE_SNAPTRIM_ERROR
);
14384 pg
->publish_stats_to_osd();
14387 boost::statechart::result
PrimaryLogPG::AwaitAsyncWork::react(const DoSnapWork
&)
14389 PrimaryLogPGRef pg
= context
< SnapTrimmer
>().pg
;
14390 snapid_t snap_to_trim
= context
<Trimming
>().snap_to_trim
;
14391 auto &in_flight
= context
<Trimming
>().in_flight
;
14392 assert(in_flight
.empty());
14394 assert(pg
->is_primary() && pg
->is_active());
14395 if (!context
< SnapTrimmer
>().can_trim()) {
14396 ldout(pg
->cct
, 10) << "something changed, reverting to NotTrimming" << dendl
;
14397 post_event(KickTrim());
14398 return transit
< NotTrimming
>();
14401 ldout(pg
->cct
, 10) << "AwaitAsyncWork: trimming snap " << snap_to_trim
<< dendl
;
14403 vector
<hobject_t
> to_trim
;
14404 unsigned max
= pg
->cct
->_conf
->osd_pg_max_concurrent_snap_trims
;
14405 to_trim
.reserve(max
);
14406 int r
= pg
->snap_mapper
.get_next_objects_to_trim(
14410 if (r
!= 0 && r
!= -ENOENT
) {
14411 lderr(pg
->cct
) << "get_next_objects_to_trim returned "
14412 << cpp_strerror(r
) << dendl
;
14413 assert(0 == "get_next_objects_to_trim returned an invalid code");
14414 } else if (r
== -ENOENT
) {
14416 ldout(pg
->cct
, 10) << "got ENOENT" << dendl
;
14418 ldout(pg
->cct
, 10) << "adding snap " << snap_to_trim
14419 << " to purged_snaps"
14421 pg
->info
.purged_snaps
.insert(snap_to_trim
);
14422 pg
->snap_trimq
.erase(snap_to_trim
);
14423 ldout(pg
->cct
, 10) << "purged_snaps now "
14424 << pg
->info
.purged_snaps
<< ", snap_trimq now "
14425 << pg
->snap_trimq
<< dendl
;
14427 ObjectStore::Transaction t
;
14428 pg
->dirty_big_info
= true;
14429 pg
->write_if_dirty(t
);
14430 int tr
= pg
->osd
->store
->queue_transaction(pg
->osr
.get(), std::move(t
), NULL
);
14433 pg
->share_pg_info();
14434 post_event(KickTrim());
14435 return transit
< NotTrimming
>();
14437 assert(!to_trim
.empty());
14439 for (auto &&object
: to_trim
) {
14441 ldout(pg
->cct
, 10) << "AwaitAsyncWork react trimming " << object
<< dendl
;
14443 int error
= pg
->trim_object(in_flight
.empty(), object
, &ctx
);
14445 if (error
== -ENOLCK
) {
14446 ldout(pg
->cct
, 10) << "could not get write lock on obj "
14447 << object
<< dendl
;
14449 pg
->state_set(PG_STATE_SNAPTRIM_ERROR
);
14450 ldout(pg
->cct
, 10) << "Snaptrim error=" << error
<< dendl
;
14452 if (!in_flight
.empty()) {
14453 ldout(pg
->cct
, 10) << "letting the ones we already started finish" << dendl
;
14454 return transit
< WaitRepops
>();
14456 if (error
== -ENOLCK
) {
14457 ldout(pg
->cct
, 10) << "waiting for it to clear"
14459 return transit
< WaitRWLock
>();
14461 return transit
< NotTrimming
>();
14465 in_flight
.insert(object
);
14466 ctx
->register_on_success(
14467 [pg
, object
, &in_flight
]() {
14468 assert(in_flight
.find(object
) != in_flight
.end());
14469 in_flight
.erase(object
);
14470 if (in_flight
.empty()) {
14471 if (pg
->state_test(PG_STATE_SNAPTRIM_ERROR
)) {
14472 pg
->snap_trimmer_machine
.process_event(Reset());
14474 pg
->snap_trimmer_machine
.process_event(RepopsComplete());
14479 pg
->simple_opc_submit(std::move(ctx
));
14482 return transit
< WaitRepops
>();
14485 void PrimaryLogPG::setattr_maybe_cache(
14486 ObjectContextRef obc
,
14492 t
->setattr(obc
->obs
.oi
.soid
, key
, val
);
14495 void PrimaryLogPG::setattrs_maybe_cache(
14496 ObjectContextRef obc
,
14499 map
<string
, bufferlist
> &attrs
)
14501 t
->setattrs(obc
->obs
.oi
.soid
, attrs
);
14504 void PrimaryLogPG::rmattr_maybe_cache(
14505 ObjectContextRef obc
,
14510 t
->rmattr(obc
->obs
.oi
.soid
, key
);
14513 int PrimaryLogPG::getattr_maybe_cache(
14514 ObjectContextRef obc
,
14518 if (pool
.info
.require_rollback()) {
14519 map
<string
, bufferlist
>::iterator i
= obc
->attr_cache
.find(key
);
14520 if (i
!= obc
->attr_cache
.end()) {
14528 return pgbackend
->objects_get_attr(obc
->obs
.oi
.soid
, key
, val
);
14531 int PrimaryLogPG::getattrs_maybe_cache(
14532 ObjectContextRef obc
,
14533 map
<string
, bufferlist
> *out
,
14537 if (pool
.info
.require_rollback()) {
14539 *out
= obc
->attr_cache
;
14541 r
= pgbackend
->objects_get_attrs(obc
->obs
.oi
.soid
, out
);
14543 if (out
&& user_only
) {
14544 map
<string
, bufferlist
> tmp
;
14545 for (map
<string
, bufferlist
>::iterator i
= out
->begin();
14548 if (i
->first
.size() > 1 && i
->first
[0] == '_')
14549 tmp
[i
->first
.substr(1, i
->first
.size())].claim(i
->second
);
14556 bool PrimaryLogPG::check_failsafe_full(ostream
&ss
) {
14557 return osd
->check_failsafe_full(ss
);
14560 void intrusive_ptr_add_ref(PrimaryLogPG
*pg
) { pg
->get("intptr"); }
14561 void intrusive_ptr_release(PrimaryLogPG
*pg
) { pg
->put("intptr"); }
14563 #ifdef PG_DEBUG_REFS
14564 uint64_t get_with_id(PrimaryLogPG
*pg
) { return pg
->get_with_id(); }
14565 void put_with_id(PrimaryLogPG
*pg
, uint64_t id
) { return pg
->put_with_id(id
); }
14568 void intrusive_ptr_add_ref(PrimaryLogPG::RepGather
*repop
) { repop
->get(); }
14569 void intrusive_ptr_release(PrimaryLogPG::RepGather
*repop
) { repop
->put(); }