inner-1859: release switch (#3355)

Signed-off-by: dcy <dcy10000@gmail.com>

Signed-off-by: dcy <dcy10000@gmail.com>
(cherry picked from commit bc7d40209d)
This commit is contained in:
Rico
2022-08-16 11:20:16 +08:00
committed by dcy10000
parent 12f1fb6449
commit a6092f1a44
3 changed files with 60 additions and 3 deletions

View File

@@ -214,6 +214,26 @@ public final class SystemConfig {
private String gmsslOcaPem = null;
private boolean supportSSL = false;
private int enableAsyncRelease = 0;
//unit: ms
private long releaseTimeout = 10 * 60 * 1000L;
public int getEnableAsyncRelease() {
return enableAsyncRelease;
}
public void setEnableAsyncRelease(int enableAsyncRelease) {
this.enableAsyncRelease = enableAsyncRelease;
}
public long getReleaseTimeout() {
return releaseTimeout;
}
public void setReleaseTimeout(long releaseTimeout) {
this.releaseTimeout = releaseTimeout;
}
public String getServerCertificateKeyStoreUrl() {
return serverCertificateKeyStoreUrl;
}
@@ -1676,6 +1696,8 @@ public final class SystemConfig {
", enableRoutePenetration=" + enableRoutePenetration +
", routePenetrationRules='" + routePenetrationRules + '\'' +
", groupConcatMaxLen='" + groupConcatMaxLen +
", releaseTimeout=" + releaseTimeout +
", enableAsyncRelease=" + enableAsyncRelease +
"]";
}

View File

@@ -5,6 +5,7 @@
package com.actiontech.dble.net.handler;
import com.actiontech.dble.config.model.SystemConfig;
import com.actiontech.dble.net.connection.BackendConnection;
import com.actiontech.dble.services.mysqlsharding.MySQLResponseService;
@@ -26,6 +27,32 @@ public class BackEndRecycleRunnable implements Runnable, BackEndCleaner {
service.setRecycler(this);
}
public void runSync() {
BackendConnection conn = service.getConnection();
if (conn.isClosed()) {
return;
}
try {
lock.lock();
try {
if (service.isRowDataFlowing()) {
if (!condRelease.await(SystemConfig.getInstance().getReleaseTimeout(), TimeUnit.MILLISECONDS)) {
if (!conn.isClosed()) {
conn.businessClose("recycle time out");
}
}
}
} catch (Exception e) {
service.getConnection().businessClose("recycle exception");
} finally {
lock.unlock();
}
} catch (Throwable e) {
service.getConnection().businessClose("recycle exception");
}
}
@Override
public void run() {
@@ -38,7 +65,7 @@ public class BackEndRecycleRunnable implements Runnable, BackEndCleaner {
lock.lock();
try {
if (service.isRowDataFlowing()) {
if (!condRelease.await(10, TimeUnit.MILLISECONDS)) {
if (!condRelease.await(SystemConfig.getInstance().getReleaseTimeout(), TimeUnit.MILLISECONDS)) {
if (!conn.isClosed()) {
conn.businessClose("recycle time out");
}

View File

@@ -228,6 +228,9 @@ public class MySQLResponseService extends BackendService {
protocolResponseHandler = defaultResponseHandler;
}
synAndDoExecuteMultiNode(synSQL, rrn, service.getCharset());
} catch (Exception e) {
LOGGER.info("route error {},{},{}", rrn, this, service);
throw e;
} finally {
TraceManager.finishSpan(this, traceObject);
}
@@ -351,8 +354,13 @@ public class MySQLResponseService extends BackendService {
if (logResponse.compareAndSet(false, true)) {
session.setBackendResponseEndTime(this);
}
DbleServer.getInstance().getComplexQueryExecutor().execute(new BackEndRecycleRunnable(this));
return false;
if (SystemConfig.getInstance().getEnableAsyncRelease() == 1) {
DbleServer.getInstance().getComplexQueryExecutor().execute(new BackEndRecycleRunnable(this));
return false;
} else {
new BackEndRecycleRunnable(this).runSync();
}
}
complexQuery = false;
attachment = null;