Skip to content

Commit

Permalink
protect pool entry
Browse files Browse the repository at this point in the history
  • Loading branch information
nitincchauhan committed Sep 17, 2015
1 parent 0069a4e commit e3167d4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 34 deletions.
Expand Up @@ -21,12 +21,9 @@
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.zaxxer.hikari.pool.PoolEntry;
import com.zaxxer.hikari.util.ClockSource;

public final class CodaHaleMetricsTracker extends MetricsTracker
{
private static final ClockSource clockSource = ClockSource.INSTANCE;

private final String poolName;
private final Timer connectionObtainTimer;
private final Histogram connectionUsage;
Expand Down Expand Up @@ -95,7 +92,7 @@ public Context recordConnectionRequest()
@Override
public void recordConnectionUsage(final PoolEntry bagEntry)
{
connectionUsage.update(clockSource.elapsedMillis(bagEntry.lastOpenTime));
connectionUsage.update(bagEntry.getElapsedMillis());
}

public Timer getConnectionAcquisitionTimer()
Expand All @@ -122,12 +119,5 @@ public void stop()
{
innerContext.stop();
}

/** {@inheritDoc} */
@Override
public void setConnectionLastOpen(final PoolEntry bagEntry, final long now)
{
bagEntry.lastOpenTime = now;
}
}
}
12 changes: 0 additions & 12 deletions src/main/java/com/zaxxer/hikari/metrics/MetricsTracker.java
Expand Up @@ -17,7 +17,6 @@
package com.zaxxer.hikari.metrics;

import com.zaxxer.hikari.pool.PoolEntry;
import com.zaxxer.hikari.util.ClockSource;

/**
* This class only supports realtime, not historical metrics.
Expand Down Expand Up @@ -59,16 +58,5 @@ public void stop()
{
// do nothing
}

/**
* Set the lastOpenTime on the provided bag entry.
*
* @param bagEntry the bag entry
* @param now the last open timestamp from {@link ClockSource#currentTime()}
*/
public void setConnectionLastOpen(final PoolEntry bagEntry, final long now)
{
// do nothing
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/pool/HikariPool.java
Expand Up @@ -171,7 +171,7 @@ public final Connection getConnection(final long hardTimeout) throws SQLExceptio
timeout = hardTimeout - clockSource.elapsedMillis(startTime, now);
}
else {
metricsContext.setConnectionLastOpen(poolEntry, now);
poolEntry.lastOpenTime = now;
metricsContext.stop();
return poolEntry.createProxyConnection(leakTask.start(poolEntry), now);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/pool/PoolBase.java
Expand Up @@ -29,7 +29,7 @@

abstract class PoolBase
{
protected final Logger LOGGER = LoggerFactory.getLogger(PoolBase.class);
private final Logger LOGGER = LoggerFactory.getLogger(PoolBase.class);
protected final HikariConfig config;
protected final String poolName;
protected long connectionTimeout;
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/com/zaxxer/hikari/pool/PoolEntry.java
Expand Up @@ -37,11 +37,11 @@ public final class PoolEntry implements IConcurrentBagEntry
{
private static final Logger LOGGER = LoggerFactory.getLogger(PoolEntry.class);

public Connection connection;
public long lastAccess;
Connection connection;
long lastAccess;

public volatile long lastOpenTime;
public volatile boolean evict;
volatile long lastOpenTime;
volatile boolean evict;

private final FastList<Statement> openStatements;
private final PoolBase poolBase;
Expand All @@ -63,7 +63,7 @@ public final class PoolEntry implements IConcurrentBagEntry
*
* @param lastAccess last access time-stamp
*/
public void recycle(final long lastAccess)
void recycle(final long lastAccess)
{
this.lastAccess = lastAccess;
poolBase.releaseConnection(this);
Expand All @@ -72,7 +72,7 @@ public void recycle(final long lastAccess)
/**
* @param endOfLife
*/
public void setFutureEol(final ScheduledFuture<?> endOfLife)
void setFutureEol(final ScheduledFuture<?> endOfLife)
{
this.endOfLife = endOfLife;
}
Expand All @@ -92,7 +92,7 @@ public String getPoolName()
return poolBase.getPoolName();
}

public Connection getConnection()
Connection getConnection()
{
return connection;
}
Expand All @@ -107,16 +107,22 @@ public boolean isEvicted()
return evict;
}

public void evict()
void evict()
{
this.evict = true;
}

public FastList<Statement> getStatementsList()
FastList<Statement> getStatementsList()
{
return openStatements;
}

/** Returns millis since lastOpenTime */
public long getElapsedMillis()
{
return ClockSource.INSTANCE.elapsedMillis(lastOpenTime);
}

// ***********************************************************************
// IConcurrentBagEntry methods
// ***********************************************************************
Expand Down

0 comments on commit e3167d4

Please sign in to comment.