Skip to content

Commit f6b3acb

Browse files
committed
DS-2259: Database - fix database settings initialization and increase statement timeout.
Signed-off-by: mchrza <maximilian.chrzan@here.com>
1 parent 500c38f commit f6b3acb

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

  • xyz-jobs/xyz-job-steps/src/main/java/com/here/xyz/jobs/steps/execution/db

xyz-jobs/xyz-job-steps/src/main/java/com/here/xyz/jobs/steps/execution/db/Database.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@
5555
import software.amazon.awssdk.services.rds.model.DBCluster;
5656

5757
public class Database extends ExecutionResource {
58-
private static final int STATEMENT_TIMEOUT = 100;
58+
private static final int STATEMENT_TIMEOUT = 895; //seconds - has to greater than the query timeouts
59+
private static final int DB_CHECKOUT_TIMEOUT_MS = 20_000;
60+
private static final int DB_ACQUIRE_RETRY_DELAY_MS = 5_000;
61+
private static final int DB_ACQUIRE_RETRY_ATTEMPTS = 10;
62+
private static final int DB_ACQUIRE_INCREMENT = 3;
63+
private static final int DB_MAX_POOL_SIZE = 10;
5964
private static final List<ScriptResourcePath> SCRIPT_RESOURCE_PATHS = List.of(new ScriptResourcePath("/sql", "jobs", "common"), new ScriptResourcePath("/jobs", "jobs"));
6065
private static final Logger logger = LogManager.getLogger();
6166
private static final float DB_MAX_JOB_UTILIZATION_PERCENTAGE = 0.6f;
@@ -107,12 +112,23 @@ static void closeAll() {
107112

108113
DatabaseSettings getDatabaseSettings() {
109114
if (dbSettings == null)
110-
dbSettings = new RestrictedDatabaseSettings(getName(), connectorDbSettingsMap)
111-
.withApplicationName("JobFramework")
112-
.withScriptResourcePaths(SCRIPT_RESOURCE_PATHS);
115+
dbSettings = applyRuntimeDbSettings(new RestrictedDatabaseSettings(getName(), connectorDbSettingsMap)
116+
.withApplicationName("JobFramework"));
113117
return dbSettings;
114118
}
115119

120+
private static <T extends DatabaseSettings> T applyRuntimeDbSettings(T settings) {
121+
settings
122+
.withStatementTimeoutSeconds(STATEMENT_TIMEOUT)
123+
.withDbCheckoutTimeout(DB_CHECKOUT_TIMEOUT_MS)
124+
.withDbAcquireRetryDelay(DB_ACQUIRE_RETRY_DELAY_MS)
125+
.withDbAcquireRetryAttempts(DB_ACQUIRE_RETRY_ATTEMPTS)
126+
.withDbAcquireIncrement(DB_ACQUIRE_INCREMENT)
127+
.withDbMaxPoolSize(DB_MAX_POOL_SIZE)
128+
.withScriptResourcePaths(SCRIPT_RESOURCE_PATHS);
129+
return settings;
130+
}
131+
116132
public static Future<List<Database>> getAll() {
117133
logger.info("Gathering all database objects ...");
118134
List<Database> allDbs = cache.getIfPresent(ALL_DATABASES);
@@ -202,14 +218,7 @@ private static List<Database> loadDatabasesForConnector(Connector connector) {
202218
connectorParameters.getEcps());
203219
fixLocalDbHosts(connectorDbSettingsMap);
204220

205-
DatabaseSettings connectorDbSettings = new DatabaseSettings(connector.id, connectorDbSettingsMap)
206-
.withStatementTimeoutSeconds(STATEMENT_TIMEOUT)
207-
.withDbCheckoutTimeout(20_000)
208-
.withDbAcquireRetryDelay(5_000)
209-
.withDbAcquireRetryAttempts(10)
210-
.withDbAcquireIncrement(3)
211-
.withDbMaxPoolSize(10)
212-
.withScriptResourcePaths(SCRIPT_RESOURCE_PATHS);
221+
DatabaseSettings connectorDbSettings = applyRuntimeDbSettings(new DatabaseSettings(connector.id, connectorDbSettingsMap));
213222

214223
String rdsClusterId = DBClusterResolver.getClusterIdFromHostname(connectorDbSettings.getHost());
215224

0 commit comments

Comments
 (0)