提交一些更改

This commit is contained in:
super
2026-05-20 09:05:28 +08:00
parent 9639738724
commit 76695a31c6
28 changed files with 1620 additions and 8062 deletions
@@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
import java.time.Duration;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
@Slf4j
@Service
@@ -19,6 +20,12 @@ public class CozeCredentialPoolService {
private static final Duration INFLIGHT_TTL = Duration.ofMinutes(30);
/**
* 每个 moduleType 只 WARN 一次,避免高频日志噪音。
* key = moduleType,value = 仅作占位,仅用 putIfAbsent 语义判断"是否已经 WARN 过"。
*/
private final ConcurrentHashMap<String, Boolean> stripeWarnedModules = new ConcurrentHashMap<>();
private final CozeCredentialMapper cozeCredentialMapper;
private final StringRedisTemplate stringRedisTemplate;
@@ -63,6 +70,16 @@ public class CozeCredentialPoolService {
return null;
}
int safeStripeSize = Math.max(1, stripeSize);
// 自检:当 stripe < credentials.size() 时凭据轮换会偏向首张凭据,
// 通常说明 stripeSize 配置错(推荐 stripe == credentials.size())。
// 仅 WARN 一次,避免日志噪音;不阻断启动,留运维自行调整。
if (safeStripeSize < credentials.size() && moduleType != null && !moduleType.isBlank()) {
if (stripeWarnedModules.putIfAbsent(moduleType, Boolean.TRUE) == null) {
log.warn("[coze-credential] stripeSize({}) < credentials.size({}) for moduleType={}, "
+ "round-robin will be biased; consider setting stripeSize == credentials.size()",
safeStripeSize, credentials.size(), moduleType);
}
}
long cursor = nextCursor(moduleType);
int index = (int) ((Math.max(0L, cursor) / safeStripeSize) % credentials.size());
return credentials.get(index);