diff --git a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbGroup.java b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbGroup.java index 76d3e98cc7..a3e82b7aeb 100644 --- a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbGroup.java +++ b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbGroup.java @@ -215,6 +215,8 @@ private boolean checkState() { if (getBindingCount() != 0) { state = STATE_DELETING; IOProcessor.BACKENDS_OLD_GROUP.add(this); + long time = System.nanoTime(); + allSourceMap.values().forEach(f -> f.setAsyncExecStopTime(time)); return false; } state = STATE_ABANDONED; @@ -265,7 +267,7 @@ public void stopOfFresh(List sourceNames, String reason, boolean closeFr public boolean stopOfBackground(String reason) { if (state.intValue() == STATE_DELETING && getBindingCount() == 0) { for (PhysicalDbInstance dbInstance : allSourceMap.values()) { - dbInstance.stopDirectly(reason, false, false); + dbInstance.stopOfBackground(reason); } return true; } diff --git a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbInstance.java b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbInstance.java index 5aaf32ae39..0cc65a8679 100644 --- a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbInstance.java +++ b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbInstance.java @@ -62,6 +62,8 @@ public abstract class PhysicalDbInstance implements ReadTimeStatusInstance { private volatile boolean needSkipEvit = false; private volatile boolean needSkipHeartTest = false; private volatile int logCount; + private volatile long lastExecTime; // stop、start + private volatile long asyncExecStopTime; public PhysicalDbInstance(DbInstanceConfig config, DbGroupConfig dbGroupConfig, boolean isReadNode) { this.config = config; @@ -388,6 +390,7 @@ public void startHeartbeat() { } void start(String reason, boolean isStartHeartbeat) { + lastExecTime = System.nanoTime(); startPool(reason); if (isStartHeartbeat) { startHeartbeat(); @@ -408,6 +411,7 @@ private boolean checkState() { if (dbGroup.getBindingCount() != 0) { dbGroup.setState(PhysicalDbGroup.STATE_DELETING); IOProcessor.BACKENDS_OLD_INSTANCE.add(this); + setAsyncExecStopTime(System.nanoTime()); return false; } if (dbGroup.isStop()) { @@ -416,6 +420,7 @@ private boolean checkState() { if (dbGroup.getBindingCount() != 0) { dbGroup.setState(PhysicalDbGroup.STATE_DELETING); IOProcessor.BACKENDS_OLD_INSTANCE.add(this); + setAsyncExecStopTime(System.nanoTime()); return false; } return true; @@ -423,6 +428,10 @@ private boolean checkState() { public boolean stopOfBackground(String reason) { if (dbGroup.getState() == PhysicalDbGroup.STATE_DELETING && dbGroup.getBindingCount() == 0) { + if (asyncExecStopTime <= lastExecTime) { // In extreme cases (equal cases), in extreme cases there may be problems, + LOGGER.info("discard expired stop() operations"); + return true; + } stopDirectly(reason, false, false); return true; } @@ -450,6 +459,7 @@ public void stop(String reason, boolean closeFront) { } protected void stop(String reason, boolean closeFront, boolean isStopHeartbeat, boolean isStopPool) { + lastExecTime = System.nanoTime(); if (isStopHeartbeat) { stopHeartbeat(reason); } @@ -518,6 +528,22 @@ public boolean enable() { return false; } + public long getLastExecTime() { + return lastExecTime; + } + + public void setLastExecTime(long lastExecTime) { + this.lastExecTime = lastExecTime; + } + + public long getAsyncExecStopTime() { + return asyncExecStopTime; + } + + public void setAsyncExecStopTime(long asyncExecStopTime) { + this.asyncExecStopTime = asyncExecStopTime; + } + public final int getActiveConnections() { return connectionPool.getCount(PooledConnection.STATE_IN_USE); }