Skip to content

Commit 6398677

Browse files
committed
EndTxn: avoid creating a producer ID if nothing was produced
1 parent c7c08fb commit 6398677

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Diff for: pkg/kgo/txn.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ func (cl *Client) EndTransaction(ctx context.Context, commit TransactionEndTry)
427427
}
428428
}
429429

430+
// If no partition was added to a transaction, then we have nothing to commit.
431+
if !anyAdded {
432+
cl.cfg.logger.Log(LogLevelInfo, "no records were produced during the commit; thus no transaction was began; ending without doing anything")
433+
return nil
434+
}
435+
430436
id, epoch, err := cl.producerID()
431437
if err != nil {
432438
if commit {
@@ -468,12 +474,6 @@ func (cl *Client) EndTransaction(ctx context.Context, commit TransactionEndTry)
468474
}
469475
}
470476

471-
// If no partition was added to a transaction, then we have nothing to commit.
472-
if !anyAdded {
473-
cl.cfg.logger.Log(LogLevelInfo, "no records were produced during the commit; thus no transaction was began; ending without doing anything")
474-
return nil
475-
}
476-
477477
cl.cfg.logger.Log(LogLevelInfo, "ending transaction",
478478
"transactional_id", *cl.cfg.txnID,
479479
"producer_id", id,

0 commit comments

Comments
 (0)