Skip to content

Commit 6f6a737

Browse files
authored
Merge pull request ceph#55131 from ronen-fr/wip-rf-reserver
osd/scrub: partial implementation of scrub reserver Reviewed-by: Samuel Just <[email protected]>-
2 parents f63c485 + 5970ff6 commit 6f6a737

File tree

7 files changed

+498
-117
lines changed

7 files changed

+498
-117
lines changed

src/common/AsyncReserver.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,39 @@ class AsyncReserver {
264264
do_queues();
265265
}
266266

267+
/**
268+
* The synchronous version of request_reservation
269+
* Used to handle requests from OSDs that do not support the async interface
270+
* to scrub replica reservations, but still must count towards the max
271+
* active reservations.
272+
*/
273+
bool request_reservation_or_fail(
274+
T item, ///< [in] reservation key
275+
Context *on_reserved ///< [in] callback to be called on reservation
276+
)
277+
{
278+
std::lock_guard l(lock);
279+
ceph_assert(!queue_pointers.count(item) && !in_progress.count(item));
280+
281+
if (in_progress.size() >= max_allowed) {
282+
rdout(10) << fmt::format("{}: request: {} denied", __func__, item)
283+
<< dendl;
284+
return false;
285+
}
286+
287+
const unsigned prio = UINT_MAX;
288+
Reservation r(item, prio, on_reserved, nullptr);
289+
queues[prio].push_back(r);
290+
queue_pointers.insert(std::make_pair(
291+
item, std::make_pair(prio, --(queues[prio]).end())));
292+
do_queues();
293+
// the new request should be in_progress now
294+
ceph_assert(in_progress.count(item));
295+
rdout(10) << fmt::format("{}: request: {} granted", __func__, item)
296+
<< dendl;
297+
return true;
298+
}
299+
267300
/**
268301
* Cancels reservation
269302
*

src/messages/MOSDScrubReserve.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
class MOSDScrubReserve : public MOSDFastDispatchOp {
2121
private:
22-
static constexpr int HEAD_VERSION = 2;
22+
static constexpr int HEAD_VERSION = 3;
2323
static constexpr int COMPAT_VERSION = 1;
2424
public:
2525
using reservation_nonce_t = uint32_t;
@@ -35,6 +35,9 @@ class MOSDScrubReserve : public MOSDFastDispatchOp {
3535
int32_t type;
3636
pg_shard_t from;
3737
reservation_nonce_t reservation_nonce{0};
38+
/// 'false' if the (legacy) primary is expecting an immediate
39+
/// granted / denied response
40+
bool wait_for_resources{false};
3841

3942
epoch_t get_map_epoch() const override {
4043
return map_epoch;
@@ -48,12 +51,12 @@ class MOSDScrubReserve : public MOSDFastDispatchOp {
4851
map_epoch(0), type(-1) {}
4952
MOSDScrubReserve(spg_t pgid,
5053
epoch_t map_epoch,
51-
int type,
54+
ReserveMsgOp type_code,
5255
pg_shard_t from,
5356
reservation_nonce_t nonce)
5457
: MOSDFastDispatchOp{MSG_OSD_SCRUB_RESERVE, HEAD_VERSION, COMPAT_VERSION},
5558
pgid(pgid), map_epoch(map_epoch),
56-
type(type), from(from), reservation_nonce{nonce} {}
59+
type(static_cast<int32_t>(type_code)), from(from), reservation_nonce{nonce} {}
5760

5861
std::string_view get_type_name() const {
5962
return "MOSDScrubReserve";
@@ -63,7 +66,7 @@ class MOSDScrubReserve : public MOSDFastDispatchOp {
6366
out << "MOSDScrubReserve(" << pgid << " ";
6467
switch (type) {
6568
case REQUEST:
66-
out << "REQUEST ";
69+
out << (wait_for_resources ? "QREQUEST " : "REQUEST ");
6770
break;
6871
case GRANT:
6972
out << "GRANT ";
@@ -89,10 +92,16 @@ class MOSDScrubReserve : public MOSDFastDispatchOp {
8992
decode(from, p);
9093
if (header.version >= 2) {
9194
decode(reservation_nonce, p);
95+
if (header.version >= 3) {
96+
decode(wait_for_resources, p);
97+
} else {
98+
wait_for_resources = false;
99+
}
92100
} else {
93101
// a zero nonce (identifying legacy senders) is ignored when
94102
// checking the request for obsolescence
95103
reservation_nonce = 0;
104+
wait_for_resources = false;
96105
}
97106
}
98107

@@ -103,6 +112,7 @@ class MOSDScrubReserve : public MOSDFastDispatchOp {
103112
encode(type, payload);
104113
encode(from, payload);
105114
encode(reservation_nonce, payload);
115+
encode(wait_for_resources, payload);
106116
}
107117
private:
108118
template<class T, typename... Args>

src/osd/scrubber/osd_scrub.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ bool OsdScrub::inc_scrubs_remote(pg_t pgid)
473473
return m_resource_bookkeeper.inc_scrubs_remote(pgid);
474474
}
475475

476+
void OsdScrub::enqueue_remote_reservation(pg_t pgid)
477+
{
478+
m_resource_bookkeeper.enqueue_remote_reservation(pgid);
479+
}
480+
476481
void OsdScrub::dec_scrubs_remote(pg_t pgid)
477482
{
478483
m_resource_bookkeeper.dec_scrubs_remote(pgid);

src/osd/scrubber/osd_scrub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class OsdScrub {
7070
bool is_high_priority);
7171
void dec_scrubs_local();
7272
bool inc_scrubs_remote(pg_t pgid);
73+
void enqueue_remote_reservation(pg_t pgid);
7374
void dec_scrubs_remote(pg_t pgid);
7475

7576
// counting the number of PGs stuck while scrubbing, waiting for objects

0 commit comments

Comments
 (0)