Skip to content

Commit 44c4a17

Browse files
authored
Merge pull request ceph#59118 from xxhdx1985126/wip-crimson-backfill-cancellation
crimson/osd/backfill_state: support backfill cancellation Reviewed-by: Matan Breizman <[email protected]>
2 parents 9d65f7f + db433a6 commit 44c4a17

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

src/crimson/osd/backfill_state.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,14 @@ BackfillState::Crashed::Crashed()
498498
ceph_abort_msg("{}: this should not happen");
499499
}
500500

501+
// -- Cancelled
502+
BackfillState::Cancelled::Cancelled()
503+
{
504+
backfill_state().backfill_info.clear();
505+
backfill_state().peer_backfill_info.clear();
506+
backfill_state().progress_tracker.reset();
507+
}
508+
501509
// ProgressTracker is an intermediary between the BackfillListener and
502510
// BackfillMachine + its states. All requests to push or drop an object
503511
// are directed through it. The same happens with notifications about

src/crimson/osd/backfill_state.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ struct BackfillState {
5858
struct RequestDone : sc::event<RequestDone> {
5959
};
6060

61+
struct CancelBackfill : sc::event<CancelBackfill> {
62+
};
63+
6164
private:
6265
// internal events
6366
struct RequestPrimaryScanning : sc::event<RequestPrimaryScanning> {
@@ -132,10 +135,16 @@ struct BackfillState {
132135
explicit Crashed();
133136
};
134137

138+
struct Cancelled : sc::simple_state<Cancelled, BackfillMachine>,
139+
StateHelper<Cancelled> {
140+
explicit Cancelled();
141+
};
142+
135143
struct Initial : sc::state<Initial, BackfillMachine>,
136144
StateHelper<Initial> {
137145
using reactions = boost::mpl::list<
138146
sc::custom_reaction<Triggered>,
147+
sc::transition<CancelBackfill, Cancelled>,
139148
sc::transition<sc::event_base, Crashed>>;
140149
explicit Initial(my_context);
141150
// initialize after triggering backfill by on_activate_complete().
@@ -146,6 +155,7 @@ struct BackfillState {
146155
struct Enqueuing : sc::state<Enqueuing, BackfillMachine>,
147156
StateHelper<Enqueuing> {
148157
using reactions = boost::mpl::list<
158+
sc::transition<CancelBackfill, Cancelled>,
149159
sc::transition<RequestPrimaryScanning, PrimaryScanning>,
150160
sc::transition<RequestReplicasScanning, ReplicasScanning>,
151161
sc::transition<RequestWaiting, Waiting>,
@@ -206,6 +216,7 @@ struct BackfillState {
206216
sc::custom_reaction<ObjectPushed>,
207217
sc::custom_reaction<PrimaryScanned>,
208218
sc::transition<RequestDone, Done>,
219+
sc::transition<CancelBackfill, Cancelled>,
209220
sc::transition<sc::event_base, Crashed>>;
210221
explicit PrimaryScanning(my_context);
211222
sc::result react(ObjectPushed);
@@ -219,6 +230,7 @@ struct BackfillState {
219230
sc::custom_reaction<ObjectPushed>,
220231
sc::custom_reaction<ReplicaScanned>,
221232
sc::transition<RequestDone, Done>,
233+
sc::transition<CancelBackfill, Cancelled>,
222234
sc::transition<sc::event_base, Crashed>>;
223235
explicit ReplicasScanning(my_context);
224236
// collect scanning result; if all results are collected, transition
@@ -243,6 +255,7 @@ struct BackfillState {
243255
using reactions = boost::mpl::list<
244256
sc::custom_reaction<ObjectPushed>,
245257
sc::transition<RequestDone, Done>,
258+
sc::transition<CancelBackfill, Cancelled>,
246259
sc::transition<sc::event_base, Crashed>>;
247260
explicit Waiting(my_context);
248261
sc::result react(ObjectPushed);

src/crimson/osd/pg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ class PG : public boost::intrusive_ref_counter<
417417
recovery_handler->on_backfill_reserved();
418418
}
419419
void on_backfill_canceled() final {
420-
ceph_assert(0 == "Not implemented");
420+
recovery_handler->backfill_cancelled();
421421
}
422422

423423
void on_recovery_reserved() final {

src/crimson/osd/pg_recovery.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ bool PGRecovery::budget_available() const
605605

606606
void PGRecovery::backfilled()
607607
{
608+
backfill_state.reset();
608609
using LocalPeeringEvent = crimson::osd::LocalPeeringEvent;
609610
std::ignore = pg->get_shard_services().start_operation<LocalPeeringEvent>(
610611
static_cast<crimson::osd::PG*>(pg),
@@ -615,11 +616,30 @@ void PGRecovery::backfilled()
615616
PeeringState::Backfilled{});
616617
}
617618

619+
void PGRecovery::backfill_cancelled()
620+
{
621+
// We are not creating a new BackfillRecovery request here, as we
622+
// need to cancel the backfill synchronously (before this method returns).
623+
using BackfillState = crimson::osd::BackfillState;
624+
backfill_state->process_event(
625+
BackfillState::CancelBackfill{}.intrusive_from_this());
626+
backfill_state.reset();
627+
}
628+
618629
void PGRecovery::dispatch_backfill_event(
619630
boost::intrusive_ptr<const boost::statechart::event_base> evt)
620631
{
621632
logger().debug("{}", __func__);
622-
backfill_state->process_event(evt);
633+
if (backfill_state) {
634+
backfill_state->process_event(evt);
635+
} else {
636+
// TODO: Do we need to worry about cases in which the pg has
637+
// been through both backfill cancellations and backfill
638+
// restarts between the sendings and replies of
639+
// ReplicaScan/ObjectPush requests? Seems classic OSDs
640+
// doesn't handle these cases.
641+
logger().debug("{}, backfill cancelled, dropping evt");
642+
}
623643
}
624644

625645
void PGRecovery::on_backfill_reserved()

src/crimson/osd/pg_recovery.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class PGRecovery : public crimson::osd::BackfillState::BackfillListener {
9797
template <class EventT>
9898
void start_backfill_recovery(
9999
const EventT& evt);
100+
void backfill_cancelled();
100101
void request_replica_scan(
101102
const pg_shard_t& target,
102103
const hobject_t& begin,

0 commit comments

Comments
 (0)