diff --git a/src/main/java/com/actiontech/dble/rwsplit/RWSplitNonBlockingSession.java b/src/main/java/com/actiontech/dble/rwsplit/RWSplitNonBlockingSession.java index 9d7e5f6685..70dc7c0a23 100644 --- a/src/main/java/com/actiontech/dble/rwsplit/RWSplitNonBlockingSession.java +++ b/src/main/java/com/actiontech/dble/rwsplit/RWSplitNonBlockingSession.java @@ -42,6 +42,9 @@ public class RWSplitNonBlockingSession extends Session { public static final Logger LOGGER = LoggerFactory.getLogger(RWSplitNonBlockingSession.class); private volatile BackendConnection conn; + + //previous preserve conn + private volatile BackendConnection backupConn; private final RWSplitService rwSplitService; private PhysicalDbGroup rwGroup; @@ -314,9 +317,20 @@ public void executeHint(DbleHintParser.HintInfo hintInfo, int sqlType, String sq if (LOGGER.isDebugEnabled()) { LOGGER.debug("route sql {} to {}", sql, dbInstance); } + if (rwSplitService.isInTransaction()) { + if (conn != null) { + backupConn = conn; + conn = null; + } + rwSplitService.setForceUseAutoCommit(true); + } RWSplitHandler handler = new RWSplitHandler(rwSplitService, false, null, callback); dbInstance.getConnection(rwSplitService.getSchema(), handler, null, false); } catch (Exception e) { + if (rwSplitService.isForceUseAutoCommit()) { + conn = backupConn; + backupConn = null; + } rwSplitService.executeException(e, sql); } } @@ -350,8 +364,11 @@ public void bind(BackendConnection bindConn) { public void unbindIfSafe() { final BackendConnection tmp = conn; - if (tmp != null && rwSplitService.isKeepBackendConn()) { + if (tmp != null && !rwSplitService.isKeepBackendConn()) { this.conn = null; + conn = backupConn; + backupConn = null; + if (rwSplitService.isFlowControlled()) { releaseConnectionFromFlowControlled(tmp); } @@ -363,16 +380,28 @@ public void unbindIfSafe() { public void unbind() { this.conn = null; + conn = backupConn; + backupConn = null; } public void close(String reason) { if (null != rwGroup) { rwGroup.unBindRwSplitSession(this); } - final BackendConnection tmp = this.conn; - this.conn = null; - if (tmp != null) { - tmp.close(reason); + { + final BackendConnection tmp = this.conn; + this.conn = null; + if (tmp != null) { + tmp.close(reason); + } + } + + { + final BackendConnection tmp = this.backupConn; + this.backupConn = null; + if (tmp != null) { + tmp.close(reason); + } } } 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 61dced9de6..9b7077fa39 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 @@ -348,14 +348,22 @@ private static SystemVariables checkVersionAGetSystemVariables(ConfigInitializer //check packetSize/lowerCase ConfigUtil.getAndSyncKeyVariables(changeItemList, true); //keep the original system variables - newSystemVariables = DbleServer.getInstance().getSystemVariables(); + SystemVariables memorySystemVariables = DbleServer.getInstance().getSystemVariables(); + SystemVariables currentSystemVariables = getSystemVariablesFromdbGroup(loader, loader.getDbGroups()); + int memoryLowerCase = memorySystemVariables.isLowerCaseTableNames() ? 1 : 0; + if (memorySystemVariables.isLowerCaseTableNames() != currentSystemVariables.isLowerCaseTableNames()) { // check if the lowerCase of the backend has changed + throw new Exception("Dble memory's lowercase value is " + memoryLowerCase + ", " + + "But it was found that the lower_case_table_names value of the dbInstance is not " + memoryLowerCase + ". " + + "Please unify dbInstances's lower_case_table_names or use 'reload @@config_all -r;'"); + } else { + newSystemVariables = memorySystemVariables; + } } ReloadLogHelper.briefInfo("check and get system variables from random node end"); return newSystemVariables; } - /** * test connection */ diff --git a/src/main/java/com/actiontech/dble/services/manager/response/ShowHelp.java b/src/main/java/com/actiontech/dble/services/manager/response/ShowHelp.java index 4ae8f42775..944968b1e5 100644 --- a/src/main/java/com/actiontech/dble/services/manager/response/ShowHelp.java +++ b/src/main/java/com/actiontech/dble/services/manager/response/ShowHelp.java @@ -237,9 +237,9 @@ private static RowDataPacket getRow(String stmt, String desc, String charset) { HELPS.put("show @@statistic", "Turn off statistic information"); HELPS.put("enable @@statistic", "Turn on statistic sql"); - HELPS.put("enable @@enableStatisticAnalysis", "Turn on statistic analysis sql('show @@sql.sum.user/table' or 'show @@sql.condition')"); + HELPS.put("enable @@statisticAnalysis", "Turn on statistic analysis sql('show @@sql.sum.user/table' or 'show @@sql.condition')"); HELPS.put("disable @@statistic", "Turn off statistic sql"); - HELPS.put("disable @@enableStatisticAnalysis", "Turn off statistic analysis sql('show @@sql.sum.user/table' or 'show @@sql.condition')"); + HELPS.put("disable @@statisticAnalysis", "Turn off statistic analysis sql('show @@sql.sum.user/table' or 'show @@sql.condition')"); HELPS.put("reload @@statistic_table_size = ? [where table='?' | where table in (dble_information.tableA,...)]", "Statistic table size"); HELPS.put("reload @@samplingRate=?", "Reset the samplingRate size"); HELPS.put("show @@statistic_queue.usage", "Show the queue usage"); diff --git a/src/main/java/com/actiontech/dble/services/mysqlsharding/MySQLResponseService.java b/src/main/java/com/actiontech/dble/services/mysqlsharding/MySQLResponseService.java index d0318d3154..874e34cdc2 100644 --- a/src/main/java/com/actiontech/dble/services/mysqlsharding/MySQLResponseService.java +++ b/src/main/java/com/actiontech/dble/services/mysqlsharding/MySQLResponseService.java @@ -125,12 +125,15 @@ public void execute(byte[] originPacket) { write(originPacket, WriteFlags.QUERY_END); } - public void execute(BusinessService service, String sql) { + execute(service, sql, false); + } + + public void execute(BusinessService service, String sql, boolean forceUseAutoCommit) { boolean changeUser = isChangeUser(service); if (changeUser) return; - StringBuilder synSQL = getSynSql(null, null, service.isAutocommit(), service); + StringBuilder synSQL = getSynSql(null, null, forceUseAutoCommit || service.isAutocommit(), service); if (protocolResponseHandler != defaultResponseHandler) { protocolResponseHandler = defaultResponseHandler; } diff --git a/src/main/java/com/actiontech/dble/services/rwsplit/RWSplitHandler.java b/src/main/java/com/actiontech/dble/services/rwsplit/RWSplitHandler.java index c999b602f9..fe679de202 100644 --- a/src/main/java/com/actiontech/dble/services/rwsplit/RWSplitHandler.java +++ b/src/main/java/com/actiontech/dble/services/rwsplit/RWSplitHandler.java @@ -71,7 +71,7 @@ public void execute(final BackendConnection conn) { mysqlService.execute(rwSplitService, originPacket); } else if (!StringUtil.isEmpty(executeSql)) { // such as: Hint sql (remove comment sentences) - mysqlService.execute(rwSplitService, executeSql); + mysqlService.execute(rwSplitService, executeSql, rwSplitService.isForceUseAutoCommit()); } else { // not happen mysqlService.execute(rwSplitService, rwSplitService.getExecuteSqlBytes()); diff --git a/src/main/java/com/actiontech/dble/services/rwsplit/RWSplitService.java b/src/main/java/com/actiontech/dble/services/rwsplit/RWSplitService.java index e3fb683840..42bad8f06b 100644 --- a/src/main/java/com/actiontech/dble/services/rwsplit/RWSplitService.java +++ b/src/main/java/com/actiontech/dble/services/rwsplit/RWSplitService.java @@ -77,6 +77,8 @@ public class RWSplitService extends BusinessService { // prepare statement private ConcurrentHashMap psHolder = new ConcurrentHashMap<>(); + private boolean forceUseAutoCommit = false; + public RWSplitService(AbstractConnection connection, AuthResultInfo info) { super(connection, info); @@ -116,6 +118,13 @@ protected void beforeInsertServiceTask(@NotNull ServiceTask task) { session.trace(t -> t.setRequestTime()); } + @Override + protected boolean beforeHandlingTask(@NotNull ServiceTask task) { + //initialize value for the REQUEST + setForceUseAutoCommit(false); + return super.beforeHandlingTask(task); + } + @Override protected void handleInnerData(byte[] data) { session.trace(t -> t.startProcess()); @@ -400,7 +409,8 @@ public PreparedStatementHolder getPrepareStatement(long id) { } public boolean isKeepBackendConn() { - return !isInTransaction() && !isInLoadData() && psHolder.isEmpty() && !isLockTable() && !isUsingTmpTable() && nameSet.isEmpty(); + boolean releaseConn = (!isInTransaction() || isForceUseAutoCommit()) && !isInLoadData() && psHolder.isEmpty() && !isLockTable() && !isUsingTmpTable() && nameSet.isEmpty(); + return !releaseConn; } public boolean isInitDb() { @@ -423,6 +433,14 @@ public void setMultiHandler(RWSplitMultiHandler multiHandler) { this.multiHandler = multiHandler; } + public boolean isForceUseAutoCommit() { + return forceUseAutoCommit; + } + + public void setForceUseAutoCommit(boolean forceUseAutoCommit) { + this.forceUseAutoCommit = forceUseAutoCommit; + } + @Override public void killAndClose(String reason) { session.close(reason); diff --git a/src/main/java/com/actiontech/dble/statistic/sql/handler/SqlStatisticHandler.java b/src/main/java/com/actiontech/dble/statistic/sql/handler/SqlStatisticHandler.java index ca5f11fce9..afd0b94a55 100644 --- a/src/main/java/com/actiontech/dble/statistic/sql/handler/SqlStatisticHandler.java +++ b/src/main/java/com/actiontech/dble/statistic/sql/handler/SqlStatisticHandler.java @@ -229,7 +229,7 @@ public long getExaminedRows() { } public String getSqlDigest() { - if (init.compareAndSet(false, true)) { + if (init.compareAndSet(false, true) || this.sqlDigest == null) { try { if (stmt.equalsIgnoreCase("begin")) { this.sqlDigest = "begin";