1:解决并发量大时无法获取redis连接的问题
2:解决加载id映射关系时遇见无法找到id关系的数据报错的问题
This commit is contained in:
@@ -36,10 +36,13 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
|||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent event) {
|
public void contextInitialized(ServletContextEvent event) {
|
||||||
try {
|
try {
|
||||||
|
long begin = System.currentTimeMillis();
|
||||||
for (int i = 0; i < Configurations.getIntProperty("maxRedisDBIndex", 6); i++) {
|
for (int i = 0; i < Configurations.getIntProperty("maxRedisDBIndex", 6); i++) {
|
||||||
RedisTemplate<String, String> redisTemplate = SpringContextHolder.getBean("redisTemplate" + i);
|
RedisTemplate<String, String> redisTemplate = SpringContextHolder.getBean("redisTemplate" + i);
|
||||||
getAllId(redisTemplate, i);
|
getAllId(redisTemplate, i);
|
||||||
}
|
}
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
logger.info("从redis读取数据需要" + ((end - begin) / 1000) + "秒");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -97,57 +100,60 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
|||||||
|
|
||||||
for (Long groupId : groupCompileIdMap.keySet()) {
|
for (Long groupId : groupCompileIdMap.keySet()) {
|
||||||
if (idRelationMap.containsKey(redisDBIndex)) {
|
if (idRelationMap.containsKey(redisDBIndex)) {
|
||||||
MaatRelation maatRelation = idRelationMap.get(redisDBIndex);
|
Set<String> regionIdSet = groupRegionIdMap.get(groupId);
|
||||||
|
if (regionIdSet != null && regionIdSet.size() > 0) {// 防止出现错误数据,redis里面有域配置但是找不多对应的编译配置,分组配置,或者有分组配置但是找不到域或编译,或者有编译找不到分组和域
|
||||||
Map<Long, Set<Long>> compileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
MaatRelation maatRelation = idRelationMap.get(redisDBIndex);
|
||||||
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
Map<Long, Set<Long>> compileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
||||||
for (Long compileId : compileIdList) {
|
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
||||||
if (compileAndGroupMap.containsKey(compileId)) {
|
for (Long compileId : compileIdList) {
|
||||||
compileAndGroupMap.get(compileId).add(groupId);
|
if (compileAndGroupMap.containsKey(compileId)) {
|
||||||
} else {
|
compileAndGroupMap.get(compileId).add(groupId);
|
||||||
Set<Long> set = new HashSet<Long>();
|
} else {
|
||||||
set.add(groupId);
|
Set<Long> set = new HashSet<Long>();
|
||||||
compileAndGroupMap.put(compileId, set);
|
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();
|
Map<Long, Set<String>> groupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||||
if (groupAndRegionMap.containsKey(groupId)) {
|
if (groupAndRegionMap.containsKey(groupId)) {
|
||||||
groupAndRegionMap.get(groupId).addAll(groupRegionIdMap.get(groupId));
|
groupAndRegionMap.get(groupId).addAll(groupRegionIdMap.get(groupId));
|
||||||
} else {
|
} else {
|
||||||
groupAndRegionMap.put(groupId, groupRegionIdMap.get(groupId));
|
groupAndRegionMap.put(groupId, groupRegionIdMap.get(groupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
MaatRelation maatRelation = new MaatRelation();
|
Set<String> regionIdSet = groupRegionIdMap.get(groupId);
|
||||||
|
if (regionIdSet != null && regionIdSet.size() > 0) {// 防止出现错误数据,redis里面有域配置但是找不多对应的编译配置,分组配置,或者有分组配置但是找不到域或编译,或者有编译找不到分组和域
|
||||||
Map<Long, Set<Long>> compileAndGroupMap = new ConcurrentHashMap<Long, Set<Long>>();
|
MaatRelation maatRelation = new MaatRelation();
|
||||||
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
Map<Long, Set<Long>> compileAndGroupMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||||
for (Long compileId : compileIdList) {
|
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
||||||
if (compileAndGroupMap.containsKey(compileId)) {
|
for (Long compileId : compileIdList) {
|
||||||
compileAndGroupMap.get(compileId).add(groupId);
|
if (compileAndGroupMap.containsKey(compileId)) {
|
||||||
} else {
|
compileAndGroupMap.get(compileId).add(groupId);
|
||||||
Set<Long> set = new HashSet<Long>();
|
} else {
|
||||||
set.add(groupId);
|
Set<Long> set = new HashSet<Long>();
|
||||||
compileAndGroupMap.put(compileId, set);
|
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 {
|
} else {
|
||||||
logger.error("redis" + redisDBIndex + "号库中没有id对应关系(没有配置),请检查redisDBIndex是否正确");
|
logger.error("redis" + redisDBIndex + "号库中没有id对应关系(没有配置),请检查redisDBIndex是否正确");
|
||||||
}
|
}
|
||||||
syso(maatRelation);
|
// syso(maatRelation);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +238,7 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
|||||||
addKey(maatRelation, compileAndGroupRelations);
|
addKey(maatRelation, compileAndGroupRelations);
|
||||||
idRelationMap.put(redisDBIndex, maatRelation);
|
idRelationMap.put(redisDBIndex, maatRelation);
|
||||||
}
|
}
|
||||||
syso(maatRelation);
|
// syso(maatRelation);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import java.util.Map;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.nis.web.service.restful.ConfigRedisServiceimpl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* <p>Title: ServiceAndRDBIndexReal</p>
|
* <p>Title: ServiceAndRDBIndexReal</p>
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ import java.util.Map;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -31,6 +29,7 @@ import com.nis.restful.RestBusinessCode;
|
|||||||
import com.nis.restful.RestServiceException;
|
import com.nis.restful.RestServiceException;
|
||||||
import com.nis.util.Constants;
|
import com.nis.util.Constants;
|
||||||
import com.nis.util.OracleErrorCodeUtil;
|
import com.nis.util.OracleErrorCodeUtil;
|
||||||
|
import com.nis.util.ServiceAndRDBIndexReal;
|
||||||
import com.nis.util.StringUtil;
|
import com.nis.util.StringUtil;
|
||||||
import com.nis.util.StringUtils;
|
import com.nis.util.StringUtils;
|
||||||
import com.nis.web.controller.BaseRestController;
|
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.ApiOperation;
|
||||||
import com.wordnik.swagger.annotations.ApiParam;
|
import com.wordnik.swagger.annotations.ApiParam;
|
||||||
|
|
||||||
|
import net.sf.json.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName: ConfigSourcesController
|
* @ClassName: ConfigSourcesController
|
||||||
* @Description: 配置存储服务
|
* @Description: 配置存储服务
|
||||||
@@ -65,10 +66,10 @@ public class ConfigSourcesController extends BaseRestController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
ConfigRedisService configRedisService;
|
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")
|
@ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller")
|
||||||
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
||||||
public String testRedis(Integer type) {
|
public String saveUnMaat(Integer type) {
|
||||||
try {
|
try {
|
||||||
List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
|
List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
|
||||||
if (type == 1) {
|
if (type == 1) {
|
||||||
@@ -162,13 +163,14 @@ public class ConfigSourcesController extends BaseRestController {
|
|||||||
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
||||||
public String saveMaat(Integer service) {
|
public String saveMaat(Integer service) {
|
||||||
try {
|
try {
|
||||||
List<MaatConfig> listMap = new ArrayList<MaatConfig>();
|
|
||||||
listMap.add(getMaatConfig(service));
|
|
||||||
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
|
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
|
||||||
configMap.put(1, listMap);
|
List<Integer> redisDBByService = ServiceAndRDBIndexReal.getRedisDBByService(service);
|
||||||
listMap = new ArrayList<MaatConfig>();
|
MaatConfig maatConfig = getMaatConfig(service);
|
||||||
listMap.add(getMaatConfig(service));
|
for (Integer db : redisDBByService) {
|
||||||
configMap.put(2, listMap);
|
List<MaatConfig> listMap = new ArrayList<MaatConfig>();
|
||||||
|
listMap.add(maatConfig);
|
||||||
|
configMap.put(db, listMap);
|
||||||
|
}
|
||||||
if (configRedisService.saveMaatConfig(configMap)) {
|
if (configRedisService.saveMaatConfig(configMap)) {
|
||||||
configRedisService.addMaatRelation(configMap);
|
configRedisService.addMaatRelation(configMap);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
<property name="maxTotal" value="${redis.maxTotal}" />
|
<property name="maxTotal" value="${redis.maxTotal}" />
|
||||||
<property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
|
<property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
|
||||||
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
|
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
|
||||||
|
<property name="testOnReturn" value="${redis.testOnReturn}" />
|
||||||
</bean>
|
</bean>
|
||||||
<!-- 默认使用数据库0,设置connectionFactory为非单例模式,方便选择redis数据库 -->
|
<!-- 默认使用数据库0,设置connectionFactory为非单例模式,方便选择redis数据库 -->
|
||||||
<bean id="connectionFactory0"
|
<bean id="connectionFactory0"
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ jdbc.test.password=OrTu/cLwlduYPW/tmxqNgQ==
|
|||||||
redis.host=10.0.6.249
|
redis.host=10.0.6.249
|
||||||
redis.port=6379
|
redis.port=6379
|
||||||
redis.pass=
|
redis.pass=
|
||||||
redis.maxIdle=200
|
redis.maxIdle=5
|
||||||
redis.maxTotal=250
|
redis.maxTotal=250
|
||||||
redis.maxWaitMillis=1000
|
redis.maxWaitMillis=100000
|
||||||
redis.testOnBorrow=true
|
redis.testOnBorrow=true
|
||||||
|
redis.testOnReturn=true
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ unMaatService=3:32;4:96;25:32;28:32;29:32;261:16;262:16;263:16;264:16;265:16;266
|
|||||||
|
|
||||||
##各业务类型对应的redisdb,业务类型:redisdb,多个业务以“;”分隔,多个db以“,”数量不能超过6个
|
##各业务类型对应的redisdb,业务类型:redisdb,多个业务以“;”分隔,多个db以“,”数量不能超过6个
|
||||||
#serviceDBIndex=3:2,3;1:2;80:2;81:2;82:2;83:2;84:2;85:2;144:2;145:2;146:2;147:2;148:2;149:2;96:3;97:3;98:3;99:3;160:3,4;161:3;162:3;163:3;100:3;101:3;164:3;165:3
|
#serviceDBIndex=3:2,3;1:2;80:2;81:2;82:2;83:2;84:2;85:2;144:2;145:2;146:2;147:2;148:2;149:2;96:3;97:3;98:3;99:3;160:3,4;161:3;162:3;163:3;100:3;101:3;164:3;165:3
|
||||||
serviceDBIndex=1:2,3,4;2:2,3,4;16:2;17:2;18:2;19:2;20:2;21:2;22:2;23:2;24:2;26:2;27:2;30:2;31:2;128:2;129:2;130:2;131:2;132:2;133:2;134:2;135:2;136:2;137:2;138:2;139:2;140:2;141:2;256:2;257:2;258:2;259:2;260:2;384:2;385:2;386:2;387:2;388:2;512:2;513:2;528:2;529:2;544:2;545:2;560:2;561:2;3:5;4:5;25:5;28:5;29:5;261:5;262:5;263:5;264:5;265:5;266:5;389:5;390:5;391:5;392:5;393:5;394:5;
|
serviceDBIndex=1:2,3,4;2:2,3,4;16:3,4,5;17:2;18:2;19:2;20:2;21:2;22:2;23:2;24:2;26:2;27:2;30:2;31:2;128:2;129:2;130:2;131:2;132:2;133:2;134:2;135:2;136:2;137:2;138:2;139:2;140:2;141:2;256:2;257:2;258:2;259:2;260:2;384:2;385:2;386:2;387:2;388:2;512:2;513:2;528:2;529:2;544:2;545:2;560:2;561:2;3:5;4:5;25:5;28:5;29:5;261:5;262:5;263:5;264:5;265:5;266:5;389:5;390:5;391:5;392:5;393:5;394:5;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user