-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMDSMonitor.cc
2151 lines (1908 loc) · 66.7 KB
/
MDSMonitor.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <[email protected]>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include <sstream>
#include <boost/utility.hpp>
#include "MDSMonitor.h"
#include "Monitor.h"
#include "MonitorDBStore.h"
#include "OSDMonitor.h"
#include "common/strtol.h"
#include "common/ceph_argparse.h"
#include "common/perf_counters.h"
#include "common/Timer.h"
#include "common/config.h"
#include "common/cmdparse.h"
#include "messages/MMDSMap.h"
#include "messages/MMDSBeacon.h"
#include "messages/MMDSLoadTargets.h"
#include "messages/MMonCommand.h"
#include "messages/MGenericMessage.h"
#include "include/assert.h"
#include "include/str_list.h"
#include "mds/mdstypes.h"
#define dout_subsys ceph_subsys_mon
#undef dout_prefix
#define dout_prefix _prefix(_dout, mon, mdsmap)
static ostream& _prefix(std::ostream *_dout, Monitor *mon, MDSMap const& mdsmap) {
return *_dout << "mon." << mon->name << "@" << mon->rank
<< "(" << mon->get_state_name()
<< ").mds e" << mdsmap.get_epoch() << " ";
}
/*
* Specialized implementation of cmd_getval to allow us to parse
* out strongly-typedef'd types
*/
template<> bool cmd_getval(CephContext *cct, const cmdmap_t& cmdmap,
std::string k, mds_gid_t &val)
{
return cmd_getval(cct, cmdmap, k, (int64_t&)val);
}
template<> bool cmd_getval(CephContext *cct, const cmdmap_t& cmdmap,
std::string k, mds_rank_t &val)
{
return cmd_getval(cct, cmdmap, k, (int64_t&)val);
}
template<> bool cmd_getval(CephContext *cct, const cmdmap_t& cmdmap,
std::string k, MDSMap::DaemonState &val)
{
return cmd_getval(cct, cmdmap, k, (int64_t&)val);
}
static const string MDS_METADATA_PREFIX("mds_metadata");
// my methods
void MDSMonitor::print_map(MDSMap &m, int dbl)
{
dout(dbl) << "print_map\n";
m.print(*_dout);
*_dout << dendl;
}
void MDSMonitor::create_new_fs(MDSMap &m, const std::string &name, int metadata_pool, int data_pool)
{
m.enabled = true;
m.fs_name = name;
m.max_mds = g_conf->max_mds;
m.created = ceph_clock_now(g_ceph_context);
m.data_pools.insert(data_pool);
m.metadata_pool = metadata_pool;
m.cas_pool = -1;
m.compat = get_mdsmap_compat_set_default();
m.session_timeout = g_conf->mds_session_timeout;
m.session_autoclose = g_conf->mds_session_autoclose;
m.max_file_size = g_conf->mds_max_file_size;
print_map(m);
}
// service methods
void MDSMonitor::create_initial()
{
dout(10) << "create_initial" << dendl;
// Initial state is a disable MDS map
assert(mdsmap.get_enabled() == false);
}
void MDSMonitor::update_from_paxos(bool *need_bootstrap)
{
version_t version = get_last_committed();
if (version == mdsmap.epoch)
return;
assert(version >= mdsmap.epoch);
dout(10) << __func__ << " version " << version
<< ", my e " << mdsmap.epoch << dendl;
// read and decode
mdsmap_bl.clear();
int err = get_version(version, mdsmap_bl);
assert(err == 0);
assert(mdsmap_bl.length() > 0);
dout(10) << __func__ << " got " << version << dendl;
mdsmap.decode(mdsmap_bl);
// new map
dout(4) << "new map" << dendl;
print_map(mdsmap, 0);
check_subs();
update_logger();
}
void MDSMonitor::init()
{
(void)load_metadata(pending_metadata);
}
void MDSMonitor::create_pending()
{
pending_mdsmap = mdsmap;
pending_mdsmap.epoch++;
dout(10) << "create_pending e" << pending_mdsmap.epoch << dendl;
}
void MDSMonitor::encode_pending(MonitorDBStore::TransactionRef t)
{
dout(10) << "encode_pending e" << pending_mdsmap.epoch << dendl;
pending_mdsmap.modified = ceph_clock_now(g_ceph_context);
// print map iff 'debug mon = 30' or higher
print_map(pending_mdsmap, 30);
// apply to paxos
assert(get_last_committed() + 1 == pending_mdsmap.epoch);
bufferlist mdsmap_bl;
pending_mdsmap.encode(mdsmap_bl, mon->get_quorum_features());
/* put everything in the transaction */
put_version(t, pending_mdsmap.epoch, mdsmap_bl);
put_last_committed(t, pending_mdsmap.epoch);
// Encode MDSHealth data
for (std::map<uint64_t, MDSHealth>::iterator i = pending_daemon_health.begin();
i != pending_daemon_health.end(); ++i) {
bufferlist bl;
i->second.encode(bl);
t->put(MDS_HEALTH_PREFIX, stringify(i->first), bl);
}
for (std::set<uint64_t>::iterator i = pending_daemon_health_rm.begin();
i != pending_daemon_health_rm.end(); ++i) {
t->erase(MDS_HEALTH_PREFIX, stringify(*i));
}
pending_daemon_health_rm.clear();
remove_from_metadata(t);
}
version_t MDSMonitor::get_trim_to()
{
version_t floor = 0;
if (g_conf->mon_mds_force_trim_to > 0 &&
g_conf->mon_mds_force_trim_to < (int)get_last_committed()) {
floor = g_conf->mon_mds_force_trim_to;
dout(10) << __func__ << " explicit mon_mds_force_trim_to = "
<< floor << dendl;
}
unsigned max = g_conf->mon_max_mdsmap_epochs;
version_t last = get_last_committed();
if (last - get_first_committed() > max && floor < last - max)
return last - max;
return floor;
}
void MDSMonitor::update_logger()
{
dout(10) << "update_logger" << dendl;
mon->cluster_logger->set(l_cluster_num_mds_up, mdsmap.get_num_up_mds());
mon->cluster_logger->set(l_cluster_num_mds_in, mdsmap.get_num_in_mds());
mon->cluster_logger->set(l_cluster_num_mds_failed, mdsmap.get_num_failed_mds());
mon->cluster_logger->set(l_cluster_mds_epoch, mdsmap.get_epoch());
}
bool MDSMonitor::preprocess_query(MonOpRequestRef op)
{
op->mark_mdsmon_event(__func__);
PaxosServiceMessage *m = static_cast<PaxosServiceMessage*>(op->get_req());
dout(10) << "preprocess_query " << *m << " from " << m->get_orig_source_inst() << dendl;
switch (m->get_type()) {
case MSG_MDS_BEACON:
return preprocess_beacon(op);
case MSG_MON_COMMAND:
return preprocess_command(op);
case MSG_MDS_OFFLOAD_TARGETS:
return preprocess_offload_targets(op);
default:
assert(0);
return true;
}
}
void MDSMonitor::_note_beacon(MMDSBeacon *m)
{
mds_gid_t gid = mds_gid_t(m->get_global_id());
version_t seq = m->get_seq();
dout(15) << "_note_beacon " << *m << " noting time" << dendl;
last_beacon[gid].stamp = ceph_clock_now(g_ceph_context);
last_beacon[gid].seq = seq;
}
bool MDSMonitor::preprocess_beacon(MonOpRequestRef op)
{
op->mark_mdsmon_event(__func__);
MMDSBeacon *m = static_cast<MMDSBeacon*>(op->get_req());
MDSMap::DaemonState state = m->get_state();
mds_gid_t gid = m->get_global_id();
version_t seq = m->get_seq();
MDSMap::mds_info_t info;
// check privileges, ignore if fails
MonSession *session = m->get_session();
assert(session);
if (!session->is_capable("mds", MON_CAP_X)) {
dout(0) << "preprocess_beacon got MMDSBeacon from entity with insufficient privileges "
<< session->caps << dendl;
goto ignore;
}
if (m->get_fsid() != mon->monmap->fsid) {
dout(0) << "preprocess_beacon on fsid " << m->get_fsid() << " != " << mon->monmap->fsid << dendl;
goto ignore;
}
dout(12) << "preprocess_beacon " << *m
<< " from " << m->get_orig_source_inst()
<< " " << m->get_compat()
<< dendl;
// make sure the address has a port
if (m->get_orig_source_addr().get_port() == 0) {
dout(1) << " ignoring boot message without a port" << dendl;
goto ignore;
}
// check compat
if (!m->get_compat().writeable(mdsmap.compat)) {
dout(1) << " mds " << m->get_source_inst() << " can't write to mdsmap " << mdsmap.compat << dendl;
goto ignore;
}
// fw to leader?
if (!mon->is_leader())
return false;
if (pending_mdsmap.test_flag(CEPH_MDSMAP_DOWN)) {
dout(7) << " mdsmap DOWN flag set, ignoring mds " << m->get_source_inst() << " beacon" << dendl;
goto ignore;
}
// booted, but not in map?
if (pending_mdsmap.is_dne_gid(gid)) {
if (state != MDSMap::STATE_BOOT) {
dout(7) << "mds_beacon " << *m << " is not in mdsmap (state "
<< ceph_mds_state_name(state) << ")" << dendl;
mon->send_reply(op, new MMDSMap(mon->monmap->fsid, &mdsmap));
m->put();
return true;
} else {
return false; // not booted yet.
}
}
info = pending_mdsmap.get_info_gid(gid);
// old seq?
if (info.state_seq > seq) {
dout(7) << "mds_beacon " << *m << " has old seq, ignoring" << dendl;
goto ignore;
}
if (mdsmap.get_epoch() != m->get_last_epoch_seen()) {
dout(10) << "mds_beacon " << *m
<< " ignoring requested state, because mds hasn't seen latest map" << dendl;
goto reply;
}
if (info.laggy()) {
_note_beacon(m);
return false; // no longer laggy, need to update map.
}
if (state == MDSMap::STATE_BOOT) {
// ignore, already booted.
goto ignore;
}
// is there a state change here?
if (info.state != state) {
// legal state change?
if ((info.state == MDSMap::STATE_STANDBY ||
info.state == MDSMap::STATE_STANDBY_REPLAY ||
info.state == MDSMap::STATE_ONESHOT_REPLAY) && state > 0) {
dout(10) << "mds_beacon mds can't activate itself (" << ceph_mds_state_name(info.state)
<< " -> " << ceph_mds_state_name(state) << ")" << dendl;
goto reply;
}
if ((state == MDSMap::STATE_STANDBY || state == MDSMap::STATE_STANDBY_REPLAY)
&& info.rank != MDS_RANK_NONE)
{
dout(4) << "mds_beacon MDS can't go back into standby after taking rank: "
"held rank " << info.rank << " while requesting state "
<< ceph_mds_state_name(state) << dendl;
goto reply;
}
if (info.state == MDSMap::STATE_STANDBY &&
(state == MDSMap::STATE_STANDBY_REPLAY ||
state == MDSMap::STATE_ONESHOT_REPLAY) &&
(pending_mdsmap.is_degraded() ||
((m->get_standby_for_rank() >= 0) &&
pending_mdsmap.get_state(m->get_standby_for_rank()) < MDSMap::STATE_ACTIVE))) {
dout(10) << "mds_beacon can't standby-replay mds." << m->get_standby_for_rank() << " at this time (cluster degraded, or mds not active)" << dendl;
dout(10) << "pending_mdsmap.is_degraded()==" << pending_mdsmap.is_degraded()
<< " rank state: " << ceph_mds_state_name(pending_mdsmap.get_state(m->get_standby_for_rank())) << dendl;
goto reply;
}
_note_beacon(m);
return false; // need to update map
}
// Comparing known daemon health with m->get_health()
// and return false (i.e. require proposal) if they
// do not match, to update our stored
if (!(pending_daemon_health[gid] == m->get_health())) {
dout(20) << __func__ << " health metrics for gid " << gid << " were updated" << dendl;
return false;
}
reply:
// note time and reply
_note_beacon(m);
mon->send_reply(op,
new MMDSBeacon(mon->monmap->fsid, m->get_global_id(), m->get_name(),
mdsmap.get_epoch(), state, seq));
return true;
ignore:
// I won't reply this beacon, drop it.
mon->no_reply(op);
return true;
}
bool MDSMonitor::preprocess_offload_targets(MonOpRequestRef op)
{
op->mark_mdsmon_event(__func__);
MMDSLoadTargets *m = static_cast<MMDSLoadTargets*>(op->get_req());
dout(10) << "preprocess_offload_targets " << *m << " from " << m->get_orig_source() << dendl;
mds_gid_t gid;
// check privileges, ignore message if fails
MonSession *session = m->get_session();
if (!session)
goto done;
if (!session->is_capable("mds", MON_CAP_X)) {
dout(0) << "preprocess_offload_targets got MMDSLoadTargets from entity with insufficient caps "
<< session->caps << dendl;
goto done;
}
gid = m->global_id;
if (mdsmap.mds_info.count(gid) &&
m->targets == mdsmap.mds_info[gid].export_targets)
goto done;
return false;
done:
return true;
}
bool MDSMonitor::prepare_update(MonOpRequestRef op)
{
op->mark_mdsmon_event(__func__);
PaxosServiceMessage *m = static_cast<PaxosServiceMessage*>(op->get_req());
dout(7) << "prepare_update " << *m << dendl;
switch (m->get_type()) {
case MSG_MDS_BEACON:
return prepare_beacon(op);
case MSG_MON_COMMAND:
return prepare_command(op);
case MSG_MDS_OFFLOAD_TARGETS:
return prepare_offload_targets(op);
default:
assert(0);
}
return true;
}
bool MDSMonitor::prepare_beacon(MonOpRequestRef op)
{
op->mark_mdsmon_event(__func__);
MMDSBeacon *m = static_cast<MMDSBeacon*>(op->get_req());
// -- this is an update --
dout(12) << "prepare_beacon " << *m << " from " << m->get_orig_source_inst() << dendl;
entity_addr_t addr = m->get_orig_source_inst().addr;
mds_gid_t gid = m->get_global_id();
MDSMap::DaemonState state = m->get_state();
version_t seq = m->get_seq();
// Ignore beacons if filesystem is disabled
if (!mdsmap.get_enabled()) {
dout(1) << "warning, MDS " << m->get_orig_source_inst() << " up but filesystem disabled" << dendl;
return false;
}
// Store health
dout(20) << __func__ << " got health from gid " << gid << " with " << m->get_health().metrics.size() << " metrics." << dendl;
pending_daemon_health[gid] = m->get_health();
// boot?
if (state == MDSMap::STATE_BOOT) {
// zap previous instance of this name?
if (g_conf->mds_enforce_unique_name) {
bool failed_mds = false;
while (mds_gid_t existing = pending_mdsmap.find_mds_gid_by_name(m->get_name())) {
if (!mon->osdmon()->is_writeable()) {
mon->osdmon()->wait_for_writeable(op, new C_RetryMessage(this, op));
return false;
}
fail_mds_gid(existing);
failed_mds = true;
}
if (failed_mds) {
assert(mon->osdmon()->is_writeable());
request_proposal(mon->osdmon());
}
}
// add
MDSMap::mds_info_t& info = pending_mdsmap.mds_info[gid];
info.global_id = gid;
info.name = m->get_name();
info.rank = -1;
info.addr = addr;
info.state = MDSMap::STATE_STANDBY;
info.state_seq = seq;
info.standby_for_rank = m->get_standby_for_rank();
info.standby_for_name = m->get_standby_for_name();
if (!info.standby_for_name.empty()) {
const MDSMap::mds_info_t *leaderinfo = mdsmap.find_by_name(info.standby_for_name);
if (leaderinfo && (leaderinfo->rank >= 0)) {
info.standby_for_rank =
mdsmap.find_by_name(info.standby_for_name)->rank;
if (mdsmap.is_followable(info.standby_for_rank)) {
info.state = MDSMap::STATE_STANDBY_REPLAY;
}
}
}
// initialize the beacon timer
last_beacon[gid].stamp = ceph_clock_now(g_ceph_context);
last_beacon[gid].seq = seq;
// new incompat?
if (!pending_mdsmap.compat.writeable(m->get_compat())) {
dout(10) << " mdsmap " << pending_mdsmap.compat << " can't write to new mds' " << m->get_compat()
<< ", updating mdsmap and killing old mds's"
<< dendl;
pending_mdsmap.compat = m->get_compat();
}
update_metadata(m->get_global_id(), m->get_sys_info());
} else {
// state change
MDSMap::mds_info_t& info = pending_mdsmap.get_info_gid(gid);
if (info.state == MDSMap::STATE_STOPPING && state != MDSMap::STATE_STOPPED ) {
// we can't transition to any other states from STOPPING
dout(0) << "got beacon for MDS in STATE_STOPPING, ignoring requested state change"
<< dendl;
_note_beacon(m);
return true;
}
if (info.laggy()) {
dout(10) << "prepare_beacon clearing laggy flag on " << addr << dendl;
info.clear_laggy();
}
dout(10) << "prepare_beacon mds." << info.rank
<< " " << ceph_mds_state_name(info.state)
<< " -> " << ceph_mds_state_name(state)
<< " standby_for_rank=" << m->get_standby_for_rank()
<< dendl;
if (state == MDSMap::STATE_STOPPED) {
pending_mdsmap.up.erase(info.rank);
pending_mdsmap.in.erase(info.rank);
pending_mdsmap.stopped.insert(info.rank);
pending_mdsmap.mds_info.erase(gid); // last! info is a ref into this map
last_beacon.erase(gid);
} else if (state == MDSMap::STATE_STANDBY_REPLAY) {
if (m->get_standby_for_rank() == MDSMap::MDS_STANDBY_NAME) {
/* convert name to rank. If we don't have it, do nothing. The
mds will stay in standby and keep requesting the state change */
dout(20) << "looking for mds " << m->get_standby_for_name()
<< " to STANDBY_REPLAY for" << dendl;
const MDSMap::mds_info_t *found_mds = NULL;
if ((found_mds = mdsmap.find_by_name(m->get_standby_for_name())) &&
(found_mds->rank >= 0) &&
mdsmap.is_followable(found_mds->rank)) {
info.standby_for_rank = found_mds->rank;
dout(10) <<" found mds " << m->get_standby_for_name()
<< "; it has rank " << info.standby_for_rank << dendl;
info.state = MDSMap::STATE_STANDBY_REPLAY;
info.state_seq = seq;
} else {
return false;
}
} else if (m->get_standby_for_rank() >= 0 &&
mdsmap.is_followable(m->get_standby_for_rank())) {
/* switch to standby-replay for this MDS*/
info.state = MDSMap::STATE_STANDBY_REPLAY;
info.state_seq = seq;
info.standby_for_rank = m->get_standby_for_rank();
} else { //it's a standby for anybody, and is already in the list
assert(pending_mdsmap.get_mds_info().count(info.global_id));
return false;
}
} else if (state == MDSMap::STATE_DAMAGED) {
if (!mon->osdmon()->is_writeable()) {
dout(4) << __func__ << ": DAMAGED from rank " << info.rank
<< " waiting for osdmon writeable to blacklist it" << dendl;
mon->osdmon()->wait_for_writeable(op, new C_RetryMessage(this, op));
return false;
}
// Record this MDS rank as damaged, so that other daemons
// won't try to run it.
dout(4) << __func__ << ": marking rank "
<< info.rank << " damaged" << dendl;
// Blacklist this MDS daemon
const utime_t until = ceph_clock_now(g_ceph_context);
pending_mdsmap.last_failure_osd_epoch = mon->osdmon()->blacklist(
info.addr, until);
request_proposal(mon->osdmon());
// Clear out daemon state and add rank to damaged list
pending_mdsmap.up.erase(info.rank);
pending_mdsmap.damaged.insert(info.rank);
last_beacon.erase(gid);
// Call erase() last because the `info` reference becomes invalid
// after we remove the instance from the map.
pending_mdsmap.mds_info.erase(gid);
// Respond to MDS, so that it knows it can continue to shut down
mon->send_reply(op, new MMDSBeacon(mon->monmap->fsid, m->get_global_id(),
m->get_name(), mdsmap.get_epoch(), state, seq));
} else if (state == MDSMap::STATE_DNE) {
if (!mon->osdmon()->is_writeable()) {
dout(4) << __func__ << ": DNE from rank " << info.rank
<< " waiting for osdmon writeable to blacklist it" << dendl;
mon->osdmon()->wait_for_writeable(op, new C_RetryMessage(this, op));
return false;
}
fail_mds_gid(gid);
assert(mon->osdmon()->is_writeable());
request_proposal(mon->osdmon());
// Respond to MDS, so that it knows it can continue to shut down
mon->send_reply(op, new MMDSBeacon(mon->monmap->fsid, m->get_global_id(),
m->get_name(), mdsmap.get_epoch(), state, seq));
} else {
info.state = state;
info.state_seq = seq;
}
}
dout(7) << "prepare_beacon pending map now:" << dendl;
print_map(pending_mdsmap);
wait_for_finished_proposal(op, new C_Updated(this, op));
return true;
}
bool MDSMonitor::prepare_offload_targets(MonOpRequestRef op)
{
op->mark_mdsmon_event(__func__);
MMDSLoadTargets *m = static_cast<MMDSLoadTargets*>(op->get_req());
mds_gid_t gid = m->global_id;
if (pending_mdsmap.mds_info.count(gid)) {
dout(10) << "prepare_offload_targets " << gid << " " << m->targets << dendl;
pending_mdsmap.mds_info[gid].export_targets = m->targets;
} else {
dout(10) << "prepare_offload_targets " << gid << " not in map" << dendl;
}
return true;
}
bool MDSMonitor::should_propose(double& delay)
{
// delegate to PaxosService to assess whether we should propose
return PaxosService::should_propose(delay);
}
void MDSMonitor::_updated(MonOpRequestRef op)
{
op->mark_mdsmon_event(__func__);
MMDSBeacon *m = static_cast<MMDSBeacon*>(op->get_req());
dout(10) << "_updated " << m->get_orig_source() << " " << *m << dendl;
mon->clog->info() << m->get_orig_source_inst() << " "
<< ceph_mds_state_name(m->get_state()) << "\n";
if (m->get_state() == MDSMap::STATE_STOPPED) {
// send the map manually (they're out of the map, so they won't get it automatic)
mon->send_reply(op, new MMDSMap(mon->monmap->fsid, &mdsmap));
} else {
mon->send_reply(op, new MMDSBeacon(mon->monmap->fsid,
m->get_global_id(),
m->get_name(),
mdsmap.get_epoch(),
m->get_state(),
m->get_seq()));
}
}
void MDSMonitor::on_active()
{
tick();
update_logger();
if (mon->is_leader())
mon->clog->info() << "mdsmap " << mdsmap << "\n";
}
void MDSMonitor::get_health(list<pair<health_status_t, string> >& summary,
list<pair<health_status_t, string> > *detail) const
{
mdsmap.get_health(summary, detail);
// For each MDS GID...
for (std::map<mds_gid_t, MDSMap::mds_info_t>::const_iterator i = mdsmap.mds_info.begin();
i != mdsmap.mds_info.end(); ++i) {
// Decode MDSHealth
bufferlist bl;
mon->store->get(MDS_HEALTH_PREFIX, stringify(i->first), bl);
if (!bl.length()) {
derr << "Missing health data for MDS " << i->first << dendl;
continue;
}
MDSHealth health;
bufferlist::iterator bl_i = bl.begin();
health.decode(bl_i);
for (std::list<MDSHealthMetric>::iterator j = health.metrics.begin(); j != health.metrics.end(); ++j) {
int const rank = i->second.rank;
std::ostringstream message;
message << "mds" << rank << ": " << j->message;
summary.push_back(std::make_pair(j->sev, message.str()));
if (detail) {
// There is no way for us to clealy associate detail entries with summary entries (#7192), so
// we duplicate the summary message in the detail string and tag the metadata on.
std::ostringstream detail_message;
detail_message << message.str();
if (j->metadata.size()) {
detail_message << "(";
std::map<std::string, std::string>::iterator k = j->metadata.begin();
while (k != j->metadata.end()) {
detail_message << k->first << ": " << k->second;
if (boost::next(k) != j->metadata.end()) {
detail_message << ", ";
}
++k;
}
detail_message << ")";
}
detail->push_back(std::make_pair(j->sev, detail_message.str()));
}
}
}
}
void MDSMonitor::dump_info(Formatter *f)
{
f->open_object_section("mdsmap");
mdsmap.dump(f);
f->close_section();
f->dump_unsigned("mdsmap_first_committed", get_first_committed());
f->dump_unsigned("mdsmap_last_committed", get_last_committed());
}
bool MDSMonitor::preprocess_command(MonOpRequestRef op)
{
op->mark_mdsmon_event(__func__);
MMonCommand *m = static_cast<MMonCommand*>(op->get_req());
int r = -1;
bufferlist rdata;
stringstream ss, ds;
map<string, cmd_vartype> cmdmap;
if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) {
// ss has reason for failure
string rs = ss.str();
mon->reply_command(op, -EINVAL, rs, rdata, get_last_committed());
return true;
}
string prefix;
cmd_getval(g_ceph_context, cmdmap, "prefix", prefix);
string format;
cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
boost::scoped_ptr<Formatter> f(Formatter::create(format));
MonSession *session = m->get_session();
if (!session) {
mon->reply_command(op, -EACCES, "access denied", rdata, get_last_committed());
return true;
}
if (prefix == "mds stat") {
if (f) {
f->open_object_section("mds_stat");
dump_info(f.get());
f->close_section();
f->flush(ds);
} else {
ds << mdsmap;
}
r = 0;
} else if (prefix == "mds dump") {
int64_t epocharg;
epoch_t epoch;
MDSMap *p = &mdsmap;
if (cmd_getval(g_ceph_context, cmdmap, "epoch", epocharg)) {
epoch = epocharg;
bufferlist b;
int err = get_version(epoch, b);
if (err == -ENOENT) {
p = 0;
r = -ENOENT;
} else {
assert(err == 0);
assert(b.length());
p = new MDSMap;
p->decode(b);
}
}
if (p) {
stringstream ds;
if (f != NULL) {
f->open_object_section("mdsmap");
p->dump(f.get());
f->close_section();
f->flush(ds);
r = 0;
} else {
p->print(ds);
r = 0;
}
if (r == 0) {
rdata.append(ds);
ss << "dumped mdsmap epoch " << p->get_epoch();
}
if (p != &mdsmap)
delete p;
}
} else if (prefix == "mds metadata") {
string who;
cmd_getval(g_ceph_context, cmdmap, "who", who);
if (!f)
f.reset(Formatter::create("json-pretty"));
f->open_object_section("mds_metadata");
r = dump_metadata(who, f.get(), ss);
f->close_section();
f->flush(ds);
} else if (prefix == "mds getmap") {
epoch_t e;
int64_t epocharg;
bufferlist b;
if (cmd_getval(g_ceph_context, cmdmap, "epoch", epocharg)) {
e = epocharg;
int err = get_version(e, b);
if (err == -ENOENT) {
r = -ENOENT;
} else {
assert(err == 0);
assert(b.length());
MDSMap mm;
mm.decode(b);
mm.encode(rdata, m->get_connection()->get_features());
ss << "got mdsmap epoch " << mm.get_epoch();
r = 0;
}
} else {
mdsmap.encode(rdata, m->get_connection()->get_features());
ss << "got mdsmap epoch " << mdsmap.get_epoch();
r = 0;
}
} else if (prefix == "mds tell") {
string whostr;
cmd_getval(g_ceph_context, cmdmap, "who", whostr);
vector<string>args_vec;
cmd_getval(g_ceph_context, cmdmap, "args", args_vec);
if (whostr == "*") {
r = -ENOENT;
const map<mds_gid_t, MDSMap::mds_info_t> mds_info = mdsmap.get_mds_info();
for (map<mds_gid_t, MDSMap::mds_info_t>::const_iterator i = mds_info.begin();
i != mds_info.end();
++i) {
m->cmd = args_vec;
mon->send_command(i->second.get_inst(), m->cmd);
r = 0;
}
if (r == -ENOENT) {
ss << "no mds active";
} else {
ss << "ok";
}
} else {
errno = 0;
long who_l = strtol(whostr.c_str(), 0, 10);
if (!errno && who_l >= 0) {
mds_rank_t who = mds_rank_t(who_l);
if (mdsmap.is_up(who)) {
m->cmd = args_vec;
mon->send_command(mdsmap.get_inst(who), m->cmd);
r = 0;
ss << "ok";
} else {
ss << "mds." << who << " not up";
r = -ENOENT;
}
} else ss << "specify mds number or *";
}
} else if (prefix == "mds compat show") {
if (f) {
f->open_object_section("mds_compat");
mdsmap.compat.dump(f.get());
f->close_section();
f->flush(ds);
} else {
ds << mdsmap.compat;
}
r = 0;
} else if (prefix == "fs ls") {
if (f) {
f->open_array_section("filesystems");
{
if (mdsmap.get_enabled()) {
f->open_object_section("filesystem");
{
f->dump_string("name", mdsmap.fs_name);
const string &md_pool_name = mon->osdmon()->osdmap.get_pool_name(mdsmap.metadata_pool);
/* Output both the names and IDs of pools, for use by
* humans and machines respectively */
f->dump_string("metadata_pool", md_pool_name);
f->dump_int("metadata_pool_id", mdsmap.metadata_pool);
f->open_array_section("data_pool_ids");
{
for (std::set<int64_t>::iterator dpi = mdsmap.data_pools.begin();
dpi != mdsmap.data_pools.end(); ++dpi) {
f->dump_int("data_pool_id", *dpi);
}
}
f->close_section();
f->open_array_section("data_pools");
{
for (std::set<int64_t>::iterator dpi = mdsmap.data_pools.begin();
dpi != mdsmap.data_pools.end(); ++dpi) {
const string &pool_name = mon->osdmon()->osdmap.get_pool_name(*dpi);
f->dump_string("data_pool", pool_name);
}
}
f->close_section();
}
f->close_section();
}
}
f->close_section();
f->flush(ds);
} else {
if (mdsmap.get_enabled()) {
const string &md_pool_name = mon->osdmon()->osdmap.get_pool_name(mdsmap.metadata_pool);
ds << "name: " << mdsmap.fs_name << ", metadata pool: " << md_pool_name << ", data pools: [";
for (std::set<int64_t>::iterator dpi = mdsmap.data_pools.begin();
dpi != mdsmap.data_pools.end(); ++dpi) {
const string &pool_name = mon->osdmon()->osdmap.get_pool_name(*dpi);
ds << pool_name << " ";
}
ds << "]" << std::endl;
} else {
ds << "No filesystems enabled" << std::endl;
}
}
r = 0;
}
if (r != -1) {
rdata.append(ds);
string rs;
getline(ss, rs);
mon->reply_command(op, r, rs, rdata, get_last_committed());
return true;
} else
return false;
}
void MDSMonitor::fail_mds_gid(mds_gid_t gid)
{
assert(pending_mdsmap.mds_info.count(gid));
MDSMap::mds_info_t& info = pending_mdsmap.mds_info[gid];
dout(10) << "fail_mds_gid " << gid << " mds." << info.name << " rank " << info.rank << dendl;
utime_t until = ceph_clock_now(g_ceph_context);
until += g_conf->mds_blacklist_interval;
pending_mdsmap.last_failure_osd_epoch = mon->osdmon()->blacklist(info.addr, until);
if (info.rank >= 0) {
if (info.state == MDSMap::STATE_CREATING) {
// If this gid didn't make it past CREATING, then forget
// the rank ever existed so that next time it's handed out
// to a gid it'll go back into CREATING.
pending_mdsmap.in.erase(info.rank);
} else {
// Put this rank into the failed list so that the next available STANDBY will
// pick it up.
pending_mdsmap.failed.insert(info.rank);
}
pending_mdsmap.up.erase(info.rank);
}
pending_mdsmap.mds_info.erase(gid);
last_beacon.erase(gid);
}
mds_gid_t MDSMonitor::gid_from_arg(const std::string& arg, std::ostream &ss)
{
std::string err;
unsigned long long rank_or_gid = strict_strtoll(arg.c_str(), 10, &err);
if (!err.empty()) {
// Try to interpret the arg as an MDS name
const MDSMap::mds_info_t *mds_info = mdsmap.find_by_name(arg);