A Raft leader in term term has a log whose entries' terms are log_terms (entry 1 is log_terms[0]).
The cluster has cluster_size servers including the leader. The leader's own match index is always
len(log_terms); followers start at match index 0, and the commit index starts at commit.
Process acknowledgements [follower, match_index] in order. A follower's match index only moves forward
(stale, lower acks are ignored). After each ack, set the commit index to the largest N such that:
log_terms[N - 1] == term (a leader only commits entries from its own term by counting replicas).If no such N exists, the commit index stays. Return the commit index after each ack.
Implement commit_indexes. Input: log_terms: list[int], term: int, cluster_size: int, commit: int, acks: list[[str, int]]. Returns: list[int].
Entry 3 (term 2) is on a majority after the first ack but isn't from term 3; once f2 has 5, entry 5 (term 3) commits and with it everything before.
def commit_indexes(log_terms, term, cluster_size, commit, acks):
return [max(m for _, m in acks[: i + 1]) for i in range(len(acks))]
Run executes the public tests. Submit grades against public and hidden tests.
A Raft leader in term term has a log whose entries' terms are log_terms (entry 1 is log_terms[0]).
The cluster has cluster_size servers including the leader. The leader's own match index is always
len(log_terms); followers start at match index 0, and the commit index starts at commit.
Process acknowledgements [follower, match_index] in order. A follower's match index only moves forward
(stale, lower acks are ignored). After each ack, set the commit index to the largest N such that:
log_terms[N - 1] == term (a leader only commits entries from its own term by counting replicas).If no such N exists, the commit index stays. Return the commit index after each ack.
Implement commit_indexes. Input: log_terms: list[int], term: int, cluster_size: int, commit: int, acks: list[[str, int]]. Returns: list[int].
Entry 3 (term 2) is on a majority after the first ack but isn't from term 3; once f2 has 5, entry 5 (term 3) commits and with it everything before.
def commit_indexes(log_terms, term, cluster_size, commit, acks):
return [max(m for _, m in acks[: i + 1]) for i in range(len(acks))]
Run executes the public tests. Submit grades against public and hidden tests.