diff --git a/src/main/java/com/actiontech/dble/config/ConfigInitializer.java b/src/main/java/com/actiontech/dble/config/ConfigInitializer.java index c5540fbc4d..98c382ac54 100644 --- a/src/main/java/com/actiontech/dble/config/ConfigInitializer.java +++ b/src/main/java/com/actiontech/dble/config/ConfigInitializer.java @@ -200,12 +200,14 @@ public void testConnection() { // check whether dbInstance is connected String dbGroupName; PhysicalDbGroup dbGroup; + boolean skipTestConnectionOnUpdate = false; if (SystemConfig.getInstance().isSkipTestConOnUpdate()) { if (reloadContext != null && !reloadContext.getAffectDbInstanceList().isEmpty()) { boolean useSharding = reloadContext.getAffectDbInstanceList().stream().map(ele -> dbGroups.get(ele.getGroupName())).anyMatch((ele) -> ele != null && !ele.isShardingUseless()); - if (useSharding) { - //not support for sharding db group - reloadContext.getAffectDbInstanceList().clear(); + + //not support for sharding db group + if (!useSharding) { + skipTestConnectionOnUpdate = true; } } } @@ -221,14 +223,12 @@ public void testConnection() { } for (PhysicalDbInstance ds : dbGroup.getDbInstances(true)) { - if (SystemConfig.getInstance().isSkipTestConOnUpdate()) { - if (reloadContext != null && !reloadContext.getAffectDbInstanceList().isEmpty()) { - String finalDbGroupName = dbGroupName; - boolean find = reloadContext.getAffectDbInstanceList().stream().anyMatch((ele) -> ele.getGroupName().equals(finalDbGroupName) && ele.getInstanceName().equals(ds.getName())); - if (!find) { - //skip test connection on this dbInstance - continue; - } + if (skipTestConnectionOnUpdate) { + String finalDbGroupName = dbGroupName; + boolean find = reloadContext.getAffectDbInstanceList().stream().anyMatch((ele) -> ele.getGroupName().equals(finalDbGroupName) && ele.getInstanceName().equals(ds.getName())); + if (!find) { + //skip test connection on this dbInstance + continue; } } if (ds.getConfig().isDisabled()) { diff --git a/src/main/java/com/actiontech/dble/services/manager/handler/UpdateHandler.java b/src/main/java/com/actiontech/dble/services/manager/handler/UpdateHandler.java index cda8dca362..6fe539f620 100644 --- a/src/main/java/com/actiontech/dble/services/manager/handler/UpdateHandler.java +++ b/src/main/java/com/actiontech/dble/services/manager/handler/UpdateHandler.java @@ -162,7 +162,7 @@ private int updateRows(ManagerService service, ManagerWritableTable managerTable for (LinkedHashMap affectPk : affectPks) { String instanceName = affectPk.get("name"); String dbGroup = affectPk.get("db_group"); - reloadContext.getAffectDbInstanceList().add(new UniqueDbInstance(dbGroup, instanceName)); + reloadContext.addAffectDbInstance(new UniqueDbInstance(dbGroup, instanceName)); } } ReloadConfig.execute(service, 0, false, new ConfStatus(ConfStatus.Status.MANAGER_UPDATE, managerTable.getTableName()), reloadContext); diff --git a/src/main/java/com/actiontech/dble/services/manager/response/ReloadContext.java b/src/main/java/com/actiontech/dble/services/manager/response/ReloadContext.java index 0de824ccd0..3511c32f54 100644 --- a/src/main/java/com/actiontech/dble/services/manager/response/ReloadContext.java +++ b/src/main/java/com/actiontech/dble/services/manager/response/ReloadContext.java @@ -7,12 +7,17 @@ package com.actiontech.dble.services.manager.response; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class ReloadContext { - List affectDbInstanceList = new ArrayList<>(); + private final List affectDbInstanceList = new ArrayList<>(); public List getAffectDbInstanceList() { - return affectDbInstanceList; + return Collections.unmodifiableList(affectDbInstanceList); + } + + public void addAffectDbInstance(UniqueDbInstance dbInstance) { + affectDbInstanceList.add(dbInstance); } }