1:解决并发量大时无法获取redis连接的问题
2:解决加载id映射关系时遇见无法找到id关系的数据报错的问题
This commit is contained in:
@@ -36,10 +36,13 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent event) {
|
||||
try {
|
||||
long begin = System.currentTimeMillis();
|
||||
for (int i = 0; i < Configurations.getIntProperty("maxRedisDBIndex", 6); i++) {
|
||||
RedisTemplate<String, String> redisTemplate = SpringContextHolder.getBean("redisTemplate" + i);
|
||||
getAllId(redisTemplate, i);
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
logger.info("从redis读取数据需要" + ((end - begin) / 1000) + "秒");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -97,57 +100,60 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
|
||||
for (Long groupId : groupCompileIdMap.keySet()) {
|
||||
if (idRelationMap.containsKey(redisDBIndex)) {
|
||||
MaatRelation maatRelation = idRelationMap.get(redisDBIndex);
|
||||
|
||||
Map<Long, Set<Long>> compileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
||||
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
||||
for (Long compileId : compileIdList) {
|
||||
if (compileAndGroupMap.containsKey(compileId)) {
|
||||
compileAndGroupMap.get(compileId).add(groupId);
|
||||
} else {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(groupId);
|
||||
compileAndGroupMap.put(compileId, set);
|
||||
Set<String> regionIdSet = groupRegionIdMap.get(groupId);
|
||||
if (regionIdSet != null && regionIdSet.size() > 0) {// 防止出现错误数据,redis里面有域配置但是找不多对应的编译配置,分组配置,或者有分组配置但是找不到域或编译,或者有编译找不到分组和域
|
||||
MaatRelation maatRelation = idRelationMap.get(redisDBIndex);
|
||||
Map<Long, Set<Long>> compileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
||||
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
||||
for (Long compileId : compileIdList) {
|
||||
if (compileAndGroupMap.containsKey(compileId)) {
|
||||
compileAndGroupMap.get(compileId).add(groupId);
|
||||
} else {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(groupId);
|
||||
compileAndGroupMap.put(compileId, set);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<Long>> groupAndCompileMap = maatRelation.getGroupAndCompileMap();
|
||||
if (groupAndCompileMap.containsKey(groupId)) {
|
||||
groupAndCompileMap.get(groupId).addAll(compileIdList);
|
||||
} else {
|
||||
groupAndCompileMap.put(groupId, compileIdList);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<Long>> groupAndCompileMap = maatRelation.getGroupAndCompileMap();
|
||||
if (groupAndCompileMap.containsKey(groupId)) {
|
||||
groupAndCompileMap.get(groupId).addAll(compileIdList);
|
||||
} else {
|
||||
groupAndCompileMap.put(groupId, compileIdList);
|
||||
}
|
||||
|
||||
Map<Long, Set<String>> groupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
if (groupAndRegionMap.containsKey(groupId)) {
|
||||
groupAndRegionMap.get(groupId).addAll(groupRegionIdMap.get(groupId));
|
||||
} else {
|
||||
groupAndRegionMap.put(groupId, groupRegionIdMap.get(groupId));
|
||||
}
|
||||
Map<Long, Set<String>> groupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
if (groupAndRegionMap.containsKey(groupId)) {
|
||||
groupAndRegionMap.get(groupId).addAll(groupRegionIdMap.get(groupId));
|
||||
} else {
|
||||
groupAndRegionMap.put(groupId, groupRegionIdMap.get(groupId));
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
MaatRelation maatRelation = new MaatRelation();
|
||||
|
||||
Map<Long, Set<Long>> compileAndGroupMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
||||
for (Long compileId : compileIdList) {
|
||||
if (compileAndGroupMap.containsKey(compileId)) {
|
||||
compileAndGroupMap.get(compileId).add(groupId);
|
||||
} else {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(groupId);
|
||||
compileAndGroupMap.put(compileId, set);
|
||||
Set<String> regionIdSet = groupRegionIdMap.get(groupId);
|
||||
if (regionIdSet != null && regionIdSet.size() > 0) {// 防止出现错误数据,redis里面有域配置但是找不多对应的编译配置,分组配置,或者有分组配置但是找不到域或编译,或者有编译找不到分组和域
|
||||
MaatRelation maatRelation = new MaatRelation();
|
||||
Map<Long, Set<Long>> compileAndGroupMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
||||
for (Long compileId : compileIdList) {
|
||||
if (compileAndGroupMap.containsKey(compileId)) {
|
||||
compileAndGroupMap.get(compileId).add(groupId);
|
||||
} else {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(groupId);
|
||||
compileAndGroupMap.put(compileId, set);
|
||||
}
|
||||
}
|
||||
maatRelation.setCompileAndGroupMap(compileAndGroupMap);
|
||||
Map<Long, Set<Long>> groupAndCompileMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
groupAndCompileMap.put(groupId, compileIdList);
|
||||
maatRelation.setGroupAndCompileMap(groupAndCompileMap);
|
||||
Map<Long, Set<String>> groupAndRegionMap = new ConcurrentHashMap<Long, Set<String>>();
|
||||
groupAndRegionMap.put(groupId, groupRegionIdMap.get(groupId));
|
||||
maatRelation.setGroupAndRegionMap(groupAndRegionMap);
|
||||
idRelationMap.put(redisDBIndex, maatRelation);
|
||||
}
|
||||
maatRelation.setCompileAndGroupMap(compileAndGroupMap);
|
||||
|
||||
Map<Long, Set<Long>> groupAndCompileMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
groupAndCompileMap.put(groupId, compileIdList);
|
||||
maatRelation.setGroupAndCompileMap(groupAndCompileMap);
|
||||
|
||||
Map<Long, Set<String>> groupAndRegionMap = new ConcurrentHashMap<Long, Set<String>>();
|
||||
groupAndRegionMap.put(groupId, groupRegionIdMap.get(groupId));
|
||||
maatRelation.setGroupAndRegionMap(groupAndRegionMap);
|
||||
idRelationMap.put(redisDBIndex, maatRelation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,7 +170,7 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
} else {
|
||||
logger.error("redis" + redisDBIndex + "号库中没有id对应关系(没有配置),请检查redisDBIndex是否正确");
|
||||
}
|
||||
syso(maatRelation);
|
||||
// syso(maatRelation);
|
||||
|
||||
}
|
||||
|
||||
@@ -232,7 +238,7 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
addKey(maatRelation, compileAndGroupRelations);
|
||||
idRelationMap.put(redisDBIndex, maatRelation);
|
||||
}
|
||||
syso(maatRelation);
|
||||
// syso(maatRelation);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nis.web.service.restful.ConfigRedisServiceimpl;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>Title: ServiceAndRDBIndexReal</p>
|
||||
|
||||
@@ -11,8 +11,6 @@ import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -31,6 +29,7 @@ import com.nis.restful.RestBusinessCode;
|
||||
import com.nis.restful.RestServiceException;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.OracleErrorCodeUtil;
|
||||
import com.nis.util.ServiceAndRDBIndexReal;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.web.controller.BaseRestController;
|
||||
@@ -44,6 +43,8 @@ import com.wordnik.swagger.annotations.Api;
|
||||
import com.wordnik.swagger.annotations.ApiOperation;
|
||||
import com.wordnik.swagger.annotations.ApiParam;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
/**
|
||||
* @ClassName: ConfigSourcesController
|
||||
* @Description: 配置存储服务
|
||||
@@ -65,10 +66,10 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
@Autowired
|
||||
ConfigRedisService configRedisService;
|
||||
|
||||
@RequestMapping(value = "/cfg/v1/save", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/cfg/v1/saveUnMaat", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller")
|
||||
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
||||
public String testRedis(Integer type) {
|
||||
public String saveUnMaat(Integer type) {
|
||||
try {
|
||||
List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
|
||||
if (type == 1) {
|
||||
@@ -162,13 +163,14 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
||||
public String saveMaat(Integer service) {
|
||||
try {
|
||||
List<MaatConfig> listMap = new ArrayList<MaatConfig>();
|
||||
listMap.add(getMaatConfig(service));
|
||||
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
configMap.put(1, listMap);
|
||||
listMap = new ArrayList<MaatConfig>();
|
||||
listMap.add(getMaatConfig(service));
|
||||
configMap.put(2, listMap);
|
||||
List<Integer> redisDBByService = ServiceAndRDBIndexReal.getRedisDBByService(service);
|
||||
MaatConfig maatConfig = getMaatConfig(service);
|
||||
for (Integer db : redisDBByService) {
|
||||
List<MaatConfig> listMap = new ArrayList<MaatConfig>();
|
||||
listMap.add(maatConfig);
|
||||
configMap.put(db, listMap);
|
||||
}
|
||||
if (configRedisService.saveMaatConfig(configMap)) {
|
||||
configRedisService.addMaatRelation(configMap);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user