From 601c4b5a310a687f8e979a41c28dd33affa05479 Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Wed, 29 Nov 2023 07:16:24 -0600 Subject: [PATCH] osd/scrub: use OpCarryingEvent for scrub events carrying common data Copied from a similar implementation in Crimson. The payload includes the MOSDScrub* op, and the 'from' id. Signed-off-by: Ronen Friedman Split from "osd/scrub: move responsibility for clearing the 'being reserved' state" --- src/osd/scrubber/scrub_machine.h | 63 ++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/src/osd/scrubber/scrub_machine.h b/src/osd/scrubber/scrub_machine.h index a67a85b8e112b..fcca0d2cc40d8 100644 --- a/src/osd/scrubber/scrub_machine.h +++ b/src/osd/scrubber/scrub_machine.h @@ -48,39 +48,54 @@ namespace mpl = ::boost::mpl; void on_event_creation(std::string_view nm); void on_event_discard(std::string_view nm); -// reservation grant/reject events carry the peer's response: -/// a replica has granted our reservation request -struct ReplicaGrant : sc::event { - OpRequestRef m_op; - pg_shard_t m_from; - ReplicaGrant(OpRequestRef op, pg_shard_t from) : m_op{op}, m_from{from} +template +struct OpCarryingEvent : sc::event { + static constexpr const char* event_name = "<>"; + const OpRequestRef m_op; + const pg_shard_t m_from; + OpCarryingEvent(OpRequestRef op, pg_shard_t from) : m_op{op}, m_from{from} { - on_event_creation("ReplicaGrant"); + on_event_creation(static_cast(this)->event_name); } + + OpCarryingEvent(const OpCarryingEvent&) = default; + OpCarryingEvent(OpCarryingEvent&&) = default; + OpCarryingEvent& operator=(const OpCarryingEvent&) = default; + OpCarryingEvent& operator=(OpCarryingEvent&&) = default; + void print(std::ostream* out) const { - *out << fmt::format("ReplicaGrant(from: {})", m_from); + *out << fmt::format("{} (from: {})", EV::event_name, m_from); } - std::string_view print() const { return "ReplicaGrant"; } - ~ReplicaGrant() { on_event_discard("ReplicaGrant"); } + std::string_view print() const { return EV::event_name; } + ~OpCarryingEvent() { on_event_discard(EV::event_name); } }; -/// a replica has denied our reservation request -struct ReplicaReject : sc::event { - OpRequestRef m_op; - pg_shard_t m_from; - ReplicaReject(OpRequestRef op, pg_shard_t from) : m_op{op}, m_from{from} - { - on_event_creation("ReplicaReject"); +#define OP_EV(T) \ + struct T : OpCarryingEvent { \ + static constexpr const char* event_name = #T; \ + template \ + T(Args&&... args) : OpCarryingEvent(std::forward(args)...) \ + { \ + } \ } - void print(std::ostream* out) const - { - *out << fmt::format("ReplicaReject(from: {})", m_from); - } - std::string_view print() const { return "ReplicaReject"; } - ~ReplicaReject() { on_event_discard("ReplicaReject"); } -}; + + +// reservation events carry peer's request/response data: + +/// a replica has granted our reservation request +OP_EV(ReplicaGrant); + +/// a replica has denied our reservation request +OP_EV(ReplicaReject); + +/// received Primary request for scrub reservation +OP_EV(ReplicaReserveReq); + +/// explicit release request from the Primary +OP_EV(ReplicaRelease); + #define MEV(E) \ struct E : sc::event { \ -- 2.39.5