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) 2015 Red Hat <contact@redhat.com>
7 * Copyright (C) 2015 SUSE LINUX GmbH
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
15 #ifndef MON_OPREQUEST_H_
16 #define MON_OPREQUEST_H_
20 #include "common/TrackedOp.h"
21 #include "include/memory.h"
22 #include "mon/Session.h"
23 #include "msg/Message.h"
25 struct MonOpRequest : public TrackedOp {
26 friend class OpTracker;
28 void mark_dispatch() {
29 mark_event("monitor_dispatch");
31 void mark_wait_for_quorum() {
32 mark_event("wait_for_quorum");
35 mark_event("monitor_zap");
37 void mark_forwarded() {
38 mark_event("forwarded");
39 forwarded_to_leader = true;
42 void mark_svc_event(const string &service, const string &event) {
44 s.append(":").append(event);
48 void mark_logmon_event(const string &event) {
49 mark_svc_event("logm", event);
51 void mark_osdmon_event(const string &event) {
52 mark_svc_event("osdmap", event);
54 void mark_pgmon_event(const string &event) {
55 mark_svc_event("pgmap", event);
57 void mark_mdsmon_event(const string &event) {
58 mark_svc_event("mdsmap", event);
60 void mark_authmon_event(const string &event) {
61 mark_svc_event("auth", event);
63 void mark_paxos_event(const string &event) {
64 mark_svc_event("paxos", event);
69 OP_TYPE_NONE = 0, ///< no type defined (default)
70 OP_TYPE_SERVICE, ///< belongs to a Paxos Service or similar
71 OP_TYPE_MONITOR, ///< belongs to the Monitor class
72 OP_TYPE_ELECTION, ///< belongs to the Elector class
73 OP_TYPE_PAXOS, ///< refers to Paxos messages
74 OP_TYPE_COMMAND, ///< is a command
77 MonOpRequest(const MonOpRequest &other) = delete;
78 MonOpRequest & operator = (const MonOpRequest &other) = delete;
82 utime_t dequeued_time;
85 bool forwarded_to_leader;
88 MonOpRequest(Message *req, OpTracker *tracker) :
90 req->get_recv_stamp().is_zero() ?
91 ceph_clock_now() : req->get_recv_stamp()),
95 forwarded_to_leader(false),
98 mark_event("header_read", request->get_recv_stamp());
99 mark_event("throttled", request->get_throttle_stamp());
100 mark_event("all_read", request->get_recv_complete_stamp());
101 mark_event("dispatched", request->get_dispatch_stamp());
104 con = req->get_connection();
106 session = static_cast<MonSession*>(con->get_priv());
111 void _dump(Formatter *f) const override {
113 f->open_array_section("events");
114 Mutex::Locker l(lock);
115 for (auto& i : events) {
116 f->dump_object("event", i);
119 f->open_object_section("info");
120 f->dump_int("seq", seq);
121 f->dump_bool("src_is_mon", is_src_mon());
122 f->dump_stream("source") << request->get_source_inst();
123 f->dump_bool("forwarded_to_leader", forwarded_to_leader);
129 void _dump_op_descriptor_unlocked(ostream& stream) const override {
130 get_req()->print(stream);
134 ~MonOpRequest() override {
136 // certain ops may not have a session (e.g., AUTH or PING)
141 MonSession *get_session() const {
148 T *get_req() const { return static_cast<T*>(request); }
150 Message *get_req() const { return get_req<Message>(); }
152 int get_req_type() const {
155 return request->get_type();
158 ConnectionRef get_connection() { return con; }
160 void set_session(MonSession *s) {
162 // we will be rewriting the existing session; drop the ref.
169 session = static_cast<MonSession*>(s->get());
173 bool is_src_mon() const {
174 return (con && con->get_peer_type() & CEPH_ENTITY_TYPE_MON);
177 typedef boost::intrusive_ptr<MonOpRequest> Ref;
179 void set_op_type(op_type_t t) {
182 void set_type_service() {
183 set_op_type(OP_TYPE_SERVICE);
185 void set_type_monitor() {
186 set_op_type(OP_TYPE_MONITOR);
188 void set_type_paxos() {
189 set_op_type(OP_TYPE_PAXOS);
191 void set_type_election() {
192 set_op_type(OP_TYPE_ELECTION);
194 void set_type_command() {
195 set_op_type(OP_TYPE_COMMAND);
198 op_type_t get_op_type() {
202 bool is_type_service() {
203 return (get_op_type() == OP_TYPE_SERVICE);
205 bool is_type_monitor() {
206 return (get_op_type() == OP_TYPE_MONITOR);
208 bool is_type_paxos() {
209 return (get_op_type() == OP_TYPE_PAXOS);
211 bool is_type_election() {
212 return (get_op_type() == OP_TYPE_ELECTION);
214 bool is_type_command() {
215 return (get_op_type() == OP_TYPE_COMMAND);
219 typedef MonOpRequest::Ref MonOpRequestRef;
221 struct C_MonOp : public Context
225 explicit C_MonOp(MonOpRequestRef o) :
228 void finish(int r) override {
229 if (op && r == -ECANCELED) {
230 op->mark_event("callback canceled");
231 } else if (op && r == -EAGAIN) {
232 op->mark_event("callback retry");
233 } else if (op && r == 0) {
234 op->mark_event("callback finished");
239 void mark_op_event(const string &event) {
241 op->mark_event_string(event);
244 virtual void _finish(int r) = 0;
247 #endif /* MON_OPREQUEST_H_ */