Pratheesh M created KAFKA-21650:
-----------------------------------
Summary: KRaft follower stays out of sync after recovery with
conflicting records in the same leader epoch
Key: KAFKA-21650
URL: https://issues.apache.org/jira/browse/KAFKA-21650
Project: Kafka
Issue Type: Bug
Components: replication
Affects Versions: 4.2.1
Reporter: Pratheesh M
h3. Observed behavior
Observed on Apache Kafka 4.2.1 in KRaft mode (commit {{18d5ecd939c8d510}}).
After an unclean shutdown, a restarting broker recovered a shorter local log
for a partition of {{__consumer_offsets}}. It applied its previous leader
assignment while registration was pending and its group coordinator appended a
new group metadata record at the recovered log end.
Selected Kafka log excerpts below are abridged. Broker, group and partition
identifiers and wall-clock timestamps are omitted. {{N}} stands for the same
offset throughout and {{E}} stands for the same leader epoch.
{code}
INFO Unable to register broker <broker> because the controller returned error
DUPLICATE_BROKER_REGISTRATION
INFO Publishing initial metadata ...
INFO Recovering ... since no clean shutdown file was found
INFO Completed load of Log(... logEndOffset=N ...)
INFO Scheduling loading of metadata from __consumer_offsets-<partition> with
epoch E
INFO Group <group> with generation <generation> is now empty.
{code}
The decoded batches at the same position contained different records. Both
batches passed checksum validation and both carried epoch {{E}}.
{code}
Replica Epoch Base offset Last offset Record at N
Restarted copy E N N GroupMetadata (members=[])
Leader copy E N N+3 OffsetCommit
{code}
On the next startup the broker registered, reopened the same local log and
became a follower. Its next fetch offset was {{N+1}}. The leader's epoch
checkpoint showed the exclusive end of {{E}} at {{N+10}}. The request was
within that epoch on the leader, which is consistent with the history check
proceeding without truncation. The leader returned the whole batch containing
{{N+1}}, beginning at {{N}}. The follower rejected the overlap.
{code}
org.apache.kafka.server.storage.log.UnexpectedAppendOffsetException:
Unexpected offset in append to __consumer_offsets-<partition>.
First offset N is less than the next offset N+1.
WARN Partition __consumer_offsets-<partition> marked as failed
{code}
Two partitions showed this pattern. Restarting the follower again repeated the
failure. Removing and then re-adding its replica through partition reassignment
rebuilt the local copy and restored ISR membership.
h3. Expected behavior
A restarting replica should be able to resume replication from a consistent
log. Please investigate whether internal group writes should be gated while
registration is pending, and how follower recovery should handle conflicting
records with the same offset and epoch.
The exact reason the first recovered log was shorter and an isolated
reproduction remain unverified.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)