]>
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> | |
23 | using namespace std; | |
24 | ||
25 | #include "include/types.h" | |
26 | #include "mds/FSMap.h" | |
27 | #include "mds/MDSMap.h" | |
28 | #include "PaxosService.h" | |
29 | #include "msg/Messenger.h" | |
30 | #include "messages/MMDSBeacon.h" | |
31 | ||
32 | class MMonCommand; | |
33 | class MMDSLoadTargets; | |
34 | class MMDSMap; | |
35 | class FileSystemCommandHandler; | |
36 | ||
37 | #define MDS_HEALTH_PREFIX "mds_health" | |
38 | ||
39 | class MDSMonitor : public PaxosService { | |
40 | public: | |
41 | MDSMonitor(Monitor *mn, Paxos *p, string service_name); | |
42 | ||
43 | // service methods | |
44 | void create_initial() override; | |
45 | void update_from_paxos(bool *need_bootstrap) override; | |
46 | void init() override; | |
47 | void create_pending() override; | |
48 | void encode_pending(MonitorDBStore::TransactionRef t) override; | |
49 | // we don't require full versions; don't encode any. | |
50 | void encode_full(MonitorDBStore::TransactionRef t) override { } | |
51 | version_t get_trim_to() override; | |
52 | ||
53 | bool preprocess_query(MonOpRequestRef op) override; // true if processed. | |
54 | bool prepare_update(MonOpRequestRef op) override; | |
55 | bool should_propose(double& delay) override; | |
56 | ||
57 | void on_active() override; | |
58 | void on_restart() override; | |
59 | ||
60 | void check_subs(); | |
61 | void check_sub(Subscription *sub); | |
62 | ||
63 | const FSMap &get_pending() const { return pending_fsmap; } | |
64 | const FSMap &get_fsmap() const { return fsmap; } | |
65 | void dump_info(Formatter *f); | |
66 | int print_nodes(Formatter *f); | |
67 | ||
68 | /** | |
69 | * Return true if a blacklist was done (i.e. OSD propose needed) | |
70 | */ | |
71 | bool fail_mds_gid(mds_gid_t gid); | |
72 | protected: | |
73 | // mds maps | |
74 | FSMap fsmap; // current | |
75 | FSMap pending_fsmap; // current + pending updates | |
76 | ||
77 | // my helpers | |
78 | void print_map(FSMap &m, int dbl=7); | |
79 | void update_logger(); | |
80 | ||
81 | void _updated(MonOpRequestRef op); | |
82 | ||
83 | void _note_beacon(class MMDSBeacon *m); | |
84 | bool preprocess_beacon(MonOpRequestRef op); | |
85 | bool prepare_beacon(MonOpRequestRef op); | |
86 | ||
87 | bool preprocess_offload_targets(MonOpRequestRef op); | |
88 | bool prepare_offload_targets(MonOpRequestRef op); | |
89 | ||
90 | void get_health(list<pair<health_status_t,string> >& summary, | |
91 | list<pair<health_status_t,string> > *detail, | |
92 | CephContext *cct) const override; | |
93 | int fail_mds(std::ostream &ss, const std::string &arg); | |
94 | ||
95 | bool preprocess_command(MonOpRequestRef op); | |
96 | bool prepare_command(MonOpRequestRef op); | |
97 | ||
98 | int parse_role( | |
99 | const std::string &role_str, | |
100 | mds_role_t *role, | |
101 | std::ostream &ss); | |
102 | ||
103 | void modify_legacy_filesystem( | |
104 | std::function<void(std::shared_ptr<Filesystem> )> fn); | |
105 | int legacy_filesystem_command( | |
106 | MonOpRequestRef op, | |
107 | std::string const &prefix, | |
108 | map<string, cmd_vartype> &cmdmap, | |
109 | std::stringstream &ss); | |
110 | int filesystem_command( | |
111 | MonOpRequestRef op, | |
112 | std::string const &prefix, | |
113 | map<string, cmd_vartype> &cmdmap, | |
114 | std::stringstream &ss); | |
115 | ||
116 | // beacons | |
117 | struct beacon_info_t { | |
118 | utime_t stamp; | |
119 | uint64_t seq; | |
120 | }; | |
121 | map<mds_gid_t, beacon_info_t> last_beacon; | |
122 | ||
123 | bool try_standby_replay( | |
124 | const MDSMap::mds_info_t& finfo, | |
125 | const Filesystem &leader_fs, | |
126 | const MDSMap::mds_info_t& ainfo); | |
127 | ||
128 | std::list<std::shared_ptr<FileSystemCommandHandler> > handlers; | |
129 | ||
130 | bool maybe_promote_standby(std::shared_ptr<Filesystem> fs); | |
131 | bool maybe_expand_cluster(std::shared_ptr<Filesystem> fs); | |
c07f9fc5 | 132 | void maybe_replace_gid(mds_gid_t gid, const MDSMap::mds_info_t& info, |
7c673cae FG |
133 | bool *mds_propose, bool *osd_propose); |
134 | void tick() override; // check state, take actions | |
135 | ||
136 | int dump_metadata(const string& who, Formatter *f, ostream& err); | |
137 | ||
7c673cae FG |
138 | void update_metadata(mds_gid_t gid, const Metadata& metadata); |
139 | void remove_from_metadata(MonitorDBStore::TransactionRef t); | |
140 | int load_metadata(map<mds_gid_t, Metadata>& m); | |
31f18b77 | 141 | void count_metadata(const string& field, Formatter *f); |
c07f9fc5 FG |
142 | public: |
143 | void count_metadata(const string& field, map<string,int> *out); | |
144 | protected: | |
7c673cae FG |
145 | |
146 | // MDS daemon GID to latest health state from that GID | |
147 | std::map<uint64_t, MDSHealth> pending_daemon_health; | |
148 | std::set<uint64_t> pending_daemon_health_rm; | |
149 | ||
150 | map<mds_gid_t, Metadata> pending_metadata; | |
151 | ||
152 | mds_gid_t gid_from_arg(const std::string& arg, std::ostream& err); | |
153 | ||
154 | // When did the mon last call into our tick() method? Used for detecting | |
155 | // when the mon was not updating us for some period (e.g. during slow | |
156 | // election) to reset last_beacon timeouts | |
157 | utime_t last_tick; | |
158 | }; | |
159 | ||
160 | #endif |