/
PeeringState.cc
7505 lines (6641 loc) · 229 KB
/
PeeringState.cc
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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "PGPeeringEvent.h"
#include "common/ceph_releases.h"
#include "common/dout.h"
#include "PeeringState.h"
#include "messages/MOSDPGRemove.h"
#include "messages/MBackfillReserve.h"
#include "messages/MRecoveryReserve.h"
#include "messages/MOSDScrubReserve.h"
#include "messages/MOSDPGInfo2.h"
#include "messages/MOSDPGTrim.h"
#include "messages/MOSDPGLog.h"
#include "messages/MOSDPGNotify2.h"
#include "messages/MOSDPGQuery2.h"
#include "messages/MOSDPGLease.h"
#include "messages/MOSDPGLeaseAck.h"
#define dout_context cct
#define dout_subsys ceph_subsys_osd
using std::dec;
using std::hex;
using std::make_pair;
using std::map;
using std::ostream;
using std::pair;
using std::set;
using std::stringstream;
using std::vector;
using ceph::Formatter;
using ceph::make_message;
BufferedRecoveryMessages::BufferedRecoveryMessages(PeeringCtx &ctx)
// steal messages from ctx
: message_map{std::move(ctx.message_map)}
{}
void BufferedRecoveryMessages::send_notify(int to, const pg_notify_t &n)
{
spg_t pgid(n.info.pgid.pgid, n.to);
send_osd_message(to, make_message<MOSDPGNotify2>(pgid, n));
}
void BufferedRecoveryMessages::send_query(
int to,
spg_t to_spgid,
const pg_query_t &q)
{
send_osd_message(to, make_message<MOSDPGQuery2>(to_spgid, q));
}
void BufferedRecoveryMessages::send_info(
int to,
spg_t to_spgid,
epoch_t min_epoch,
epoch_t cur_epoch,
const pg_info_t &info,
std::optional<pg_lease_t> lease,
std::optional<pg_lease_ack_t> lease_ack)
{
send_osd_message(
to,
make_message<MOSDPGInfo2>(
to_spgid,
info,
cur_epoch,
min_epoch,
lease,
lease_ack)
);
}
void PGPool::update(OSDMapRef map)
{
const pg_pool_t *pi = map->get_pg_pool(id);
if (!pi) {
return; // pool has been deleted
}
info = *pi;
name = map->get_pool_name(id);
bool updated = false;
if ((map->get_epoch() != cached_epoch + 1) ||
(pi->get_snap_epoch() == map->get_epoch())) {
updated = true;
}
if (info.is_pool_snaps_mode() && updated) {
snapc = pi->get_snap_context();
}
cached_epoch = map->get_epoch();
}
/*-------------Peering State Helpers----------------*/
#undef dout_prefix
#define dout_prefix (dpp->gen_prefix(*_dout))
#undef psdout
#define psdout(x) ldout(cct, x)
PeeringState::PeeringState(
CephContext *cct,
pg_shard_t pg_whoami,
spg_t spgid,
const PGPool &_pool,
OSDMapRef curmap,
DoutPrefixProvider *dpp,
PeeringListener *pl)
: state_history(*pl),
cct(cct),
spgid(spgid),
dpp(dpp),
pl(pl),
orig_ctx(0),
osdmap_ref(curmap),
pool(_pool),
pg_whoami(pg_whoami),
info(spgid),
pg_log(cct),
last_require_osd_release(curmap->require_osd_release),
missing_loc(spgid, this, dpp, cct),
machine(this, cct, spgid, dpp, pl, &state_history)
{
machine.initiate();
}
void PeeringState::start_handle(PeeringCtx *new_ctx) {
ceph_assert(!rctx);
ceph_assert(!orig_ctx);
orig_ctx = new_ctx;
if (new_ctx) {
if (messages_pending_flush) {
rctx.emplace(*messages_pending_flush, *new_ctx);
} else {
rctx.emplace(*new_ctx);
}
rctx->start_time = ceph_clock_now();
}
}
void PeeringState::begin_block_outgoing() {
ceph_assert(!messages_pending_flush);
ceph_assert(orig_ctx);
ceph_assert(rctx);
messages_pending_flush.emplace();
rctx.emplace(*messages_pending_flush, *orig_ctx);
}
void PeeringState::clear_blocked_outgoing() {
ceph_assert(orig_ctx);
ceph_assert(rctx);
messages_pending_flush = std::optional<BufferedRecoveryMessages>();
}
void PeeringState::end_block_outgoing() {
ceph_assert(messages_pending_flush);
ceph_assert(orig_ctx);
ceph_assert(rctx);
orig_ctx->accept_buffered_messages(*messages_pending_flush);
rctx.emplace(*orig_ctx);
messages_pending_flush = std::optional<BufferedRecoveryMessages>();
}
void PeeringState::end_handle() {
if (rctx) {
utime_t dur = ceph_clock_now() - rctx->start_time;
machine.event_time += dur;
}
machine.event_count++;
rctx = std::nullopt;
orig_ctx = NULL;
}
void PeeringState::check_recovery_sources(const OSDMapRef& osdmap)
{
/*
* check that any peers we are planning to (or currently) pulling
* objects from are dealt with.
*/
missing_loc.check_recovery_sources(osdmap);
pl->check_recovery_sources(osdmap);
for (auto i = peer_log_requested.begin(); i != peer_log_requested.end();) {
if (!osdmap->is_up(i->osd)) {
psdout(10) << "peer_log_requested removing " << *i << dendl;
peer_log_requested.erase(i++);
} else {
++i;
}
}
for (auto i = peer_missing_requested.begin();
i != peer_missing_requested.end();) {
if (!osdmap->is_up(i->osd)) {
psdout(10) << "peer_missing_requested removing " << *i << dendl;
peer_missing_requested.erase(i++);
} else {
++i;
}
}
}
void PeeringState::update_history(const pg_history_t& new_history)
{
auto mnow = pl->get_mnow();
info.history.refresh_prior_readable_until_ub(mnow, prior_readable_until_ub);
if (info.history.merge(new_history)) {
psdout(20) << __func__ << " advanced history from " << new_history << dendl;
dirty_info = true;
if (info.history.last_epoch_clean >= info.history.same_interval_since) {
psdout(20) << __func__ << " clearing past_intervals" << dendl;
past_intervals.clear();
dirty_big_info = true;
}
prior_readable_until_ub = info.history.get_prior_readable_until_ub(mnow);
if (prior_readable_until_ub != ceph::signedspan::zero()) {
dout(20) << __func__
<< " prior_readable_until_ub " << prior_readable_until_ub
<< " (mnow " << mnow << " + "
<< info.history.prior_readable_until_ub << ")" << dendl;
}
}
pl->on_info_history_change();
}
hobject_t PeeringState::earliest_backfill() const
{
hobject_t e = hobject_t::get_max();
for (const pg_shard_t& bt : get_backfill_targets()) {
const pg_info_t &pi = get_peer_info(bt);
e = std::min(pi.last_backfill, e);
}
return e;
}
void PeeringState::purge_strays()
{
if (is_premerge()) {
psdout(10) << "purge_strays " << stray_set << " but premerge, doing nothing"
<< dendl;
return;
}
if (cct->_conf.get_val<bool>("osd_debug_no_purge_strays")) {
return;
}
psdout(10) << "purge_strays " << stray_set << dendl;
bool removed = false;
for (auto p = stray_set.begin(); p != stray_set.end(); ++p) {
ceph_assert(!is_acting_recovery_backfill(*p));
if (get_osdmap()->is_up(p->osd)) {
psdout(10) << "sending PGRemove to osd." << *p << dendl;
vector<spg_t> to_remove;
to_remove.push_back(spg_t(info.pgid.pgid, p->shard));
auto m = make_message<MOSDPGRemove>(
get_osdmap_epoch(),
to_remove);
pl->send_cluster_message(p->osd, m, get_osdmap_epoch());
} else {
psdout(10) << "not sending PGRemove to down osd." << *p << dendl;
}
peer_missing.erase(*p);
peer_info.erase(*p);
missing_loc.remove_stray_recovery_sources(*p);
peer_purged.insert(*p);
removed = true;
}
// if we removed anyone, update peers (which include peer_info)
if (removed)
update_heartbeat_peers();
stray_set.clear();
// clear _requested maps; we may have to peer() again if we discover
// (more) stray content
peer_log_requested.clear();
peer_missing_requested.clear();
}
void PeeringState::query_unfound(Formatter *f, string state)
{
psdout(20) << "Enter PeeringState common QueryUnfound" << dendl;
{
f->dump_string("state", state);
f->dump_bool("available_might_have_unfound", true);
f->open_array_section("might_have_unfound");
for (auto p = might_have_unfound.begin();
p != might_have_unfound.end();
++p) {
if (peer_missing.count(*p)) {
; // Ignore already probed OSDs
} else {
f->open_object_section("osd");
f->dump_stream("osd") << *p;
if (peer_missing_requested.count(*p)) {
f->dump_string("status", "querying");
} else if (!get_osdmap()->is_up(p->osd)) {
f->dump_string("status", "osd is down");
} else {
f->dump_string("status", "not queried");
}
f->close_section();
}
}
f->close_section();
}
psdout(20) << "Exit PeeringState common QueryUnfound" << dendl;
return;
}
bool PeeringState::proc_replica_info(
pg_shard_t from, const pg_info_t &oinfo, epoch_t send_epoch)
{
auto p = peer_info.find(from);
if (p != peer_info.end() && p->second.last_update == oinfo.last_update) {
psdout(10) << " got dup osd." << from << " info "
<< oinfo << ", identical to ours" << dendl;
return false;
}
if (!get_osdmap()->has_been_up_since(from.osd, send_epoch)) {
psdout(10) << " got info " << oinfo << " from down osd." << from
<< " discarding" << dendl;
return false;
}
psdout(10) << " got osd." << from << " " << oinfo << dendl;
ceph_assert(is_primary());
peer_info[from] = oinfo;
might_have_unfound.insert(from);
update_history(oinfo.history);
// stray?
if (!is_up(from) && !is_acting(from)) {
psdout(10) << " osd." << from << " has stray content: " << oinfo << dendl;
stray_set.insert(from);
if (is_clean()) {
purge_strays();
}
}
// was this a new info? if so, update peers!
if (p == peer_info.end())
update_heartbeat_peers();
return true;
}
void PeeringState::remove_down_peer_info(const OSDMapRef &osdmap)
{
// Remove any downed osds from peer_info
bool removed = false;
auto p = peer_info.begin();
while (p != peer_info.end()) {
if (!osdmap->is_up(p->first.osd)) {
psdout(10) << " dropping down osd." << p->first << " info " << p->second << dendl;
peer_missing.erase(p->first);
peer_log_requested.erase(p->first);
peer_missing_requested.erase(p->first);
peer_purged.erase(p->first);
peer_info.erase(p++);
removed = true;
} else
++p;
}
// if we removed anyone, update peers (which include peer_info)
if (removed)
update_heartbeat_peers();
check_recovery_sources(osdmap);
}
void PeeringState::update_heartbeat_peers()
{
if (!is_primary())
return;
set<int> new_peers;
for (unsigned i=0; i<acting.size(); i++) {
if (acting[i] != CRUSH_ITEM_NONE)
new_peers.insert(acting[i]);
}
for (unsigned i=0; i<up.size(); i++) {
if (up[i] != CRUSH_ITEM_NONE)
new_peers.insert(up[i]);
}
for (auto p = peer_info.begin(); p != peer_info.end(); ++p) {
new_peers.insert(p->first.osd);
}
pl->update_heartbeat_peers(std::move(new_peers));
}
void PeeringState::write_if_dirty(ObjectStore::Transaction& t)
{
pl->prepare_write(
info,
last_written_info,
past_intervals,
pg_log,
dirty_info,
dirty_big_info,
last_persisted_osdmap < get_osdmap_epoch(),
t);
if (dirty_info || dirty_big_info) {
last_persisted_osdmap = get_osdmap_epoch();
last_written_info = info;
dirty_info = false;
dirty_big_info = false;
}
}
void PeeringState::advance_map(
OSDMapRef osdmap, OSDMapRef lastmap,
vector<int>& newup, int up_primary,
vector<int>& newacting, int acting_primary,
PeeringCtx &rctx)
{
ceph_assert(lastmap == osdmap_ref);
psdout(10) << "handle_advance_map "
<< newup << "/" << newacting
<< " -- " << up_primary << "/" << acting_primary
<< dendl;
update_osdmap_ref(osdmap);
pool.update(osdmap);
AdvMap evt(
osdmap, lastmap, newup, up_primary,
newacting, acting_primary);
handle_event(evt, &rctx);
if (pool.info.last_change == osdmap_ref->get_epoch()) {
pl->on_pool_change();
}
readable_interval = pool.get_readable_interval(cct->_conf);
last_require_osd_release = osdmap->require_osd_release;
}
void PeeringState::activate_map(PeeringCtx &rctx)
{
psdout(10) << __func__ << dendl;
ActMap evt;
handle_event(evt, &rctx);
if (osdmap_ref->get_epoch() - last_persisted_osdmap >
cct->_conf->osd_pg_epoch_persisted_max_stale) {
psdout(20) << __func__ << ": Dirtying info: last_persisted is "
<< last_persisted_osdmap
<< " while current is " << osdmap_ref->get_epoch() << dendl;
dirty_info = true;
} else {
psdout(20) << __func__ << ": Not dirtying info: last_persisted is "
<< last_persisted_osdmap
<< " while current is " << osdmap_ref->get_epoch() << dendl;
}
write_if_dirty(rctx.transaction);
if (get_osdmap()->check_new_blocklist_entries()) {
pl->check_blocklisted_watchers();
}
}
void PeeringState::set_last_peering_reset()
{
psdout(20) << "set_last_peering_reset " << get_osdmap_epoch() << dendl;
if (last_peering_reset != get_osdmap_epoch()) {
last_peering_reset = get_osdmap_epoch();
psdout(10) << "Clearing blocked outgoing recovery messages" << dendl;
clear_blocked_outgoing();
if (!pl->try_flush_or_schedule_async()) {
psdout(10) << "Beginning to block outgoing recovery messages" << dendl;
begin_block_outgoing();
} else {
psdout(10) << "Not blocking outgoing recovery messages" << dendl;
}
}
}
void PeeringState::complete_flush()
{
flushes_in_progress--;
if (flushes_in_progress == 0) {
pl->on_flushed();
}
}
void PeeringState::check_full_transition(OSDMapRef lastmap, OSDMapRef osdmap)
{
const pg_pool_t *pi = osdmap->get_pg_pool(info.pgid.pool());
if (!pi) {
return; // pool deleted
}
bool changed = false;
if (pi->has_flag(pg_pool_t::FLAG_FULL)) {
const pg_pool_t *opi = lastmap->get_pg_pool(info.pgid.pool());
if (!opi || !opi->has_flag(pg_pool_t::FLAG_FULL)) {
psdout(10) << " pool was marked full in " << osdmap->get_epoch() << dendl;
changed = true;
}
}
if (changed) {
info.history.last_epoch_marked_full = osdmap->get_epoch();
dirty_info = true;
}
}
bool PeeringState::should_restart_peering(
int newupprimary,
int newactingprimary,
const vector<int>& newup,
const vector<int>& newacting,
OSDMapRef lastmap,
OSDMapRef osdmap)
{
if (PastIntervals::is_new_interval(
primary.osd,
newactingprimary,
acting,
newacting,
up_primary.osd,
newupprimary,
up,
newup,
osdmap.get(),
lastmap.get(),
info.pgid.pgid)) {
psdout(20) << "new interval newup " << newup
<< " newacting " << newacting << dendl;
return true;
}
if (!lastmap->is_up(pg_whoami.osd) && osdmap->is_up(pg_whoami.osd)) {
psdout(10) << __func__ << " osd transitioned from down -> up"
<< dendl;
return true;
}
return false;
}
/* Called before initializing peering during advance_map */
void PeeringState::start_peering_interval(
const OSDMapRef lastmap,
const vector<int>& newup, int new_up_primary,
const vector<int>& newacting, int new_acting_primary,
ObjectStore::Transaction &t)
{
const OSDMapRef osdmap = get_osdmap();
set_last_peering_reset();
vector<int> oldacting, oldup;
int oldrole = get_role();
if (is_primary()) {
pl->clear_ready_to_merge();
}
pg_shard_t old_acting_primary = get_primary();
pg_shard_t old_up_primary = up_primary;
bool was_old_primary = is_primary();
bool was_old_nonprimary = is_nonprimary();
acting.swap(oldacting);
up.swap(oldup);
init_primary_up_acting(
newup,
newacting,
new_up_primary,
new_acting_primary);
if (info.stats.up != up ||
info.stats.acting != acting ||
info.stats.up_primary != new_up_primary ||
info.stats.acting_primary != new_acting_primary) {
info.stats.up = up;
info.stats.up_primary = new_up_primary;
info.stats.acting = acting;
info.stats.acting_primary = new_acting_primary;
info.stats.mapping_epoch = osdmap->get_epoch();
}
pl->clear_publish_stats();
// This will now be remapped during a backfill in cases
// that it would not have been before.
if (up != acting)
state_set(PG_STATE_REMAPPED);
else
state_clear(PG_STATE_REMAPPED);
int role = osdmap->calc_pg_role(pg_whoami, acting);
set_role(role);
// did acting, up, primary|acker change?
if (!lastmap) {
psdout(10) << " no lastmap" << dendl;
dirty_info = true;
dirty_big_info = true;
info.history.same_interval_since = osdmap->get_epoch();
} else {
std::stringstream debug;
ceph_assert(info.history.same_interval_since != 0);
bool new_interval = PastIntervals::check_new_interval(
old_acting_primary.osd,
new_acting_primary,
oldacting, newacting,
old_up_primary.osd,
new_up_primary,
oldup, newup,
info.history.same_interval_since,
info.history.last_epoch_clean,
osdmap.get(),
lastmap.get(),
info.pgid.pgid,
missing_loc.get_recoverable_predicate(),
&past_intervals,
&debug);
psdout(10) << __func__ << ": check_new_interval output: "
<< debug.str() << dendl;
if (new_interval) {
if (osdmap->get_epoch() == pl->oldest_stored_osdmap() &&
info.history.last_epoch_clean < osdmap->get_epoch()) {
psdout(10) << " map gap, clearing past_intervals and faking" << dendl;
// our information is incomplete and useless; someone else was clean
// after everything we know if osdmaps were trimmed.
past_intervals.clear();
} else {
psdout(10) << " noting past " << past_intervals << dendl;
}
dirty_info = true;
dirty_big_info = true;
info.history.same_interval_since = osdmap->get_epoch();
if (osdmap->have_pg_pool(info.pgid.pgid.pool()) &&
info.pgid.pgid.is_split(lastmap->get_pg_num(info.pgid.pgid.pool()),
osdmap->get_pg_num(info.pgid.pgid.pool()),
nullptr)) {
info.history.last_epoch_split = osdmap->get_epoch();
}
}
}
if (old_up_primary != up_primary ||
oldup != up) {
info.history.same_up_since = osdmap->get_epoch();
}
// this comparison includes primary rank via pg_shard_t
if (old_acting_primary != get_primary()) {
info.history.same_primary_since = osdmap->get_epoch();
}
on_new_interval();
pl->on_info_history_change();
psdout(1) << __func__ << " up " << oldup << " -> " << up
<< ", acting " << oldacting << " -> " << acting
<< ", acting_primary " << old_acting_primary << " -> "
<< new_acting_primary
<< ", up_primary " << old_up_primary << " -> " << new_up_primary
<< ", role " << oldrole << " -> " << role
<< ", features acting " << acting_features
<< " upacting " << upacting_features
<< dendl;
// deactivate.
state_clear(PG_STATE_ACTIVE);
state_clear(PG_STATE_PEERED);
state_clear(PG_STATE_PREMERGE);
state_clear(PG_STATE_DOWN);
state_clear(PG_STATE_RECOVERY_WAIT);
state_clear(PG_STATE_RECOVERY_TOOFULL);
state_clear(PG_STATE_RECOVERING);
peer_purged.clear();
acting_recovery_backfill.clear();
// reset primary/replica state?
if (was_old_primary || is_primary()) {
pl->clear_want_pg_temp();
} else if (was_old_nonprimary || is_nonprimary()) {
pl->clear_want_pg_temp();
}
clear_primary_state();
pl->on_change(t);
ceph_assert(!deleting);
// should we tell the primary we are here?
send_notify = !is_primary();
if (role != oldrole ||
was_old_primary != is_primary()) {
// did primary change?
if (was_old_primary != is_primary()) {
state_clear(PG_STATE_CLEAN);
}
pl->on_role_change();
} else {
// no role change.
// did primary change?
if (get_primary() != old_acting_primary) {
psdout(10) << oldacting << " -> " << acting
<< ", acting primary "
<< old_acting_primary << " -> " << get_primary()
<< dendl;
} else {
// primary is the same.
if (is_primary()) {
// i am (still) primary. but my replica set changed.
state_clear(PG_STATE_CLEAN);
psdout(10) << oldacting << " -> " << acting
<< ", replicas changed" << dendl;
}
}
}
if (acting.empty() && !up.empty() && up_primary == pg_whoami) {
psdout(10) << " acting empty, but i am up[0], clearing pg_temp" << dendl;
pl->queue_want_pg_temp(acting);
}
}
void PeeringState::on_new_interval()
{
dout(20) << __func__ << dendl;
const OSDMapRef osdmap = get_osdmap();
// initialize features
acting_features = CEPH_FEATURES_SUPPORTED_DEFAULT;
upacting_features = CEPH_FEATURES_SUPPORTED_DEFAULT;
for (auto p = acting.begin(); p != acting.end(); ++p) {
if (*p == CRUSH_ITEM_NONE)
continue;
uint64_t f = osdmap->get_xinfo(*p).features;
acting_features &= f;
upacting_features &= f;
}
for (auto p = up.begin(); p != up.end(); ++p) {
if (*p == CRUSH_ITEM_NONE)
continue;
upacting_features &= osdmap->get_xinfo(*p).features;
}
psdout(20) << __func__ << " upacting_features 0x" << std::hex
<< upacting_features << std::dec
<< " from " << acting << "+" << up << dendl;
psdout(20) << __func__ << " checking missing set deletes flag. missing = "
<< get_pg_log().get_missing() << dendl;
if (!pg_log.get_missing().may_include_deletes &&
!perform_deletes_during_peering()) {
pl->rebuild_missing_set_with_deletes(pg_log);
}
ceph_assert(
pg_log.get_missing().may_include_deletes ==
!perform_deletes_during_peering());
init_hb_stamps();
// update lease bounds for a new interval
auto mnow = pl->get_mnow();
prior_readable_until_ub = std::max(prior_readable_until_ub,
readable_until_ub);
prior_readable_until_ub = info.history.refresh_prior_readable_until_ub(
mnow, prior_readable_until_ub);
psdout(10) << __func__ << " prior_readable_until_ub "
<< prior_readable_until_ub << " (mnow " << mnow << " + "
<< info.history.prior_readable_until_ub << ")" << dendl;
prior_readable_down_osds.clear(); // we populate this when we build the priorset
readable_until =
readable_until_ub =
readable_until_ub_sent =
readable_until_ub_from_primary = ceph::signedspan::zero();
acting_readable_until_ub.clear();
if (is_primary()) {
acting_readable_until_ub.resize(acting.size(), ceph::signedspan::zero());
}
pl->on_new_interval();
}
void PeeringState::init_primary_up_acting(
const vector<int> &newup,
const vector<int> &newacting,
int new_up_primary,
int new_acting_primary)
{
actingset.clear();
acting = newacting;
for (uint8_t i = 0; i < acting.size(); ++i) {
if (acting[i] != CRUSH_ITEM_NONE)
actingset.insert(
pg_shard_t(
acting[i],
pool.info.is_erasure() ? shard_id_t(i) : shard_id_t::NO_SHARD));
}
upset.clear();
up = newup;
for (uint8_t i = 0; i < up.size(); ++i) {
if (up[i] != CRUSH_ITEM_NONE)
upset.insert(
pg_shard_t(
up[i],
pool.info.is_erasure() ? shard_id_t(i) : shard_id_t::NO_SHARD));
}
if (!pool.info.is_erasure()) {
// replicated
up_primary = pg_shard_t(new_up_primary, shard_id_t::NO_SHARD);
primary = pg_shard_t(new_acting_primary, shard_id_t::NO_SHARD);
} else {
// erasure
up_primary = pg_shard_t();
primary = pg_shard_t();
for (uint8_t i = 0; i < up.size(); ++i) {
if (up[i] == new_up_primary) {
up_primary = pg_shard_t(up[i], shard_id_t(i));
break;
}
}
for (uint8_t i = 0; i < acting.size(); ++i) {
if (acting[i] == new_acting_primary) {
primary = pg_shard_t(acting[i], shard_id_t(i));
break;
}
}
ceph_assert(up_primary.osd == new_up_primary);
ceph_assert(primary.osd == new_acting_primary);
}
}
void PeeringState::init_hb_stamps()
{
if (is_primary()) {
// we care about all other osds in the acting set
hb_stamps.resize(acting.size() - 1);
unsigned i = 0;
for (auto p : acting) {
if (p == CRUSH_ITEM_NONE || p == get_primary().osd) {
continue;
}
hb_stamps[i++] = pl->get_hb_stamps(p);
}
hb_stamps.resize(i);
} else if (is_nonprimary()) {
// we care about just the primary
hb_stamps.resize(1);
hb_stamps[0] = pl->get_hb_stamps(get_primary().osd);
} else {
hb_stamps.clear();
}
dout(10) << __func__ << " now " << hb_stamps << dendl;
}
void PeeringState::clear_recovery_state()
{
async_recovery_targets.clear();
backfill_targets.clear();
}
void PeeringState::clear_primary_state()
{
psdout(10) << "clear_primary_state" << dendl;
// clear peering state
stray_set.clear();
peer_log_requested.clear();
peer_missing_requested.clear();
peer_info.clear();
peer_bytes.clear();
peer_missing.clear();
peer_last_complete_ondisk.clear();
peer_activated.clear();
min_last_complete_ondisk = eversion_t();
pg_trim_to = eversion_t();
might_have_unfound.clear();
need_up_thru = false;
missing_loc.clear();
pg_log.reset_recovery_pointers();
clear_recovery_state();
last_update_ondisk = eversion_t();
missing_loc.clear();
pl->clear_primary_state();
}
/// return [start,end) bounds for required past_intervals
static pair<epoch_t, epoch_t> get_required_past_interval_bounds(
const pg_info_t &info,
epoch_t oldest_map) {
epoch_t start = std::max(
info.history.last_epoch_clean ? info.history.last_epoch_clean :
info.history.epoch_pool_created,
oldest_map);
epoch_t end = std::max(
info.history.same_interval_since,
info.history.epoch_pool_created);
return make_pair(start, end);
}
void PeeringState::check_past_interval_bounds() const
{
auto oldest_epoch = pl->oldest_stored_osdmap();
auto rpib = get_required_past_interval_bounds(
info,
oldest_epoch);
if (rpib.first >= rpib.second) {
// do not warn if the start bound is dictated by oldest_map; the
// past intervals are presumably appropriate given the pg info.
if (!past_intervals.empty() &&
rpib.first > oldest_epoch) {
pl->get_clog_error() << info.pgid << " required past_interval bounds are"
<< " empty [" << rpib << ") but past_intervals is not: "
<< past_intervals;
derr << info.pgid << " required past_interval bounds are"
<< " empty [" << rpib << ") but past_intervals is not: "
<< past_intervals << dendl;
}
} else {
if (past_intervals.empty()) {
pl->get_clog_error() << info.pgid << " required past_interval bounds are"
<< " not empty [" << rpib << ") but past_intervals "
<< past_intervals << " is empty";
derr << info.pgid << " required past_interval bounds are"
<< " not empty [" << rpib << ") but past_intervals "
<< past_intervals << " is empty" << dendl;
ceph_assert(!past_intervals.empty());
}
auto apib = past_intervals.get_bounds();
if (apib.first > rpib.first) {
pl->get_clog_error() << info.pgid << " past_intervals [" << apib
<< ") start interval does not contain the required"
<< " bound [" << rpib << ") start";
derr << info.pgid << " past_intervals [" << apib
<< ") start interval does not contain the required"
<< " bound [" << rpib << ") start" << dendl;
ceph_abort_msg("past_interval start interval mismatch");
}
if (apib.second != rpib.second) {
pl->get_clog_error() << info.pgid << " past_interal bound [" << apib
<< ") end does not match required [" << rpib
<< ") end";
derr << info.pgid << " past_interal bound [" << apib
<< ") end does not match required [" << rpib
<< ") end" << dendl;
ceph_abort_msg("past_interval end mismatch");
}
}
}
int PeeringState::clamp_recovery_priority(int priority, int pool_recovery_priority, int max)
{
static_assert(OSD_RECOVERY_PRIORITY_MIN < OSD_RECOVERY_PRIORITY_MAX, "Invalid priority range");
static_assert(OSD_RECOVERY_PRIORITY_MIN >= 0, "Priority range must match unsigned type");
ceph_assert(max <= OSD_RECOVERY_PRIORITY_MAX);
// User can't set this too high anymore, but might be a legacy value
if (pool_recovery_priority > OSD_POOL_PRIORITY_MAX)
pool_recovery_priority = OSD_POOL_PRIORITY_MAX;
if (pool_recovery_priority < OSD_POOL_PRIORITY_MIN)
pool_recovery_priority = OSD_POOL_PRIORITY_MIN;
// Shift range from min to max to 0 to max - min
pool_recovery_priority += (0 - OSD_POOL_PRIORITY_MIN);
ceph_assert(pool_recovery_priority >= 0 && pool_recovery_priority <= (OSD_POOL_PRIORITY_MAX - OSD_POOL_PRIORITY_MIN));
priority += pool_recovery_priority;
// Clamp to valid range
if (priority > max) {
return max;
} else if (priority < OSD_RECOVERY_PRIORITY_MIN) {
return OSD_RECOVERY_PRIORITY_MIN;
} else {
return priority;
}
}
unsigned PeeringState::get_recovery_priority()
{
// a higher value -> a higher priority
int ret = OSD_RECOVERY_PRIORITY_BASE;
int base = ret;
if (state & PG_STATE_FORCED_RECOVERY) {
ret = OSD_RECOVERY_PRIORITY_FORCED;