kafka runtime_error ai_generated partial

org.apache.kafka.common.errors.TransactionAbortableException: 事务已被协调器中止

org.apache.kafka.common.errors.TransactionAbortableException: The transaction has been aborted by the coordinator

ID: kafka/transaction-abortable

其他格式: JSON · Markdown 中文 · English
75%修复率
82%置信度
1证据数
2024-01-10首次发现

版本兼容性

版本状态引入弃用备注
Kafka 3.4.0 active
Kafka 3.5.0 active
Kafka 3.6.0 active

根因分析

事务协调器因超时、围栏或协调器故障转移而中止事务。

English

Transactional coordinator aborted the transaction due to a timeout, fencing, or coordinator failover.

generic

官方文档

https://kafka.apache.org/documentation/#transactionalconfigs

解决方案

  1. Retry the transaction with a new transactional.id after aborting the current one.
    Code example:
    producer.initTransactions();
    try {
      producer.beginTransaction();
      // send messages
      producer.commitTransaction();
    } catch (TransactionAbortableException e) {
      producer.abortTransaction();
      // Reinitialize with a new transactional.id
      properties.put("transactional.id", "new-txn-id-" + System.currentTimeMillis());
      producer.close();
      producer = new KafkaProducer<>(properties);
      producer.initTransactions();
    }
  2. Increase transaction coordinator timeout and ensure stable network.
    Command to check coordinator:
    kafka-transactions --bootstrap-server localhost:9092 --describe --transactional-id my-txn-id
    Set in producer config:
    properties.put("transaction.timeout.ms", "60000");
    properties.put("max.block.ms", "120000");

无效尝试

常见但无效的做法:

  1. Increase transaction.timeout.ms to 3600000 50% 失败

    Longer timeout may mask underlying issues like coordinator instability or network partitions.

  2. Disable idempotent producer 90% 失败

    Transactions require idempotent producer; disabling it causes different errors.

  3. Restart all brokers 80% 失败

    Restarting brokers does not clear the aborted transaction state; coordinator still has the abort marker.