-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
PG.h
2563 lines (2227 loc) · 80.2 KB
/
PG.h
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 <sage@newdream.net>
*
* 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.
*
*/
#ifndef CEPH_PG_H
#define CEPH_PG_H
#include <boost/statechart/custom_reaction.hpp>
#include <boost/statechart/event.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/state.hpp>
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/transition.hpp>
#include <boost/statechart/event_base.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/circular_buffer.hpp>
#include "include/memory.h"
#include "include/mempool.h"
// re-include our assert to clobber boost's
#include "include/assert.h"
#include "include/types.h"
#include "include/stringify.h"
#include "osd_types.h"
#include "include/xlist.h"
#include "SnapMapper.h"
#include "Session.h"
#include "common/Timer.h"
#include "PGLog.h"
#include "OSDMap.h"
#include "messages/MOSDPGLog.h"
#include "include/str_list.h"
#include "PGBackend.h"
#include <atomic>
#include <list>
#include <memory>
#include <stack>
#include <string>
#include <tuple>
using namespace std;
// #include "include/unordered_map.h"
// #include "include/unordered_set.h"
//#define DEBUG_RECOVERY_OIDS // track set of recovering oids explicitly, to find counting bugs
class OSD;
class OSDService;
class MOSDOp;
class MOSDPGScan;
class MOSDPGBackfill;
class MOSDPGInfo;
class PG;
struct OpRequest;
typedef OpRequest::Ref OpRequestRef;
class MOSDPGLog;
class CephContext;
namespace Scrub {
class Store;
}
void intrusive_ptr_add_ref(PG *pg);
void intrusive_ptr_release(PG *pg);
using state_history_entry = std::tuple<utime_t, utime_t, const char*>;
using embedded_state = std::pair<utime_t, const char*>;
struct PGStateInstance {
// Time spent in pg states
void setepoch(const epoch_t current_epoch) {
this_epoch = current_epoch;
}
void enter_state(const utime_t entime, const char* state) {
embedded_states.push(std::make_pair(entime, state));
}
void exit_state(const utime_t extime) {
embedded_state this_state = embedded_states.top();
state_history.push_back(state_history_entry{
this_state.first, extime, this_state.second});
embedded_states.pop();
}
epoch_t this_epoch;
utime_t enter_time;
std::vector<state_history_entry> state_history;
std::stack<embedded_state> embedded_states;
};
class PGStateHistory {
// Member access protected with the PG lock
public:
PGStateHistory() : buffer(10) {}
void enter(PG* pg, const utime_t entime, const char* state);
void exit(const char* state);
void reset() {
pi = nullptr;
}
void set_pg_in_destructor() { pg_in_destructor = true; }
void dump(Formatter* f) const;
private:
bool pg_in_destructor = false;
PG* thispg = nullptr;
std::unique_ptr<PGStateInstance> tmppi;
PGStateInstance* pi = nullptr;
boost::circular_buffer<std::unique_ptr<PGStateInstance>> buffer;
};
#ifdef PG_DEBUG_REFS
#include "common/tracked_int_ptr.hpp"
uint64_t get_with_id(PG *pg);
void put_with_id(PG *pg, uint64_t id);
typedef TrackedIntPtr<PG> PGRef;
#else
typedef boost::intrusive_ptr<PG> PGRef;
#endif
class PGRecoveryStats {
struct per_state_info {
uint64_t enter, exit; // enter/exit counts
uint64_t events;
utime_t event_time; // time spent processing events
utime_t total_time; // total time in state
utime_t min_time, max_time;
// cppcheck-suppress unreachableCode
per_state_info() : enter(0), exit(0), events(0) {}
};
map<const char *,per_state_info> info;
Mutex lock;
public:
PGRecoveryStats() : lock("PGRecoverStats::lock") {}
void reset() {
Mutex::Locker l(lock);
info.clear();
}
void dump(ostream& out) {
Mutex::Locker l(lock);
for (map<const char *,per_state_info>::iterator p = info.begin(); p != info.end(); ++p) {
per_state_info& i = p->second;
out << i.enter << "\t" << i.exit << "\t"
<< i.events << "\t" << i.event_time << "\t"
<< i.total_time << "\t"
<< i.min_time << "\t" << i.max_time << "\t"
<< p->first << "\n";
}
}
void dump_formatted(Formatter *f) {
Mutex::Locker l(lock);
f->open_array_section("pg_recovery_stats");
for (map<const char *,per_state_info>::iterator p = info.begin();
p != info.end(); ++p) {
per_state_info& i = p->second;
f->open_object_section("recovery_state");
f->dump_int("enter", i.enter);
f->dump_int("exit", i.exit);
f->dump_int("events", i.events);
f->dump_stream("event_time") << i.event_time;
f->dump_stream("total_time") << i.total_time;
f->dump_stream("min_time") << i.min_time;
f->dump_stream("max_time") << i.max_time;
vector<string> states;
get_str_vec(p->first, "/", states);
f->open_array_section("nested_states");
for (vector<string>::iterator st = states.begin();
st != states.end(); ++st) {
f->dump_string("state", *st);
}
f->close_section();
f->close_section();
}
f->close_section();
}
void log_enter(const char *s) {
Mutex::Locker l(lock);
info[s].enter++;
}
void log_exit(const char *s, utime_t dur, uint64_t events, utime_t event_dur) {
Mutex::Locker l(lock);
per_state_info &i = info[s];
i.exit++;
i.total_time += dur;
if (dur > i.max_time)
i.max_time = dur;
if (dur < i.min_time || i.min_time == utime_t())
i.min_time = dur;
i.events += events;
i.event_time += event_dur;
}
};
struct PGPool {
CephContext* cct;
epoch_t cached_epoch;
int64_t id;
string name;
uint64_t auid;
pg_pool_t info;
SnapContext snapc; // the default pool snapc, ready to go.
interval_set<snapid_t> cached_removed_snaps; // current removed_snaps set
interval_set<snapid_t> newly_removed_snaps; // newly removed in the last epoch
PGPool(CephContext* cct, OSDMapRef map, int64_t i)
: cct(cct),
cached_epoch(map->get_epoch()),
id(i),
name(map->get_pool_name(id)),
auid(map->get_pg_pool(id)->auid) {
const pg_pool_t *pi = map->get_pg_pool(id);
assert(pi);
info = *pi;
snapc = pi->get_snap_context();
pi->build_removed_snaps(cached_removed_snaps);
}
void update(OSDMapRef map);
};
/** PG - Replica Placement Group
*
*/
class PG : public DoutPrefixProvider {
protected:
OSDService *osd;
CephContext *cct;
OSDriver osdriver;
SnapMapper snap_mapper;
bool eio_errors_to_process = false;
virtual PGBackend *get_pgbackend() = 0;
public:
std::string gen_prefix() const override;
CephContext *get_cct() const override { return cct; }
unsigned get_subsys() const override { return ceph_subsys_osd; }
/*** PG ****/
void update_snap_mapper_bits(uint32_t bits) {
snap_mapper.update_bits(bits);
}
/// get_is_recoverable_predicate: caller owns returned pointer and must delete when done
IsPGRecoverablePredicate *get_is_recoverable_predicate() {
return get_pgbackend()->get_is_recoverable_predicate();
}
protected:
OSDMapRef osdmap_ref;
OSDMapRef last_persisted_osdmap_ref;
PGPool pool;
void requeue_map_waiters();
void update_osdmap_ref(OSDMapRef newmap) {
assert(_lock.is_locked_by_me());
osdmap_ref = std::move(newmap);
}
public:
OSDMapRef get_osdmap() const {
assert(is_locked());
assert(osdmap_ref);
return osdmap_ref;
}
protected:
/** locking and reference counting.
* I destroy myself when the reference count hits zero.
* lock() should be called before doing anything.
* get() should be called on pointer copy (to another thread, etc.).
* put() should be called on destruction of some previously copied pointer.
* unlock() when done with the current pointer (_most common_).
*/
mutable Mutex _lock;
std::atomic_uint ref{0};
#ifdef PG_DEBUG_REFS
Mutex _ref_id_lock;
map<uint64_t, string> _live_ids;
map<string, uint64_t> _tag_counts;
uint64_t _ref_id;
#endif
public:
bool deleting; // true while in removing or OSD is shutting down
ZTracer::Endpoint trace_endpoint;
void lock_suspend_timeout(ThreadPool::TPHandle &handle);
void lock(bool no_lockdep = false) const;
void unlock() const {
//generic_dout(0) << this << " " << info.pgid << " unlock" << dendl;
assert(!dirty_info);
assert(!dirty_big_info);
_lock.Unlock();
}
bool is_locked() const {
return _lock.is_locked();
}
#ifdef PG_DEBUG_REFS
uint64_t get_with_id();
void put_with_id(uint64_t);
void dump_live_ids();
#endif
void get(const char* tag);
void put(const char* tag);
bool dirty_info, dirty_big_info;
public:
bool is_ec_pg() const {
return pool.info.ec_pool();
}
// pg state
pg_info_t info; ///< current pg info
pg_info_t last_written_info; ///< last written info
__u8 info_struct_v;
static const __u8 cur_struct_v = 10;
// v10 is the new past_intervals encoding
// v9 was fastinfo_key addition
// v8 was the move to a per-pg pgmeta object
// v7 was SnapMapper addition in 86658392516d5175b2756659ef7ffaaf95b0f8ad
// (first appeared in cuttlefish).
static const __u8 compat_struct_v = 10;
bool must_upgrade() {
return info_struct_v < cur_struct_v;
}
bool can_upgrade() {
return info_struct_v >= compat_struct_v;
}
void upgrade(ObjectStore *store);
const coll_t coll;
ObjectStore::CollectionHandle ch;
PGLog pg_log;
static string get_info_key(spg_t pgid) {
return stringify(pgid) + "_info";
}
static string get_biginfo_key(spg_t pgid) {
return stringify(pgid) + "_biginfo";
}
static string get_epoch_key(spg_t pgid) {
return stringify(pgid) + "_epoch";
}
ghobject_t pgmeta_oid;
class MissingLoc {
map<hobject_t, pg_missing_item> needs_recovery_map;
map<hobject_t, set<pg_shard_t> > missing_loc;
set<pg_shard_t> missing_loc_sources;
PG *pg;
set<pg_shard_t> empty_set;
public:
boost::scoped_ptr<IsPGReadablePredicate> is_readable;
boost::scoped_ptr<IsPGRecoverablePredicate> is_recoverable;
explicit MissingLoc(PG *pg)
: pg(pg) {}
void set_backend_predicates(
IsPGReadablePredicate *_is_readable,
IsPGRecoverablePredicate *_is_recoverable) {
is_readable.reset(_is_readable);
is_recoverable.reset(_is_recoverable);
}
string gen_prefix() const { return pg->gen_prefix(); }
bool needs_recovery(
const hobject_t &hoid,
eversion_t *v = 0) const {
map<hobject_t, pg_missing_item>::const_iterator i =
needs_recovery_map.find(hoid);
if (i == needs_recovery_map.end())
return false;
if (v)
*v = i->second.need;
return true;
}
bool is_deleted(const hobject_t &hoid) const {
auto i = needs_recovery_map.find(hoid);
if (i == needs_recovery_map.end())
return false;
return i->second.is_delete();
}
bool is_unfound(const hobject_t &hoid) const {
return needs_recovery(hoid) && !is_deleted(hoid) && (
!missing_loc.count(hoid) ||
!(*is_recoverable)(missing_loc.find(hoid)->second));
}
bool readable_with_acting(
const hobject_t &hoid,
const set<pg_shard_t> &acting) const;
uint64_t num_unfound() const {
uint64_t ret = 0;
for (map<hobject_t, pg_missing_item>::const_iterator i =
needs_recovery_map.begin();
i != needs_recovery_map.end();
++i) {
if (is_unfound(i->first))
++ret;
}
return ret;
}
bool have_unfound() const {
for (map<hobject_t, pg_missing_item>::const_iterator i =
needs_recovery_map.begin();
i != needs_recovery_map.end();
++i) {
if (is_unfound(i->first))
return true;
}
return false;
}
void clear() {
needs_recovery_map.clear();
missing_loc.clear();
missing_loc_sources.clear();
}
void add_location(const hobject_t &hoid, pg_shard_t location) {
missing_loc[hoid].insert(location);
}
void remove_location(const hobject_t &hoid, pg_shard_t location) {
missing_loc[hoid].erase(location);
}
void add_active_missing(const pg_missing_t &missing) {
for (map<hobject_t, pg_missing_item>::const_iterator i =
missing.get_items().begin();
i != missing.get_items().end();
++i) {
map<hobject_t, pg_missing_item>::const_iterator j =
needs_recovery_map.find(i->first);
if (j == needs_recovery_map.end()) {
needs_recovery_map.insert(*i);
} else {
lgeneric_dout(pg->cct, 0) << this << " " << pg->info.pgid << " unexpected need for "
<< i->first << " have " << j->second
<< " tried to add " << i->second << dendl;
assert(i->second.need == j->second.need);
}
}
}
void add_missing(const hobject_t &hoid, eversion_t need, eversion_t have) {
needs_recovery_map[hoid] = pg_missing_item(need, have);
}
void revise_need(const hobject_t &hoid, eversion_t need) {
assert(needs_recovery(hoid));
needs_recovery_map[hoid].need = need;
}
/// Adds info about a possible recovery source
bool add_source_info(
pg_shard_t source, ///< [in] source
const pg_info_t &oinfo, ///< [in] info
const pg_missing_t &omissing, ///< [in] (optional) missing
ThreadPool::TPHandle* handle ///< [in] ThreadPool handle
); ///< @return whether a new object location was discovered
/// Adds recovery sources in batch
void add_batch_sources_info(
const set<pg_shard_t> &sources, ///< [in] a set of resources which can be used for all objects
ThreadPool::TPHandle* handle ///< [in] ThreadPool handle
);
/// Uses osdmap to update structures for now down sources
void check_recovery_sources(const OSDMapRef& osdmap);
/// Call when hoid is no longer missing in acting set
void recovered(const hobject_t &hoid) {
needs_recovery_map.erase(hoid);
missing_loc.erase(hoid);
}
/// Call to update structures for hoid after a change
void rebuild(
const hobject_t &hoid,
pg_shard_t self,
const set<pg_shard_t> to_recover,
const pg_info_t &info,
const pg_missing_t &missing,
const map<pg_shard_t, pg_missing_t> &pmissing,
const map<pg_shard_t, pg_info_t> &pinfo) {
recovered(hoid);
boost::optional<pg_missing_item> item;
auto miter = missing.get_items().find(hoid);
if (miter != missing.get_items().end()) {
item = miter->second;
} else {
for (auto &&i: to_recover) {
if (i == self)
continue;
auto pmiter = pmissing.find(i);
assert(pmiter != pmissing.end());
miter = pmiter->second.get_items().find(hoid);
if (miter != pmiter->second.get_items().end()) {
item = miter->second;
break;
}
}
}
if (!item)
return; // recovered!
needs_recovery_map[hoid] = *item;
if (item->is_delete())
return;
auto mliter =
missing_loc.insert(make_pair(hoid, set<pg_shard_t>())).first;
assert(info.last_backfill.is_max());
assert(info.last_update >= item->need);
if (!missing.is_missing(hoid))
mliter->second.insert(self);
for (auto &&i: pmissing) {
auto pinfoiter = pinfo.find(i.first);
assert(pinfoiter != pinfo.end());
if (item->need <= pinfoiter->second.last_update &&
hoid <= pinfoiter->second.last_backfill &&
!i.second.is_missing(hoid))
mliter->second.insert(i.first);
}
}
const set<pg_shard_t> &get_locations(const hobject_t &hoid) const {
return missing_loc.count(hoid) ?
missing_loc.find(hoid)->second : empty_set;
}
const map<hobject_t, set<pg_shard_t>> &get_missing_locs() const {
return missing_loc;
}
const map<hobject_t, pg_missing_item> &get_needs_recovery() const {
return needs_recovery_map;
}
} missing_loc;
PastIntervals past_intervals;
interval_set<snapid_t> snap_trimq;
/* You should not use these items without taking their respective queue locks
* (if they have one) */
xlist<PG*>::item stat_queue_item;
bool scrub_queued;
bool recovery_queued;
int recovery_ops_active;
set<pg_shard_t> waiting_on_backfill;
#ifdef DEBUG_RECOVERY_OIDS
set<hobject_t> recovering_oids;
#endif
protected:
int role; // 0 = primary, 1 = replica, -1=none.
unsigned state; // PG_STATE_*
bool send_notify; ///< true if we are non-primary and should notify the primary
public:
eversion_t last_update_ondisk; // last_update that has committed; ONLY DEFINED WHEN is_active()
eversion_t last_complete_ondisk; // last_complete that has committed.
eversion_t last_update_applied;
struct C_UpdateLastRollbackInfoTrimmedToApplied : Context {
PGRef pg;
epoch_t e;
eversion_t v;
C_UpdateLastRollbackInfoTrimmedToApplied(PG *pg, epoch_t e, eversion_t v)
: pg(pg), e(e), v(v) {}
void finish(int) override {
pg->lock();
if (!pg->pg_has_reset_since(e)) {
pg->last_rollback_info_trimmed_to_applied = v;
}
pg->unlock();
}
};
// entries <= last_rollback_info_trimmed_to_applied have been trimmed,
// and the transaction has applied
eversion_t last_rollback_info_trimmed_to_applied;
// primary state
public:
pg_shard_t primary;
pg_shard_t pg_whoami;
pg_shard_t up_primary;
vector<int> up, acting, want_acting;
set<pg_shard_t> actingbackfill, actingset, upset;
map<pg_shard_t,eversion_t> peer_last_complete_ondisk;
eversion_t min_last_complete_ondisk; // up: min over last_complete_ondisk, peer_last_complete_ondisk
eversion_t pg_trim_to;
set<int> blocked_by; ///< osds we are blocked by (for pg stats)
// [primary only] content recovery state
public:
struct BufferedRecoveryMessages {
map<int, map<spg_t, pg_query_t> > query_map;
map<int, vector<pair<pg_notify_t, PastIntervals> > > info_map;
map<int, vector<pair<pg_notify_t, PastIntervals> > > notify_list;
};
struct RecoveryCtx {
utime_t start_time;
map<int, map<spg_t, pg_query_t> > *query_map;
map<int, vector<pair<pg_notify_t, PastIntervals> > > *info_map;
map<int, vector<pair<pg_notify_t, PastIntervals> > > *notify_list;
set<PGRef> created_pgs;
C_Contexts *on_applied;
C_Contexts *on_safe;
ObjectStore::Transaction *transaction;
ThreadPool::TPHandle* handle;
RecoveryCtx(map<int, map<spg_t, pg_query_t> > *query_map,
map<int,
vector<pair<pg_notify_t, PastIntervals> > > *info_map,
map<int,
vector<pair<pg_notify_t, PastIntervals> > > *notify_list,
C_Contexts *on_applied,
C_Contexts *on_safe,
ObjectStore::Transaction *transaction)
: query_map(query_map), info_map(info_map),
notify_list(notify_list),
on_applied(on_applied),
on_safe(on_safe),
transaction(transaction),
handle(NULL) {}
RecoveryCtx(BufferedRecoveryMessages &buf, RecoveryCtx &rctx)
: query_map(&(buf.query_map)),
info_map(&(buf.info_map)),
notify_list(&(buf.notify_list)),
on_applied(rctx.on_applied),
on_safe(rctx.on_safe),
transaction(rctx.transaction),
handle(rctx.handle) {}
void accept_buffered_messages(BufferedRecoveryMessages &m) {
assert(query_map);
assert(info_map);
assert(notify_list);
for (map<int, map<spg_t, pg_query_t> >::iterator i = m.query_map.begin();
i != m.query_map.end();
++i) {
map<spg_t, pg_query_t> &omap = (*query_map)[i->first];
for (map<spg_t, pg_query_t>::iterator j = i->second.begin();
j != i->second.end();
++j) {
omap[j->first] = j->second;
}
}
for (map<int, vector<pair<pg_notify_t, PastIntervals> > >::iterator i
= m.info_map.begin();
i != m.info_map.end();
++i) {
vector<pair<pg_notify_t, PastIntervals> > &ovec =
(*info_map)[i->first];
ovec.reserve(ovec.size() + i->second.size());
ovec.insert(ovec.end(), i->second.begin(), i->second.end());
}
for (map<int, vector<pair<pg_notify_t, PastIntervals> > >::iterator i
= m.notify_list.begin();
i != m.notify_list.end();
++i) {
vector<pair<pg_notify_t, PastIntervals> > &ovec =
(*notify_list)[i->first];
ovec.reserve(ovec.size() + i->second.size());
ovec.insert(ovec.end(), i->second.begin(), i->second.end());
}
}
};
PGStateHistory pgstate_history;
struct NamedState {
const char *state_name;
utime_t enter_time;
PG* pg;
const char *get_state_name() { return state_name; }
NamedState(PG *pg_, const char *state_name_)
: state_name(state_name_), enter_time(ceph_clock_now()), pg(pg_) {
pg->pgstate_history.enter(pg, enter_time, state_name);
}
virtual ~NamedState() { pg->pgstate_history.exit(state_name); }
};
protected:
/*
* peer_info -- projected (updates _before_ replicas ack)
* peer_missing -- committed (updates _after_ replicas ack)
*/
bool need_up_thru;
set<pg_shard_t> stray_set; // non-acting osds that have PG data.
map<pg_shard_t, pg_info_t> peer_info; // info from peers (stray or prior)
set<pg_shard_t> peer_purged; // peers purged
map<pg_shard_t, pg_missing_t> peer_missing;
set<pg_shard_t> peer_log_requested; // logs i've requested (and start stamps)
set<pg_shard_t> peer_missing_requested;
// i deleted these strays; ignore racing PGInfo from them
set<pg_shard_t> peer_activated;
// primary-only, recovery-only state
set<pg_shard_t> might_have_unfound; // These osds might have objects on them
// which are unfound on the primary
epoch_t last_peering_reset;
/* heartbeat peers */
void set_probe_targets(const set<pg_shard_t> &probe_set);
void clear_probe_targets();
public:
Mutex heartbeat_peer_lock;
set<int> heartbeat_peers;
set<int> probe_targets;
/**
* BackfillInterval
*
* Represents the objects in a range [begin, end)
*
* Possible states:
* 1) begin == end == hobject_t() indicates the the interval is unpopulated
* 2) Else, objects contains all objects in [begin, end)
*/
struct BackfillInterval {
// info about a backfill interval on a peer
eversion_t version; /// version at which the scan occurred
map<hobject_t,eversion_t> objects;
hobject_t begin;
hobject_t end;
/// clear content
void clear() {
*this = BackfillInterval();
}
/// clear objects list only
void clear_objects() {
objects.clear();
}
/// reinstantiate with a new start+end position and sort order
void reset(hobject_t start) {
clear();
begin = end = start;
}
/// true if there are no objects in this interval
bool empty() const {
return objects.empty();
}
/// true if interval extends to the end of the range
bool extends_to_end() const {
return end.is_max();
}
/// removes items <= soid and adjusts begin to the first object
void trim_to(const hobject_t &soid) {
trim();
while (!objects.empty() &&
objects.begin()->first <= soid) {
pop_front();
}
}
/// Adjusts begin to the first object
void trim() {
if (!objects.empty())
begin = objects.begin()->first;
else
begin = end;
}
/// drop first entry, and adjust @begin accordingly
void pop_front() {
assert(!objects.empty());
objects.erase(objects.begin());
trim();
}
/// dump
void dump(Formatter *f) const {
f->dump_stream("begin") << begin;
f->dump_stream("end") << end;
f->open_array_section("objects");
for (map<hobject_t, eversion_t>::const_iterator i =
objects.begin();
i != objects.end();
++i) {
f->open_object_section("object");
f->dump_stream("object") << i->first;
f->dump_stream("version") << i->second;
f->close_section();
}
f->close_section();
}
};
protected:
BackfillInterval backfill_info;
map<pg_shard_t, BackfillInterval> peer_backfill_info;
bool backfill_reserved;
bool backfill_reserving;
friend class OSD;
public:
set<pg_shard_t> backfill_targets;
bool is_backfill_targets(pg_shard_t osd) {
return backfill_targets.count(osd);
}
protected:
/*
* blocked request wait hierarchy
*
* In order to preserve request ordering we need to be careful about the
* order in which blocked requests get requeued. Generally speaking, we
* push the requests back up to the op_wq in reverse order (most recent
* request first) so that they come back out again in the original order.
* However, because there are multiple wait queues, we need to requeue
* waitlists in order. Generally speaking, we requeue the wait lists
* that are checked first.
*
* Here are the various wait lists, in the order they are used during
* request processing, with notes:
*
* - waiting_for_map
* - may start or stop blocking at any time (depending on client epoch)
* - waiting_for_peered
* - !is_peered() or flushes_in_progress
* - only starts blocking on interval change; never restarts
* - waiting_for_active
* - !is_active()
* - only starts blocking on interval change; never restarts
* - waiting_for_scrub
* - starts and stops blocking for varying intervals during scrub
* - waiting_for_unreadable_object
* - never restarts once object is readable (* except for EIO?)
* - waiting_for_degraded_object
* - never restarts once object is writeable (* except for EIO?)
* - waiting_for_blocked_object
* - starts and stops based on proxied op activity
* - obc rwlocks
* - starts and stops based on read/write activity
*
* Notes:
*
* 1. During and interval change, we requeue *everything* in the above order.
*
* 2. When an obc rwlock is released, we check for a scrub block and requeue
* the op there if it applies. We ignore the unreadable/degraded/blocked
* queues because we assume they cannot apply at that time (this is
* probably mostly true).
*
* 3. The requeue_ops helper will push ops onto the waiting_for_map list if
* it is non-empty.
*
* These three behaviors are generally sufficient to maintain ordering, with
* the possible exception of cases where we make an object degraded or
* unreadable that was previously okay, e.g. when scrub or op processing
* encounter an unexpected error. FIXME.
*/
// pg waiters
unsigned flushes_in_progress;
// ops with newer maps than our (or blocked behind them)
// track these by client, since inter-request ordering doesn't otherwise
// matter.
unordered_map<entity_name_t,list<OpRequestRef>> waiting_for_map;
// ops waiting on peered
list<OpRequestRef> waiting_for_peered;
// ops waiting on active (require peered as well)
list<OpRequestRef> waiting_for_active;
list<OpRequestRef> waiting_for_scrub;
list<OpRequestRef> waiting_for_cache_not_full;
list<OpRequestRef> waiting_for_clean_to_primary_repair;
map<hobject_t, list<OpRequestRef>> waiting_for_unreadable_object,
waiting_for_degraded_object,
waiting_for_blocked_object;
set<hobject_t> objects_blocked_on_cache_full;
map<hobject_t,snapid_t> objects_blocked_on_degraded_snap;
map<hobject_t,ObjectContextRef> objects_blocked_on_snap_promotion;
// Callbacks should assume pg (and nothing else) is locked
map<hobject_t, list<Context*>> callbacks_for_degraded_object;
map<eversion_t,
list<pair<OpRequestRef, version_t> > > waiting_for_ondisk;
void requeue_object_waiters(map<hobject_t, list<OpRequestRef>>& m);
void requeue_op(OpRequestRef op);
void requeue_ops(list<OpRequestRef> &l);
// stats that persist lazily
object_stat_collection_t unstable_stats;
// publish stats
Mutex pg_stats_publish_lock;
bool pg_stats_publish_valid;
pg_stat_t pg_stats_publish;
// for ordering writes
ceph::shared_ptr<ObjectStore::Sequencer> osr;
void _update_calc_stats();
void _update_blocked_by();
void publish_stats_to_osd();
void clear_publish_stats();
public:
void clear_primary_state();
bool is_actingbackfill(pg_shard_t osd) const {
return actingbackfill.count(osd);
}
bool is_acting(pg_shard_t osd) const {
return has_shard(pool.info.ec_pool(), acting, osd);
}
bool is_up(pg_shard_t osd) const {
return has_shard(pool.info.ec_pool(), up, osd);
}
static bool has_shard(bool ec, const vector<int>& v, pg_shard_t osd) {
if (ec) {
return v.size() > (unsigned)osd.shard && v[osd.shard] == osd.osd;
} else {
return std::find(v.begin(), v.end(), osd.osd) != v.end();
}
}
bool needs_recovery() const;
bool needs_backfill() const;
/// clip calculated priority to reasonable range
inline int clamp_recovery_priority(int priority);
/// get log recovery reservation priority
unsigned get_recovery_priority();
/// get backfill reservation priority
unsigned get_backfill_priority();
void mark_clean(); ///< mark an active pg clean
void _change_recovery_force_mode(int new_mode, bool clear);
/// 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 = MAX(
info.history.last_epoch_clean ? info.history.last_epoch_clean :
info.history.epoch_pool_created,
oldest_map);
epoch_t end = MAX(
info.history.same_interval_since,
info.history.epoch_pool_created);
return make_pair(start, end);
}
void check_past_interval_bounds() const;
PastIntervals::PriorSet build_prior();