Skip to content
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

Support config reactive datasource with list of database urls for fault tolerance and load balance #31994

Closed

Conversation

benstonezhang
Copy link
Contributor

Add support to config load balance urls for reactive datasources in application.properties, for example:

quarkus.datasource.reactive.url=mysql://host1:3306/dbname,mysql://host2:3306/dbname,mysql://host3:3306/dbname

or

quarkus.datasource.reactive.url[0]=mysql://host1:3306/dbname
quarkus.datasource.reactive.url[1]=mysql://host2:3306/dbname
quarkus.datasource.reactive.url[2]=mysql://host3:3306/dbname

The original PR is #31852, which only update reactive mysql client. As @tsegismont suggested, I replaced public Optional<String> url with public Optional<List<String>> urls in DataSourceReactiveRuntimeConfig, and all of reactive database client were updated accordingly.

There is one exception: Vert.x oracle client already have build-in load balance support, and there is no such function like OraclePool.pool(Vertx vertx, List<OracleConnectOptions> databases, PoolOptions options). So only the first url is valid and others is discarded even if you config more urls.

The original PR title maybe improperly and misleading, so I create this one.

@benstonezhang benstonezhang changed the title Support config reactive datasource with list of urls for fault tolerance and load balance Support config reactive datasource with list of database urls for fault tolerance and load balance Mar 21, 2023
Copy link
Contributor

@tsegismont tsegismont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @benstonezhang

