]> git.proxmox.com Git - ceph.git/blob - ceph/src/osd/OpRequest.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / osd / OpRequest.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2012 New Dream Network/Sage Weil <sage@newdream.net>
7 *
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.
12 */
13
14 #ifndef OPREQUEST_H_
15 #define OPREQUEST_H_
16
17 #include "osd/osd_op_util.h"
18 #include "osd/osd_types.h"
19 #include "common/TrackedOp.h"
20 #ifdef HAVE_JAEGER
21 #include "common/tracer.h"
22 #endif
23
24 /**
25 * The OpRequest takes in a Message* and takes over a single reference
26 * to it, which it puts() when destroyed.
27 */
28 struct OpRequest : public TrackedOp {
29 friend class OpTracker;
30
31 private:
32 OpInfo op_info;
33
34 public:
35 int maybe_init_op_info(const OSDMap &osdmap);
36
37 auto get_flags() const { return op_info.get_flags(); }
38 bool op_info_needs_init() const { return op_info.get_flags() == 0; }
39 bool check_rmw(int flag) const { return op_info.check_rmw(flag); }
40 bool may_read() const { return op_info.may_read(); }
41 bool may_write() const { return op_info.may_write(); }
42 bool may_cache() const { return op_info.may_cache(); }
43 bool rwordered_forced() const { return op_info.rwordered_forced(); }
44 bool rwordered() const { return op_info.rwordered(); }
45 bool includes_pg_op() const { return op_info.includes_pg_op(); }
46 bool need_read_cap() const { return op_info.need_read_cap(); }
47 bool need_write_cap() const { return op_info.need_write_cap(); }
48 bool need_promote() const { return op_info.need_promote(); }
49 bool need_skip_handle_cache() const { return op_info.need_skip_handle_cache(); }
50 bool need_skip_promote() const { return op_info.need_skip_promote(); }
51 bool allows_returnvec() const { return op_info.allows_returnvec(); }
52
53 std::vector<OpInfo::ClassInfo> classes() const {
54 return op_info.get_classes();
55 }
56
57 void _dump(ceph::Formatter *f) const override;
58
59 bool has_feature(uint64_t f) const {
60 return request->get_connection()->has_feature(f);
61 }
62
63 private:
64 Message *request; /// the logical request we are tracking
65 osd_reqid_t reqid;
66 entity_inst_t req_src_inst;
67 uint8_t hit_flag_points;
68 uint8_t latest_flag_point;
69 utime_t dequeued_time;
70 static const uint8_t flag_queued_for_pg=1 << 0;
71 static const uint8_t flag_reached_pg = 1 << 1;
72 static const uint8_t flag_delayed = 1 << 2;
73 static const uint8_t flag_started = 1 << 3;
74 static const uint8_t flag_sub_op_sent = 1 << 4;
75 static const uint8_t flag_commit_sent = 1 << 5;
76
77 OpRequest(Message *req, OpTracker *tracker);
78
79 protected:
80 void _dump_op_descriptor_unlocked(std::ostream& stream) const override;
81 void _unregistered() override;
82 bool filter_out(const std::set<std::string>& filters) override;
83
84 public:
85 ~OpRequest() override {
86 request->put();
87 }
88
89 bool check_send_map = true; ///< true until we check if sender needs a map
90 epoch_t sent_epoch = 0; ///< client's map epoch
91 epoch_t min_epoch = 0; ///< min epoch needed to handle this msg
92
93 bool hitset_inserted;
94 #ifdef HAVE_JAEGER
95 jspan osd_parent_span = nullptr;
96 void set_osd_parent_span(jspan& span) {
97 if(osd_parent_span){
98 jaeger_tracing::finish_span(osd_parent_span);
99 }
100 osd_parent_span = move(span);
101 }
102 #else
103 void set_osd_parent_span(...) {}
104 #endif
105 template<class T>
106 const T* get_req() const { return static_cast<const T*>(request); }
107
108 const Message *get_req() const { return request; }
109 Message *get_nonconst_req() { return request; }
110
111 entity_name_t get_source() {
112 if (request) {
113 return request->get_source();
114 } else {
115 return entity_name_t();
116 }
117 }
118
119 std::string_view state_string() const override {
120 switch(latest_flag_point) {
121 case flag_queued_for_pg: return "queued for pg";
122 case flag_reached_pg: return "reached pg";
123 case flag_delayed: return "delayed";
124 case flag_started: return "started";
125 case flag_sub_op_sent: return "waiting for sub ops";
126 case flag_commit_sent: return "commit sent; apply or cleanup";
127 default: break;
128 }
129 return "no flag points reached";
130 }
131
132 void mark_queued_for_pg() {
133 mark_flag_point(flag_queued_for_pg, "queued_for_pg");
134 }
135 void mark_reached_pg() {
136 mark_flag_point(flag_reached_pg, "reached_pg");
137 }
138 void mark_delayed(const std::string& s) {
139 mark_flag_point_string(flag_delayed, s);
140 }
141 void mark_started() {
142 mark_flag_point(flag_started, "started");
143 }
144 void mark_sub_op_sent(const std::string& s) {
145 mark_flag_point_string(flag_sub_op_sent, s);
146 }
147 void mark_commit_sent() {
148 mark_flag_point(flag_commit_sent, "commit_sent");
149 }
150
151 utime_t get_dequeued_time() const {
152 return dequeued_time;
153 }
154 void set_dequeued_time(utime_t deq_time) {
155 dequeued_time = deq_time;
156 }
157
158 osd_reqid_t get_reqid() const {
159 return reqid;
160 }
161
162 typedef boost::intrusive_ptr<OpRequest> Ref;
163
164 private:
165 void mark_flag_point(uint8_t flag, const char *s);
166 void mark_flag_point_string(uint8_t flag, const std::string& s);
167 };
168
169 typedef OpRequest::Ref OpRequestRef;
170
171 #endif /* OPREQUEST_H_ */