|
@@ -7,10 +7,13 @@ import com.tzld.piaoquan.recommend.feature.model.feature.FeatureKeyProto;
|
|
import com.tzld.piaoquan.recommend.feature.model.feature.MultiGetFeatureRequest;
|
|
import com.tzld.piaoquan.recommend.feature.model.feature.MultiGetFeatureRequest;
|
|
import com.tzld.piaoquan.recommend.feature.model.feature.MultiGetFeatureResponse;
|
|
import com.tzld.piaoquan.recommend.feature.model.feature.MultiGetFeatureResponse;
|
|
import com.tzld.piaoquan.recommend.feature.util.CommonCollectionUtils;
|
|
import com.tzld.piaoquan.recommend.feature.util.CommonCollectionUtils;
|
|
|
|
+import com.tzld.piaoquan.recommend.feature.util.CompressionUtil;
|
|
|
|
+import com.tzld.piaoquan.recommend.feature.util.JSONUtils;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -30,6 +33,13 @@ public class FeatureV2Service {
|
|
@ApolloJsonValue("${dts.config.v2:}")
|
|
@ApolloJsonValue("${dts.config.v2:}")
|
|
private List<DTSConfig> dtsConfigs;
|
|
private List<DTSConfig> dtsConfigs;
|
|
|
|
|
|
|
|
+ @ApolloJsonValue("${dts.config:}")
|
|
|
|
+ private List<DTSConfig> newDtsConfigs;
|
|
|
|
+
|
|
|
|
+ @Value("${compress.switch: false}")
|
|
|
|
+ private boolean compressSwitch;
|
|
|
|
+
|
|
|
|
+
|
|
public MultiGetFeatureResponse multiGetFeature(MultiGetFeatureRequest request) {
|
|
public MultiGetFeatureResponse multiGetFeature(MultiGetFeatureRequest request) {
|
|
if (request.getFeatureKeyCount() == 0) {
|
|
if (request.getFeatureKeyCount() == 0) {
|
|
return MultiGetFeatureResponse.newBuilder()
|
|
return MultiGetFeatureResponse.newBuilder()
|
|
@@ -39,8 +49,11 @@ public class FeatureV2Service {
|
|
// 目前都在一个Redis,所以放在一个list简化处理
|
|
// 目前都在一个Redis,所以放在一个list简化处理
|
|
List<String> redisKeys = CommonCollectionUtils.toList(request.getFeatureKeyList(), fk -> redisKey(fk));
|
|
List<String> redisKeys = CommonCollectionUtils.toList(request.getFeatureKeyList(), fk -> redisKey(fk));
|
|
List<String> values = redisTemplate.opsForValue().multiGet(redisKeys);
|
|
List<String> values = redisTemplate.opsForValue().multiGet(redisKeys);
|
|
|
|
+ if (compressSwitch) {
|
|
|
|
+ values = CommonCollectionUtils.toList(values, CompressionUtil::snappyDecompress);
|
|
|
|
+ }
|
|
|
|
|
|
- // log.info("feature key {} value {}", JSONUtils.toJson(redisKeys), JSONUtils.toJson(values));
|
|
|
|
|
|
+ log.info("feature key {} value {}", JSONUtils.toJson(redisKeys), JSONUtils.toJson(values));
|
|
|
|
|
|
MultiGetFeatureResponse.Builder builder = MultiGetFeatureResponse.newBuilder();
|
|
MultiGetFeatureResponse.Builder builder = MultiGetFeatureResponse.newBuilder();
|
|
builder.setResult(Result.newBuilder().setCode(1));
|
|
builder.setResult(Result.newBuilder().setCode(1));
|
|
@@ -53,9 +66,10 @@ public class FeatureV2Service {
|
|
|
|
|
|
// Note:写入和读取的key生成规则应保持一致
|
|
// Note:写入和读取的key生成规则应保持一致
|
|
private String redisKey(FeatureKeyProto fk) {
|
|
private String redisKey(FeatureKeyProto fk) {
|
|
- Optional<DTSConfig> optional = dtsConfigs.stream()
|
|
|
|
- .filter(c -> c.getOdps() != null && StringUtils.equals(c.getOdps().getTable(), fk.getTableName()))
|
|
|
|
- .findFirst();
|
|
|
|
|
|
+
|
|
|
|
+ Optional<DTSConfig> optional = (compressSwitch ? newDtsConfigs : dtsConfigs)
|
|
|
|
+ .stream().filter(c -> c.getOdps() != null && StringUtils.equals(c.getOdps().getTable(),
|
|
|
|
+ fk.getTableName())).findFirst();
|
|
if (!optional.isPresent()) {
|
|
if (!optional.isPresent()) {
|
|
log.error("table {} not config", fk.getTableName());
|
|
log.error("table {} not config", fk.getTableName());
|
|
return "";
|
|
return "";
|