Repository navigation
Make refresh ticket deduction atomic with opponent refresh - #192
Merged
Merged
Conversation
The opponent refresh, ticket deduction and usage log were committed separately, so a failure after the refresh left new opponents without a deducted ticket. The deduction also read-modified-wrote the status row, letting concurrent refreshes lose a deduction and leave two opponent sets active. Run all three in one transaction and deduct with a conditional ExecuteUpdate (remaining_count > 0) first, which locks the status row and serializes concurrent refreshes for the same avatar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
POST /available-opponents/refreshcommitted three steps separately:RefreshAvailableOpponents(own transaction)UpdateRefreshTicketStatusPerRound(read-modify-write on the tracked entity)AddRefreshTicketUsageLogThis caused two issues observed on heimdall in season 44, round 1:
used_countone lower than the number of sets). This gave the user one extra +22 opportunity in the round.remaining_countand wrote the same value back (5 usage logs vsused_count = 4). Because neither saw the other's uncommitted set, two opponent sets stayed active at the same time (10 active opponents).Both affected records have been corrected manually in the DB.
Fix
ITicketRepository.TryDeductRefreshTicket, which does a conditionalExecuteUpdate(remaining_count > 0).ReadCommittedtransaction, deducting first. TheUPDATEholds the status row lock until commit, so concurrent refreshes for the same avatar are serialized and the later one soft-deletes the set committed by the earlier one. If no ticket is left, it returnsNO_REFRESH_TICKETSas before.RefreshAvailableOpponents. It is a singleSaveChangesand now runs in the caller's transaction (a nestedBeginTransactionwould throw).Test
dotnet buildpassesdotnet test ArenaService.Testspasses (39/39)🤖 Generated with Claude Code