Skip to content

Commit

Permalink
EndTxn: avoid creating a producer ID if nothing was produced
Browse files Browse the repository at this point in the history
  • Loading branch information
twmb committed May 7, 2021
1 parent c7c08fb commit 6398677
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/kgo/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6398677

Please sign in to comment.