From 4a10f2b963af4e7fda762d52c344e47c0a0e4d91 Mon Sep 17 00:00:00 2001 From: sageweil Date: Wed, 28 Feb 2007 04:05:31 +0000 Subject: [PATCH] hmm git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1137 29311d96-e01e-0410-9327-a35deaab8ce9 --- .../riccardo/monitor2/messages/MMonPaxos.h | 14 +- branches/riccardo/monitor2/mon/Paxos.cc | 180 +++++++++++++----- branches/riccardo/monitor2/mon/Paxos.h | 46 ++++- 3 files changed, 186 insertions(+), 54 deletions(-) diff --git a/branches/riccardo/monitor2/messages/MMonPaxos.h b/branches/riccardo/monitor2/messages/MMonPaxos.h index b3f6e850a9c5d..10265374fc56d 100644 --- a/branches/riccardo/monitor2/messages/MMonPaxos.h +++ b/branches/riccardo/monitor2/messages/MMonPaxos.h @@ -30,20 +30,20 @@ class MMonPaxos : public Message { int op; int machine_id; - version_t proposal; - version_t n; + version_t pn; + version_t v; bufferlist value; MMonPaxos() : Message(MSG_MON_PAXOS) {} MMonPaxos(int o, int mid, - version_t pn, version_t v) : Message(MSG_MON_PAXOS), - op(o), machine_id(mid), - proposal(pn), n(v) {} + version_t _pn, version_t _v) : Message(MSG_MON_PAXOS), + op(o), machine_id(mid), + pn(_pn), v(_v) {} MMonPaxos(int o, int mid, - version_t pn, version_t v, + version_t _pn, version_t _v, bufferlist& b) : Message(MSG_MON_PAXOS), op(o), machine_id(mid), - proposal(pn), n(v), + pn(_pn), v(_v), value(b) {} virtual char *get_type_name() { return "paxos"; } diff --git a/branches/riccardo/monitor2/mon/Paxos.cc b/branches/riccardo/monitor2/mon/Paxos.cc index f1c2c12c74744..ea1ed59c1462a 100644 --- a/branches/riccardo/monitor2/mon/Paxos.cc +++ b/branches/riccardo/monitor2/mon/Paxos.cc @@ -24,48 +24,150 @@ // --------------------------------- + +// PHASE 1 + // proposer -void Paxos::propose(version_t v, bufferlist& value) +void Paxos::leader_start() { -//todo high rf: what si this?!? + dout(10) << "i am the leader, start paxos" << endl; + + // reset the number of lasts received + last_num = 0; + my_pn = get_new_proposal_number(); + last_pn = 0; + + // send collect + for (int i=0; imonmap->num_mon; ++i) { + if (i == whoami) continue; + // todo high rf I pass the pn twice... what is the last parameter for? + mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_COLLECT, whoami, pn, 0), + mon->monmap->get_inst(i)); + } } + +void Paxos::handle_collect(MMonPaxos *m) +{ + if (m->pn > accepted_pn[m->v]) { + dout(10) << "handle_collect - replied LAST" << *m << endl; + // send ack/last + mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_LAST, machine_id, + accepted_pn[m->v], m->v, + accepted_value[m->v])); + accepted_pn[m->v] = m->pn; + } + else { + dout(10) << "handle_collect - replied OLDROUND" << *m << endl; + // send nak/oldround + mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_LAST, machine_id, + accepted_pn[m->v], m->v, + accepted_value[m->v])); + } + delete m; +} + void Paxos::handle_last(MMonPaxos *m) { - dout(10) << "handle_last - one more last collected " << *m << endl; + dout(10) << "handle_last " << *m << endl; + + if (m->pn > last_pn) { + dout(10) << " accepter accepted pn " << m->pn << ", taking that value" << endl; + last_value = m->value; + } + + // majority? + bool had = have_majority(); num_last++; + + if (!had && have_majority()) { + dout(5) << "handle_last - we just got a majority" << endl; + + if (last_pn) { + // propose previous value + propose(); + } else { + // it's unconstrained. + } + } + + + + // use == instead of > so that if we receive additional LAST messages, we will not do this again - if (num_last == (unsigned)(mon->monmap->num_mon / 2)+1){ - dout(5) << "handle_last - got majority" << endl; - // bcast to everyone else - begin - num_accepts=0; - for (int i=0; imonmap->num_mon; ++i) { - // we only set up our value if we get the majority, so for now we don't save it - if (i == whoami) continue; - // todo high rf: where is the data we want to send? - mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_BEGIN, whoami, pn, DATA_TO_SEND), - MSG_ADDR_MON(i), mon->monmap->get_inst(i)); - } + if (num_last == (unsigned)(mon->monmap->num_mon / 2)+1) { + dout(5) << "handle_last - got majority" << endl; + + // propose + propose + + // bcast to everyone else - begin + num_accept = 0; + for (int i=0; imonmap->num_mon; ++i) { + if (i == whoami) continue; + // we only set up our value if we get the majority, so for now we don't save it + // todo high rf: where is the data we want to send? + mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_BEGIN, machine_id, + pn, DATA_TO_SEND), + mon->monmap->get_inst(i)); + } } delete m; } +void Paxos::handle_oldround(MMonPaxos *m) +{ + dout(10) << "handle_oldround " << *m << endl; + + // the state is already constrained because an acceptor has + // accepted with a higher pn than ours. + + // in any case, we can propose for this state. + + last_value = m->value; + last_pn = m->pn; + + // ? + if (have_majority()) + propose(); + + delete m; +} + + + void Paxos::handle_accept(MMonPaxos *m) { dout(10) << "handle_accept " << *m << endl; num_accepts++; - if (num_accepts == (unsigned)(mon->monmap->num_mon / 2)+1){ - dout(5) << "handle_accept - bcast commit messages" << *m << endl; - for (int i=0; imonmap->num_mon; ++i) { - mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_COMMIT, whoami, pn, DATA_TO_COMMIT), - MSG_ADDR_MON(i), mon->monmap->get_inst(i)); - } + if (num_accepts == (unsigned)(mon->monmap->num_mon / 2)+1){ + dout(5) << "handle_accept - bcast commit messages" << *m << endl; + for (int i=0; imonmap->num_mon; ++i) { + mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_COMMIT, + whoami, + pn, + DATA_TO_COMMIT), + mon->monmap->get_inst(i)); + } } delete m; } + +void Paxos::propose(version_t v, bufferlist& value) +{ + last_value = value; + last_version = v; + + // kick start whatever + // send some message +} + + + + void Paxos::handle_ack(MMonPaxos *m) { //todo high rf: Do we have to do anything here?!? @@ -110,16 +212,19 @@ version_t Paxos::get_new_proposal_number(version_t gt) // accepter void Paxos::handle_collect(MMonPaxos *m) { - if (m->pn > last) { - dout(10) << "handle_collect - replied LAST" << *m << endl; - mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_LAST, whoami, last)); - last = m->pn; - } - else { - dout(10) << "handle_collect - replied OLDROUND" << *m << endl; - mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_OLDROUND, whoami, last)); - } - + if (m->pn > accepted_pn[m->v]) { + dout(10) << "handle_collect - replied LAST" << *m << endl; + mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_LAST, machine_id, + m->pn, m->v)); + accepted_pn[m->v] = m->pn; + } + else { + dout(10) << "handle_collect - replied OLDROUND" << *m << endl; + mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_OLDROUND, machine_id, + accepted_pn[m->v], m->v, + accepted_value[m->v])); + } + delete m; } @@ -153,21 +258,6 @@ void Paxos::handle_begin(MMonPaxos *m) // --------------------------------- -void Paxos::leader_start() -{ - dout(10) << "i am the leader, start paxos" << endl; - - // reset the number of lasts received - num_lasts = 0; - version_t pn = get_new_proposal_number(); - for (int i=0; imonmap->num_mon; ++i) { - if (i == whoami) continue; - // todo high rf I pass the pn twice... what is the last parameter for? - mon->messenger->send_message(new MMonPaxos(MMonPaxos::OP_COLLECT, whoami, pn, pn), - mon->monmap->get_inst(i)); - } -} - void Paxos::dispatch(Message *m) diff --git a/branches/riccardo/monitor2/mon/Paxos.h b/branches/riccardo/monitor2/mon/Paxos.h index 52a509d25aa76..622460d51e18d 100644 --- a/branches/riccardo/monitor2/mon/Paxos.h +++ b/branches/riccardo/monitor2/mon/Paxos.h @@ -11,6 +11,27 @@ * */ +/* +time----> + +ccccccccccccccccccaaa?????????????????????????????????????? +ccccccccccccccc???????????????????????????????????????????? +ccccccccccccccccccaaa?????????????????????????????????????? +ccccccccccccccccccaaa?????????????????????????????????????? +ccca??????????????????????????????????????????????????????? + +collect(v>2) + last and values for each v>2 + or + oldround ... + + +what values we\'ve accepted, and for at pn\'s +what values we happen to know have been committed. + + +dddddddddddddddd_?????????????????????????????????????????? +*/ #ifndef __MON_PAXOS_H #define __MON_PAXOS_H @@ -34,10 +55,28 @@ class Paxos { // my state machine info int machine_id; const char *machine_name; - map accepted_values; - map accepted_proposal_number; // proposer + /* + version_t last_version; // the last version i'm proposing + int num_last; // number of peers that have responded my collect + //version_t last_pn; // my proposal number + int num_accept; // number of peers that have accepted my propose + + version_t constrained_thru; + */ + //map last_pn; + + // phase 1 + version_t my_pn; // my pn + version_t last_pn; // the largest pn i've heard via a LAST + bufferlist last_value; // the value i'm proposing + int last_num; // how many LAST's i've received + + bool have_majority() { + return num_accept > (mon->monmap->num_mon / 2)+1; + } + void propose(version_t v, bufferlist& value); void handle_last(MMonPaxos*); @@ -48,6 +87,9 @@ class Paxos { version_t get_new_proposal_number(version_t gt=0); // accepter + map accepted_values; + map accepted_pn; + void handle_collect(MMonPaxos*); // learner -- 2.39.5