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>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
18 #include <boost/statechart/custom_reaction.hpp>
19 #include <boost/statechart/event.hpp>
20 #include <boost/statechart/simple_state.hpp>
21 #include <boost/statechart/state.hpp>
22 #include <boost/statechart/state_machine.hpp>
23 #include <boost/statechart/transition.hpp>
24 #include <boost/statechart/event_base.hpp>
25 #include <boost/scoped_ptr.hpp>
26 #include <boost/circular_buffer.hpp>
27 #include "include/memory.h"
28 #include "include/mempool.h"
30 // re-include our assert to clobber boost's
31 #include "include/assert.h"
33 #include "include/types.h"
34 #include "include/stringify.h"
35 #include "osd_types.h"
36 #include "include/xlist.h"
37 #include "SnapMapper.h"
39 #include "common/Timer.h"
43 #include "messages/MOSDPGLog.h"
44 #include "include/str_list.h"
45 #include "PGBackend.h"
55 // #include "include/unordered_map.h"
56 // #include "include/unordered_set.h"
58 //#define DEBUG_RECOVERY_OIDS // track set of recovering oids explicitly, to find counting bugs
69 typedef OpRequest::Ref OpRequestRef
;
77 void intrusive_ptr_add_ref(PG
*pg
);
78 void intrusive_ptr_release(PG
*pg
);
80 using state_history_entry
= std::tuple
<utime_t
, utime_t
, const char*>;
81 using embedded_state
= std::pair
<utime_t
, const char*>;
83 struct PGStateInstance
{
84 // Time spent in pg states
86 void setepoch(const epoch_t current_epoch
) {
87 this_epoch
= current_epoch
;
90 void enter_state(const utime_t entime
, const char* state
) {
91 embedded_states
.push(std::make_pair(entime
, state
));
94 void exit_state(const utime_t extime
) {
95 embedded_state this_state
= embedded_states
.top();
96 state_history
.push_back(state_history_entry
{
97 this_state
.first
, extime
, this_state
.second
});
98 embedded_states
.pop();
103 std::vector
<state_history_entry
> state_history
;
104 std::stack
<embedded_state
> embedded_states
;
107 class PGStateHistory
{
108 // Member access protected with the PG lock
110 PGStateHistory() : buffer(10) {}
112 void enter(PG
* pg
, const utime_t entime
, const char* state
);
114 void exit(const char* state
);
120 void set_pg_in_destructor() { pg_in_destructor
= true; }
122 void dump(Formatter
* f
) const;
125 bool pg_in_destructor
= false;
126 PG
* thispg
= nullptr;
127 std::unique_ptr
<PGStateInstance
> tmppi
;
128 PGStateInstance
* pi
= nullptr;
129 boost::circular_buffer
<std::unique_ptr
<PGStateInstance
>> buffer
;
134 #include "common/tracked_int_ptr.hpp"
135 uint64_t get_with_id(PG
*pg
);
136 void put_with_id(PG
*pg
, uint64_t id
);
137 typedef TrackedIntPtr
<PG
> PGRef
;
139 typedef boost::intrusive_ptr
<PG
> PGRef
;
142 class PGRecoveryStats
{
143 struct per_state_info
{
144 uint64_t enter
, exit
; // enter/exit counts
146 utime_t event_time
; // time spent processing events
147 utime_t total_time
; // total time in state
148 utime_t min_time
, max_time
;
150 // cppcheck-suppress unreachableCode
151 per_state_info() : enter(0), exit(0), events(0) {}
153 map
<const char *,per_state_info
> info
;
157 PGRecoveryStats() : lock("PGRecoverStats::lock") {}
160 Mutex::Locker
l(lock
);
163 void dump(ostream
& out
) {
164 Mutex::Locker
l(lock
);
165 for (map
<const char *,per_state_info
>::iterator p
= info
.begin(); p
!= info
.end(); ++p
) {
166 per_state_info
& i
= p
->second
;
167 out
<< i
.enter
<< "\t" << i
.exit
<< "\t"
168 << i
.events
<< "\t" << i
.event_time
<< "\t"
169 << i
.total_time
<< "\t"
170 << i
.min_time
<< "\t" << i
.max_time
<< "\t"
175 void dump_formatted(Formatter
*f
) {
176 Mutex::Locker
l(lock
);
177 f
->open_array_section("pg_recovery_stats");
178 for (map
<const char *,per_state_info
>::iterator p
= info
.begin();
179 p
!= info
.end(); ++p
) {
180 per_state_info
& i
= p
->second
;
181 f
->open_object_section("recovery_state");
182 f
->dump_int("enter", i
.enter
);
183 f
->dump_int("exit", i
.exit
);
184 f
->dump_int("events", i
.events
);
185 f
->dump_stream("event_time") << i
.event_time
;
186 f
->dump_stream("total_time") << i
.total_time
;
187 f
->dump_stream("min_time") << i
.min_time
;
188 f
->dump_stream("max_time") << i
.max_time
;
189 vector
<string
> states
;
190 get_str_vec(p
->first
, "/", states
);
191 f
->open_array_section("nested_states");
192 for (vector
<string
>::iterator st
= states
.begin();
193 st
!= states
.end(); ++st
) {
194 f
->dump_string("state", *st
);
202 void log_enter(const char *s
) {
203 Mutex::Locker
l(lock
);
206 void log_exit(const char *s
, utime_t dur
, uint64_t events
, utime_t event_dur
) {
207 Mutex::Locker
l(lock
);
208 per_state_info
&i
= info
[s
];
211 if (dur
> i
.max_time
)
213 if (dur
< i
.min_time
|| i
.min_time
== utime_t())
216 i
.event_time
+= event_dur
;
222 epoch_t cached_epoch
;
228 SnapContext snapc
; // the default pool snapc, ready to go.
230 interval_set
<snapid_t
> cached_removed_snaps
; // current removed_snaps set
231 interval_set
<snapid_t
> newly_removed_snaps
; // newly removed in the last epoch
233 PGPool(CephContext
* cct
, OSDMapRef map
, int64_t i
)
235 cached_epoch(map
->get_epoch()),
237 name(map
->get_pool_name(id
)),
238 auid(map
->get_pg_pool(id
)->auid
) {
239 const pg_pool_t
*pi
= map
->get_pg_pool(id
);
242 snapc
= pi
->get_snap_context();
243 pi
->build_removed_snaps(cached_removed_snaps
);
246 void update(OSDMapRef map
);
249 /** PG - Replica Placement Group
253 class PG
: public DoutPrefixProvider
{
258 SnapMapper snap_mapper
;
260 virtual PGBackend
*get_pgbackend() = 0;
262 std::string
gen_prefix() const override
;
263 CephContext
*get_cct() const override
{ return cct
; }
264 unsigned get_subsys() const override
{ return ceph_subsys_osd
; }
267 void update_snap_mapper_bits(uint32_t bits
) {
268 snap_mapper
.update_bits(bits
);
270 /// get_is_recoverable_predicate: caller owns returned pointer and must delete when done
271 IsPGRecoverablePredicate
*get_is_recoverable_predicate() {
272 return get_pgbackend()->get_is_recoverable_predicate();
275 OSDMapRef osdmap_ref
;
276 OSDMapRef last_persisted_osdmap_ref
;
279 void requeue_map_waiters();
281 void update_osdmap_ref(OSDMapRef newmap
) {
282 assert(_lock
.is_locked_by_me());
283 osdmap_ref
= std::move(newmap
);
287 OSDMapRef
get_osdmap() const {
294 /** locking and reference counting.
295 * I destroy myself when the reference count hits zero.
296 * lock() should be called before doing anything.
297 * get() should be called on pointer copy (to another thread, etc.).
298 * put() should be called on destruction of some previously copied pointer.
299 * unlock() when done with the current pointer (_most common_).
302 std::atomic_uint ref
{0};
306 map
<uint64_t, string
> _live_ids
;
307 map
<string
, uint64_t> _tag_counts
;
312 bool deleting
; // true while in removing or OSD is shutting down
314 ZTracer::Endpoint trace_endpoint
;
316 void lock_suspend_timeout(ThreadPool::TPHandle
&handle
);
317 void lock(bool no_lockdep
= false) const;
318 void unlock() const {
319 //generic_dout(0) << this << " " << info.pgid << " unlock" << dendl;
321 assert(!dirty_big_info
);
325 bool is_locked() const {
326 return _lock
.is_locked();
330 uint64_t get_with_id();
331 void put_with_id(uint64_t);
332 void dump_live_ids();
334 void get(const char* tag
);
335 void put(const char* tag
);
337 bool dirty_info
, dirty_big_info
;
340 bool is_ec_pg() const {
341 return pool
.info
.ec_pool();
344 pg_info_t info
; ///< current pg info
345 pg_info_t last_written_info
; ///< last written info
347 static const __u8 cur_struct_v
= 10;
348 // v10 is the new past_intervals encoding
349 // v9 was fastinfo_key addition
350 // v8 was the move to a per-pg pgmeta object
351 // v7 was SnapMapper addition in 86658392516d5175b2756659ef7ffaaf95b0f8ad
352 // (first appeared in cuttlefish).
353 static const __u8 compat_struct_v
= 7;
354 bool must_upgrade() {
355 return info_struct_v
< cur_struct_v
;
358 return info_struct_v
>= compat_struct_v
;
360 void upgrade(ObjectStore
*store
);
363 ObjectStore::CollectionHandle ch
;
365 static string
get_info_key(spg_t pgid
) {
366 return stringify(pgid
) + "_info";
368 static string
get_biginfo_key(spg_t pgid
) {
369 return stringify(pgid
) + "_biginfo";
371 static string
get_epoch_key(spg_t pgid
) {
372 return stringify(pgid
) + "_epoch";
374 ghobject_t pgmeta_oid
;
377 map
<hobject_t
, pg_missing_item
> needs_recovery_map
;
378 map
<hobject_t
, set
<pg_shard_t
> > missing_loc
;
379 set
<pg_shard_t
> missing_loc_sources
;
381 set
<pg_shard_t
> empty_set
;
383 boost::scoped_ptr
<IsPGReadablePredicate
> is_readable
;
384 boost::scoped_ptr
<IsPGRecoverablePredicate
> is_recoverable
;
385 explicit MissingLoc(PG
*pg
)
387 void set_backend_predicates(
388 IsPGReadablePredicate
*_is_readable
,
389 IsPGRecoverablePredicate
*_is_recoverable
) {
390 is_readable
.reset(_is_readable
);
391 is_recoverable
.reset(_is_recoverable
);
393 string
gen_prefix() const { return pg
->gen_prefix(); }
395 const hobject_t
&hoid
,
396 eversion_t
*v
= 0) const {
397 map
<hobject_t
, pg_missing_item
>::const_iterator i
=
398 needs_recovery_map
.find(hoid
);
399 if (i
== needs_recovery_map
.end())
405 bool is_unfound(const hobject_t
&hoid
) const {
406 return needs_recovery(hoid
) && (
407 !missing_loc
.count(hoid
) ||
408 !(*is_recoverable
)(missing_loc
.find(hoid
)->second
));
410 bool readable_with_acting(
411 const hobject_t
&hoid
,
412 const set
<pg_shard_t
> &acting
) const;
413 uint64_t num_unfound() const {
415 for (map
<hobject_t
, pg_missing_item
>::const_iterator i
=
416 needs_recovery_map
.begin();
417 i
!= needs_recovery_map
.end();
419 if (is_unfound(i
->first
))
425 bool have_unfound() const {
426 for (map
<hobject_t
, pg_missing_item
>::const_iterator i
=
427 needs_recovery_map
.begin();
428 i
!= needs_recovery_map
.end();
430 if (is_unfound(i
->first
))
436 needs_recovery_map
.clear();
438 missing_loc_sources
.clear();
441 void add_location(const hobject_t
&hoid
, pg_shard_t location
) {
442 missing_loc
[hoid
].insert(location
);
444 void remove_location(const hobject_t
&hoid
, pg_shard_t location
) {
445 missing_loc
[hoid
].erase(location
);
447 void add_active_missing(const pg_missing_t
&missing
) {
448 for (map
<hobject_t
, pg_missing_item
>::const_iterator i
=
449 missing
.get_items().begin();
450 i
!= missing
.get_items().end();
452 map
<hobject_t
, pg_missing_item
>::const_iterator j
=
453 needs_recovery_map
.find(i
->first
);
454 if (j
== needs_recovery_map
.end()) {
455 needs_recovery_map
.insert(*i
);
457 assert(i
->second
.need
== j
->second
.need
);
462 void add_missing(const hobject_t
&hoid
, eversion_t need
, eversion_t have
) {
463 needs_recovery_map
[hoid
] = pg_missing_item(need
, have
);
465 void revise_need(const hobject_t
&hoid
, eversion_t need
) {
466 assert(needs_recovery(hoid
));
467 needs_recovery_map
[hoid
].need
= need
;
470 /// Adds info about a possible recovery source
471 bool add_source_info(
472 pg_shard_t source
, ///< [in] source
473 const pg_info_t
&oinfo
, ///< [in] info
474 const pg_missing_t
&omissing
, ///< [in] (optional) missing
475 ThreadPool::TPHandle
* handle
///< [in] ThreadPool handle
476 ); ///< @return whether a new object location was discovered
478 /// Adds recovery sources in batch
479 void add_batch_sources_info(
480 const set
<pg_shard_t
> &sources
, ///< [in] a set of resources which can be used for all objects
481 ThreadPool::TPHandle
* handle
///< [in] ThreadPool handle
484 /// Uses osdmap to update structures for now down sources
485 void check_recovery_sources(const OSDMapRef
& osdmap
);
487 /// Call when hoid is no longer missing in acting set
488 void recovered(const hobject_t
&hoid
) {
489 needs_recovery_map
.erase(hoid
);
490 missing_loc
.erase(hoid
);
493 /// Call to update structures for hoid after a change
495 const hobject_t
&hoid
,
497 const set
<pg_shard_t
> to_recover
,
498 const pg_info_t
&info
,
499 const pg_missing_t
&missing
,
500 const map
<pg_shard_t
, pg_missing_t
> &pmissing
,
501 const map
<pg_shard_t
, pg_info_t
> &pinfo
) {
503 boost::optional
<pg_missing_item
> item
;
504 auto miter
= missing
.get_items().find(hoid
);
505 if (miter
!= missing
.get_items().end()) {
506 item
= miter
->second
;
508 for (auto &&i
: to_recover
) {
511 auto pmiter
= pmissing
.find(i
);
512 assert(pmiter
!= pmissing
.end());
513 miter
= pmiter
->second
.get_items().find(hoid
);
514 if (miter
!= pmiter
->second
.get_items().end()) {
515 item
= miter
->second
;
521 return; // recovered!
523 needs_recovery_map
[hoid
] = *item
;
525 missing_loc
.insert(make_pair(hoid
, set
<pg_shard_t
>())).first
;
526 assert(info
.last_backfill
.is_max());
527 assert(info
.last_update
>= item
->need
);
528 if (!missing
.is_missing(hoid
))
529 mliter
->second
.insert(self
);
530 for (auto &&i
: pmissing
) {
531 auto pinfoiter
= pinfo
.find(i
.first
);
532 assert(pinfoiter
!= pinfo
.end());
533 if (item
->need
<= pinfoiter
->second
.last_update
&&
534 hoid
<= pinfoiter
->second
.last_backfill
&&
535 !i
.second
.is_missing(hoid
))
536 mliter
->second
.insert(i
.first
);
540 const set
<pg_shard_t
> &get_locations(const hobject_t
&hoid
) const {
541 return missing_loc
.count(hoid
) ?
542 missing_loc
.find(hoid
)->second
: empty_set
;
544 const map
<hobject_t
, set
<pg_shard_t
>> &get_missing_locs() const {
547 const map
<hobject_t
, pg_missing_item
> &get_needs_recovery() const {
548 return needs_recovery_map
;
552 PastIntervals past_intervals
;
554 interval_set
<snapid_t
> snap_trimq
;
556 /* You should not use these items without taking their respective queue locks
557 * (if they have one) */
558 xlist
<PG
*>::item stat_queue_item
;
560 bool recovery_queued
;
562 int recovery_ops_active
;
563 set
<pg_shard_t
> waiting_on_backfill
;
564 #ifdef DEBUG_RECOVERY_OIDS
565 set
<hobject_t
> recovering_oids
;
569 int role
; // 0 = primary, 1 = replica, -1=none.
570 unsigned state
; // PG_STATE_*
572 bool send_notify
; ///< true if we are non-primary and should notify the primary
575 eversion_t last_update_ondisk
; // last_update that has committed; ONLY DEFINED WHEN is_active()
576 eversion_t last_complete_ondisk
; // last_complete that has committed.
577 eversion_t last_update_applied
;
580 struct C_UpdateLastRollbackInfoTrimmedToApplied
: Context
{
584 C_UpdateLastRollbackInfoTrimmedToApplied(PG
*pg
, epoch_t e
, eversion_t v
)
585 : pg(pg
), e(e
), v(v
) {}
586 void finish(int) override
{
588 if (!pg
->pg_has_reset_since(e
)) {
589 pg
->last_rollback_info_trimmed_to_applied
= v
;
594 // entries <= last_rollback_info_trimmed_to_applied have been trimmed,
595 // and the transaction has applied
596 eversion_t last_rollback_info_trimmed_to_applied
;
601 pg_shard_t pg_whoami
;
602 pg_shard_t up_primary
;
603 vector
<int> up
, acting
, want_acting
;
604 set
<pg_shard_t
> actingbackfill
, actingset
, upset
;
605 map
<pg_shard_t
,eversion_t
> peer_last_complete_ondisk
;
606 eversion_t min_last_complete_ondisk
; // up: min over last_complete_ondisk, peer_last_complete_ondisk
607 eversion_t pg_trim_to
;
609 set
<int> blocked_by
; ///< osds we are blocked by (for pg stats)
611 // [primary only] content recovery state
614 struct BufferedRecoveryMessages
{
615 map
<int, map
<spg_t
, pg_query_t
> > query_map
;
616 map
<int, vector
<pair
<pg_notify_t
, PastIntervals
> > > info_map
;
617 map
<int, vector
<pair
<pg_notify_t
, PastIntervals
> > > notify_list
;
622 map
<int, map
<spg_t
, pg_query_t
> > *query_map
;
623 map
<int, vector
<pair
<pg_notify_t
, PastIntervals
> > > *info_map
;
624 map
<int, vector
<pair
<pg_notify_t
, PastIntervals
> > > *notify_list
;
625 set
<PGRef
> created_pgs
;
626 C_Contexts
*on_applied
;
628 ObjectStore::Transaction
*transaction
;
629 ThreadPool::TPHandle
* handle
;
630 RecoveryCtx(map
<int, map
<spg_t
, pg_query_t
> > *query_map
,
632 vector
<pair
<pg_notify_t
, PastIntervals
> > > *info_map
,
634 vector
<pair
<pg_notify_t
, PastIntervals
> > > *notify_list
,
635 C_Contexts
*on_applied
,
637 ObjectStore::Transaction
*transaction
)
638 : query_map(query_map
), info_map(info_map
),
639 notify_list(notify_list
),
640 on_applied(on_applied
),
642 transaction(transaction
),
645 RecoveryCtx(BufferedRecoveryMessages
&buf
, RecoveryCtx
&rctx
)
646 : query_map(&(buf
.query_map
)),
647 info_map(&(buf
.info_map
)),
648 notify_list(&(buf
.notify_list
)),
649 on_applied(rctx
.on_applied
),
650 on_safe(rctx
.on_safe
),
651 transaction(rctx
.transaction
),
652 handle(rctx
.handle
) {}
654 void accept_buffered_messages(BufferedRecoveryMessages
&m
) {
658 for (map
<int, map
<spg_t
, pg_query_t
> >::iterator i
= m
.query_map
.begin();
659 i
!= m
.query_map
.end();
661 map
<spg_t
, pg_query_t
> &omap
= (*query_map
)[i
->first
];
662 for (map
<spg_t
, pg_query_t
>::iterator j
= i
->second
.begin();
663 j
!= i
->second
.end();
665 omap
[j
->first
] = j
->second
;
668 for (map
<int, vector
<pair
<pg_notify_t
, PastIntervals
> > >::iterator i
669 = m
.info_map
.begin();
670 i
!= m
.info_map
.end();
672 vector
<pair
<pg_notify_t
, PastIntervals
> > &ovec
=
673 (*info_map
)[i
->first
];
674 ovec
.reserve(ovec
.size() + i
->second
.size());
675 ovec
.insert(ovec
.end(), i
->second
.begin(), i
->second
.end());
677 for (map
<int, vector
<pair
<pg_notify_t
, PastIntervals
> > >::iterator i
678 = m
.notify_list
.begin();
679 i
!= m
.notify_list
.end();
681 vector
<pair
<pg_notify_t
, PastIntervals
> > &ovec
=
682 (*notify_list
)[i
->first
];
683 ovec
.reserve(ovec
.size() + i
->second
.size());
684 ovec
.insert(ovec
.end(), i
->second
.begin(), i
->second
.end());
690 PGStateHistory pgstate_history
;
693 const char *state_name
;
696 const char *get_state_name() { return state_name
; }
697 NamedState(PG
*pg_
, const char *state_name_
)
698 : state_name(state_name_
), enter_time(ceph_clock_now()), pg(pg_
) {
699 pg
->pgstate_history
.enter(pg
, enter_time
, state_name
);
701 virtual ~NamedState() { pg
->pgstate_history
.exit(state_name
); }
709 * peer_info -- projected (updates _before_ replicas ack)
710 * peer_missing -- committed (updates _after_ replicas ack)
714 set
<pg_shard_t
> stray_set
; // non-acting osds that have PG data.
715 eversion_t oldest_update
; // acting: lowest (valid) last_update in active set
716 map
<pg_shard_t
, pg_info_t
> peer_info
; // info from peers (stray or prior)
717 set
<pg_shard_t
> peer_purged
; // peers purged
718 map
<pg_shard_t
, pg_missing_t
> peer_missing
;
719 set
<pg_shard_t
> peer_log_requested
; // logs i've requested (and start stamps)
720 set
<pg_shard_t
> peer_missing_requested
;
722 // i deleted these strays; ignore racing PGInfo from them
723 set
<pg_shard_t
> peer_activated
;
725 // primary-only, recovery-only state
726 set
<pg_shard_t
> might_have_unfound
; // These osds might have objects on them
727 // which are unfound on the primary
728 epoch_t last_peering_reset
;
731 /* heartbeat peers */
732 void set_probe_targets(const set
<pg_shard_t
> &probe_set
);
733 void clear_probe_targets();
735 Mutex heartbeat_peer_lock
;
736 set
<int> heartbeat_peers
;
737 set
<int> probe_targets
;
742 * Represents the objects in a range [begin, end)
745 * 1) begin == end == hobject_t() indicates the the interval is unpopulated
746 * 2) Else, objects contains all objects in [begin, end)
748 struct BackfillInterval
{
749 // info about a backfill interval on a peer
750 eversion_t version
; /// version at which the scan occurred
751 map
<hobject_t
,eversion_t
> objects
;
757 *this = BackfillInterval();
760 /// clear objects list only
761 void clear_objects() {
765 /// reinstantiate with a new start+end position and sort order
766 void reset(hobject_t start
) {
771 /// true if there are no objects in this interval
773 return objects
.empty();
776 /// true if interval extends to the end of the range
777 bool extends_to_end() const {
781 /// removes items <= soid and adjusts begin to the first object
782 void trim_to(const hobject_t
&soid
) {
784 while (!objects
.empty() &&
785 objects
.begin()->first
<= soid
) {
790 /// Adjusts begin to the first object
792 if (!objects
.empty())
793 begin
= objects
.begin()->first
;
798 /// drop first entry, and adjust @begin accordingly
800 assert(!objects
.empty());
801 objects
.erase(objects
.begin());
806 void dump(Formatter
*f
) const {
807 f
->dump_stream("begin") << begin
;
808 f
->dump_stream("end") << end
;
809 f
->open_array_section("objects");
810 for (map
<hobject_t
, eversion_t
>::const_iterator i
=
814 f
->open_object_section("object");
815 f
->dump_stream("object") << i
->first
;
816 f
->dump_stream("version") << i
->second
;
824 BackfillInterval backfill_info
;
825 map
<pg_shard_t
, BackfillInterval
> peer_backfill_info
;
826 bool backfill_reserved
;
827 bool backfill_reserving
;
832 set
<pg_shard_t
> backfill_targets
;
834 bool is_backfill_targets(pg_shard_t osd
) {
835 return backfill_targets
.count(osd
);
841 * blocked request wait hierarchy
843 * In order to preserve request ordering we need to be careful about the
844 * order in which blocked requests get requeued. Generally speaking, we
845 * push the requests back up to the op_wq in reverse order (most recent
846 * request first) so that they come back out again in the original order.
847 * However, because there are multiple wait queues, we need to requeue
848 * waitlists in order. Generally speaking, we requeue the wait lists
849 * that are checked first.
851 * Here are the various wait lists, in the order they are used during
852 * request processing, with notes:
855 * - may start or stop blocking at any time (depending on client epoch)
856 * - waiting_for_peered
857 * - !is_peered() or flushes_in_progress
858 * - only starts blocking on interval change; never restarts
859 * - waiting_for_active
861 * - only starts blocking on interval change; never restarts
862 * - waiting_for_scrub
863 * - starts and stops blocking for varying intervals during scrub
864 * - waiting_for_unreadable_object
865 * - never restarts once object is readable (* except for EIO?)
866 * - waiting_for_degraded_object
867 * - never restarts once object is writeable (* except for EIO?)
868 * - waiting_for_blocked_object
869 * - starts and stops based on proxied op activity
871 * - starts and stops based on read/write activity
875 * 1. During and interval change, we requeue *everything* in the above order.
877 * 2. When an obc rwlock is released, we check for a scrub block and requeue
878 * the op there if it applies. We ignore the unreadable/degraded/blocked
879 * queues because we assume they cannot apply at that time (this is
880 * probably mostly true).
882 * 3. The requeue_ops helper will push ops onto the waiting_for_map list if
885 * These three behaviors are generally sufficient to maintain ordering, with
886 * the possible exception of cases where we make an object degraded or
887 * unreadable that was previously okay, e.g. when scrub or op processing
888 * encounter an unexpected error. FIXME.
892 unsigned flushes_in_progress
;
894 // ops with newer maps than our (or blocked behind them)
895 // track these by client, since inter-request ordering doesn't otherwise
897 unordered_map
<entity_name_t
,list
<OpRequestRef
>> waiting_for_map
;
899 // ops waiting on peered
900 list
<OpRequestRef
> waiting_for_peered
;
902 // ops waiting on active (require peered as well)
903 list
<OpRequestRef
> waiting_for_active
;
904 list
<OpRequestRef
> waiting_for_scrub
;
906 list
<OpRequestRef
> waiting_for_cache_not_full
;
907 list
<OpRequestRef
> waiting_for_all_missing
;
908 map
<hobject_t
, list
<OpRequestRef
>> waiting_for_unreadable_object
,
909 waiting_for_degraded_object
,
910 waiting_for_blocked_object
;
912 set
<hobject_t
> objects_blocked_on_cache_full
;
913 map
<hobject_t
,snapid_t
> objects_blocked_on_degraded_snap
;
914 map
<hobject_t
,ObjectContextRef
> objects_blocked_on_snap_promotion
;
916 // Callbacks should assume pg (and nothing else) is locked
917 map
<hobject_t
, list
<Context
*>> callbacks_for_degraded_object
;
920 list
<pair
<OpRequestRef
, version_t
> > > waiting_for_ondisk
;
922 void requeue_object_waiters(map
<hobject_t
, list
<OpRequestRef
>>& m
);
923 void requeue_op(OpRequestRef op
);
924 void requeue_ops(list
<OpRequestRef
> &l
);
926 // stats that persist lazily
927 object_stat_collection_t unstable_stats
;
930 Mutex pg_stats_publish_lock
;
931 bool pg_stats_publish_valid
;
932 pg_stat_t pg_stats_publish
;
934 // for ordering writes
935 ceph::shared_ptr
<ObjectStore::Sequencer
> osr
;
937 void _update_calc_stats();
938 void _update_blocked_by();
939 void publish_stats_to_osd();
940 void clear_publish_stats();
943 void clear_primary_state();
946 bool is_actingbackfill(pg_shard_t osd
) const {
947 return actingbackfill
.count(osd
);
949 bool is_acting(pg_shard_t osd
) const {
950 return has_shard(pool
.info
.ec_pool(), acting
, osd
);
952 bool is_up(pg_shard_t osd
) const {
953 return has_shard(pool
.info
.ec_pool(), up
, osd
);
955 static bool has_shard(bool ec
, const vector
<int>& v
, pg_shard_t osd
) {
957 return v
.size() > (unsigned)osd
.shard
&& v
[osd
.shard
] == osd
.osd
;
959 return std::find(v
.begin(), v
.end(), osd
.osd
) != v
.end();
963 bool needs_recovery() const;
964 bool needs_backfill() const;
966 /// get log recovery reservation priority
967 unsigned get_recovery_priority();
968 /// get backfill reservation priority
969 unsigned get_backfill_priority();
971 void mark_clean(); ///< mark an active pg clean
973 /// return [start,end) bounds for required past_intervals
974 static pair
<epoch_t
, epoch_t
> get_required_past_interval_bounds(
975 const pg_info_t
&info
,
976 epoch_t oldest_map
) {
978 info
.history
.last_epoch_clean
? info
.history
.last_epoch_clean
:
979 info
.history
.epoch_created
,
982 info
.history
.same_interval_since
,
983 info
.history
.epoch_created
);
984 return make_pair(start
, end
);
986 void check_past_interval_bounds() const;
987 PastIntervals::PriorSet
build_prior();
989 void remove_down_peer_info(const OSDMapRef osdmap
);
991 bool adjust_need_up_thru(const OSDMapRef osdmap
);
993 bool all_unfound_are_queried_or_lost(const OSDMapRef osdmap
) const;
994 virtual void dump_recovery_info(Formatter
*f
) const = 0;
996 bool calc_min_last_complete_ondisk() {
997 eversion_t min
= last_complete_ondisk
;
998 assert(!actingbackfill
.empty());
999 for (set
<pg_shard_t
>::iterator i
= actingbackfill
.begin();
1000 i
!= actingbackfill
.end();
1002 if (*i
== get_primary()) continue;
1003 if (peer_last_complete_ondisk
.count(*i
) == 0)
1004 return false; // we don't have complete info
1005 eversion_t a
= peer_last_complete_ondisk
[*i
];
1009 if (min
== min_last_complete_ondisk
)
1011 min_last_complete_ondisk
= min
;
1015 virtual void calc_trim_to() = 0;
1017 void proc_replica_log(pg_info_t
&oinfo
, const pg_log_t
&olog
,
1018 pg_missing_t
& omissing
, pg_shard_t from
);
1019 void proc_master_log(ObjectStore::Transaction
& t
, pg_info_t
&oinfo
, pg_log_t
&olog
,
1020 pg_missing_t
& omissing
, pg_shard_t from
);
1021 bool proc_replica_info(
1022 pg_shard_t from
, const pg_info_t
&info
, epoch_t send_epoch
);
1024 struct PGLogEntryHandler
: public PGLog::LogEntryHandler
{
1026 ObjectStore::Transaction
*t
;
1027 PGLogEntryHandler(PG
*pg
, ObjectStore::Transaction
*t
) : pg(pg
), t(t
) {}
1030 void remove(const hobject_t
&hoid
) override
{
1031 pg
->get_pgbackend()->remove(hoid
, t
);
1033 void try_stash(const hobject_t
&hoid
, version_t v
) override
{
1034 pg
->get_pgbackend()->try_stash(hoid
, v
, t
);
1036 void rollback(const pg_log_entry_t
&entry
) override
{
1037 assert(entry
.can_rollback());
1038 pg
->get_pgbackend()->rollback(entry
, t
);
1040 void rollforward(const pg_log_entry_t
&entry
) override
{
1041 pg
->get_pgbackend()->rollforward(entry
, t
);
1043 void trim(const pg_log_entry_t
&entry
) override
{
1044 pg
->get_pgbackend()->trim(entry
, t
);
1048 void update_object_snap_mapping(
1049 ObjectStore::Transaction
*t
, const hobject_t
&soid
,
1050 const set
<snapid_t
> &snaps
);
1051 void clear_object_snap_mapping(
1052 ObjectStore::Transaction
*t
, const hobject_t
&soid
);
1053 void remove_snap_mapped_object(
1054 ObjectStore::Transaction
& t
, const hobject_t
& soid
);
1056 ObjectStore::Transaction
& t
, pg_info_t
&oinfo
,
1057 pg_log_t
&olog
, pg_shard_t from
);
1058 void rewind_divergent_log(ObjectStore::Transaction
& t
, eversion_t newhead
);
1059 bool search_for_missing(
1060 const pg_info_t
&oinfo
, const pg_missing_t
&omissing
,
1064 void check_for_lost_objects();
1065 void forget_lost_objects();
1067 void discover_all_missing(std::map
<int, map
<spg_t
,pg_query_t
> > &query_map
);
1069 void trim_write_ahead();
1071 map
<pg_shard_t
, pg_info_t
>::const_iterator
find_best_info(
1072 const map
<pg_shard_t
, pg_info_t
> &infos
,
1073 bool restrict_to_up_acting
,
1074 bool *history_les_bound
) const;
1075 static void calc_ec_acting(
1076 map
<pg_shard_t
, pg_info_t
>::const_iterator auth_log_shard
,
1078 const vector
<int> &acting
,
1079 pg_shard_t acting_primary
,
1080 const vector
<int> &up
,
1081 pg_shard_t up_primary
,
1082 const map
<pg_shard_t
, pg_info_t
> &all_info
,
1084 bool restrict_to_up_acting
,
1086 set
<pg_shard_t
> *backfill
,
1087 set
<pg_shard_t
> *acting_backfill
,
1088 pg_shard_t
*want_primary
,
1090 static void calc_replicated_acting(
1091 map
<pg_shard_t
, pg_info_t
>::const_iterator auth_log_shard
,
1093 const vector
<int> &acting
,
1094 pg_shard_t acting_primary
,
1095 const vector
<int> &up
,
1096 pg_shard_t up_primary
,
1097 const map
<pg_shard_t
, pg_info_t
> &all_info
,
1099 bool restrict_to_up_acting
,
1101 set
<pg_shard_t
> *backfill
,
1102 set
<pg_shard_t
> *acting_backfill
,
1103 pg_shard_t
*want_primary
,
1105 bool choose_acting(pg_shard_t
&auth_log_shard
,
1106 bool restrict_to_up_acting
,
1107 bool *history_les_bound
);
1108 void build_might_have_unfound();
1110 ObjectStore::Transaction
& t
,
1111 epoch_t activation_epoch
,
1112 list
<Context
*>& tfin
,
1113 map
<int, map
<spg_t
,pg_query_t
> >& query_map
,
1115 vector
<pair
<pg_notify_t
, PastIntervals
> > > *activator_map
,
1117 void _activate_committed(epoch_t epoch
, epoch_t activation_epoch
);
1118 void all_activated_and_committed();
1120 void proc_primary_info(ObjectStore::Transaction
&t
, const pg_info_t
&info
);
1122 bool have_unfound() const {
1123 return missing_loc
.have_unfound();
1125 uint64_t get_num_unfound() const {
1126 return missing_loc
.num_unfound();
1129 virtual void check_local() = 0;
1132 * @param ops_begun returns how many recovery ops the function started
1133 * @returns true if any useful work was accomplished; false otherwise
1135 virtual bool start_recovery_ops(
1137 ThreadPool::TPHandle
&handle
,
1138 uint64_t *ops_begun
) = 0;
1140 void purge_strays();
1142 void update_heartbeat_peers();
1144 Context
*finish_sync_event
;
1146 void finish_recovery(list
<Context
*>& tfin
);
1147 void _finish_recovery(Context
*c
);
1148 void cancel_recovery();
1149 void clear_recovery_state();
1150 virtual void _clear_recovery_state() = 0;
1151 virtual void check_recovery_sources(const OSDMapRef
& newmap
) = 0;
1152 void start_recovery_op(const hobject_t
& soid
);
1153 void finish_recovery_op(const hobject_t
& soid
, bool dequeue
=false);
1155 void split_into(pg_t child_pgid
, PG
*child
, unsigned split_bits
);
1156 virtual void _split_into(pg_t child_pgid
, PG
*child
, unsigned split_bits
) = 0;
1158 friend class C_OSD_RepModify_Commit
;
1161 Mutex backoff_lock
; // orders inside Backoff::lock
1162 map
<hobject_t
,set
<BackoffRef
>> backoffs
;
1164 void add_backoff(SessionRef s
, const hobject_t
& begin
, const hobject_t
& end
);
1165 void release_backoffs(const hobject_t
& begin
, const hobject_t
& end
);
1166 void release_backoffs(const hobject_t
& o
) {
1167 release_backoffs(o
, o
);
1169 void clear_backoffs();
1171 void add_pg_backoff(SessionRef s
) {
1172 hobject_t begin
= info
.pgid
.pgid
.get_hobj_start();
1173 hobject_t end
= info
.pgid
.pgid
.get_hobj_end(pool
.info
.get_pg_num());
1174 add_backoff(s
, begin
, end
);
1176 void release_pg_backoffs() {
1177 hobject_t begin
= info
.pgid
.pgid
.get_hobj_start();
1178 hobject_t end
= info
.pgid
.pgid
.get_hobj_end(pool
.info
.get_pg_num());
1179 release_backoffs(begin
, end
);
1182 void rm_backoff(BackoffRef b
);
1190 set
<pg_shard_t
> reserved_peers
;
1191 bool reserved
, reserve_failed
;
1192 epoch_t epoch_start
;
1194 // common to both scrubs
1196 bool queue_snap_trim
;
1198 set
<pg_shard_t
> waiting_on_whom
;
1202 ScrubMap primary_scrubmap
;
1203 map
<pg_shard_t
, ScrubMap
> received_maps
;
1204 OpRequestRef active_rep_scrub
;
1205 utime_t scrub_reg_stamp
; // stamp we registered for
1208 bool sleeping
= false;
1209 bool needs_sleep
= true;
1210 utime_t sleep_start
;
1212 // flags to indicate explicitly requested scrubs (by admin)
1213 bool must_scrub
, must_deep_scrub
, must_repair
;
1215 // Priority to use for scrub scheduling
1218 // this flag indicates whether we would like to do auto-repair of the PG or not
1221 // Maps from objects with errors to missing/inconsistent peers
1222 map
<hobject_t
, set
<pg_shard_t
>> missing
;
1223 map
<hobject_t
, set
<pg_shard_t
>> inconsistent
;
1225 // Map from object with errors to good peers
1226 map
<hobject_t
, list
<pair
<ScrubMap::object
, pg_shard_t
> >> authoritative
;
1228 // Cleaned map pending snap metadata scrub
1229 ScrubMap cleaned_meta_map
;
1231 // digest updates which we are waiting on
1232 int num_digest_updates_pending
;
1235 hobject_t start
, end
;
1236 eversion_t subset_last_update
;
1238 // chunky scrub state
1247 WAIT_DIGEST_UPDATES
,
1251 std::unique_ptr
<Scrub::Store
> store
;
1256 list
<Context
*> callbacks
;
1257 void add_callback(Context
*context
) {
1258 callbacks
.push_back(context
);
1260 void run_callbacks() {
1261 list
<Context
*> to_run
;
1262 to_run
.swap(callbacks
);
1263 for (list
<Context
*>::iterator i
= to_run
.begin();
1270 static const char *state_string(const PG::Scrubber::State
& state
) {
1271 const char *ret
= NULL
;
1274 case INACTIVE
: ret
= "INACTIVE"; break;
1275 case NEW_CHUNK
: ret
= "NEW_CHUNK"; break;
1276 case WAIT_PUSHES
: ret
= "WAIT_PUSHES"; break;
1277 case WAIT_LAST_UPDATE
: ret
= "WAIT_LAST_UPDATE"; break;
1278 case BUILD_MAP
: ret
= "BUILD_MAP"; break;
1279 case WAIT_REPLICAS
: ret
= "WAIT_REPLICAS"; break;
1280 case COMPARE_MAPS
: ret
= "COMPARE_MAPS"; break;
1281 case WAIT_DIGEST_UPDATES
: ret
= "WAIT_DIGEST_UPDATES"; break;
1282 case FINISH
: ret
= "FINISH"; break;
1287 bool is_chunky_scrub_active() const { return state
!= INACTIVE
; }
1289 // classic (non chunk) scrubs block all writes
1290 // chunky scrubs only block writes to a range
1291 bool write_blocked_by_scrub(const hobject_t
&soid
) {
1292 return (soid
>= start
&& soid
< end
);
1298 queue_snap_trim
= false;
1300 waiting_on_whom
.clear();
1301 if (active_rep_scrub
) {
1302 active_rep_scrub
= OpRequestRef();
1304 received_maps
.clear();
1307 must_deep_scrub
= false;
1308 must_repair
= false;
1309 auto_repair
= false;
1311 state
= PG::Scrubber::INACTIVE
;
1312 start
= hobject_t();
1314 subset_last_update
= eversion_t();
1321 inconsistent
.clear();
1323 authoritative
.clear();
1324 num_digest_updates_pending
= 0;
1325 cleaned_meta_map
= ScrubMap();
1328 sleep_start
= utime_t();
1331 void create_results(const hobject_t
& obj
);
1332 void cleanup_store(ObjectStore::Transaction
*t
);
1335 bool scrub_after_recovery
;
1340 const hobject_t
& soid
, list
<pair
<ScrubMap::object
, pg_shard_t
> > *ok_peers
,
1341 pg_shard_t bad_peer
);
1343 void scrub(epoch_t queued
, ThreadPool::TPHandle
&handle
);
1344 void chunky_scrub(ThreadPool::TPHandle
&handle
);
1345 void scrub_compare_maps();
1347 * return true if any inconsistency/missing is repaired, false otherwise
1349 bool scrub_process_inconsistent();
1350 void scrub_finish();
1351 void scrub_clear_state();
1352 void _scan_snaps(ScrubMap
&map
);
1353 void _scan_rollback_obs(
1354 const vector
<ghobject_t
> &rollback_obs
,
1355 ThreadPool::TPHandle
&handle
);
1356 void _request_scrub_map(pg_shard_t replica
, eversion_t version
,
1357 hobject_t start
, hobject_t end
, bool deep
,
1359 int build_scrub_map_chunk(
1361 hobject_t start
, hobject_t end
, bool deep
, uint32_t seed
,
1362 ThreadPool::TPHandle
&handle
);
1364 * returns true if [begin, end) is good to scrub at this time
1365 * a false return value obliges the implementer to requeue scrub when the
1366 * condition preventing scrub clears
1368 virtual bool _range_available_for_scrub(
1369 const hobject_t
&begin
, const hobject_t
&end
) = 0;
1370 virtual void scrub_snapshot_metadata(
1372 const std::map
<hobject_t
, pair
<uint32_t, uint32_t>> &missing_digest
) { }
1373 virtual void _scrub_clear_state() { }
1374 virtual void _scrub_finish() { }
1375 virtual void split_colls(
1379 const pg_pool_t
*pool
,
1380 ObjectStore::Transaction
*t
) = 0;
1381 void clear_scrub_reserved();
1382 void scrub_reserve_replicas();
1383 void scrub_unreserve_replicas();
1384 bool scrub_all_replicas_reserved() const;
1386 void reg_next_scrub();
1387 void unreg_next_scrub();
1391 ThreadPool::TPHandle
&handle
);
1392 void do_replica_scrub_map(OpRequestRef op
);
1393 void sub_op_scrub_map(OpRequestRef op
);
1395 void handle_scrub_reserve_request(OpRequestRef op
);
1396 void handle_scrub_reserve_grant(OpRequestRef op
, pg_shard_t from
);
1397 void handle_scrub_reserve_reject(OpRequestRef op
, pg_shard_t from
);
1398 void handle_scrub_reserve_release(OpRequestRef op
);
1400 void reject_reservation();
1401 void schedule_backfill_full_retry();
1402 void schedule_recovery_full_retry();
1404 // -- recovery state --
1406 template <class EVT
>
1407 struct QueuePeeringEvt
: Context
{
1411 QueuePeeringEvt(PG
*pg
, epoch_t epoch
, EVT evt
) :
1412 pg(pg
), epoch(epoch
), evt(evt
) {}
1413 void finish(int r
) override
{
1415 pg
->queue_peering_event(PG::CephPeeringEvtRef(
1416 new PG::CephPeeringEvt(
1424 class CephPeeringEvt
{
1426 epoch_t epoch_requested
;
1427 boost::intrusive_ptr
< const boost::statechart::event_base
> evt
;
1430 MEMPOOL_CLASS_HELPERS();
1432 CephPeeringEvt(epoch_t epoch_sent
,
1433 epoch_t epoch_requested
,
1435 epoch_sent(epoch_sent
), epoch_requested(epoch_requested
),
1436 evt(evt_
.intrusive_from_this()) {
1438 out
<< "epoch_sent: " << epoch_sent
1439 << " epoch_requested: " << epoch_requested
<< " ";
1443 epoch_t
get_epoch_sent() { return epoch_sent
; }
1444 epoch_t
get_epoch_requested() { return epoch_requested
; }
1445 const boost::statechart::event_base
&get_event() { return *evt
; }
1446 string
get_desc() { return desc
; }
1448 typedef ceph::shared_ptr
<CephPeeringEvt
> CephPeeringEvtRef
;
1449 list
<CephPeeringEvtRef
> peering_queue
; // op queue
1450 list
<CephPeeringEvtRef
> peering_waiters
;
1452 struct QueryState
: boost::statechart::event
< QueryState
> {
1454 explicit QueryState(Formatter
*f
) : f(f
) {}
1455 void print(std::ostream
*out
) const {
1460 struct MInfoRec
: boost::statechart::event
< MInfoRec
> {
1464 MInfoRec(pg_shard_t from
, const pg_info_t
&info
, epoch_t msg_epoch
) :
1465 from(from
), info(info
), msg_epoch(msg_epoch
) {}
1466 void print(std::ostream
*out
) const {
1467 *out
<< "MInfoRec from " << from
<< " info: " << info
;
1471 struct MLogRec
: boost::statechart::event
< MLogRec
> {
1473 boost::intrusive_ptr
<MOSDPGLog
> msg
;
1474 MLogRec(pg_shard_t from
, MOSDPGLog
*msg
) :
1475 from(from
), msg(msg
) {}
1476 void print(std::ostream
*out
) const {
1477 *out
<< "MLogRec from " << from
;
1481 struct MNotifyRec
: boost::statechart::event
< MNotifyRec
> {
1485 MNotifyRec(pg_shard_t from
, const pg_notify_t
¬ify
, uint64_t f
) :
1486 from(from
), notify(notify
), features(f
) {}
1487 void print(std::ostream
*out
) const {
1488 *out
<< "MNotifyRec from " << from
<< " notify: " << notify
1489 << " features: 0x" << hex
<< features
<< dec
;
1493 struct MQuery
: boost::statechart::event
< MQuery
> {
1496 epoch_t query_epoch
;
1497 MQuery(pg_shard_t from
, const pg_query_t
&query
, epoch_t query_epoch
):
1498 from(from
), query(query
), query_epoch(query_epoch
) {}
1499 void print(std::ostream
*out
) const {
1500 *out
<< "MQuery from " << from
1501 << " query_epoch " << query_epoch
1502 << " query: " << query
;
1506 struct AdvMap
: boost::statechart::event
< AdvMap
> {
1509 vector
<int> newup
, newacting
;
1510 int up_primary
, acting_primary
;
1512 OSDMapRef osdmap
, OSDMapRef lastmap
,
1513 vector
<int>& newup
, int up_primary
,
1514 vector
<int>& newacting
, int acting_primary
):
1515 osdmap(osdmap
), lastmap(lastmap
),
1517 newacting(newacting
),
1518 up_primary(up_primary
),
1519 acting_primary(acting_primary
) {}
1520 void print(std::ostream
*out
) const {
1525 struct ActMap
: boost::statechart::event
< ActMap
> {
1526 ActMap() : boost::statechart::event
< ActMap
>() {}
1527 void print(std::ostream
*out
) const {
1531 struct Activate
: boost::statechart::event
< Activate
> {
1532 epoch_t activation_epoch
;
1533 explicit Activate(epoch_t q
) : boost::statechart::event
< Activate
>(),
1534 activation_epoch(q
) {}
1535 void print(std::ostream
*out
) const {
1536 *out
<< "Activate from " << activation_epoch
;
1539 struct RequestBackfillPrio
: boost::statechart::event
< RequestBackfillPrio
> {
1541 explicit RequestBackfillPrio(unsigned prio
) :
1542 boost::statechart::event
< RequestBackfillPrio
>(),
1544 void print(std::ostream
*out
) const {
1545 *out
<< "RequestBackfillPrio: priority " << priority
;
1548 #define TrivialEvent(T) struct T : boost::statechart::event< T > { \
1549 T() : boost::statechart::event< T >() {} \
1550 void print(std::ostream *out) const { \
1554 TrivialEvent(Initialize
)
1556 TrivialEvent(GotInfo
)
1557 TrivialEvent(NeedUpThru
)
1558 TrivialEvent(NullEvt
)
1559 TrivialEvent(FlushedEvt
)
1560 TrivialEvent(Backfilled
)
1561 TrivialEvent(LocalBackfillReserved
)
1562 TrivialEvent(RemoteBackfillReserved
)
1563 TrivialEvent(RemoteReservationRejected
)
1564 TrivialEvent(RequestBackfill
)
1565 TrivialEvent(RequestRecovery
)
1566 TrivialEvent(RecoveryDone
)
1567 TrivialEvent(BackfillTooFull
)
1568 TrivialEvent(RecoveryTooFull
)
1570 TrivialEvent(AllReplicasRecovered
)
1571 TrivialEvent(DoRecovery
)
1572 TrivialEvent(LocalRecoveryReserved
)
1573 TrivialEvent(RemoteRecoveryReserved
)
1574 TrivialEvent(AllRemotesReserved
)
1575 TrivialEvent(AllBackfillsReserved
)
1576 TrivialEvent(GoClean
)
1578 TrivialEvent(AllReplicasActivated
)
1580 TrivialEvent(IntervalFlush
)
1582 /* Encapsulates PG recovery process */
1583 class RecoveryState
{
1584 void start_handle(RecoveryCtx
*new_ctx
);
1587 void begin_block_outgoing();
1588 void end_block_outgoing();
1589 void clear_blocked_outgoing();
1594 class RecoveryMachine
: public boost::statechart::state_machine
< RecoveryMachine
, Initial
> {
1595 RecoveryState
*state
;
1600 uint64_t event_count
;
1602 void clear_event_counters() {
1603 event_time
= utime_t();
1607 void log_enter(const char *state_name
);
1608 void log_exit(const char *state_name
, utime_t duration
);
1610 RecoveryMachine(RecoveryState
*state
, PG
*pg
) : state(state
), pg(pg
), event_count(0) {}
1612 /* Accessor functions for state methods */
1613 ObjectStore::Transaction
* get_cur_transaction() {
1614 assert(state
->rctx
);
1615 assert(state
->rctx
->transaction
);
1616 return state
->rctx
->transaction
;
1619 void send_query(pg_shard_t to
, const pg_query_t
&query
) {
1620 assert(state
->rctx
);
1621 assert(state
->rctx
->query_map
);
1622 (*state
->rctx
->query_map
)[to
.osd
][spg_t(pg
->info
.pgid
.pgid
, to
.shard
)] =
1626 map
<int, map
<spg_t
, pg_query_t
> > *get_query_map() {
1627 assert(state
->rctx
);
1628 assert(state
->rctx
->query_map
);
1629 return state
->rctx
->query_map
;
1632 map
<int, vector
<pair
<pg_notify_t
, PastIntervals
> > > *get_info_map() {
1633 assert(state
->rctx
);
1634 assert(state
->rctx
->info_map
);
1635 return state
->rctx
->info_map
;
1638 list
< Context
* > *get_on_safe_context_list() {
1639 assert(state
->rctx
);
1640 assert(state
->rctx
->on_safe
);
1641 return &(state
->rctx
->on_safe
->contexts
);
1644 list
< Context
* > *get_on_applied_context_list() {
1645 assert(state
->rctx
);
1646 assert(state
->rctx
->on_applied
);
1647 return &(state
->rctx
->on_applied
->contexts
);
1650 RecoveryCtx
*get_recovery_ctx() { return &*(state
->rctx
); }
1652 void send_notify(pg_shard_t to
,
1653 const pg_notify_t
&info
, const PastIntervals
&pi
) {
1654 assert(state
->rctx
);
1655 assert(state
->rctx
->notify_list
);
1656 (*state
->rctx
->notify_list
)[to
.osd
].push_back(make_pair(info
, pi
));
1659 friend class RecoveryMachine
;
1663 struct Crashed
: boost::statechart::state
< Crashed
, RecoveryMachine
>, NamedState
{
1664 explicit Crashed(my_context ctx
);
1669 struct Initial
: boost::statechart::state
< Initial
, RecoveryMachine
>, NamedState
{
1670 explicit Initial(my_context ctx
);
1673 typedef boost::mpl::list
<
1674 boost::statechart::transition
< Initialize
, Reset
>,
1675 boost::statechart::custom_reaction
< Load
>,
1676 boost::statechart::custom_reaction
< NullEvt
>,
1677 boost::statechart::transition
< boost::statechart::event_base
, Crashed
>
1680 boost::statechart::result
react(const Load
&);
1681 boost::statechart::result
react(const MNotifyRec
&);
1682 boost::statechart::result
react(const MInfoRec
&);
1683 boost::statechart::result
react(const MLogRec
&);
1684 boost::statechart::result
react(const boost::statechart::event_base
&) {
1685 return discard_event();
1689 struct Reset
: boost::statechart::state
< Reset
, RecoveryMachine
>, NamedState
{
1690 explicit Reset(my_context ctx
);
1693 typedef boost::mpl::list
<
1694 boost::statechart::custom_reaction
< QueryState
>,
1695 boost::statechart::custom_reaction
< AdvMap
>,
1696 boost::statechart::custom_reaction
< ActMap
>,
1697 boost::statechart::custom_reaction
< NullEvt
>,
1698 boost::statechart::custom_reaction
< FlushedEvt
>,
1699 boost::statechart::custom_reaction
< IntervalFlush
>,
1700 boost::statechart::transition
< boost::statechart::event_base
, Crashed
>
1702 boost::statechart::result
react(const QueryState
& q
);
1703 boost::statechart::result
react(const AdvMap
&);
1704 boost::statechart::result
react(const ActMap
&);
1705 boost::statechart::result
react(const FlushedEvt
&);
1706 boost::statechart::result
react(const IntervalFlush
&);
1707 boost::statechart::result
react(const boost::statechart::event_base
&) {
1708 return discard_event();
1714 struct Started
: boost::statechart::state
< Started
, RecoveryMachine
, Start
>, NamedState
{
1715 explicit Started(my_context ctx
);
1718 typedef boost::mpl::list
<
1719 boost::statechart::custom_reaction
< QueryState
>,
1720 boost::statechart::custom_reaction
< AdvMap
>,
1721 boost::statechart::custom_reaction
< NullEvt
>,
1722 boost::statechart::custom_reaction
< FlushedEvt
>,
1723 boost::statechart::custom_reaction
< IntervalFlush
>,
1724 boost::statechart::transition
< boost::statechart::event_base
, Crashed
>
1726 boost::statechart::result
react(const QueryState
& q
);
1727 boost::statechart::result
react(const AdvMap
&);
1728 boost::statechart::result
react(const FlushedEvt
&);
1729 boost::statechart::result
react(const IntervalFlush
&);
1730 boost::statechart::result
react(const boost::statechart::event_base
&) {
1731 return discard_event();
1735 struct MakePrimary
: boost::statechart::event
< MakePrimary
> {
1736 MakePrimary() : boost::statechart::event
< MakePrimary
>() {}
1738 struct MakeStray
: boost::statechart::event
< MakeStray
> {
1739 MakeStray() : boost::statechart::event
< MakeStray
>() {}
1744 struct Start
: boost::statechart::state
< Start
, Started
>, NamedState
{
1745 explicit Start(my_context ctx
);
1748 typedef boost::mpl::list
<
1749 boost::statechart::transition
< MakePrimary
, Primary
>,
1750 boost::statechart::transition
< MakeStray
, Stray
>
1755 struct WaitActingChange
;
1756 struct NeedActingChange
: boost::statechart::event
< NeedActingChange
> {
1757 NeedActingChange() : boost::statechart::event
< NeedActingChange
>() {}
1760 struct IsIncomplete
: boost::statechart::event
< IsIncomplete
> {
1761 IsIncomplete() : boost::statechart::event
< IsIncomplete
>() {}
1764 struct IsDown
: boost::statechart::event
< IsDown
> {
1765 IsDown() : boost::statechart::event
< IsDown
>() {}
1768 struct Primary
: boost::statechart::state
< Primary
, Started
, Peering
>, NamedState
{
1769 explicit Primary(my_context ctx
);
1772 typedef boost::mpl::list
<
1773 boost::statechart::custom_reaction
< ActMap
>,
1774 boost::statechart::custom_reaction
< MNotifyRec
>,
1775 boost::statechart::transition
< NeedActingChange
, WaitActingChange
>
1777 boost::statechart::result
react(const ActMap
&);
1778 boost::statechart::result
react(const MNotifyRec
&);
1781 struct WaitActingChange
: boost::statechart::state
< WaitActingChange
, Primary
>,
1783 typedef boost::mpl::list
<
1784 boost::statechart::custom_reaction
< QueryState
>,
1785 boost::statechart::custom_reaction
< AdvMap
>,
1786 boost::statechart::custom_reaction
< MLogRec
>,
1787 boost::statechart::custom_reaction
< MInfoRec
>,
1788 boost::statechart::custom_reaction
< MNotifyRec
>
1790 explicit WaitActingChange(my_context ctx
);
1791 boost::statechart::result
react(const QueryState
& q
);
1792 boost::statechart::result
react(const AdvMap
&);
1793 boost::statechart::result
react(const MLogRec
&);
1794 boost::statechart::result
react(const MInfoRec
&);
1795 boost::statechart::result
react(const MNotifyRec
&);
1802 struct Peering
: boost::statechart::state
< Peering
, Primary
, GetInfo
>, NamedState
{
1803 PastIntervals::PriorSet prior_set
;
1804 bool history_les_bound
; //< need osd_find_best_info_ignore_history_les
1806 explicit Peering(my_context ctx
);
1809 typedef boost::mpl::list
<
1810 boost::statechart::custom_reaction
< QueryState
>,
1811 boost::statechart::transition
< Activate
, Active
>,
1812 boost::statechart::custom_reaction
< AdvMap
>
1814 boost::statechart::result
react(const QueryState
& q
);
1815 boost::statechart::result
react(const AdvMap
&advmap
);
1818 struct WaitLocalRecoveryReserved
;
1820 struct Active
: boost::statechart::state
< Active
, Primary
, Activating
>, NamedState
{
1821 explicit Active(my_context ctx
);
1824 const set
<pg_shard_t
> remote_shards_to_reserve_recovery
;
1825 const set
<pg_shard_t
> remote_shards_to_reserve_backfill
;
1826 bool all_replicas_activated
;
1828 typedef boost::mpl::list
<
1829 boost::statechart::custom_reaction
< QueryState
>,
1830 boost::statechart::custom_reaction
< ActMap
>,
1831 boost::statechart::custom_reaction
< AdvMap
>,
1832 boost::statechart::custom_reaction
< MInfoRec
>,
1833 boost::statechart::custom_reaction
< MNotifyRec
>,
1834 boost::statechart::custom_reaction
< MLogRec
>,
1835 boost::statechart::custom_reaction
< Backfilled
>,
1836 boost::statechart::custom_reaction
< AllReplicasActivated
>
1838 boost::statechart::result
react(const QueryState
& q
);
1839 boost::statechart::result
react(const ActMap
&);
1840 boost::statechart::result
react(const AdvMap
&);
1841 boost::statechart::result
react(const MInfoRec
& infoevt
);
1842 boost::statechart::result
react(const MNotifyRec
& notevt
);
1843 boost::statechart::result
react(const MLogRec
& logevt
);
1844 boost::statechart::result
react(const Backfilled
&) {
1845 return discard_event();
1847 boost::statechart::result
react(const AllReplicasActivated
&);
1850 struct Clean
: boost::statechart::state
< Clean
, Active
>, NamedState
{
1851 typedef boost::mpl::list
<
1852 boost::statechart::transition
< DoRecovery
, WaitLocalRecoveryReserved
>
1854 explicit Clean(my_context ctx
);
1858 struct Recovered
: boost::statechart::state
< Recovered
, Active
>, NamedState
{
1859 typedef boost::mpl::list
<
1860 boost::statechart::transition
< GoClean
, Clean
>,
1861 boost::statechart::custom_reaction
< AllReplicasActivated
>
1863 explicit Recovered(my_context ctx
);
1865 boost::statechart::result
react(const AllReplicasActivated
&) {
1866 post_event(GoClean());
1867 return forward_event();
1871 struct Backfilling
: boost::statechart::state
< Backfilling
, Active
>, NamedState
{
1872 typedef boost::mpl::list
<
1873 boost::statechart::transition
< Backfilled
, Recovered
>,
1874 boost::statechart::custom_reaction
< RemoteReservationRejected
>
1876 explicit Backfilling(my_context ctx
);
1877 boost::statechart::result
react(const RemoteReservationRejected
& evt
);
1881 struct WaitRemoteBackfillReserved
: boost::statechart::state
< WaitRemoteBackfillReserved
, Active
>, NamedState
{
1882 typedef boost::mpl::list
<
1883 boost::statechart::custom_reaction
< RemoteBackfillReserved
>,
1884 boost::statechart::custom_reaction
< RemoteReservationRejected
>,
1885 boost::statechart::transition
< AllBackfillsReserved
, Backfilling
>
1887 set
<pg_shard_t
>::const_iterator backfill_osd_it
;
1888 explicit WaitRemoteBackfillReserved(my_context ctx
);
1890 boost::statechart::result
react(const RemoteBackfillReserved
& evt
);
1891 boost::statechart::result
react(const RemoteReservationRejected
& evt
);
1894 struct WaitLocalBackfillReserved
: boost::statechart::state
< WaitLocalBackfillReserved
, Active
>, NamedState
{
1895 typedef boost::mpl::list
<
1896 boost::statechart::transition
< LocalBackfillReserved
, WaitRemoteBackfillReserved
>
1898 explicit WaitLocalBackfillReserved(my_context ctx
);
1902 struct NotBackfilling
: boost::statechart::state
< NotBackfilling
, Active
>, NamedState
{
1903 typedef boost::mpl::list
<
1904 boost::statechart::transition
< RequestBackfill
, WaitLocalBackfillReserved
>,
1905 boost::statechart::custom_reaction
< RemoteBackfillReserved
>,
1906 boost::statechart::custom_reaction
< RemoteReservationRejected
>
1908 explicit NotBackfilling(my_context ctx
);
1910 boost::statechart::result
react(const RemoteBackfillReserved
& evt
);
1911 boost::statechart::result
react(const RemoteReservationRejected
& evt
);
1914 struct NotRecovering
: boost::statechart::state
< NotRecovering
, Active
>, NamedState
{
1915 typedef boost::mpl::list
<
1916 boost::statechart::transition
< DoRecovery
, WaitLocalRecoveryReserved
>
1918 explicit NotRecovering(my_context ctx
);
1922 struct RepNotRecovering
;
1923 struct ReplicaActive
: boost::statechart::state
< ReplicaActive
, Started
, RepNotRecovering
>, NamedState
{
1924 explicit ReplicaActive(my_context ctx
);
1927 typedef boost::mpl::list
<
1928 boost::statechart::custom_reaction
< QueryState
>,
1929 boost::statechart::custom_reaction
< ActMap
>,
1930 boost::statechart::custom_reaction
< MQuery
>,
1931 boost::statechart::custom_reaction
< MInfoRec
>,
1932 boost::statechart::custom_reaction
< MLogRec
>,
1933 boost::statechart::custom_reaction
< Activate
>
1935 boost::statechart::result
react(const QueryState
& q
);
1936 boost::statechart::result
react(const MInfoRec
& infoevt
);
1937 boost::statechart::result
react(const MLogRec
& logevt
);
1938 boost::statechart::result
react(const ActMap
&);
1939 boost::statechart::result
react(const MQuery
&);
1940 boost::statechart::result
react(const Activate
&);
1943 struct RepRecovering
: boost::statechart::state
< RepRecovering
, ReplicaActive
>, NamedState
{
1944 typedef boost::mpl::list
<
1945 boost::statechart::transition
< RecoveryDone
, RepNotRecovering
>,
1946 boost::statechart::transition
< RemoteReservationRejected
, RepNotRecovering
>,
1947 boost::statechart::custom_reaction
< BackfillTooFull
>
1949 explicit RepRecovering(my_context ctx
);
1950 boost::statechart::result
react(const BackfillTooFull
&evt
);
1954 struct RepWaitBackfillReserved
: boost::statechart::state
< RepWaitBackfillReserved
, ReplicaActive
>, NamedState
{
1955 typedef boost::mpl::list
<
1956 boost::statechart::custom_reaction
< RemoteBackfillReserved
>,
1957 boost::statechart::custom_reaction
< RemoteReservationRejected
>
1959 explicit RepWaitBackfillReserved(my_context ctx
);
1961 boost::statechart::result
react(const RemoteBackfillReserved
&evt
);
1962 boost::statechart::result
react(const RemoteReservationRejected
&evt
);
1965 struct RepWaitRecoveryReserved
: boost::statechart::state
< RepWaitRecoveryReserved
, ReplicaActive
>, NamedState
{
1966 typedef boost::mpl::list
<
1967 boost::statechart::custom_reaction
< RemoteRecoveryReserved
>
1969 explicit RepWaitRecoveryReserved(my_context ctx
);
1971 boost::statechart::result
react(const RemoteRecoveryReserved
&evt
);
1974 struct RepNotRecovering
: boost::statechart::state
< RepNotRecovering
, ReplicaActive
>, NamedState
{
1975 typedef boost::mpl::list
<
1976 boost::statechart::custom_reaction
< RequestBackfillPrio
>,
1977 boost::statechart::transition
< RequestRecovery
, RepWaitRecoveryReserved
>,
1978 boost::statechart::transition
< RecoveryDone
, RepNotRecovering
> // for compat with pre-reservation peers
1980 explicit RepNotRecovering(my_context ctx
);
1981 boost::statechart::result
react(const RequestBackfillPrio
&evt
);
1985 struct Recovering
: boost::statechart::state
< Recovering
, Active
>, NamedState
{
1986 typedef boost::mpl::list
<
1987 boost::statechart::custom_reaction
< AllReplicasRecovered
>,
1988 boost::statechart::custom_reaction
< RequestBackfill
>
1990 explicit Recovering(my_context ctx
);
1992 void release_reservations();
1993 boost::statechart::result
react(const AllReplicasRecovered
&evt
);
1994 boost::statechart::result
react(const RequestBackfill
&evt
);
1997 struct WaitRemoteRecoveryReserved
: boost::statechart::state
< WaitRemoteRecoveryReserved
, Active
>, NamedState
{
1998 typedef boost::mpl::list
<
1999 boost::statechart::custom_reaction
< RemoteRecoveryReserved
>,
2000 boost::statechart::transition
< AllRemotesReserved
, Recovering
>
2002 set
<pg_shard_t
>::const_iterator remote_recovery_reservation_it
;
2003 explicit WaitRemoteRecoveryReserved(my_context ctx
);
2004 boost::statechart::result
react(const RemoteRecoveryReserved
&evt
);
2008 struct WaitLocalRecoveryReserved
: boost::statechart::state
< WaitLocalRecoveryReserved
, Active
>, NamedState
{
2009 typedef boost::mpl::list
<
2010 boost::statechart::transition
< LocalRecoveryReserved
, WaitRemoteRecoveryReserved
>,
2011 boost::statechart::custom_reaction
< RecoveryTooFull
>
2013 explicit WaitLocalRecoveryReserved(my_context ctx
);
2015 boost::statechart::result
react(const RecoveryTooFull
&evt
);
2018 struct Activating
: boost::statechart::state
< Activating
, Active
>, NamedState
{
2019 typedef boost::mpl::list
<
2020 boost::statechart::transition
< AllReplicasRecovered
, Recovered
>,
2021 boost::statechart::transition
< DoRecovery
, WaitLocalRecoveryReserved
>,
2022 boost::statechart::transition
< RequestBackfill
, WaitLocalBackfillReserved
>
2024 explicit Activating(my_context ctx
);
2028 struct Stray
: boost::statechart::state
< Stray
, Started
>, NamedState
{
2029 map
<int, pair
<pg_query_t
, epoch_t
> > pending_queries
;
2031 explicit Stray(my_context ctx
);
2034 typedef boost::mpl::list
<
2035 boost::statechart::custom_reaction
< MQuery
>,
2036 boost::statechart::custom_reaction
< MLogRec
>,
2037 boost::statechart::custom_reaction
< MInfoRec
>,
2038 boost::statechart::custom_reaction
< ActMap
>,
2039 boost::statechart::custom_reaction
< RecoveryDone
>
2041 boost::statechart::result
react(const MQuery
& query
);
2042 boost::statechart::result
react(const MLogRec
& logevt
);
2043 boost::statechart::result
react(const MInfoRec
& infoevt
);
2044 boost::statechart::result
react(const ActMap
&);
2045 boost::statechart::result
react(const RecoveryDone
&) {
2046 return discard_event();
2052 struct GetInfo
: boost::statechart::state
< GetInfo
, Peering
>, NamedState
{
2053 set
<pg_shard_t
> peer_info_requested
;
2055 explicit GetInfo(my_context ctx
);
2059 typedef boost::mpl::list
<
2060 boost::statechart::custom_reaction
< QueryState
>,
2061 boost::statechart::transition
< GotInfo
, GetLog
>,
2062 boost::statechart::custom_reaction
< MNotifyRec
>,
2063 boost::statechart::transition
< IsDown
, Down
>
2065 boost::statechart::result
react(const QueryState
& q
);
2066 boost::statechart::result
react(const MNotifyRec
& infoevt
);
2069 struct GotLog
: boost::statechart::event
< GotLog
> {
2070 GotLog() : boost::statechart::event
< GotLog
>() {}
2073 struct GetLog
: boost::statechart::state
< GetLog
, Peering
>, NamedState
{
2074 pg_shard_t auth_log_shard
;
2075 boost::intrusive_ptr
<MOSDPGLog
> msg
;
2077 explicit GetLog(my_context ctx
);
2080 typedef boost::mpl::list
<
2081 boost::statechart::custom_reaction
< QueryState
>,
2082 boost::statechart::custom_reaction
< MLogRec
>,
2083 boost::statechart::custom_reaction
< GotLog
>,
2084 boost::statechart::custom_reaction
< AdvMap
>,
2085 boost::statechart::transition
< IsIncomplete
, Incomplete
>
2087 boost::statechart::result
react(const AdvMap
&);
2088 boost::statechart::result
react(const QueryState
& q
);
2089 boost::statechart::result
react(const MLogRec
& logevt
);
2090 boost::statechart::result
react(const GotLog
&);
2095 struct GetMissing
: boost::statechart::state
< GetMissing
, Peering
>, NamedState
{
2096 set
<pg_shard_t
> peer_missing_requested
;
2098 explicit GetMissing(my_context ctx
);
2101 typedef boost::mpl::list
<
2102 boost::statechart::custom_reaction
< QueryState
>,
2103 boost::statechart::custom_reaction
< MLogRec
>,
2104 boost::statechart::transition
< NeedUpThru
, WaitUpThru
>
2106 boost::statechart::result
react(const QueryState
& q
);
2107 boost::statechart::result
react(const MLogRec
& logevt
);
2110 struct WaitUpThru
: boost::statechart::state
< WaitUpThru
, Peering
>, NamedState
{
2111 explicit WaitUpThru(my_context ctx
);
2114 typedef boost::mpl::list
<
2115 boost::statechart::custom_reaction
< QueryState
>,
2116 boost::statechart::custom_reaction
< ActMap
>,
2117 boost::statechart::custom_reaction
< MLogRec
>
2119 boost::statechart::result
react(const QueryState
& q
);
2120 boost::statechart::result
react(const ActMap
& am
);
2121 boost::statechart::result
react(const MLogRec
& logrec
);
2124 struct Down
: boost::statechart::state
< Down
, Peering
>, NamedState
{
2125 explicit Down(my_context ctx
);
2126 typedef boost::mpl::list
<
2127 boost::statechart::custom_reaction
< QueryState
>
2129 boost::statechart::result
react(const QueryState
& infoevt
);
2133 struct Incomplete
: boost::statechart::state
< Incomplete
, Peering
>, NamedState
{
2134 typedef boost::mpl::list
<
2135 boost::statechart::custom_reaction
< AdvMap
>,
2136 boost::statechart::custom_reaction
< MNotifyRec
>,
2137 boost::statechart::custom_reaction
< QueryState
>
2139 explicit Incomplete(my_context ctx
);
2140 boost::statechart::result
react(const AdvMap
&advmap
);
2141 boost::statechart::result
react(const MNotifyRec
& infoevt
);
2142 boost::statechart::result
react(const QueryState
& infoevt
);
2147 RecoveryMachine machine
;
2150 /// context passed in by state machine caller
2151 RecoveryCtx
*orig_ctx
;
2153 /// populated if we are buffering messages pending a flush
2154 boost::optional
<BufferedRecoveryMessages
> messages_pending_flush
;
2157 * populated between start_handle() and end_handle(), points into
2158 * the message lists for messages_pending_flush while blocking messages
2159 * or into orig_ctx otherwise
2161 boost::optional
<RecoveryCtx
> rctx
;
2164 explicit RecoveryState(PG
*pg
)
2165 : machine(this, pg
), pg(pg
), orig_ctx(0) {
2169 void handle_event(const boost::statechart::event_base
&evt
,
2170 RecoveryCtx
*rctx
) {
2172 machine
.process_event(evt
);
2176 void handle_event(CephPeeringEvtRef evt
,
2177 RecoveryCtx
*rctx
) {
2179 machine
.process_event(evt
->get_event());
2187 PG(OSDService
*o
, OSDMapRef curmap
,
2188 const PGPool
&pool
, spg_t p
);
2193 explicit PG(const PG
& rhs
);
2194 PG
& operator=(const PG
& rhs
);
2196 uint64_t peer_features
;
2197 uint64_t acting_features
;
2198 uint64_t upacting_features
;
2202 Mutex scrub_sleep_lock
;
2203 SafeTimer scrub_sleep_timer
;
2206 const spg_t
& get_pgid() const { return pg_id
; }
2208 void reset_min_peer_features() {
2209 peer_features
= CEPH_FEATURES_SUPPORTED_DEFAULT
;
2211 uint64_t get_min_peer_features() const { return peer_features
; }
2212 void apply_peer_features(uint64_t f
) { peer_features
&= f
; }
2214 uint64_t get_min_acting_features() const { return acting_features
; }
2215 uint64_t get_min_upacting_features() const { return upacting_features
; }
2217 void init_primary_up_acting(
2218 const vector
<int> &newup
,
2219 const vector
<int> &newacting
,
2221 int new_acting_primary
) {
2224 for (uint8_t i
= 0; i
< acting
.size(); ++i
) {
2225 if (acting
[i
] != CRUSH_ITEM_NONE
)
2229 pool
.info
.ec_pool() ? shard_id_t(i
) : shard_id_t::NO_SHARD
));
2233 for (uint8_t i
= 0; i
< up
.size(); ++i
) {
2234 if (up
[i
] != CRUSH_ITEM_NONE
)
2238 pool
.info
.ec_pool() ? shard_id_t(i
) : shard_id_t::NO_SHARD
));
2240 if (!pool
.info
.ec_pool()) {
2241 up_primary
= pg_shard_t(new_up_primary
, shard_id_t::NO_SHARD
);
2242 primary
= pg_shard_t(new_acting_primary
, shard_id_t::NO_SHARD
);
2245 up_primary
= pg_shard_t();
2246 primary
= pg_shard_t();
2247 for (uint8_t i
= 0; i
< up
.size(); ++i
) {
2248 if (up
[i
] == new_up_primary
) {
2249 up_primary
= pg_shard_t(up
[i
], shard_id_t(i
));
2253 for (uint8_t i
= 0; i
< acting
.size(); ++i
) {
2254 if (acting
[i
] == new_acting_primary
) {
2255 primary
= pg_shard_t(acting
[i
], shard_id_t(i
));
2259 assert(up_primary
.osd
== new_up_primary
);
2260 assert(primary
.osd
== new_acting_primary
);
2262 pg_shard_t
get_primary() const { return primary
; }
2264 int get_role() const { return role
; }
2265 void set_role(int r
) { role
= r
; }
2267 bool is_primary() const { return pg_whoami
== primary
; }
2268 bool is_replica() const { return role
> 0; }
2270 epoch_t
get_last_peering_reset() const { return last_peering_reset
; }
2272 //int get_state() const { return state; }
2273 bool state_test(int m
) const { return (state
& m
) != 0; }
2274 void state_set(int m
) { state
|= m
; }
2275 void state_clear(int m
) { state
&= ~m
; }
2277 bool is_complete() const { return info
.last_complete
== info
.last_update
; }
2278 bool should_send_notify() const { return send_notify
; }
2280 int get_state() const { return state
; }
2281 bool is_active() const { return state_test(PG_STATE_ACTIVE
); }
2282 bool is_activating() const { return state_test(PG_STATE_ACTIVATING
); }
2283 bool is_peering() const { return state_test(PG_STATE_PEERING
); }
2284 bool is_down() const { return state_test(PG_STATE_DOWN
); }
2285 bool is_incomplete() const { return state_test(PG_STATE_INCOMPLETE
); }
2286 bool is_clean() const { return state_test(PG_STATE_CLEAN
); }
2287 bool is_degraded() const { return state_test(PG_STATE_DEGRADED
); }
2288 bool is_undersized() const { return state_test(PG_STATE_UNDERSIZED
); }
2290 bool is_scrubbing() const { return state_test(PG_STATE_SCRUBBING
); }
2291 bool is_peered() const {
2292 return state_test(PG_STATE_ACTIVE
) || state_test(PG_STATE_PEERED
);
2295 bool is_empty() const { return info
.last_update
== eversion_t(0,0); }
2299 const vector
<int>& up
,
2301 const vector
<int>& acting
,
2303 const pg_history_t
& history
,
2304 const PastIntervals
& pim
,
2306 ObjectStore::Transaction
*t
);
2309 void do_pending_flush();
2311 static void _create(ObjectStore::Transaction
& t
, spg_t pgid
, int bits
);
2312 static void _init(ObjectStore::Transaction
& t
,
2313 spg_t pgid
, const pg_pool_t
*pool
);
2316 void prepare_write_info(map
<string
,bufferlist
> *km
);
2318 void update_store_with_options();
2319 void update_store_on_load();
2322 static int _prepare_write_info(
2324 map
<string
,bufferlist
> *km
,
2327 pg_info_t
&last_written_info
,
2328 PastIntervals
&past_intervals
,
2329 bool dirty_big_info
,
2332 PerfCounters
*logger
= nullptr);
2333 void write_if_dirty(ObjectStore::Transaction
& t
);
2335 PGLog::IndexedLog projected_log
;
2336 bool check_in_progress_op(
2337 const osd_reqid_t
&r
,
2338 eversion_t
*version
,
2339 version_t
*user_version
,
2340 int *return_code
) const;
2341 eversion_t projected_last_update
;
2342 eversion_t
get_next_version() const {
2343 eversion_t
at_version(
2344 get_osdmap()->get_epoch(),
2345 projected_last_update
.version
+1);
2346 assert(at_version
> info
.last_update
);
2347 assert(at_version
> pg_log
.get_head());
2348 assert(at_version
> projected_last_update
);
2352 void add_log_entry(const pg_log_entry_t
& e
, bool applied
);
2354 const vector
<pg_log_entry_t
>& logv
,
2356 eversion_t roll_forward_to
,
2357 ObjectStore::Transaction
&t
,
2358 bool transaction_applied
= true);
2359 bool check_log_for_corruption(ObjectStore
*store
);
2362 std::string
get_corrupt_pg_log_name() const;
2363 static int read_info(
2364 ObjectStore
*store
, spg_t pgid
, const coll_t
&coll
,
2365 bufferlist
&bl
, pg_info_t
&info
, PastIntervals
&past_intervals
,
2367 void read_state(ObjectStore
*store
, bufferlist
&bl
);
2368 static bool _has_removal_flag(ObjectStore
*store
, spg_t pgid
);
2369 static int peek_map_epoch(ObjectStore
*store
, spg_t pgid
,
2370 epoch_t
*pepoch
, bufferlist
*bl
);
2371 void update_snap_map(
2372 const vector
<pg_log_entry_t
> &log_entries
,
2373 ObjectStore::Transaction
& t
);
2375 void filter_snapc(vector
<snapid_t
> &snaps
);
2377 void log_weirdness();
2379 virtual void kick_snap_trim() = 0;
2380 virtual void snap_trimmer_scrub_complete() = 0;
2381 bool requeue_scrub();
2382 void queue_recovery(bool front
= false);
2384 unsigned get_scrub_priority();
2386 /// share pg info after a pg is active
2387 void share_pg_info();
2390 bool append_log_entries_update_missing(
2391 const mempool::osd::list
<pg_log_entry_t
> &entries
,
2392 ObjectStore::Transaction
&t
);
2395 * Merge entries updating missing as necessary on all
2396 * actingbackfill logs and missings (also missing_loc)
2398 void merge_new_log_entries(
2399 const mempool::osd::list
<pg_log_entry_t
> &entries
,
2400 ObjectStore::Transaction
&t
);
2402 void reset_interval_flush();
2403 void start_peering_interval(
2404 const OSDMapRef lastmap
,
2405 const vector
<int>& newup
, int up_primary
,
2406 const vector
<int>& newacting
, int acting_primary
,
2407 ObjectStore::Transaction
*t
);
2408 void on_new_interval();
2409 virtual void _on_new_interval() = 0;
2410 void start_flush(ObjectStore::Transaction
*t
,
2411 list
<Context
*> *on_applied
,
2412 list
<Context
*> *on_safe
);
2413 void set_last_peering_reset();
2414 bool pg_has_reset_since(epoch_t e
) {
2415 assert(is_locked());
2416 return deleting
|| e
< get_last_peering_reset();
2419 void update_history(const pg_history_t
& history
);
2420 void fulfill_info(pg_shard_t from
, const pg_query_t
&query
,
2421 pair
<pg_shard_t
, pg_info_t
> ¬ify_info
);
2422 void fulfill_log(pg_shard_t from
, const pg_query_t
&query
, epoch_t query_epoch
);
2424 void check_full_transition(OSDMapRef lastmap
, OSDMapRef osdmap
);
2426 bool should_restart_peering(
2428 int newactingprimary
,
2429 const vector
<int>& newup
,
2430 const vector
<int>& newacting
,
2434 // OpRequest queueing
2435 bool can_discard_op(OpRequestRef
& op
);
2436 bool can_discard_scan(OpRequestRef op
);
2437 bool can_discard_backfill(OpRequestRef op
);
2438 bool can_discard_request(OpRequestRef
& op
);
2440 template<typename T
, int MSGTYPE
>
2441 bool can_discard_replica_op(OpRequestRef
& op
);
2443 bool old_peering_msg(epoch_t reply_epoch
, epoch_t query_epoch
);
2444 bool old_peering_evt(CephPeeringEvtRef evt
) {
2445 return old_peering_msg(evt
->get_epoch_sent(), evt
->get_epoch_requested());
2447 static bool have_same_or_newer_map(epoch_t cur_epoch
, epoch_t e
) {
2448 return e
<= cur_epoch
;
2450 bool have_same_or_newer_map(epoch_t e
) {
2451 return e
<= get_osdmap()->get_epoch();
2454 bool op_has_sufficient_caps(OpRequestRef
& op
);
2458 void take_waiters();
2459 void queue_peering_event(CephPeeringEvtRef evt
);
2460 void handle_peering_event(CephPeeringEvtRef evt
, RecoveryCtx
*rctx
);
2461 void queue_query(epoch_t msg_epoch
, epoch_t query_epoch
,
2462 pg_shard_t from
, const pg_query_t
& q
);
2463 void queue_null(epoch_t msg_epoch
, epoch_t query_epoch
);
2464 void queue_flushed(epoch_t started_at
);
2465 void handle_advance_map(
2466 OSDMapRef osdmap
, OSDMapRef lastmap
,
2467 vector
<int>& newup
, int up_primary
,
2468 vector
<int>& newacting
, int acting_primary
,
2470 void handle_activate_map(RecoveryCtx
*rctx
);
2471 void handle_create(RecoveryCtx
*rctx
);
2472 void handle_loaded(RecoveryCtx
*rctx
);
2473 void handle_query_state(Formatter
*f
);
2475 virtual void on_removal(ObjectStore::Transaction
*t
) = 0;
2479 virtual void do_request(
2481 ThreadPool::TPHandle
&handle
2484 virtual void do_op(OpRequestRef
& op
) = 0;
2485 virtual void do_sub_op(OpRequestRef op
) = 0;
2486 virtual void do_sub_op_reply(OpRequestRef op
) = 0;
2487 virtual void do_scan(
2489 ThreadPool::TPHandle
&handle
2491 virtual void do_backfill(OpRequestRef op
) = 0;
2492 virtual void snap_trimmer(epoch_t epoch_queued
) = 0;
2494 virtual int do_command(
2500 ceph_tid_t tid
) = 0;
2502 virtual void on_role_change() = 0;
2503 virtual void on_pool_change() = 0;
2504 virtual void on_change(ObjectStore::Transaction
*t
) = 0;
2505 virtual void on_activate() = 0;
2506 virtual void on_flushed() = 0;
2507 virtual void on_shutdown() = 0;
2508 virtual void check_blacklisted_watchers() = 0;
2509 virtual void get_watchers(std::list
<obj_watch_item_t
>&) = 0;
2511 virtual bool agent_work(int max
) = 0;
2512 virtual bool agent_work(int max
, int agent_flush_quota
) = 0;
2513 virtual void agent_stop() = 0;
2514 virtual void agent_delay() = 0;
2515 virtual void agent_clear() = 0;
2516 virtual void agent_choose_mode_restart() = 0;
2519 ostream
& operator<<(ostream
& out
, const PG
& pg
);
2521 ostream
& operator<<(ostream
& out
, const PG::BackfillInterval
& bi
);