Skip to content

Commit

Permalink
mon: Rearrange Paxos::dispatch to be a little cleaner
Browse files Browse the repository at this point in the history
The Message is actually always a MMonPaxos (which is not a subtype of
PaxosServiceMessage, so that whole thing was wrong!). This lets
us clean up the switch quite a bit and correct the odd casts
going around.

Signed-off-by: Greg Farnum <gfarnum@redhat.com>
  • Loading branch information
gregsfortytwo committed Aug 19, 2019
1 parent 0dd2d0f commit 0c85f8f
Showing 1 changed file with 35 additions and 39 deletions.
74 changes: 35 additions & 39 deletions src/mon/Paxos.cc
Expand Up @@ -1418,53 +1418,49 @@ void Paxos::dispatch(MonOpRequestRef op)
{
ceph_assert(op->is_type_paxos());
op->mark_paxos_event("dispatch");
PaxosServiceMessage *m = static_cast<PaxosServiceMessage*>(op->get_req());

if (op->get_req()->get_type() != MSG_MON_PAXOS) {
dout(0) << "Got unexpected message type " << op->get_req()->get_type()
<< " in Paxos::dispatch, aborting!" << dendl;
ceph_abort();
}

auto *req = op->get_req<MMonPaxos>();

// election in progress?
if (!mon->is_leader() && !mon->is_peon()) {
dout(5) << "election in progress, dropping " << *m << dendl;
dout(5) << "election in progress, dropping " << *req << dendl;
return;
}

// check sanity
ceph_assert(mon->is_leader() ||
(mon->is_peon() && m->get_source().num() == mon->get_leader()));

switch (m->get_type()) {

case MSG_MON_PAXOS:
{
MMonPaxos *pm = reinterpret_cast<MMonPaxos*>(m);

// NOTE: these ops are defined in messages/MMonPaxos.h
switch (pm->op) {
// learner
case MMonPaxos::OP_COLLECT:
handle_collect(op);
break;
case MMonPaxos::OP_LAST:
handle_last(op);
break;
case MMonPaxos::OP_BEGIN:
handle_begin(op);
break;
case MMonPaxos::OP_ACCEPT:
handle_accept(op);
break;
case MMonPaxos::OP_COMMIT:
handle_commit(op);
break;
case MMonPaxos::OP_LEASE:
handle_lease(op);
break;
case MMonPaxos::OP_LEASE_ACK:
handle_lease_ack(op);
break;
default:
ceph_abort();
}
}
(mon->is_peon() && req->get_source().num() == mon->get_leader()));

// NOTE: these ops are defined in messages/MMonPaxos.h
switch (req->op) {
// learner
case MMonPaxos::OP_COLLECT:
handle_collect(op);
break;
case MMonPaxos::OP_LAST:
handle_last(op);
break;
case MMonPaxos::OP_BEGIN:
handle_begin(op);
break;
case MMonPaxos::OP_ACCEPT:
handle_accept(op);
break;
case MMonPaxos::OP_COMMIT:
handle_commit(op);
break;
case MMonPaxos::OP_LEASE:
handle_lease(op);
break;
case MMonPaxos::OP_LEASE_ACK:
handle_lease_ack(op);
break;

default:
ceph_abort();
}
Expand Down

0 comments on commit 0c85f8f

Please sign in to comment.