|
|
@@ -54,11 +54,14 @@ public class FeatureV2Client {
|
|
|
*/
|
|
|
public Map<String, String> multiGetFeature(List<FeatureKeyProto> protos) {
|
|
|
if (CollectionUtils.isEmpty(protos)) {
|
|
|
+ log.debug("multiGetFeature: protos is empty, return empty map");
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 从第 0 次尝试开始
|
|
|
- return multiGetFeatureWithRetry(protos, 0);
|
|
|
+ Map<String, String> result = multiGetFeatureWithRetry(protos, 0);
|
|
|
+ log.debug("multiGetFeature: end, result.size={}", result != null ? result.size() : 0);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -69,6 +72,8 @@ public class FeatureV2Client {
|
|
|
* @return 特征数据 Map
|
|
|
*/
|
|
|
private Map<String, String> multiGetFeatureWithRetry(List<FeatureKeyProto> protos, int attemptCount) {
|
|
|
+ log.debug("multiGetFeatureWithRetry: start, attempt={}, protos.size={}", attemptCount, protos.size());
|
|
|
+
|
|
|
MultiGetFeatureRequest request = MultiGetFeatureRequest.newBuilder()
|
|
|
.addAllFeatureKey(protos)
|
|
|
.build();
|
|
|
@@ -105,9 +110,9 @@ public class FeatureV2Client {
|
|
|
Status.Code code = e.getStatus().getCode();
|
|
|
String description = e.getStatus().getDescription();
|
|
|
|
|
|
- // 记录详细的错误信息
|
|
|
- log.error("gRPC call failed: code={}, description={}, attempt={}/{}, protos.size={}",
|
|
|
- code, description, attemptCount + 1, MAX_RETRY_ATTEMPTS + 1, protos.size(), e);
|
|
|
+ // 记录详细的错误信息(使用 error 级别确保一定会输出)
|
|
|
+ log.error("gRPC call failed: code={}, description={}, attempt={}/{}, protos.size={}, exception={}",
|
|
|
+ code, description, attemptCount + 1, MAX_RETRY_ATTEMPTS + 1, protos.size(), e.getClass().getName(), e);
|
|
|
|
|
|
// 判断是否应该重试
|
|
|
if (shouldRetry(code) && attemptCount < MAX_RETRY_ATTEMPTS) {
|
|
|
@@ -129,6 +134,11 @@ public class FeatureV2Client {
|
|
|
log.error("gRPC call failed after {} attempts, returning empty result for graceful degradation. code={}",
|
|
|
attemptCount + 1, code);
|
|
|
return Collections.emptyMap();
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 捕获所有其他异常(不应该发生,但为了安全起见)
|
|
|
+ log.error("multiGetFeatureWithRetry: unexpected exception, attempt={}/{}, protos.size={}, exception={}",
|
|
|
+ attemptCount + 1, MAX_RETRY_ATTEMPTS + 1, protos.size(), e.getClass().getName(), e);
|
|
|
+ return Collections.emptyMap();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -142,6 +152,10 @@ public class FeatureV2Client {
|
|
|
// UNAVAILABLE: 连接不可用(如网络断开、连接关闭)- 应该重试
|
|
|
// DEADLINE_EXCEEDED: 超时 - 应该重试
|
|
|
// RESOURCE_EXHAUSTED: 资源耗尽(如连接池满)- 应该重试
|
|
|
- return code == Status.Code.UNAVAILABLE || code == Status.Code.DEADLINE_EXCEEDED || code == Status.Code.RESOURCE_EXHAUSTED;
|
|
|
+ // CANCELLED: 请求被取消(如服务端处理失败、连接中断)- 应该重试
|
|
|
+ return code == Status.Code.UNAVAILABLE
|
|
|
+ || code == Status.Code.DEADLINE_EXCEEDED
|
|
|
+ || code == Status.Code.RESOURCE_EXHAUSTED
|
|
|
+ || code == Status.Code.CANCELLED;
|
|
|
}
|
|
|
}
|