]> git.proxmox.com Git - ceph.git/blob - ceph/src/mon/MDSMonitor.h
c41246992d5c83c7402258ff91868ea2e077d44c
[ceph.git] / ceph / src / mon / MDSMonitor.h
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
24 #include "include/types.h"
25 #include "PaxosFSMap.h"
26 #include "PaxosService.h"
27 #include "msg/Messenger.h"
28 #include "messages/MMDSBeacon.h"
29 #include "CommandHandler.h"
30
31 class FileSystemCommandHandler;
32
33 class MDSMonitor : public PaxosService, public PaxosFSMap, protected CommandHandler {
34 public:
35 using clock = ceph::coarse_mono_clock;
36 using time = ceph::coarse_mono_time;
37
38 MDSMonitor(Monitor &mn, Paxos &p, std::string service_name);
39
40 // service methods
41 void create_initial() override;
42 void get_store_prefixes(std::set<std::string>& s) const override;
43 void update_from_paxos(bool *need_bootstrap) override;
44 void init() override;
45 void create_pending() override;
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 { }
49 version_t get_trim_to() const override;
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
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
62 void on_active() override;
63 void on_restart() override;
64
65 void check_subs();
66 void check_sub(Subscription *sub);
67
68 void dump_info(ceph::Formatter *f);
69 int print_nodes(ceph::Formatter *f);
70
71 /**
72 * Return true if a blocklist was done (i.e. OSD propose needed)
73 */
74 bool fail_mds_gid(FSMap &fsmap, mds_gid_t gid);
75
76 bool is_leader() const override { return mon.is_leader(); }
77
78 protected:
79 using mds_info_t = MDSMap::mds_info_t;
80
81 // my helpers
82 template<int dblV = 7>
83 void print_map(const FSMap &m);
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
94 int fail_mds(FSMap &fsmap, std::ostream &ss,
95 const std::string &arg, mds_info_t *failed_info);
96
97 bool preprocess_command(MonOpRequestRef op);
98 bool prepare_command(MonOpRequestRef op);
99
100 int filesystem_command(
101 FSMap &fsmap,
102 MonOpRequestRef op,
103 std::string const &prefix,
104 const cmdmap_t& cmdmap,
105 std::stringstream &ss);
106
107 // beacons
108 struct beacon_info_t {
109 ceph::mono_time stamp = ceph::mono_clock::zero();
110 uint64_t seq = 0;
111 beacon_info_t() {}
112 beacon_info_t(ceph::mono_time stamp, uint64_t seq) : stamp(stamp), seq(seq) {}
113 };
114 std::map<mds_gid_t, beacon_info_t> last_beacon;
115
116 std::list<std::shared_ptr<FileSystemCommandHandler> > handlers;
117
118 bool maybe_promote_standby(FSMap& fsmap, Filesystem& fs);
119 bool maybe_resize_cluster(FSMap &fsmap, fs_cluster_id_t fscid);
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);
122 void tick() override; // check state, take actions
123
124 int dump_metadata(const FSMap &fsmap, const std::string &who, ceph::Formatter *f,
125 std::ostream& err);
126
127 void update_metadata(mds_gid_t gid, const Metadata& metadata);
128 void remove_from_metadata(const FSMap &fsmap, MonitorDBStore::TransactionRef t);
129 int load_metadata(std::map<mds_gid_t, Metadata>& m);
130 void count_metadata(const std::string& field, ceph::Formatter *f);
131
132 public:
133 void print_fs_summary(std::ostream& out) {
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);
138
139 protected:
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
144 std::map<mds_gid_t, Metadata> pending_metadata;
145
146 mds_gid_t gid_from_arg(const FSMap &fsmap, const std::string &arg, std::ostream& err);
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
151 ceph::mono_time last_tick = ceph::mono_clock::zero();
152
153 private:
154 time last_fsmap_struct_flush = clock::zero();
155 bool check_fsmap_struct_version = true;
156 };
157
158 #endif