X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/4b9798f44ae94deabf87dd534337b55259272950..e478ac59e66e89cbc174e781ac715c8644539947:/rsm.h diff --git a/rsm.h b/rsm.h index bf37a5d..ef919ff 100644 --- a/rsm.h +++ b/rsm.h @@ -3,32 +3,37 @@ #ifndef rsm_h #define rsm_h -#include -#include +#include "types.h" #include "rsm_protocol.h" -#include "rsm_state_transfer.h" #include "rpc/rpc.h" #include #include "config.h" +class rsm_state_transfer { + public: + virtual string marshal_state() = 0; + virtual void unmarshal_state(string) = 0; + virtual ~rsm_state_transfer() {} +}; + class rsm : public config_view_change { private: void reg1(int proc, handler *); protected: - std::map procs; + map procs; config *cfg; - class rsm_state_transfer *stf; + rsm_state_transfer *stf = nullptr; rpcs *rsmrpc; // On slave: expected viewstamp of next invoke request // On primary: viewstamp for the next request from rsm_client - viewstamp myvs; - viewstamp last_myvs; // Viewstamp of the last executed request - std::string primary; + viewstamp last_myvs{0, 0}; // Viewstamp of the last executed request + viewstamp myvs{0, 1}; + string primary; bool insync; bool inviewchange; unsigned vid_commit; // Latest view id that is known to rsm layer unsigned vid_insync; // The view id that this node is synchronizing for - std::vector backups; // A list of unsynchronized backups + vector backups; // A list of unsynchronized backups // For testing purposes rpcs *testsvr; @@ -37,43 +42,38 @@ class rsm : public config_view_change { bool break1; bool break2; - - rsm_client_protocol::status client_members(std::vector &r, int i); - rsm_protocol::status invoke(int &, int proc, viewstamp vs, std::string mreq); - rsm_protocol::status transferreq(rsm_protocol::transferres &r, std::string src, + rsm_client_protocol::status client_members(vector &r, int i); + rsm_protocol::status invoke(int &, int proc, viewstamp vs, string mreq); + rsm_protocol::status transferreq(rsm_protocol::transferres &r, string src, viewstamp last, unsigned vid); - rsm_protocol::status transferdonereq(int &, std::string m, unsigned vid); - rsm_protocol::status joinreq(rsm_protocol::joinres &r, std::string src, + rsm_protocol::status transferdonereq(int &, string m, unsigned vid); + rsm_protocol::status joinreq(string & log, string src, viewstamp last); - rsm_test_protocol::status test_net_repairreq(int &r, int heal); - rsm_test_protocol::status breakpointreq(int &r, int b); + rsm_test_protocol::status test_net_repairreq(rsm_test_protocol::status &r, int heal); + rsm_test_protocol::status breakpointreq(rsm_test_protocol::status &r, int b); - std::mutex rsm_mutex; - std::mutex invoke_mutex; - std::condition_variable recovery_cond; - std::condition_variable sync_cond; + mutex rsm_mutex, invoke_mutex; + cond recovery_cond, sync_cond; - void execute(int procno, std::string req, std::string &r); - rsm_client_protocol::status client_invoke(std::string &r, int procno, - std::string req); - bool statetransfer(std::string m); - bool statetransferdone(std::string m); - bool join(std::string m); + void execute(int procno, string req, string &r); + rsm_client_protocol::status client_invoke(string &r, int procno, string req); + bool statetransfer(string m, lock & rsm_mutex_lock); + bool statetransferdone(string m, lock & rsm_mutex_lock); + bool join(string m, lock & rsm_mutex_lock); void set_primary(unsigned vid); - std::string find_highest(viewstamp &vs, std::string &m, unsigned &vid); - bool sync_with_backups(); - bool sync_with_primary(); - void net_repair_wo(bool heal); + bool sync_with_backups(lock & rsm_mutex_lock); + bool sync_with_primary(lock & rsm_mutex_lock); + void net_repair(bool heal, lock & rsm_mutex_lock); void breakpoint1(); void breakpoint2(); - void partition1(); - void commit_change_wo(unsigned vid); + void partition1(lock & rsm_mutex_lock); + void commit_change(unsigned vid, lock & rsm_mutex_lock); public: - rsm (std::string _first, std::string _me); - ~rsm() {}; + rsm (string _first, string _me); + ~rsm() {} bool amiprimary(); - void set_state_transfer(rsm_state_transfer *_stf) { stf = _stf; }; + void set_state_transfer(rsm_state_transfer *_stf) { stf = _stf; } void recovery(); void commit_change(unsigned vid); @@ -81,7 +81,7 @@ class rsm : public config_view_change { }; template void rsm::reg(int proc, F f, C *c) { - reg1(proc, marshalled_func::wrap(f, c)); + reg1(proc, marshalled_func::wrap(f, c)); } #endif /* rsm_h */