From 57126d2903f62cc08de163b70565d611b6358fd3 Mon Sep 17 00:00:00 2001 From: "tomas.martins" Date: Wed, 15 Dec 2021 15:56:29 +0000 Subject: [PATCH] 286:AbstractDatabaseEngine function getConnection, fix debug messages and fix number of attemps executed --- .../engine/AbstractDatabaseEngine.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/feedzai/commons/sql/abstraction/engine/AbstractDatabaseEngine.java b/src/main/java/com/feedzai/commons/sql/abstraction/engine/AbstractDatabaseEngine.java index 166f871a..e8e20c4f 100644 --- a/src/main/java/com/feedzai/commons/sql/abstraction/engine/AbstractDatabaseEngine.java +++ b/src/main/java/com/feedzai/commons/sql/abstraction/engine/AbstractDatabaseEngine.java @@ -371,14 +371,8 @@ public synchronized Connection getConnection() throws RetryLimitExceededExceptio } try { - if (maximumNumberOfTries > 0) { - if (retries == (maximumNumberOfTries / 2) || retries == (maximumNumberOfTries - 1)) { - logger.error("The connection to the database was lost. Remaining retries: {}", (maximumNumberOfTries - retries)); - notificationLogger.error("The connection to the database was lost. Remaining retries: {}", (maximumNumberOfTries - retries)); - } else { - logger.debug("Retrying ({}/{}) in {} seconds...", retries, maximumNumberOfTries, TimeUnit.MILLISECONDS.toSeconds(retryInterval)); - } + logger.debug("Retrying ({}/{}) in {} seconds...", retries, maximumNumberOfTries, TimeUnit.MILLISECONDS.toSeconds(retryInterval)); } else { logger.debug("Retry number {} in {} seconds...", retries, TimeUnit.MILLISECONDS.toSeconds(retryInterval)); if (retries % 10 == 0) { @@ -388,9 +382,7 @@ public synchronized Connection getConnection() throws RetryLimitExceededExceptio Thread.sleep(retryInterval); connect(); // this sets the new object. - // recover state. - try { recover(); } catch (final Exception e) { @@ -406,7 +398,11 @@ public synchronized Connection getConnection() throws RetryLimitExceededExceptio } catch (final SQLException ex) { logger.debug("Connection failed."); - if (maximumNumberOfTries > 0 && retries > maximumNumberOfTries) { + if (retries == (maximumNumberOfTries / 2) || retries == (maximumNumberOfTries - 1)) { + logger.error("The connection to the database was lost. Remaining retries: {}", (maximumNumberOfTries - retries)); + notificationLogger.error("The connection to the database was lost. Remaining retries: {}", (maximumNumberOfTries - retries)); + } + else if (maximumNumberOfTries > 0 && retries >= maximumNumberOfTries) { throw new RetryLimitExceededException("Maximum number of retries for a connection exceeded.", ex); }