|
|
@@ -32,26 +32,17 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class FeatureV2Service {
|
|
|
- @Qualifier("redisTemplate")
|
|
|
- @Autowired
|
|
|
- private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
@Qualifier("byteRedisTemplate")
|
|
|
@Autowired
|
|
|
private RedisTemplate<String, byte[]> byteRedisTemplate;
|
|
|
|
|
|
@ApolloJsonValue("${dts.config:}")
|
|
|
- private List<DTSConfig> newDtsConfigs;
|
|
|
-
|
|
|
- @ApolloJsonValue("${dts.config.v2:}")
|
|
|
- private List<DTSConfig> dtsConfigsV2;
|
|
|
+ private List<DTSConfig> dtsConfigs;
|
|
|
|
|
|
@Value("${feature.mget.batch.size:300}")
|
|
|
private Integer batchSize;
|
|
|
|
|
|
- @Value("${feature.service.optimize.switch:false}")
|
|
|
- private Boolean optimizeV3Switch;
|
|
|
-
|
|
|
public MultiGetFeatureResponse multiGetFeature(MultiGetFeatureRequest request) {
|
|
|
int keyCount = request.getFeatureKeyCount();
|
|
|
if (keyCount == 0) {
|
|
|
@@ -62,17 +53,10 @@ public class FeatureV2Service {
|
|
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
|
- List<String> redisKeys;
|
|
|
- if (Boolean.TRUE.equals(optimizeV3Switch)) {
|
|
|
- redisKeys = request.getFeatureKeyList().stream()
|
|
|
- .map(this::buildRedisKeyV2)
|
|
|
- .collect(Collectors.toList());
|
|
|
- } else {
|
|
|
- redisKeys = request.getFeatureKeyList().stream()
|
|
|
- .map(this::redisKey)
|
|
|
- .map(s -> String.format("%s:v2", s))
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
+ List<String> redisKeys = request.getFeatureKeyList()
|
|
|
+ .stream()
|
|
|
+ .map(this::redisKey)
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
int safeBatchSize = (batchSize == null || batchSize <= 0) ? 300 : batchSize;
|
|
|
|
|
|
@@ -106,9 +90,9 @@ public class FeatureV2Service {
|
|
|
}
|
|
|
} catch (TimeoutException e) {
|
|
|
bf.future.cancel(true);
|
|
|
- log.warn("Batch mGetV2 timeout, startIndex={}, size={}", bf.startIndex, bf.size);
|
|
|
+ log.warn("Batch mGet timeout, startIndex={}, size={}", bf.startIndex, bf.size);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("Batch mGetV2 failed, startIndex={}, size={}", bf.startIndex, bf.size, e);
|
|
|
+ log.error("Batch mGet failed, startIndex={}, size={}", bf.startIndex, bf.size, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -140,15 +124,11 @@ public class FeatureV2Service {
|
|
|
}
|
|
|
|
|
|
private String redisKey(FeatureKeyProto fk) {
|
|
|
- return this.buildRedisKey(fk, newDtsConfigs);
|
|
|
- }
|
|
|
-
|
|
|
- private String buildRedisKeyV2(FeatureKeyProto fk) {
|
|
|
- return this.buildRedisKey(fk, dtsConfigsV2);
|
|
|
+ return this.buildRedisKey(fk, dtsConfigs);
|
|
|
}
|
|
|
|
|
|
// Note:写入和读取的key生成规则应保持一致
|
|
|
- private String buildRedisKey(FeatureKeyProto fk, List<DTSConfig> dtsConfigs){
|
|
|
+ private String buildRedisKey(FeatureKeyProto fk, List<DTSConfig> dtsConfigs) {
|
|
|
Optional<DTSConfig> optional = dtsConfigs.stream()
|
|
|
.filter(c -> c.getOdps() != null && StringUtils.equals(c.getOdps().getTable(), fk.getTableName()))
|
|
|
.findFirst();
|