-
Notifications
You must be signed in to change notification settings - Fork 112
batch: resolve pending transactions when a flush yields no batch #446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,9 +66,31 @@ func (m *Impl) loop() { | |
| pendingTrans := []*transaction.Tracked{} | ||
| pendingAcks := sync.WaitGroup{} | ||
|
|
||
| // resolvePending acknowledges every accumulated transaction with the given | ||
| // result and clears the slice. Used when a flush yields no batch to send, so | ||
| // those transactions are resolved immediately rather than lingering and | ||
| // inheriting a future batch's result. | ||
| resolvePending := func(ackErr error) { | ||
| for _, t := range pendingTrans { | ||
| if err := t.Ack(closeNowCtx, ackErr); err != nil { | ||
| break | ||
| } | ||
| } | ||
| pendingTrans = nil | ||
| } | ||
|
|
||
| flushBatchFn := func() { | ||
| sendMsg := m.batcher.Flush(closeNowCtx) | ||
| sendMsg, err := m.batcher.Flush(closeNowCtx) | ||
| if err != nil { | ||
| // The batching processors failed and the batch has been dropped. | ||
| // Nack the accumulated transactions so the source can retry them. | ||
| resolvePending(err) | ||
| return | ||
| } | ||
| if sendMsg == nil { | ||
| // No batch produced (the policy was empty or every message was | ||
| // intentionally filtered away); the data was consumed successfully. | ||
| resolvePending(nil) | ||
| return | ||
| } | ||
|
Comment on lines
82
to
95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The input batcher received the same behavioral fix as the output batcher — Per the project test patterns, changed code should be accompanied by tests exercising the new behavior.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in c03f060: |
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth adding context to this error message so it can be related to the error log above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call — done in c03f060. The returned error is now wrapped as
fmt.Errorf("batch processors resulted in error: %w", err), so the nack reason surfaced downstream lines up with the logged message just above it.