Skip to content

Commit

Permalink
limit size of slow query log queue. (#2514)
Browse files Browse the repository at this point in the history
Signed-off-by: dcy <dcy10000@gmail.com>
(cherry picked from commit 4ac2a18)
  • Loading branch information
dcy10000 authored and LUAgam committed Jan 31, 2023
1 parent 857764f commit 695d9e8
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SlowQueryLogProcessor extends Thread {
"Time Id Command Argument";

public SlowQueryLogProcessor() {
this.queue = new LinkedBlockingQueue<>();
this.queue = new LinkedBlockingQueue<>(2000);
this.store = new DailyRotateLogStore(SystemConfig.getInstance().getSlowLogBaseDir(), SystemConfig.getInstance().getSlowLogBaseName(), "log", 64, FILE_HEADER);
scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("SlowLogFlushTimerScheduler-%d").build());
}
Expand Down Expand Up @@ -120,7 +120,14 @@ public void run() {
public void putSlowQueryLog(ShardingService service, TraceResult log) {
if (log.isCompleted() && log.getOverAllMilliSecond() > SlowQueryLog.getInstance().getSlowTime()) {
SlowQueryLogEntry logEntry = new SlowQueryLogEntry(service.getExecuteSql(), log, service.getUser(), service.getConnection().getHost(), service.getConnection().getId());
queue.add(logEntry);
try {
final boolean enQueue = queue.offer(logEntry, 3, TimeUnit.SECONDS);
if (!enQueue) {
LOGGER.warn("slow log queue has so many item. Discard log entry: {} ", logEntry.toString());
}
} catch (InterruptedException e) {
LOGGER.info(" ", e);
}
}
}
}

0 comments on commit 695d9e8

Please sign in to comment.