Skip to content

fix(server/storage): stop consuming auto-increment ids on player saves - #777

Merged
ChatDisabled merged 1 commit into
mainfrom
fix/issue-762
Sep 26, 2026
Merged

ChatDisabled merged 1 commit into
mainfrom
fix/issue-762

Conversation

@ChatDisabled

Copy link
Copy Markdown
Member

Every save runs INSERT ... ON DUPLICATE KEY UPDATE against players, whose id column is AUTO_INCREMENT. With the default innodb_autoinc_lock_mode (1 on MariaDB, 2 on MySQL 8), InnoDB allocates a new id before it finds the duplicate citizenid, so every save of an existing character burns an id. Since #731 every SetMetadata call saves, so a busy server goes through ids quickly, and once the counter passes the signed INT max the upsert fails with Out of range value for column 'id'. After that no existing character can be saved.

This updates the row by citizenid first 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_INCREMENT at 2 and the next character got id 2. The old query moved the counter to 6 after 5 saves. Lint is clean.

Fixes #762

@ChatDisabled
ChatDisabled merged commit f0553b6 into main Sep 26, 2026
5 checks passed
@ChatDisabled
ChatDisabled deleted the fix/issue-762 branch September 26, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect SQL query usage in player storage

1 participant