1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#pragma once
#include <seastar/core/future.hh>
#include <boost/intrusive/list.hpp>
#include <boost/intrusive_ptr.hpp>
#include "osd/osd_op_util.h"
#include "crimson/net/Connection.h"
#include "crimson/osd/object_context.h"
#include "crimson/osd/osdmap_gate.h"
#include "crimson/osd/osd_operation.h"
#include "crimson/osd/osd_operations/client_request_common.h"
#include "crimson/osd/pg_activation_blocker.h"
#include "crimson/osd/pg_map.h"
#include "crimson/osd/scrub/pg_scrubber.h"
#include "crimson/common/type_helpers.h"
#include "crimson/common/utility.h"
#include "messages/MOSDOp.h"
namespace crimson::osd {
class PG;
class OSD;
class ShardServices;
class ClientRequest final : public PhasedOperationT<ClientRequest>,
private CommonClientRequest {
// Initially set to primary core, updated to pg core after with_pg()
ShardServices *shard_services = nullptr;
crimson::net::ConnectionRef l_conn;
crimson::net::ConnectionXcoreRef r_conn;
// must be after conn due to ConnectionPipeline's life-time
Ref<MOSDOp> m;
OpInfo op_info;
seastar::promise<> on_complete;
unsigned instance_id = 0;
public:
class PGPipeline : public CommonPGPipeline {
public:
struct AwaitMap : OrderedExclusivePhaseT<AwaitMap> {
static constexpr auto type_name = "ClientRequest::PGPipeline::await_map";
} await_map;
struct SendReply : OrderedExclusivePhaseT<SendReply> {
static constexpr auto type_name = "ClientRequest::PGPipeline::send_reply";
} send_reply;
friend class ClientRequest;
friend class LttngBackend;
friend class HistoricBackend;
friend class ReqRequest;
friend class LogMissingRequest;
friend class LogMissingRequestReply;
};
/**
* instance_handle_t
*
* Client request is, at present, the only Operation which can be requeued.
* This is, mostly, fine. However, reusing the PipelineHandle or
* BlockingEvent structures before proving that the prior instance has stopped
* can create hangs or crashes due to violations of the BlockerT and
* PipelineHandle invariants.
*
* To solve this, we create an instance_handle_t which contains the events
* for the portion of execution that can be rerun as well as the
* PipelineHandle. ClientRequest::with_pg_int grabs a reference to the current
* instance_handle_t and releases its PipelineHandle in the finally block.
* On requeue, we create a new instance_handle_t with a fresh PipelineHandle
* and events tuple and use it and use it for the next invocation of
* with_pg_int.
*/
std::tuple<
StartEvent,
ConnectionPipeline::AwaitActive::BlockingEvent,
ConnectionPipeline::AwaitMap::BlockingEvent,
OSD_OSDMapGate::OSDMapBlocker::BlockingEvent,
ConnectionPipeline::GetPGMapping::BlockingEvent,
PerShardPipeline::CreateOrWaitPG::BlockingEvent,
PGMap::PGCreationBlockingEvent,
CompletionEvent
> tracking_events;
class instance_handle_t : public boost::intrusive_ref_counter<instance_handle_t> {
public:
// intrusive_ptr because seastar::lw_shared_ptr includes a cpu debug check
// that we will fail since the core on which we allocate the request may not
// be the core on which we perform with_pg_int. This is harmless, since we
// don't leave any references on the source core, so we just bypass it by using
// intrusive_ptr instead.
using ref_t = boost::intrusive_ptr<instance_handle_t>;
PipelineHandle handle;
std::tuple<
PGPipeline::AwaitMap::BlockingEvent,
PG_OSDMapGate::OSDMapBlocker::BlockingEvent,
PGPipeline::WaitForActive::BlockingEvent,
PGActivationBlocker::BlockingEvent,
PGPipeline::RecoverMissing::BlockingEvent,
scrub::PGScrubber::BlockingEvent,
PGPipeline::CheckAlreadyCompleteGetObc::BlockingEvent,
PGPipeline::LockOBC::BlockingEvent,
PGPipeline::Process::BlockingEvent,
PGPipeline::WaitRepop::BlockingEvent,
PGPipeline::SendReply::BlockingEvent,
CompletionEvent
> pg_tracking_events;
template <class BlockingEventT>
typename BlockingEventT::template Trigger<ClientRequest>
get_trigger(ClientRequest &op) {
return {std::get<BlockingEventT>(pg_tracking_events), op};
}
template <typename BlockingEventT, typename InterruptorT=void, typename F>
auto with_blocking_event(F &&f, ClientRequest &op) {
auto ret = std::forward<F>(f)(get_trigger<BlockingEventT>(op));
if constexpr (std::is_same_v<InterruptorT, void>) {
return ret;
} else {
using ret_t = decltype(ret);
return typename InterruptorT::template futurize_t<ret_t>{std::move(ret)};
}
}
template <typename InterruptorT=void, typename StageT>
auto enter_stage(StageT &stage, ClientRequest &op) {
return this->template with_blocking_event<
typename StageT::BlockingEvent,
InterruptorT>(
[&stage, this](auto &&trigger) {
return handle.template enter<ClientRequest>(
stage, std::move(trigger));
}, op);
}
template <typename StageT>
void enter_stage_sync(StageT &stage, ClientRequest &op) {
handle.template enter_sync<ClientRequest>(
stage, get_trigger<typename StageT::BlockingEvent>(op));
}
template <
typename InterruptorT=void, typename BlockingObj, typename Method,
typename... Args>
auto enter_blocker(
ClientRequest &op, BlockingObj &obj, Method method, Args&&... args) {
return this->template with_blocking_event<
typename BlockingObj::Blocker::BlockingEvent,
InterruptorT>(
[&obj, method,
args=std::forward_as_tuple(std::move(args)...)](auto &&trigger) mutable {
return apply_method_to_tuple(
obj, method,
std::tuple_cat(
std::forward_as_tuple(std::move(trigger)),
std::move(args))
);
}, op);
}
};
instance_handle_t::ref_t instance_handle;
void reset_instance_handle() {
instance_handle = new instance_handle_t;
}
auto get_instance_handle() { return instance_handle; }
auto get_instance_handle() const { return instance_handle; }
std::set<snapid_t> snaps_need_to_recover() {
std::set<snapid_t> ret;
auto target = m->get_hobj();
if (!target.is_head()) {
ret.insert(target.snap);
}
for (auto &op : m->ops) {
if (op.op.op == CEPH_OSD_OP_ROLLBACK) {
ret.insert((snapid_t)op.op.snap.snapid);
}
}
return ret;
}
using ordering_hook_t = boost::intrusive::list_member_hook<>;
ordering_hook_t ordering_hook;
class Orderer {
using list_t = boost::intrusive::list<
ClientRequest,
boost::intrusive::member_hook<
ClientRequest,
typename ClientRequest::ordering_hook_t,
&ClientRequest::ordering_hook>
>;
list_t list;
public:
void add_request(ClientRequest &request) {
assert(!request.ordering_hook.is_linked());
intrusive_ptr_add_ref(&request);
list.push_back(request);
}
void remove_request(ClientRequest &request) {
assert(request.ordering_hook.is_linked());
list.erase(list_t::s_iterator_to(request));
intrusive_ptr_release(&request);
}
void requeue(Ref<PG> pg);
void clear_and_cancel(PG &pg);
};
void complete_request();
static constexpr OperationTypeCode type = OperationTypeCode::client_request;
ClientRequest(
ShardServices &shard_services,
crimson::net::ConnectionRef, Ref<MOSDOp> &&m);
~ClientRequest();
void print(std::ostream &) const final;
void dump_detail(Formatter *f) const final;
static constexpr bool can_create() { return false; }
spg_t get_pgid() const {
return m->get_spg();
}
PipelineHandle &get_handle() { return instance_handle->handle; }
epoch_t get_epoch() const { return m->get_min_epoch(); }
ConnectionPipeline &get_connection_pipeline();
PerShardPipeline &get_pershard_pipeline(ShardServices &);
crimson::net::Connection &get_local_connection() {
assert(l_conn);
assert(!r_conn);
return *l_conn;
};
crimson::net::Connection &get_foreign_connection() {
assert(r_conn);
assert(!l_conn);
return *r_conn;
};
crimson::net::ConnectionFFRef prepare_remote_submission() {
assert(l_conn);
assert(!r_conn);
auto ret = seastar::make_foreign(std::move(l_conn));
l_conn.reset();
return ret;
}
void finish_remote_submission(crimson::net::ConnectionFFRef conn) {
assert(conn);
assert(!l_conn);
assert(!r_conn);
r_conn = make_local_shared_foreign(std::move(conn));
}
interruptible_future<> with_pg_process_interruptible(
Ref<PG> pgref, const unsigned instance_id, instance_handle_t &ihref);
seastar::future<> with_pg_process(Ref<PG> pg);
public:
seastar::future<> with_pg(
ShardServices &shard_services, Ref<PG> pgref);
private:
template <typename FuncT>
interruptible_future<> with_sequencer(FuncT&& func);
interruptible_future<> reply_op_error(const Ref<PG>& pg, int err);
interruptible_future<> do_process(
instance_handle_t &ihref,
Ref<PG> pg,
crimson::osd::ObjectContextRef obc,
unsigned this_instance_id);
::crimson::interruptible::interruptible_future<
::crimson::osd::IOInterruptCondition> process_pg_op(
Ref<PG> pg);
interruptible_future<>
recover_missing_snaps(
Ref<PG> pg,
instance_handle_t &ihref,
ObjectContextRef head,
std::set<snapid_t> &snaps);
::crimson::interruptible::interruptible_future<
::crimson::osd::IOInterruptCondition> process_op(
instance_handle_t &ihref,
Ref<PG> pg,
unsigned this_instance_id);
bool is_pg_op() const;
PGPipeline &client_pp(PG &pg);
template <typename Errorator>
using interruptible_errorator =
::crimson::interruptible::interruptible_errorator<
::crimson::osd::IOInterruptCondition,
Errorator>;
bool is_misdirected(const PG& pg) const;
const SnapContext get_snapc(
PG &pg,
crimson::osd::ObjectContextRef obc) const;
public:
friend class LttngBackend;
friend class HistoricBackend;
auto get_started() const {
return get_event<StartEvent>().get_timestamp();
};
auto get_completed() const {
return get_event<CompletionEvent>().get_timestamp();
};
void put_historic() const;
};
}
#if FMT_VERSION >= 90000
template <> struct fmt::formatter<crimson::osd::ClientRequest> : fmt::ostream_formatter {};
#endif
|