mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add stat PreparedStatementCacheDeleteCount
This commit is contained in:
@@ -187,6 +187,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
protected final AtomicLong preparedStatementCount = new AtomicLong();
|
||||
protected final AtomicLong closedPreparedStatementCount = new AtomicLong();
|
||||
protected final AtomicLong cachedPreparedStatementCount = new AtomicLong();
|
||||
protected final AtomicLong cachedPreparedStatementDeleteCount = new AtomicLong();
|
||||
|
||||
protected final Histogram transactionHistogram = new Histogram(
|
||||
10,
|
||||
@@ -254,6 +255,14 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
public void decrementCachedPreparedStatementCount() {
|
||||
cachedPreparedStatementCount.decrementAndGet();
|
||||
}
|
||||
|
||||
public void incrementCachedPreparedStatementDeleteCount() {
|
||||
cachedPreparedStatementDeleteCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public long getCachedPreparedStatementDeleteCount() {
|
||||
return cachedPreparedStatementDeleteCount.get();
|
||||
}
|
||||
|
||||
public long getCachedPreparedStatementCount() {
|
||||
return cachedPreparedStatementCount.get();
|
||||
|
||||
@@ -140,4 +140,6 @@ public interface DruidAbstractDataSourceMBean {
|
||||
long getClosedPreparedStatementCount();
|
||||
|
||||
long getCachedPreparedStatementCount();
|
||||
|
||||
long getCachedPreparedStatementDeleteCount();
|
||||
}
|
||||
|
||||
@@ -180,6 +180,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
closedPreparedStatementCount.set(0);
|
||||
preparedStatementCount.set(0);
|
||||
transactionHistogram.reset();
|
||||
cachedPreparedStatementDeleteCount.set(0);
|
||||
}
|
||||
|
||||
public boolean isEnable() {
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.alibaba.druid.pool.xa;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import javax.sql.XAConnection;
|
||||
import javax.transaction.xa.XAException;
|
||||
import javax.transaction.xa.XAResource;
|
||||
import javax.transaction.xa.Xid;
|
||||
|
||||
import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
import com.alibaba.druid.pool.ConnectionHolder;
|
||||
import com.alibaba.druid.pool.PoolableConnection;
|
||||
|
||||
public class XAPoolableConnection extends PoolableConnection implements XAResource {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(XAPoolableConnection.class);
|
||||
|
||||
protected final XAConnection xaConnection;
|
||||
|
||||
protected final XAResource xaResource;
|
||||
|
||||
protected Xid currentXid;
|
||||
|
||||
private Lock stateLock = new ReentrantLock();
|
||||
|
||||
public XAPoolableConnection(ConnectionHolder holder, XAConnection xaConnection) throws SQLException{
|
||||
super(holder);
|
||||
|
||||
this.xaConnection = xaConnection;
|
||||
this.xaResource = xaConnection.getXAResource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit(Xid xid, boolean onePhase) throws XAException {
|
||||
xaResource.commit(xid, onePhase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end(Xid xid, int arg1) throws XAException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forget(Xid xid) throws XAException {
|
||||
xaResource.forget(xid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransactionTimeout() throws XAException {
|
||||
return xaResource.getTransactionTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameRM(XAResource other) throws XAException {
|
||||
return xaResource.isSameRM(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int prepare(Xid xid) throws XAException {
|
||||
return xaResource.prepare(xid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Xid[] recover(int flag) throws XAException {
|
||||
return xaResource.recover(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(Xid xid) throws XAException {
|
||||
xaResource.rollback(xid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setTransactionTimeout(int seconds) throws XAException {
|
||||
return xaResource.setTransactionTimeout(seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Xid xid, int flags) throws XAException {
|
||||
if (holder == null) {
|
||||
throw new XAException("connection is closed");
|
||||
}
|
||||
|
||||
try {
|
||||
xaResource.start(xid, flags);
|
||||
} catch (XAException e) {
|
||||
// JBAS-3336 Connections that fail in enlistment should not be returned
|
||||
// to the pool
|
||||
if (isFailedXA(e.errorCode)) {
|
||||
LOG.error("Start transaction failed for " + this);
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
stateLock.lock();
|
||||
try {
|
||||
currentXid = xid;
|
||||
} finally {
|
||||
stateLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isFailedXA(int errorCode) {
|
||||
return (errorCode == XAException.XAER_RMERR || errorCode == XAException.XAER_RMFAIL);
|
||||
}
|
||||
}
|
||||
@@ -200,6 +200,8 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
|
||||
map.put("RollbackCount", dataSource.getRollbackCount());
|
||||
map.put("LastError", JMXUtils.getErrorCompositeData(dataSource.getLastError()));
|
||||
map.put("LastCreateError", JMXUtils.getErrorCompositeData(dataSource.getCreateError()));
|
||||
map.put("PreparedStatementCacheDeleteCount", dataSource.getCachedPreparedStatementDeleteCount());
|
||||
map.put("Version", dataSource.getVersion());
|
||||
|
||||
return new CompositeDataSupport(rowType, map);
|
||||
}
|
||||
@@ -220,7 +222,8 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
|
||||
SimpleType.BOOLEAN, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.STRING, //
|
||||
SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, //
|
||||
SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG//
|
||||
, SimpleType.LONG, SimpleType.LONG, JMXUtils.getThrowableCompositeType(), JMXUtils.getThrowableCompositeType()
|
||||
, SimpleType.LONG, SimpleType.LONG, JMXUtils.getThrowableCompositeType(), JMXUtils.getThrowableCompositeType(), SimpleType.LONG //
|
||||
, SimpleType.STRING
|
||||
//
|
||||
};
|
||||
|
||||
@@ -238,7 +241,8 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
|
||||
"RemoveAbandonedCount", //
|
||||
"NotEmptyWaitCount", "NotEmptyWaitNanos", "ErrorCount", "ReusePreparedStatementCount",
|
||||
"StartTransactionCount", //
|
||||
"CommitCount", "RollbackCount", "LastError", "LastCreateError"
|
||||
"CommitCount", "RollbackCount", "LastError", "LastCreateError", "PreparedStatementCacheDeleteCount" //
|
||||
, "Version"
|
||||
//
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user