]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | /* Metadata Server Monitor | |
16 | */ | |
17 | ||
18 | #ifndef CEPH_MDSMONITOR_H | |
19 | #define CEPH_MDSMONITOR_H | |
20 | ||
21 | #include <map> | |
22 | #include <set> | |
7c673cae FG |
23 | |
24 | #include "include/types.h" | |
28e407b8 | 25 | #include "PaxosFSMap.h" |
7c673cae FG |
26 | #include "PaxosService.h" |
27 | #include "msg/Messenger.h" | |
28 | #include "messages/MMDSBeacon.h" | |
11fdf7f2 | 29 | #include "CommandHandler.h" |
7c673cae | 30 | |
7c673cae FG |
31 | class FileSystemCommandHandler; |
32 | ||
11fdf7f2 | 33 | class MDSMonitor : public PaxosService, public PaxosFSMap, protected CommandHandler { |
7c673cae | 34 | public: |
522d829b TL |
35 | using clock = ceph::coarse_mono_clock; |
36 | using time = ceph::coarse_mono_time; | |
37 | ||
f67539c2 | 38 | MDSMonitor(Monitor &mn, Paxos &p, std::string service_name); |
7c673cae FG |
39 | |
40 | // service methods | |
41 | void create_initial() override; | |
f67539c2 | 42 | void get_store_prefixes(std::set<std::string>& s) const override; |
7c673cae FG |
43 | void update_from_paxos(bool *need_bootstrap) override; |
44 | void init() override; | |
f67539c2 | 45 | void create_pending() override; |
7c673cae FG |
46 | void encode_pending(MonitorDBStore::TransactionRef t) override; |
47 | // we don't require full versions; don't encode any. | |
48 | void encode_full(MonitorDBStore::TransactionRef t) override { } | |
11fdf7f2 | 49 | version_t get_trim_to() const override; |
7c673cae FG |
50 | |
51 | bool preprocess_query(MonOpRequestRef op) override; // true if processed. | |
52 | bool prepare_update(MonOpRequestRef op) override; | |
53 | bool should_propose(double& delay) override; | |
54 | ||
92f5a8d4 TL |
55 | bool should_print_status() const { |
56 | auto& fs = get_fsmap(); | |
57 | auto fs_count = fs.filesystem_count(); | |
58 | auto standby_count = fs.get_num_standby(); | |
59 | return fs_count > 0 || standby_count > 0; | |
60 | } | |
61 | ||
7c673cae FG |
62 | void on_active() override; |
63 | void on_restart() override; | |
64 | ||
65 | void check_subs(); | |
66 | void check_sub(Subscription *sub); | |
67 | ||
f67539c2 TL |
68 | void dump_info(ceph::Formatter *f); |
69 | int print_nodes(ceph::Formatter *f); | |
7c673cae FG |
70 | |
71 | /** | |
f67539c2 | 72 | * Return true if a blocklist was done (i.e. OSD propose needed) |
7c673cae | 73 | */ |
1adf2230 | 74 | bool fail_mds_gid(FSMap &fsmap, mds_gid_t gid); |
7c673cae | 75 | |
f67539c2 | 76 | bool is_leader() const override { return mon.is_leader(); } |
28e407b8 AA |
77 | |
78 | protected: | |
9f95a23c TL |
79 | using mds_info_t = MDSMap::mds_info_t; |
80 | ||
7c673cae | 81 | // my helpers |
11fdf7f2 TL |
82 | template<int dblV = 7> |
83 | void print_map(const FSMap &m); | |
7c673cae FG |
84 | |
85 | void _updated(MonOpRequestRef op); | |
86 | ||
87 | void _note_beacon(class MMDSBeacon *m); | |
88 | bool preprocess_beacon(MonOpRequestRef op); | |
89 | bool prepare_beacon(MonOpRequestRef op); | |
90 | ||
91 | bool preprocess_offload_targets(MonOpRequestRef op); | |
92 | bool prepare_offload_targets(MonOpRequestRef op); | |
93 | ||
1adf2230 | 94 | int fail_mds(FSMap &fsmap, std::ostream &ss, |
f67539c2 | 95 | const std::string &arg, mds_info_t *failed_info); |
7c673cae FG |
96 | |
97 | bool preprocess_command(MonOpRequestRef op); | |
98 | bool prepare_command(MonOpRequestRef op); | |
99 | ||
7c673cae | 100 | int filesystem_command( |
1adf2230 | 101 | FSMap &fsmap, |
7c673cae FG |
102 | MonOpRequestRef op, |
103 | std::string const &prefix, | |
11fdf7f2 | 104 | const cmdmap_t& cmdmap, |
7c673cae FG |
105 | std::stringstream &ss); |
106 | ||
107 | // beacons | |
108 | struct beacon_info_t { | |
f67539c2 | 109 | ceph::mono_time stamp = ceph::mono_clock::zero(); |
1adf2230 AA |
110 | uint64_t seq = 0; |
111 | beacon_info_t() {} | |
f67539c2 | 112 | beacon_info_t(ceph::mono_time stamp, uint64_t seq) : stamp(stamp), seq(seq) {} |
7c673cae | 113 | }; |
f67539c2 | 114 | std::map<mds_gid_t, beacon_info_t> last_beacon; |
7c673cae | 115 | |
7c673cae FG |
116 | std::list<std::shared_ptr<FileSystemCommandHandler> > handlers; |
117 | ||
11fdf7f2 TL |
118 | bool maybe_promote_standby(FSMap& fsmap, Filesystem& fs); |
119 | bool maybe_resize_cluster(FSMap &fsmap, fs_cluster_id_t fscid); | |
9f95a23c TL |
120 | bool drop_mds(FSMap &fsmap, mds_gid_t gid, const mds_info_t* rep_info, bool* osd_propose); |
121 | bool check_health(FSMap &fsmap, bool* osd_propose); | |
7c673cae FG |
122 | void tick() override; // check state, take actions |
123 | ||
f67539c2 TL |
124 | int dump_metadata(const FSMap &fsmap, const std::string &who, ceph::Formatter *f, |
125 | std::ostream& err); | |
7c673cae | 126 | |
7c673cae | 127 | void update_metadata(mds_gid_t gid, const Metadata& metadata); |
1adf2230 | 128 | void remove_from_metadata(const FSMap &fsmap, MonitorDBStore::TransactionRef t); |
f67539c2 TL |
129 | int load_metadata(std::map<mds_gid_t, Metadata>& m); |
130 | void count_metadata(const std::string& field, ceph::Formatter *f); | |
131 | ||
c07f9fc5 | 132 | public: |
20effc67 | 133 | void print_fs_summary(std::ostream& out) { |
f67539c2 TL |
134 | get_fsmap().print_fs_summary(out); |
135 | } | |
136 | void count_metadata(const std::string& field, std::map<std::string,int> *out); | |
137 | void get_versions(std::map<std::string, std::list<std::string>> &versions); | |
7c673cae | 138 | |
f67539c2 | 139 | protected: |
7c673cae FG |
140 | // MDS daemon GID to latest health state from that GID |
141 | std::map<uint64_t, MDSHealth> pending_daemon_health; | |
142 | std::set<uint64_t> pending_daemon_health_rm; | |
143 | ||
f67539c2 | 144 | std::map<mds_gid_t, Metadata> pending_metadata; |
7c673cae | 145 | |
1adf2230 | 146 | mds_gid_t gid_from_arg(const FSMap &fsmap, const std::string &arg, std::ostream& err); |
7c673cae FG |
147 | |
148 | // When did the mon last call into our tick() method? Used for detecting | |
149 | // when the mon was not updating us for some period (e.g. during slow | |
150 | // election) to reset last_beacon timeouts | |
f67539c2 | 151 | ceph::mono_time last_tick = ceph::mono_clock::zero(); |
522d829b TL |
152 | |
153 | private: | |
154 | time last_fsmap_struct_flush = clock::zero(); | |
155 | bool check_fsmap_struct_version = true; | |
7c673cae FG |
156 | }; |
157 | ||
158 | #endif |