1:修改配置下发及停启用接口的逻辑
2:完成公共组域配置新增和修改功能
This commit is contained in:
@@ -179,7 +179,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
/**
|
||||
* 下发配置时,需要记录编译,组,域等配置id的对应关系,以便于在取消配置时可以根据配置id查找对应的编译,分组,域的关系
|
||||
*/
|
||||
private void addMaatRelation(Map<Integer, List<MaatConfig>> configMap, Transaction transaction) {
|
||||
private void addMaatRelation(Map<Integer, List<MaatConfig>> configMap, Transaction transaction,
|
||||
List<Long> commonGroupIdList) {
|
||||
if (configMap != null && configMap.size() > 0) {
|
||||
int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
|
||||
transaction.select(idRelaRedisDBIndex);
|
||||
@@ -221,7 +222,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
/**
|
||||
* 添加组和域的关联关系信息
|
||||
*/
|
||||
addGroupRegionReal(maatConfig, transaction, redisDBSetStr, idRelaRedisDBIndex);
|
||||
addGroupRegionReal(maatConfig, transaction, redisDBSetStr, idRelaRedisDBIndex,
|
||||
commonGroupIdList);
|
||||
}
|
||||
for (String compile : compileAndGroupMap.keySet()) {
|
||||
List<String> list = compileAndGroupMap.get(compile);
|
||||
@@ -385,9 +387,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
* @param regionMapList
|
||||
* @param compileAndGroupRelations
|
||||
*/
|
||||
private Map<String, List<String>> addGroupAndRegionRelations(MaatXmlConfig maatXmlConfig, int service, int type,
|
||||
List<Map<String, String>> regionMapList, Map<String, List<String>> groupAndRegionMap,
|
||||
String redisDBSetStr) {
|
||||
private Map<String, Set<String>> addGroupAndRegionRelations(MaatXmlConfig maatXmlConfig, int service, int type,
|
||||
List<Map<String, String>> regionMapList, Map<String, Set<String>> groupAndRegionMap, String redisDBSetStr,
|
||||
List<Long> commonGroupIdList) {
|
||||
if (regionMapList != null && regionMapList.size() > 0) {
|
||||
for (Map<String, String> map : regionMapList) {
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
@@ -424,14 +426,22 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
break;
|
||||
}
|
||||
}
|
||||
String groupIdStr = "GROUPREGION:" + map.get("group_id");// groupregion里面value是region的信息,key是group的信息
|
||||
// commonGroupIdList
|
||||
Long groupId = Long.parseLong(map.get("group_id"));
|
||||
|
||||
String groupIdStr = "GROUPREGION:" + groupId;// groupregion里面value是region的信息,key是group的信息
|
||||
if (commonGroupIdList.contains(groupId)) {
|
||||
groupIdStr = "COMMONGROUPREGION:" + groupId;
|
||||
}
|
||||
|
||||
if (groupAndRegionMap.containsKey(groupIdStr.toUpperCase())) {
|
||||
groupAndRegionMap.get(groupIdStr.toUpperCase()).add(maatKey.toUpperCase() + redisDBSetStr);
|
||||
} else {
|
||||
List<String> list = new ArrayList<String>();
|
||||
Set<String> list = new HashSet<String>();
|
||||
list.add(maatKey.toUpperCase() + redisDBSetStr);
|
||||
groupAndRegionMap.put(groupIdStr.toUpperCase(), list);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return groupAndRegionMap;
|
||||
@@ -471,10 +481,19 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
setConfig(maatConfig, maatXmlConfig, maatVersion, service, transaction,
|
||||
redisDBIndex, commonGroupIdList);
|
||||
}
|
||||
if (commonGroupIdList != null && commonGroupIdList.size() > 0) {
|
||||
for (String db : Constants.COMMONGROUPDBARR) {
|
||||
transaction.select(Integer.parseInt(db));
|
||||
transaction.incrBy("MAAT_VERSION", 1l);
|
||||
logger.info("向{}号redis数据库更新了MAAT_VERSION", Integer.parseInt(db));
|
||||
}
|
||||
} else {
|
||||
transaction.select(redisDBIndex);
|
||||
transaction.incrBy("MAAT_VERSION", 1l);
|
||||
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
|
||||
Integer.valueOf(maatVersionStr) + 1);
|
||||
}
|
||||
|
||||
transaction.incrBy("MAAT_VERSION", 1l);
|
||||
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
|
||||
Integer.valueOf(maatVersionStr) + 1);
|
||||
count++;
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
@@ -488,7 +507,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
if (count == configMap.size()) {
|
||||
addMaatRelation(configMap, transaction);
|
||||
addMaatRelation(configMap, transaction, commonGroupIdList);
|
||||
addStatisticsReal(configMap, transaction);
|
||||
transaction.exec();
|
||||
return true;
|
||||
@@ -1082,6 +1101,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
private void removeConfig(Long id, MaatXmlConfig maatXmlConfig, Double maatVersion, int service,
|
||||
Transaction transaction, int redisDBIndex, int idRelaRedisDBIndex, boolean isStart,
|
||||
List<Long> keepGroupId) {
|
||||
|
||||
Map<String, Boolean> groupIsCommonMap = new HashMap<>();
|
||||
|
||||
if (maatXmlConfig != null) {
|
||||
Map<String, String> keyMap = new HashMap<>();
|
||||
// 删除(重命名)编译配置
|
||||
@@ -1110,9 +1132,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
} else {
|
||||
groupCompileAndDBStrs = keyMap.get(groupId);
|
||||
}
|
||||
|
||||
String groupIdReal = groupId.replace("GROUPCOMPILE:", "");
|
||||
|
||||
String[] compileGroupArr = org.apache.commons.lang.StringUtils
|
||||
.split(groupCompileAndDBStrs, ";");// 获取组对应的编译id,示例:
|
||||
// ;COMPILEGROUP:24070-2, 5
|
||||
@@ -1120,49 +1140,68 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
if (groupAndCompileStr != null && !groupAndCompileStr.trim().equals("")) {
|
||||
String compileId = getRegionInfo(groupAndCompileStr);// COMPILEGROUP:24070
|
||||
if (compileId != null && !compileId.trim().equals("")) {
|
||||
|
||||
if (isStart || (keepGroupId != null && keepGroupId.size() > 0
|
||||
&& !keepGroupId.contains(Long.parseLong(groupIdReal)))) {// 如果是修改为生效则置为生效,如果是失效如果包含保留的group,则不将域置为失效,否则将域置为失效,否
|
||||
// if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效
|
||||
// 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效
|
||||
if (compileId.equals(compileStr)) {//
|
||||
String groupRegionKey = groupId.replace("GROUPCOMPILE",
|
||||
"GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
String regionStrs = null;
|
||||
if (!keyMap.containsKey(groupRegionKey)) {
|
||||
regionStrs = JedisUtils.get(groupRegionKey,
|
||||
idRelaRedisDBIndex);
|
||||
keyMap.put(groupRegionKey, regionStrs);
|
||||
} else {
|
||||
regionStrs = keyMap.get(groupRegionKey);
|
||||
}
|
||||
if (regionStrs != null && !regionStrs.trim().equals("")) {
|
||||
String[] regionStrArr = regionStrs.split(";");
|
||||
for (String str : regionStrArr) {
|
||||
if (str != null && !str.trim().equals("")) {
|
||||
boolean isCommonGroup = false;
|
||||
if (isStart) {
|
||||
String commonGroupRegionKey = groupId
|
||||
.replace("GROUPCOMPILE", "COMMONGROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
if (!groupIsCommonMap.containsKey(commonGroupRegionKey)) {
|
||||
boolean exist = JedisUtils.exists(commonGroupRegionKey,
|
||||
idRelaRedisDBIndex);
|
||||
groupIsCommonMap.put(commonGroupRegionKey, exist);
|
||||
if (exist) {
|
||||
isCommonGroup = true;
|
||||
}
|
||||
|
||||
String regionStr = getRegionInfo(str);
|
||||
if (regionStr != null
|
||||
&& !regionStr.trim().equals("")) {
|
||||
String[] regionKeyArr = regionStr.split(";");
|
||||
if (regionKeyArr != null
|
||||
&& regionKeyArr.length > 0) {
|
||||
// 根据分组与域关联关系找到对应域配置然后删除(重命名)
|
||||
removeRegionConfig(maatXmlConfig,
|
||||
regionKeyArr, maatVersion, service,
|
||||
transaction, redisDBIndex, isStart);
|
||||
} else {
|
||||
isCommonGroup = groupIsCommonMap
|
||||
.get(commonGroupRegionKey);
|
||||
}
|
||||
}
|
||||
if (!isCommonGroup) {// 如果是公共组则不进行操作,因为公共组本来就是有效的
|
||||
String regionStrs = null;
|
||||
if (!keyMap.containsKey(groupRegionKey)) {
|
||||
regionStrs = JedisUtils.get(groupRegionKey,
|
||||
idRelaRedisDBIndex);
|
||||
keyMap.put(groupRegionKey, regionStrs);
|
||||
} else {
|
||||
regionStrs = keyMap.get(groupRegionKey);
|
||||
}
|
||||
if (regionStrs != null && !regionStrs.trim().equals("")) {
|
||||
String[] regionStrArr = regionStrs.split(";");
|
||||
for (String str : regionStrArr) {
|
||||
if (str != null && !str.trim().equals("")) {
|
||||
|
||||
String regionStr = getRegionInfo(str);
|
||||
if (regionStr != null
|
||||
&& !regionStr.trim().equals("")) {
|
||||
String[] regionKeyArr = regionStr
|
||||
.split(";");
|
||||
if (regionKeyArr != null
|
||||
&& regionKeyArr.length > 0) {
|
||||
// 根据分组与域关联关系找到对应域配置然后删除(重命名)
|
||||
removeRegionConfig(maatXmlConfig,
|
||||
regionKeyArr, maatVersion,
|
||||
service, transaction,
|
||||
redisDBIndex, isStart);
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException("从"
|
||||
+ idRelaRedisDBIndex
|
||||
+ "号redis库中无法获取MAAT配置分组与域的关联关系,key为"
|
||||
+ groupRegionKey,
|
||||
RestBusinessCode.KeyNotExistsInRedis
|
||||
.getValue());
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException("从"
|
||||
+ idRelaRedisDBIndex
|
||||
+ "号redis库中无法获取MAAT配置分组与域的关联关系,key为"
|
||||
+ groupRegionKey,
|
||||
RestBusinessCode.KeyNotExistsInRedis
|
||||
.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
// 根据分组与编译关联关系找到对应分组配置然后删除(重命名)
|
||||
@@ -1426,16 +1465,38 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
.split(compileGroupStr, ";");
|
||||
// 被分组复用的业务,不能将域置为失效,其分组关系也不置为失效
|
||||
|
||||
// if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效
|
||||
|
||||
if (compileGroupStrSplit[0].toUpperCase()
|
||||
.equals(compileStr.toUpperCase())) {
|
||||
String groupRegion = groupCompile.replace("GROUPCOMPILE",
|
||||
"GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
// String commonGroupRegion = groupCompile.replace("GROUPCOMPILE",
|
||||
// "COMMONGROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
|
||||
String groupRegionVal = JedisUtils.get(groupRegion,
|
||||
idRelaRedisDBIndex);
|
||||
|
||||
if (groupRegionVal == null
|
||||
|| groupRegionVal.trim().equals("")) {// 如果从普通的组中无法获,取则尝试下获取公共组
|
||||
|
||||
groupRegion = groupCompile.replace("GROUPCOMPILE",
|
||||
"COMMONGROUPREGION");
|
||||
|
||||
groupRegionVal = JedisUtils.get(groupRegion,
|
||||
idRelaRedisDBIndex);
|
||||
break;
|
||||
}
|
||||
if (groupRegionVal == null
|
||||
|| groupRegionVal.trim().equals("")) {// 如果普通的组和公共组都无法获取则给出错误提示
|
||||
throw new ServiceRuntimeException("从" + idRelaRedisDBIndex
|
||||
+ "号redis库中无法获取"
|
||||
+ groupCompile.replace("GROUPCOMPILE",
|
||||
"COMMONGROUPREGION")
|
||||
+ "和"
|
||||
+ groupCompile.replace("GROUPCOMPILE",
|
||||
"GROUPREGION")
|
||||
+ ",请检查groupid是否正确,或联系开发人员检查删除redis数据是否被人为删除了",
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
try {
|
||||
// 为了提高效率,不判断了,如果报错直接捕捉异常处理
|
||||
// 删除分组与域的关联关系
|
||||
@@ -1675,11 +1736,161 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
|
||||
private void addTmpReion(List<Map<String, String>> regionMapList, MaatXmlExpr maatXmlExpr, Transaction transaction,
|
||||
int type, int tmpStorageReuseRegionDB, int idRelaRedisDBIndex, List<MaatXmlExpr> expressionList,
|
||||
private void addReionToCommonGroup(List<Map<String, String>> regionMapList, MaatXmlExpr maatXmlExpr,
|
||||
Transaction transaction, int type, int idRelaRedisDBIndex, List<MaatXmlExpr> expressionList, boolean isAdd)
|
||||
throws Exception {
|
||||
Set<Long> groupIdSet = new HashSet<>();
|
||||
Map<Integer, Double> dbVersionMap = new HashMap<>();// 记录所有redisdb的maatversion,避免每次查询影响性能
|
||||
if (regionMapList != null && regionMapList.size() > 0) {
|
||||
String[] keySplit = maatXmlExpr.getKeyExpression().split(";");
|
||||
|
||||
for (Map<String, String> map : regionMapList) {
|
||||
String maatKey = null;
|
||||
StringBuffer keyBF = new StringBuffer();
|
||||
for (String keyStr : keySplit) {
|
||||
if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[")) {
|
||||
keyStr = keyStr.trim().replace("[", "").replace("]", "");
|
||||
String keyVal = map.get(keyStr);
|
||||
if (keyVal != null && !keyVal.equals("")) {
|
||||
keyBF.append(keyVal);
|
||||
} else {
|
||||
throw new ServiceRuntimeException("未从map中获取到" + keyStr + "的值,请检查数据或配置文件是否正确",
|
||||
RestBusinessCode.NotFoundValueByKey.getValue());
|
||||
}
|
||||
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) {
|
||||
keyStr = keyStr.trim().replace("{", "").replace("}", "");
|
||||
if (keyStr.toLowerCase().contains("table_name")) {
|
||||
String argTableName = map.get("table_name");
|
||||
if (argTableName == null) {
|
||||
throw new ServiceRuntimeException("添加分组复用域配置时,必须要传入表名,请检查参数,配置类型:" + type + ",对应的真实表名",
|
||||
RestBusinessCode.NotFoundTableName.getValue());
|
||||
} else {
|
||||
keyBF.append(argTableName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
}
|
||||
String groupId = null;
|
||||
StringBuffer valBF = new StringBuffer();
|
||||
String[] valSplit = maatXmlExpr.getValueExpression().split(";");
|
||||
for (String valStr : valSplit) {
|
||||
if (!StringUtils.isEmpty(valStr) && valStr.trim().startsWith("[")) {
|
||||
valStr = valStr.trim().replace("[", "").replace("]", "");
|
||||
if (valStr.toLowerCase().equals("op_time") && type == 12) {
|
||||
String user_region = map.get("user_region");
|
||||
valBF.append(user_region + "\t");
|
||||
}
|
||||
String val = map.get(valStr);
|
||||
if (val != null) {
|
||||
valBF.append(val);
|
||||
if (valStr.equals("group_id")) {
|
||||
groupId = val;
|
||||
}
|
||||
} else {
|
||||
// 所有在maat.xml中配置的属性都不可以为空
|
||||
throw new ServiceRuntimeException("未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据或配置文件是否正确",
|
||||
RestBusinessCode.NotFoundValueByKey.getValue());
|
||||
}
|
||||
} else if (valStr.equals(" ")) {
|
||||
valBF.append(" ");
|
||||
} else if (valStr.equals("\\t")) {// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t
|
||||
valBF.append("\t");
|
||||
} else if (valStr.equals("\\n")) {
|
||||
valBF.append("\n");
|
||||
} else {
|
||||
valBF.append(valStr.trim());
|
||||
}
|
||||
}
|
||||
|
||||
for (String db : Constants.COMMONGROUPDBARR) {
|
||||
// 将域配置下发到每个db中,并更新MAAT_UPDATE_STATUS等信息
|
||||
int everyDb = Integer.parseInt(db);
|
||||
transaction.select(everyDb);
|
||||
maatKey = keyBF.toString();
|
||||
transaction.set(maatKey.toUpperCase(), valBF.toString());
|
||||
logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", everyDb, maatKey.toUpperCase(),
|
||||
valBF.toString());
|
||||
|
||||
Double maatVersion = null;
|
||||
if (!dbVersionMap.containsKey(everyDb)) {
|
||||
String maatVersionStr = JedisUtils.get("MAAT_VERSION", everyDb);
|
||||
if (maatVersionStr == null) {
|
||||
maatVersionStr = "0";
|
||||
}
|
||||
maatVersion = Double.valueOf(maatVersionStr) + 1D;
|
||||
dbVersionMap.put(everyDb, maatVersion);
|
||||
} else {
|
||||
maatVersion = dbVersionMap.get(everyDb);
|
||||
}
|
||||
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, everyDb, false);
|
||||
}
|
||||
groupIdSet.add(Long.parseLong(groupId));
|
||||
String groupRegionStr = "COMMONGROUPREGION:" + groupId;
|
||||
transaction.select(idRelaRedisDBIndex);
|
||||
if (!isAdd) {
|
||||
transaction.del(groupRegionStr);
|
||||
}
|
||||
// 更新组与域的关系
|
||||
transaction.append(groupRegionStr, ";" + maatKey.toUpperCase() + "-" + Constants.COMMONGROUPDBARR[0]);// redisdb随便写一个即可,实际每个库都下发了
|
||||
|
||||
}
|
||||
if (!isAdd) {
|
||||
|
||||
Map<String, String> keyMap = new HashMap<>();// 记录15号库中的COMPILEGROUP,GROUPCOMPILE,避免每次去redis中查询,影响性能
|
||||
for (Long groupId : groupIdSet) {
|
||||
String groupRegionStr = "COMMONGROUPREGION:" + groupId;
|
||||
String regionVal = null;
|
||||
if (!keyMap.containsKey(groupRegionStr)) {
|
||||
regionVal = JedisUtils.get(groupRegionStr, idRelaRedisDBIndex);
|
||||
keyMap.put(groupRegionStr, regionVal);
|
||||
} else {
|
||||
regionVal = keyMap.get(groupRegionStr);
|
||||
}
|
||||
|
||||
String[] commonsplit = org.apache.commons.lang.StringUtils.split(regionVal, ";");
|
||||
for (String regionKey : commonsplit) {
|
||||
String maatKey = regionKey.substring(0, regionKey.indexOf("-"));
|
||||
for (String db : Constants.COMMONGROUPDBARR) {
|
||||
int everyDb = Integer.parseInt(db);
|
||||
transaction.select(everyDb);
|
||||
String obsoleteKey = maatKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
transaction.rename(maatKey, obsoleteKey);
|
||||
Double maatVersion = dbVersionMap.get(everyDb);
|
||||
updateMaatInfo(expressionList, obsoleteKey, transaction, maatVersion, everyDb, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for (String db : Constants.COMMONGROUPDBARR) {
|
||||
// int everyDb = Integer.parseInt(db);
|
||||
// transaction.select(everyDb);
|
||||
// for (String commonGroupKey : keyMap.keySet()) {
|
||||
// String[] commonsplit = org.apache.commons.lang.StringUtils.split(keyMap.get(commonGroupKey),
|
||||
// ";");
|
||||
// for (String regionKey : commonsplit) {
|
||||
// String maatKey = regionKey.substring(0, regionKey.indexOf("-"));
|
||||
// try {
|
||||
// transaction.del(maatKey);
|
||||
// } catch (Exception e) {
|
||||
// logger.error("公共组:{}中的域配置:{}在{}号db中找不到,请联系开发人员检查业务逻辑是否正确,失败原因:{}", commonGroupKey,
|
||||
// maatKey, everyDb, ExceptionUtil.getExceptionMsg(e));
|
||||
// }
|
||||
// Double maatVersion = dbVersionMap.get(everyDb);
|
||||
// updateMaatInfo(expressionList, maatKey, transaction, maatVersion, everyDb, false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addTmpReionold(List<Map<String, String>> regionMapList, MaatXmlExpr maatXmlExpr,
|
||||
Transaction transaction, int type, int idRelaRedisDBIndex, List<MaatXmlExpr> expressionList,
|
||||
Set<Integer> redisDB) throws Exception {
|
||||
Map<String, String> keyMap = new HashMap<>();
|
||||
Map<Integer, Double> dbVersionMap = new HashMap<>();
|
||||
Map<String, String> keyMap = new HashMap<>();// 记录15号库中的COMPILEGROUP,GROUPCOMPILE,避免每次去redis中查询,影响性能
|
||||
Map<Integer, Double> dbVersionMap = new HashMap<>();// 记录每个redisdb中的maat_version,避免每次去redis中查询,影响性能
|
||||
if (regionMapList != null && regionMapList.size() > 0) {
|
||||
String[] keySplit = maatXmlExpr.getKeyExpression().split(";");
|
||||
for (Map<String, String> map : regionMapList) {
|
||||
@@ -1742,11 +1953,13 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
|
||||
transaction.select(tmpStorageReuseRegionDB);
|
||||
maatKey = keyBF.toString();
|
||||
transaction.set(maatKey.toUpperCase(), valBF.toString());
|
||||
logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", tmpStorageReuseRegionDB, maatKey.toUpperCase(),
|
||||
valBF.toString());
|
||||
//
|
||||
//
|
||||
// transaction.select(tmpStorageReuseRegionDB);
|
||||
// maatKey = keyBF.toString();
|
||||
// transaction.set(maatKey.toUpperCase(), valBF.toString());
|
||||
// logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", tmpStorageReuseRegionDB, maatKey.toUpperCase(),
|
||||
// valBF.toString());
|
||||
|
||||
String groupIdStr = "GROUPCOMPILE:" + groupId;
|
||||
String groupCompileVal = null;
|
||||
@@ -1806,19 +2019,13 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单独添加域时,先判断下当前组是否被使用了(是否有对应的编译),如果被使用了则分发到所有编译在的redisdb里,
|
||||
* 如果没有被使用则先存储在临时库里面,后面下发编译时使用到了该分组再把该分组下的所有域复制到编译下面
|
||||
*/
|
||||
@Override
|
||||
public boolean updateGroupRegion(List<MaatConfig> configList) {
|
||||
public boolean updateGroupRegion(List<MaatConfig> configList, boolean isAdd) {
|
||||
Jedis resource = JedisUtils.getResource(0);
|
||||
Transaction transaction = resource.multi();
|
||||
try {
|
||||
if (configList != null && configList.size() > 0) {
|
||||
int tmpStorageReuseRegionDB = Configurations.getIntProperty("tmpStorageReuseRegionDB", 15);
|
||||
int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
|
||||
transaction.select(tmpStorageReuseRegionDB);
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(37);// maat类配置的表达式都一样,这里因为没有service所以就随便取了一个
|
||||
MaatXmlExpr maatXmlExpr12 = null;
|
||||
MaatXmlExpr maatXmlExpr13 = null;
|
||||
@@ -1836,19 +2043,19 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
}
|
||||
Set<Integer> redisDB = new HashSet<Integer>();
|
||||
|
||||
for (MaatConfig maatConfig : configList) {
|
||||
addTmpReion(maatConfig.getIpRegionMapList(), maatXmlExpr12, transaction, 12,
|
||||
tmpStorageReuseRegionDB, idRelaRedisDBIndex, expressionList, redisDB);
|
||||
addTmpReion(maatConfig.getNumRegionMapList(), maatXmlExpr13, transaction, 13,
|
||||
tmpStorageReuseRegionDB, idRelaRedisDBIndex, expressionList, redisDB);
|
||||
addTmpReion(maatConfig.getStrRegionMapList(), maatXmlExpr14, transaction, 14,
|
||||
tmpStorageReuseRegionDB, idRelaRedisDBIndex, expressionList, redisDB);
|
||||
addReionToCommonGroup(maatConfig.getIpRegionMapList(), maatXmlExpr12, transaction, 12,
|
||||
idRelaRedisDBIndex, expressionList, isAdd);
|
||||
addReionToCommonGroup(maatConfig.getNumRegionMapList(), maatXmlExpr13, transaction, 13,
|
||||
idRelaRedisDBIndex, expressionList, isAdd);
|
||||
addReionToCommonGroup(maatConfig.getStrRegionMapList(), maatXmlExpr14, transaction, 14,
|
||||
idRelaRedisDBIndex, expressionList, isAdd);
|
||||
}
|
||||
for (Integer redisDb : redisDB) {
|
||||
transaction.select(redisDb);
|
||||
for (String db : Constants.COMMONGROUPDBARR) {
|
||||
transaction.select(Integer.parseInt(db));
|
||||
transaction.incrBy("MAAT_VERSION", 1l);
|
||||
logger.info("向{}号redis数据库更新了MAAT_VERSION", redisDb);
|
||||
logger.info("向{}号redis数据库更新了MAAT_VERSION", Integer.parseInt(db));
|
||||
// logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDb, maatVersion);
|
||||
}
|
||||
|
||||
@@ -1885,23 +2092,27 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
* @param idRelaRedisDBIndex
|
||||
*/
|
||||
private void addGroupRegionReal(MaatConfig maatConfig, Transaction transaction, String redisDBSetStr,
|
||||
int idRelaRedisDBIndex) {
|
||||
Map<String, List<String>> map = new HashMap<String, List<String>>();
|
||||
int idRelaRedisDBIndex, List<Long> commonGroupIdList) {
|
||||
Map<String, Set<String>> map = new HashMap<String, Set<String>>();
|
||||
int service = maatConfig.getService();
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 12, maatConfig.getIpRegionMapList(), map, redisDBSetStr);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 13, maatConfig.getNumRegionMapList(), map, redisDBSetStr);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 14, maatConfig.getStrRegionMapList(), map, redisDBSetStr);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 15, maatConfig.getStrStrRegionMapList(), map, redisDBSetStr);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 12, maatConfig.getIpRegionMapList(), map, redisDBSetStr,
|
||||
commonGroupIdList);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 13, maatConfig.getNumRegionMapList(), map, redisDBSetStr,
|
||||
commonGroupIdList);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 14, maatConfig.getStrRegionMapList(), map, redisDBSetStr,
|
||||
commonGroupIdList);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 15, maatConfig.getStrStrRegionMapList(), map, redisDBSetStr,
|
||||
commonGroupIdList);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 16, maatConfig.getFileDigestRegionMapList(), map,
|
||||
redisDBSetStr);
|
||||
redisDBSetStr, commonGroupIdList);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 17, maatConfig.getFileLikeRegionMapList(), map,
|
||||
redisDBSetStr);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 18, maatConfig.getIpClientRangeMapList(), map,
|
||||
redisDBSetStr);
|
||||
redisDBSetStr, commonGroupIdList);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 18, maatConfig.getIpClientRangeMapList(), map, redisDBSetStr,
|
||||
commonGroupIdList);
|
||||
|
||||
for (String groupIdStr : map.keySet()) {
|
||||
List<String> list = map.get(groupIdStr);
|
||||
Set<String> list = map.get(groupIdStr);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (list != null && list.size() > 0) {
|
||||
for (String regionIdStr : list) {
|
||||
@@ -1931,6 +2142,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
// Boolean serviceIsReuse = ServiceAndRDBIndexReal.serviceIsReuse(service);
|
||||
int count = 0;// 计算下所有的域是不是都没有值,如果没有值则给出提示
|
||||
List<Map<String, String>> ipRegionMapList = maatConfig.getIpRegionMapList();
|
||||
|
||||
if (ipRegionMapList != null && ipRegionMapList.size() > 0) {
|
||||
count += ipRegionMapList.size();
|
||||
for (Map<String, String> map : ipRegionMapList) {
|
||||
@@ -2042,6 +2254,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (count == 0 && isReuseSaveRegion) {
|
||||
// throw new ServiceRuntimeException("添加分组复用域配置时,所有的域配置都为空,请检查配置参数是否正确",
|
||||
// RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||
|
||||
Reference in New Issue
Block a user