From 63986779a656fe099eedb3da6590086ccd8ed20a Mon Sep 17 00:00:00 2001 From: Travis Bischel Date: Thu, 6 May 2021 18:13:04 -0600 Subject: [PATCH] EndTxn: avoid creating a producer ID if nothing was produced --- pkg/kgo/txn.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/kgo/txn.go b/pkg/kgo/txn.go index 0bf558c8..8ef2e794 100644 --- a/pkg/kgo/txn.go +++ b/pkg/kgo/txn.go @@ -427,6 +427,12 @@ func (cl *Client) EndTransaction(ctx context.Context, commit TransactionEndTry) } } + // If no partition was added to a transaction, then we have nothing to commit. + if !anyAdded { + cl.cfg.logger.Log(LogLevelInfo, "no records were produced during the commit; thus no transaction was began; ending without doing anything") + return nil + } + id, epoch, err := cl.producerID() if err != nil { if commit { @@ -468,12 +474,6 @@ func (cl *Client) EndTransaction(ctx context.Context, commit TransactionEndTry) } } - // If no partition was added to a transaction, then we have nothing to commit. - if !anyAdded { - cl.cfg.logger.Log(LogLevelInfo, "no records were produced during the commit; thus no transaction was began; ending without doing anything") - return nil - } - cl.cfg.logger.Log(LogLevelInfo, "ending transaction", "transactional_id", *cl.cfg.txnID, "producer_id", id,