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