Authored by chenchao

add log

@@ -30,6 +30,7 @@ public class RedisLimitor { @@ -30,6 +30,7 @@ public class RedisLimitor {
30 30
31 private Integer threshold; 31 private Integer threshold;
32 32
  33 + @Builder.Default
33 private int retry = 3; 34 private int retry = 3;
34 35
35 /** 36 /**
@@ -48,9 +49,11 @@ public class RedisLimitor { @@ -48,9 +49,11 @@ public class RedisLimitor {
48 if (threshold <= 0 || StringUtils.isBlank(key)){ 49 if (threshold <= 0 || StringUtils.isBlank(key)){
49 return false; 50 return false;
50 } 51 }
51 - logger.info("enter acquire,key {} threshold {} retry {}", key, threshold, retry); 52 + logger.info("enter RedisLimitor.tryAcquire,key {} threshold {} retry {}", key, threshold, retry);
52 String valueFromCache = redisTemplate.getStringRedisTemplate().opsForValue().get(key); 53 String valueFromCache = redisTemplate.getStringRedisTemplate().opsForValue().get(key);
53 boolean notExisted = StringUtils.isBlank(valueFromCache); 54 boolean notExisted = StringUtils.isBlank(valueFromCache);
  55 + logger.info("RedisLimitor.tryAcquire get value from cache, key {} threshold {} retry {} valueFromCache {}",
  56 + key, threshold, retry, valueFromCache);
54 //distributed lock by set nx 57 //distributed lock by set nx
55 if (notExisted){ 58 if (notExisted){
56 //起始设置为0 59 //起始设置为0
@@ -78,7 +81,8 @@ public class RedisLimitor { @@ -78,7 +81,8 @@ public class RedisLimitor {
78 logger.warn("RedisLimitor.acquire over limit,key {} threshold from cache {},int val {}, config val {}", key, valueFromCache, intValFromCache, threshold); 81 logger.warn("RedisLimitor.acquire over limit,key {} threshold from cache {},int val {}, config val {}", key, valueFromCache, intValFromCache, threshold);
79 return false; 82 return false;
80 } 83 }
81 - 84 + logger.info("RedisLimitor.tryAcquire finish, key {} threshold {} retry {} valueFromCache {}",
  85 + key, threshold, retry, valueFromCache);
82 return true; 86 return true;
83 } 87 }
84 88
@@ -140,7 +140,7 @@ public class MsgService { @@ -140,7 +140,7 @@ public class MsgService {
140 RedisKeyBuilder rkb = CacheKeyBuilder.bidOrderNoticeKey(tabType, uid, caseId); 140 RedisKeyBuilder rkb = CacheKeyBuilder.bidOrderNoticeKey(tabType, uid, caseId);
141 //use thread pool to control 141 //use thread pool to control
142 Supplier<Integer> supplier = () -> sendPrdPush(uid, sellerOrderGoods, product); 142 Supplier<Integer> supplier = () -> sendPrdPush(uid, sellerOrderGoods, product);
143 - executorService.submit(()->redisLimitStrategy.checkLimit(uid, storageId, rkb, noticeRuleNodeMap, supplier)); 143 + executorService.submit(()->redisLimitStrategy.limit(uid, storageId, rkb, noticeRuleNodeMap, supplier));
144 } 144 }
145 145
146 long taskCount = executorService.getTaskCount(); 146 long taskCount = executorService.getTaskCount();
@@ -6,6 +6,8 @@ import com.yohoufo.common.concurrent.RedisLimitor; @@ -6,6 +6,8 @@ import com.yohoufo.common.concurrent.RedisLimitor;
6 import com.yohoufo.msg.constants.RuleKeyType; 6 import com.yohoufo.msg.constants.RuleKeyType;
7 import com.yohoufo.msg.model.NoticeRuleNode; 7 import com.yohoufo.msg.model.NoticeRuleNode;
8 import lombok.Builder; 8 import lombok.Builder;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
9 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service; 12 import org.springframework.stereotype.Service;
11 13
@@ -18,11 +20,12 @@ import java.util.function.Supplier; @@ -18,11 +20,12 @@ import java.util.function.Supplier;
18 20
19 @Service 21 @Service
20 public class RedisLimitStrategy { 22 public class RedisLimitStrategy {
  23 + private final Logger logger = LoggerFactory.getLogger(getClass());
21 24
22 @Autowired 25 @Autowired
23 private RedisConcurrentFactory redisConcurrentFactory; 26 private RedisConcurrentFactory redisConcurrentFactory;
24 27
25 - public boolean checkLimit(Integer uid, Integer storageId, 28 + public boolean limit(Integer uid, Integer storageId,
26 RedisKeyBuilder rkb, 29 RedisKeyBuilder rkb,
27 Map<Integer, NoticeRuleNode> noticeRuleNodeMap, 30 Map<Integer, NoticeRuleNode> noticeRuleNodeMap,
28 Supplier<Integer> pushSupplier){ 31 Supplier<Integer> pushSupplier){
@@ -50,6 +53,8 @@ public class RedisLimitStrategy { @@ -50,6 +53,8 @@ public class RedisLimitStrategy {
50 } 53 }
51 54
52 } 55 }
  56 + logger.info("RedisLimitStrategy.limit check by all config ,uid {} sku {} result {}",
  57 + uid, storageId, result);
53 //所有条件都满足后,聚合处理自增 58 //所有条件都满足后,聚合处理自增
54 if (result){ 59 if (result){
55 pushSupplier.get(); 60 pushSupplier.get();
@@ -59,7 +64,7 @@ public class RedisLimitStrategy { @@ -59,7 +64,7 @@ public class RedisLimitStrategy {
59 return result; 64 return result;
60 } 65 }
61 66
62 - public CheckResultNode checkLimitBySingleRule(RedisKeyBuilder rkb, NoticeRuleNode ruleNode){ 67 + private CheckResultNode checkLimitBySingleRule(RedisKeyBuilder rkb, NoticeRuleNode ruleNode){
63 68
64 Integer uid = ruleNode.getUid(); 69 Integer uid = ruleNode.getUid();
65 TimeUnit timeUnit = ruleNode.getTimeUnit(); 70 TimeUnit timeUnit = ruleNode.getTimeUnit();