]> git.proxmox.com Git - ceph.git/blame - ceph/src/mon/MgrMonitor.h
update sources to v12.2.3
[ceph.git] / ceph / src / mon / MgrMonitor.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) 2016 John Spray <john.spray@redhat.com>
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
31f18b77
FG
14#ifndef CEPH_MGRMONITOR_H
15#define CEPH_MGRMONITOR_H
7c673cae 16
c07f9fc5
FG
17#include <map>
18#include <set>
19
7c673cae
FG
20#include "include/Context.h"
21#include "MgrMap.h"
22#include "PaxosService.h"
c07f9fc5 23#include "MonCommand.h"
7c673cae 24
31f18b77 25class MgrMonitor: public PaxosService
7c673cae
FG
26{
27 MgrMap map;
28 MgrMap pending_map;
224ce89b 29 bool ever_had_active_mgr = false;
7c673cae 30
c07f9fc5
FG
31 std::map<std::string, bufferlist> pending_metadata;
32 std::set<std::string> pending_metadata_rm;
33
7c673cae
FG
34 utime_t first_seen_inactive;
35
31f18b77 36 std::map<uint64_t, ceph::coarse_mono_clock::time_point> last_beacon;
7c673cae
FG
37
38 /**
39 * If a standby is available, make it active, given that
40 * there is currently no active daemon.
41 *
42 * @return true if a standby was promoted
43 */
44 bool promote_standby();
45 void drop_active();
181888fb
FG
46
47 /**
48 * Remove this gid from the list of standbys. By default,
49 * also remove metadata (i.e. forget the daemon entirely).
50 *
51 * Set `drop_meta` to false if you would like to keep
52 * the daemon's metadata, for example if you're dropping
53 * it as a standby before reinstating it as the active daemon.
54 */
55 void drop_standby(uint64_t gid, bool drop_meta=true);
7c673cae 56
31f18b77
FG
57 Context *digest_event = nullptr;
58 void cancel_timer();
7c673cae
FG
59
60 bool check_caps(MonOpRequestRef op, const uuid_d& fsid);
61
224ce89b
WB
62 health_status_t should_warn_about_mgr_down();
63
c07f9fc5
FG
64 // Command descriptions we've learned from the active mgr
65 std::vector<MonCommand> command_descs;
66 std::vector<MonCommand> pending_command_descs;
67
7c673cae
FG
68public:
69 MgrMonitor(Monitor *mn, Paxos *p, const string& service_name)
31f18b77 70 : PaxosService(mn, p, service_name)
7c673cae 71 {}
31f18b77 72 ~MgrMonitor() override {}
7c673cae
FG
73
74 void init() override;
75 void on_shutdown() override;
76
77 const MgrMap &get_map() const { return map; }
78
79 bool in_use() const { return map.epoch > 0; }
80
b32b8144
FG
81 version_t get_trim_to() override;
82
7c673cae 83 void create_initial() override;
3efd9988 84 void get_store_prefixes(std::set<string>& s) override;
7c673cae
FG
85 void update_from_paxos(bool *need_bootstrap) override;
86 void create_pending() override;
87 void encode_pending(MonitorDBStore::TransactionRef t) override;
88
89 bool preprocess_query(MonOpRequestRef op) override;
90 bool prepare_update(MonOpRequestRef op) override;
91
92 bool preprocess_command(MonOpRequestRef op);
93 bool prepare_command(MonOpRequestRef op);
94
95 void encode_full(MonitorDBStore::TransactionRef t) override { }
96
97 bool preprocess_beacon(MonOpRequestRef op);
98 bool prepare_beacon(MonOpRequestRef op);
99
100 void check_sub(Subscription *sub);
101 void check_subs();
102 void send_digests();
103
104 void on_active() override;
224ce89b
WB
105 void on_restart() override;
106
7c673cae
FG
107 void get_health(list<pair<health_status_t,string> >& summary,
108 list<pair<health_status_t,string> > *detail,
109 CephContext *cct) const override;
110 void tick() override;
111
112 void print_summary(Formatter *f, std::ostream *ss) const;
113
d2e6a577 114 const std::vector<MonCommand> &get_command_descs() const;
c07f9fc5
FG
115
116 int load_metadata(const string& name, std::map<string, string>& m,
117 ostream *err);
118 int dump_metadata(const string& name, Formatter *f, ostream *err);
119 void count_metadata(const string& field, Formatter *f);
120 void count_metadata(const string& field, std::map<string,int> *out);
121
7c673cae 122 friend class C_Updated;
3efd9988
FG
123
124 // When did the mon last call into our tick() method? Used for detecting
125 // when the mon was not updating us for some period (e.g. during slow
126 // election) to reset last_beacon timeouts
127 ceph::coarse_mono_clock::time_point last_tick;
7c673cae
FG
128};
129
31f18b77 130#endif