]> git.proxmox.com Git - ceph.git/blame - ceph/src/mon/MDSMonitor.h
update source to Ceph Pacific 16.2.2
[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>
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
31class FileSystemCommandHandler;
32
11fdf7f2 33class MDSMonitor : public PaxosService, public PaxosFSMap, protected CommandHandler {
7c673cae 34 public:
f67539c2 35 MDSMonitor(Monitor &mn, Paxos &p, std::string service_name);
7c673cae
FG
36
37 // service methods
38 void create_initial() override;
f67539c2 39 void get_store_prefixes(std::set<std::string>& s) const override;
7c673cae
FG
40 void update_from_paxos(bool *need_bootstrap) override;
41 void init() override;
f67539c2 42 void create_pending() override;
7c673cae
FG
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 { }
11fdf7f2 46 version_t get_trim_to() const override;
7c673cae
FG
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
92f5a8d4
TL
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
7c673cae
FG
59 void on_active() override;
60 void on_restart() override;
61
62 void check_subs();
63 void check_sub(Subscription *sub);
64
f67539c2
TL
65 void dump_info(ceph::Formatter *f);
66 int print_nodes(ceph::Formatter *f);
7c673cae
FG
67
68 /**
f67539c2 69 * Return true if a blocklist was done (i.e. OSD propose needed)
7c673cae 70 */
1adf2230 71 bool fail_mds_gid(FSMap &fsmap, mds_gid_t gid);
7c673cae 72
f67539c2 73 bool is_leader() const override { return mon.is_leader(); }
28e407b8
AA
74
75 protected:
9f95a23c
TL
76 using mds_info_t = MDSMap::mds_info_t;
77
7c673cae 78 // my helpers
11fdf7f2
TL
79 template<int dblV = 7>
80 void print_map(const FSMap &m);
7c673cae
FG
81
82 void _updated(MonOpRequestRef op);
83
84 void _note_beacon(class MMDSBeacon *m);
85 bool preprocess_beacon(MonOpRequestRef op);
86 bool prepare_beacon(MonOpRequestRef op);
87
88 bool preprocess_offload_targets(MonOpRequestRef op);
89 bool prepare_offload_targets(MonOpRequestRef op);
90
1adf2230 91 int fail_mds(FSMap &fsmap, std::ostream &ss,
f67539c2 92 const std::string &arg, mds_info_t *failed_info);
7c673cae
FG
93
94 bool preprocess_command(MonOpRequestRef op);
95 bool prepare_command(MonOpRequestRef op);
96
7c673cae 97 int filesystem_command(
1adf2230 98 FSMap &fsmap,
7c673cae
FG
99 MonOpRequestRef op,
100 std::string const &prefix,
11fdf7f2 101 const cmdmap_t& cmdmap,
7c673cae
FG
102 std::stringstream &ss);
103
104 // beacons
105 struct beacon_info_t {
f67539c2 106 ceph::mono_time stamp = ceph::mono_clock::zero();
1adf2230
AA
107 uint64_t seq = 0;
108 beacon_info_t() {}
f67539c2 109 beacon_info_t(ceph::mono_time stamp, uint64_t seq) : stamp(stamp), seq(seq) {}
7c673cae 110 };
f67539c2 111 std::map<mds_gid_t, beacon_info_t> last_beacon;
7c673cae 112
7c673cae
FG
113 std::list<std::shared_ptr<FileSystemCommandHandler> > handlers;
114
11fdf7f2
TL
115 bool maybe_promote_standby(FSMap& fsmap, Filesystem& fs);
116 bool maybe_resize_cluster(FSMap &fsmap, fs_cluster_id_t fscid);
9f95a23c
TL
117 bool drop_mds(FSMap &fsmap, mds_gid_t gid, const mds_info_t* rep_info, bool* osd_propose);
118 bool check_health(FSMap &fsmap, bool* osd_propose);
7c673cae
FG
119 void tick() override; // check state, take actions
120
f67539c2
TL
121 int dump_metadata(const FSMap &fsmap, const std::string &who, ceph::Formatter *f,
122 std::ostream& err);
7c673cae 123
7c673cae 124 void update_metadata(mds_gid_t gid, const Metadata& metadata);
1adf2230 125 void remove_from_metadata(const FSMap &fsmap, MonitorDBStore::TransactionRef t);
f67539c2
TL
126 int load_metadata(std::map<mds_gid_t, Metadata>& m);
127 void count_metadata(const std::string& field, ceph::Formatter *f);
128
c07f9fc5 129public:
f67539c2
TL
130 void print_fs_summary(ostream& out) {
131 get_fsmap().print_fs_summary(out);
132 }
133 void count_metadata(const std::string& field, std::map<std::string,int> *out);
134 void get_versions(std::map<std::string, std::list<std::string>> &versions);
7c673cae 135
f67539c2 136protected:
7c673cae
FG
137 // MDS daemon GID to latest health state from that GID
138 std::map<uint64_t, MDSHealth> pending_daemon_health;
139 std::set<uint64_t> pending_daemon_health_rm;
140
f67539c2 141 std::map<mds_gid_t, Metadata> pending_metadata;
7c673cae 142
1adf2230 143 mds_gid_t gid_from_arg(const FSMap &fsmap, const std::string &arg, std::ostream& err);
7c673cae
FG
144
145 // When did the mon last call into our tick() method? Used for detecting
146 // when the mon was not updating us for some period (e.g. during slow
147 // election) to reset last_beacon timeouts
f67539c2 148 ceph::mono_time last_tick = ceph::mono_clock::zero();
7c673cae
FG
149};
150
151#endif