-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPG.cc
7474 lines (6598 loc) · 218 KB
/
PG.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
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <[email protected]>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include "PG.h"
#include "common/errno.h"
#include "common/config.h"
#include "OSD.h"
#include "OpRequest.h"
#include "common/Timer.h"
#include "messages/MOSDOp.h"
#include "messages/MOSDPGNotify.h"
#include "messages/MOSDPGLog.h"
#include "messages/MOSDPGRemove.h"
#include "messages/MOSDPGInfo.h"
#include "messages/MOSDPGTrim.h"
#include "messages/MOSDPGScan.h"
#include "messages/MOSDPGBackfill.h"
#include "messages/MBackfillReserve.h"
#include "messages/MRecoveryReserve.h"
#include "messages/MOSDPGPush.h"
#include "messages/MOSDPGPushReply.h"
#include "messages/MOSDPGPull.h"
#include "messages/MOSDECSubOpWrite.h"
#include "messages/MOSDECSubOpWriteReply.h"
#include "messages/MOSDECSubOpRead.h"
#include "messages/MOSDECSubOpReadReply.h"
#include "messages/MOSDSubOp.h"
#include "messages/MOSDSubOpReply.h"
#include "common/BackTrace.h"
#include <sstream>
#define dout_subsys ceph_subsys_osd
#undef dout_prefix
#define dout_prefix _prefix(_dout, this)
template <class T>
static ostream& _prefix(std::ostream *_dout, T *t)
{
return *_dout << t->gen_prefix();
}
void PG::get(const string &tag)
{
ref.inc();
#ifdef PG_DEBUG_REFS
Mutex::Locker l(_ref_id_lock);
if (!_tag_counts.count(tag)) {
_tag_counts[tag] = 0;
}
_tag_counts[tag]++;
#endif
}
void PG::put(const string &tag)
{
#ifdef PG_DEBUG_REFS
{
Mutex::Locker l(_ref_id_lock);
assert(_tag_counts.count(tag));
_tag_counts[tag]--;
if (_tag_counts[tag] == 0) {
_tag_counts.erase(tag);
}
}
#endif
if (ref.dec() == 0)
delete this;
}
#ifdef PG_DEBUG_REFS
uint64_t PG::get_with_id()
{
ref.inc();
Mutex::Locker l(_ref_id_lock);
uint64_t id = ++_ref_id;
BackTrace bt(0);
stringstream ss;
bt.print(ss);
dout(20) << __func__ << ": " << info.pgid << " got id " << id << dendl;
assert(!_live_ids.count(id));
_live_ids.insert(make_pair(id, ss.str()));
return id;
}
void PG::put_with_id(uint64_t id)
{
dout(20) << __func__ << ": " << info.pgid << " put id " << id << dendl;
{
Mutex::Locker l(_ref_id_lock);
assert(_live_ids.count(id));
_live_ids.erase(id);
}
if (ref.dec() == 0)
delete this;
}
void PG::dump_live_ids()
{
Mutex::Locker l(_ref_id_lock);
dout(0) << "\t" << __func__ << ": " << info.pgid << " live ids:" << dendl;
for (map<uint64_t, string>::iterator i = _live_ids.begin();
i != _live_ids.end();
++i) {
dout(0) << "\t\tid: " << *i << dendl;
}
dout(0) << "\t" << __func__ << ": " << info.pgid << " live tags:" << dendl;
for (map<string, uint64_t>::iterator i = _tag_counts.begin();
i != _tag_counts.end();
++i) {
dout(0) << "\t\tid: " << *i << dendl;
}
}
#endif
void PGPool::update(OSDMapRef map)
{
const pg_pool_t *pi = map->get_pg_pool(id);
assert(pi);
info = *pi;
auid = pi->auid;
name = map->get_pool_name(id);
if (pi->get_snap_epoch() == map->get_epoch()) {
pi->build_removed_snaps(newly_removed_snaps);
newly_removed_snaps.subtract(cached_removed_snaps);
cached_removed_snaps.union_of(newly_removed_snaps);
snapc = pi->get_snap_context();
} else {
newly_removed_snaps.clear();
}
}
PG::PG(OSDService *o, OSDMapRef curmap,
const PGPool &_pool, spg_t p, const hobject_t& loid,
const hobject_t& ioid) :
osd(o),
cct(o->cct),
osdriver(osd->store, coll_t(), OSD::make_snapmapper_oid()),
snap_mapper(
&osdriver,
p.ps(),
p.get_split_bits(curmap->get_pg_num(_pool.id)),
_pool.id,
p.shard),
map_lock("PG::map_lock"),
osdmap_ref(curmap), last_persisted_osdmap_ref(curmap), pool(_pool),
_lock("PG::_lock"),
ref(0),
#ifdef PG_DEBUG_REFS
_ref_id_lock("PG::_ref_id_lock"), _ref_id(0),
#endif
deleting(false), dirty_info(false), dirty_big_info(false),
info(p),
info_struct_v(0),
coll(p), pg_log(cct), log_oid(loid), biginfo_oid(ioid),
missing_loc(this),
recovery_item(this), scrub_item(this), scrub_finalize_item(this), snap_trim_item(this), stat_queue_item(this),
recovery_ops_active(0),
role(0),
state(0),
send_notify(false),
pg_whoami(osd->whoami, p.shard),
need_up_thru(false),
last_peering_reset(0),
heartbeat_peer_lock("PG::heartbeat_peer_lock"),
backfill_reserved(0),
backfill_reserving(0),
flushes_in_progress(0),
pg_stats_publish_lock("PG::pg_stats_publish_lock"),
pg_stats_publish_valid(false),
osr(osd->osr_registry.lookup_or_create(p, (stringify(p)))),
finish_sync_event(NULL),
scrub_after_recovery(false),
active_pushes(0),
recovery_state(this)
{
#ifdef PG_DEBUG_REFS
osd->add_pgid(p, this);
#endif
}
PG::~PG()
{
#ifdef PG_DEBUG_REFS
osd->remove_pgid(info.pgid, this);
#endif
}
void PG::lock_suspend_timeout(ThreadPool::TPHandle &handle)
{
handle.suspend_tp_timeout();
lock();
handle.reset_tp_timeout();
}
void PG::lock(bool no_lockdep)
{
_lock.Lock(no_lockdep);
// if we have unrecorded dirty state with the lock dropped, there is a bug
assert(!dirty_info);
assert(!dirty_big_info);
dout(30) << "lock" << dendl;
}
std::string PG::gen_prefix() const
{
stringstream out;
OSDMapRef mapref = osdmap_ref;
if (_lock.is_locked_by_me()) {
out << "osd." << osd->whoami
<< " pg_epoch: " << (mapref ? mapref->get_epoch():0)
<< " " << *this << " ";
} else {
out << "osd." << osd->whoami
<< " pg_epoch: " << (mapref ? mapref->get_epoch():0)
<< " pg[" << info.pgid << "(unlocked)] ";
}
return out.str();
}
/********* PG **********/
void PG::proc_master_log(
ObjectStore::Transaction& t, pg_info_t &oinfo,
pg_log_t &olog, pg_missing_t& omissing, pg_shard_t from)
{
dout(10) << "proc_master_log for osd." << from << ": "
<< olog << " " << omissing << dendl;
assert(!is_active() && is_primary());
// merge log into our own log to build master log. no need to
// make any adjustments to their missing map; we are taking their
// log to be authoritative (i.e., their entries are by definitely
// non-divergent).
merge_log(t, oinfo, olog, from);
peer_info[from] = oinfo;
dout(10) << " peer osd." << from << " now " << oinfo << " " << omissing << dendl;
might_have_unfound.insert(from);
peer_missing[from].swap(omissing);
}
void PG::proc_replica_log(
ObjectStore::Transaction& t,
pg_info_t &oinfo, pg_log_t &olog, pg_missing_t& omissing,
pg_shard_t from)
{
dout(10) << "proc_replica_log for osd." << from << ": "
<< oinfo << " " << olog << " " << omissing << dendl;
pg_log.proc_replica_log(t, oinfo, olog, omissing, from);
peer_info[from] = oinfo;
dout(10) << " peer osd." << from << " now " << oinfo << " " << omissing << dendl;
might_have_unfound.insert(from);
for (map<hobject_t, pg_missing_t::item>::iterator i = omissing.missing.begin();
i != omissing.missing.end();
++i) {
dout(20) << " after missing " << i->first << " need " << i->second.need
<< " have " << i->second.have << dendl;
}
peer_missing[from].swap(omissing);
}
bool PG::proc_replica_info(pg_shard_t from, const pg_info_t &oinfo)
{
map<pg_shard_t, pg_info_t>::iterator p = peer_info.find(from);
if (p != peer_info.end() && p->second.last_update == oinfo.last_update) {
dout(10) << " got dup osd." << from << " info " << oinfo << ", identical to ours" << dendl;
return false;
}
dout(10) << " got osd." << from << " " << oinfo << dendl;
assert(is_primary());
peer_info[from] = oinfo;
might_have_unfound.insert(from);
unreg_next_scrub();
if (info.history.merge(oinfo.history))
dirty_info = true;
reg_next_scrub();
// stray?
if (!is_up(from) && !is_acting(from)) {
dout(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 PG::remove_snap_mapped_object(
ObjectStore::Transaction &t, const hobject_t &soid)
{
t.remove(
coll,
ghobject_t(soid, ghobject_t::NO_GEN, pg_whoami.shard));
clear_object_snap_mapping(&t, soid);
}
void PG::clear_object_snap_mapping(
ObjectStore::Transaction *t, const hobject_t &soid)
{
OSDriver::OSTransaction _t(osdriver.get_transaction(t));
if (soid.snap < CEPH_MAXSNAP) {
int r = snap_mapper.remove_oid(
soid,
&_t);
if (!(r == 0 || r == -ENOENT)) {
derr << __func__ << ": remove_oid returned " << cpp_strerror(r) << dendl;
assert(0);
}
}
}
void PG::update_object_snap_mapping(
ObjectStore::Transaction *t, const hobject_t &soid, const set<snapid_t> &snaps)
{
OSDriver::OSTransaction _t(osdriver.get_transaction(t));
assert(soid.snap < CEPH_MAXSNAP);
int r = snap_mapper.remove_oid(
soid,
&_t);
if (!(r == 0 || r == -ENOENT)) {
derr << __func__ << ": remove_oid returned " << cpp_strerror(r) << dendl;
assert(0);
}
snap_mapper.add_oid(
soid,
snaps,
&_t);
}
void PG::merge_log(
ObjectStore::Transaction& t, pg_info_t &oinfo, pg_log_t &olog, pg_shard_t from)
{
PGLogEntryHandler rollbacker;
pg_log.merge_log(
t, oinfo, olog, from, info, &rollbacker, dirty_info, dirty_big_info);
rollbacker.apply(this, &t);
}
void PG::rewind_divergent_log(ObjectStore::Transaction& t, eversion_t newhead)
{
PGLogEntryHandler rollbacker;
pg_log.rewind_divergent_log(
t, newhead, info, &rollbacker, dirty_info, dirty_big_info);
rollbacker.apply(this, &t);
}
/*
* Process information from a replica to determine if it could have any
* objects that i need.
*
* TODO: if the missing set becomes very large, this could get expensive.
* Instead, we probably want to just iterate over our unfound set.
*/
bool PG::search_for_missing(
const pg_info_t &oinfo, const pg_missing_t &omissing,
pg_shard_t from,
RecoveryCtx *ctx)
{
unsigned num_unfound_before = missing_loc.num_unfound();
bool found_missing = missing_loc.add_source_info(
from, oinfo, omissing);
if (found_missing && num_unfound_before != missing_loc.num_unfound())
publish_stats_to_osd();
if (found_missing &&
(get_osdmap()->get_features(NULL) & CEPH_FEATURE_OSD_ERASURE_CODES)) {
pg_info_t tinfo(oinfo);
tinfo.pgid.shard = pg_whoami.shard;
(*(ctx->info_map))[from.osd].push_back(
make_pair(
pg_notify_t(
from.shard, pg_whoami.shard,
get_osdmap()->get_epoch(),
get_osdmap()->get_epoch(),
tinfo),
past_intervals));
}
return found_missing;
}
bool PG::MissingLoc::readable_with_acting(
const hobject_t &hoid,
const set<pg_shard_t> &acting) const {
if (!needs_recovery(hoid)) return true;
if (!missing_loc.count(hoid)) return false;
const set<pg_shard_t> &locs = missing_loc.find(hoid)->second;
dout(10) << __func__ << ": locs:" << locs << dendl;
set<pg_shard_t> have_acting;
for (set<pg_shard_t>::const_iterator i = locs.begin();
i != locs.end();
++i) {
if (acting.count(*i))
have_acting.insert(*i);
}
return (*is_readable)(have_acting);
}
bool PG::MissingLoc::add_source_info(
pg_shard_t fromosd,
const pg_info_t &oinfo,
const pg_missing_t &omissing)
{
bool found_missing = false;;
// found items?
for (map<hobject_t,pg_missing_t::item>::const_iterator p = needs_recovery_map.begin();
p != needs_recovery_map.end();
++p) {
const hobject_t &soid(p->first);
eversion_t need = p->second.need;
if (oinfo.last_update < need) {
dout(10) << "search_for_missing " << soid << " " << need
<< " also missing on osd." << fromosd
<< " (last_update " << oinfo.last_update << " < needed " << need << ")"
<< dendl;
continue;
}
if (p->first >= oinfo.last_backfill) {
// FIXME: this is _probably_ true, although it could conceivably
// be in the undefined region! Hmm!
dout(10) << "search_for_missing " << soid << " " << need
<< " also missing on osd." << fromosd
<< " (past last_backfill " << oinfo.last_backfill << ")"
<< dendl;
continue;
}
if (oinfo.last_complete < need) {
if (omissing.is_missing(soid)) {
dout(10) << "search_for_missing " << soid << " " << need
<< " also missing on osd." << fromosd << dendl;
continue;
}
}
dout(10) << "search_for_missing " << soid << " " << need
<< " is on osd." << fromosd << dendl;
missing_loc[soid].insert(fromosd);
missing_loc_sources.insert(fromosd);
found_missing = true;
}
dout(20) << "needs_recovery_map missing " << needs_recovery_map << dendl;
return found_missing;
}
void PG::discover_all_missing(map<int, map<spg_t,pg_query_t> > &query_map)
{
const pg_missing_t &missing = pg_log.get_missing();
assert(have_unfound());
dout(10) << __func__ << " "
<< missing.num_missing() << " missing, "
<< get_num_unfound() << " unfound"
<< dendl;
std::set<pg_shard_t>::const_iterator m = might_have_unfound.begin();
std::set<pg_shard_t>::const_iterator mend = might_have_unfound.end();
for (; m != mend; ++m) {
pg_shard_t peer(*m);
if (!get_osdmap()->is_up(peer.osd)) {
dout(20) << __func__ << " skipping down osd." << peer << dendl;
continue;
}
map<pg_shard_t, pg_info_t>::const_iterator iter = peer_info.find(peer);
if (iter != peer_info.end() &&
(iter->second.is_empty() || iter->second.dne())) {
// ignore empty peers
continue;
}
// If we've requested any of this stuff, the pg_missing_t information
// should be on its way.
// TODO: coalsce requested_* into a single data structure
if (peer_missing.find(peer) != peer_missing.end()) {
dout(20) << __func__ << ": osd." << peer
<< ": we already have pg_missing_t" << dendl;
continue;
}
if (peer_log_requested.find(peer) != peer_log_requested.end()) {
dout(20) << __func__ << ": osd." << peer
<< ": in peer_log_requested" << dendl;
continue;
}
if (peer_missing_requested.find(peer) != peer_missing_requested.end()) {
dout(20) << __func__ << ": osd." << peer
<< ": in peer_missing_requested" << dendl;
continue;
}
// Request missing
dout(10) << __func__ << ": osd." << peer << ": requesting pg_missing_t"
<< dendl;
peer_missing_requested.insert(peer);
query_map[peer.osd][spg_t(info.pgid.pgid, peer.shard)] =
pg_query_t(
pg_query_t::FULLLOG,
peer.shard, pg_whoami.shard,
info.history, get_osdmap()->get_epoch());
}
}
/******* PG ***********/
bool PG::needs_recovery() const
{
assert(is_primary());
bool ret = false;
const pg_missing_t &missing = pg_log.get_missing();
if (missing.num_missing()) {
dout(10) << __func__ << " primary has " << missing.num_missing() << dendl;
ret = true;
}
assert(!actingbackfill.empty());
set<pg_shard_t>::const_iterator end = actingbackfill.end();
set<pg_shard_t>::const_iterator a = actingbackfill.begin();
assert(a != end);
for (; a != end; ++a) {
if (*a == get_primary()) continue;
pg_shard_t peer = *a;
map<pg_shard_t, pg_missing_t>::const_iterator pm = peer_missing.find(peer);
if (pm == peer_missing.end()) {
dout(10) << __func__ << " osd." << peer << " don't have missing set" << dendl;
ret = true;
continue;
}
if (pm->second.num_missing()) {
dout(10) << __func__ << " osd." << peer << " has " << pm->second.num_missing() << " missing" << dendl;
ret = true;
}
}
if (!ret)
dout(10) << __func__ << " is recovered" << dendl;
return ret;
}
bool PG::needs_backfill() const
{
assert(is_primary());
bool ret = false;
// We can assume that only possible osds that need backfill
// are on the backfill_targets vector nodes.
set<pg_shard_t>::const_iterator end = backfill_targets.end();
set<pg_shard_t>::const_iterator a = backfill_targets.begin();
for (; a != end; ++a) {
pg_shard_t peer = *a;
map<pg_shard_t, pg_info_t>::const_iterator pi = peer_info.find(peer);
if (!pi->second.last_backfill.is_max()) {
dout(10) << __func__ << " osd." << peer << " has last_backfill " << pi->second.last_backfill << dendl;
ret = true;
}
}
if (!ret)
dout(10) << __func__ << " does not need backfill" << dendl;
return ret;
}
bool PG::_calc_past_interval_range(epoch_t *start, epoch_t *end)
{
*end = info.history.same_interval_since;
// Do we already have the intervals we want?
map<epoch_t,pg_interval_t>::const_iterator pif = past_intervals.begin();
if (pif != past_intervals.end()) {
if (pif->first <= info.history.last_epoch_clean) {
dout(10) << __func__ << ": already have past intervals back to "
<< info.history.last_epoch_clean << dendl;
return false;
}
*end = past_intervals.begin()->first;
}
*start = MAX(MAX(info.history.epoch_created,
info.history.last_epoch_clean),
osd->get_superblock().oldest_map);
if (*start >= *end) {
dout(10) << __func__ << " start epoch " << *start << " >= end epoch " << *end
<< ", nothing to do" << dendl;
return false;
}
return true;
}
void PG::generate_past_intervals()
{
epoch_t cur_epoch, end_epoch;
if (!_calc_past_interval_range(&cur_epoch, &end_epoch)) {
return;
}
OSDMapRef last_map, cur_map;
int primary = -1;
int old_primary = -1;
vector<int> acting, up, old_acting, old_up;
cur_map = osd->get_map(cur_epoch);
cur_map->pg_to_up_acting_osds(
get_pgid().pgid, &up, 0, &acting, &primary);
epoch_t same_interval_since = cur_epoch;
dout(10) << __func__ << " over epochs " << cur_epoch << "-"
<< end_epoch << dendl;
++cur_epoch;
for (; cur_epoch <= end_epoch; ++cur_epoch) {
last_map.swap(cur_map);
old_up.swap(up);
old_acting.swap(acting);
old_primary = primary;
cur_map = osd->get_map(cur_epoch);
cur_map->pg_to_up_acting_osds(
get_pgid().pgid, &up, 0, &acting, &primary);
std::stringstream debug;
bool new_interval = pg_interval_t::check_new_interval(
old_primary,
primary,
old_acting,
acting,
old_up,
up,
same_interval_since,
info.history.last_epoch_clean,
cur_map,
last_map,
info.pgid.pool(),
info.pgid.pgid,
&past_intervals,
&debug);
if (new_interval) {
dout(10) << debug.str() << dendl;
same_interval_since = cur_epoch;
}
}
// record our work.
dirty_info = true;
dirty_big_info = true;
}
/*
* Trim past_intervals.
*
* This gets rid of all the past_intervals that happened before last_epoch_clean.
*/
void PG::trim_past_intervals()
{
std::map<epoch_t,pg_interval_t>::iterator pif = past_intervals.begin();
std::map<epoch_t,pg_interval_t>::iterator end = past_intervals.end();
while (pif != end) {
if (pif->second.last >= info.history.last_epoch_clean)
return;
dout(10) << __func__ << ": trimming " << pif->second << dendl;
past_intervals.erase(pif++);
dirty_big_info = true;
}
}
bool PG::adjust_need_up_thru(const OSDMapRef osdmap)
{
epoch_t up_thru = get_osdmap()->get_up_thru(osd->whoami);
if (need_up_thru &&
up_thru >= info.history.same_interval_since) {
dout(10) << "adjust_need_up_thru now " << up_thru << ", need_up_thru now false" << dendl;
need_up_thru = false;
return true;
}
return false;
}
void PG::remove_down_peer_info(const OSDMapRef osdmap)
{
// Remove any downed osds from peer_info
bool removed = false;
map<pg_shard_t, pg_info_t>::iterator p = peer_info.begin();
while (p != peer_info.end()) {
if (!osdmap->is_up(p->first.osd)) {
dout(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_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);
}
/*
* Returns true unless there is a non-lost OSD in might_have_unfound.
*/
bool PG::all_unfound_are_queried_or_lost(const OSDMapRef osdmap) const
{
assert(is_primary());
set<pg_shard_t>::const_iterator peer = might_have_unfound.begin();
set<pg_shard_t>::const_iterator mend = might_have_unfound.end();
for (; peer != mend; ++peer) {
if (peer_missing.count(*peer))
continue;
map<pg_shard_t, pg_info_t>::const_iterator iter = peer_info.find(*peer);
if (iter != peer_info.end() &&
(iter->second.is_empty() || iter->second.dne()))
continue;
const osd_info_t &osd_info(osdmap->get_info(peer->osd));
if (osd_info.lost_at <= osd_info.up_from) {
// If there is even one OSD in might_have_unfound that isn't lost, we
// still might retrieve our unfound.
return false;
}
}
dout(10) << "all_unfound_are_queried_or_lost all of might_have_unfound " << might_have_unfound
<< " have been queried or are marked lost" << dendl;
return true;
}
void PG::build_prior(std::auto_ptr<PriorSet> &prior_set)
{
if (1) {
// sanity check
for (map<pg_shard_t,pg_info_t>::iterator it = peer_info.begin();
it != peer_info.end();
++it) {
assert(info.history.last_epoch_started >= it->second.history.last_epoch_started);
}
}
prior_set.reset(
new PriorSet(
pool.info.ec_pool(),
get_pgbackend()->get_is_recoverable_predicate(),
*get_osdmap(),
past_intervals,
up,
acting,
info,
this));
PriorSet &prior(*prior_set.get());
if (prior.pg_down) {
state_set(PG_STATE_DOWN);
}
if (get_osdmap()->get_up_thru(osd->whoami) < info.history.same_interval_since) {
dout(10) << "up_thru " << get_osdmap()->get_up_thru(osd->whoami)
<< " < same_since " << info.history.same_interval_since
<< ", must notify monitor" << dendl;
need_up_thru = true;
} else {
dout(10) << "up_thru " << get_osdmap()->get_up_thru(osd->whoami)
<< " >= same_since " << info.history.same_interval_since
<< ", all is well" << dendl;
need_up_thru = false;
}
set_probe_targets(prior_set->probe);
}
void PG::clear_primary_state(bool staying_primary)
{
dout(10) << "clear_primary_state" << dendl;
// clear peering state
stray_set.clear();
peer_log_requested.clear();
peer_missing_requested.clear();
peer_info.clear();
peer_missing.clear();
need_up_thru = false;
peer_last_complete_ondisk.clear();
peer_activated.clear();
min_last_complete_ondisk = eversion_t();
pg_trim_to = eversion_t();
stray_purged.clear();
might_have_unfound.clear();
last_update_ondisk = eversion_t();
snap_trimq.clear();
finish_sync_event = 0; // so that _finish_recvoery doesn't go off in another thread
missing_loc.clear();
pg_log.reset_recovery_pointers();
scrubber.reserved_peers.clear();
scrub_after_recovery = false;
osd->recovery_wq.dequeue(this);
osd->snap_trim_wq.dequeue(this);
if (!staying_primary)
agent_clear();
}
/**
* find_best_info
*
* Returns an iterator to the best info in infos sorted by:
* 1) Prefer newer last_update
* 2) Prefer longer tail if it brings another info into contiguity
* 3) Prefer current primary
*/
map<pg_shard_t, pg_info_t>::const_iterator PG::find_best_info(
const map<pg_shard_t, pg_info_t> &infos) const
{
eversion_t min_last_update_acceptable = eversion_t::max();
epoch_t max_last_epoch_started_found = 0;
for (map<pg_shard_t, pg_info_t>::const_iterator i = infos.begin();
i != infos.end();
++i) {
if (max_last_epoch_started_found < i->second.last_epoch_started) {
min_last_update_acceptable = eversion_t::max();
max_last_epoch_started_found = i->second.last_epoch_started;
}
if (max_last_epoch_started_found == i->second.last_epoch_started) {
if (min_last_update_acceptable > i->second.last_update)
min_last_update_acceptable = i->second.last_update;
}
}
assert(min_last_update_acceptable != eversion_t::max());
map<pg_shard_t, pg_info_t>::const_iterator best = infos.end();
// find osd with newest last_update (oldest for ec_pool).
// if there are multiples, prefer
// - a longer tail, if it brings another peer into log contiguity
// - the current primary
for (map<pg_shard_t, pg_info_t>::const_iterator p = infos.begin();
p != infos.end();
++p) {
// Only consider peers with last_update >= min_last_update_acceptable
if (p->second.last_update < min_last_update_acceptable)
continue;
// Disquality anyone who is incomplete (not fully backfilled)
if (p->second.is_incomplete())
continue;
if (best == infos.end()) {
best = p;
continue;
}
// Prefer newer last_update
if (pool.info.require_rollback()) {
if (p->second.last_update > best->second.last_update)
continue;
if (p->second.last_update < best->second.last_update) {
best = p;
continue;
}
} else {
if (p->second.last_update < best->second.last_update)
continue;
if (p->second.last_update > best->second.last_update) {
best = p;
continue;
}
}
// Prefer longer tail if it brings another peer into contiguity
for (map<pg_shard_t, pg_info_t>::const_iterator q = infos.begin();
q != infos.end();
++q) {
if (q->second.is_incomplete())
continue; // don't care about log contiguity
if (q->second.last_update < best->second.log_tail &&
q->second.last_update >= p->second.log_tail) {
dout(10) << "calc_acting prefer osd." << p->first
<< " because it brings osd." << q->first << " into log contiguity" << dendl;
best = p;
continue;
}
if (q->second.last_update < p->second.log_tail &&
q->second.last_update >= best->second.log_tail) {
continue;
}
}
// prefer current primary (usually the caller), all things being equal
if (p->first == pg_whoami) {
dout(10) << "calc_acting prefer osd." << p->first
<< " because it is current primary" << dendl;
best = p;
continue;
}
}
return best;
}
void PG::calc_ec_acting(
map<pg_shard_t, pg_info_t>::const_iterator auth_log_shard,
unsigned size,
const vector<int> &acting,
pg_shard_t acting_primary,
const vector<int> &up,
pg_shard_t up_primary,
const map<pg_shard_t, pg_info_t> &all_info,
bool compat_mode,
vector<int> *_want,
set<pg_shard_t> *backfill,
set<pg_shard_t> *acting_backfill,
pg_shard_t *want_primary,
ostream &ss) {
vector<int> want(size, CRUSH_ITEM_NONE);
map<shard_id_t, set<pg_shard_t> > all_info_by_shard;
unsigned usable = 0;
for(map<pg_shard_t, pg_info_t>::const_iterator i = all_info.begin();
i != all_info.end();
++i) {
all_info_by_shard[i->first.shard].insert(i->first);
}
for (shard_id_t i = 0; i < want.size(); ++i) {
ss << "For position " << (unsigned)i << ": ";
if (up.size() > (unsigned)i && up[i] != CRUSH_ITEM_NONE &&
!all_info.find(pg_shard_t(up[i], i))->second.is_incomplete() &&
all_info.find(pg_shard_t(up[i], i))->second.last_update >=
auth_log_shard->second.log_tail) {
ss << " selecting up[i]: " << pg_shard_t(up[i], i) << std::endl;
want[i] = up[i];
++usable;
continue;
}
if (up.size() > (unsigned)i && up[i] != CRUSH_ITEM_NONE) {
ss << " backfilling up[i]: " << pg_shard_t(up[i], i)
<< " and ";
backfill->insert(pg_shard_t(up[i], i));
}
if (acting.size() > (unsigned)i && acting[i] != CRUSH_ITEM_NONE &&
!all_info.find(pg_shard_t(acting[i], i))->second.is_incomplete() &&
all_info.find(pg_shard_t(acting[i], i))->second.last_update >=
auth_log_shard->second.log_tail) {
ss << " selecting acting[i]: " << pg_shard_t(acting[i], i) << std::endl;
want[i] = acting[i];
++usable;
} else {
for (set<pg_shard_t>::iterator j = all_info_by_shard[i].begin();
j != all_info_by_shard[i].end();
++j) {
assert(j->shard == i);
if (!all_info.find(*j)->second.is_incomplete() &&
all_info.find(*j)->second.last_update >=
auth_log_shard->second.log_tail) {
ss << " selecting stray: " << *j << std::endl;
want[i] = j->osd;
++usable;
break;
}
}
if (want[i] == CRUSH_ITEM_NONE)
ss << " failed to fill position " << i << std::endl;
}
}
bool found_primary = false;
for (shard_id_t i = 0; i < want.size(); ++i) {
if (want[i] != CRUSH_ITEM_NONE) {
acting_backfill->insert(pg_shard_t(want[i], i));
if (!found_primary) {
*want_primary = pg_shard_t(want[i], i);
found_primary = true;
}
}
}
acting_backfill->insert(backfill->begin(), backfill->end());