Skip to content

Commit

Permalink
inner-730: fixed: 'use schema' cause slowQuery thread terminated.
Browse files Browse the repository at this point in the history
Signed-off-by: dcy <dcy10000@gmail.com>
  • Loading branch information
dcy10000 committed Jan 6, 2021
1 parent daba179 commit 40dfee8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

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;
Expand All @@ -16,7 +15,6 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.concurrent.*;

Expand Down Expand Up @@ -52,8 +50,11 @@ public void run() {
if (log == null) {
continue;
}
writeLog(log);
logSize++;

if (writeLog(log)) {
logSize++;
}

synchronized (this) {
if ((logSize - lastLogSize) % SlowQueryLog.getInstance().getFlushSize() == 0) {
flushLog();
Expand All @@ -62,29 +63,34 @@ public void run() {
}
// 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -110,6 +111,7 @@ private static void parserAndExecuteShowTables(ShardingService shardingService,
}
RouterUtil.routeToSingleNode(rrs, node);
ShowTablesHandler showTablesHandler = new ShowTablesHandler(rrs, shardingService.getSession2(), info);
shardingService.getSession2().setPreExecuteEnd(TraceResult.SqlTraceType.SINGLE_NODE_QUERY);
showTablesHandler.execute();
}

Expand Down

0 comments on commit 40dfee8

Please sign in to comment.