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 b296744 commit 5b64b6c
Show file tree
Hide file tree
Showing 3 changed files with 70 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
46 changes: 45 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,51 @@ 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).
*/
@JsonInclude(Include.NON_NULL)
val connectionTimeout: Long? = null,

/**
* 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).
*/
@JsonInclude(Include.NON_NULL)
val idleTimeout: Long? = null,

/**
* 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).
*/
@JsonInclude(Include.NON_NULL)
val keepaliveTime: Long? = null,

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

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

/**
* 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).
*/
@JsonInclude(Include.NON_NULL)
val minimumIdle: Int? = null

/**
* 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

config.connectionTimeout?.also { connectionTimeout = it }
config.idleTimeout?.also { idleTimeout = it }
config.keepaliveTime?.also { keepaliveTime = it }
config.maxLifetime?.also { maxLifetime = it }
config.maximumPoolSize?.also { maximumPoolSize = it }
config.minimumIdle?.also { minimumIdle = it }

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

Expand Down

0 comments on commit 5b64b6c

Please sign in to comment.