Partition ballot numbers between all legislators

This commit is contained in:
Julien CLEMENT 2020-05-07 11:11:41 +02:00
parent b33d2f17ab
commit 5c27b7df2f
4 changed files with 14 additions and 1 deletions

@ -68,13 +68,16 @@ namespace paxos
/* Create VHostConfig vector and fill with VHostConfig */ /* Create VHostConfig vector and fill with VHostConfig */
std::vector<LegislatorConfig> legislator_configs; std::vector<LegislatorConfig> legislator_configs;
int i = 0;
for (auto it : legislators) for (auto it : legislators)
{ {
/* Differenciable vhost checking */ /* Differenciable vhost checking */
auto legislator = it.get<paxos::LegislatorConfig>(); auto legislator = it.get<paxos::LegislatorConfig>();
legislator.ballot_partition_id = i;
legislator.is_self = name == legislator.name; legislator.is_self = name == legislator.name;
legislator_configs.push_back(legislator); legislator_configs.push_back(legislator);
++i;
} }
return legislator_configs; return legislator_configs;

@ -12,6 +12,8 @@ namespace paxos
std::string port; std::string port;
std::string name; std::string name;
bool is_self; bool is_self;
int ballot_partition_id;
}; };
struct ServerConfig struct ServerConfig

@ -19,12 +19,19 @@ namespace paxos
{ {
has_started = false; has_started = false;
quorum_previous_votes.clear(); quorum_previous_votes.clear();
int new_ballot_number = ledger.last_tried() + 1; int new_ballot_number = get_next_ballot_id(ledger.last_tried());
ledger.set_last_tried(new_ballot_number); ledger.set_last_tried(new_ballot_number);
log(config_.name + " is initiating ballot " + std::to_string(new_ballot_number), green); log(config_.name + " is initiating ballot " + std::to_string(new_ballot_number), green);
send_next_ballot(new_ballot_number); send_next_ballot(new_ballot_number);
} }
int Legislator::get_next_ballot_id(int previous_ballot_id)
{
if (previous_ballot_id == -1)
return config_.ballot_partition_id;
return previous_ballot_id + legislators.size();
}
void Legislator::send_next_ballot(int ballot) void Legislator::send_next_ballot(int ballot)
{ {
std::string ballot_string = std::to_string(ballot); std::string ballot_string = std::to_string(ballot);

@ -16,6 +16,7 @@ namespace paxos
LegislatorConfig config_; LegislatorConfig config_;
void initiate_ballot(); void initiate_ballot();
int get_next_ballot_id(int previous_ballot_id);
void send_next_ballot(int ballot); void send_next_ballot(int ballot);
void receive_next_ballot(Message message); void receive_next_ballot(Message message);