@@ -23,10 +24,10 @@ public class DataSourceReactiveRuntimeConfig {
public boolean cachePreparedStatements = false;

/**
* The datasource URL.
* The datasource URLs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment explaining that if multiple values are set, then the pool will be configured to create new connections using each of the urls, in a round-robin fashion?

@@ -112,7 +112,7 @@ private OracleConnectOptions toOracleConnectOptions(DataSourceRuntimeConfig data
DataSourceReactiveOracleConfig dataSourceReactiveOracleConfig) {
OracleConnectOptions oracleConnectOptions;
if (dataSourceReactiveRuntimeConfig.url.isPresent()) {
String url = dataSourceReactiveRuntimeConfig.url.get();
String url = dataSourceReactiveRuntimeConfig.url.get().get(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please log a warning if the user provides two or more urls for Oracle?

@@ -25,6 +27,6 @@ interface Input {

PoolOptions poolOptions();

DB2ConnectOptions db2ConnectOptions();
List<DB2ConnectOptions> db2ConnectOptionsList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For DB2, we should do the same as with Oracle (only log a warning if the user provides two or more urls).

@@ -25,6 +27,6 @@ interface Input {

PoolOptions poolOptions();

MSSQLConnectOptions msSQLConnectOptions();
List<MSSQLConnectOptions> msSQLConnectOptionsList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For SQL Server, we should do the same as with Oracle (only log a warning if the user provides two or more urls).

import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;

public class MySQLPoolLoadBalanceTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for PostgreSQL too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revised, please check.
For DB2 and SQL Server, as the Reactive DB2 Client and Reactive MSSQL Client documented, Vert.x do support advanced pool configuration:

DB2Pool pool = DB2Pool.pool(Arrays.asList(server1, server2, server3), options);
MSSQLPool pool = MSSQLPool.pool(Arrays.asList(server1, server2, server3), options);

so I think we should support it too.

Copy link
Contributor

@tsegismont tsegismont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the updates. Yes, in the Vert.x API / documentation it is possible but, in practice, I'm aware of multi-master systems only for MySQL, Postgres and Oracle.

For Oracle we can't support it the same way because the driver has to take care of it.

String url = dataSourceReactiveRuntimeConfig.url.get().get(0);
List<String> urls = dataSourceReactiveRuntimeConfig.url.get();
if (urls.size() > 1) {
log.warn("The Oracle driver does not support multiple URLs. This first is used, and others is ignored.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.warn("The Oracle driver does not support multiple URLs. This first is used, and others is ignored.");
log.warn("The Reactive Oracle Client does not support multiple URLs. The first one will be used, and others will be ignored.");

@benstonezhang
Copy link
Contributor Author

I'm not family with DB2 and SQL Server. I will rework it tomorrow.

@tsegismont
Copy link
Contributor

tsegismont commented Mar 23, 2023 via email

Sanne and others added 8 commits March 23, 2023 18:40
Bumps [mariadb-java-client](https://github.com/mariadb-corporation/mariadb-connector-j) from 3.1.2 to 3.1.3.
- [Release notes](https://github.com/mariadb-corporation/mariadb-connector-j/releases)
- [Changelog](https://github.com/mariadb-corporation/mariadb-connector-j/blob/master/CHANGELOG.md)
- [Commits](mariadb-corporation/mariadb-connector-j@3.1.2...3.1.3)

---
updated-dependencies:
- dependency-name: org.mariadb.jdbc:mariadb-java-client
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps `smallrye-open-api.version` from 3.3.0 to 3.3.1.

Updates `smallrye-open-api-core` from 3.3.0 to 3.3.1
- [Release notes](https://github.com/smallrye/smallrye-open-api/releases)
- [Commits](smallrye/smallrye-open-api@3.3.0...3.3.1)

Updates `smallrye-open-api-jaxrs` from 3.3.0 to 3.3.1

Updates `smallrye-open-api-spring` from 3.3.0 to 3.3.1

Updates `smallrye-open-api-vertx` from 3.3.0 to 3.3.1

Updates `smallrye-open-api-ui` from 3.3.0 to 3.3.1

---
updated-dependencies:
- dependency-name: io.smallrye:smallrye-open-api-core
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: io.smallrye:smallrye-open-api-jaxrs
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: io.smallrye:smallrye-open-api-spring
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: io.smallrye:smallrye-open-api-vertx
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: io.smallrye:smallrye-open-api-ui
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
@benstonezhang
Copy link
Contributor Author

@tsegismont code updated, please check. Thx.

Sgitario and others added 10 commits March 24, 2023 07:19
Ensure Dialects initialzed by Hibernate Reactive extension use the ReactiveDialectWrapper
Allow using the annotation `@PartFilename` on method parameters
…g.mariadb.jdbc-mariadb-java-client-3.1.3

Bump mariadb-java-client from 3.1.2 to 3.1.3
…allrye-open-api.version-3.3.1

Bump smallrye-open-api.version from 3.3.0 to 3.3.1
@tsegismont
Copy link
Contributor

Can you please rebase your PR rather than merging the main branch into your branch?

@quarkus-bot quarkus-bot bot added area/config area/core area/dependencies Pull requests that update a dependency file area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/documentation area/hibernate-orm Hibernate ORM area/hibernate-reactive Hibernate Reactive area/liquibase area/panache area/platform Issues related to definition and interaction with Quarkus Platform area/rest area/tracing labels Mar 24, 2023
@github-actions
Copy link

github-actions bot commented Mar 24, 2023

🙈 The PR is closed and the preview is expired.

@tsegismont
Copy link
Contributor

It doesn't look good @benstonezhang

@benstonezhang
Copy link
Contributor Author

just done rebase and push

@quarkus-bot
Copy link

quarkus-bot bot commented Mar 24, 2023

✔️ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

@benstonezhang
Copy link
Contributor Author

@tsegismont Sorry, seems I had messed this branch. I create a new PR #32128, please check.

@quarkus-bot quarkus-bot bot added the triage/invalid This doesn't seem right label Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config area/core area/dependencies Pull requests that update a dependency file area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/documentation area/hibernate-orm Hibernate ORM area/hibernate-reactive Hibernate Reactive area/liquibase area/panache area/persistence OBSOLETE, DO NOT USE area/platform Issues related to definition and interaction with Quarkus Platform area/reactive-sql-clients area/rest area/tracing triage/invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.