-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMDSMonitor.cc
1127 lines (993 loc) · 32.4 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 "MDSMonitor.h"
#include "Monitor.h"
#include "MonitorStore.h"
#include "OSDMonitor.h"
#include "messages/MMDSMap.h"
#include "messages/MMDSBeacon.h"
#include "messages/MMDSLoadTargets.h"
#include "messages/MMonCommand.h"
#include "messages/MGenericMessage.h"
#include "common/Timer.h"
#include <sstream>
#include "common/config.h"
#define DOUT_SUBSYS mon
#undef dout_prefix
#define dout_prefix _prefix(mon, mdsmap)
static ostream& _prefix(Monitor *mon, MDSMap& mdsmap) {
return *_dout << "mon." << mon->name << "@" << mon->rank
<< (mon->is_starting() ? (const char*)"(starting)":(mon->is_leader() ? (const char*)"(leader)":(mon->is_peon() ? (const char*)"(peon)":(const char*)"(?\?)")))
<< ".mds e" << mdsmap.get_epoch() << " ";
}
// my methods
void MDSMonitor::print_map(MDSMap &m, int dbl)
{
dout(7) << "print_map\n";
m.print(*_dout);
*_dout << dendl;
}
void MDSMonitor::create_new_fs(MDSMap &m, int metadata_pool, int data_pool)
{
m.max_mds = g_conf.max_mds;
m.created = g_clock.now();
m.data_pg_pools.push_back(data_pool);
m.metadata_pg_pool = metadata_pool;
m.cas_pg_pool = CEPH_CASDATA_RULE;
m.compat = mdsmap_compat;
print_map(m);
}
// service methods
void MDSMonitor::create_initial(bufferlist& bl)
{
dout(10) << "create_initial" << dendl;
create_new_fs(pending_mdsmap, CEPH_METADATA_RULE, CEPH_DATA_RULE);
}
bool MDSMonitor::update_from_paxos()
{
version_t paxosv = paxos->get_version();
if (paxosv == mdsmap.epoch) return true;
assert(paxosv >= mdsmap.epoch);
dout(10) << "update_from_paxos paxosv " << paxosv
<< ", my e " << mdsmap.epoch << dendl;
// read and decode
mdsmap_bl.clear();
bool success = paxos->read(paxosv, mdsmap_bl);
assert(success);
dout(10) << "update_from_paxos got " << paxosv << dendl;
mdsmap.decode(mdsmap_bl);
// save as 'latest', too.
paxos->stash_latest(paxosv, mdsmap_bl);
// new map
dout(4) << "new map" << dendl;
print_map(mdsmap, 0);
check_subs();
return true;
}
void MDSMonitor::create_pending()
{
pending_mdsmap = mdsmap;
pending_mdsmap.epoch++;
dout(10) << "create_pending e" << pending_mdsmap.epoch << dendl;
}
void MDSMonitor::encode_pending(bufferlist &bl)
{
dout(10) << "encode_pending e" << pending_mdsmap.epoch << dendl;
pending_mdsmap.modified = g_clock.now();
//print_map(pending_mdsmap);
// apply to paxos
assert(paxos->get_version() + 1 == pending_mdsmap.epoch);
pending_mdsmap.encode(bl);
}
bool MDSMonitor::preprocess_query(PaxosServiceMessage *m)
{
dout(10) << "preprocess_query " << *m << " from " << m->get_orig_source_inst() << dendl;
switch (m->get_type()) {
case MSG_MDS_BEACON:
return preprocess_beacon((MMDSBeacon*)m);
case MSG_MON_COMMAND:
return preprocess_command((MMonCommand*)m);
case MSG_MDS_OFFLOAD_TARGETS:
return preprocess_offload_targets((MMDSLoadTargets*)m);
default:
assert(0);
m->put();
return true;
}
}
void MDSMonitor::_note_beacon(MMDSBeacon *m)
{
uint64_t gid = m->get_global_id();
version_t seq = m->get_seq();
dout(15) << "_note_beacon " << *m << " noting time" << dendl;
last_beacon[gid].stamp = g_clock.now();
last_beacon[gid].seq = seq;
}
bool MDSMonitor::preprocess_beacon(MMDSBeacon *m)
{
entity_addr_t addr = m->get_orig_source_inst().addr;
int state = m->get_state();
uint64_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();
if (!session)
goto out;
if (!session->caps.check_privileges(PAXOS_MDSMAP, MON_CAP_X)) {
dout(0) << "preprocess_beason got MMDSBeacon from entity with insufficient privileges "
<< session->caps << dendl;
goto out;
}
if (ceph_fsid_compare(&m->get_fsid(), &mon->monmap->fsid)) {
dout(0) << "preprocess_beacon on fsid " << m->get_fsid() << " != " << mon->monmap->fsid << dendl;
goto out;
}
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 out;
}
// 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 out;
}
// 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 out;
}
// 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" << dendl;
mon->send_reply(m, new MMDSMap(mon->monmap->fsid, &mdsmap));
goto out;
} 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 out;
}
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 ignore;
}
if (info.laggy()) {
_note_beacon(m);
return false; // no longer laggy, need to update map.
}
if (state == MDSMap::STATE_BOOT) {
// ignore, already booted.
goto out;
}
// 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 ignore;
}
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 ignore;
}
_note_beacon(m);
return false; // need to update map
}
ignore:
// note time and reply
_note_beacon(m);
mon->send_reply(m,
new MMDSBeacon(mon->monmap->fsid, m->get_global_id(), m->get_name(),
mdsmap.get_epoch(), state, seq));
// done
out:
m->put();
return true;
}
bool MDSMonitor::preprocess_offload_targets(MMDSLoadTargets* m)
{
dout(10) << "preprocess_offload_targets " << *m << " from " << m->get_orig_source() << dendl;
uint64_t gid;
// check privileges, ignore message if fails
MonSession *session = m->get_session();
if (!session)
goto done;
if (!session->caps.check_privileges(PAXOS_MDSMAP, 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:
m->put();
return true;
}
bool MDSMonitor::prepare_update(PaxosServiceMessage *m)
{
dout(7) << "prepare_update " << *m << dendl;
switch (m->get_type()) {
case MSG_MDS_BEACON:
return prepare_beacon((MMDSBeacon*)m);
case MSG_MON_COMMAND:
return prepare_command((MMonCommand*)m);
case MSG_MDS_OFFLOAD_TARGETS:
return prepare_offload_targets((MMDSLoadTargets*)m);
default:
assert(0);
m->put();
}
return true;
}
bool MDSMonitor::prepare_beacon(MMDSBeacon *m)
{
// -- 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;
uint64_t gid = m->get_global_id();
int state = m->get_state();
version_t seq = m->get_seq();
// boot?
if (state == MDSMap::STATE_BOOT) {
// 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()) {
if (mdsmap.find_by_name(info.standby_for_name))
info.standby_for_rank =
mdsmap.find_by_name(info.standby_for_name)->rank;
}
if (info.standby_for_rank >= 0 && !mdsmap.is_dne(info.standby_for_rank)) {
info.state = MDSMap::STATE_STANDBY_REPLAY;
}
// initialize the beacon timer
last_beacon[gid].stamp = g_clock.now();
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();
}
} else {
// state change
MDSMap::mds_info_t& info = pending_mdsmap.get_info_gid(gid);
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)) {
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 {
m->put();
return false;
}
} else if (m->get_standby_for_rank() >= 0 &&
!mdsmap.is_dne(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));
m->put();
return false;
}
} else {
info.state = state;
info.state_seq = seq;
}
}
dout(7) << "prepare_beacon pending map now:" << dendl;
print_map(pending_mdsmap);
paxos->wait_for_commit(new C_Updated(this, m));
return true;
}
bool MDSMonitor::prepare_offload_targets(MMDSLoadTargets *m)
{
uint64_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;
}
m->put();
return true;
}
bool MDSMonitor::should_propose(double& delay)
{
delay = 0.0;
return true;
}
void MDSMonitor::_updated(MMDSBeacon *m)
{
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(m, new MMDSMap(mon->monmap->fsid, &mdsmap));
}
m->put();
}
void MDSMonitor::committed()
{
tick();
}
enum health_status_t MDSMonitor::get_health(ostream &oss) const
{
return mdsmap.get_health(oss);
}
bool MDSMonitor::preprocess_command(MMonCommand *m)
{
int r = -1;
bufferlist rdata;
stringstream ss;
if (m->cmd.size() > 1) {
if (m->cmd[1] == "stat") {
ss << mdsmap;
r = 0;
}
else if (m->cmd[1] == "dump") {
MDSMap *p = &mdsmap;
if (m->cmd.size() > 2) {
epoch_t e = atoi(m->cmd[2].c_str());
bufferlist b;
mon->store->get_bl_sn(b,"mdsmap",e);
if (!b.length()) {
p = 0;
r = -ENOENT;
} else {
p = new MDSMap;
p->decode(b);
}
}
if (p) {
stringstream ds;
p->print(ds);
rdata.append(ds);
ss << "dumped mdsmap epoch " << p->get_epoch();
if (p != &mdsmap)
delete p;
r = 0;
}
}
else if (m->cmd[1] == "getmap") {
if (m->cmd.size() > 2) {
epoch_t e = atoi(m->cmd[2].c_str());
bufferlist b;
mon->store->get_bl_sn(b,"mdsmap",e);
if (!b.length()) {
r = -ENOENT;
} else {
MDSMap m;
m.decode(b);
m.encode(rdata);
ss << "got mdsmap epoch " << m.get_epoch();
}
} else {
mdsmap.encode(rdata);
ss << "got mdsmap epoch " << mdsmap.get_epoch();
}
r = 0;
}
else if (m->cmd[1] == "injectargs" && m->cmd.size() == 4) {
if (m->cmd[2] == "*") {
for (unsigned i=0; i<mdsmap.get_max_mds(); i++)
if (mdsmap.is_active(i))
mon->inject_args(mdsmap.get_inst(i), m->cmd[3]);
r = 0;
ss << "ok bcast";
} else {
errno = 0;
int who = strtol(m->cmd[2].c_str(), 0, 10);
if (!errno && who >= 0) {
if (mdsmap.is_up(who)) {
mon->inject_args(mdsmap.get_inst(who), m->cmd[3]);
r = 0;
ss << "ok";
} else {
ss << "mds" << who << " not up";
r = -ENOENT;
}
} else
ss << "specify mds number or *";
}
}
else if (m->cmd[1] == "tell") {
m->cmd.erase(m->cmd.begin()); //take out first two args; don't need them
m->cmd.erase(m->cmd.begin());
if (m->cmd[0] == "*") {
m->cmd.erase(m->cmd.begin()); //and now we're done with the target num
for (unsigned i = 0; i < mdsmap.get_max_mds(); ++i) {
if (mdsmap.is_active(i))
mon->send_command(mdsmap.get_inst(i), m->cmd, paxos->get_version());
}
} else {
errno = 0;
int who = strtol(m->cmd[0].c_str(), 0, 10);
m->cmd.erase(m->cmd.begin()); //done with target num now
if (!errno && who >= 0) {
if (mdsmap.is_up(who)) {
mon->send_command(mdsmap.get_inst(who), m->cmd, paxos->get_version());
r = 0;
ss << "ok";
} else {
ss << "mds" << who << " no up";
r = -ENOENT;
}
} else ss << "specify mds number or *";
}
}
else if (m->cmd[1] == "compat") {
if (m->cmd.size() >= 3) {
if (m->cmd[2] == "show") {
ss << mdsmap.compat;
r = 0;
} else if (m->cmd[2] == "help") {
ss << "mds compat <rm_compat|rm_ro_compat|rm_incompat> <id>";
r = 0;
}
} else {
ss << "mds compat <rm_compat|rm_ro_compat|rm_incompat> <id>";
r = 0;
}
}
}
if (r != -1) {
string rs;
getline(ss, rs);
mon->reply_command(m, r, rs, rdata, paxos->get_version());
return true;
} else
return false;
}
int MDSMonitor::fail_mds(std::ostream &ss, const std::string &arg)
{
std::string err;
int w = strict_strtol(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);
if (!mds_info) {
ss << "Can't find any MDS named '" << arg << "'";
return -ENOENT;
}
w = mds_info->rank;
}
if (pending_mdsmap.up.count(w)) {
uint64_t gid = pending_mdsmap.up[w];
if (pending_mdsmap.mds_info.count(gid)) {
utime_t until = g_clock.now();
until += g_conf.mds_blacklist_interval;
MDSMap::mds_info_t& info = pending_mdsmap.mds_info[pending_mdsmap.up[w]];
pending_mdsmap.last_failure_osd_epoch = mon->osdmon()->blacklist(info.addr, until);
mon->osdmon()->propose_pending();
pending_mdsmap.mds_info.erase(gid);
}
pending_mdsmap.up.erase(w);
pending_mdsmap.failed.insert(w);
ss << "failed mds" << w;
}
return 0;
}
int MDSMonitor::cluster_fail(std::ostream &ss)
{
dout(10) << "cluster_fail" << dendl;
if (!pending_mdsmap.test_flag(CEPH_MDSMAP_DOWN)) {
ss << "mdsmap must be marked DOWN first ('mds cluster_down')";
return -EPERM;
}
if (pending_mdsmap.up.size() && !mon->osdmon()->paxos->is_writeable()) {
ss << "osdmap not writeable, can't blacklist up mds's";
return -EAGAIN;
}
// --- reset the cluster map ---
if (pending_mdsmap.mds_info.size()) {
// blacklist all old mds's
utime_t until = g_clock.now();
until += g_conf.mds_blacklist_interval;
for (map<int32_t,uint64_t>::iterator p = pending_mdsmap.up.begin();
p != pending_mdsmap.up.end();
++p) {
MDSMap::mds_info_t& info = pending_mdsmap.mds_info[p->second];
dout(10) << " blacklisting gid " << p->second << " " << info.addr << dendl;
pending_mdsmap.last_failure_osd_epoch = mon->osdmon()->blacklist(info.addr, until);
}
mon->osdmon()->propose_pending();
}
pending_mdsmap.up.clear();
pending_mdsmap.failed.insert(pending_mdsmap.in.begin(),
pending_mdsmap.in.end());
pending_mdsmap.in.clear();
pending_mdsmap.mds_info.clear();
ss << "failed all mds cluster members";
return 0;
}
bool MDSMonitor::prepare_command(MMonCommand *m)
{
int r = -EINVAL;
stringstream ss;
bufferlist rdata;
if (m->cmd.size() > 1) {
if (m->cmd[1] == "stop" && m->cmd.size() > 2) {
int who = atoi(m->cmd[2].c_str());
if (mdsmap.is_active(who)) {
r = 0;
uint64_t gid = pending_mdsmap.up[who];
ss << "telling mds" << who << " " << pending_mdsmap.mds_info[gid].addr << " to stop";
pending_mdsmap.mds_info[gid].state = MDSMap::STATE_STOPPING;
} else {
r = -EEXIST;
ss << "mds" << who << " not active ("
<< ceph_mds_state_name(mdsmap.get_state(who)) << ")";
}
}
else if (m->cmd[1] == "set_max_mds" && m->cmd.size() > 2) {
pending_mdsmap.max_mds = atoi(m->cmd[2].c_str());
r = 0;
ss << "max_mds = " << pending_mdsmap.max_mds;
}
else if (m->cmd[1] == "setmap" && m->cmd.size() == 3) {
MDSMap map;
map.decode(m->get_data());
epoch_t e = atoi(m->cmd[2].c_str());
//if (ceph_fsid_compare(&map.get_fsid(), &mon->monmap->fsid) == 0) {
if (pending_mdsmap.epoch == e) {
map.epoch = pending_mdsmap.epoch; // make sure epoch is correct
pending_mdsmap = map;
string rs = "set mds map";
paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
return true;
} else
ss << "next mdsmap epoch " << pending_mdsmap.epoch << " != " << e;
//} else
//ss << "mdsmap fsid " << map.fsid << " does not match monitor fsid " << mon->monmap->fsid;
}
else if (m->cmd[1] == "set_state" && m->cmd.size() == 4) {
uint64_t gid = atoi(m->cmd[2].c_str());
int state = atoi(m->cmd[3].c_str());
if (!pending_mdsmap.is_dne_gid(gid)) {
MDSMap::mds_info_t& info = pending_mdsmap.get_info_gid(gid);
info.state = state;
stringstream ss;
ss << "set mds gid " << gid << " to state " << state << " " << ceph_mds_state_name(state);
string rs;
getline(ss, rs);
paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
return true;
}
}
else if (m->cmd[1] == "fail" && m->cmd.size() == 3) {
r = fail_mds(ss, m->cmd[2]);
}
else if (m->cmd[1] == "rm" && m->cmd.size() == 3) {
uint64_t gid = atoll(m->cmd[2].c_str());
pending_mdsmap.mds_info.erase(gid);
stringstream ss;
ss << "removed mds gid " << gid;
string rs;
getline(ss, rs);
paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
return true;
}
else if (m->cmd[1] == "rmfailed" && m->cmd.size() == 3) {
int w = atoi(m->cmd[2].c_str());
pending_mdsmap.failed.erase(w);
stringstream ss;
ss << "removed failed mds" << w;
string rs;
getline(ss, rs);
paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
return true;
}
else if (m->cmd[1] == "cluster_fail") {
r = cluster_fail(ss);
}
else if (m->cmd[1] == "cluster_down") {
if (pending_mdsmap.test_flag(CEPH_MDSMAP_DOWN)) {
ss << "mdsmap already marked DOWN";
r = -EPERM;
} else {
pending_mdsmap.set_flag(CEPH_MDSMAP_DOWN);
ss << "marked mdsmap DOWN";
r = 0;
}
}
else if (m->cmd[1] == "cluster_up") {
if (pending_mdsmap.test_flag(CEPH_MDSMAP_DOWN)) {
pending_mdsmap.clear_flag(CEPH_MDSMAP_DOWN);
ss << "unmarked mdsmap DOWN";
r = 0;
} else {
ss << "mdsmap not marked DOWN";
r = -EPERM;
}
}
else if (m->cmd[1] == "compat" && m->cmd.size() == 4) {
uint64_t f = atoll(m->cmd[3].c_str());
if (m->cmd[2] == "rm_compat") {
if (pending_mdsmap.compat.compat.contains(f)) {
ss << "removing compat feature " << f;
pending_mdsmap.compat.compat.remove(f);
r = 0;
} else {
ss << "compat feature " << f << " not present in " << pending_mdsmap.compat;
r = -ENOENT;
}
} else if (m->cmd[2] == "rm_incompat") {
if (pending_mdsmap.compat.incompat.contains(f)) {
ss << "removing incompat feature " << f;
pending_mdsmap.compat.incompat.remove(f);
r = 0;
} else {
ss << "incompat feature " << f << " not present in " << pending_mdsmap.compat;
r = -ENOENT;
}
}
} else if (m->cmd[1] == "newfs" && m->cmd.size() == 4) {
MDSMap newmap;
int metadata = atoi(m->cmd[2].c_str());
int data = atoi(m->cmd[3].c_str());
pending_mdsmap = newmap;
pending_mdsmap.epoch = mdsmap.epoch + 1;
create_new_fs(pending_mdsmap, metadata, data);
ss << "new fs with metadata pool " << metadata << " and data pool " << data;
string rs;
getline(ss, rs);
paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
return true;
}
}
if (r == -EINVAL)
ss << "unrecognized command";
string rs;
getline(ss, rs);
if (r >= 0) {
// success.. delay reply
paxos->wait_for_commit(new Monitor::C_Command(mon, m, r, rs, paxos->get_version()));
return true;
} else {
// reply immediately
mon->reply_command(m, r, rs, rdata, paxos->get_version());
return false;
}
}
void MDSMonitor::check_subs()
{
string type = "mdsmap";
xlist<Subscription*>::iterator p = mon->session_map.subs[type].begin();
while (!p.end()) {
Subscription *sub = *p;
++p;
check_sub(sub);
}
}
void MDSMonitor::check_sub(Subscription *sub)
{
if (sub->next <= mdsmap.get_epoch()) {
mon->messenger->send_message(new MMDSMap(mon->monmap->fsid, &mdsmap),
sub->session->inst);
if (sub->onetime)
mon->session_map.remove_sub(sub);
else
sub->next = mdsmap.get_epoch() + 1;
}
}
void MDSMonitor::tick()
{
// make sure mds's are still alive
// ...if i am an active leader
if (!paxos->is_active()) return;
update_from_paxos();
dout(10) << mdsmap << dendl;
bool do_propose = false;
if (!mon->is_leader()) return;
// expand mds cluster (add new nodes to @in)?
while (pending_mdsmap.get_num_mds() < pending_mdsmap.get_max_mds() &&
!pending_mdsmap.is_degraded()) {
int mds = 0;
string name;
while (pending_mdsmap.is_in(mds))
mds++;
uint64_t newgid = pending_mdsmap.find_unused_for(mds, name);
if (!newgid)
break;
MDSMap::mds_info_t& info = pending_mdsmap.mds_info[newgid];
dout(1) << "adding standby " << info.addr << " as mds" << mds << dendl;
info.rank = mds;
if (pending_mdsmap.stopped.count(mds)) {
info.state = MDSMap::STATE_STARTING;
pending_mdsmap.stopped.erase(mds);
} else
info.state = MDSMap::STATE_CREATING;
info.inc = ++pending_mdsmap.inc[mds];
pending_mdsmap.in.insert(mds);
pending_mdsmap.up[mds] = newgid;
do_propose = true;
}
// check beacon timestamps
utime_t now = g_clock.now();
utime_t cutoff = now;
cutoff -= g_conf.mds_beacon_grace;
// make sure last_beacon is fully populated
for (map<uint64_t,MDSMap::mds_info_t>::iterator p = pending_mdsmap.mds_info.begin();
p != pending_mdsmap.mds_info.end();
++p) {
if (last_beacon.count(p->first) == 0) {
const MDSMap::mds_info_t& info = p->second;
dout(10) << " adding " << p->second.addr << " mds" << info.rank << "." << info.inc
<< " " << ceph_mds_state_name(info.state)
<< " to last_beacon" << dendl;
last_beacon[p->first].stamp = g_clock.now();
last_beacon[p->first].seq = 0;
}
}
if (mon->osdmon()->paxos->is_writeable()) {
bool propose_osdmap = false;
map<uint64_t, beacon_info_t>::iterator p = last_beacon.begin();
while (p != last_beacon.end()) {
uint64_t gid = p->first;
utime_t since = p->second.stamp;
uint64_t seq = p->second.seq;
p++;
if (pending_mdsmap.mds_info.count(gid) == 0) {
// clean it out
last_beacon.erase(gid);
continue;
}
if (since >= cutoff && pending_mdsmap.mds_info[gid].standby_for_rank != MDSMap::MDS_STANDBY_ANY)
continue;
MDSMap::mds_info_t& info = pending_mdsmap.mds_info[gid];
if (since >= cutoff && info.standby_for_rank == MDSMap::MDS_STANDBY_ANY) {
/* this mds is not laggy, but has no rank assigned.
* See if we can find it somebody to shadow
*/
int gid = 0;
for (map<uint64_t,MDSMap::mds_info_t>::iterator i = pending_mdsmap.mds_info.begin();
i != pending_mdsmap.mds_info.end();
++i) {
if (i->second.rank >= 0) {
if ((gid = pending_mdsmap.find_standby_for(
i->second.rank, i->second.name))) {
dout(20) << "checking rank " << i->second.rank << dendl;
dout(20) << "follower gid" << gid << "has state"
<< ceph_mds_state_name(pending_mdsmap.get_info_gid(gid).state) << dendl;
if (pending_mdsmap.get_info_gid(gid).state == MDSMap::STATE_STANDBY_REPLAY) {
dout(20) << "skipping this MDS since it has a follower!" << dendl;
continue; // this MDS already has a standby
}
}
// hey, we found an MDS without a standby. Pair them!
info.standby_for_rank = i->second.rank;
dout(10) << "setting to shadow mds rank " << info.standby_for_rank << dendl;
info.state = MDSMap::STATE_STANDBY_REPLAY;
do_propose = true;
break;
}
}
continue;
}
dout(10) << "no beacon from " << gid << " " << info.addr << " mds" << info.rank << "." << info.inc
<< " " << ceph_mds_state_name(info.state)
<< " since " << since << dendl;
// are we in?
// and is there a non-laggy standby that can take over for us?
uint64_t sgid;
if (info.rank >= 0 &&
info.state != CEPH_MDS_STATE_STANDBY &&
(sgid = pending_mdsmap.find_replacement_for(info.rank, info.name)) != 0) {
MDSMap::mds_info_t& si = pending_mdsmap.mds_info[sgid];
dout(10) << " replacing " << gid << " " << info.addr << " mds" << info.rank << "." << info.inc
<< " " << ceph_mds_state_name(info.state)
<< " with " << sgid << "/" << si.name << " " << si.addr << dendl;
switch (info.state) {
case MDSMap::STATE_CREATING:
case MDSMap::STATE_STARTING:
si.state = info.state;
break;
case MDSMap::STATE_STANDBY_REPLAY:
case MDSMap::STATE_REPLAY:
case MDSMap::STATE_RESOLVE:
case MDSMap::STATE_RECONNECT:
case MDSMap::STATE_REJOIN:
case MDSMap::STATE_CLIENTREPLAY:
case MDSMap::STATE_ACTIVE:
case MDSMap::STATE_STOPPING:
si.state = MDSMap::STATE_REPLAY;
break;
default:
assert(0);
}
info.state_seq = seq;
si.rank = info.rank;
si.inc = ++pending_mdsmap.inc[info.rank];
pending_mdsmap.up[info.rank] = sgid;
if (si.state > 0)
pending_mdsmap.last_failure = pending_mdsmap.epoch;