|
55 | 55 | import software.amazon.awssdk.services.rds.model.DBCluster; |
56 | 56 |
|
57 | 57 | 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; |
59 | 64 | private static final List<ScriptResourcePath> SCRIPT_RESOURCE_PATHS = List.of(new ScriptResourcePath("/sql", "jobs", "common"), new ScriptResourcePath("/jobs", "jobs")); |
60 | 65 | private static final Logger logger = LogManager.getLogger(); |
61 | 66 | private static final float DB_MAX_JOB_UTILIZATION_PERCENTAGE = 0.6f; |
@@ -107,12 +112,23 @@ static void closeAll() { |
107 | 112 |
|
108 | 113 | DatabaseSettings getDatabaseSettings() { |
109 | 114 | 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")); |
113 | 117 | return dbSettings; |
114 | 118 | } |
115 | 119 |
|
| 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 | + |
116 | 132 | public static Future<List<Database>> getAll() { |
117 | 133 | logger.info("Gathering all database objects ..."); |
118 | 134 | List<Database> allDbs = cache.getIfPresent(ALL_DATABASES); |
@@ -202,14 +218,7 @@ private static List<Database> loadDatabasesForConnector(Connector connector) { |
202 | 218 | connectorParameters.getEcps()); |
203 | 219 | fixLocalDbHosts(connectorDbSettingsMap); |
204 | 220 |
|
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)); |
213 | 222 |
|
214 | 223 | String rdsClusterId = DBClusterResolver.getClusterIdFromHostname(connectorDbSettings.getHost()); |
215 | 224 |
|
|
0 commit comments