[redisson]RMapCache监听过期事件,第一条消息重复

2024-07-18 38 views
8

@Component public class ModelAutoOfflineInitializr {

private static final Logger logger = LoggerFactory.getLogger(ModelAutoOfflineInitializr.class);

@Autowired
private RedissonClient redissonClient;

@Autowired
private ModelService modelService;

@Value("${train.model.auto.offline.time}")
private Long autoOfflineTime;

@Async
public void executeAsync() {
    logger.info("准备加载已发布在云服务上的模型...");
    RMapCache<String, ModelRecord> map = redissonClient.getMapCache(RedisConstant.ALGORITHMTRAINING_ONLINE_MODEL_MAP);
    map.addListener(new EntryExpiredListener<String, ModelRecord>() {
        @Override
        public void onExpired(EntryEvent<String, ModelRecord> entryEvent) {
            String algorithmServiceId = entryEvent.getValue().getAlgorithmServiceId();
            try {
                logger.info(algorithmServiceId+"模型1个小时内没有被调用,置入下线处理队列..");
            } catch (Exception e) {
                logger.error("云服务模型下线异常", e);
            } 
        }
    });
    loadCloudServiceModelRecord(map);
}

private void loadCloudServiceModelRecord(RMapCache<String, ModelRecord> map) {
    List<ModelRecord> modelRecords = modelService.getAllCloudServiceModelRecord();
    for (ModelRecord modelRecord : modelRecords) {
        if(!map.containsKey(modelRecord.getAlgorithmServiceId())){
            logger.info("加载云服务模型--"+modelRecord.getAlgorithmServiceId());
            map.put(modelRecord.getAlgorithmServiceId(), modelRecord, autoOfflineTime, TimeUnit.SECONDS);
        }
    }
}

}

15:03:00.688 [main] INFO c.y.s.a.b.ModelAutoOfflineInitializr - 加载云服务模型--258 15:03:00.699 [main] INFO c.y.s.a.b.ModelAutoOfflineInitializr - 加载云服务模型--259 15:03:00.704 [main] INFO c.y.s.a.b.ModelAutoOfflineInitializr - 加载云服务模型--260 15:03:00.709 [main] INFO c.y.s.a.b.ModelAutoOfflineInitializr - 加载云服务模型--256 15:03:00.760 [main] INFO c.y.s.a.SaasAlgorithmtrainingApplication - Started SaasAlgorithmtrainingApplication in 37.839 seconds (JVM running for 38.498) 15:03:05.063 [Timer-0] INFO c.y.p.k.c.masterkey.MasterKeyManager - MasterKeyManager Refresh kms.3alevel.saas,100 Success! 15:03:15.316 [redisson-3-2] INFO c.y.s.a.b.ModelAutoOfflineInitializr - 258模型1个小时内没有被调用,置入下线处理队列.. 15:03:15.316 [redisson-3-2] INFO c.y.s.a.b.ModelAutoOfflineInitializr - 259模型1个小时内没有被调用,置入下线处理队列.. 15:03:15.316 [redisson-3-2] INFO c.y.s.a.b.ModelAutoOfflineInitializr - 260模型1个小时内没有被调用,置入下线处理队列.. 15:03:15.316 [redisson-3-2] INFO c.y.s.a.b.ModelAutoOfflineInitializr - 256模型1个小时内没有被调用,置入下线处理队列.. 15:03:15.316 [redisson-3-2] INFO c.y.s.a.b.ModelAutoOfflineInitializr - 258模型1个小时内没有被调用,置入下线处理队列..

258这个模型,监听器监听到2次,但是实际只放进去一次,并且,我查看了RMapCache里也的确是一条数据,每次都是第一条数据会被监听到2次,so,问题是个什么情况?求大神解答!!!

回答

8

自己顶一下

4

能给提供一个重现吗?

1

目前我们测试环境一直是这种情况,重现可以的,你这边需要我提供哪些数据?

1

如果不麻烦的话,能否提供在https://github.com/redisson/redisson/blob/master/redisson/src/test/java/org/redisson/RedissonMapCacheTest.java 这个测试类里提供相关的重现代码?