1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
15 /* Metadata Server Monitor
18 #ifndef CEPH_MDSMONITOR_H
19 #define CEPH_MDSMONITOR_H
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"
31 class FileSystemCommandHandler
;
33 class MDSMonitor
: public PaxosService
, public PaxosFSMap
, protected CommandHandler
{
35 using clock
= ceph::coarse_mono_clock
;
36 using time
= ceph::coarse_mono_time
;
38 MDSMonitor(Monitor
&mn
, Paxos
&p
, std::string service_name
);
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
;
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
;
51 bool preprocess_query(MonOpRequestRef op
) override
; // true if processed.
52 bool prepare_update(MonOpRequestRef op
) override
;
53 bool should_propose(double& delay
) override
;
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;
62 void on_active() override
;
63 void on_restart() override
;
66 void check_sub(Subscription
*sub
);
68 void dump_info(ceph::Formatter
*f
);
69 int print_nodes(ceph::Formatter
*f
);
72 * Return true if a blocklist was done (i.e. OSD propose needed)
74 bool fail_mds_gid(FSMap
&fsmap
, mds_gid_t gid
);
76 bool is_leader() const override
{ return mon
.is_leader(); }
79 using mds_info_t
= MDSMap::mds_info_t
;
82 template<int dblV
= 7>
83 void print_map(const FSMap
&m
);
85 void _updated(MonOpRequestRef op
);
87 void _note_beacon(class MMDSBeacon
*m
);
88 bool preprocess_beacon(MonOpRequestRef op
);
89 bool prepare_beacon(MonOpRequestRef op
);
91 bool preprocess_offload_targets(MonOpRequestRef op
);
92 bool prepare_offload_targets(MonOpRequestRef op
);
94 int fail_mds(FSMap
&fsmap
, std::ostream
&ss
,
95 const std::string
&arg
, mds_info_t
*failed_info
);
97 bool preprocess_command(MonOpRequestRef op
);
98 bool prepare_command(MonOpRequestRef op
);
100 int filesystem_command(
103 std::string
const &prefix
,
104 const cmdmap_t
& cmdmap
,
105 std::stringstream
&ss
);
108 struct beacon_info_t
{
109 ceph::mono_time stamp
= ceph::mono_clock::zero();
112 beacon_info_t(ceph::mono_time stamp
, uint64_t seq
) : stamp(stamp
), seq(seq
) {}
114 std::map
<mds_gid_t
, beacon_info_t
> last_beacon
;
116 std::list
<std::shared_ptr
<FileSystemCommandHandler
> > handlers
;
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
124 int dump_metadata(const FSMap
&fsmap
, const std::string
&who
, ceph::Formatter
*f
,
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
);
133 void print_fs_summary(std::ostream
& out
) {
134 get_fsmap().print_fs_summary(out
);
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
);
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
;
144 std::map
<mds_gid_t
, Metadata
> pending_metadata
;
146 mds_gid_t
gid_from_arg(const FSMap
&fsmap
, const std::string
&arg
, std::ostream
& err
);
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();
154 time last_fsmap_struct_flush
= clock::zero();
155 bool check_fsmap_struct_version
= true;