修改asn缓存初始化方法加入参数是否强制刷新,部署多个tomcat服务时个个tomcat缓存可能存在不一致的情况,这就需要强制重新加载缓存
This commit is contained in:
@@ -65,29 +65,17 @@ public class AsnCacheUtils{
|
|||||||
return configGroupInfos;
|
return configGroupInfos;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* 初始化缓存
|
* 初始化缓存
|
||||||
|
*
|
||||||
|
* @param force是否强制刷新
|
||||||
*/
|
*/
|
||||||
//@PostConstruct
|
//@PostConstruct
|
||||||
public synchronized static void init() {
|
public synchronized static void init(boolean force) {
|
||||||
long start=System.currentTimeMillis();
|
long start=System.currentTimeMillis();
|
||||||
logger.warn("AsnCacheUtils init start...");
|
logger.warn("AsnCacheUtils init start...");
|
||||||
Cache cache=getCache(ASN_NO_CACHE);
|
Cache cache=getCache(ASN_NO_CACHE);
|
||||||
//查询总量
|
if(force) {
|
||||||
Long count=configGroupInfoDao.getCountByType(4);
|
|
||||||
//缓存key
|
|
||||||
boolean loadDatabase=false;
|
|
||||||
if(cache.getKeys().size()==0) {
|
|
||||||
loadDatabase=true;
|
|
||||||
}else {
|
|
||||||
long c=0l;
|
|
||||||
for(Object key:cache.getKeys()) {
|
|
||||||
c+=getMap(key).size();
|
|
||||||
}
|
|
||||||
if(c!=count) {
|
|
||||||
loadDatabase=true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(loadDatabase) {
|
|
||||||
List<ConfigGroupInfo> list=configGroupInfoDao.findAllList(4);
|
List<ConfigGroupInfo> list=configGroupInfoDao.findAllList(4);
|
||||||
Map<Long,Map<Long,ConfigGroupInfo>> groupMap=Maps.newHashMap();
|
Map<Long,Map<Long,ConfigGroupInfo>> groupMap=Maps.newHashMap();
|
||||||
for(ConfigGroupInfo configGroupInfo:list) {
|
for(ConfigGroupInfo configGroupInfo:list) {
|
||||||
@@ -104,7 +92,41 @@ public class AsnCacheUtils{
|
|||||||
Element element = new Element(e.getKey(), e.getValue());
|
Element element = new Element(e.getKey(), e.getValue());
|
||||||
cache.put(element);
|
cache.put(element);
|
||||||
}
|
}
|
||||||
|
}else {
|
||||||
|
//查询总量
|
||||||
|
Long count=configGroupInfoDao.getCountByType(4);
|
||||||
|
boolean loadDatabase=false;
|
||||||
|
if(cache.getKeys().size()==0) {
|
||||||
|
loadDatabase=true;
|
||||||
|
}else {
|
||||||
|
long c=0l;
|
||||||
|
for(Object key:cache.getKeys()) {
|
||||||
|
c+=getMap(key).size();
|
||||||
|
}
|
||||||
|
if(c!=count) {
|
||||||
|
loadDatabase=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(loadDatabase) {
|
||||||
|
List<ConfigGroupInfo> list=configGroupInfoDao.findAllList(4);
|
||||||
|
Map<Long,Map<Long,ConfigGroupInfo>> groupMap=Maps.newHashMap();
|
||||||
|
for(ConfigGroupInfo configGroupInfo:list) {
|
||||||
|
if(groupMap.containsKey(configGroupInfo.getAsnId()/cache_rage)) {
|
||||||
|
groupMap.get(configGroupInfo.getAsnId()/cache_rage)
|
||||||
|
.put(configGroupInfo.getAsnId(), configGroupInfo);
|
||||||
|
}else {
|
||||||
|
Map<Long,ConfigGroupInfo> m=Maps.newHashMap();
|
||||||
|
m.put(configGroupInfo.getAsnId(), configGroupInfo);
|
||||||
|
groupMap.put(configGroupInfo.getAsnId()/cache_rage, m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(Entry<Long, Map<Long, ConfigGroupInfo>> e:groupMap.entrySet()) {
|
||||||
|
Element element = new Element(e.getKey(), e.getValue());
|
||||||
|
cache.put(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long end=System.currentTimeMillis();
|
long end=System.currentTimeMillis();
|
||||||
logger.warn("AsnCacheUtils init finish,cost:"+(end-start));
|
logger.warn("AsnCacheUtils init finish,cost:"+(end-start));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1197,7 +1197,7 @@ public class BaseController {
|
|||||||
ipPortCfgs=this.checkIpCfgMulity(serviceDict, regionDict, null, list);
|
ipPortCfgs=this.checkIpCfgMulity(serviceDict, regionDict, null, list);
|
||||||
} else if (regionDict.getFunctionId().equals(600)) {// ASN IP
|
} else if (regionDict.getFunctionId().equals(600)) {// ASN IP
|
||||||
//加载asn缓存
|
//加载asn缓存
|
||||||
AsnCacheUtils.init();
|
AsnCacheUtils.init(true);
|
||||||
BlockingQueue<AsnIpTemplate> list = ei.getDataList(AsnIpTemplate.class );
|
BlockingQueue<AsnIpTemplate> list = ei.getDataList(AsnIpTemplate.class );
|
||||||
ipPortCfgs=this.checkIpCfgMulity(serviceDict, regionDict, asnNoMaps, list);
|
ipPortCfgs=this.checkIpCfgMulity(serviceDict, regionDict, asnNoMaps, list);
|
||||||
} else if (regionDict.getFunctionId().equals(301)) {// DDOS IP
|
} else if (regionDict.getFunctionId().equals(301)) {// DDOS IP
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class AsnIpController extends BaseController{
|
|||||||
|
|
||||||
// List<PolicyGroupInfo> policyGroups=policyGroupInfoService.findPolicyGroupInfosByType(4);
|
// List<PolicyGroupInfo> policyGroups=policyGroupInfoService.findPolicyGroupInfosByType(4);
|
||||||
// model.addAttribute("policyGroups", policyGroups);
|
// model.addAttribute("policyGroups", policyGroups);
|
||||||
AsnCacheUtils.init();
|
AsnCacheUtils.init(false);
|
||||||
List<ConfigGroupInfo> policyGroups=AsnCacheUtils.getAllAsnGroup();
|
List<ConfigGroupInfo> policyGroups=AsnCacheUtils.getAllAsnGroup();
|
||||||
model.addAttribute("policyGroups", policyGroups);
|
model.addAttribute("policyGroups", policyGroups);
|
||||||
return "/basics/asnIpCfgList";
|
return "/basics/asnIpCfgList";
|
||||||
@@ -137,7 +137,7 @@ public class AsnIpController extends BaseController{
|
|||||||
@RequestMapping(value="ajaxGroupName",method=RequestMethod.POST)
|
@RequestMapping(value="ajaxGroupName",method=RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Map<String, String> ajaxGroupName(Model model,String ids){
|
public Map<String, String> ajaxGroupName(Model model,String ids){
|
||||||
AsnCacheUtils.init();
|
AsnCacheUtils.init(false);
|
||||||
Map<String, String> groupMap=new HashMap<>();
|
Map<String, String> groupMap=new HashMap<>();
|
||||||
for(String id:ids.split(",")) {
|
for(String id:ids.split(",")) {
|
||||||
ConfigGroupInfo info=AsnCacheUtils.get(Long.parseLong(id));
|
ConfigGroupInfo info=AsnCacheUtils.get(Long.parseLong(id));
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
|||||||
configGroupInfoS.clear();
|
configGroupInfoS.clear();
|
||||||
}
|
}
|
||||||
//刷新缓存
|
//刷新缓存
|
||||||
AsnCacheUtils.init();
|
AsnCacheUtils.init(true);
|
||||||
long end=System.currentTimeMillis();
|
long end=System.currentTimeMillis();
|
||||||
logger.warn("Save group finish,cost:"+(end-start));
|
logger.warn("Save group finish,cost:"+(end-start));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user