根因:pullCreditFromPhp 在 db-worker 线程用裸 JDBC UPDATE users + invalidateScoreCache, 但 /credits 在 Server thread 走 getScore() 命中 scoreCache 返回旧值。 DB 实际已更新(90.77),但缓存返回旧值(100.77)→ '同步了个寂寞'。 invalidateScoreCache 和 clearScoreCache 都治标不治本——线程竞争窗口无法消除。 最终修复:getScore 去掉 cache-hit early return,每次查 DB。users 表很小(几十人), 查 DB 开销可忽略。scoreCache 仍由 setScore/addScore 写入供 checkRestrictions 去重, 但 getScore 不再提前返回缓存。 WebManager pullCreditFromPhp 循环结束后保留 clearScoreCache 兜底。
This commit is contained in:
@@ -313,9 +313,11 @@ public class CreditManager {
|
|||||||
␍
|
␍
|
||||||
/** ★ 第58批-问题4:返回 double,支持小数积分 */␍
|
/** ★ 第58批-问题4:返回 double,支持小数积分 */␍
|
||||||
public double getScore(String playerName) {␍
|
public double getScore(String playerName) {␍
|
||||||
if (scoreCache.containsKey(playerName)) {␍
|
// ★ 第98批续修复:去掉永久缓存命中——pullCreditFromPhp 用裸 JDBC UPDATE users,␍
|
||||||
return scoreCache.get(playerName);␍
|
// 缓存不知道 DB 已变 → /credits 返回旧值 → "同步了个寂寞"。␍
|
||||||
}␍
|
// users 表很小(几十人),每次查 DB 开销可忽略。␍
|
||||||
|
// scoreCache 仍由 setScore/addScore 写入,仅供 checkRestrictions 等同 tick 高频调用去重,␍
|
||||||
|
// 但 getScore 不再命中缓存提前返回——每次查 DB 保证数据新鲜。␍
|
||||||
double score = DEFAULT_INIT_SCORE;␍
|
double score = DEFAULT_INIT_SCORE;␍
|
||||||
try {␍
|
try {␍
|
||||||
PreparedStatement ps = db.getConnection().prepareStatement(␍
|
PreparedStatement ps = db.getConnection().prepareStatement(␍
|
||||||
|
|||||||
+13107
-13105
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user