mirror of
https://github.com/actiontech/dble.git
synced 2026-05-07 15:01:10 -05:00
inner-2383: add log
inner-2383: add log inner-2383: fix for ci inner-2383: skip test other connection on some case
This commit is contained in:
@@ -42,6 +42,7 @@ import com.actiontech.dble.net.connection.BackendConnection;
|
||||
import com.actiontech.dble.net.connection.FrontendConnection;
|
||||
import com.actiontech.dble.route.RouteResultsetNode;
|
||||
import com.actiontech.dble.route.util.PropertiesUtil;
|
||||
import com.actiontech.dble.services.manager.response.ReloadContext;
|
||||
import com.actiontech.dble.services.manager.response.ReloadConfig;
|
||||
import com.actiontech.dble.services.manager.response.ShowBinlogStatus;
|
||||
import com.actiontech.dble.services.mysqlsharding.ShardingService;
|
||||
@@ -288,7 +289,7 @@ public final class ClusterLogic {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ReloadConfig.ReloadResult result = ReloadConfig.reloadByConfig(Integer.parseInt(params), false);
|
||||
ReloadConfig.ReloadResult result = ReloadConfig.reloadByConfig(Integer.parseInt(params), false, new ReloadContext());
|
||||
if (!checkLocalResult(result.isSuccess())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import com.actiontech.dble.config.util.ConfigException;
|
||||
import com.actiontech.dble.plan.common.ptr.BoolPtr;
|
||||
import com.actiontech.dble.route.function.AbstractPartitionAlgorithm;
|
||||
import com.actiontech.dble.route.parser.util.Pair;
|
||||
import com.actiontech.dble.route.sequence.handler.IncrSequenceMySQLHandler;
|
||||
import com.actiontech.dble.services.manager.response.ReloadContext;
|
||||
import com.actiontech.dble.singleton.TraceManager;
|
||||
import com.actiontech.dble.util.StringUtil;
|
||||
import com.google.common.collect.Maps;
|
||||
@@ -42,6 +44,7 @@ public class ConfigInitializer implements ProblemReporter {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigInitializer.class);
|
||||
|
||||
private volatile ReloadContext reloadContext;
|
||||
private volatile Map<UserName, UserConfig> users;
|
||||
private volatile Map<String, SchemaConfig> schemas = Maps.newHashMap();
|
||||
private volatile Map<String, ShardingNode> shardingNodes = Maps.newHashMap();
|
||||
@@ -206,6 +209,17 @@ public class ConfigInitializer implements ProblemReporter {
|
||||
// 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());
|
||||
|
||||
//not support for sharding db group
|
||||
if (!useSharding) {
|
||||
skipTestConnectionOnUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, PhysicalDbGroup> entry : this.dbGroups.entrySet()) {
|
||||
dbGroup = entry.getValue();
|
||||
dbGroupName = entry.getKey();
|
||||
@@ -218,6 +232,14 @@ public class ConfigInitializer implements ProblemReporter {
|
||||
}
|
||||
|
||||
for (PhysicalDbInstance ds : dbGroup.getDbInstances(true)) {
|
||||
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()) {
|
||||
errorInfos.add(new ErrorInfo("Backend", "WARNING", "dbGroup[" + dbGroupName + "," + ds.getName() + "] is disabled"));
|
||||
LOGGER.info("dbGroup[" + ds.getDbGroupConfig().getName() + "] is disabled,just mark testing failed and skip it");
|
||||
@@ -357,4 +379,8 @@ public class ConfigInitializer implements ProblemReporter {
|
||||
public String getSequenceConfig() {
|
||||
return sequenceConfig;
|
||||
}
|
||||
|
||||
public void setReloadContext(ReloadContext reloadContext) {
|
||||
this.reloadContext = reloadContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ public final class SystemConfig {
|
||||
private int useCostTimeStat = 0;
|
||||
private int maxCostStatSize = 100;
|
||||
private int costSamplePercent = 1;
|
||||
private boolean skipTestConOnUpdate = false;
|
||||
//connection
|
||||
private String charset = "utf8mb4";
|
||||
private int maxPacketSize = 4 * 1024 * 1024;
|
||||
@@ -631,6 +632,14 @@ public final class SystemConfig {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSkipTestConOnUpdate() {
|
||||
return skipTestConOnUpdate;
|
||||
}
|
||||
|
||||
public void setSkipTestConOnUpdate(boolean skipTestConOnUpdate) {
|
||||
this.skipTestConOnUpdate = skipTestConOnUpdate;
|
||||
}
|
||||
|
||||
public long getXaLogCleanPeriod() {
|
||||
return xaLogCleanPeriod;
|
||||
}
|
||||
@@ -1526,6 +1535,7 @@ public final class SystemConfig {
|
||||
", routePenetrationRules='" + routePenetrationRules + '\'' +
|
||||
", releaseTimeout=" + releaseTimeout +
|
||||
", enableAsyncRelease=" + enableAsyncRelease +
|
||||
", skipTestConOnUpdate=" + skipTestConOnUpdate +
|
||||
", enableCheckSchema=" + enableCheckSchema +
|
||||
"]";
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public final class DeleteHandler {
|
||||
Set<LinkedHashMap<String, String>> affectPks = ManagerTableUtil.getAffectPks(service, managerTable, foundRows, null);
|
||||
rowSize = managerTable.deleteRows(affectPks);
|
||||
if (rowSize != 0) {
|
||||
ReloadConfig.execute(service, 0, false, new ConfStatus(ConfStatus.Status.MANAGER_DELETE, managerTable.getTableName()), packetResult);
|
||||
ReloadConfig.execute(service, 0, false, new ConfStatus(ConfStatus.Status.MANAGER_DELETE, managerTable.getTableName()), packetResult, null);
|
||||
}
|
||||
packetResult.setRowSize(rowSize);
|
||||
} catch (SQLException e) {
|
||||
|
||||
@@ -79,7 +79,7 @@ public final class InsertHandler {
|
||||
managerTable.checkPrimaryKeyDuplicate(rows);
|
||||
rowSize = managerTable.insertRows(rows);
|
||||
if (rowSize != 0) {
|
||||
ReloadConfig.execute(service, 0, false, new ConfStatus(ConfStatus.Status.MANAGER_INSERT, managerTable.getTableName()), packetResult);
|
||||
ReloadConfig.execute(service, 0, false, new ConfStatus(ConfStatus.Status.MANAGER_INSERT, managerTable.getTableName()), packetResult, null);
|
||||
}
|
||||
managerTable.afterExecute();
|
||||
packetResult.setRowSize(rowSize);
|
||||
|
||||
@@ -25,7 +25,10 @@ import com.actiontech.dble.services.manager.information.ManagerBaseTable;
|
||||
import com.actiontech.dble.services.manager.information.ManagerSchemaInfo;
|
||||
import com.actiontech.dble.services.manager.information.ManagerTableUtil;
|
||||
import com.actiontech.dble.services.manager.information.ManagerWritableTable;
|
||||
import com.actiontech.dble.services.manager.information.tables.DbleDbInstance;
|
||||
import com.actiontech.dble.services.manager.response.ReloadConfig;
|
||||
import com.actiontech.dble.services.manager.response.ReloadContext;
|
||||
import com.actiontech.dble.services.manager.response.UniqueDbInstance;
|
||||
import com.actiontech.dble.util.StringUtil;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
@@ -39,7 +42,9 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public final class UpdateHandler {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UpdateHandler.class);
|
||||
@@ -181,7 +186,17 @@ public final class UpdateHandler {
|
||||
if (!affectPks.isEmpty()) {
|
||||
rowSize = managerTable.updateRows(affectPks, values);
|
||||
if (rowSize != 0) {
|
||||
ReloadConfig.execute(service, 0, false, new ConfStatus(ConfStatus.Status.MANAGER_UPDATE, managerTable.getTableName()), packetResult);
|
||||
|
||||
ReloadContext reloadContext = new ReloadContext();
|
||||
if (managerTable instanceof DbleDbInstance) {
|
||||
for (LinkedHashMap<String, String> affectPk : affectPks) {
|
||||
String instanceName = affectPk.get("name");
|
||||
String dbGroup = affectPk.get("db_group");
|
||||
reloadContext.addAffectDbInstance(new UniqueDbInstance(dbGroup, instanceName));
|
||||
}
|
||||
}
|
||||
ReloadConfig.execute(service, 0, false, new ConfStatus(ConfStatus.Status.MANAGER_UPDATE, managerTable.getTableName()), packetResult, reloadContext);
|
||||
|
||||
}
|
||||
}
|
||||
return rowSize;
|
||||
|
||||
@@ -74,15 +74,17 @@ public final class ReloadConfig {
|
||||
writeErrorResult(service, e.getMessage() == null ? e.toString() : e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void execute(ManagerService service, final int loadAllMode, boolean returnFlag, ConfStatus confStatus) throws Exception {
|
||||
execute(service, loadAllMode, returnFlag, confStatus, new ReloadContext());
|
||||
}
|
||||
|
||||
public static void execute(ManagerService service, final int loadAllMode, boolean returnFlag, ConfStatus confStatus, ReloadContext reloadContext) throws Exception {
|
||||
try {
|
||||
PacketResult packetResult = new PacketResult();
|
||||
if (ClusterConfig.getInstance().isClusterEnable()) {
|
||||
reloadWithCluster(service, loadAllMode, confStatus, packetResult);
|
||||
reloadWithCluster(service, loadAllMode, confStatus, packetResult, reloadContext);
|
||||
} else {
|
||||
reloadWithoutCluster(service, loadAllMode, returnFlag, confStatus, packetResult);
|
||||
reloadWithoutCluster(service, loadAllMode, returnFlag, confStatus, packetResult, reloadContext);
|
||||
}
|
||||
writePacket(packetResult.isSuccess(), service, packetResult.getErrorMsg(), packetResult.getErrorCode());
|
||||
} finally {
|
||||
@@ -90,19 +92,19 @@ public final class ReloadConfig {
|
||||
}
|
||||
}
|
||||
|
||||
public static void execute(ManagerService service, final int loadAllMode, boolean returnFlag, ConfStatus confStatus, PacketResult packetResult) throws Exception {
|
||||
public static void execute(ManagerService service, final int loadAllMode, boolean returnFlag, ConfStatus confStatus, PacketResult packetResult, ReloadContext reloadContext) throws Exception {
|
||||
try {
|
||||
if (ClusterConfig.getInstance().isClusterEnable()) {
|
||||
reloadWithCluster(service, loadAllMode, confStatus, packetResult);
|
||||
reloadWithCluster(service, loadAllMode, confStatus, packetResult, reloadContext);
|
||||
} else {
|
||||
reloadWithoutCluster(service, loadAllMode, returnFlag, confStatus, packetResult);
|
||||
reloadWithoutCluster(service, loadAllMode, returnFlag, confStatus, packetResult, reloadContext);
|
||||
}
|
||||
} finally {
|
||||
ReloadManager.reloadFinish();
|
||||
}
|
||||
}
|
||||
|
||||
private static void reloadWithCluster(ManagerService service, int loadAllMode, ConfStatus confStatus, PacketResult packetResult) throws Exception {
|
||||
private static void reloadWithCluster(ManagerService service, int loadAllMode, ConfStatus confStatus, PacketResult packetResult, ReloadContext reloadContext) throws Exception {
|
||||
TraceManager.TraceObject traceObject = TraceManager.serviceTrace(service, "reload-with-cluster");
|
||||
try {
|
||||
DistributeLock distributeLock = null;
|
||||
@@ -133,9 +135,9 @@ public final class ReloadConfig {
|
||||
ReloadResult reloadResult;
|
||||
if (confStatus.getStatus().equals(ConfStatus.Status.MANAGER_INSERT) || confStatus.getStatus().equals(ConfStatus.Status.MANAGER_UPDATE) ||
|
||||
confStatus.getStatus().equals(ConfStatus.Status.MANAGER_DELETE)) {
|
||||
reloadResult = reloadByConfig(loadAllMode, true);
|
||||
reloadResult = reloadByConfig(loadAllMode, true, reloadContext);
|
||||
} else {
|
||||
reloadResult = reloadByLocalXml(loadAllMode);
|
||||
reloadResult = reloadByLocalXml(loadAllMode, reloadContext);
|
||||
}
|
||||
if (!reloadResult.isSuccess()) {
|
||||
packetResult.setSuccess(false);
|
||||
@@ -188,7 +190,7 @@ public final class ReloadConfig {
|
||||
}
|
||||
|
||||
|
||||
private static void reloadWithoutCluster(ManagerService service, final int loadAllMode, boolean returnFlag, ConfStatus confStatus, PacketResult packetResult) throws Exception {
|
||||
private static void reloadWithoutCluster(ManagerService service, final int loadAllMode, boolean returnFlag, ConfStatus confStatus, PacketResult packetResult, ReloadContext reloadContext) throws Exception {
|
||||
TraceManager.TraceObject traceObject = TraceManager.serviceTrace(service, "reload-in-local");
|
||||
final ReentrantReadWriteLock lock = DbleServer.getInstance().getConfig().getLock();
|
||||
lock.writeLock().lock();
|
||||
@@ -202,9 +204,9 @@ public final class ReloadConfig {
|
||||
ReloadResult reloadResult;
|
||||
if (confStatus.getStatus().equals(ConfStatus.Status.MANAGER_INSERT) || confStatus.getStatus().equals(ConfStatus.Status.MANAGER_UPDATE) ||
|
||||
confStatus.getStatus().equals(ConfStatus.Status.MANAGER_DELETE)) {
|
||||
reloadResult = reloadByConfig(loadAllMode, true);
|
||||
reloadResult = reloadByConfig(loadAllMode, true, reloadContext);
|
||||
} else {
|
||||
reloadResult = reloadByLocalXml(loadAllMode);
|
||||
reloadResult = reloadByLocalXml(loadAllMode, reloadContext);
|
||||
}
|
||||
if (reloadResult.isSuccess() && returnFlag) {
|
||||
// ok package
|
||||
@@ -228,11 +230,11 @@ public final class ReloadConfig {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ReloadResult reloadByLocalXml(final int loadAllMode) throws Exception {
|
||||
return reload(loadAllMode, null, null, null, null);
|
||||
public static ReloadResult reloadByLocalXml(final int loadAllMode, ReloadContext reloadContext) throws Exception {
|
||||
return reload(loadAllMode, null, null, null, null, reloadContext);
|
||||
}
|
||||
|
||||
public static ReloadResult reloadByConfig(final int loadAllMode, boolean isWriteToLocal) throws Exception {
|
||||
public static ReloadResult reloadByConfig(final int loadAllMode, boolean isWriteToLocal, ReloadContext reloadContext) throws Exception {
|
||||
String userConfig = DbleTempConfig.getInstance().getUserConfig();
|
||||
userConfig = StringUtil.isBlank(userConfig) ? DbleServer.getInstance().getConfig().getUserConfig() : userConfig;
|
||||
String dbConfig = DbleTempConfig.getInstance().getDbConfig();
|
||||
@@ -241,14 +243,14 @@ public final class ReloadConfig {
|
||||
shardingConfig = StringUtil.isBlank(shardingConfig) ? DbleServer.getInstance().getConfig().getShardingConfig() : shardingConfig;
|
||||
String sequenceConfig = DbleTempConfig.getInstance().getSequenceConfig();
|
||||
sequenceConfig = StringUtil.isBlank(sequenceConfig) ? DbleServer.getInstance().getConfig().getSequenceConfig() : sequenceConfig;
|
||||
ReloadResult reloadResult = reload(loadAllMode, userConfig, dbConfig, shardingConfig, sequenceConfig);
|
||||
ReloadResult reloadResult = reload(loadAllMode, userConfig, dbConfig, shardingConfig, sequenceConfig, reloadContext);
|
||||
DbleTempConfig.getInstance().clean();
|
||||
//sync json to local
|
||||
DbleServer.getInstance().getConfig().syncJsonToLocal(isWriteToLocal);
|
||||
return reloadResult;
|
||||
}
|
||||
|
||||
private static ReloadResult reload(final int loadAllMode, String userConfig, String dbConfig, String shardingConfig, String sequenceConfig) throws Exception {
|
||||
private static ReloadResult reload(final int loadAllMode, String userConfig, String dbConfig, String shardingConfig, String sequenceConfig, ReloadContext reloadContext) throws Exception {
|
||||
TraceManager.TraceObject traceObject = TraceManager.threadTrace("self-reload");
|
||||
try {
|
||||
/*
|
||||
@@ -264,6 +266,7 @@ public final class ReloadConfig {
|
||||
} else {
|
||||
loader = new ConfigInitializer(userConfig, dbConfig, shardingConfig, sequenceConfig);
|
||||
}
|
||||
loader.setReloadContext(reloadContext);
|
||||
} catch (Exception e) {
|
||||
throw new Exception(e);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2023 ActionTech.
|
||||
* based on code by MyCATCopyrightHolder Copyright (c) 2013, OpenCloudDB/MyCAT.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.services.manager.response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ReloadContext {
|
||||
private final List<UniqueDbInstance> affectDbInstanceList = new ArrayList<>();
|
||||
|
||||
public List<UniqueDbInstance> getAffectDbInstanceList() {
|
||||
return Collections.unmodifiableList(affectDbInstanceList);
|
||||
}
|
||||
|
||||
public void addAffectDbInstance(UniqueDbInstance dbInstance) {
|
||||
affectDbInstanceList.add(dbInstance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2023 ActionTech.
|
||||
* based on code by MyCATCopyrightHolder Copyright (c) 2013, OpenCloudDB/MyCAT.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.services.manager.response;
|
||||
|
||||
public class UniqueDbInstance {
|
||||
String groupName;
|
||||
String instanceName;
|
||||
|
||||
public UniqueDbInstance(String groupName, String instanceName) {
|
||||
this.groupName = groupName;
|
||||
this.instanceName = instanceName;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public void setGroupName(String groupName) {
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
public String getInstanceName() {
|
||||
return instanceName;
|
||||
}
|
||||
|
||||
public void setInstanceName(String instanceName) {
|
||||
this.instanceName = instanceName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user