]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/Beacon.h
update sources to 12.2.10
[ceph.git] / ceph / src / mds / Beacon.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) 2012 Red Hat
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
16 #ifndef BEACON_STATE_H
17 #define BEACON_STATE_H
18
19 #include <boost/utility/string_view.hpp>
20 #include <mutex>
21 #include <thread>
22
23 #include "include/types.h"
24 #include "include/Context.h"
25 #include "msg/Dispatcher.h"
26 #include "messages/MMDSBeacon.h"
27
28 class MonClient;
29 class MMDSBeacon;
30 class Message;
31 class MDSRank;
32
33
34 /**
35 * One of these per MDS. Handle beacon logic in this separate class so
36 * that a busy MDS holding its own lock does not hold up sending beacon
37 * messages to the mon and cause false lagginess.
38 *
39 * So that we can continue to operate while the MDS is holding its own lock,
40 * we keep copies of the data needed to generate beacon messages. The MDS is
41 * responsible for calling Beacon::notify_* when things change.
42 */
43 class Beacon : public Dispatcher
44 {
45 public:
46 using clock = ceph::coarse_mono_clock;
47 using time = ceph::coarse_mono_time;
48
49 Beacon(CephContext *cct, MonClient *monc, boost::string_view name);
50 ~Beacon() override;
51
52 void init(MDSMap const *mdsmap);
53 void shutdown();
54
55 bool ms_can_fast_dispatch_any() const override { return true; }
56 bool ms_can_fast_dispatch(const Message *m) const override;
57 void ms_fast_dispatch(Message *m) override;
58 bool ms_dispatch(Message *m) override;
59 void ms_handle_connect(Connection *c) override {}
60 bool ms_handle_reset(Connection *c) override {return false;}
61 void ms_handle_remote_reset(Connection *c) override {}
62 bool ms_handle_refused(Connection *c) override {return false;}
63
64 void notify_mdsmap(MDSMap const *mdsmap);
65 void notify_health(MDSRank const *mds);
66
67 void handle_mds_beacon(MMDSBeacon *m);
68 void send();
69
70 void set_want_state(MDSMap const *mdsmap, MDSMap::DaemonState const newstate);
71 MDSMap::DaemonState get_want_state() const;
72
73 /**
74 * Send a beacon, and block until the ack is received from the mon
75 * or `duration` seconds pass, whichever happens sooner. Useful
76 * for emitting a last message on shutdown.
77 */
78 void send_and_wait(const double duration);
79
80 bool is_laggy();
81 double last_cleared_laggy() const {
82 std::unique_lock<std::mutex> lock(mutex);
83 return std::chrono::duration<double>(clock::now()-last_laggy).count();
84 }
85
86 private:
87 void _notify_mdsmap(MDSMap const *mdsmap);
88 void _send();
89
90 mutable std::mutex mutex;
91 std::thread sender;
92 std::condition_variable cvar;
93 time last_send = time::min();
94 double beacon_interval = 5.0;
95 bool finished = false;
96 MonClient* monc;
97
98 // Items we duplicate from the MDS to have access under our own lock
99 std::string name;
100 version_t epoch = 0;
101 CompatSet compat;
102 mds_rank_t standby_for_rank = MDS_RANK_NONE;
103 std::string standby_for_name;
104 fs_cluster_id_t standby_for_fscid = FS_CLUSTER_ID_NONE;
105 bool standby_replay = false;
106 MDSMap::DaemonState want_state = MDSMap::STATE_BOOT;
107
108 // Internal beacon state
109 version_t last_seq = 0; // last seq sent to monitor
110 std::map<version_t,time> seq_stamp; // seq # -> time sent
111 time last_acked_stamp = time::min(); // last time we sent a beacon that got acked
112 time last_mon_reconnect = time::min();
113 bool laggy = false;
114 time last_laggy = time::min();
115
116 // Health status to be copied into each beacon message
117 MDSHealth health;
118 };
119
120 #endif // BEACON_STATE_H