Kafka Exception LogTruncationException
org.apache.kafka.clients.consumer.LogTruncationException
Non-retriable
Client
In the event of an unclean leader election, the log will be truncated, previously committed data will be lost, and new data will be written over these offsets. When this happens, the consumer will detect the truncation and raise this exception (if no automatic reset policy has been defined) with the first offset known to diverge from what the consumer previously read.
Common Causes
- The consumer detected that the log was truncated below its fetch position — typically after an unclean leader election promoted a replica that was missing records
- Offsets/leader-epoch checks revealed the broker's log diverged from what the consumer had already consumed
- Failover to a follower that had not fully caught up
Solutions
- Decide on data semantics: the safest fix is to prevent the cause — set unclean.leader.election.enable=false and use replication.factor>=3 with min.insync.replicas>=2
- Handle the exception by inspecting the offsetOutOfRangePartitions / divergence info it exposes and resetting to a safe position
- Investigate the cluster: an unclean election means a leader was lost with un-replicated data
Example Stack Trace
org.apache.kafka.clients.consumer.LogTruncationException: Detected truncated partitions: {orders-0=...} after fetch offset/leader epoch validationRelated
Related Client exceptions: DisconnectException · InterruptException
Hitting
LogTruncationException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.