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 "include/types.h"
20 #include "include/Context.h"
21 #include "common/Mutex.h"
22 #include "msg/Dispatcher.h"
23 #include "messages/MMDSBeacon.h"
32 * One of these per MDS. Handle beacon logic in this separate class so
33 * that a busy MDS holding its own lock does not hold up sending beacon
34 * messages to the mon and cause false lagginess.
36 * So that we can continue to operate while the MDS is holding its own lock,
37 * we keep copies of the data needed to generate beacon messages. The MDS is
38 * responsible for calling Beacon::notify_* when things change.
40 class Beacon
: public Dispatcher
43 Beacon(CephContext
*cct_
, MonClient
*monc_
, std::string name
);
46 void init(MDSMap
const *mdsmap
);
49 bool ms_dispatch(Message
*m
) override
;
50 void ms_handle_connect(Connection
*c
) override
{}
51 bool ms_handle_reset(Connection
*c
) override
{return false;}
52 void ms_handle_remote_reset(Connection
*c
) override
{}
53 bool ms_handle_refused(Connection
*c
) override
{return false;}
55 void notify_mdsmap(MDSMap
const *mdsmap
);
56 void notify_health(MDSRank
const *mds
);
58 void handle_mds_beacon(MMDSBeacon
*m
);
61 void set_want_state(MDSMap
const *mdsmap
, MDSMap::DaemonState
const newstate
);
62 MDSMap::DaemonState
get_want_state() const;
65 * Send a beacon, and block until the ack is received from the mon
66 * or `duration` seconds pass, whichever happens sooner. Useful
67 * for emitting a last message on shutdown.
69 void send_and_wait(const double duration
);
72 utime_t
get_laggy_until() const;
75 void _notify_mdsmap(MDSMap
const *mdsmap
);
83 // Items we duplicate from the MDS to have access under our own lock
87 mds_rank_t standby_for_rank
;
88 std::string standby_for_name
;
89 fs_cluster_id_t standby_for_fscid
;
91 MDSMap::DaemonState want_state
;
93 // Internal beacon state
94 version_t last_seq
; // last seq sent to monitor
95 std::map
<version_t
,utime_t
> seq_stamp
; // seq # -> time sent
96 utime_t last_acked_stamp
; // last time we sent a beacon that got acked
97 utime_t last_mon_reconnect
;
101 // Health status to be copied into each beacon message
105 Context
*sender
= nullptr;
107 version_t awaiting_seq
;
111 #endif // BEACON_STATE_H