家族升级锁超时时间延长

This commit is contained in:
tianfeng 2026-03-09 18:28:41 +08:00
parent 66eb9a1af4
commit af920c3e95

View File

@ -86,6 +86,8 @@ public class FamilyCommon {
private final FamilyMemberTotalExpService familyMemberTotalExpService; private final FamilyMemberTotalExpService familyMemberTotalExpService;
private final RedisService redisService; private final RedisService redisService;
private static final long BASE_RETRY_INTERVAL = 200L;
private static final int MAX_RETRY = 8;
/** /**
* 移除群聊. * 移除群聊.
@ -134,11 +136,10 @@ public class FamilyCommon {
} }
String lockKey = "family:level:lock:" + member.getFamilyId(); String lockKey = "family:level:lock:" + member.getFamilyId();
int maxRetry = 5;
int retryCount = 0; int retryCount = 0;
boolean lockAcquired = false; boolean lockAcquired = false;
while (retryCount < maxRetry) { while (retryCount < MAX_RETRY) {
try { try {
lockAcquired = redisService.setIfAbsent(lockKey, "1", 30, TimeUnit.SECONDS); lockAcquired = redisService.setIfAbsent(lockKey, "1", 30, TimeUnit.SECONDS);
@ -163,8 +164,8 @@ public class FamilyCommon {
// 未获取到锁进行重试 // 未获取到锁进行重试
retryCount++; retryCount++;
if (retryCount < maxRetry) { if (retryCount < MAX_RETRY) {
Thread.sleep(100L * retryCount); Thread.sleep((long)(BASE_RETRY_INTERVAL * Math.pow(2, retryCount)));
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -198,7 +199,7 @@ public class FamilyCommon {
// 重试失败日志 // 重试失败日志
log.error("获取家族升级锁失败,重试{}次后放弃,FamilyId:{},userId:{},exp:{}", log.error("获取家族升级锁失败,重试{}次后放弃,FamilyId:{},userId:{},exp:{}",
maxRetry, member.getFamilyId(), userId, exp); MAX_RETRY, member.getFamilyId(), userId, exp);
} }
/** /**