Properly use Follower's next_index for sending batches instead of the known committed_log_size

This commit is contained in:
Tyler Neely 2022-08-29 14:13:40 +00:00
parent 28fae9e6d0
commit d50a6ab232

View File

@ -335,13 +335,16 @@ class Raft {
// AppendEntries RPCs are initiated by leaders to replicate log entries and to provide a form of heartbeat
void BroadcastAppendEntries(std::map<Address, FollowerTracker> &followers) {
for (auto &[address, follower] : followers) {
const LogSize follower_log_size = follower.confirmed_log_size;
const LogIndex next_index = follower.next_index;
const auto missing = state_.log.size() - follower_log_size;
const auto missing = state_.log.size() - next_index;
const auto batch_size = std::min(missing, kMaximumAppendBatchSize);
const auto start_index = follower_log_size;
const auto start_index = next_index;
const auto end_index = start_index + batch_size;
// advance follower's next index
follower.next_index += batch_size;
std::vector<std::pair<Term, WriteOperation>> entries;
entries.insert(entries.begin(), state_.log.begin() + start_index, state_.log.begin() + end_index);
@ -349,7 +352,7 @@ class Raft {
const Term previous_term_from_index = PreviousTermFromIndex(start_index);
Log("sending ", entries.size(), " entries to Follower ", address.last_known_port,
" which are above its known confirmed log size of ", follower_log_size);
" which are above its next_index of ", next_index);
AppendRequest<WriteOperation> ar{
.term = state_.term,