From b6e6812d9d43d2f9fd9d401f7aa927be6e9729aa Mon Sep 17 00:00:00 2001 From: DigitalSonic Date: Tue, 5 Nov 2019 18:00:00 +0800 Subject: [PATCH] Update RandomDataSourceValidateThread.java add some logs --- .../selector/RandomDataSourceValidateThread.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceValidateThread.java b/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceValidateThread.java index 5a64b5c856..64b55ce50c 100644 --- a/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceValidateThread.java +++ b/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceValidateThread.java @@ -58,7 +58,10 @@ public class RandomDataSourceValidateThread implements Runnable { */ public static void logSuccessTime(DataSourceProxy dataSource) { if (dataSource != null && !StringUtils.isEmpty(dataSource.getName())) { - SUCCESS_TIMES.put(dataSource.getName(), System.currentTimeMillis()); + String name = dataSource.getName(); + long time = System.currentTimeMillis(); + LOG.debug("Log successTime [" + time + "] for " + name); + SUCCESS_TIMES.put(name, time); } } @@ -115,7 +118,7 @@ public class RandomDataSourceValidateThread implements Runnable { private void checkAllDataSources() { Map dataSourceMap = selector.getDataSourceMap(); List> tasks = new ArrayList>(); - + LOG.debug("Checking all DataSource."); for (final Map.Entry e : dataSourceMap.entrySet()) { if (!(e.getValue() instanceof DruidDataSource)) { continue; @@ -136,6 +139,7 @@ public class RandomDataSourceValidateThread implements Runnable { return true; } + LOG.debug("Start checking " + key + "."); boolean flag = check(key, dataSource); if (flag) { @@ -164,10 +168,12 @@ public class RandomDataSourceValidateThread implements Runnable { private boolean isSkipChecking(String key, DruidDataSource dataSource) { Long lastSuccessTime = SUCCESS_TIMES.get(dataSource.getName()); Long lastCheckTime = lastCheckTimes.get(dataSource.getName()); - + long currentTime = System.currentTimeMillis(); + LOG.debug("Connection=" + key + ", lastSuccessTime=" + lastSuccessTime + + ", lastCheckTime=" + lastCheckTime + ", currentTime=" + currentTime); return lastSuccessTime != null && lastCheckTime != null - && (System.currentTimeMillis() - lastSuccessTime) <= checkingIntervalSeconds * 1000 - && (System.currentTimeMillis() - lastCheckTime) <= 5 * checkingIntervalSeconds * 1000 + && (currentTime - lastSuccessTime) <= checkingIntervalSeconds * 1000 + && (currentTime - lastCheckTime) <= 5 * checkingIntervalSeconds * 1000 && (!errorCounts.containsKey(key) || errorCounts.get(key) < 1); }