fix(database): 修复玩家数据并发写入一致性#710
Open
zhibeigg wants to merge 1 commit into
Open
Conversation
通过复合唯一索引、兼容迁移和原子 upsert 阻止重复记录,并收敛缓存延迟写与调度竞态以确保最新值最终落库。
11 tasks
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.
原有问题
玩家数据库的表约束、首次写入和延迟缓存写回不是一个完整的原子流程:
(user, key)复合唯一约束,并发首次写入采用先查后插时可能同时创建多行。典型触发场景与后果
本 PR 修改
(user, key)复合唯一约束;升级时按稳定顺序保留最新记录,再创建正确索引。修改目的
保证同一玩家键在并发创建、连续更新和插件关闭场景下仍只有一个确定的最终值,避免重复记录、数据回档和迁移后约束失效。
兼容性与行为变化
验证
./gradlew :module:database:database-player:build :module:database:database-player-redis:build --rerun-tasks --no-parallel --stacktracegit diff --checkRefs #703