-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
OSD.h
2500 lines (2230 loc) · 68.7 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 "PG.h"
#include "msg/Dispatcher.h"
#include "common/Mutex.h"
#include "common/RWLock.h"
#include "common/Timer.h"
#include "common/WorkQueue.h"
#include "common/AsyncReserver.h"
#include "os/ObjectStore.h"
#include "OSDCap.h"
#include "auth/KeyRing.h"
#include "osd/ClassHandler.h"
#include "include/CompatSet.h"
#include "OpRequest.h"
#include <atomic>
#include <map>
#include <memory>
#include "include/memory.h"
using namespace std;
#include "include/unordered_map.h"
#include "common/shared_cache.hpp"
#include "common/simple_cache.hpp"
#include "common/sharedptr_registry.hpp"
#include "common/WeightedPriorityQueue.h"
#include "common/PrioritizedQueue.h"
#include "messages/MOSDOp.h"
#include "include/Spinlock.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_prepare_lat,
l_osd_op_r,
l_osd_op_r_outb,
l_osd_op_r_lat,
l_osd_op_r_process_lat,
l_osd_op_r_prepare_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_w_prepare_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_op_rw_prepare_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_rop,
l_osd_loadavg,
l_osd_buf,
l_osd_history_alloc_bytes,
l_osd_history_alloc_num,
l_osd_cached_crc,
l_osd_cached_crc_adjusted,
l_osd_pg,
l_osd_pg_primary,
l_osd_pg_replica,
l_osd_pg_stray,
l_osd_hb_to,
l_osd_map,
l_osd_mape,
l_osd_mape_dup,
l_osd_waiting_for_map,
l_osd_map_cache_hit,
l_osd_map_cache_miss,
l_osd_map_cache_miss_low,
l_osd_map_cache_miss_low_avg,
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 FuseStore;
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;
class LogChannel;
class CephContext;
typedef ceph::shared_ptr<ObjectStore::Sequencer> SequencerRef;
class MOSDOp;
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;
explicit 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 queued.
*/
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;
explicit PGScrub(epoch_t e) : epoch_queued(e) {}
ostream &operator<<(ostream &rhs) {
return rhs << "PGScrub";
}
};
struct PGSnapTrim {
epoch_t epoch_queued;
explicit PGSnapTrim(epoch_t e) : epoch_queued(e) {}
ostream &operator<<(ostream &rhs) {
return rhs << "PGSnapTrim";
}
};
struct PGRecovery {
epoch_t epoch_queued;
uint64_t reserved_pushes;
PGRecovery(epoch_t e, uint64_t reserved_pushes)
: epoch_queued(e), reserved_pushes(reserved_pushes) {}
ostream &operator<<(ostream &rhs) {
return rhs << "PGRecovery(epoch=" << epoch_queued
<< ", reserved_pushes: " << reserved_pushes << ")";
}
};
class PGQueueable {
typedef boost::variant<
OpRequestRef,
PGSnapTrim,
PGScrub,
PGRecovery
> 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()(const OpRequestRef &op);
void operator()(const PGSnapTrim &op);
void operator()(const PGScrub &op);
void operator()(const PGRecovery &op);
};
public:
// cppcheck-suppress noExplicitConstructor
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) {}
PGQueueable(
const PGRecovery &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) {}
const boost::optional<OpRequestRef> maybe_get_op() const {
const OpRequestRef *op = boost::get<OpRequestRef>(&qvariant);
return op ? OpRequestRef(*op) : boost::optional<OpRequestRef>();
}
uint64_t get_reserved_pushes() const {
const PGRecovery *op = boost::get<PGRecovery>(&qvariant);
return op ? op->reserved_pushes : 0;
}
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;
ceph::shared_ptr<ObjectStore::Sequencer> meta_osr;
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;
GenContextWQ recovery_gen_wq;
GenContextWQ op_gen_wq;
ClassHandler *&class_handler;
void dequeue_pg(PG *pg, list<OpRequestRef> *dequeued);
private:
// -- map epoch lower bound --
Mutex pg_epoch_lock;
multiset<epoch_t> pg_epochs;
map<spg_t,epoch_t> pg_epoch;
public:
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();
}
private:
// -- superblock --
Mutex publish_lock, pre_publish_lock; // pre-publish orders before publish
OSDSuperblock superblock;
public:
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; }
std::atomic<epoch_t> max_oldest_map;
private:
OSDMapRef osdmap;
public:
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 map
* 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.
*/
private:
OSDMapRef next_osdmap;
Cond pre_publish_cond;
public:
void pre_publish_map(OSDMapRef map) {
Mutex::Locker l(pre_publish_lock);
next_osdmap = std::move(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>::const_iterator i = map_reservations.cbegin();
if (i == map_reservations.cend() || 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,
const 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();
}
private:
// -- scrub scheduling --
Mutex sched_scrub_lock;
int scrubs_pending;
int scrubs_active;
public:
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,
double pool_scrub_min_interval = 0,
double pool_scrub_max_interval = 0, 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, double pool_scrub_min_interval,
double pool_scrub_max_interval, bool must) {
ScrubJob scrub(pgid, t, pool_scrub_min_interval, pool_scrub_max_interval,
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>::const_iterator iter = sched_scrub_pg.lower_bound(next);
if (iter == sched_scrub_pg.cend())
return false;
++iter;
if (iter == sched_scrub_pg.cend())
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);
private:
// -- 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, hobject_t::BitwiseComparator> agent_oids;
bool agent_active;
struct AgentThread : public Thread {
OSDService *osd;
explicit 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;
public:
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 (evict) op
void agent_start_evict_op() {
Mutex::Locker l(agent_lock);
++agent_ops;
}
/// note finish or cancellation of an async (evict) op
void agent_finish_evict_op() {
Mutex::Locker l(agent_lock);
assert(agent_ops > 0);
--agent_ops;
agent_cond.Signal();
}
/// 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 --;
}
private:
/// throttle promotion attempts
std::atomic_uint promote_probability_millis{1000}; ///< probability thousands. one word.
PromoteCounter promote_counter;
utime_t last_recalibrate;
unsigned long promote_max_objects, promote_max_bytes;
public:
bool promote_throttle() {
// NOTE: lockless! we rely on the probability being a single word.
promote_counter.attempt();
if ((unsigned)rand() % 1000 > promote_probability_millis)
return true; // yes throttle (no promote)
if (promote_max_objects &&
promote_counter.objects > promote_max_objects)
return true; // yes throttle
if (promote_max_bytes &&
promote_counter.bytes > promote_max_bytes)
return true; // yes throttle
return false; // no throttle (promote)
}
void promote_finish(uint64_t bytes) {
promote_counter.finish(bytes);
}
void promote_throttle_recalibrate();
// -- Objecter, for tiering 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
std::atomic_uint last_tid{0};
ceph_tid_t get_tid() {
return (ceph_tid_t)last_tid++;
}
// -- backfill_reservation --
Finisher reserver_finisher;
AsyncReserver<spg_t> local_reserver;
AsyncReserver<spg_t> remote_reserver;
// -- pg_temp --
private:
Mutex pg_temp_lock;
map<pg_t, vector<int> > pg_temp_wanted;
map<pg_t, vector<int> > pg_temp_pending;
void _sent_pg_temp();
public:
void queue_want_pg_temp(pg_t pgid, vector<int>& want);
void remove_want_pg_temp(pg_t pgid);
void requeue_pg_temp();
void send_pg_temp();
void queue_for_peering(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,
pg->get_scrub_priority(),
ceph_clock_now(cct),
entity_inst_t())));
}
// -- pg recovery and associated throttling --
Mutex recovery_lock;
list<pair<epoch_t, PGRef> > awaiting_throttle;
utime_t defer_recovery_until;
uint64_t recovery_ops_active;
uint64_t recovery_ops_reserved;
bool recovery_paused;
#ifdef DEBUG_RECOVERY_OIDS
map<spg_t, set<hobject_t, hobject_t::BitwiseComparator> > recovery_oids;
#endif
void start_recovery_op(PG *pg, const hobject_t& soid);
void finish_recovery_op(PG *pg, const hobject_t& soid, bool dequeue);
bool _recover_now(uint64_t *available_pushes);
void _maybe_queue_recovery();
void release_reserved_pushes(uint64_t pushes) {
Mutex::Locker l(recovery_lock);
assert(recovery_ops_reserved >= pushes);
recovery_ops_reserved -= pushes;
_maybe_queue_recovery();
}
void defer_recovery(float defer_for) {
defer_recovery_until = ceph_clock_now(cct);
defer_recovery_until += defer_for;
}
void pause_recovery() {
Mutex::Locker l(recovery_lock);
recovery_paused = true;
}
bool recovery_is_paused() {
Mutex::Locker l(recovery_lock);
return recovery_paused;
}
void unpause_recovery() {
Mutex::Locker l(recovery_lock);
recovery_paused = false;
_maybe_queue_recovery();
}
void kick_recovery_queue() {
Mutex::Locker l(recovery_lock);
_maybe_queue_recovery();
}
void clear_queued_recovery(PG *pg, bool front = false) {
Mutex::Locker l(recovery_lock);
for (list<pair<epoch_t, PGRef> >::iterator i = awaiting_throttle.begin();
i != awaiting_throttle.end();
) {
if (i->second.get() == pg) {
awaiting_throttle.erase(i++);
return;
} else {
++i;
}
}
}
// replay / delayed pg activation
void queue_for_recovery(PG *pg, bool front = false) {
Mutex::Locker l(recovery_lock);
if (front) {
awaiting_throttle.push_front(make_pair(pg->get_osdmap()->get_epoch(), pg));
} else {
awaiting_throttle.push_back(make_pair(pg->get_osdmap()->get_epoch(), pg));
}
_maybe_queue_recovery();
}
void _queue_for_recovery(
pair<epoch_t, PGRef> p, uint64_t reserved_pushes) {
assert(recovery_lock.is_locked_by_me());
pair<PGRef, PGQueueable> to_queue = make_pair(
p.second,
PGQueueable(
PGRecovery(p.first, reserved_pushes),
cct->_conf->osd_recovery_cost,
cct->_conf->osd_recovery_priority,
ceph_clock_now(cct),
entity_inst_t()));
op_wq.queue(to_queue);
}
// 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;