Repository navigation
fix(player): detect stale player data writes across servers - #281
Merged
Merged
Conversation
A player can be written from a stale copy after a server switch or an admin edit, which silently overwrote newer data. The player model now carries the entity version, updates are only accepted while the stored version matches, and a conflict reloads the database state into the cache instead of writing.
Contributor
Test results 36 files 36 suites 21s ⏱️ Results for commit 52060e3. |
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
With player data now cached on the server the player is on (#279), one gap remained: when a player switches between two servers running StarDust, Velocity connects them to the new server before disconnecting them from the old one. The new server can load the player before the old server's last change has reached the database, and an administrator can change a player who is online somewhere else. In both cases an outdated copy could later overwrite newer data without anyone noticing.
Every player copy now remembers the database version it was loaded with. A write is only accepted while that version is still the stored one; otherwise it is rejected, the server reloads the current data from the database and logs a warning with both versions. A player who is inserted twice at the same moment keeps the existing row instead of failing. No message broker or new service is needed: the version column already exists, and a player is only ever written by the server they are on.
Implements the OpenSpec change
guard-player-data-handoff(#278).Notes
./gradlew cleanTest testpasses; 6 new database tests against an in-memory H2 database (stale write rejected, matching write advances the version, consecutive writes of the same copy succeed, duplicate insert keeps the stored row) and a cache test for the reload on conflict.