fix(points): eliminate lost-update race on UserProgress totals - #1111
Open
Danielobito009 wants to merge 1 commit into
Open
fix(points): eliminate lost-update race on UserProgress totals#1111Danielobito009 wants to merge 1 commit into
Danielobito009 wants to merge 1 commit into
Conversation
Replace read-modify-write with atomic SQL increment in addPoints(): - Use SQL upsert with ON CONFLICT DO UPDATE SET col = col + :points instead of JS totalPoints += points (eliminates lost-update race) - Wrap PointTransaction insert and aggregate update in single database transaction (eliminates partial-write inconsistency) - Handle first-award with upsert instead of conditional create (eliminates duplicate row race on concurrent first awards) - Inject DataSource for QueryRunner-based transaction control test(points): assert concurrent awards accumulate correctly - N=10 concurrent awards produce total equal to N * pointsPerAward - Aggregate total always equals sum of ledger rows - Two concurrent first awards produce exactly one progress row - Rollback on failure leaves no partial writes - Large burst (N=50) produces correct total Closes rinafcode#1001
|
@Danielobito009 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Well done on the job done so far! |
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.
Fix: Eliminate Lost-Update Race on UserProgress Totals in PointsService.addPoints
Issue: #1001
Problem
The
PointsService.addPoints()method contained a critical lost-update race condition that could silently lose points when concurrent calls updated the same user's progress.Root Cause: