Tweak HikariCP config to hopefully improve recovery from database downtime (#2223, #2084)

This commit is contained in:
Luck 2020-05-09 18:19:49 +01:00
parent 10fbc24f43
commit 665c53093a
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 17 additions and 11 deletions

View File

@ -37,6 +37,7 @@ import java.sql.Statement;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public abstract class HikariConnectionFactory implements ConnectionFactory {
@ -77,7 +78,13 @@ public abstract class HikariConnectionFactory implements ConnectionFactory {
config.setPoolName("luckperms-hikari");
appendConfigurationInfo(config);
appendProperties(config, new HashMap<>(this.configuration.getProperties()));
Map<String, String> properties = new HashMap<>(this.configuration.getProperties());
// https://github.com/brettwooldridge/HikariCP/wiki/Rapid-Recovery
properties.putIfAbsent("socketTimeout", String.valueOf(TimeUnit.SECONDS.toMillis(30)));
appendProperties(config, properties);
config.setMaximumPoolSize(this.configuration.getMaxPoolSize());
config.setMinimumIdle(this.configuration.getMinIdleConnections());

View File

@ -50,10 +50,6 @@ public class MariaDbConnectionFactory extends HikariConnectionFactory {
@Override
protected void appendProperties(HikariConfig config, Map<String, String> properties) {
if (properties.isEmpty()) {
return;
}
String propertiesString = properties.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(";"));
// kinda hacky. this will call #setProperties on the datasource, which will append these options

View File

@ -49,15 +49,18 @@ public class MySqlConnectionFactory extends HikariConnectionFactory {
@Override
protected void appendProperties(HikariConfig config, Map<String, String> properties) {
// https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
properties.putIfAbsent("cachePrepStmts", "true");
properties.putIfAbsent("alwaysSendSetIsolation", "false");
properties.putIfAbsent("cacheServerConfiguration", "true");
properties.putIfAbsent("elideSetAutoCommits", "true");
properties.putIfAbsent("useLocalSessionState", "true");
properties.putIfAbsent("useServerPrepStmts", "true");
properties.putIfAbsent("prepStmtCacheSize", "250");
properties.putIfAbsent("prepStmtCacheSqlLimit", "2048");
properties.putIfAbsent("useServerPrepStmts", "true");
properties.putIfAbsent("useLocalSessionState", "true");
properties.putIfAbsent("rewriteBatchedStatements", "true");
properties.putIfAbsent("cacheResultSetMetadata", "true");
properties.putIfAbsent("cacheServerConfiguration", "true");
properties.putIfAbsent("elideSetAutoCommits", "true");
properties.putIfAbsent("maintainTimeStats", "false");
properties.putIfAbsent("alwaysSendSetIsolation", "false");
properties.putIfAbsent("cacheCallableStmts", "true");
// append configurable properties