火箭能量异步刷新数据丢失 问题处理
This commit is contained in:
parent
3cbcb484cc
commit
b39b6ac26c
@ -103,19 +103,27 @@ public class RocketEnergyAggregator {
|
|||||||
|
|
||||||
distributedLockUtil.executeWithLock(lockKey, 10L, () -> {
|
distributedLockUtil.executeWithLock(lockKey, 10L, () -> {
|
||||||
|
|
||||||
// 原子性地取出所有数据
|
// 先 peek 不删除,等处理成功后再删除
|
||||||
List<RocketEnergyAddCmd> batch = new ArrayList<>();
|
List<RocketEnergyAddCmd> batch = new ArrayList<>(queue); // 复制数据,不删除原队列
|
||||||
RocketEnergyAddCmd cmd;
|
|
||||||
while ((cmd = queue.poll()) != null) {
|
|
||||||
batch.add(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (batch.isEmpty()) {
|
if (batch.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理这个房间的能量增加
|
try {
|
||||||
processRoomEnergyBatch(roomId, batch);
|
// 处理这个房间的能量增加
|
||||||
|
processRoomEnergyBatch(roomId, batch);
|
||||||
|
|
||||||
|
// 处理成功后才删除队列中的数据
|
||||||
|
for (int i = 0; i < batch.size(); i++) {
|
||||||
|
queue.poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理房间{}火箭能量失败,数据保留在队列中等待重试", roomId, e);
|
||||||
|
throw e; // 重新抛出,让外层处理
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}, "火箭能量刷新操作中");
|
}, "火箭能量刷新操作中");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user