X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5fd8cc8409d0efadc07dfe8d6774ad9ff477663d..2546a41ad36fdc9ef6471cb35a1d56930ae1b527:/paxos.h diff --git a/paxos.h b/paxos.h index 7188edb..8561dd5 100644 --- a/paxos.h +++ b/paxos.h @@ -3,96 +3,99 @@ #include #include -#include "rpc.h" +#include +#include "rpc/rpc.h" #include "paxos_protocol.h" #include "log.h" -#include "mutex.h" +#include "lock.h" +using std::string; +using std::map; +using std::vector; class paxos_change { - public: - virtual void paxos_commit(unsigned instance, std::string v) = 0; - virtual ~paxos_change() {}; + public: + virtual void paxos_commit(unsigned instance, const string & v) = 0; + virtual ~paxos_change() {} }; class acceptor { - private: - log *l; - rpcs *pxs; - paxos_change *cfg; - std::string me; - mutex pxs_mutex; - - // Acceptor state - prop_t n_h; // number of the highest proposal seen in a prepare - prop_t n_a; // number of highest proposal accepted - std::string v_a; // value of highest proposal accepted - unsigned instance_h; // number of the highest instance we have decided - std::map values; // vals of each instance - - void commit_wo(unsigned instance, std::string v); - paxos_protocol::status preparereq(std::string src, - paxos_protocol::preparearg a, - paxos_protocol::prepareres &r); - paxos_protocol::status acceptreq(std::string src, - paxos_protocol::acceptarg a, bool &r); - paxos_protocol::status decidereq(std::string src, - paxos_protocol::decidearg a, int &r); - - friend class log; - - public: - acceptor(class paxos_change *cfg, bool _first, std::string _me, - std::string _value); - ~acceptor() {}; - void commit(unsigned instance, std::string v); - unsigned instance() { return instance_h; } - std::string value(unsigned instance) { return values[instance]; } - std::string dump(); - void restore(std::string); - rpcs *get_rpcs() { return pxs; }; - prop_t get_n_h() { return n_h; }; - unsigned get_instance_h() { return instance_h; }; + private: + log *l; + rpcs *pxs; + paxos_change *cfg; + string me; + mutex pxs_mutex; + + // Acceptor state + prop_t n_h; // number of the highest proposal seen in a prepare + prop_t n_a; // number of highest proposal accepted + string v_a; // value of highest proposal accepted + unsigned instance_h; // number of the highest instance we have decided + map values; // vals of each instance + + void commit(unsigned instance, const string & v, lock & pxs_mutex_lock); + paxos_protocol::status preparereq(paxos_protocol::prepareres & r, + const string & src, paxos_protocol::preparearg a); + paxos_protocol::status acceptreq(bool & r, const string & src, + paxos_protocol::acceptarg a); + paxos_protocol::status decidereq(int & r, const string & src, + paxos_protocol::decidearg a); + + friend class log; + + public: + acceptor(class paxos_change *cfg, bool _first, const string & _me, + const string & _value); + ~acceptor() {} + void commit(unsigned instance, const string & v); + unsigned instance() { return instance_h; } + const string & value(unsigned instance) { return values[instance]; } + string dump(); + void restore(const string &); + rpcs *get_rpcs() { return pxs; } + prop_t get_n_h() { return n_h; } + unsigned get_instance_h() { return instance_h; } }; -extern bool isamember(std::string m, const std::vector &nodes); -extern std::string print_members(const std::vector &nodes); +extern bool isamember(const string & m, const vector & nodes); +extern string print_members(const vector & nodes); class proposer { - private: - log *l; - paxos_change *cfg; - acceptor *acc; - std::string me; - bool break1; - bool break2; - - mutex pxs_mutex; - - // Proposer state - bool stable; - prop_t my_n; // number of the last proposal used in this instance - - void setn(); - bool prepare(unsigned instance, std::vector &accepts, - std::vector nodes, - std::string &v); - void accept(unsigned instance, std::vector &accepts, - std::vector nodes, std::string v); - void decide(unsigned instance, std::vector accepts, - std::string v); - - void breakpoint1(); - void breakpoint2(); - bool majority(const std::vector &l1, const std::vector &l2); - - friend class log; - public: - proposer(class paxos_change *cfg, class acceptor *_acceptor, std::string _me); - ~proposer() {}; - bool run(int instance, std::vector cnodes, std::string v); - bool isrunning(); - void breakpoint(int b); + private: + log *l; + paxos_change *cfg; + acceptor *acc; + string me; + bool break1; + bool break2; + + mutex pxs_mutex; + + // Proposer state + bool stable; + prop_t my_n; // number of the last proposal used in this instance + + void setn(); + bool prepare(unsigned instance, vector & accepts, + const vector & nodes, + string & v); + void accept(unsigned instance, vector & accepts, + const vector & nodes, const string & v); + void decide(unsigned instance, const vector & accepts, + const string & v); + + void breakpoint1(); + void breakpoint2(); + bool majority(const vector & l1, const vector & l2); + + friend class log; + public: + proposer(class paxos_change *cfg, class acceptor *_acceptor, const string &_me); + ~proposer() {} + bool run(unsigned instance, const vector & cnodes, const string & v); + bool isrunning(); + void breakpoint(int b); };