public void FindsMajorityPerfectly(int[] matchIndices, long majority) { var s = new VolatileLeaderState(); foreach (var i in matchIndices) { s.SetMatchIndex(Guid.NewGuid(), i); } Assert.Equal(majority, s.GetMajorityMatchIndex()); }
internal void UpdateCommitIndex() { /* * If there exists an N such that N > commitIndex, a majority * of matchIndex[i] ≥ N, and log[N].term == currentTerm: * set commitIndex = N(§5.3, §5.4). */ var majorityIndex = _volatileLeaderState.GetMajorityMatchIndex(); var index = _volatileState.CommitIndex + 1; // next while (index <= _logPersister.LastIndex && index <= majorityIndex && _logPersister.GetEntries(index, 1).First().Term == State.CurrentTerm) { index++; } _volatileState.CommitIndex = index - 1; }