/
OSD.h
2365 lines (2103 loc) · 64.5 KB
/
OSD.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_OSD_H
#define CEPH_OSD_H
#include "boost/tuple/tuple.hpp"
#include "PG.h"
#include "msg/Dispatcher.h"
#include "common/Mutex.h"
#include "common/RWLock.h"
#include "common/Timer.h"
#include "common/WorkQueue.h"
#include "common/LogClient.h"
#include "common/AsyncReserver.h"
#include "common/ceph_context.h"
#include "os/ObjectStore.h"
#include "OSDCap.h"
#include "osd/ClassHandler.h"
#include "include/CompatSet.h"
#include "auth/KeyRing.h"
#include "messages/MOSDRepScrub.h"
#include "OpRequest.h"
#include <map>
#include <memory>
#include "include/memory.h"
using namespace std;
#include "include/unordered_map.h"
#include "include/unordered_set.h"
#include "Watch.h"
#include "common/shared_cache.hpp"
#include "common/simple_cache.hpp"
#include "common/sharedptr_registry.hpp"
#include "common/PrioritizedQueue.h"
#include "messages/MOSDOp.h"
#define CEPH_OSD_PROTOCOL 10 /* cluster internal */
enum {
l_osd_first = 10000,
l_osd_op_wip,
l_osd_op,
l_osd_op_inb,
l_osd_op_outb,
l_osd_op_lat,
l_osd_op_process_lat,
l_osd_op_r,
l_osd_op_r_outb,
l_osd_op_r_lat,
l_osd_op_r_process_lat,
l_osd_op_w,
l_osd_op_w_inb,
l_osd_op_w_rlat,
l_osd_op_w_lat,
l_osd_op_w_process_lat,
l_osd_op_rw,
l_osd_op_rw_inb,
l_osd_op_rw_outb,
l_osd_op_rw_rlat,
l_osd_op_rw_lat,
l_osd_op_rw_process_lat,
l_osd_sop,
l_osd_sop_inb,
l_osd_sop_lat,
l_osd_sop_w,
l_osd_sop_w_inb,
l_osd_sop_w_lat,
l_osd_sop_pull,
l_osd_sop_pull_lat,
l_osd_sop_push,
l_osd_sop_push_inb,
l_osd_sop_push_lat,
l_osd_pull,
l_osd_push,
l_osd_push_outb,
l_osd_push_in,
l_osd_push_inb,
l_osd_rop,
l_osd_loadavg,
l_osd_buf,
l_osd_pg,
l_osd_pg_primary,
l_osd_pg_replica,
l_osd_pg_stray,
l_osd_hb_to,
l_osd_hb_from,
l_osd_map,
l_osd_mape,
l_osd_mape_dup,
l_osd_waiting_for_map,
l_osd_stat_bytes,
l_osd_stat_bytes_used,
l_osd_stat_bytes_avail,
l_osd_copyfrom,
l_osd_tier_promote,
l_osd_tier_flush,
l_osd_tier_flush_fail,
l_osd_tier_try_flush,
l_osd_tier_try_flush_fail,
l_osd_tier_evict,
l_osd_tier_whiteout,
l_osd_tier_dirty,
l_osd_tier_clean,
l_osd_tier_delay,
l_osd_tier_proxy_read,
l_osd_tier_proxy_write,
l_osd_agent_wake,
l_osd_agent_skip,
l_osd_agent_flush,
l_osd_agent_evict,
l_osd_object_ctx_cache_hit,
l_osd_object_ctx_cache_total,
l_osd_op_cache_hit,
l_osd_tier_flush_lat,
l_osd_tier_promote_lat,
l_osd_tier_r_lat,
l_osd_last,
};
// RecoveryState perf counters
enum {
rs_first = 20000,
rs_initial_latency,
rs_started_latency,
rs_reset_latency,
rs_start_latency,
rs_primary_latency,
rs_peering_latency,
rs_backfilling_latency,
rs_waitremotebackfillreserved_latency,
rs_waitlocalbackfillreserved_latency,
rs_notbackfilling_latency,
rs_repnotrecovering_latency,
rs_repwaitrecoveryreserved_latency,
rs_repwaitbackfillreserved_latency,
rs_RepRecovering_latency,
rs_activating_latency,
rs_waitlocalrecoveryreserved_latency,
rs_waitremoterecoveryreserved_latency,
rs_recovering_latency,
rs_recovered_latency,
rs_clean_latency,
rs_active_latency,
rs_replicaactive_latency,
rs_stray_latency,
rs_getinfo_latency,
rs_getlog_latency,
rs_waitactingchange_latency,
rs_incomplete_latency,
rs_getmissing_latency,
rs_waitupthru_latency,
rs_last,
};
class Messenger;
class Message;
class MonClient;
class PerfCounters;
class ObjectStore;
class OSDMap;
class MLog;
class MClass;
class MOSDPGMissing;
class Objecter;
class Watch;
class Notification;
class ReplicatedPG;
class AuthAuthorizeHandlerRegistry;
class OpsFlightSocketHook;
class HistoricOpsSocketHook;
class TestOpsSocketHook;
struct C_CompleteSplits;
typedef ceph::shared_ptr<ObjectStore::Sequencer> SequencerRef;
class DeletingState {
Mutex lock;
Cond cond;
enum {
QUEUED,
CLEARING_DIR,
CLEARING_WAITING,
DELETING_DIR,
DELETED_DIR,
CANCELED,
} status;
bool stop_deleting;
public:
const spg_t pgid;
const PGRef old_pg_state;
DeletingState(const pair<spg_t, PGRef> &in) :
lock("DeletingState::lock"), status(QUEUED), stop_deleting(false),
pgid(in.first), old_pg_state(in.second) {
}
/// transition status to CLEARING_WAITING
bool pause_clearing() {
Mutex::Locker l(lock);
assert(status == CLEARING_DIR);
if (stop_deleting) {
status = CANCELED;
cond.Signal();
return false;
}
status = CLEARING_WAITING;
return true;
} ///< @return false if we should cancel deletion
/// start or resume the clearing - transition the status to CLEARING_DIR
bool start_or_resume_clearing() {
Mutex::Locker l(lock);
assert(
status == QUEUED ||
status == DELETED_DIR ||
status == CLEARING_WAITING);
if (stop_deleting) {
status = CANCELED;
cond.Signal();
return false;
}
status = CLEARING_DIR;
return true;
} ///< @return false if we should cancel the deletion
/// transition status to CLEARING_DIR
bool resume_clearing() {
Mutex::Locker l(lock);
assert(status == CLEARING_WAITING);
if (stop_deleting) {
status = CANCELED;
cond.Signal();
return false;
}
status = CLEARING_DIR;
return true;
} ///< @return false if we should cancel deletion
/// transition status to deleting
bool start_deleting() {
Mutex::Locker l(lock);
assert(status == CLEARING_DIR);
if (stop_deleting) {
status = CANCELED;
cond.Signal();
return false;
}
status = DELETING_DIR;
return true;
} ///< @return false if we should cancel deletion
/// signal collection removal queued
void finish_deleting() {
Mutex::Locker l(lock);
assert(status == DELETING_DIR);
status = DELETED_DIR;
cond.Signal();
}
/// try to halt the deletion
bool try_stop_deletion() {
Mutex::Locker l(lock);
stop_deleting = true;
/**
* If we are in DELETING_DIR or CLEARING_DIR, there are in progress
* operations we have to wait for before continuing on. States
* CLEARING_WAITING and QUEUED indicate that the remover will check
* stop_deleting before queueing any further operations. CANCELED
* indicates that the remover has already halted. DELETED_DIR
* indicates that the deletion has been fully queueud.
*/
while (status == DELETING_DIR || status == CLEARING_DIR)
cond.Wait(lock);
return status != DELETED_DIR;
} ///< @return true if we don't need to recreate the collection
};
typedef ceph::shared_ptr<DeletingState> DeletingStateRef;
class OSD;
struct PGScrub {
epoch_t epoch_queued;
PGScrub(epoch_t e) : epoch_queued(e) {}
ostream &operator<<(ostream &rhs) {
return rhs << "PGScrub";
}
};
struct PGSnapTrim {
epoch_t epoch_queued;
PGSnapTrim(epoch_t e) : epoch_queued(e) {}
ostream &operator<<(ostream &rhs) {
return rhs << "PGSnapTrim";
}
};
class PGQueueable {
typedef boost::variant<
OpRequestRef,
PGSnapTrim,
PGScrub
> QVariant;
QVariant qvariant;
int cost;
unsigned priority;
utime_t start_time;
entity_inst_t owner;
struct RunVis : public boost::static_visitor<> {
OSD *osd;
PGRef &pg;
ThreadPool::TPHandle &handle;
RunVis(OSD *osd, PGRef &pg, ThreadPool::TPHandle &handle)
: osd(osd), pg(pg), handle(handle) {}
void operator()(OpRequestRef &op);
void operator()(PGSnapTrim &op);
void operator()(PGScrub &op);
};
public:
PGQueueable(OpRequestRef op)
: qvariant(op), cost(op->get_req()->get_cost()),
priority(op->get_req()->get_priority()),
start_time(op->get_req()->get_recv_stamp()),
owner(op->get_req()->get_source_inst())
{}
PGQueueable(
const PGSnapTrim &op, int cost, unsigned priority, utime_t start_time,
const entity_inst_t &owner)
: qvariant(op), cost(cost), priority(priority), start_time(start_time),
owner(owner) {}
PGQueueable(
const PGScrub &op, int cost, unsigned priority, utime_t start_time,
const entity_inst_t &owner)
: qvariant(op), cost(cost), priority(priority), start_time(start_time),
owner(owner) {}
boost::optional<OpRequestRef> maybe_get_op() {
OpRequestRef *op = boost::get<OpRequestRef>(&qvariant);
return op ? *op : boost::optional<OpRequestRef>();
}
void run(OSD *osd, PGRef &pg, ThreadPool::TPHandle &handle) {
RunVis v(osd, pg, handle);
boost::apply_visitor(v, qvariant);
}
unsigned get_priority() const { return priority; }
int get_cost() const { return cost; }
utime_t get_start_time() const { return start_time; }
entity_inst_t get_owner() const { return owner; }
};
class OSDService {
public:
OSD *osd;
CephContext *cct;
SharedPtrRegistry<spg_t, ObjectStore::Sequencer> osr_registry;
SharedPtrRegistry<spg_t, DeletingState> deleting_pgs;
const int whoami;
ObjectStore *&store;
LogClient &log_client;
LogChannelRef clog;
PGRecoveryStats &pg_recovery_stats;
private:
Messenger *&cluster_messenger;
Messenger *&client_messenger;
public:
PerfCounters *&logger;
PerfCounters *&recoverystate_perf;
MonClient *&monc;
ShardedThreadPool::ShardedWQ < pair <PGRef, PGQueueable> > &op_wq;
ThreadPool::BatchWorkQueue<PG> &peering_wq;
ThreadPool::WorkQueue<PG> &recovery_wq;
GenContextWQ recovery_gen_wq;
GenContextWQ op_gen_wq;
ClassHandler *&class_handler;
void dequeue_pg(PG *pg, list<OpRequestRef> *dequeued);
// -- map epoch lower bound --
Mutex pg_epoch_lock;
multiset<epoch_t> pg_epochs;
map<spg_t,epoch_t> pg_epoch;
void pg_add_epoch(spg_t pgid, epoch_t epoch) {
Mutex::Locker l(pg_epoch_lock);
map<spg_t,epoch_t>::iterator t = pg_epoch.find(pgid);
assert(t == pg_epoch.end());
pg_epoch[pgid] = epoch;
pg_epochs.insert(epoch);
}
void pg_update_epoch(spg_t pgid, epoch_t epoch) {
Mutex::Locker l(pg_epoch_lock);
map<spg_t,epoch_t>::iterator t = pg_epoch.find(pgid);
assert(t != pg_epoch.end());
pg_epochs.erase(pg_epochs.find(t->second));
t->second = epoch;
pg_epochs.insert(epoch);
}
void pg_remove_epoch(spg_t pgid) {
Mutex::Locker l(pg_epoch_lock);
map<spg_t,epoch_t>::iterator t = pg_epoch.find(pgid);
if (t != pg_epoch.end()) {
pg_epochs.erase(pg_epochs.find(t->second));
pg_epoch.erase(t);
}
}
epoch_t get_min_pg_epoch() {
Mutex::Locker l(pg_epoch_lock);
if (pg_epochs.empty())
return 0;
else
return *pg_epochs.begin();
}
// -- superblock --
Mutex publish_lock, pre_publish_lock; // pre-publish orders before publish
OSDSuperblock superblock;
OSDSuperblock get_superblock() {
Mutex::Locker l(publish_lock);
return superblock;
}
void publish_superblock(const OSDSuperblock &block) {
Mutex::Locker l(publish_lock);
superblock = block;
}
int get_nodeid() const { return whoami; }
OSDMapRef osdmap;
OSDMapRef get_osdmap() {
Mutex::Locker l(publish_lock);
return osdmap;
}
epoch_t get_osdmap_epoch() {
Mutex::Locker l(publish_lock);
return osdmap ? osdmap->get_epoch() : 0;
}
void publish_map(OSDMapRef map) {
Mutex::Locker l(publish_lock);
osdmap = map;
}
/*
* osdmap - current published amp
* next_osdmap - pre_published map that is about to be published.
*
* We use the next_osdmap to send messages and initiate connections,
* but only if the target is the same instance as the one in the map
* epoch the current user is working from (i.e., the result is
* equivalent to what is in next_osdmap).
*
* This allows the helpers to start ignoring osds that are about to
* go down, and let OSD::handle_osd_map()/note_down_osd() mark them
* down, without worrying about reopening connections from threads
* working from old maps.
*/
OSDMapRef next_osdmap;
Cond pre_publish_cond;
void pre_publish_map(OSDMapRef map) {
Mutex::Locker l(pre_publish_lock);
next_osdmap = map;
}
void activate_map();
/// map epochs reserved below
map<epoch_t, unsigned> map_reservations;
/// gets ref to next_osdmap and registers the epoch as reserved
OSDMapRef get_nextmap_reserved() {
Mutex::Locker l(pre_publish_lock);
if (!next_osdmap)
return OSDMapRef();
epoch_t e = next_osdmap->get_epoch();
map<epoch_t, unsigned>::iterator i =
map_reservations.insert(make_pair(e, 0)).first;
i->second++;
return next_osdmap;
}
/// releases reservation on map
void release_map(OSDMapRef osdmap) {
Mutex::Locker l(pre_publish_lock);
map<epoch_t, unsigned>::iterator i =
map_reservations.find(osdmap->get_epoch());
assert(i != map_reservations.end());
assert(i->second > 0);
if (--(i->second) == 0) {
map_reservations.erase(i);
}
pre_publish_cond.Signal();
}
/// blocks until there are no reserved maps prior to next_osdmap
void await_reserved_maps() {
Mutex::Locker l(pre_publish_lock);
assert(next_osdmap);
while (true) {
map<epoch_t, unsigned>::iterator i = map_reservations.begin();
if (i == map_reservations.end() || i->first >= next_osdmap->get_epoch()) {
break;
} else {
pre_publish_cond.Wait(pre_publish_lock);
}
}
}
private:
Mutex peer_map_epoch_lock;
map<int, epoch_t> peer_map_epoch;
public:
epoch_t get_peer_epoch(int p);
epoch_t note_peer_epoch(int p, epoch_t e);
void forget_peer_epoch(int p, epoch_t e);
void send_map(class MOSDMap *m, Connection *con);
void send_incremental_map(epoch_t since, Connection *con, OSDMapRef& osdmap);
MOSDMap *build_incremental_map_msg(epoch_t from, epoch_t to,
OSDSuperblock& superblock);
bool should_share_map(entity_name_t name, Connection *con, epoch_t epoch,
OSDMapRef& osdmap, const epoch_t *sent_epoch_p);
void share_map(entity_name_t name, Connection *con, epoch_t epoch,
OSDMapRef& osdmap, epoch_t *sent_epoch_p);
void share_map_peer(int peer, Connection *con,
OSDMapRef map = OSDMapRef());
ConnectionRef get_con_osd_cluster(int peer, epoch_t from_epoch);
pair<ConnectionRef,ConnectionRef> get_con_osd_hb(int peer, epoch_t from_epoch); // (back, front)
void send_message_osd_cluster(int peer, Message *m, epoch_t from_epoch);
void send_message_osd_cluster(Message *m, Connection *con) {
con->send_message(m);
}
void send_message_osd_cluster(Message *m, const ConnectionRef& con) {
con->send_message(m);
}
void send_message_osd_client(Message *m, Connection *con) {
con->send_message(m);
}
void send_message_osd_client(Message *m, const ConnectionRef& con) {
con->send_message(m);
}
entity_name_t get_cluster_msgr_name() {
return cluster_messenger->get_myname();
}
// -- scrub scheduling --
Mutex sched_scrub_lock;
int scrubs_pending;
int scrubs_active;
struct ScrubJob {
/// pg to be scrubbed
spg_t pgid;
/// a time scheduled for scrub. but the scrub could be delayed if system
/// load is too high or it fails to fall in the scrub hours
utime_t sched_time;
/// the hard upper bound of scrub time
utime_t deadline;
ScrubJob() {}
explicit ScrubJob(const spg_t& pg, const utime_t& timestamp, bool must = true);
/// order the jobs by sched_time
bool operator<(const ScrubJob& rhs) const;
};
set<ScrubJob> sched_scrub_pg;
/// @returns the scrub_reg_stamp used for unregister the scrub job
utime_t reg_pg_scrub(spg_t pgid, utime_t t, bool must) {
ScrubJob scrub(pgid, t, must);
Mutex::Locker l(sched_scrub_lock);
sched_scrub_pg.insert(scrub);
return scrub.sched_time;
}
void unreg_pg_scrub(spg_t pgid, utime_t t) {
Mutex::Locker l(sched_scrub_lock);
size_t removed = sched_scrub_pg.erase(ScrubJob(pgid, t));
assert(removed);
}
bool first_scrub_stamp(ScrubJob *out) {
Mutex::Locker l(sched_scrub_lock);
if (sched_scrub_pg.empty())
return false;
set<ScrubJob>::iterator iter = sched_scrub_pg.begin();
*out = *iter;
return true;
}
bool next_scrub_stamp(const ScrubJob& next,
ScrubJob *out) {
Mutex::Locker l(sched_scrub_lock);
if (sched_scrub_pg.empty())
return false;
set<ScrubJob>::iterator iter = sched_scrub_pg.lower_bound(next);
if (iter == sched_scrub_pg.end())
return false;
++iter;
if (iter == sched_scrub_pg.end())
return false;
*out = *iter;
return true;
}
bool can_inc_scrubs_pending();
bool inc_scrubs_pending();
void inc_scrubs_active(bool reserved);
void dec_scrubs_pending();
void dec_scrubs_active();
void reply_op_error(OpRequestRef op, int err);
void reply_op_error(OpRequestRef op, int err, eversion_t v, version_t uv);
void handle_misdirected_op(PG *pg, OpRequestRef op);
// -- agent shared state --
Mutex agent_lock;
Cond agent_cond;
map<uint64_t, set<PGRef> > agent_queue;
set<PGRef>::iterator agent_queue_pos;
bool agent_valid_iterator;
int agent_ops;
int flush_mode_high_count; //once have one pg with FLUSH_MODE_HIGH then flush objects with high speed
set<hobject_t> agent_oids;
bool agent_active;
struct AgentThread : public Thread {
OSDService *osd;
AgentThread(OSDService *o) : osd(o) {}
void *entry() {
osd->agent_entry();
return NULL;
}
} agent_thread;
bool agent_stop_flag;
Mutex agent_timer_lock;
SafeTimer agent_timer;
void agent_entry();
void agent_stop();
void _enqueue(PG *pg, uint64_t priority) {
if (!agent_queue.empty() &&
agent_queue.rbegin()->first < priority)
agent_valid_iterator = false; // inserting higher-priority queue
set<PGRef>& nq = agent_queue[priority];
if (nq.empty())
agent_cond.Signal();
nq.insert(pg);
}
void _dequeue(PG *pg, uint64_t old_priority) {
set<PGRef>& oq = agent_queue[old_priority];
set<PGRef>::iterator p = oq.find(pg);
assert(p != oq.end());
if (p == agent_queue_pos)
++agent_queue_pos;
oq.erase(p);
if (oq.empty()) {
if (agent_queue.rbegin()->first == old_priority)
agent_valid_iterator = false;
agent_queue.erase(old_priority);
}
}
/// enable agent for a pg
void agent_enable_pg(PG *pg, uint64_t priority) {
Mutex::Locker l(agent_lock);
_enqueue(pg, priority);
}
/// adjust priority for an enagled pg
void agent_adjust_pg(PG *pg, uint64_t old_priority, uint64_t new_priority) {
Mutex::Locker l(agent_lock);
assert(new_priority != old_priority);
_enqueue(pg, new_priority);
_dequeue(pg, old_priority);
}
/// disable agent for a pg
void agent_disable_pg(PG *pg, uint64_t old_priority) {
Mutex::Locker l(agent_lock);
_dequeue(pg, old_priority);
}
/// note start of an async (flush) op
void agent_start_op(const hobject_t& oid) {
Mutex::Locker l(agent_lock);
++agent_ops;
assert(agent_oids.count(oid) == 0);
agent_oids.insert(oid);
}
/// note finish or cancellation of an async (flush) op
void agent_finish_op(const hobject_t& oid) {
Mutex::Locker l(agent_lock);
assert(agent_ops > 0);
--agent_ops;
assert(agent_oids.count(oid) == 1);
agent_oids.erase(oid);
agent_cond.Signal();
}
/// check if we are operating on an object
bool agent_is_active_oid(const hobject_t& oid) {
Mutex::Locker l(agent_lock);
return agent_oids.count(oid);
}
/// get count of active agent ops
int agent_get_num_ops() {
Mutex::Locker l(agent_lock);
return agent_ops;
}
void agent_inc_high_count() {
Mutex::Locker l(agent_lock);
flush_mode_high_count ++;
}
void agent_dec_high_count() {
Mutex::Locker l(agent_lock);
flush_mode_high_count --;
}
// -- Objecter, for teiring reads/writes from/to other OSDs --
Objecter *objecter;
Finisher objecter_finisher;
// -- Watch --
Mutex watch_lock;
SafeTimer watch_timer;
uint64_t next_notif_id;
uint64_t get_next_id(epoch_t cur_epoch) {
Mutex::Locker l(watch_lock);
return (((uint64_t)cur_epoch) << 32) | ((uint64_t)(next_notif_id++));
}
// -- Backfill Request Scheduling --
Mutex backfill_request_lock;
SafeTimer backfill_request_timer;
// -- tids --
// for ops i issue
ceph_tid_t last_tid;
Mutex tid_lock;
ceph_tid_t get_tid() {
ceph_tid_t t;
tid_lock.Lock();
t = ++last_tid;
tid_lock.Unlock();
return t;
}
// -- backfill_reservation --
Finisher reserver_finisher;
AsyncReserver<spg_t> local_reserver;
AsyncReserver<spg_t> remote_reserver;
// -- pg_temp --
Mutex pg_temp_lock;
map<pg_t, vector<int> > pg_temp_wanted;
void queue_want_pg_temp(pg_t pgid, vector<int>& want);
void remove_want_pg_temp(pg_t pgid) {
Mutex::Locker l(pg_temp_lock);
pg_temp_wanted.erase(pgid);
}
void send_pg_temp();
void queue_for_peering(PG *pg);
bool queue_for_recovery(PG *pg);
void queue_for_snap_trim(PG *pg) {
op_wq.queue(
make_pair(
pg,
PGQueueable(
PGSnapTrim(pg->get_osdmap()->get_epoch()),
cct->_conf->osd_snap_trim_cost,
cct->_conf->osd_snap_trim_priority,
ceph_clock_now(cct),
entity_inst_t())));
}
void queue_for_scrub(PG *pg) {
op_wq.queue(
make_pair(
pg,
PGQueueable(
PGScrub(pg->get_osdmap()->get_epoch()),
cct->_conf->osd_scrub_cost,
cct->_conf->osd_scrub_priority,
ceph_clock_now(cct),
entity_inst_t())));
}
// osd map cache (past osd maps)
Mutex map_cache_lock;
SharedLRU<epoch_t, const OSDMap> map_cache;
SimpleLRU<epoch_t, bufferlist> map_bl_cache;
SimpleLRU<epoch_t, bufferlist> map_bl_inc_cache;
OSDMapRef try_get_map(epoch_t e);
OSDMapRef get_map(epoch_t e) {
OSDMapRef ret(try_get_map(e));
assert(ret);
return ret;
}
OSDMapRef add_map(OSDMap *o) {
Mutex::Locker l(map_cache_lock);
return _add_map(o);
}
OSDMapRef _add_map(OSDMap *o);
void add_map_bl(epoch_t e, bufferlist& bl) {
Mutex::Locker l(map_cache_lock);
return _add_map_bl(e, bl);
}
void pin_map_bl(epoch_t e, bufferlist &bl);
void _add_map_bl(epoch_t e, bufferlist& bl);
bool get_map_bl(epoch_t e, bufferlist& bl) {
Mutex::Locker l(map_cache_lock);
return _get_map_bl(e, bl);
}
bool _get_map_bl(epoch_t e, bufferlist& bl);
void add_map_inc_bl(epoch_t e, bufferlist& bl) {
Mutex::Locker l(map_cache_lock);
return _add_map_inc_bl(e, bl);
}
void pin_map_inc_bl(epoch_t e, bufferlist &bl);
void _add_map_inc_bl(epoch_t e, bufferlist& bl);
bool get_inc_map_bl(epoch_t e, bufferlist& bl);
void clear_map_bl_cache_pins(epoch_t e);
void need_heartbeat_peer_update();
void pg_stat_queue_enqueue(PG *pg);
void pg_stat_queue_dequeue(PG *pg);
void init();
void start_shutdown();
void shutdown();
// split
Mutex in_progress_split_lock;
map<spg_t, spg_t> pending_splits; // child -> parent
map<spg_t, set<spg_t> > rev_pending_splits; // parent -> [children]
set<spg_t> in_progress_splits; // child
void _start_split(spg_t parent, const set<spg_t> &children);
void start_split(spg_t parent, const set<spg_t> &children) {
Mutex::Locker l(in_progress_split_lock);
return _start_split(parent, children);
}
void mark_split_in_progress(spg_t parent, const set<spg_t> &pgs);
void complete_split(const set<spg_t> &pgs);
void cancel_pending_splits_for_parent(spg_t parent);
void _cancel_pending_splits_for_parent(spg_t parent);
bool splitting(spg_t pgid);
void expand_pg_num(OSDMapRef old_map,
OSDMapRef new_map);
void _maybe_split_pgid(OSDMapRef old_map,
OSDMapRef new_map,
spg_t pgid);
void init_splits_between(spg_t pgid, OSDMapRef frommap, OSDMapRef tomap);
// -- stats --
Mutex stat_lock;
osd_stat_t osd_stat;
void update_osd_stat(vector<int>& hb_peers);
osd_stat_t get_osd_stat() {
Mutex::Locker l(stat_lock);
return osd_stat;
}
// -- OSD Full Status --
Mutex full_status_lock;
enum s_names { NONE, NEAR, FULL } cur_state;
time_t last_msg;
double cur_ratio;
float get_full_ratio();
float get_nearfull_ratio();
void check_nearfull_warning(const osd_stat_t &stat);
bool check_failsafe_full();
bool too_full_for_backfill(double *ratio, double *max_ratio);
// -- epochs --
private:
mutable Mutex epoch_lock; // protects access to boot_epoch, up_epoch, bind_epoch
epoch_t boot_epoch; // _first_ epoch we were marked up (after this process started)
epoch_t up_epoch; // _most_recent_ epoch we were marked up
epoch_t bind_epoch; // epoch we last did a bind to new ip:ports
public:
/**
* Retrieve the boot_, up_, and bind_ epochs the OSD has set. The params
* can be NULL if you don't care about them.
*/
void retrieve_epochs(epoch_t *_boot_epoch, epoch_t *_up_epoch,
epoch_t *_bind_epoch) const;
/**
* Set the boot, up, and bind epochs. Any NULL params will not be set.
*/
void set_epochs(const epoch_t *_boot_epoch, const epoch_t *_up_epoch,
const epoch_t *_bind_epoch);
epoch_t get_boot_epoch() const {
epoch_t ret;
retrieve_epochs(&ret, NULL, NULL);
return ret;
}
epoch_t get_up_epoch() const {
epoch_t ret;
retrieve_epochs(NULL, &ret, NULL);
return ret;
}
epoch_t get_bind_epoch() const {
epoch_t ret;
retrieve_epochs(NULL, NULL, &ret);
return ret;
}
// -- stopping --
Mutex is_stopping_lock;
Cond is_stopping_cond;
enum {
NOT_STOPPING,
PREPARING_TO_STOP,
STOPPING } state;
bool is_stopping() {
Mutex::Locker l(is_stopping_lock);
return state == STOPPING;
}
bool is_preparing_to_stop() {
Mutex::Locker l(is_stopping_lock);
return state == PREPARING_TO_STOP;
}
bool prepare_to_stop();
void got_stop_ack();
#ifdef PG_DEBUG_REFS
Mutex pgid_lock;
map<spg_t, int> pgid_tracker;
map<spg_t, PG*> live_pgs;
void add_pgid(spg_t pgid, PG *pg) {
Mutex::Locker l(pgid_lock);
if (!pgid_tracker.count(pgid)) {
pgid_tracker[pgid] = 0;
live_pgs[pgid] = pg;
}
pgid_tracker[pgid]++;
}
void remove_pgid(spg_t pgid, PG *pg) {
Mutex::Locker l(pgid_lock);
assert(pgid_tracker.count(pgid));
assert(pgid_tracker[pgid] > 0);
pgid_tracker[pgid]--;
if (pgid_tracker[pgid] == 0) {
pgid_tracker.erase(pgid);
live_pgs.erase(pgid);
}
}
void dump_live_pgids() {
Mutex::Locker l(pgid_lock);
derr << "live pgids:" << dendl;
for (map<spg_t, int>::iterator i = pgid_tracker.begin();
i != pgid_tracker.end();
++i) {
derr << "\t" << *i << dendl;
live_pgs[i->first]->dump_live_ids();
}
}