osd: move M{Backfill,Recovery}Reserve event logic into message

Better encapsulation!

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2017-12-05 21:33:40 -06:00
parent 3b904547fb
commit 25da186ab8
3 changed files with 114 additions and 99 deletions

View File

@ -16,8 +16,9 @@
#define CEPH_MBACKFILL_H
#include "msg/Message.h"
#include "messages/MOSDPeeringOp.h"
class MBackfillReserve : public Message {
class MBackfillReserve : public MOSDPeeringOp {
static const int HEAD_VERSION = 4;
static const int COMPAT_VERSION = 4;
public:
@ -35,13 +36,65 @@ public:
uint32_t type;
uint32_t priority;
spg_t get_spg() const {
return pgid;
}
epoch_t get_map_epoch() const {
return query_epoch;
}
epoch_t get_min_epoch() const {
return query_epoch;
}
PGPeeringEvent *get_event() override {
switch (type) {
case REQUEST:
return new PGPeeringEvent(
query_epoch,
query_epoch,
RequestBackfillPrio(priority));
case GRANT:
return new PGPeeringEvent(
query_epoch,
query_epoch,
RemoteBackfillReserved());
case REJECT:
// NOTE: this is replica -> primary "i reject your request"
// and also primary -> replica "cancel my previously-granted request"
// (for older peers)
// and also replica -> primary "i revoke your reservation"
// (for older peers)
return new PGPeeringEvent(
query_epoch,
query_epoch,
RemoteReservationRejected());
case RELEASE:
return new PGPeeringEvent(
query_epoch,
query_epoch,
RemoteReservationCanceled());
case TOOFULL:
return new PGPeeringEvent(
query_epoch,
query_epoch,
RemoteReservationRevokedTooFull());
case REVOKE:
return new PGPeeringEvent(
query_epoch,
query_epoch,
RemoteReservationRevoked());
default:
ceph_abort();
}
}
MBackfillReserve()
: Message(MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION),
: MOSDPeeringOp(MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION),
query_epoch(0), type(-1), priority(-1) {}
MBackfillReserve(int type,
spg_t pgid,
epoch_t query_epoch, unsigned prio = -1)
: Message(MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION),
: MOSDPeeringOp(MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION),
pgid(pgid), query_epoch(query_epoch),
type(type), priority(prio) {}
@ -49,30 +102,28 @@ public:
return "MBackfillReserve";
}
void print(ostream& out) const override {
out << "MBackfillReserve ";
void inner_print(ostream& out) const override {
switch (type) {
case REQUEST:
out << "REQUEST ";
out << "REQUEST";
break;
case GRANT:
out << "GRANT ";
out << "GRANT";
break;
case REJECT:
out << "REJECT ";
break;
case RELEASE:
out << "RELEASE ";
out << "RELEASE";
break;
case TOOFULL:
out << "TOOFULL ";
out << "TOOFULL";
break;
case REVOKE:
out << "REVOKE ";
out << "REVOKE";
break;
}
out << " pgid: " << pgid << ", query_epoch: " << query_epoch;
if (type == REQUEST) out << ", prio: " << priority;
if (type == REQUEST) out << " prio: " << priority;
return;
}

View File

@ -16,8 +16,9 @@
#define CEPH_MRECOVERY_H
#include "msg/Message.h"
#include "messages/MOSDPeeringOp.h"
class MRecoveryReserve : public Message {
class MRecoveryReserve : public MOSDPeeringOp {
static const int HEAD_VERSION = 3;
static const int COMPAT_VERSION = 2;
public:
@ -32,14 +33,51 @@ public:
uint32_t type;
uint32_t priority = 0;
spg_t get_spg() const {
return pgid;
}
epoch_t get_map_epoch() const {
return query_epoch;
}
epoch_t get_min_epoch() const {
return query_epoch;
}
PGPeeringEvent *get_event() override {
switch (type) {
case REQUEST:
return new PGPeeringEvent(
query_epoch,
query_epoch,
RequestRecoveryPrio(priority));
case GRANT:
return new PGPeeringEvent(
query_epoch,
query_epoch,
RemoteRecoveryReserved());
case RELEASE:
return new PGPeeringEvent(
query_epoch,
query_epoch,
RecoveryDone());
case REVOKE:
return new PGPeeringEvent(
query_epoch,
query_epoch,
DeferRecovery(0.0));
default:
ceph_abort();
}
}
MRecoveryReserve()
: Message(MSG_OSD_RECOVERY_RESERVE, HEAD_VERSION, COMPAT_VERSION),
: MOSDPeeringOp(MSG_OSD_RECOVERY_RESERVE, HEAD_VERSION, COMPAT_VERSION),
query_epoch(0), type(-1) {}
MRecoveryReserve(int type,
spg_t pgid,
epoch_t query_epoch,
unsigned prio = 0)
: Message(MSG_OSD_RECOVERY_RESERVE, HEAD_VERSION, COMPAT_VERSION),
: MOSDPeeringOp(MSG_OSD_RECOVERY_RESERVE, HEAD_VERSION, COMPAT_VERSION),
pgid(pgid), query_epoch(query_epoch),
type(type), priority(prio) {}
@ -47,25 +85,22 @@ public:
return "MRecoveryReserve";
}
void print(ostream& out) const override {
out << "MRecoveryReserve(" << pgid;
void inner_print(ostream& out) const override {
switch (type) {
case REQUEST:
out << " REQUEST";
out << "REQUEST";
break;
case GRANT:
out << " GRANT";
out << "GRANT";
break;
case RELEASE:
out << " RELEASE";
out << "RELEASE";
break;
case REVOKE:
out << " REVOKE";
out << "REVOKE";
break;
}
out << " e" << query_epoch << ")";
if (type == REQUEST) out << ", prio: " << priority;
return;
if (type == REQUEST) out << " prio: " << priority;
}
void decode_payload() override {

View File

@ -8606,7 +8606,7 @@ void OSD::handle_pg_trim(OpRequestRef op)
void OSD::handle_pg_backfill_reserve(OpRequestRef op)
{
const MBackfillReserve *m = static_cast<const MBackfillReserve*>(op->get_req());
MBackfillReserve *m = static_cast<MBackfillReserve*>(op->get_nonconst_req());
assert(m->get_type() == MSG_OSD_BACKFILL_RESERVE);
if (!require_osd_peer(op->get_req()))
@ -8614,58 +8614,14 @@ void OSD::handle_pg_backfill_reserve(OpRequestRef op)
if (!require_same_or_newer_map(op, m->query_epoch, false))
return;
PGPeeringEventRef evt;
if (m->type == MBackfillReserve::REQUEST) {
evt = PGPeeringEventRef(
new PGPeeringEvent(
m->query_epoch,
m->query_epoch,
RequestBackfillPrio(m->priority)));
} else if (m->type == MBackfillReserve::GRANT) {
evt = PGPeeringEventRef(
new PGPeeringEvent(
m->query_epoch,
m->query_epoch,
RemoteBackfillReserved()));
} else if (m->type == MBackfillReserve::REJECT) {
// NOTE: this is replica -> primary "i reject your request"
// and also primary -> replica "cancel my previously-granted request"
// (for older peers)
// and also replica -> primary "i revoke your reservation"
// (for older peers)
evt = PGPeeringEventRef(
new PGPeeringEvent(
m->query_epoch,
m->query_epoch,
RemoteReservationRejected()));
} else if (m->type == MBackfillReserve::RELEASE) {
evt = PGPeeringEventRef(
new PGPeeringEvent(
m->query_epoch,
m->query_epoch,
RemoteReservationCanceled()));
} else if (m->type == MBackfillReserve::TOOFULL) {
evt = PGPeeringEventRef(
new PGPeeringEvent(
m->query_epoch,
m->query_epoch,
RemoteReservationRevokedTooFull()));
} else if (m->type == MBackfillReserve::REVOKE) {
evt = PGPeeringEventRef(
new PGPeeringEvent(
m->query_epoch,
m->query_epoch,
RemoteReservationRevoked()));
} else {
ceph_abort();
}
PGPeeringEventRef evt(m->get_event());
enqueue_peering_evt(m->pgid, evt);
}
void OSD::handle_pg_recovery_reserve(OpRequestRef op)
{
const MRecoveryReserve *m = static_cast<const MRecoveryReserve*>(op->get_req());
MRecoveryReserve *m = static_cast<MRecoveryReserve*>(op->get_nonconst_req());
assert(m->get_type() == MSG_OSD_RECOVERY_RESERVE);
if (!require_osd_peer(op->get_req()))
@ -8673,34 +8629,7 @@ void OSD::handle_pg_recovery_reserve(OpRequestRef op)
if (!require_same_or_newer_map(op, m->query_epoch, false))
return;
PGPeeringEventRef evt;
if (m->type == MRecoveryReserve::REQUEST) {
evt = PGPeeringEventRef(
new PGPeeringEvent(
m->query_epoch,
m->query_epoch,
RequestRecoveryPrio(m->priority)));
} else if (m->type == MRecoveryReserve::GRANT) {
evt = PGPeeringEventRef(
new PGPeeringEvent(
m->query_epoch,
m->query_epoch,
RemoteRecoveryReserved()));
} else if (m->type == MRecoveryReserve::RELEASE) {
evt = PGPeeringEventRef(
new PGPeeringEvent(
m->query_epoch,
m->query_epoch,
RecoveryDone()));
} else if (m->type == MRecoveryReserve::REVOKE) {
evt = PGPeeringEventRef(
new PGPeeringEvent(
m->query_epoch,
m->query_epoch,
DeferRecovery(0.0)));
} else {
ceph_abort();
}
PGPeeringEventRef evt(m->get_event());
enqueue_peering_evt(m->pgid, evt);
}