Skip to content

Commit

Permalink
feat(model): Allow configuring further PostgreSQL connection parameters
Browse files Browse the repository at this point in the history
The implementation has been done based on [1].

Fixes #8543.

[1]: eclipse-apoapsis/ort-server@f0f601e

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Apr 19, 2024
1 parent ce7d028 commit fb092bc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
18 changes: 18 additions & 0 deletions integrations/schemas/ort-configuration-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,24 @@
},
"parallelTransactions": {
"type": "integer"
},
"connectionTimeout": {
"type": "integer"
},
"idleTimeout": {
"type": "integer"
},
"keepaliveTime": {
"type": "integer"
},
"maxLifetime": {
"type": "integer"
},
"maximumPoolSize": {
"type": "integer"
},
"minimumIdle": {
"type": "integer"
}
},
"required": [
Expand Down
40 changes: 39 additions & 1 deletion model/src/main/kotlin/config/PostgresConnection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,45 @@ data class PostgresConnection(
/**
* The number of parallel transactions to use for the storage dispatcher.
*/
val parallelTransactions: Int = 5
val parallelTransactions: Int = 5,

/**
* The maximum number of milliseconds to wait for connections from the pool. For details see the
* [Hikari documentation](https://github.com/brettwooldridge/HikariCP#frequently-used).
*/
val connectionTimeout: Long?,

/**
* The maximum number of milliseconds a connection is allowed to sit idle in the pool. This requires that
* [minimumIdle] is set to a value lower than [maximumPoolSize]. For details see the
* [Hikari documentation](https://github.com/brettwooldridge/HikariCP#frequently-used).
*/
val idleTimeout: Long?,

/**
* The frequency in milliseconds that the pool will attempt to keep an idle connection alive. Must be set to a value
* lower than [maxLifetime]. For details see the
* [Hikari documentation](https://github.com/brettwooldridge/HikariCP#frequently-used).
*/
val keepaliveTime: Long?,

/**
* The maximum lifetime of a connection in milliseconds. For details see the
* [Hikari documentation](https://github.com/brettwooldridge/HikariCP#frequently-used).
*/
val maxLifetime: Long?,

/**
* The maximum size of the connection pool. For details see the
* [Hikari documentation](https://github.com/brettwooldridge/HikariCP#frequently-used).
*/
val maximumPoolSize: Int?,

/**
* The minimum number of idle connections that the pool tries to maintain. For details see the
* [Hikari documentation](https://github.com/brettwooldridge/HikariCP#frequently-used).
*/
val minimumIdle: Int?

/**
* TODO: Make additional parameters configurable, see:
Expand Down
7 changes: 7 additions & 0 deletions model/src/main/kotlin/utils/DatabaseUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ object DatabaseUtils {
schema = config.schema
maximumPoolSize = maxPoolSize

connectionTimeout = config.connectionTimeout ?: connectionTimeout
idleTimeout = config.idleTimeout ?: idleTimeout
keepaliveTime = config.keepaliveTime ?: keepaliveTime
maxLifetime = config.maxLifetime ?: maxLifetime
maximumPoolSize = config.maximumPoolSize ?: maximumPoolSize
minimumIdle = config.minimumIdle ?: minimumIdle

val suffix = " - $applicationNameSuffix".takeIf { applicationNameSuffix.isNotEmpty() }.orEmpty()
addDataSourceProperty("ApplicationName", "$ORT_FULL_NAME$suffix")

Expand Down

0 comments on commit fb092bc

Please sign in to comment.