]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/MetricsHandler.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / mds / MetricsHandler.h
CommitLineData
f67539c2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#ifndef CEPH_MDS_METRICS_HANDLER_H
5#define CEPH_MDS_METRICS_HANDLER_H
6
7#include <thread>
8#include <utility>
9#include <boost/variant.hpp>
10
11#include "msg/Dispatcher.h"
12#include "common/ceph_mutex.h"
13#include "include/common_fwd.h"
14#include "include/cephfs/metrics/Types.h"
15
16#include "messages/MMDSPing.h"
17#include "messages/MClientMetrics.h"
18
19#include "MDSPerfMetricTypes.h"
20
21class MDSRank;
22class Session;
23
24class MetricsHandler : public Dispatcher {
25public:
26 MetricsHandler(CephContext *cct, MDSRank *mds);
27
28 bool ms_can_fast_dispatch_any() const override {
29 return true;
30 }
31 bool ms_can_fast_dispatch2(const cref_t<Message> &m) const override;
32 void ms_fast_dispatch2(const ref_t<Message> &m) override;
33 bool ms_dispatch2(const ref_t<Message> &m) override;
34
35 void ms_handle_connect(Connection *c) override {
36 }
37 bool ms_handle_reset(Connection *c) override {
38 return false;
39 }
40 void ms_handle_remote_reset(Connection *c) override {
41 }
42 bool ms_handle_refused(Connection *c) override {
43 return false;
44 }
45
46 void add_session(Session *session);
47 void remove_session(Session *session);
48
49 void init();
50 void shutdown();
51
52 void notify_mdsmap(const MDSMap &mdsmap);
53
54private:
55 struct HandlePayloadVisitor : public boost::static_visitor<void> {
56 MetricsHandler *metrics_handler;
57 Session *session;
58
59 HandlePayloadVisitor(MetricsHandler *metrics_handler, Session *session)
60 : metrics_handler(metrics_handler), session(session) {
61 }
62
63 template <typename ClientMetricPayload>
64 inline void operator()(const ClientMetricPayload &payload) const {
65 metrics_handler->handle_payload(session, payload);
66 }
67 };
68
69 MDSRank *mds;
70 // drop this lock when calling ->send_message_mds() else mds might
71 // deadlock
72 ceph::mutex lock = ceph::make_mutex("MetricsHandler::lock");
73
74 // ISN sent by rank0 pinger is 1
75 version_t next_seq = 0;
76
77 // sequence number incremented on each update sent to rank 0.
78 // this is nowhere related to next_seq and is completely used
79 // locally to figure out if a session got added and removed
80 // within an update to rank 0.
81 version_t last_updated_seq = 0;
82
83 std::thread updater;
84 std::map<entity_inst_t, std::pair<version_t, Metrics>> client_metrics_map;
85
86 // address of rank 0 mds, so that the message can be sent without
87 // acquiring mds_lock. misdirected messages to rank 0 are taken
88 // care of by rank 0.
89 boost::optional<entity_addrvec_t> addr_rank0;
90
91 bool stopping = false;
92
93 void handle_payload(Session *session, const CapInfoPayload &payload);
94 void handle_payload(Session *session, const ReadLatencyPayload &payload);
95 void handle_payload(Session *session, const WriteLatencyPayload &payload);
96 void handle_payload(Session *session, const MetadataLatencyPayload &payload);
97 void handle_payload(Session *session, const DentryLeasePayload &payload);
98 void handle_payload(Session *session, const OpenedFilesPayload &payload);
99 void handle_payload(Session *session, const PinnedIcapsPayload &payload);
100 void handle_payload(Session *session, const OpenedInodesPayload &payload);
101 void handle_payload(Session *session, const UnknownPayload &payload);
102
103 void set_next_seq(version_t seq);
104 void reset_seq();
105
106 void handle_client_metrics(const cref_t<MClientMetrics> &m);
107 void handle_mds_ping(const cref_t<MMDSPing> &m);
108
109 void update_rank0();
110};
111
112#endif // CEPH_MDS_METRICS_HANDLER_H