Skip to content

Commit

Permalink
r/consensus: allow raft to flush on empty append entries requests
Browse files Browse the repository at this point in the history
When linearizable barrier is requested we want follower to flush its log
to make sure that all possible entries are committed with traditional
raft semantics. Added handling of flushing log on the follower if leader
requested it and append entries request is empty.

Signed-off-by: Michal Maslanka <michal@redpanda.com>
  • Loading branch information
mmaslankaprv committed Jul 10, 2023
1 parent 97754b9 commit 9cd72e5
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/v/raft/consensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1899,19 +1899,25 @@ consensus::do_append_entries(append_entries_request&& r) {
return ss::make_ready_future<append_entries_reply>(
std::move(reply));
}
auto f = ss::now();
if (r.is_flush_required() && lstats.dirty_offset > _flushed_offset) {
f = flush_log();
}
auto last_visible = std::min(
lstats.dirty_offset, request_metadata.last_visible_index);
// on the follower leader control visibility of entries in the log
maybe_update_last_visible_index(last_visible);
_last_leader_visible_offset = std::max(
request_metadata.last_visible_index, _last_leader_visible_offset);
return maybe_update_follower_commit_idx(
model::offset(request_metadata.commit_index))
.then([reply = std::move(reply)]() mutable {
reply.result = append_entries_reply::status::success;
return ss::make_ready_future<append_entries_reply>(
std::move(reply));
});
return f.then([this, reply, request_metadata] {
return maybe_update_follower_commit_idx(
model::offset(request_metadata.commit_index))
.then([this, reply]() mutable {
reply.last_flushed_log_index = _flushed_offset;
reply.result = append_entries_reply::status::success;
return reply;
});
});
}

// section 3
Expand Down

0 comments on commit 9cd72e5

Please sign in to comment.