Skip to content

Commit

Permalink
include the server thread id (a.k.a connection id) in certain importa…
Browse files Browse the repository at this point in the history
…nt log messages
  • Loading branch information
jaikiran committed Aug 24, 2021
1 parent 0b78458 commit e0a3fc2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ public void close() {

/** Force closes socket and stream readers/writers. */
public void abort() {
if (logger.isDebugEnabled()) {
logger.debug("aborting connection {}", serverThreadId);
}
this.explicitClosed = true;

boolean lockStatus = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,8 @@ public boolean ping() throws SQLException {

} catch (IOException e) {
connected = false;
throw new SQLNonTransientConnectionException("Could not ping: " + e.getMessage(), "08000", e);
throw new SQLNonTransientConnectionException(
"Could not ping connection " + serverThreadId + " : " + e.getMessage(), "08000", e);
} finally {
lock.unlock();
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/mariadb/jdbc/internal/util/pool/Pool.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,15 @@ private void removeIdleTimeoutConnection() {
}

if (shouldBeReleased && idleConnections.remove(item)) {

final long connId = item.getConnection().getServerThreadId();
totalConnection.decrementAndGet();
silentCloseConnection(item);
addConnectionRequest();
if (logger.isDebugEnabled()) {
logger.debug(
"pool {} connection removed due to inactivity (total:{}, active:{}, pending:{})",
"pool {} connection {} removed due to inactivity (total:{}, active:{}, pending:{})",
poolTag,
connId,
totalConnection.get(),
getActiveConnections(),
pendingRequestNumber.get());
Expand Down Expand Up @@ -234,8 +235,9 @@ private void addConnection() throws SQLException {

if (logger.isDebugEnabled()) {
logger.debug(
"pool {} new physical connection created (total:{}, active:{}, pending:{})",
"pool {} new physical connection {} created (total:{}, active:{}, pending:{})",
poolTag,
connection.getServerThreadId(),
totalConnection.get(),
getActiveConnections(),
pendingRequestNumber.get());
Expand Down Expand Up @@ -266,6 +268,7 @@ private MariaDbPooledConnection getIdleConnection(long timeout, TimeUnit timeUni

if (item != null) {
MariaDbConnection connection = item.getConnection();
final long connId = connection.getServerThreadId();
try {
if (TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - item.getLastUsed().get())
> options.poolValidMinDelay) {
Expand All @@ -292,8 +295,9 @@ private MariaDbPooledConnection getIdleConnection(long timeout, TimeUnit timeUni
addConnectionRequest();
if (logger.isDebugEnabled()) {
logger.debug(
"pool {} connection removed from pool due to failed validation (total:{}, active:{}, pending:{})",
"pool {} connection {} removed from pool due to failed validation (total:{}, active:{}, pending:{})",
poolTag,
connId,
totalConnection.get(),
getActiveConnections(),
pendingRequestNumber.get());
Expand Down

0 comments on commit e0a3fc2

Please sign in to comment.