1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/ranges.h>
#include "crimson/common/type_helpers.h"
#include "crimson/osd/backfill_facades.h"
#include "crimson/osd/osd_operations/background_recovery.h"
#include "crimson/osd/osd_operations/peering_event.h"
#include "crimson/osd/pg.h"
#include "crimson/osd/pg_backend.h"
#include "crimson/osd/pg_recovery.h"
#include "osd/osd_types.h"
#include "osd/PeeringState.h"
namespace {
seastar::logger& logger() {
return crimson::get_logger(ceph_subsys_osd);
}
}
using std::map;
using std::set;
using PglogBasedRecovery = crimson::osd::PglogBasedRecovery;
void PGRecovery::start_pglogbased_recovery()
{
auto [op, fut] = pg->get_shard_services().start_operation<PglogBasedRecovery>(
static_cast<crimson::osd::PG*>(pg),
pg->get_shard_services(),
pg->get_osdmap_epoch(),
float(0.001));
pg->set_pglog_based_recovery_op(op.get());
}
PGRecovery::interruptible_future<bool>
PGRecovery::start_recovery_ops(
RecoveryBackend::RecoveryBlockingEvent::TriggerI& trigger,
PglogBasedRecovery &recover_op,
size_t max_to_start)
{
assert(pg->is_primary());
assert(pg->is_peered());
if (pg->has_reset_since(recover_op.get_epoch_started()) ||
recover_op.is_cancelled()) {
logger().debug("recovery {} cancelled.", recover_op);
return seastar::make_ready_future<bool>(false);
}
ceph_assert(pg->is_recovering());
// in ceph-osd the do_recovery() path handles both the pg log-based
// recovery and the backfill, albeit they are separated at the layer
// of PeeringState. In crimson-osd backfill has been cut from it, so
// and do_recovery() is actually solely for pg log-based recovery.
// At the time of writing it's considered to move it to FSM and fix
// the naming as well.
assert(!pg->is_backfilling());
assert(!pg->get_peering_state().is_deleting());
std::vector<interruptible_future<>> started;
started.reserve(max_to_start);
max_to_start -= start_primary_recovery_ops(trigger, max_to_start, &started);
if (max_to_start > 0) {
max_to_start -= start_replica_recovery_ops(trigger, max_to_start, &started);
}
return interruptor::parallel_for_each(started,
[] (auto&& ifut) {
return std::move(ifut);
}).then_interruptible([this, &recover_op] {
//TODO: maybe we should implement a recovery race interruptor in the future
if (pg->has_reset_since(recover_op.get_epoch_started()) ||
recover_op.is_cancelled()) {
logger().debug("recovery {} cancelled.", recover_op);
return seastar::make_ready_future<bool>(false);
}
ceph_assert(pg->is_recovering());
ceph_assert(!pg->is_backfilling());
bool done = !pg->get_peering_state().needs_recovery();
if (done) {
logger().debug("start_recovery_ops: AllReplicasRecovered for pg: {}",
pg->get_pgid());
using LocalPeeringEvent = crimson::osd::LocalPeeringEvent;
if (!pg->get_peering_state().needs_backfill()) {
logger().debug("start_recovery_ops: AllReplicasRecovered for pg: {}",
pg->get_pgid());
(void) pg->get_shard_services().start_operation<LocalPeeringEvent>(
static_cast<crimson::osd::PG*>(pg),
pg->get_pg_whoami(),
pg->get_pgid(),
pg->get_osdmap_epoch(),
pg->get_osdmap_epoch(),
PeeringState::AllReplicasRecovered{});
} else {
logger().debug("start_recovery_ops: RequestBackfill for pg: {}",
pg->get_pgid());
(void) pg->get_shard_services().start_operation<LocalPeeringEvent>(
static_cast<crimson::osd::PG*>(pg),
pg->get_pg_whoami(),
pg->get_pgid(),
pg->get_osdmap_epoch(),
pg->get_osdmap_epoch(),
PeeringState::RequestBackfill{});
}
pg->reset_pglog_based_recovery_op();
}
return seastar::make_ready_future<bool>(!done);
});
}
size_t PGRecovery::start_primary_recovery_ops(
RecoveryBackend::RecoveryBlockingEvent::TriggerI& trigger,
size_t max_to_start,
std::vector<PGRecovery::interruptible_future<>> *out)
{
if (!pg->is_recovering()) {
return 0;
}
if (!pg->get_peering_state().have_missing()) {
pg->get_peering_state().local_recovery_complete();
return 0;
}
const auto &missing = pg->get_peering_state().get_pg_log().get_missing();
logger().info("{} recovering {} in pg {}, missing {}", __func__,
pg->get_recovery_backend()->total_recovering(),
*static_cast<crimson::osd::PG*>(pg),
missing);
unsigned started = 0;
int skipped = 0;
map<version_t, hobject_t>::const_iterator p =
missing.get_rmissing().lower_bound(pg->get_peering_state().get_pg_log().get_log().last_requested);
while (started < max_to_start && p != missing.get_rmissing().end()) {
// TODO: chain futures here to enable yielding to scheduler?
hobject_t soid;
version_t v = p->first;
auto it_objects = pg->get_peering_state().get_pg_log().get_log().objects.find(p->second);
if (it_objects != pg->get_peering_state().get_pg_log().get_log().objects.end()) {
// look at log!
pg_log_entry_t *latest = it_objects->second;
assert(latest->is_update() || latest->is_delete());
soid = latest->soid;
} else {
soid = p->second;
}
hobject_t head = soid.get_head();
if (pg->get_peering_state().get_missing_loc().is_unfound(soid)) {
logger().debug("{}: object {} unfound", __func__, soid);
++skipped;
++p;
continue;
}
if (pg->get_peering_state().get_missing_loc().is_unfound(head)) {
logger().debug("{}: head object {} unfound", __func__, soid);
++skipped;
++p;
continue;
}
const pg_missing_item& item = missing.get_items().find(p->second)->second;
++p;
bool head_missing = missing.is_missing(head);
logger().info(
"{} {} item.need {} {} {} {} {}",
__func__,
soid,
item.need,
missing.is_missing(soid) ? " (missing)":"",
head_missing ? " (missing head)":"",
pg->get_recovery_backend()->is_recovering(soid) ? " (recovering)":"",
pg->get_recovery_backend()->is_recovering(head) ? " (recovering head)":"");
// TODO: handle lost/unfound
if (pg->get_recovery_backend()->is_recovering(soid)) {
auto& recovery_waiter = pg->get_recovery_backend()->get_recovering(soid);
out->emplace_back(recovery_waiter.wait_for_recovered(trigger));
++started;
} else if (pg->get_recovery_backend()->is_recovering(head)) {
++skipped;
} else {
if (head_missing) {
auto it = missing.get_items().find(head);
assert(it != missing.get_items().end());
auto head_need = it->second.need;
out->emplace_back(recover_missing(trigger, head, head_need));
++skipped;
} else {
out->emplace_back(recover_missing(trigger, soid, item.need));
}
++started;
}
if (!skipped)
pg->get_peering_state().set_last_requested(v);
}
logger().info("{} started {} skipped {}", __func__, started, skipped);
return started;
}
size_t PGRecovery::start_replica_recovery_ops(
RecoveryBackend::RecoveryBlockingEvent::TriggerI& trigger,
size_t max_to_start,
std::vector<PGRecovery::interruptible_future<>> *out)
{
if (!pg->is_recovering()) {
return 0;
}
uint64_t started = 0;
assert(!pg->get_peering_state().get_acting_recovery_backfill().empty());
auto recovery_order = get_replica_recovery_order();
for (auto &peer : recovery_order) {
assert(peer != pg->get_peering_state().get_primary());
const auto& pm = pg->get_peering_state().get_peer_missing(peer);
logger().debug("{}: peer osd.{} missing {} objects", __func__,
peer, pm.num_missing());
logger().trace("{}: peer osd.{} missing {}", __func__,
peer, pm.get_items());
// recover oldest first
for (auto p = pm.get_rmissing().begin();
p != pm.get_rmissing().end() && started < max_to_start;
++p) {
const auto &soid = p->second;
if (pg->get_peering_state().get_missing_loc().is_unfound(soid)) {
logger().debug("{}: object {} still unfound", __func__, soid);
continue;
}
const pg_info_t &pi = pg->get_peering_state().get_peer_info(peer);
if (soid > pi.last_backfill) {
if (!pg->get_recovery_backend()->is_recovering(soid)) {
logger().error(
"{}: object {} in missing set for backfill (last_backfill {})"
" but not in recovering",
__func__,
soid,
pi.last_backfill);
ceph_abort();
}
continue;
}
if (pg->get_recovery_backend()->is_recovering(soid)) {
logger().debug("{}: already recovering object {}", __func__, soid);
auto& recovery_waiter = pg->get_recovery_backend()->get_recovering(soid);
out->emplace_back(recovery_waiter.wait_for_recovered(trigger));
started++;
continue;
}
if (pg->get_peering_state().get_missing_loc().is_deleted(soid)) {
logger().debug("{}: soid {} is a delete, removing", __func__, soid);
map<hobject_t,pg_missing_item>::const_iterator r =
pm.get_items().find(soid);
started++;
out->emplace_back(
prep_object_replica_deletes(trigger, soid, r->second.need));
continue;
}
if (soid.is_snap() &&
pg->get_peering_state().get_pg_log().get_missing().is_missing(
soid.get_head())) {
logger().debug("{}: head {} still missing on primary", __func__,
soid.get_head());
continue;
}
if (pg->get_peering_state().get_pg_log().get_missing().is_missing(soid)) {
logger().debug("{}: soid {} still missing on primary", __func__, soid);
continue;
}
logger().debug("{}: recover_object_replicas({})", __func__,soid);
map<hobject_t,pg_missing_item>::const_iterator r = pm.get_items().find(
soid);
started++;
out->emplace_back(
prep_object_replica_pushes(trigger, soid, r->second.need));
}
}
return started;
}
PGRecovery::interruptible_future<>
PGRecovery::recover_missing(
RecoveryBackend::RecoveryBlockingEvent::TriggerI& trigger,
const hobject_t &soid, eversion_t need)
{
logger().info("{} {} v {}", __func__, soid, need);
auto [recovering, added] = pg->get_recovery_backend()->add_recovering(soid);
if (added) {
logger().info("{} {} v {}, new recovery", __func__, soid, need);
if (pg->get_peering_state().get_missing_loc().is_deleted(soid)) {
return recovering.wait_track_blocking(
trigger,
pg->get_recovery_backend()->recover_delete(soid, need));
} else {
return recovering.wait_track_blocking(
trigger,
pg->get_recovery_backend()->recover_object(soid, need)
.handle_exception_interruptible(
[=, this, soid = std::move(soid)] (auto e) {
on_failed_recover({ pg->get_pg_whoami() }, soid, need);
return seastar::make_ready_future<>();
})
);
}
} else {
return recovering.wait_for_recovered();
}
}
RecoveryBackend::interruptible_future<> PGRecovery::prep_object_replica_deletes(
RecoveryBackend::RecoveryBlockingEvent::TriggerI& trigger,
const hobject_t& soid,
eversion_t need)
{
logger().info("{} {} v {}", __func__, soid, need);
auto [recovering, added] = pg->get_recovery_backend()->add_recovering(soid);
if (added) {
logger().info("{} {} v {}, new recovery", __func__, soid, need);
return recovering.wait_track_blocking(
trigger,
pg->get_recovery_backend()->push_delete(soid, need).then_interruptible(
[=, this] {
object_stat_sum_t stat_diff;
stat_diff.num_objects_recovered = 1;
on_global_recover(soid, stat_diff, true);
return seastar::make_ready_future<>();
})
);
} else {
return recovering.wait_for_recovered();
}
}
RecoveryBackend::interruptible_future<> PGRecovery::prep_object_replica_pushes(
RecoveryBackend::RecoveryBlockingEvent::TriggerI& trigger,
const hobject_t& soid,
eversion_t need)
{
logger().info("{} {} v {}", __func__, soid, need);
auto [recovering, added] = pg->get_recovery_backend()->add_recovering(soid);
if (added) {
logger().info("{} {} v {}, new recovery", __func__, soid, need);
return recovering.wait_track_blocking(
trigger,
pg->get_recovery_backend()->recover_object(soid, need)
.handle_exception_interruptible(
[=, this, soid = std::move(soid)] (auto e) {
on_failed_recover({ pg->get_pg_whoami() }, soid, need);
return seastar::make_ready_future<>();
})
);
} else {
return recovering.wait_for_recovered();
}
}
RecoveryBackend::interruptible_future<>
PGRecovery::on_local_recover(
const hobject_t& soid,
const ObjectRecoveryInfo& recovery_info,
const bool is_delete,
ceph::os::Transaction& t)
{
if (const auto &log = pg->get_peering_state().get_pg_log();
!is_delete &&
log.get_missing().is_missing(recovery_info.soid) &&
log.get_missing().get_items().find(recovery_info.soid)->second.need > recovery_info.version) {
assert(pg->is_primary());
if (const auto* latest = log.get_log().objects.find(recovery_info.soid)->second;
latest->op == pg_log_entry_t::LOST_REVERT) {
ceph_abort("mark_unfound_lost (LOST_REVERT) is not implemented yet");
}
}
return RecoveryBackend::interruptor::async(
[soid, &recovery_info, is_delete, &t, this] {
if (soid.is_snap()) {
OSDriver::OSTransaction _t(pg->get_osdriver().get_transaction(&t));
int r = pg->get_snap_mapper().remove_oid(soid, &_t);
assert(r == 0 || r == -ENOENT);
if (!is_delete) {
set<snapid_t> snaps;
auto p = recovery_info.ss.clone_snaps.find(soid.snap);
assert(p != recovery_info.ss.clone_snaps.end());
snaps.insert(p->second.begin(), p->second.end());
pg->get_snap_mapper().add_oid(recovery_info.soid, snaps, &_t);
}
}
pg->get_peering_state().recover_got(soid,
recovery_info.version, is_delete, t);
if (pg->is_primary()) {
if (!is_delete) {
auto& obc = pg->get_recovery_backend()->get_recovering(soid).obc; //TODO: move to pg backend?
obc->obs.exists = true;
obc->obs.oi = recovery_info.oi;
}
if (!pg->is_unreadable_object(soid)) {
pg->get_recovery_backend()->get_recovering(soid).set_readable();
}
pg->publish_stats_to_osd();
}
});
}
void PGRecovery::on_global_recover (
const hobject_t& soid,
const object_stat_sum_t& stat_diff,
const bool is_delete)
{
logger().info("{} {}", __func__, soid);
pg->get_peering_state().object_recovered(soid, stat_diff);
pg->publish_stats_to_osd();
auto& recovery_waiter = pg->get_recovery_backend()->get_recovering(soid);
recovery_waiter.set_recovered();
pg->get_recovery_backend()->remove_recovering(soid);
pg->get_recovery_backend()->found_and_remove(soid);
}
void PGRecovery::on_failed_recover(
const set<pg_shard_t>& from,
const hobject_t& soid,
const eversion_t& v)
{
for (auto pg_shard : from) {
if (pg_shard != pg->get_pg_whoami()) {
pg->get_peering_state().force_object_missing(pg_shard, soid, v);
}
}
}
void PGRecovery::on_peer_recover(
pg_shard_t peer,
const hobject_t &oid,
const ObjectRecoveryInfo &recovery_info)
{
crimson::get_logger(ceph_subsys_osd).debug(
"{}: {}, {} on {}", __func__, oid,
recovery_info.version, peer);
pg->get_peering_state().on_peer_recover(peer, oid, recovery_info.version);
}
void PGRecovery::_committed_pushed_object(epoch_t epoch,
eversion_t last_complete)
{
if (!pg->has_reset_since(epoch)) {
pg->get_peering_state().recovery_committed_to(last_complete);
} else {
crimson::get_logger(ceph_subsys_osd).debug(
"{} pg has changed, not touching last_complete_ondisk",
__func__);
}
}
template <class EventT>
void PGRecovery::start_backfill_recovery(const EventT& evt)
{
using BackfillRecovery = crimson::osd::BackfillRecovery;
std::ignore = pg->get_shard_services().start_operation<BackfillRecovery>(
static_cast<crimson::osd::PG*>(pg),
pg->get_shard_services(),
pg->get_osdmap_epoch(),
evt);
}
void PGRecovery::request_replica_scan(
const pg_shard_t& target,
const hobject_t& begin,
const hobject_t& end)
{
logger().debug("{}: target.osd={}", __func__, target.osd);
auto msg = crimson::make_message<MOSDPGScan>(
MOSDPGScan::OP_SCAN_GET_DIGEST,
pg->get_pg_whoami(),
pg->get_osdmap_epoch(),
pg->get_last_peering_reset(),
spg_t(pg->get_pgid().pgid, target.shard),
begin,
end);
std::ignore = pg->get_shard_services().send_to_osd(
target.osd,
std::move(msg),
pg->get_osdmap_epoch());
}
void PGRecovery::request_primary_scan(
const hobject_t& begin)
{
logger().debug("{}", __func__);
using crimson::common::local_conf;
std::ignore = pg->get_recovery_backend()->scan_for_backfill(
begin,
local_conf()->osd_backfill_scan_min,
local_conf()->osd_backfill_scan_max
).then_interruptible([this] (BackfillInterval bi) {
logger().debug("request_primary_scan:{}", __func__);
using BackfillState = crimson::osd::BackfillState;
start_backfill_recovery(BackfillState::PrimaryScanned{ std::move(bi) });
});
}
void PGRecovery::enqueue_push(
const hobject_t& obj,
const eversion_t& v,
const std::vector<pg_shard_t> &peers)
{
logger().info("{}: obj={} v={} peers={}", __func__, obj, v, peers);
auto &peering_state = pg->get_peering_state();
peering_state.prepare_backfill_for_missing(obj, v, peers);
auto [recovering, added] = pg->get_recovery_backend()->add_recovering(obj);
if (!added)
return;
std::ignore = pg->get_recovery_backend()->recover_object(obj, v).\
handle_exception_interruptible([] (auto) {
ceph_abort_msg("got exception on backfill's push");
return seastar::make_ready_future<>();
}).then_interruptible([this, obj] {
logger().debug("enqueue_push:{}", __func__);
using BackfillState = crimson::osd::BackfillState;
start_backfill_recovery(BackfillState::ObjectPushed(std::move(obj)));
});
}
void PGRecovery::enqueue_drop(
const pg_shard_t& target,
const hobject_t& obj,
const eversion_t& v)
{
// allocate a pair if target is seen for the first time
auto& req = backfill_drop_requests[target];
if (!req) {
req = crimson::make_message<MOSDPGBackfillRemove>(
spg_t(pg->get_pgid().pgid, target.shard), pg->get_osdmap_epoch());
}
req->ls.emplace_back(obj, v);
}
void PGRecovery::maybe_flush()
{
for (auto& [target, req] : backfill_drop_requests) {
std::ignore = pg->get_shard_services().send_to_osd(
target.osd,
std::move(req),
pg->get_osdmap_epoch());
}
backfill_drop_requests.clear();
}
void PGRecovery::update_peers_last_backfill(
const hobject_t& new_last_backfill)
{
logger().debug("{}: new_last_backfill={}",
__func__, new_last_backfill);
// If new_last_backfill == MAX, then we will send OP_BACKFILL_FINISH to
// all the backfill targets. Otherwise, we will move last_backfill up on
// those targets need it and send OP_BACKFILL_PROGRESS to them.
for (const auto& bt : pg->get_peering_state().get_backfill_targets()) {
if (const pg_info_t& pinfo = pg->get_peering_state().get_peer_info(bt);
new_last_backfill > pinfo.last_backfill) {
pg->get_peering_state().update_peer_last_backfill(bt, new_last_backfill);
auto m = crimson::make_message<MOSDPGBackfill>(
pinfo.last_backfill.is_max() ? MOSDPGBackfill::OP_BACKFILL_FINISH
: MOSDPGBackfill::OP_BACKFILL_PROGRESS,
pg->get_osdmap_epoch(),
pg->get_last_peering_reset(),
spg_t(pg->get_pgid().pgid, bt.shard));
// Use default priority here, must match sub_op priority
// TODO: if pinfo.last_backfill.is_max(), then
// start_recovery_op(hobject_t::get_max());
m->last_backfill = pinfo.last_backfill;
m->stats = pinfo.stats;
std::ignore = pg->get_shard_services().send_to_osd(
bt.osd, std::move(m), pg->get_osdmap_epoch());
logger().info("{}: peer {} num_objects now {} / {}",
__func__,
bt,
pinfo.stats.stats.sum.num_objects,
pg->get_info().stats.stats.sum.num_objects);
}
}
}
bool PGRecovery::budget_available() const
{
crimson::osd::scheduler::params_t params =
{1, 0, crimson::osd::scheduler::scheduler_class_t::background_best_effort};
auto &ss = pg->get_shard_services();
auto futopt = ss.try_acquire_throttle_now(std::move(params));
if (!futopt) {
return true;
}
std::ignore = interruptor::make_interruptible(std::move(*futopt)
).then_interruptible([this] {
assert(!backfill_state->is_triggered());
using BackfillState = crimson::osd::BackfillState;
backfill_state->process_event(
BackfillState::ThrottleAcquired{}.intrusive_from_this());
});
return false;
}
void PGRecovery::on_pg_clean()
{
backfill_state.reset();
}
void PGRecovery::backfilled()
{
using LocalPeeringEvent = crimson::osd::LocalPeeringEvent;
std::ignore = pg->get_shard_services().start_operation<LocalPeeringEvent>(
static_cast<crimson::osd::PG*>(pg),
pg->get_pg_whoami(),
pg->get_pgid(),
pg->get_osdmap_epoch(),
pg->get_osdmap_epoch(),
PeeringState::Backfilled{});
}
void PGRecovery::backfill_cancelled()
{
// We are not creating a new BackfillRecovery request here, as we
// need to cancel the backfill synchronously (before this method returns).
using BackfillState = crimson::osd::BackfillState;
backfill_state->process_event(
BackfillState::CancelBackfill{}.intrusive_from_this());
}
void PGRecovery::dispatch_backfill_event(
boost::intrusive_ptr<const boost::statechart::event_base> evt)
{
logger().debug("{}", __func__);
assert(backfill_state);
backfill_state->process_event(evt);
// TODO: Do we need to worry about cases in which the pg has
// been through both backfill cancellations and backfill
// restarts between the sendings and replies of
// ReplicaScan/ObjectPush requests? Seems classic OSDs
// doesn't handle these cases.
}
void PGRecovery::on_activate_complete()
{
logger().debug("{} backfill_state={}",
__func__, fmt::ptr(backfill_state.get()));
backfill_state.reset();
}
void PGRecovery::on_backfill_reserved()
{
logger().debug("{}", __func__);
// yes, it's **not** backfilling yet. The PG_STATE_BACKFILLING
// will be set after on_backfill_reserved() returns.
// Backfill needs to take this into consideration when scheduling
// events -- they must be mutually exclusive with PeeringEvent
// instances. Otherwise the execution might begin without having
// the state updated.
ceph_assert(!pg->get_peering_state().is_backfilling());
// let's be lazy with creating the backfill stuff
using BackfillState = crimson::osd::BackfillState;
if (!backfill_state) {
// PIMP and depedency injection for the sake of unittestability.
// I'm not afraid about the performance here.
backfill_state = std::make_unique<BackfillState>(
*this,
std::make_unique<crimson::osd::PeeringFacade>(pg->get_peering_state()),
std::make_unique<crimson::osd::PGFacade>(
*static_cast<crimson::osd::PG*>(pg)));
}
// it may be we either start a completely new backfill (first
// event since last on_activate_complete()) or to resume already
// (but stopped one).
start_backfill_recovery(BackfillState::Triggered{});
}
|