]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/osd/osd_operations/background_recovery.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crimson / osd / osd_operations / background_recovery.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #pragma once
5
6 #include <boost/statechart/event_base.hpp>
7
8 #include "crimson/net/Connection.h"
9 #include "crimson/osd/osd_operation.h"
10 #include "crimson/osd/recovery_backend.h"
11 #include "crimson/common/type_helpers.h"
12 #include "crimson/osd/osd_operations/peering_event.h"
13 #include "crimson/osd/pg.h"
14
15 namespace crimson::osd {
16 class PG;
17 class ShardServices;
18
19 template <class T>
20 class BackgroundRecoveryT : public PhasedOperationT<T> {
21 public:
22 static constexpr OperationTypeCode type = OperationTypeCode::background_recovery;
23
24 BackgroundRecoveryT(
25 Ref<PG> pg,
26 ShardServices &ss,
27 epoch_t epoch_started,
28 crimson::osd::scheduler::scheduler_class_t scheduler_class, float delay = 0);
29
30 virtual void print(std::ostream &) const;
31 seastar::future<> start();
32
33 protected:
34 Ref<PG> pg;
35 const epoch_t epoch_started;
36 float delay = 0;
37
38 private:
39 virtual void dump_detail(Formatter *f) const;
40 crimson::osd::scheduler::params_t get_scheduler_params() const {
41 return {
42 1, // cost
43 0, // owner
44 scheduler_class
45 };
46 }
47 using do_recovery_ret_t = typename PhasedOperationT<T>::template interruptible_future<bool>;
48 virtual do_recovery_ret_t do_recovery() = 0;
49 ShardServices &ss;
50 const crimson::osd::scheduler::scheduler_class_t scheduler_class;
51 };
52
53 /// represent a recovery initiated for serving a client request
54 ///
55 /// unlike @c PglogBasedRecovery and @c BackfillRecovery,
56 /// @c UrgentRecovery is not throttled by the scheduler. and it
57 /// utilizes @c RecoveryBackend directly to recover the unreadable
58 /// object.
59 class UrgentRecovery final : public BackgroundRecoveryT<UrgentRecovery> {
60 public:
61 UrgentRecovery(
62 const hobject_t& soid,
63 const eversion_t& need,
64 Ref<PG> pg,
65 ShardServices& ss,
66 epoch_t epoch_started);
67 void print(std::ostream&) const final;
68
69 std::tuple<
70 OperationThrottler::BlockingEvent,
71 RecoveryBackend::RecoveryBlockingEvent
72 > tracking_events;
73
74 private:
75 void dump_detail(Formatter* f) const final;
76 interruptible_future<bool> do_recovery() override;
77 const hobject_t soid;
78 const eversion_t need;
79 };
80
81 class PglogBasedRecovery final : public BackgroundRecoveryT<PglogBasedRecovery> {
82 public:
83 PglogBasedRecovery(
84 Ref<PG> pg,
85 ShardServices &ss,
86 epoch_t epoch_started,
87 float delay = 0);
88
89 std::tuple<
90 OperationThrottler::BlockingEvent,
91 RecoveryBackend::RecoveryBlockingEvent
92 > tracking_events;
93
94 private:
95 interruptible_future<bool> do_recovery() override;
96 };
97
98 class BackfillRecovery final : public BackgroundRecoveryT<BackfillRecovery> {
99 public:
100
101 template <class EventT>
102 BackfillRecovery(
103 Ref<PG> pg,
104 ShardServices &ss,
105 epoch_t epoch_started,
106 const EventT& evt);
107
108 PipelineHandle& get_handle() { return handle; }
109
110 std::tuple<
111 OperationThrottler::BlockingEvent,
112 PGPeeringPipeline::Process::BlockingEvent
113 > tracking_events;
114
115 private:
116 boost::intrusive_ptr<const boost::statechart::event_base> evt;
117 PipelineHandle handle;
118
119 static PGPeeringPipeline &bp(PG &pg);
120 interruptible_future<bool> do_recovery() override;
121 };
122
123 template <class EventT>
124 BackfillRecovery::BackfillRecovery(
125 Ref<PG> pg,
126 ShardServices &ss,
127 const epoch_t epoch_started,
128 const EventT& evt)
129 : BackgroundRecoveryT(
130 std::move(pg),
131 ss,
132 epoch_started,
133 crimson::osd::scheduler::scheduler_class_t::background_best_effort),
134 evt(evt.intrusive_from_this())
135 {}
136
137 }
138
139 #if FMT_VERSION >= 90000
140 template <> struct fmt::formatter<crimson::osd::BackfillRecovery> : fmt::ostream_formatter {};
141 template <> struct fmt::formatter<crimson::osd::PglogBasedRecovery> : fmt::ostream_formatter {};
142 template <> struct fmt::formatter<crimson::osd::UrgentRecovery> : fmt::ostream_formatter {};
143 template <class T> struct fmt::formatter<crimson::osd::BackgroundRecoveryT<T>> : fmt::ostream_formatter {};
144 #endif