mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
DruidDataSource add keepAlive support.
This commit is contained in:
@@ -119,8 +119,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
private long notEmptyWaitNanos = 0L;
|
||||
|
||||
private int keepAliveCheckCount = 0;
|
||||
private final AtomicInteger keepAliveCheckOkCount = new AtomicInteger();
|
||||
private final AtomicInteger keepAliveCheckErrCount = new AtomicInteger();
|
||||
|
||||
private int activePeak = 0;
|
||||
private long activePeakTime = 0;
|
||||
@@ -1747,6 +1745,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
value.setWaitThreadCount(lock.getWaitQueueLength(notEmpty));
|
||||
value.setNotEmptyWaitCount(this.notEmptyWaitCount);
|
||||
value.setNotEmptyWaitNanos(this.notEmptyWaitNanos);
|
||||
value.setKeepAliveCheckCount(this.keepAliveCheckCount);
|
||||
|
||||
// reset
|
||||
this.poolingPeak = 0;
|
||||
@@ -1755,6 +1754,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
this.activePeakTime = 0;
|
||||
this.connectCount = 0;
|
||||
this.closeCount = 0;
|
||||
this.keepAliveCheckCount = 0;
|
||||
|
||||
this.notEmptyWaitCount = 0;
|
||||
this.notEmptyWaitNanos = 0;
|
||||
@@ -2365,6 +2365,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
if (keepAliveCount > 0) {
|
||||
this.getDataSourceStat().addKeepAliveCheckCount(keepAliveCount);
|
||||
for (int i = 0; i < keepAliveCount; ++i) {
|
||||
DruidConnectionHolder holer = keepAliveConnections[i];
|
||||
Connection connection = holer.getConnection();
|
||||
@@ -2383,9 +2384,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
if (validate) {
|
||||
holer.setLastActiveTimeMillis(System.currentTimeMillis());
|
||||
put(holer);
|
||||
keepAliveCheckOkCount.incrementAndGet();
|
||||
} else {
|
||||
keepAliveCheckErrCount.incrementAndGet();
|
||||
JdbcUtils.close(connection);
|
||||
}
|
||||
}
|
||||
@@ -2699,6 +2698,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
map.put("CreateErrorCount", this.getCreateErrorCount());
|
||||
map.put("DiscardCount", this.getDiscardCount());
|
||||
|
||||
|
||||
return map;
|
||||
} catch (JMException ex) {
|
||||
throw new IllegalStateException("getStatData error", ex);
|
||||
@@ -2797,6 +2797,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
dataMap.put("RemoveAbandoned", this.isRemoveAbandoned());
|
||||
dataMap.put("ClobOpenCount", this.getDataSourceStat().getClobOpenCount());
|
||||
dataMap.put("BlobOpenCount", this.getDataSourceStat().getBlobOpenCount());
|
||||
dataMap.put("KeepAliveCheckCount", this.getDataSourceStat().getKeepAliveCheckCount());
|
||||
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
@@ -234,6 +234,10 @@ public class DruidDataSourceStatLoggerImpl extends DruidDataSourceStatLoggerAdap
|
||||
map.put("sqlList", sqlList);
|
||||
}
|
||||
|
||||
if (statValue.getKeepAliveCheckCount() > 0) {
|
||||
map.put("keepAliveCheckCount", statValue.getKeepAliveCheckCount());
|
||||
}
|
||||
|
||||
String text = JSONUtils.toJSONString(map);
|
||||
|
||||
log(text);
|
||||
|
||||
@@ -117,6 +117,9 @@ public class DruidDataSourceStatValue {
|
||||
@MField(aggregate = AggregateType.Sum)
|
||||
protected long startTransactionCount;
|
||||
|
||||
@MField(aggregate = AggregateType.Sum)
|
||||
protected long keepAliveCheckCount;
|
||||
|
||||
// protected long[] transactionHistogram;
|
||||
protected long[] connectionHoldTimeHistogram;
|
||||
|
||||
@@ -563,4 +566,11 @@ public class DruidDataSourceStatValue {
|
||||
this.poolingPeakTime = poolingPeakTime;
|
||||
}
|
||||
|
||||
public long getKeepAliveCheckCount() {
|
||||
return keepAliveCheckCount;
|
||||
}
|
||||
|
||||
public void setKeepAliveCheckCount(long keepAliveCheckCount) {
|
||||
this.keepAliveCheckCount = keepAliveCheckCount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ public class JdbcDataSourceStat implements JdbcDataSourceStatMBean {
|
||||
private final AtomicLong clobOpenCount = new AtomicLong();
|
||||
|
||||
private final AtomicLong blobOpenCount = new AtomicLong();
|
||||
private final AtomicLong keepAliveCheckCount = new AtomicLong();
|
||||
|
||||
private boolean resetStatEnable = true;
|
||||
|
||||
@@ -497,4 +498,15 @@ public class JdbcDataSourceStat implements JdbcDataSourceStatMBean {
|
||||
blobOpenCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public long getKeepAliveCheckCount() {
|
||||
return keepAliveCheckCount.get();
|
||||
}
|
||||
|
||||
public long getKeepAliveCheckCountAndReset() {
|
||||
return keepAliveCheckCount.getAndSet(0);
|
||||
}
|
||||
|
||||
public void addKeepAliveCheckCount(long delta) {
|
||||
keepAliveCheckCount.addAndGet(delta);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user