/
OSDMonitor.cc
13576 lines (12468 loc) · 423 KB
/
OSDMonitor.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 <sage@newdream.net>
* Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
* Copyright (C) 2014 Red Hat <contact@redhat.com>
*
* Author: Loic Dachary <loic@dachary.org>
*
* 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 <algorithm>
#include <boost/algorithm/string.hpp>
#include <experimental/iterator>
#include <locale>
#include <sstream>
#include "mon/OSDMonitor.h"
#include "mon/Monitor.h"
#include "mon/MDSMonitor.h"
#include "mon/MgrStatMonitor.h"
#include "mon/AuthMonitor.h"
#include "mon/ConfigKeyService.h"
#include "mon/MonitorDBStore.h"
#include "mon/Session.h"
#include "crush/CrushWrapper.h"
#include "crush/CrushTester.h"
#include "crush/CrushTreeDumper.h"
#include "messages/MOSDBeacon.h"
#include "messages/MOSDFailure.h"
#include "messages/MOSDMarkMeDown.h"
#include "messages/MOSDMarkMeDead.h"
#include "messages/MOSDFull.h"
#include "messages/MOSDMap.h"
#include "messages/MMonGetOSDMap.h"
#include "messages/MOSDBoot.h"
#include "messages/MOSDAlive.h"
#include "messages/MPoolOp.h"
#include "messages/MPoolOpReply.h"
#include "messages/MOSDPGCreate.h"
#include "messages/MOSDPGCreate2.h"
#include "messages/MOSDPGCreated.h"
#include "messages/MOSDPGTemp.h"
#include "messages/MOSDPGReadyToMerge.h"
#include "messages/MMonCommand.h"
#include "messages/MRemoveSnaps.h"
#include "messages/MOSDScrub.h"
#include "messages/MRoute.h"
#include "messages/MMonGetPurgedSnaps.h"
#include "messages/MMonGetPurgedSnapsReply.h"
#include "common/TextTable.h"
#include "common/Timer.h"
#include "common/ceph_argparse.h"
#include "common/perf_counters.h"
#include "common/strtol.h"
#include "common/numa.h"
#include "common/config.h"
#include "common/errno.h"
#include "erasure-code/ErasureCodePlugin.h"
#include "compressor/Compressor.h"
#include "common/Checksummer.h"
#include "include/compat.h"
#include "include/ceph_assert.h"
#include "include/stringify.h"
#include "include/util.h"
#include "common/cmdparse.h"
#include "include/str_list.h"
#include "include/str_map.h"
#include "include/scope_guard.h"
#include "auth/cephx/CephxKeyServer.h"
#include "osd/OSDCap.h"
#include "json_spirit/json_spirit_reader.h"
#include <boost/algorithm/string/predicate.hpp>
#define dout_subsys ceph_subsys_mon
static const string OSD_PG_CREATING_PREFIX("osd_pg_creating");
static const string OSD_METADATA_PREFIX("osd_metadata");
static const string OSD_SNAP_PREFIX("osd_snap");
/*
OSD snapshot metadata
---------------------
-- starting with mimic --
"removed_epoch_%llu_%08lx" % (pool, epoch)
-> interval_set<snapid_t>
"removed_snap_%llu_%016llx" % (pool, last_snap)
-> { first_snap, end_snap, epoch } (last_snap = end_snap - 1)
"purged_snap_%llu_%016llx" % (pool, last_snap)
-> { first_snap, end_snap, epoch } (last_snap = end_snap - 1)
- note that the {removed,purged}_snap put the last snap in they key so
that we can use forward iteration only to search for an epoch in an
interval. e.g., to test if epoch N is removed/purged, we'll find a key
>= N that either does or doesn't contain the given snap.
-- starting with octopus --
"purged_epoch_%08lx" % epoch
-> map<int64_t,interval_set<snapid_t>>
*/
namespace {
const uint32_t MAX_POOL_APPLICATIONS = 4;
const uint32_t MAX_POOL_APPLICATION_KEYS = 64;
const uint32_t MAX_POOL_APPLICATION_LENGTH = 128;
bool is_osd_writable(const OSDCapGrant& grant, const std::string* pool_name) {
// Note: this doesn't include support for the application tag match
if ((grant.spec.allow & OSD_CAP_W) != 0) {
auto& match = grant.match;
if (match.is_match_all()) {
return true;
} else if (pool_name != nullptr &&
!match.pool_namespace.pool_name.empty() &&
match.pool_namespace.pool_name == *pool_name) {
return true;
}
}
return false;
}
bool is_unmanaged_snap_op_permitted(CephContext* cct,
const KeyServer& key_server,
const EntityName& entity_name,
const MonCap& mon_caps,
const entity_addr_t& peer_socket_addr,
const std::string* pool_name)
{
typedef std::map<std::string, std::string> CommandArgs;
if (mon_caps.is_capable(
cct, CEPH_ENTITY_TYPE_MON,
entity_name, "osd",
"osd pool op unmanaged-snap",
(pool_name == nullptr ?
CommandArgs{} /* pool DNE, require unrestricted cap */ :
CommandArgs{{"poolname", *pool_name}}),
false, true, false,
peer_socket_addr)) {
return true;
}
AuthCapsInfo caps_info;
if (!key_server.get_service_caps(entity_name, CEPH_ENTITY_TYPE_OSD,
caps_info)) {
dout(10) << "unable to locate OSD cap data for " << entity_name
<< " in auth db" << dendl;
return false;
}
string caps_str;
if (caps_info.caps.length() > 0) {
auto p = caps_info.caps.cbegin();
try {
decode(caps_str, p);
} catch (const buffer::error &err) {
derr << "corrupt OSD cap data for " << entity_name << " in auth db"
<< dendl;
return false;
}
}
OSDCap osd_cap;
if (!osd_cap.parse(caps_str, nullptr)) {
dout(10) << "unable to parse OSD cap data for " << entity_name
<< " in auth db" << dendl;
return false;
}
// if the entity has write permissions in one or all pools, permit
// usage of unmanaged-snapshots
if (osd_cap.allow_all()) {
return true;
}
for (auto& grant : osd_cap.grants) {
if (grant.profile.is_valid()) {
for (auto& profile_grant : grant.profile_grants) {
if (is_osd_writable(profile_grant, pool_name)) {
return true;
}
}
} else if (is_osd_writable(grant, pool_name)) {
return true;
}
}
return false;
}
} // anonymous namespace
void LastEpochClean::Lec::report(ps_t ps, epoch_t last_epoch_clean)
{
if (epoch_by_pg.size() <= ps) {
epoch_by_pg.resize(ps + 1, 0);
}
const auto old_lec = epoch_by_pg[ps];
if (old_lec >= last_epoch_clean) {
// stale lec
return;
}
epoch_by_pg[ps] = last_epoch_clean;
if (last_epoch_clean < floor) {
floor = last_epoch_clean;
} else if (last_epoch_clean > floor) {
if (old_lec == floor) {
// probably should increase floor?
auto new_floor = std::min_element(std::begin(epoch_by_pg),
std::end(epoch_by_pg));
floor = *new_floor;
}
}
if (ps != next_missing) {
return;
}
for (; next_missing < epoch_by_pg.size(); next_missing++) {
if (epoch_by_pg[next_missing] == 0) {
break;
}
}
}
void LastEpochClean::remove_pool(uint64_t pool)
{
report_by_pool.erase(pool);
}
void LastEpochClean::report(const pg_t& pg, epoch_t last_epoch_clean)
{
auto& lec = report_by_pool[pg.pool()];
return lec.report(pg.ps(), last_epoch_clean);
}
epoch_t LastEpochClean::get_lower_bound(const OSDMap& latest) const
{
auto floor = latest.get_epoch();
for (auto& pool : latest.get_pools()) {
auto reported = report_by_pool.find(pool.first);
if (reported == report_by_pool.end()) {
return 0;
}
if (reported->second.next_missing < pool.second.get_pg_num()) {
return 0;
}
if (reported->second.floor < floor) {
floor = reported->second.floor;
}
}
return floor;
}
class C_UpdateCreatingPGs : public Context {
public:
OSDMonitor *osdmon;
utime_t start;
epoch_t epoch;
C_UpdateCreatingPGs(OSDMonitor *osdmon, epoch_t e) :
osdmon(osdmon), start(ceph_clock_now()), epoch(e) {}
void finish(int r) override {
if (r >= 0) {
utime_t end = ceph_clock_now();
dout(10) << "osdmap epoch " << epoch << " mapping took "
<< (end - start) << " seconds" << dendl;
osdmon->update_creating_pgs();
osdmon->check_pg_creates_subs();
}
}
};
#undef dout_prefix
#define dout_prefix _prefix(_dout, mon, osdmap)
static ostream& _prefix(std::ostream *_dout, Monitor *mon, const OSDMap& osdmap) {
return *_dout << "mon." << mon->name << "@" << mon->rank
<< "(" << mon->get_state_name()
<< ").osd e" << osdmap.get_epoch() << " ";
}
OSDMonitor::OSDMonitor(
CephContext *cct,
Monitor *mn,
Paxos *p,
const string& service_name)
: PaxosService(mn, p, service_name),
cct(cct),
inc_osd_cache(g_conf()->mon_osd_cache_size),
full_osd_cache(g_conf()->mon_osd_cache_size),
has_osdmap_manifest(false),
mapper(mn->cct, &mn->cpu_tp)
{}
bool OSDMonitor::_have_pending_crush()
{
return pending_inc.crush.length() > 0;
}
CrushWrapper &OSDMonitor::_get_stable_crush()
{
return *osdmap.crush;
}
void OSDMonitor::_get_pending_crush(CrushWrapper& newcrush)
{
bufferlist bl;
if (pending_inc.crush.length())
bl = pending_inc.crush;
else
osdmap.crush->encode(bl, CEPH_FEATURES_SUPPORTED_DEFAULT);
auto p = bl.cbegin();
newcrush.decode(p);
}
void OSDMonitor::create_initial()
{
dout(10) << "create_initial for " << mon->monmap->fsid << dendl;
OSDMap newmap;
bufferlist bl;
mon->store->get("mkfs", "osdmap", bl);
if (bl.length()) {
newmap.decode(bl);
newmap.set_fsid(mon->monmap->fsid);
} else {
newmap.build_simple(cct, 0, mon->monmap->fsid, 0);
}
newmap.set_epoch(1);
newmap.created = newmap.modified = ceph_clock_now();
// new clusters should sort bitwise by default.
newmap.set_flag(CEPH_OSDMAP_SORTBITWISE);
newmap.flags |=
CEPH_OSDMAP_RECOVERY_DELETES |
CEPH_OSDMAP_PURGED_SNAPDIRS |
CEPH_OSDMAP_PGLOG_HARDLIMIT;
newmap.full_ratio = g_conf()->mon_osd_full_ratio;
if (newmap.full_ratio > 1.0) newmap.full_ratio /= 100;
newmap.backfillfull_ratio = g_conf()->mon_osd_backfillfull_ratio;
if (newmap.backfillfull_ratio > 1.0) newmap.backfillfull_ratio /= 100;
newmap.nearfull_ratio = g_conf()->mon_osd_nearfull_ratio;
if (newmap.nearfull_ratio > 1.0) newmap.nearfull_ratio /= 100;
// new cluster should require latest by default
if (g_conf().get_val<bool>("mon_debug_no_require_octopus")) {
if (g_conf().get_val<bool>("mon_debug_no_require_nautilus")) {
derr << __func__ << " mon_debug_no_require_octopus and nautilus=true" << dendl;
newmap.require_osd_release = ceph_release_t::mimic;
} else {
derr << __func__ << " mon_debug_no_require_octopus=true" << dendl;
newmap.require_osd_release = ceph_release_t::nautilus;
}
} else {
newmap.require_osd_release = ceph_release_t::octopus;
ceph_release_t r = ceph_release_from_name(
g_conf()->mon_osd_initial_require_min_compat_client);
if (!r) {
ceph_abort_msg("mon_osd_initial_require_min_compat_client is not valid");
}
newmap.require_min_compat_client = r;
}
// encode into pending incremental
uint64_t features = newmap.get_encoding_features();
newmap.encode(pending_inc.fullmap,
features | CEPH_FEATURE_RESERVED);
pending_inc.full_crc = newmap.get_crc();
dout(20) << " full crc " << pending_inc.full_crc << dendl;
}
void OSDMonitor::get_store_prefixes(std::set<string>& s) const
{
s.insert(service_name);
s.insert(OSD_PG_CREATING_PREFIX);
s.insert(OSD_METADATA_PREFIX);
s.insert(OSD_SNAP_PREFIX);
}
void OSDMonitor::update_from_paxos(bool *need_bootstrap)
{
// we really don't care if the version has been updated, because we may
// have trimmed without having increased the last committed; yet, we may
// need to update the in-memory manifest.
load_osdmap_manifest();
version_t version = get_last_committed();
if (version == osdmap.epoch)
return;
ceph_assert(version > osdmap.epoch);
dout(15) << "update_from_paxos paxos e " << version
<< ", my e " << osdmap.epoch << dendl;
if (mapping_job) {
if (!mapping_job->is_done()) {
dout(1) << __func__ << " mapping job "
<< mapping_job.get() << " did not complete, "
<< mapping_job->shards << " left, canceling" << dendl;
mapping_job->abort();
}
mapping_job.reset();
}
load_health();
/*
* We will possibly have a stashed latest that *we* wrote, and we will
* always be sure to have the oldest full map in the first..last range
* due to encode_trim_extra(), which includes the oldest full map in the trim
* transaction.
*
* encode_trim_extra() does not however write the full map's
* version to 'full_latest'. This is only done when we are building the
* full maps from the incremental versions. But don't panic! We make sure
* that the following conditions find whichever full map version is newer.
*/
version_t latest_full = get_version_latest_full();
if (latest_full == 0 && get_first_committed() > 1)
latest_full = get_first_committed();
if (get_first_committed() > 1 &&
latest_full < get_first_committed()) {
// the monitor could be just sync'ed with its peer, and the latest_full key
// is not encoded in the paxos commits in encode_pending(), so we need to
// make sure we get it pointing to a proper version.
version_t lc = get_last_committed();
version_t fc = get_first_committed();
dout(10) << __func__ << " looking for valid full map in interval"
<< " [" << fc << ", " << lc << "]" << dendl;
latest_full = 0;
for (version_t v = lc; v >= fc; v--) {
string full_key = "full_" + stringify(v);
if (mon->store->exists(get_service_name(), full_key)) {
dout(10) << __func__ << " found latest full map v " << v << dendl;
latest_full = v;
break;
}
}
ceph_assert(latest_full > 0);
auto t(std::make_shared<MonitorDBStore::Transaction>());
put_version_latest_full(t, latest_full);
mon->store->apply_transaction(t);
dout(10) << __func__ << " updated the on-disk full map version to "
<< latest_full << dendl;
}
if ((latest_full > 0) && (latest_full > osdmap.epoch)) {
bufferlist latest_bl;
get_version_full(latest_full, latest_bl);
ceph_assert(latest_bl.length() != 0);
dout(7) << __func__ << " loading latest full map e" << latest_full << dendl;
osdmap = OSDMap();
osdmap.decode(latest_bl);
}
bufferlist bl;
if (!mon->store->get(OSD_PG_CREATING_PREFIX, "creating", bl)) {
auto p = bl.cbegin();
std::lock_guard<std::mutex> l(creating_pgs_lock);
creating_pgs.decode(p);
dout(7) << __func__ << " loading creating_pgs last_scan_epoch "
<< creating_pgs.last_scan_epoch
<< " with " << creating_pgs.pgs.size() << " pgs" << dendl;
} else {
dout(1) << __func__ << " missing creating pgs; upgrade from post-kraken?"
<< dendl;
}
// walk through incrementals
MonitorDBStore::TransactionRef t;
size_t tx_size = 0;
while (version > osdmap.epoch) {
bufferlist inc_bl;
int err = get_version(osdmap.epoch+1, inc_bl);
ceph_assert(err == 0);
ceph_assert(inc_bl.length());
dout(7) << "update_from_paxos applying incremental " << osdmap.epoch+1
<< dendl;
OSDMap::Incremental inc(inc_bl);
err = osdmap.apply_incremental(inc);
ceph_assert(err == 0);
if (!t)
t.reset(new MonitorDBStore::Transaction);
// Write out the full map for all past epochs. Encode the full
// map with the same features as the incremental. If we don't
// know, use the quorum features. If we don't know those either,
// encode with all features.
uint64_t f = inc.encode_features;
if (!f)
f = mon->get_quorum_con_features();
if (!f)
f = -1;
bufferlist full_bl;
osdmap.encode(full_bl, f | CEPH_FEATURE_RESERVED);
tx_size += full_bl.length();
bufferlist orig_full_bl;
get_version_full(osdmap.epoch, orig_full_bl);
if (orig_full_bl.length()) {
// the primary provided the full map
ceph_assert(inc.have_crc);
if (inc.full_crc != osdmap.crc) {
// This will happen if the mons were running mixed versions in
// the past or some other circumstance made the full encoded
// maps divergent. Reloading here will bring us back into
// sync with the primary for this and all future maps. OSDs
// will also be brought back into sync when they discover the
// crc mismatch and request a full map from a mon.
derr << __func__ << " full map CRC mismatch, resetting to canonical"
<< dendl;
dout(20) << __func__ << " my (bad) full osdmap:\n";
JSONFormatter jf(true);
jf.dump_object("osdmap", osdmap);
jf.flush(*_dout);
*_dout << "\nhexdump:\n";
full_bl.hexdump(*_dout);
*_dout << dendl;
osdmap = OSDMap();
osdmap.decode(orig_full_bl);
dout(20) << __func__ << " canonical full osdmap:\n";
JSONFormatter jf(true);
jf.dump_object("osdmap", osdmap);
jf.flush(*_dout);
*_dout << "\nhexdump:\n";
orig_full_bl.hexdump(*_dout);
*_dout << dendl;
}
} else {
ceph_assert(!inc.have_crc);
put_version_full(t, osdmap.epoch, full_bl);
}
put_version_latest_full(t, osdmap.epoch);
// share
dout(1) << osdmap << dendl;
if (osdmap.epoch == 1) {
t->erase("mkfs", "osdmap");
}
if (tx_size > g_conf()->mon_sync_max_payload_size*2) {
mon->store->apply_transaction(t);
t = MonitorDBStore::TransactionRef();
tx_size = 0;
}
for (const auto &osd_state : inc.new_state) {
if (osd_state.second & CEPH_OSD_UP) {
// could be marked up *or* down, but we're too lazy to check which
last_osd_report.erase(osd_state.first);
}
if (osd_state.second & CEPH_OSD_EXISTS) {
// could be created *or* destroyed, but we can safely drop it
osd_epochs.erase(osd_state.first);
}
}
}
if (t) {
mon->store->apply_transaction(t);
}
for (int o = 0; o < osdmap.get_max_osd(); o++) {
if (osdmap.is_out(o))
continue;
auto found = down_pending_out.find(o);
if (osdmap.is_down(o)) {
// populate down -> out map
if (found == down_pending_out.end()) {
dout(10) << " adding osd." << o << " to down_pending_out map" << dendl;
down_pending_out[o] = ceph_clock_now();
}
} else {
if (found != down_pending_out.end()) {
dout(10) << " removing osd." << o << " from down_pending_out map" << dendl;
down_pending_out.erase(found);
}
}
}
// XXX: need to trim MonSession connected with a osd whose id > max_osd?
check_osdmap_subs();
check_pg_creates_subs();
share_map_with_random_osd();
update_logger();
process_failures();
// make sure our feature bits reflect the latest map
update_msgr_features();
if (!mon->is_leader()) {
// will be called by on_active() on the leader, avoid doing so twice
start_mapping();
}
}
void OSDMonitor::start_mapping()
{
// initiate mapping job
if (mapping_job) {
dout(10) << __func__ << " canceling previous mapping_job " << mapping_job.get()
<< dendl;
mapping_job->abort();
}
if (!osdmap.get_pools().empty()) {
auto fin = new C_UpdateCreatingPGs(this, osdmap.get_epoch());
mapping_job = mapping.start_update(osdmap, mapper,
g_conf()->mon_osd_mapping_pgs_per_chunk);
dout(10) << __func__ << " started mapping job " << mapping_job.get()
<< " at " << fin->start << dendl;
mapping_job->set_finish_event(fin);
} else {
dout(10) << __func__ << " no pools, no mapping job" << dendl;
mapping_job = nullptr;
}
}
void OSDMonitor::update_msgr_features()
{
set<int> types;
types.insert((int)entity_name_t::TYPE_OSD);
types.insert((int)entity_name_t::TYPE_CLIENT);
types.insert((int)entity_name_t::TYPE_MDS);
types.insert((int)entity_name_t::TYPE_MON);
for (set<int>::iterator q = types.begin(); q != types.end(); ++q) {
uint64_t mask;
uint64_t features = osdmap.get_features(*q, &mask);
if ((mon->messenger->get_policy(*q).features_required & mask) != features) {
dout(0) << "crush map has features " << features << ", adjusting msgr requires" << dendl;
ceph::net::Policy p = mon->messenger->get_policy(*q);
p.features_required = (p.features_required & ~mask) | features;
mon->messenger->set_policy(*q, p);
}
}
}
void OSDMonitor::on_active()
{
update_logger();
if (mon->is_leader()) {
mon->clog->debug() << "osdmap " << osdmap;
if (!priority_convert) {
// Only do this once at start-up
convert_pool_priorities();
priority_convert = true;
}
} else {
list<MonOpRequestRef> ls;
take_all_failures(ls);
while (!ls.empty()) {
MonOpRequestRef op = ls.front();
op->mark_osdmon_event(__func__);
dispatch(op);
ls.pop_front();
}
}
start_mapping();
}
void OSDMonitor::on_restart()
{
last_osd_report.clear();
}
void OSDMonitor::on_shutdown()
{
dout(10) << __func__ << dendl;
if (mapping_job) {
dout(10) << __func__ << " canceling previous mapping_job " << mapping_job.get()
<< dendl;
mapping_job->abort();
}
// discard failure info, waiters
list<MonOpRequestRef> ls;
take_all_failures(ls);
ls.clear();
}
void OSDMonitor::update_logger()
{
dout(10) << "update_logger" << dendl;
mon->cluster_logger->set(l_cluster_num_osd, osdmap.get_num_osds());
mon->cluster_logger->set(l_cluster_num_osd_up, osdmap.get_num_up_osds());
mon->cluster_logger->set(l_cluster_num_osd_in, osdmap.get_num_in_osds());
mon->cluster_logger->set(l_cluster_osd_epoch, osdmap.get_epoch());
}
void OSDMonitor::create_pending()
{
pending_inc = OSDMap::Incremental(osdmap.epoch+1);
pending_inc.fsid = mon->monmap->fsid;
pending_metadata.clear();
pending_metadata_rm.clear();
pending_pseudo_purged_snaps.clear();
dout(10) << "create_pending e " << pending_inc.epoch << dendl;
// safety checks (this shouldn't really happen)
{
if (osdmap.backfillfull_ratio <= 0) {
pending_inc.new_backfillfull_ratio = g_conf()->mon_osd_backfillfull_ratio;
if (pending_inc.new_backfillfull_ratio > 1.0)
pending_inc.new_backfillfull_ratio /= 100;
dout(1) << __func__ << " setting backfillfull_ratio = "
<< pending_inc.new_backfillfull_ratio << dendl;
}
if (osdmap.full_ratio <= 0) {
pending_inc.new_full_ratio = g_conf()->mon_osd_full_ratio;
if (pending_inc.new_full_ratio > 1.0)
pending_inc.new_full_ratio /= 100;
dout(1) << __func__ << " setting full_ratio = "
<< pending_inc.new_full_ratio << dendl;
}
if (osdmap.nearfull_ratio <= 0) {
pending_inc.new_nearfull_ratio = g_conf()->mon_osd_nearfull_ratio;
if (pending_inc.new_nearfull_ratio > 1.0)
pending_inc.new_nearfull_ratio /= 100;
dout(1) << __func__ << " setting nearfull_ratio = "
<< pending_inc.new_nearfull_ratio << dendl;
}
}
// Rewrite CRUSH rule IDs if they are using legacy "ruleset"
// structure.
if (osdmap.crush->has_legacy_rule_ids()) {
CrushWrapper newcrush;
_get_pending_crush(newcrush);
// First, for all pools, work out which rule they really used
// by resolving ruleset to rule.
for (const auto &i : osdmap.get_pools()) {
const auto pool_id = i.first;
const auto &pool = i.second;
int new_rule_id = newcrush.find_rule(pool.crush_rule,
pool.type, pool.size);
dout(1) << __func__ << " rewriting pool "
<< osdmap.get_pool_name(pool_id) << " crush ruleset "
<< pool.crush_rule << " -> rule id " << new_rule_id << dendl;
if (pending_inc.new_pools.count(pool_id) == 0) {
pending_inc.new_pools[pool_id] = pool;
}
pending_inc.new_pools[pool_id].crush_rule = new_rule_id;
}
// Now, go ahead and renumber all the rules so that their
// rule_id field corresponds to their position in the array
auto old_to_new = newcrush.renumber_rules();
dout(1) << __func__ << " Rewrote " << old_to_new << " crush IDs:" << dendl;
for (const auto &i : old_to_new) {
dout(1) << __func__ << " " << i.first << " -> " << i.second << dendl;
}
pending_inc.crush.clear();
newcrush.encode(pending_inc.crush, mon->get_quorum_con_features());
}
}
creating_pgs_t
OSDMonitor::update_pending_pgs(const OSDMap::Incremental& inc,
const OSDMap& nextmap)
{
dout(10) << __func__ << dendl;
creating_pgs_t pending_creatings;
{
std::lock_guard<std::mutex> l(creating_pgs_lock);
pending_creatings = creating_pgs;
}
// check for new or old pools
if (pending_creatings.last_scan_epoch < inc.epoch) {
unsigned queued = 0;
queued += scan_for_creating_pgs(osdmap.get_pools(),
inc.old_pools,
inc.modified,
&pending_creatings);
queued += scan_for_creating_pgs(inc.new_pools,
inc.old_pools,
inc.modified,
&pending_creatings);
dout(10) << __func__ << " " << queued << " pools queued" << dendl;
for (auto deleted_pool : inc.old_pools) {
auto removed = pending_creatings.remove_pool(deleted_pool);
dout(10) << __func__ << " " << removed
<< " pg removed because containing pool deleted: "
<< deleted_pool << dendl;
last_epoch_clean.remove_pool(deleted_pool);
}
// pgmon updates its creating_pgs in check_osd_map() which is called by
// on_active() and check_osd_map() could be delayed if lease expires, so its
// creating_pgs could be stale in comparison with the one of osdmon. let's
// trim them here. otherwise, they will be added back after being erased.
unsigned removed = 0;
for (auto& pg : pending_created_pgs) {
dout(20) << __func__ << " noting created pg " << pg << dendl;
pending_creatings.created_pools.insert(pg.pool());
removed += pending_creatings.pgs.erase(pg);
}
pending_created_pgs.clear();
dout(10) << __func__ << " " << removed
<< " pgs removed because they're created" << dendl;
pending_creatings.last_scan_epoch = osdmap.get_epoch();
}
// filter out any pgs that shouldn't exist.
{
auto i = pending_creatings.pgs.begin();
while (i != pending_creatings.pgs.end()) {
if (!nextmap.pg_exists(i->first)) {
dout(10) << __func__ << " removing pg " << i->first
<< " which should not exist" << dendl;
i = pending_creatings.pgs.erase(i);
} else {
++i;
}
}
}
// process queue
unsigned max = std::max<int64_t>(1, g_conf()->mon_osd_max_creating_pgs);
const auto total = pending_creatings.pgs.size();
while (pending_creatings.pgs.size() < max &&
!pending_creatings.queue.empty()) {
auto p = pending_creatings.queue.begin();
int64_t poolid = p->first;
dout(10) << __func__ << " pool " << poolid
<< " created " << p->second.created
<< " modified " << p->second.modified
<< " [" << p->second.start << "-" << p->second.end << ")"
<< dendl;
int64_t n = std::min<int64_t>(max - pending_creatings.pgs.size(),
p->second.end - p->second.start);
ps_t first = p->second.start;
ps_t end = first + n;
for (ps_t ps = first; ps < end; ++ps) {
const pg_t pgid{ps, static_cast<uint64_t>(poolid)};
// NOTE: use the *current* epoch as the PG creation epoch so that the
// OSD does not have to generate a long set of PastIntervals.
pending_creatings.pgs.emplace(
pgid,
creating_pgs_t::pg_create_info(inc.epoch,
p->second.modified));
dout(10) << __func__ << " adding " << pgid << dendl;
}
p->second.start = end;
if (p->second.done()) {
dout(10) << __func__ << " done with queue for " << poolid << dendl;
pending_creatings.queue.erase(p);
} else {
dout(10) << __func__ << " pool " << poolid
<< " now [" << p->second.start << "-" << p->second.end << ")"
<< dendl;
}
}
dout(10) << __func__ << " queue remaining: " << pending_creatings.queue.size()
<< " pools" << dendl;
if (mon->monmap->min_mon_release >= ceph_release_t::octopus) {
// walk creating pgs' history and past_intervals forward
for (auto& i : pending_creatings.pgs) {
// this mirrors PG::start_peering_interval()
pg_t pgid = i.first;
// this is a bit imprecise, but sufficient?
struct min_size_predicate_t : public IsPGRecoverablePredicate {
const pg_pool_t *pi;
bool operator()(const set<pg_shard_t> &have) const {
return have.size() >= pi->min_size;
}
explicit min_size_predicate_t(const pg_pool_t *i) : pi(i) {}
} min_size_predicate(nextmap.get_pg_pool(pgid.pool()));
vector<int> up, acting;
int up_primary, acting_primary;
nextmap.pg_to_up_acting_osds(
pgid, &up, &up_primary, &acting, &acting_primary);
if (i.second.history.epoch_created == 0) {
// new pg entry, set it up
i.second.up = up;
i.second.acting = acting;
i.second.up_primary = up_primary;
i.second.acting_primary = acting_primary;
i.second.history = pg_history_t(i.second.create_epoch,
i.second.create_stamp);
dout(10) << __func__ << " pg " << pgid << " just added, "
<< " up " << i.second.up
<< " p " << i.second.up_primary
<< " acting " << i.second.acting
<< " p " << i.second.acting_primary
<< " history " << i.second.history
<< " past_intervals " << i.second.past_intervals
<< dendl;
} else {
std::stringstream debug;
if (PastIntervals::check_new_interval(
i.second.acting_primary, acting_primary,
i.second.acting, acting,
i.second.up_primary, up_primary,
i.second.up, up,
i.second.history.same_interval_since,
i.second.history.last_epoch_clean,
&nextmap,
&osdmap,
pgid,
min_size_predicate,
&i.second.past_intervals,
&debug)) {
epoch_t e = inc.epoch;
i.second.history.same_interval_since = e;
if (i.second.up != up) {
i.second.history.same_up_since = e;
}
if (i.second.acting_primary != acting_primary) {
i.second.history.same_primary_since = e;
}
if (pgid.is_split(
osdmap.get_pg_num(pgid.pool()),
nextmap.get_pg_num(pgid.pool()),
nullptr)) {
i.second.history.last_epoch_split = e;
}
dout(10) << __func__ << " pg " << pgid << " new interval,"
<< " up " << i.second.up << " -> " << up
<< " p " << i.second.up_primary << " -> " << up_primary
<< " acting " << i.second.acting << " -> " << acting
<< " p " << i.second.acting_primary << " -> "
<< acting_primary
<< " history " << i.second.history
<< " past_intervals " << i.second.past_intervals
<< dendl;
dout(20) << " debug: " << debug.str() << dendl;
i.second.up = up;
i.second.acting = acting;
i.second.up_primary = up_primary;
i.second.acting_primary = acting_primary;
}
}
}
}
dout(10) << __func__
<< " " << (pending_creatings.pgs.size() - total)
<< "/" << pending_creatings.pgs.size()
<< " pgs added from queued pools" << dendl;
return pending_creatings;
}
void OSDMonitor::maybe_prime_pg_temp()
{
bool all = false;
if (pending_inc.crush.length()) {
dout(10) << __func__ << " new crush map, all" << dendl;
all = true;
}
if (!pending_inc.new_up_client.empty()) {
dout(10) << __func__ << " new up osds, all" << dendl;
all = true;
}
// check for interesting OSDs
set<int> osds;