]> git.proxmox.com Git - ceph.git/blame - ceph/src/mon/MDSMonitor.h
update sources to 12.2.8
[ceph.git] / ceph / src / mon / MDSMonitor.h
CommitLineData
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>
23using namespace std;
24
25#include "include/types.h"
28e407b8 26#include "PaxosFSMap.h"
7c673cae
FG
27#include "PaxosService.h"
28#include "msg/Messenger.h"
29#include "messages/MMDSBeacon.h"
30
31class MMonCommand;
32class MMDSLoadTargets;
33class MMDSMap;
34class FileSystemCommandHandler;
35
28e407b8 36class MDSMonitor : public PaxosService, public PaxosFSMap {
7c673cae
FG
37 public:
38 MDSMonitor(Monitor *mn, Paxos *p, string service_name);
39
40 // service methods
41 void create_initial() override;
3efd9988 42 void get_store_prefixes(std::set<string>& s) override;
7c673cae
FG
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() 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 void on_active() override;
56 void on_restart() override;
57
58 void check_subs();
59 void check_sub(Subscription *sub);
60
7c673cae
FG
61 void dump_info(Formatter *f);
62 int print_nodes(Formatter *f);
63
64 /**
65 * Return true if a blacklist was done (i.e. OSD propose needed)
66 */
1adf2230 67 bool fail_mds_gid(FSMap &fsmap, mds_gid_t gid);
7c673cae 68
28e407b8
AA
69 bool is_leader() const override { return mon->is_leader(); }
70
71 protected:
7c673cae 72 // my helpers
28e407b8 73 void print_map(const FSMap &m, int dbl=7);
7c673cae
FG
74 void update_logger();
75
76 void _updated(MonOpRequestRef op);
77
78 void _note_beacon(class MMDSBeacon *m);
79 bool preprocess_beacon(MonOpRequestRef op);
80 bool prepare_beacon(MonOpRequestRef op);
81
82 bool preprocess_offload_targets(MonOpRequestRef op);
83 bool prepare_offload_targets(MonOpRequestRef op);
84
85 void get_health(list<pair<health_status_t,string> >& summary,
86 list<pair<health_status_t,string> > *detail,
87 CephContext *cct) const override;
1adf2230
AA
88 int fail_mds(FSMap &fsmap, std::ostream &ss,
89 const std::string &arg,
d2e6a577 90 MDSMap::mds_info_t *failed_info);
7c673cae
FG
91
92 bool preprocess_command(MonOpRequestRef op);
93 bool prepare_command(MonOpRequestRef op);
94
7c673cae 95 void modify_legacy_filesystem(
1adf2230 96 FSMap &fsmap,
7c673cae
FG
97 std::function<void(std::shared_ptr<Filesystem> )> fn);
98 int legacy_filesystem_command(
1adf2230 99 FSMap &fsmap,
7c673cae
FG
100 MonOpRequestRef op,
101 std::string const &prefix,
102 map<string, cmd_vartype> &cmdmap,
103 std::stringstream &ss);
104 int filesystem_command(
1adf2230 105 FSMap &fsmap,
7c673cae
FG
106 MonOpRequestRef op,
107 std::string const &prefix,
108 map<string, cmd_vartype> &cmdmap,
109 std::stringstream &ss);
110
111 // beacons
112 struct beacon_info_t {
1adf2230
AA
113 mono_time stamp = mono_clock::zero();
114 uint64_t seq = 0;
115 beacon_info_t() {}
116 beacon_info_t(mono_time stamp, uint64_t seq) : stamp(stamp), seq(seq) {}
7c673cae
FG
117 };
118 map<mds_gid_t, beacon_info_t> last_beacon;
119
1adf2230
AA
120 bool try_standby_replay(FSMap &fsmap, const MDSMap::mds_info_t& finfo,
121 const Filesystem &leader_fs, const MDSMap::mds_info_t& ainfo);
7c673cae
FG
122
123 std::list<std::shared_ptr<FileSystemCommandHandler> > handlers;
124
1adf2230
AA
125 bool maybe_promote_standby(FSMap &fsmap, std::shared_ptr<Filesystem> &fs);
126 bool maybe_expand_cluster(FSMap &fsmap, fs_cluster_id_t fscid);
127 void maybe_replace_gid(FSMap &fsmap, mds_gid_t gid,
128 const MDSMap::mds_info_t& info, bool *mds_propose, bool *osd_propose);
7c673cae
FG
129 void tick() override; // check state, take actions
130
1adf2230
AA
131 int dump_metadata(const FSMap &fsmap, const std::string &who, Formatter *f,
132 ostream& err);
7c673cae 133
7c673cae 134 void update_metadata(mds_gid_t gid, const Metadata& metadata);
1adf2230 135 void remove_from_metadata(const FSMap &fsmap, MonitorDBStore::TransactionRef t);
7c673cae 136 int load_metadata(map<mds_gid_t, Metadata>& m);
1adf2230 137 void count_metadata(const std::string& field, Formatter *f);
c07f9fc5 138public:
1adf2230 139 void count_metadata(const std::string& field, map<string,int> *out);
c07f9fc5 140protected:
7c673cae
FG
141
142 // MDS daemon GID to latest health state from that GID
143 std::map<uint64_t, MDSHealth> pending_daemon_health;
144 std::set<uint64_t> pending_daemon_health_rm;
145
146 map<mds_gid_t, Metadata> pending_metadata;
147
1adf2230 148 mds_gid_t gid_from_arg(const FSMap &fsmap, const std::string &arg, std::ostream& err);
7c673cae
FG
149
150 // When did the mon last call into our tick() method? Used for detecting
151 // when the mon was not updating us for some period (e.g. during slow
152 // election) to reset last_beacon timeouts
1adf2230 153 mono_time last_tick = mono_clock::zero();
7c673cae
FG
154};
155
156#endif