perf: reduce the number of test connections (#3343)

This commit is contained in:
LUA
2022-08-09 10:29:20 +08:00
committed by GitHub
parent 4865e3766d
commit 66f3db9fe0
2 changed files with 34 additions and 33 deletions

View File

@@ -34,6 +34,7 @@ import com.actiontech.dble.services.manager.response.ChangeItemType;
import com.actiontech.dble.services.manager.response.ChangeType;
import com.actiontech.dble.singleton.TraceManager;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -245,6 +246,7 @@ public class ConfigInitializer implements ProblemReporter {
// check whether dbInstance is connected
String dbGroupName;
PhysicalDbGroup dbGroup;
Set<String> dbGroupTested = Sets.newHashSet();
for (ChangeItem changeItem : changeItemList) {
ChangeType type = changeItem.getType();
@@ -255,18 +257,10 @@ public class ConfigInitializer implements ProblemReporter {
if (itemType == ChangeItemType.PHYSICAL_DB_GROUP) {
//test dbGroup
dbGroup = (PhysicalDbGroup) item;
dbGroupName = dbGroup.getGroupName();
// sharding group
List<Pair<String, String>> schemaList = checkDbGroupMaxConn(hostSchemaMap, dbGroup);
for (PhysicalDbInstance ds : dbGroup.getDbInstances(true)) {
//test dbInstance
boolean testResult = checkAndTestDbInstance(ds, dbGroupName, schemaList);
if (!testResult) {
isAllDbInstanceConnected = false;
errDbInstanceNames.add("dbInstance[" + dbGroupName + "." + ds.getName() + "]");
}
boolean isDbInstanceConnected = testDbGroup(dbGroup, hostSchemaMap, dbGroupTested, errDbInstanceNames);
if (!isDbInstanceConnected) {
isAllDbInstanceConnected = false;
}
} else if (itemType == ChangeItemType.PHYSICAL_DB_INSTANCE) {
PhysicalDbInstance ds = (PhysicalDbInstance) item;
@@ -282,17 +276,10 @@ public class ConfigInitializer implements ProblemReporter {
} else if (itemType == ChangeItemType.SHARDING_NODE) {
ShardingNode shardingNode = (ShardingNode) item;
dbGroup = shardingNode.getDbGroup();
dbGroupName = dbGroup.getGroupName();
// sharding group
List<Pair<String, String>> schemaList = checkDbGroupMaxConn(hostSchemaMap, dbGroup);
for (PhysicalDbInstance ds : dbGroup.getDbInstances(true)) {
//test dbInstance
boolean testResult = checkAndTestDbInstance(ds, dbGroupName, schemaList);
if (!testResult) {
isAllDbInstanceConnected = false;
errDbInstanceNames.add("dbInstance[" + dbGroupName + "." + ds.getName() + "]");
}
boolean isDbInstanceConnected = testDbGroup(dbGroup, hostSchemaMap, dbGroupTested, errDbInstanceNames);
if (!isDbInstanceConnected) {
isAllDbInstanceConnected = false;
}
}
break;
@@ -312,17 +299,10 @@ public class ConfigInitializer implements ProblemReporter {
} else if (itemType == ChangeItemType.SHARDING_NODE) {
ShardingNode shardingNode = (ShardingNode) item;
dbGroup = shardingNode.getDbGroup();
dbGroupName = dbGroup.getGroupName();
// sharding group
List<Pair<String, String>> schemaList = checkDbGroupMaxConn(hostSchemaMap, dbGroup);
for (PhysicalDbInstance ds : dbGroup.getDbInstances(true)) {
//test dbInstance
boolean testResult = checkAndTestDbInstance(ds, dbGroupName, schemaList);
if (!testResult) {
isAllDbInstanceConnected = false;
errDbInstanceNames.add("dbInstance[" + dbGroupName + "." + ds.getName() + "]");
}
boolean isDbInstanceConnected = testDbGroup(dbGroup, hostSchemaMap, dbGroupTested, errDbInstanceNames);
if (!isDbInstanceConnected) {
isAllDbInstanceConnected = false;
}
}
break;
@@ -401,6 +381,25 @@ public class ConfigInitializer implements ProblemReporter {
}
}
private boolean testDbGroup(PhysicalDbGroup dbGroup, Map<String, List<Pair<String, String>>> hostSchemaMap, Set<String> dbGroupTested, Set<String> errDbInstanceNames) {
String dbGroupName = dbGroup.getGroupName();
boolean isAllDbInstanceConnected = true;
if (dbGroupTested.add(dbGroupName)) {
// sharding group
List<Pair<String, String>> schemaList = checkDbGroupMaxConn(hostSchemaMap, dbGroup);
for (PhysicalDbInstance ds : dbGroup.getDbInstances(true)) {
//test dbInstance
boolean testResult = checkAndTestDbInstance(ds, dbGroupName, schemaList);
if (!testResult) {
isAllDbInstanceConnected = false;
errDbInstanceNames.add("dbInstance[" + dbGroupName + "." + ds.getName() + "]");
}
}
}
return isAllDbInstanceConnected;
}
private List<Pair<String, String>> checkDbInstanceMaxConn(Map<String, List<Pair<String, String>>> hostSchemaMap, PhysicalDbInstance ds) {
List<Pair<String, String>> schemaList = null;
if (hostSchemaMap.containsKey(ds.getDbGroupConfig().getName())) {

View File

@@ -523,9 +523,10 @@ public class ServerConfig {
PhysicalDbInstance physicalDbInstance = (PhysicalDbInstance) item;
//delete slave instance
PhysicalDbGroup physicalDbGroup = oldDbGroupMap.get(physicalDbInstance.getDbGroupConfig().getName());
PhysicalDbInstance oldDbInstance = removeDbInstance(physicalDbGroup, physicalDbInstance.getName());
PhysicalDbInstance oldDbInstance = physicalDbGroup.getAllDbInstanceMap().get(physicalDbInstance.getName());
oldDbInstance.stop("reload config, recycle old instance", ((loadAllMode & ManagerParseConfig.OPTF_MODE) != 0));
oldDbInstance = null;
removeDbInstance(physicalDbGroup, physicalDbInstance.getName());
} else if (itemType == ChangeItemType.SHARDING_NODE) {
ShardingNode shardingNode = (ShardingNode) item;
if (shardingNode.getDbGroup() != null) {
@@ -566,9 +567,10 @@ public class ServerConfig {
if (changeItem.isAffectHeartbeat() || changeItem.isAffectConnectionPool()) {
PhysicalDbInstance physicalDbInstance = (PhysicalDbInstance) item;
PhysicalDbGroup physicalDbGroup = oldDbGroupMap.get(physicalDbInstance.getDbGroupConfig().getName());
PhysicalDbInstance oldDbInstance = removeDbInstance(physicalDbGroup, physicalDbInstance.getName());
PhysicalDbInstance oldDbInstance = physicalDbGroup.getAllDbInstanceMap().get(physicalDbInstance.getName());
oldDbInstance.stop("reload config, recycle old instance", ((loadAllMode & ManagerParseConfig.OPTF_MODE) != 0));
oldDbInstance = null;
removeDbInstance(physicalDbGroup, physicalDbInstance.getName());
physicalDbInstance.init("reload config", true);
physicalDbGroup.setDbInstance(physicalDbInstance);
} else {