Now searchs the next ballot to initiate by looking ballots initiated by others

This commit is contained in:
Julien CLEMENT 2020-05-07 11:40:49 +02:00
parent 5c27b7df2f
commit c68c0a8a07
2 changed files with 8 additions and 4 deletions

View File

@ -19,16 +19,20 @@ namespace paxos
{ {
has_started = false; has_started = false;
quorum_previous_votes.clear(); quorum_previous_votes.clear();
int new_ballot_number = get_next_ballot_id(ledger.last_tried()); int new_ballot_number = get_next_ballot_id();
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) int Legislator::get_next_ballot_id()
{ {
int previous_ballot_id = ledger.last_tried();
if (previous_ballot_id == -1) if (previous_ballot_id == -1)
return config_.ballot_partition_id; previous_ballot_id = config_.ballot_partition_id - legislators.size();
int last_voted_ballot = ledger.next_bal();
while (last_voted_ballot > (int)legislators.size() + previous_ballot_id)
previous_ballot_id += legislators.size();
return previous_ballot_id + legislators.size(); return previous_ballot_id + legislators.size();
} }

View File

@ -16,7 +16,7 @@ namespace paxos
LegislatorConfig config_; LegislatorConfig config_;
void initiate_ballot(); void initiate_ballot();
int get_next_ballot_id(int previous_ballot_id); int get_next_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);