inner-730: fixed: 'use schema' cause slowQuery thread terminated. (#2397)

Signed-off-by: dcy <dcy10000@gmail.com>
(cherry picked from commit 84c3f87391)
This commit is contained in:
Rico
2021-01-11 15:45:50 +08:00
committed by guoaomen
parent e04e87407c
commit 857764ff7b
2 changed files with 22 additions and 14 deletions
@@ -7,7 +7,6 @@ package com.actiontech.dble.log.slow;
import com.actiontech.dble.config.model.SystemConfig;
import com.actiontech.dble.log.DailyRotateLogStore;
import com.actiontech.dble.server.status.SlowQueryLog;
import com.actiontech.dble.server.trace.TraceResult;
import com.actiontech.dble.services.mysqlsharding.ShardingService;
@@ -16,7 +15,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.concurrent.*;
@@ -52,8 +50,11 @@ public class SlowQueryLogProcessor extends Thread {
if (log == null) {
continue;
}
writeLog(log);
logSize++;
if (writeLog(log)) {
logSize++;
}
synchronized (this) {
if ((logSize - lastLogSize) % SlowQueryLog.getInstance().getFlushSize() == 0) {
flushLog();
@@ -62,29 +63,34 @@ public class SlowQueryLogProcessor extends Thread {
}
// disable slow_query_log, end task
while ((log = queue.poll()) != null) {
writeLog(log);
logSize++;
if (writeLog(log)) {
logSize++;
}
}
scheduler.shutdown();
flushLog();
store.close();
} catch (IOException e) {
LOGGER.info("transaction log error:", e);
store.close();
} finally {
scheduler.shutdown();
flushLog();
store.close();
}
}
private synchronized void writeLog(SlowQueryLogEntry log) throws IOException {
if (log == null)
return;
private synchronized boolean writeLog(SlowQueryLogEntry log) throws IOException {
if (log == null) {
return false;
}
byte[] data;
try {
data = log.toString().getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
return;
} catch (Exception e) {
LOGGER.warn("generate write log error ", e);
return false;
}
ByteBuffer buffer = ByteBuffer.wrap(data);
store.write(buffer);
return true;
}
private void flushLog() {
@@ -27,6 +27,7 @@ import com.actiontech.dble.plan.visitor.MySQLItemVisitor;
import com.actiontech.dble.route.RouteResultset;
import com.actiontech.dble.route.util.RouterUtil;
import com.actiontech.dble.server.parser.ServerParse;
import com.actiontech.dble.server.trace.TraceResult;
import com.actiontech.dble.services.mysqlsharding.ShardingService;
import com.actiontech.dble.singleton.ProxyMeta;
import com.actiontech.dble.util.StringUtil;
@@ -110,6 +111,7 @@ public final class ShowTables {
}
RouterUtil.routeToSingleNode(rrs, node);
ShowTablesHandler showTablesHandler = new ShowTablesHandler(rrs, shardingService.getSession2(), info);
shardingService.getSession2().setPreExecuteEnd(TraceResult.SqlTraceType.SINGLE_NODE_QUERY);
showTablesHandler.execute();
}