-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#3542] Added additional parameters to the JDBC configuration #3548
[#3542] Added additional parameters to the JDBC configuration #3548
Conversation
@@ -66,12 +66,18 @@ and availability. | |||
| `HONO_REGISTRY_JDBC_ADAPTER_USERNAME` <br> `hono.registry.jdbc.adapter.username` | no | - | The username used to access the database. | | |||
| `HONO_REGISTRY_JDBC_ADAPTER_PASSWORD` <br> `hono.registry.jdbc.adapter.password` | no | - | The password used to access the database. | | |||
| `HONO_REGISTRY_JDBC_ADAPTER_MAXIMUMPOOLSIZE` <br> `hono.registry.jdbc.adapter.maximumPoolSize` | no | Depends on the connection pool implementation. `15` for C3P0. | The maximum size of the connection pool. | | |||
| `HONO_REGISTRY_JDBC_ADAPTER_MINIMUMPOOLSIZE` <br> `hono.registry.jdbc.adapter.minimumPoolSize` | no | Depends on the connection pool implementation. `3` for C3P0. | The minimum size of the connection pool. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since there is no way for a user to configure the particular connection pool implementation to be used, I believe that we should remove the reference to C3P0
here (and in the other places). I would also propose to define reasonable default values for the arbitrary properties in the JdbcOptions
class itself, instead of relying on the implicit defaults of C3P0 ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the references and defined default values in the JdbcOptions
class.
options.maximumPoolSize().ifPresentOrElse(this::setMaximumPoolSize, () -> setMaximumPoolSize(MAXIMUM_POOL_SIZE_DEFAULT)); | ||
options.minimumPoolSize().ifPresentOrElse(this::setMinimumPoolSize, () -> setMinimumPoolSize(MINIMUM_POOL_SIZE_DEFAULT)); | ||
options.initialPoolSize().ifPresentOrElse(this::setInitialPoolSize, () -> setInitialPoolSize(INITIAL_POOL_SIZE_DEFAULT)); | ||
options.maximumIdleTime().ifPresentOrElse(this::setMaximumIdleTime, () -> setMaximumIdleTime(MAXIMUM_IDLE_TIME_DEFAULT)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we usually set the default values in the corresponding *Options
class methods using the @WithDefault
annotation. For an example, you might want to refer to https://github.com/eclipse-hono/hono/blob/master/core/src/main/java/org/eclipse/hono/config/ServerOptions.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it. Thanks for the tip :)
if (dataSourceProperties.getMinimumPoolSize() != null) { | ||
config.put("min_pool_size", dataSourceProperties.getMinimumPoolSize()); | ||
} | ||
if (dataSourceProperties.getInitialPoolSize() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also add a check whether the initial pool size is indeed between min and max?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this as well, but decided against it because, since every value could be null (via default constructor or setter methods), it would be very complicated to cover every edge case meaningfully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when we change the types of these properties to int
, there shouldn't be an issue with checking the boundaries anymore, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but then we would have to get rid of the default constructor or add the default values there as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is what we do in other properties classes as well, e.g. ServiceConfigProperties
. This is not pretty but at least it would be consistent. The overall issue is that we had introduced the Options/Properties duality during the time of the migration from Spring to Quarkus. Spring heavily uses properties, Quarkus uses the interface based Options approach. We will need to start tidying that up ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I was already wondering why that is. I added the defaults to the Properties class as well, changed the types from Integer to int and added a value validation.
OptionalInt minimumPoolSize(); | ||
|
||
/** | ||
* Gets the initial size of the DB connection pool. | ||
* | ||
* @return The initial number of connections in the pool. | ||
*/ | ||
OptionalInt initialPoolSize(); | ||
|
||
/** | ||
* Gets the maximum idle time of connections in the DB connection pool. | ||
* | ||
* @return The maximum idle time of connections in the pool. | ||
*/ | ||
OptionalInt maximumIdleTime(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add checks to ensure the values are >= 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, we could do that. Is there an annotation or something you have in mind that I should use or why did you comment this in this interface rather than in the JdbcProperties class?
@@ -38,6 +38,9 @@ public class JdbcProperties { | |||
private String username; | |||
private String password; | |||
private Integer maximumPoolSize; | |||
private Integer minimumPoolSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that we always have a (default) value for these properties, we should probably define them as int
s instead of Integer
s, shouldn't we?
if (dataSourceProperties.getMinimumPoolSize() != null) { | ||
config.put("min_pool_size", dataSourceProperties.getMinimumPoolSize()); | ||
} | ||
if (dataSourceProperties.getInitialPoolSize() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when we change the types of these properties to int
, there shouldn't be an issue with checking the boundaries anymore, right?
…mIdleTime as parameters to the JDBC configuration Signed-off-by: Matthias Kaemmer <[email protected]>
removed reference to c3p0 and set default values for the connection pool in the JdbcProperties class Signed-off-by: Matthias Kaemmer <[email protected]>
changed declaration of default values for connection pool Signed-off-by: Matthias Kaemmer <[email protected]>
* removed null checks * added value validation Signed-off-by: Matthias Kaemmer <[email protected]>
9c93861
to
bca7159
Compare
@@ -140,4 +179,16 @@ public static JDBCClient dataSource(final Vertx vertx, final JdbcProperties data | |||
|
|||
} | |||
|
|||
private static void putValidValueIntoConfig(final JsonObject config, final String label, final int value, final int limit, final boolean checkLowerLimit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we have defined the limits at the class level, by means of constants, I believe that we should enforce these limits in the setters instead of deferring it to the time the datasource is being constructed (which may actually never happen), or am I mistaken?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the non negativ checks I think you are right, we could do those checks in the setter methods. However, for the initialPoolSize we would have the problem that we don't have control over the order in which someone calls the setter methods. So for example if you call setInitialPoolSize with input 5, which is between the defaults for min and maxPoolSize, this would be seen as valid input and initialPoolSize would be set to 5. After that you could just change the maxPoolSize to be below 5 or the minPoolSize to be above 5, which would result in an invalid configuration. Therefor, in my opinion it makes more sense to enforce this right before we create the JDBCClient, at which point we can be sure all the values have been set. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see your point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -140,4 +179,16 @@ public static JDBCClient dataSource(final Vertx vertx, final JdbcProperties data | |||
|
|||
} | |||
|
|||
private static void putValidValueIntoConfig(final JsonObject config, final String label, final int value, final int limit, final boolean checkLowerLimit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see your point
Additional parameters are: