What is OffsetForLeaderEpoch?
Follower replicas call this after a leader failover to determine the divergence point and truncate their local log to match the new leader. Without it, a follower might replay entries the new leader doesn't have, causing data inconsistency across leader elections.
Wire Diagram
Request Header · flexible
message_size
int32 · 4B
api_key
int16 · 2B
api_version
int16 · 2B
correlation_id
int32 · 4B
client_id
string (compact)
tagged
var
OffsetForLeaderEpochRequest v4
ReplicaId
int32 · 4B
tagged
var
Topic
string (compact)
tagged
var
Partition
int32 · 4B
CurrentLeaderEpoch
int32 · 4B
LeaderEpoch
int32 · 4B
tagged
var
Schema & Example
Schema { "ReplicaId": int32, "Topics": [{ "Topic": string, "Partitions": [{ "Partition": int32, "CurrentLeaderEpoch": int32, "LeaderEpoch": int32 }] }] }
Example { "ReplicaId": -1, "Topics": [{ "Topic": "orders", "Partitions": [{ "Partition": 0, "CurrentLeaderEpoch": 12, "LeaderEpoch": 17 }] }] }