set default timeout to 15 seconds

main 1.4.4
Jörg Prante 11 months ago
parent 52097a4468
commit a7ac905757

@ -1,5 +1,5 @@
group = org.xbib
name = database
version = 1.4.3
version = 1.4.4
org.gradle.warning.mode = ALL

@ -176,7 +176,7 @@ public class Pool implements BagStateListener {
public void quietlyCloseConnection(Connection connection, String closureReason) {
if (connection != null) {
try {
logger.log(Level.FINE, () -> MessageFormat.format("{0} closing connection {1} {2}", poolName, connection, closureReason));
logger.log(Level.FINE, () -> MessageFormat.format("{0} closing connection {1} {2} with a timeout of 15 seconds", poolName, connection, closureReason));
try (connection) {
setNetworkTimeout(connection, TimeUnit.SECONDS.toMillis(15));
} catch (SQLException e) {

@ -92,14 +92,14 @@ public class PoolConfig {
this.properties = properties;
this.minIdle = -1;
this.maxPoolSize = -1;
this.maxLifetime = TimeUnit.MINUTES.toMillis(30);
this.connectionTimeout = TimeUnit.SECONDS.toMillis(30);
this.validationTimeout = TimeUnit.SECONDS.toMillis(5);
this.maxLifetime = TimeUnit.MINUTES.toMillis(60);
this.connectionTimeout = TimeUnit.SECONDS.toMillis(15);
this.validationTimeout = TimeUnit.SECONDS.toMillis(15);
this.idleTimeout = TimeUnit.MINUTES.toMillis(1);
this.initializationFailTimeout = -1;
this.isAutoCommit = true; // JDBC convention
this.aliveBypassWindowMs = TimeUnit.MILLISECONDS.toMillis(500);
this.housekeepingPeriodMs = TimeUnit.SECONDS.toMillis(30);
this.housekeepingPeriodMs = TimeUnit.SECONDS.toMillis(60);
}
/**
@ -639,13 +639,11 @@ public class PoolConfig {
}
}
if (connectionTimeout < 250) {
logger.log(Level.WARNING, "connectionTimeout is less than 250ms, setting to ms: " +
poolName + " " + TimeUnit.MILLISECONDS.toMillis(250));
logger.log(Level.WARNING, poolName + " connectionTimeout is less than 250ms, setting to " + TimeUnit.MILLISECONDS.toMillis(250) + " ms");
connectionTimeout = TimeUnit.MILLISECONDS.toMillis(250);
}
if (validationTimeout < 250) {
logger.log(Level.WARNING, "validationTimeout is less than 250ms, setting to ms" +
poolName + " " + TimeUnit.MILLISECONDS.toMillis(250));
logger.log(Level.WARNING, poolName + " validationTimeout is less than 250ms, setting to ms" + TimeUnit.MILLISECONDS.toMillis(250) + " ms");
validationTimeout = TimeUnit.MILLISECONDS.toMillis(250);
}
if (maxPoolSize < 1) {
@ -655,14 +653,13 @@ public class PoolConfig {
minIdle = maxPoolSize;
}
if (idleTimeout + TimeUnit.SECONDS.toMillis(1) > maxLifetime && maxLifetime > 0 && minIdle < maxPoolSize) {
logger.log(Level.WARNING, "idleTimeout is close to or more than maxLifetime, disabling it:" + poolName);
logger.log(Level.WARNING, poolName + " idleTimeout is close to or more than maxLifetime, disabling it");
idleTimeout = 0;
} else if (idleTimeout != 0 && idleTimeout < TimeUnit.SECONDS.toMillis(10) && minIdle < maxPoolSize) {
logger.log(Level.WARNING, "idleTimeout is less than 10s, setting to default ms: " +
poolName + " " + TimeUnit.SECONDS.toMillis(10));
logger.log(Level.WARNING, poolName + " idleTimeout is less than 10s, setting to default " + TimeUnit.SECONDS.toMillis(10) + " ms");
idleTimeout = TimeUnit.SECONDS.toMillis(10);
} else if (idleTimeout != TimeUnit.SECONDS.toMillis(10) && idleTimeout != 0 && minIdle == maxPoolSize) {
logger.log(Level.WARNING, "idleTimeout has been set but has no effect because the pool is operating as a fixed size pool: " + poolName);
logger.log(Level.WARNING, poolName + " idleTimeout has been set but has no effect because the pool is operating as a fixed size pool");
}
}

@ -125,7 +125,7 @@ public interface Database extends Supplier<Database> {
* Probe the underlying connection.
* @return true if database has executed a probe query successfully, false if not
*/
boolean probe() throws SQLException;
boolean probe(int seconds) throws SQLException;
Options options();
@ -280,5 +280,5 @@ public interface Database extends Supplier<Database> {
* @param consumer a consumer for the queue table data column or null
* @throws SQLException if rollback fails
*/
public void consumeQueue(String table, String channel, int limit, Consumer<String> consumer) throws SQLException;
void consumeQueue(String table, String channel, int limit, Consumer<String> consumer) throws SQLException;
}

@ -140,9 +140,8 @@ public class DatabaseImpl implements Database {
}
@Override
public boolean probe() throws SQLException {
// use a standard timeout of 5 seconds
return connection != null && connection.isValid(5);
public boolean probe(int seconds) throws SQLException {
return connection != null && connection.isValid(seconds);
}
@Override

@ -320,15 +320,15 @@ public final class DatabaseProvider implements Supplier<Database>, Closeable {
return database;
}
public boolean check() {
public boolean check(int seconds) {
Metric metric = new Metric(logger.isLoggable(Level.FINE));
boolean probe = false;
try {
if (database != null) {
probe = database.probe();
probe = database.probe(seconds);
} else {
get();
probe = database.probe();
probe = database.probe(seconds);
}
} catch (SQLException | RuntimeException e) {
metric.checkpoint("fail", e.getMessage());

@ -20,7 +20,7 @@ public class OptionsDefault implements Options {
@Override
public int timeoutSeconds() {
return 5;
return 15;
}
@Override

@ -77,7 +77,7 @@ public abstract class CommonTest {
dbp = createDatabaseProvider(new OptionsOverride() {
});
db = dbp.get();
if (!db.probe()) {
if (!db.probe(15)) {
fail();
}
db.dropTableQuietly(TEST_TABLE_NAME);

Loading…
Cancel
Save