]>
git.proxmox.com Git - ceph.git/blob - ceph/src/mon/MonOpRequest.h
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 "mon/Session.h"
22 #include "msg/Message.h"
24 struct MonOpRequest
: public TrackedOp
{
25 friend class OpTracker
;
27 void mark_dispatch() {
28 mark_event("monitor_dispatch");
30 void mark_wait_for_quorum() {
31 mark_event("wait_for_quorum");
34 mark_event("monitor_zap");
36 void mark_forwarded() {
37 mark_event("forwarded");
38 forwarded_to_leader
= true;
41 void mark_svc_event(const std::string
&service
, const std::string
&event
) {
42 std::string s
= service
;
43 s
.append(":").append(event
);
47 void mark_logmon_event(const std::string
&event
) {
48 mark_svc_event("logm", event
);
50 void mark_osdmon_event(const std::string
&event
) {
51 mark_svc_event("osdmap", event
);
53 void mark_pgmon_event(const std::string
&event
) {
54 mark_svc_event("pgmap", event
);
56 void mark_mdsmon_event(const std::string
&event
) {
57 mark_svc_event("mdsmap", event
);
59 void mark_authmon_event(const std::string
&event
) {
60 mark_svc_event("auth", event
);
62 void mark_paxos_event(const std::string
&event
) {
63 mark_svc_event("paxos", event
);
68 OP_TYPE_NONE
= 0, ///< no type defined (default)
69 OP_TYPE_SERVICE
, ///< belongs to a Paxos Service or similar
70 OP_TYPE_MONITOR
, ///< belongs to the Monitor class
71 OP_TYPE_ELECTION
, ///< belongs to the Elector class
72 OP_TYPE_PAXOS
, ///< refers to Paxos messages
73 OP_TYPE_COMMAND
, ///< is a command
76 MonOpRequest(const MonOpRequest
&other
) = delete;
77 MonOpRequest
& operator = (const MonOpRequest
&other
) = delete;
81 utime_t dequeued_time
;
82 RefCountedPtr session
;
84 bool forwarded_to_leader
;
87 MonOpRequest(Message
*req
, OpTracker
*tracker
) :
89 req
->get_recv_stamp().is_zero() ?
90 ceph_clock_now() : req
->get_recv_stamp()),
93 forwarded_to_leader(false),
97 con
= req
->get_connection();
99 session
= con
->get_priv();
104 void _dump(ceph::Formatter
*f
) const override
{
106 f
->open_array_section("events");
107 std::lock_guard
l(lock
);
108 for (auto i
= events
.begin(); i
!= events
.end(); ++i
) {
109 f
->open_object_section("event");
110 f
->dump_string("event", i
->str
);
111 f
->dump_stream("time") << i
->stamp
;
115 if (i_next
< events
.end()) {
116 f
->dump_float("duration", i_next
->stamp
- i
->stamp
);
118 f
->dump_float("duration", events
.rbegin()->stamp
- get_initiated());
124 f
->open_object_section("info");
125 f
->dump_int("seq", seq
);
126 f
->dump_bool("src_is_mon", is_src_mon());
127 f
->dump_stream("source") << request
->get_source_inst();
128 f
->dump_bool("forwarded_to_leader", forwarded_to_leader
);
134 void _dump_op_descriptor(std::ostream
& stream
) const override
{
135 get_req()->print(stream
);
139 ~MonOpRequest() override
{
143 MonSession
*get_session() const {
144 return static_cast<MonSession
*>(session
.get());
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
) {
164 bool is_src_mon() const {
165 return (con
&& con
->get_peer_type() & CEPH_ENTITY_TYPE_MON
);
168 typedef boost::intrusive_ptr
<MonOpRequest
> Ref
;
170 void set_op_type(op_type_t t
) {
173 void set_type_service() {
174 set_op_type(OP_TYPE_SERVICE
);
176 void set_type_monitor() {
177 set_op_type(OP_TYPE_MONITOR
);
179 void set_type_paxos() {
180 set_op_type(OP_TYPE_PAXOS
);
182 void set_type_election_or_ping() {
183 set_op_type(OP_TYPE_ELECTION
);
185 void set_type_command() {
186 set_op_type(OP_TYPE_COMMAND
);
189 op_type_t
get_op_type() {
193 bool is_type_service() {
194 return (get_op_type() == OP_TYPE_SERVICE
);
196 bool is_type_monitor() {
197 return (get_op_type() == OP_TYPE_MONITOR
);
199 bool is_type_paxos() {
200 return (get_op_type() == OP_TYPE_PAXOS
);
202 bool is_type_election_or_ping() {
203 return (get_op_type() == OP_TYPE_ELECTION
);
205 bool is_type_command() {
206 return (get_op_type() == OP_TYPE_COMMAND
);
210 typedef MonOpRequest::Ref MonOpRequestRef
;
212 struct C_MonOp
: public Context
216 explicit C_MonOp(MonOpRequestRef o
) :
219 void finish(int r
) override
{
220 if (op
&& r
== -ECANCELED
) {
221 op
->mark_event("callback canceled");
222 } else if (op
&& r
== -EAGAIN
) {
223 op
->mark_event("callback retry");
224 } else if (op
&& r
== 0) {
225 op
->mark_event("callback finished");
230 void mark_op_event(const std::string
&event
) {
232 op
->mark_event(event
);
235 virtual void _finish(int r
) = 0;
238 #endif /* MON_OPREQUEST_H_ */