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>
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"
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.
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.
42 class Beacon
: public Dispatcher
45 Beacon(CephContext
*cct_
, MonClient
*monc_
, boost::string_view name
);
48 void init(MDSMap
const *mdsmap
);
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;}
57 void notify_mdsmap(MDSMap
const *mdsmap
);
58 void notify_health(MDSRank
const *mds
);
60 void handle_mds_beacon(MMDSBeacon
*m
);
63 void set_want_state(MDSMap
const *mdsmap
, MDSMap::DaemonState
const newstate
);
64 MDSMap::DaemonState
get_want_state() const;
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.
71 void send_and_wait(const double duration
);
74 utime_t
get_laggy_until() const;
77 void _notify_mdsmap(MDSMap
const *mdsmap
);
85 // Items we duplicate from the MDS to have access under our own lock
89 mds_rank_t standby_for_rank
;
90 std::string standby_for_name
;
91 fs_cluster_id_t standby_for_fscid
;
93 MDSMap::DaemonState want_state
;
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
;
103 // Health status to be copied into each beacon message
107 Context
*sender
= nullptr;
109 version_t awaiting_seq
;
113 #endif // BEACON_STATE_H