Commit 5ee64ebf authored by Andre Freyssinet's avatar Andre Freyssinet

Fixes an error in the calculation of the delay between 2 connection attempts.

parent 40b638d5
......@@ -482,35 +482,40 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
lastexc = null;
completed = true;
} catch (SQLException sqle) {
if (logmon.isLoggable(BasicLevel.DEBUG))
logmon.log(BasicLevel.WARN, "DBTransaction, commit: try to reconnect", sqle);
else
logmon.log(BasicLevel.WARN, "DBTransaction, commit: try to reconnect - " + sqle.getMessage());
lastexc = sqle;
retry += 1;
long time = System.currentTimeMillis();
if (startRetry == 0L) startRetry = time;
if ((connectRetryCount > 0) && (retry > connectRetryCount)) {
logmon.log(BasicLevel.WARN, "DBTransaction, commit: maximum number of reconnection attempts reached: " + connectRetryCount);
break;
}
if ((connectRetryMaxPeriod > 0L) && ((time - startRetry) > connectRetryMaxPeriod)) {
logmon.log(BasicLevel.WARN, "DBTransaction, commit: reconnection period exceeded: " + connectRetryMaxPeriod);
break;
}
if ((connectRetryCount > 0) && (retry > connectRetryCount)) break;
if ((connectRetryMaxPeriod > 0L) && ((time - startRetry) > connectRetryMaxPeriod)) break;
if (logmon.isLoggable(BasicLevel.DEBUG))
logmon.log(BasicLevel.WARN, "DBTransaction, commit: try to reconnect", sqle);
else
logmon.log(BasicLevel.WARN, "DBTransaction, commit: try to reconnect - " + sqle.getMessage());
try {
if (lastTry == 0L) {
// It's the first retry do not wait.
lastTry = time;
} else {
// Wait for at least configured delay
// Do not wait the 1st time.
if (lastTry != 0L) {
// Wait for at least configured delay since last attempt to connect
long delay = connectRetryMinDelay - (time - lastTry);
lastTry = time;
try {
if (delay > 0) Thread.sleep(delay);
} catch (InterruptedException exc) {}
}
lastTry = System.currentTimeMillis();
connectDB();
createPreparedStatement();
} catch (IOException exc) {}
} catch (IOException exc) {
logmon.log(BasicLevel.INFO, "DBTransaction, commit: cannot reconnect" + exc.getMessage());
}
}
} while (!completed);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment