From 43acec3d2c7b903d19b949de9becbfb90704c144 Mon Sep 17 00:00:00 2001 From: wenyh <44251917+wenyh1@users.noreply.github.com> Date: Fri, 4 Aug 2023 14:44:14 +0800 Subject: [PATCH] [inner-2318] the lowercase on the mysql side changes, after 'reload @@config_all', the heartbeat of the dbInstance should be in the error state --- .../com/actiontech/dble/config/DbleTempConfig.java | 9 --------- .../java/com/actiontech/dble/config/ServerConfig.java | 11 ----------- .../com/actiontech/dble/config/util/ConfigUtil.java | 9 +++------ .../dble/server/variables/SystemVariables.java | 9 ++++++++- .../dble/services/manager/response/ReloadConfig.java | 4 ++-- 5 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/actiontech/dble/config/DbleTempConfig.java b/src/main/java/com/actiontech/dble/config/DbleTempConfig.java index e095e4117..a2442e17b 100644 --- a/src/main/java/com/actiontech/dble/config/DbleTempConfig.java +++ b/src/main/java/com/actiontech/dble/config/DbleTempConfig.java @@ -17,7 +17,6 @@ public final class DbleTempConfig { private RawJson shardingConfig; private RawJson userConfig; private RawJson sequenceConfig; - private Boolean lowerCase; public RawJson getDbConfig() { return dbConfig; @@ -51,14 +50,6 @@ public final class DbleTempConfig { this.sequenceConfig = sequenceConfig; } - public Boolean isLowerCase() { - return lowerCase; - } - - public void setLowerCase(Boolean lowerCase) { - this.lowerCase = lowerCase; - } - public static DbleTempConfig getInstance() { return INSTANCE; } diff --git a/src/main/java/com/actiontech/dble/config/ServerConfig.java b/src/main/java/com/actiontech/dble/config/ServerConfig.java index 2e7c5ebd5..2c7c48ece 100644 --- a/src/main/java/com/actiontech/dble/config/ServerConfig.java +++ b/src/main/java/com/actiontech/dble/config/ServerConfig.java @@ -77,7 +77,6 @@ public class ServerConfig { private RawJson shardingConfig; private RawJson userConfig; private RawJson sequenceConfig; - private Boolean lowerCase; public ServerConfig() { //read sharding.xml,db.xml and user.xml @@ -166,7 +165,6 @@ public class ServerConfig { public void getAndSyncKeyVariables() throws Exception { ConfigUtil.checkDbleAndMysqlVersion(confInitNew.getDbGroups()); ConfigUtil.getAndSyncKeyVariables(confInitNew.getDbGroups(), true); - DbleServer.getInstance().getConfig().setLowerCase(DbleTempConfig.getInstance().isLowerCase()); } public boolean isFullyConfigured() { @@ -464,7 +462,6 @@ public class ServerConfig { this.dbConfig = dbJsonConfig; this.shardingConfig = shardingJsonConfig; this.sequenceConfig = sequenceJsonConfig; - this.lowerCase = DbleTempConfig.getInstance().isLowerCase(); try { ReloadLogHelper.briefInfo("ha config init ..."); @@ -995,14 +992,6 @@ public class ServerConfig { public RawJson getSequenceConfig() { return sequenceConfig; } - - public Boolean isLowerCase() { - return lowerCase; - } - - public void setLowerCase(Boolean lowerCase) { - this.lowerCase = lowerCase; - } } diff --git a/src/main/java/com/actiontech/dble/config/util/ConfigUtil.java b/src/main/java/com/actiontech/dble/config/util/ConfigUtil.java index 9ea17036c..0ad059631 100644 --- a/src/main/java/com/actiontech/dble/config/util/ConfigUtil.java +++ b/src/main/java/com/actiontech/dble/config/util/ConfigUtil.java @@ -9,7 +9,6 @@ import com.actiontech.dble.DbleServer; import com.actiontech.dble.backend.datasource.*; import com.actiontech.dble.backend.mysql.VersionUtil; import com.actiontech.dble.config.ConfigInitializer; -import com.actiontech.dble.config.DbleTempConfig; import com.actiontech.dble.config.helper.GetAndSyncDbInstanceKeyVariables; import com.actiontech.dble.config.helper.KeyVariables; import com.actiontech.dble.config.model.MysqlVersion; @@ -94,7 +93,7 @@ public final class ConfigUtil { Map oldDbInstanceMaps = new HashMap<>(); DbleServer.getInstance().getConfig().getDbGroups() .values().stream().forEach(group -> group.getAllDbInstanceMap() - .values().stream().forEach(db -> oldDbInstanceMaps.put(genDataSourceKey(group.getGroupName(), db.getName()), db))); + .values().stream().forEach(db -> oldDbInstanceMaps.put(genDataSourceKey(group.getGroupName(), db.getName()), db))); if (CollectionUtil.isEmpty(oldDbInstanceMaps)) return false; @@ -213,7 +212,7 @@ public final class ConfigUtil { private static List getClickHouseSyncKeyVariables(Set ckDbInstances, boolean isAllChange, boolean needSync, boolean existMysql) throws Exception { if (ckDbInstances.size() == 0) return new ArrayList<>(); - Boolean lowerCase = (isAllChange && !existMysql) ? null : DbleServer.getInstance().getConfig().isLowerCase(); + Boolean lowerCase = (isAllChange && !existMysql) ? null : DbleServer.getInstance().getSystemVariables().getLowerCase(); if (lowerCase != null && lowerCase) { StringBuilder sb = new StringBuilder(); sb.append("The configuration add Clickhouse. Since clickhouse is not case sensitive, so the values of lower_case_table_names for previous dbInstances must be 0."); @@ -234,7 +233,7 @@ public final class ConfigUtil { return msgList; String msg; - Boolean lowerCase = isAllChange ? null : DbleServer.getInstance().getConfig().isLowerCase(); + Boolean lowerCase = isAllChange ? null : DbleServer.getInstance().getSystemVariables().getLowerCase(); boolean reInitLowerCase = false; Set leftGroup = new HashSet<>(); Set rightGroup = new HashSet<>(); @@ -310,7 +309,6 @@ public final class ConfigUtil { throw new IOException("The configuration contains Clickhouse. Since clickhouse is not case sensitive, so the values of lower_case_table_names for all dbInstances must be 0. Current all dbInstances are 1."); } dbInstanceList.forEach(dbInstance -> dbInstance.setNeedSkipHeartTest(true)); - DbleTempConfig.getInstance().setLowerCase(lowerCase); return msgList; } @@ -340,7 +338,6 @@ public final class ConfigUtil { LOGGER.warn(msg); } dbInstanceList.forEach(dbInstance -> dbInstance.setNeedSkipHeartTest(true)); - DbleTempConfig.getInstance().setLowerCase(lowerCaseA); return msgList; } diff --git a/src/main/java/com/actiontech/dble/server/variables/SystemVariables.java b/src/main/java/com/actiontech/dble/server/variables/SystemVariables.java index c17a251b6..542d3bc72 100644 --- a/src/main/java/com/actiontech/dble/server/variables/SystemVariables.java +++ b/src/main/java/com/actiontech/dble/server/variables/SystemVariables.java @@ -15,7 +15,7 @@ import java.util.Map; public final class SystemVariables { private Map sessionVariables; - private volatile boolean lowerCase = true; + private volatile Boolean lowerCase = null; public SystemVariables() { sessionVariables = new HashMap<>(); @@ -23,6 +23,13 @@ public final class SystemVariables { } public boolean isLowerCaseTableNames() { + if (lowerCase == null) + // if uninitialized, the default is case-insensitive, so return true + return true; + return lowerCase; + } + + public Boolean getLowerCase() { return lowerCase; } diff --git a/src/main/java/com/actiontech/dble/services/manager/response/ReloadConfig.java b/src/main/java/com/actiontech/dble/services/manager/response/ReloadConfig.java index b3a5bcdd7..61dced9de 100644 --- a/src/main/java/com/actiontech/dble/services/manager/response/ReloadConfig.java +++ b/src/main/java/com/actiontech/dble/services/manager/response/ReloadConfig.java @@ -347,8 +347,8 @@ public final class ReloadConfig { ConfigUtil.checkDbleAndMysqlVersion(changeItemList, loader); //check packetSize/lowerCase ConfigUtil.getAndSyncKeyVariables(changeItemList, true); - //get system variables - newSystemVariables = getSystemVariablesFromdbGroup(loader, loader.getDbGroups()); + //keep the original system variables + newSystemVariables = DbleServer.getInstance().getSystemVariables(); } ReloadLogHelper.briefInfo("check and get system variables from random node end"); return newSystemVariables;