]>
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 | ||
94b18763 FG |
19 | #include <boost/utility/string_view.hpp> |
20 | ||
7c673cae FG |
21 | #include "include/types.h" |
22 | #include "include/Context.h" | |
23 | #include "common/Mutex.h" | |
24 | #include "msg/Dispatcher.h" | |
25 | #include "messages/MMDSBeacon.h" | |
26 | ||
27 | class MonClient; | |
28 | class MMDSBeacon; | |
29 | class Message; | |
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: | |
94b18763 | 45 | Beacon(CephContext *cct_, MonClient *monc_, boost::string_view name); |
7c673cae FG |
46 | ~Beacon() override; |
47 | ||
48 | void init(MDSMap const *mdsmap); | |
49 | void shutdown(); | |
50 | ||
51 | bool ms_dispatch(Message *m) override; | |
52 | void ms_handle_connect(Connection *c) override {} | |
53 | bool ms_handle_reset(Connection *c) override {return false;} | |
54 | void ms_handle_remote_reset(Connection *c) override {} | |
55 | bool ms_handle_refused(Connection *c) override {return false;} | |
56 | ||
57 | void notify_mdsmap(MDSMap const *mdsmap); | |
58 | void notify_health(MDSRank const *mds); | |
59 | ||
60 | void handle_mds_beacon(MMDSBeacon *m); | |
61 | void send(); | |
62 | ||
63 | void set_want_state(MDSMap const *mdsmap, MDSMap::DaemonState const newstate); | |
64 | MDSMap::DaemonState get_want_state() const; | |
65 | ||
66 | /** | |
67 | * Send a beacon, and block until the ack is received from the mon | |
68 | * or `duration` seconds pass, whichever happens sooner. Useful | |
69 | * for emitting a last message on shutdown. | |
70 | */ | |
71 | void send_and_wait(const double duration); | |
72 | ||
73 | bool is_laggy(); | |
74 | utime_t get_laggy_until() const; | |
75 | ||
76 | private: | |
77 | void _notify_mdsmap(MDSMap const *mdsmap); | |
78 | void _send(); | |
79 | ||
80 | //CephContext *cct; | |
81 | mutable Mutex lock; | |
82 | MonClient* monc; | |
83 | SafeTimer timer; | |
84 | ||
85 | // Items we duplicate from the MDS to have access under our own lock | |
86 | std::string name; | |
87 | version_t epoch; | |
88 | CompatSet compat; | |
89 | mds_rank_t standby_for_rank; | |
90 | std::string standby_for_name; | |
91 | fs_cluster_id_t standby_for_fscid; | |
92 | bool standby_replay; | |
93 | MDSMap::DaemonState want_state; | |
94 | ||
95 | // Internal beacon state | |
96 | version_t last_seq; // last seq sent to monitor | |
97 | std::map<version_t,utime_t> seq_stamp; // seq # -> time sent | |
98 | utime_t last_acked_stamp; // last time we sent a beacon that got acked | |
99 | utime_t last_mon_reconnect; | |
100 | bool was_laggy; | |
101 | utime_t laggy_until; | |
102 | ||
103 | // Health status to be copied into each beacon message | |
104 | MDSHealth health; | |
105 | ||
106 | // Ticker | |
3efd9988 | 107 | Context *sender = nullptr; |
7c673cae FG |
108 | |
109 | version_t awaiting_seq; | |
110 | Cond waiting_cond; | |
111 | }; | |
112 | ||
113 | #endif // BEACON_STATE_H | |
114 |