2017-12-22 21:36:25 +08:00
|
|
|
#include "boost/serialization/export.hpp"
|
|
|
|
|
|
|
|
#include "boost/archive/binary_iarchive.hpp"
|
|
|
|
#include "boost/archive/binary_oarchive.hpp"
|
|
|
|
#include "boost/archive/text_iarchive.hpp"
|
|
|
|
#include "boost/archive/text_oarchive.hpp"
|
|
|
|
#include "boost/serialization/export.hpp"
|
|
|
|
|
2017-12-20 22:34:42 +08:00
|
|
|
#include "communication/raft/rpc.hpp"
|
2018-01-16 23:29:45 +08:00
|
|
|
#include "communication/raft/storage/file.hpp"
|
2017-12-20 22:34:42 +08:00
|
|
|
#include "communication/raft/test_utils.hpp"
|
|
|
|
|
2018-01-24 19:16:14 +08:00
|
|
|
using namespace std::literals::chrono_literals;
|
|
|
|
|
2017-12-20 22:34:42 +08:00
|
|
|
namespace raft = communication::raft;
|
|
|
|
|
2018-01-15 21:03:07 +08:00
|
|
|
using io::network::Endpoint;
|
2017-12-20 22:34:42 +08:00
|
|
|
using raft::RaftConfig;
|
|
|
|
using raft::RpcNetwork;
|
|
|
|
using raft::test_utils::DummyState;
|
|
|
|
|
2018-01-16 23:29:45 +08:00
|
|
|
DEFINE_string(member_id, "", "id of Raft member");
|
|
|
|
DEFINE_string(log_dir, "", "Raft log directory");
|
2017-12-20 22:34:42 +08:00
|
|
|
|
2017-12-22 21:36:25 +08:00
|
|
|
BOOST_CLASS_EXPORT(raft::PeerRpcReply);
|
|
|
|
BOOST_CLASS_EXPORT(raft::PeerRpcRequest<DummyState>);
|
2017-12-20 22:34:42 +08:00
|
|
|
|
|
|
|
/* Start cluster members with:
|
2018-01-16 23:29:45 +08:00
|
|
|
* ./raft_rpc --member-id a --log-dir a_log
|
|
|
|
* ./raft_rpc --member-id b --log-dir b_log
|
|
|
|
* ./raft_rpc --member-id c --log-dir c_log
|
2017-12-20 22:34:42 +08:00
|
|
|
*
|
|
|
|
* Enjoy democracy!
|
|
|
|
*/
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
google::InitGoogleLogging(argv[0]);
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
2018-01-15 21:03:07 +08:00
|
|
|
std::unordered_map<std::string, Endpoint> directory = {
|
|
|
|
{"a", Endpoint("127.0.0.1", 12345)},
|
|
|
|
{"b", Endpoint("127.0.0.1", 12346)},
|
|
|
|
{"c", Endpoint("127.0.0.1", 12347)}};
|
2017-12-20 22:34:42 +08:00
|
|
|
|
2018-01-24 19:16:14 +08:00
|
|
|
communication::rpc::System my_system(directory[FLAGS_member_id]);
|
2017-12-20 22:34:42 +08:00
|
|
|
RpcNetwork<DummyState> network(my_system, directory);
|
2018-01-16 23:29:45 +08:00
|
|
|
raft::SimpleFileStorage<DummyState> storage(FLAGS_log_dir);
|
2017-12-20 22:34:42 +08:00
|
|
|
|
2018-01-24 19:16:14 +08:00
|
|
|
raft::RaftConfig config{{"a", "b", "c"}, 150ms, 300ms, 70ms, 30ms};
|
2017-12-20 22:34:42 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
raft::RaftMember<DummyState> raft_member(network, storage, FLAGS_member_id,
|
|
|
|
config);
|
2017-12-22 21:36:25 +08:00
|
|
|
while (true) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-12-20 22:34:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|