]> git.proxmox.com Git - ceph.git/blob - ceph/src/mon/MDSMonitor.h
import new upstream nautilus stable release 14.2.8
[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 MDSMonitor(Monitor *mn, Paxos *p, string service_name);
36
37 // service methods
38 void create_initial() override;
39 void get_store_prefixes(std::set<string>& s) const override;
40 void update_from_paxos(bool *need_bootstrap) override;
41 void init() override;
42 void create_pending() override;
43 void encode_pending(MonitorDBStore::TransactionRef t) override;
44 // we don't require full versions; don't encode any.
45 void encode_full(MonitorDBStore::TransactionRef t) override { }
46 version_t get_trim_to() const override;
47
48 bool preprocess_query(MonOpRequestRef op) override; // true if processed.
49 bool prepare_update(MonOpRequestRef op) override;
50 bool should_propose(double& delay) override;
51
52 bool should_print_status() const {
53 auto& fs = get_fsmap();
54 auto fs_count = fs.filesystem_count();
55 auto standby_count = fs.get_num_standby();
56 return fs_count > 0 || standby_count > 0;
57 }
58
59 void on_active() override;
60 void on_restart() override;
61
62 void check_subs();
63 void check_sub(Subscription *sub);
64
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(FSMap &fsmap, mds_gid_t gid);
72
73 bool is_leader() const override { return mon->is_leader(); }
74
75 protected:
76 // my helpers
77 template<int dblV = 7>
78 void print_map(const FSMap &m);
79
80 void _updated(MonOpRequestRef op);
81
82 void _note_beacon(class MMDSBeacon *m);
83 bool preprocess_beacon(MonOpRequestRef op);
84 bool prepare_beacon(MonOpRequestRef op);
85
86 bool preprocess_offload_targets(MonOpRequestRef op);
87 bool prepare_offload_targets(MonOpRequestRef op);
88
89 int fail_mds(FSMap &fsmap, std::ostream &ss,
90 const std::string &arg,
91 MDSMap::mds_info_t *failed_info);
92
93 bool preprocess_command(MonOpRequestRef op);
94 bool prepare_command(MonOpRequestRef op);
95
96 int filesystem_command(
97 FSMap &fsmap,
98 MonOpRequestRef op,
99 std::string const &prefix,
100 const cmdmap_t& cmdmap,
101 std::stringstream &ss);
102
103 // beacons
104 struct beacon_info_t {
105 mono_time stamp = mono_clock::zero();
106 uint64_t seq = 0;
107 beacon_info_t() {}
108 beacon_info_t(mono_time stamp, uint64_t seq) : stamp(stamp), seq(seq) {}
109 };
110 map<mds_gid_t, beacon_info_t> last_beacon;
111
112 std::list<std::shared_ptr<FileSystemCommandHandler> > handlers;
113
114 bool maybe_promote_standby(FSMap& fsmap, Filesystem& fs);
115 bool maybe_resize_cluster(FSMap &fsmap, fs_cluster_id_t fscid);
116 void maybe_replace_gid(FSMap &fsmap, mds_gid_t gid,
117 const MDSMap::mds_info_t& info, bool *mds_propose, bool *osd_propose);
118 void tick() override; // check state, take actions
119
120 int dump_metadata(const FSMap &fsmap, const std::string &who, Formatter *f,
121 ostream& err);
122
123 void update_metadata(mds_gid_t gid, const Metadata& metadata);
124 void remove_from_metadata(const FSMap &fsmap, MonitorDBStore::TransactionRef t);
125 int load_metadata(map<mds_gid_t, Metadata>& m);
126 void count_metadata(const std::string& field, Formatter *f);
127 public:
128 void count_metadata(const std::string& field, map<string,int> *out);
129 protected:
130
131 // MDS daemon GID to latest health state from that GID
132 std::map<uint64_t, MDSHealth> pending_daemon_health;
133 std::set<uint64_t> pending_daemon_health_rm;
134
135 map<mds_gid_t, Metadata> pending_metadata;
136
137 mds_gid_t gid_from_arg(const FSMap &fsmap, const std::string &arg, std::ostream& err);
138
139 // When did the mon last call into our tick() method? Used for detecting
140 // when the mon was not updating us for some period (e.g. during slow
141 // election) to reset last_beacon timeouts
142 mono_time last_tick = mono_clock::zero();
143 };
144
145 #endif