Skip to content

Commit

Permalink
k/replicated_partition: use confirmed term as a source of leader epoch
Browse files Browse the repository at this point in the history
A leader epoch is used by Kafka clients to determine if a replica is up
to date with the leader and to detect truncation.

The leader epoch differs from Raft term as the term is updated when
leader election starts. Whereas the leader epoch is updated after the
state of the replica is determined. Therefore the leader epoch uses
confirmed term instead of the simple term which is incremented every
time the leader election starts.

Signed-off-by: Michal Maslanka <michal@redpanda.com>
(cherry picked from commit e746f79)
  • Loading branch information
mmaslankaprv committed Apr 16, 2024
1 parent ad1d2b5 commit d6cd211
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/v/kafka/server/replicated_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,18 @@ class replicated_partition final : public kafka::partition_proxy::impl {

ss::future<std::optional<model::offset>>
get_leader_epoch_last_offset(kafka::leader_epoch) const final;

/**
* A leader epoch is used by Kafka clients to determine if a replica is up
* to date with the leader and to detect truncation.
*
* The leader epoch differs from Raft term as the term is updated when
* leader election starts. Whereas the leader epoch is updated after the
* state of the replica is determined. Therefore the leader epoch uses
* confirmed term instead of the simple term which is incremented every time
* the leader election starts.
*/
kafka::leader_epoch leader_epoch() const final {
return leader_epoch_from_term(_partition->term());
return leader_epoch_from_term(_partition->raft()->confirmed_term());
}

ss::future<error_code> validate_fetch_offset(
Expand Down

0 comments on commit d6cd211

Please sign in to comment.