fix(logmq): add per-entry fallback on batch InsertMany failure#954
Closed
mvanhorn wants to merge 1 commit into
Closed
fix(logmq): add per-entry fallback on batch InsertMany failure#954mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
When InsertMany fails for a batch, nacking every message allows one bad entry to poison the entire batch and trigger a redelivery loop that can exhaust the SQS consecutive-receive-error budget and kill the consumer. Add a processEntry helper that inserts and evaluates alerts for a single entry. On batch failure, fall back to calling processEntry per-entry so only the bad message is nacked while valid entries are acked normally. Refactor the post-batch alert loop into a shared evalAlert helper (no behaviour change on the happy path). Add unit tests for both fallback scenarios (single bad entry and full transient DB failure). Fixes hookdeck#948
Contributor
|
Seems to overlap with #953, @alexluong let's find what the right common ground between those 2 PRs is! |
Collaborator
|
Thanks for the PR @mvanhorn, I'm review it now! @alexbouchardd not quite overlap I think. The 2 PRs implemented 2 different GH issues. Only overlap is that it's related to the logmq flow but each PR solves different problem. |
Collaborator
|
Hi @mvanhorn, thanks for digging into this. After some internal discussions, we're going to close this PR as well as the underlying issue #948. After some further consideration, we realized that the per-entry insertion is not the right approach for scale and we'll need to tackle this problem in a different way. That said, the PR itself did a good job of the implementation and I appreciate the contribution! Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
processEntryhelper that inserts a single log entry and evaluates alerts for itInsertManybatch failure, fall back to callingprocessEntryper-entry instead of nacking the whole batchevalAlerthelper (no behaviour change on happy path)TestBatchProcessor_BatchFailure_SingleBadEntryandTestBatchProcessor_BatchFailure_AllEntriesFailWhy this matters
Fixes #948. With
LOG_BATCH_SIZE=1000, a single duplicate-key entry (SQLSTATE 21000:ON CONFLICT DO UPDATE command cannot affect row a second time) causesInsertManyto fail and every message in the batch to be nacked. All 1000 messages redeliver, the bad entry lands in a new batch, and the failure cycle repeats. The mass-nacking also exhausts the SQS consecutive-receive-error budget, permanently killing the consumer worker. The per-entry fallback limits blast radius to the one bad message; the remaining entries are acked normally. Transient failures (DB down) degrade gracefully - per-entry inserts all fail and everything nacks, same as before.Changes
internal/logmq/batchprocessor.go- addprocessEntryandevalAlerthelpers; callprocessEntryloop on batch insert errorinternal/logmq/batchprocessor_test.go- extendmockLogStorewithfailBatchGtfield; add two batch-failure unit testsFixes #948