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) 2012 Red Hat
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.
16 #ifndef BEACON_STATE_H
17 #define BEACON_STATE_H
19 #include <boost/utility/string_view.hpp>
23 #include "include/types.h"
24 #include "include/Context.h"
25 #include "msg/Dispatcher.h"
26 #include "messages/MMDSBeacon.h"
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.
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.
43 class Beacon
: public Dispatcher
46 using clock
= ceph::coarse_mono_clock
;
47 using time
= ceph::coarse_mono_time
;
49 Beacon(CephContext
*cct
, MonClient
*monc
, boost::string_view name
);
52 void init(MDSMap
const *mdsmap
);
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;}
64 void notify_mdsmap(MDSMap
const *mdsmap
);
65 void notify_health(MDSRank
const *mds
);
67 void handle_mds_beacon(MMDSBeacon
*m
);
70 void set_want_state(MDSMap
const *mdsmap
, MDSMap::DaemonState
const newstate
);
71 MDSMap::DaemonState
get_want_state() const;
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.
78 void send_and_wait(const double duration
);
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();
87 void _notify_mdsmap(MDSMap
const *mdsmap
);
90 mutable std::mutex mutex
;
92 std::condition_variable cvar
;
93 time last_send
= time::min();
94 double beacon_interval
= 5.0;
95 bool finished
= false;
98 // Items we duplicate from the MDS to have access under our own lock
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
;
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();
114 time last_laggy
= time::min();
116 // Health status to be copied into each beacon message
120 #endif // BEACON_STATE_H