diff --git a/src/v/raft/consensus.cc b/src/v/raft/consensus.cc index dd03d5c6c0d2c..d56eeb4defcc7 100644 --- a/src/v/raft/consensus.cc +++ b/src/v/raft/consensus.cc @@ -1899,19 +1899,25 @@ consensus::do_append_entries(append_entries_request&& r) { return ss::make_ready_future( 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( - 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