diff --git a/src/main/java/com/actiontech/dble/log/slow/SlowQueryLogProcessor.java b/src/main/java/com/actiontech/dble/log/slow/SlowQueryLogProcessor.java index bc0086d02c..515181d80a 100644 --- a/src/main/java/com/actiontech/dble/log/slow/SlowQueryLogProcessor.java +++ b/src/main/java/com/actiontech/dble/log/slow/SlowQueryLogProcessor.java @@ -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; @@ -16,7 +15,6 @@ 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 void run() { 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 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() { diff --git a/src/main/java/com/actiontech/dble/server/response/ShowTables.java b/src/main/java/com/actiontech/dble/server/response/ShowTables.java index 61879ff7f0..bf0d647fbe 100644 --- a/src/main/java/com/actiontech/dble/server/response/ShowTables.java +++ b/src/main/java/com/actiontech/dble/server/response/ShowTables.java @@ -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; @@ -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(); }