#define BEACON_STATE_H
#include <boost/utility/string_view.hpp>
+#include <mutex>
+#include <thread>
#include "include/types.h"
#include "include/Context.h"
-#include "common/Mutex.h"
#include "msg/Dispatcher.h"
#include "messages/MMDSBeacon.h"
class Beacon : public Dispatcher
{
public:
- Beacon(CephContext *cct_, MonClient *monc_, boost::string_view name);
+ using clock = ceph::coarse_mono_clock;
+ using time = ceph::coarse_mono_time;
+
+ Beacon(CephContext *cct, MonClient *monc, boost::string_view name);
~Beacon() override;
void init(MDSMap const *mdsmap);
void shutdown();
+ bool ms_can_fast_dispatch_any() const override { return true; }
+ bool ms_can_fast_dispatch(const Message *m) const override;
+ void ms_fast_dispatch(Message *m) override;
bool ms_dispatch(Message *m) override;
void ms_handle_connect(Connection *c) override {}
bool ms_handle_reset(Connection *c) override {return false;}
void send_and_wait(const double duration);
bool is_laggy();
- utime_t get_laggy_until() const;
+ double last_cleared_laggy() const {
+ std::unique_lock<std::mutex> lock(mutex);
+ return std::chrono::duration<double>(clock::now()-last_laggy).count();
+ }
private:
void _notify_mdsmap(MDSMap const *mdsmap);
void _send();
- //CephContext *cct;
- mutable Mutex lock;
+ mutable std::mutex mutex;
+ std::thread sender;
+ std::condition_variable cvar;
+ time last_send = time::min();
+ double beacon_interval = 5.0;
+ bool finished = false;
MonClient* monc;
- SafeTimer timer;
// Items we duplicate from the MDS to have access under our own lock
std::string name;
- version_t epoch;
+ version_t epoch = 0;
CompatSet compat;
- mds_rank_t standby_for_rank;
+ mds_rank_t standby_for_rank = MDS_RANK_NONE;
std::string standby_for_name;
- fs_cluster_id_t standby_for_fscid;
- bool standby_replay;
- MDSMap::DaemonState want_state;
+ fs_cluster_id_t standby_for_fscid = FS_CLUSTER_ID_NONE;
+ bool standby_replay = false;
+ MDSMap::DaemonState want_state = MDSMap::STATE_BOOT;
// Internal beacon state
- version_t last_seq; // last seq sent to monitor
- std::map<version_t,utime_t> seq_stamp; // seq # -> time sent
- utime_t last_acked_stamp; // last time we sent a beacon that got acked
- utime_t last_mon_reconnect;
- bool was_laggy;
- utime_t laggy_until;
+ version_t last_seq = 0; // last seq sent to monitor
+ std::map<version_t,time> seq_stamp; // seq # -> time sent
+ time last_acked_stamp = time::min(); // last time we sent a beacon that got acked
+ time last_mon_reconnect = time::min();
+ bool laggy = false;
+ time last_laggy = time::min();
// Health status to be copied into each beacon message
MDSHealth health;
-
- // Ticker
- Context *sender = nullptr;
-
- version_t awaiting_seq;
- Cond waiting_cond;
};
#endif // BEACON_STATE_H
-