artemlivshits opened a new issue, #19131: URL: https://github.com/apache/iceberg/issues/19131
### Apache Iceberg version main (1c99ae9); the same code is present since 1.7.0 ### Query engine Kafka Connect ### Please describe the bug 🐞 `Channel.send()` (and `Channel.commitConsumerOffsets()`) aborts the transaction and rethrows any exception from `producer.send()` / `sendOffsetsToTransaction()` / `commitTransaction()`: https://github.com/apache/iceberg/blob/1c99ae9b5262b757fa4c8afe5650cabe59a352d6/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/channel/Channel.java#L98-L117 `TransactionAbortableException` means only the current transaction failed: the producer is still valid and the client is expected to abort and retry in a new transaction ([KIP-890](https://cwiki.apache.org/confluence/display/KAFKA/KIP-890%3A+Transactions+Server-Side+Defense), [KIP-1050](https://cwiki.apache.org/confluence/display/KAFKA/KIP-1050%3A+Consistent+error+handling+for+Transactions)). Brokers can return it during normal operation, so transactional clients should expect it at any time. Because the connector rethrows it, the task fails permanently: - **Worker path:** `IcebergSinkTask.put()` → `CommitterImpl.save()` → `Worker.process()` → `Worker.receive()` → `Channel.send()`. The exception escapes `put()`. It is not an `org.apache.kafka.connect.errors.RetriableException`, so `WorkerSinkTask.deliverMessages()` kills the task ("Task is being killed and will not recover until manually restarted") and it stays FAILED. - **Coordinator path:** `Coordinator.process()` / `commit()` → `Channel.send()` / `commitConsumerOffsets()`. `CoordinatorThread` terminates with the error, `isFenced()` is false, and the next `save()` throws `NotRunningException`, failing the task the same way. Data is not lost (on restart the task seeks back to the last offsets committed in the transaction), but every affected task needs a manual restart. If many tasks hit the error at the same moment, all of them fail together. Rethrowing as a Connect `RetriableException` is not enough on its own. By the time `send()` fails, `Worker.receive()` has already called `sinkWriter.completeWrite()` and used up the `START_COMMIT` event, so a redelivered `put()` would not resend the `DataWritten` / `DataComplete` events. ### Proposed fix Retry inside `Channel.send()` (and `commitConsumerOffsets()`). Everything needed is already in hand there: `recordList` (built from the `events` argument) and `offsetsToCommit` (built from `sourceOffsets`). ```java for (int attempt = 1; ; attempt++) { synchronized (producer) { producer.beginTransaction(); try { recordList.forEach(producer::send); if (!offsetsToCommit.isEmpty()) { producer.sendOffsetsToTransaction(offsetsToCommit, KafkaUtils.consumerGroupMetadata(context)); } producer.commitTransaction(); return; } catch (TransactionAbortableException e) { abortQuietly(); if (attempt >= maxAttempts) { throw e; } // backoff, then retry } catch (Exception e) { abortQuietly(); throw e; // fenced / fatal errors: unchanged behaviour } } } ``` Why resending the same events is safe: - Records from the aborted transaction are not visible to the `read_committed` control-topic consumers, so the retry does not produce duplicates. - The `DataWritten` events only reference data files already written to storage. The retry does not touch those files again. - The source offsets are committed in the same transaction as the events, so a retry cannot commit one without the other. - If retries push past the coordinator's commit timeout, `CommitState.addResponse()` still buffers the late `DataWritten`, and `tableCommitMap()` does not filter by commit ID, so the files are included in the next commit. Things to watch: - Retries run on the `put()` thread, so the total backoff must stay well under the Connect consumer's `max.poll.interval.ms`. - If a rebalance happens between attempts, `sendOffsetsToTransaction` with the new group generation is rejected (`CommitFailedException` / fenced). That should stay fatal, which the generic `catch` above already does. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
