kafka
protocol_error
ai_generated
true
org.apache.kafka.common.errors.ProducerFencedException: Producer epoch fenced due to partition reassignment
ID: kafka/transactional-producer-epoch-fenced-during-partition-reassignment
81%Fix Rate
88%Confidence
1Evidence
2024-06-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Kafka 3.3.0 | active | — | — | — |
| Kafka 3.5.0 | active | — | — | — |
| Kafka 3.7.0 | active | — | — | — |
Root Cause
A transactional producer's epoch was invalidated because a partition it was writing to was reassigned to a different broker, causing the transaction coordinator to fence the producer.
generic中文
事务性生产者的纪元被无效化,因为它正在写入的分区被重新分配到不同的代理,导致事务协调器隔离了该生产者。
Official Documentation
https://kafka.apache.org/documentation/#producerconfigs_transactional.idWorkarounds
-
90% success Initialize a new transactional producer with a new transactional.id after catching the exception. Example in Java: try { producer.initTransactions(); } catch (ProducerFencedException e) { producer.close(); producer = createNewProducerWithNewTransactionalId(); producer.initTransactions(); }
Initialize a new transactional producer with a new transactional.id after catching the exception. Example in Java: try { producer.initTransactions(); } catch (ProducerFencedException e) { producer.close(); producer = createNewProducerWithNewTransactionalId(); producer.initTransactions(); } -
85% success Ensure partition reassignment is completed before starting transactional writes. Use 'bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --verify --reassignment-json-file reassign.json' to confirm completion.
Ensure partition reassignment is completed before starting transactional writes. Use 'bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --verify --reassignment-json-file reassign.json' to confirm completion.
中文步骤
Initialize a new transactional producer with a new transactional.id after catching the exception. Example in Java: try { producer.initTransactions(); } catch (ProducerFencedException e) { producer.close(); producer = createNewProducerWithNewTransactionalId(); producer.initTransactions(); }Ensure partition reassignment is completed before starting transactional writes. Use 'bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --verify --reassignment-json-file reassign.json' to confirm completion.
Dead Ends
Common approaches that don't work:
-
Setting transaction.timeout.ms to 300000 (5 minutes)
90% fail
Increasing transaction.timeout.ms does not prevent epoch fencing; it only delays transaction expiration.
-
Restarting the producer application without changing transactional.id
95% fail
Restarting the producer without resetting the transactional.id will still use the fenced epoch.