fix(server/storage): stop consuming auto-increment ids on player saves - #777
Merged
Merged
Conversation
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.
Every save runs
INSERT ... ON DUPLICATE KEY UPDATEagainstplayers, whoseidcolumn isAUTO_INCREMENT. With the defaultinnodb_autoinc_lock_mode(1 on MariaDB, 2 on MySQL 8), InnoDB allocates a new id before it finds the duplicatecitizenid, so every save of an existing character burns an id. Since #731 everySetMetadatacall saves, so a busy server goes through ids quickly, and once the counter passes the signedINTmax the upsert fails withOut of range value for column 'id'. After that no existing character can be saved.This updates the row by
citizenidfirst and only runs the original upsert when no row matched (a new character, or a concurrent first save). The same columns are written in both paths, and a new character still gets a single row.Tested on MariaDB 11.4 using the statements from this change: one character saved 6 times kept
AUTO_INCREMENTat 2 and the next character got id 2. The old query moved the counter to 6 after 5 saves. Lint is clean.Fixes #762