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

Add Support for MariaDB services #224

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

daviddmd
Copy link

With MariaDB Connector/J versions greater than 3.0, the use of the jdbc:mysql scheme is disallowed unless a permitMysqlScheme option is set in the JDBC URL (https://mariadb.com/kb/en/about-mariadb-connector-j/#jdbcmysql-scheme-compatibility). Besides this option, using jdbc:mariadb is also a viable option if the database is MariaDB.

Currently, the library always builds the JDBC url (if no jdbc url is detected from the credentials in the environment, in which case it retrieves it without change) with the MySQL scheme, regardless of the MariaDB database service attributes or connector in use, which causes the data source initialization to fail with >= 3.0 MariaDB connectors.

Therefore, detection for MariaDB database service attributes, such as any specific tags, schemes or labels is added, and the MySQL scheme (mysql) of the JDBC url is replaced by the MariaDB scheme (mariadb) if any of the MariaDB service conditions (label, scheme, tag) are met and the current driver class in use matches the MariaDB one, to satisfy the new requirements of the 3.0 MariaDB connector (compatible with older versions of the connector).
This is accomplished by overriding the createJdbcUrl method from AbstractJdbcUrlCreator in MySqlJdbcUrlCreator and replacing the built/existing (from environment) JDBC url MySQL scheme with MariaDB if the aforementioned conditions are met.

Tests were added to simulate the conditions found in MariaDB services and verify that the service is detected as expected, while not changing the behaviour for MySQL services, regardless of the driver being used.

Copy link
Member

@anthonydahanne anthonydahanne left a comment

Choose a reason for hiding this comment

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

Hello @daviddmd !
Thanks a lot for your contribution!

I have left you a question, because it was not super clear to me when I read that code change; it could be that you already chose the best way to patch the url with mariadb; but just wanted to check with you first.

Then 2 things:

  • please do not replace tabs indentations with spaces in MySqlJdbcUrlCreator ; all the code base is tab indented
  • instead of merging main into your branch , to help the reviewers review your contribution and also to keep a cleaner history, please rebase instead

other than that, I think I don't have much to add! (maybe @pivotal-david-osullivan you have some other comments)
This looks good!

@massiinthesea
Copy link

Hello,

We have a spring boot 3 application and are currently experiencing a problem using a mariaDB service on an environment deployed in Cloudfoundry PaaS

It worked fine until buildpack version 4.62.0, but since this version, because of this change: #227

In fact, before, for a specific environment, I used to disable the addition of the cloud profile with JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{ enabled: false }'

But this doesn't seem to work anymore, the cloud profile being added every time, even with this set.
JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{ enabled: false }'

With the cloud profile, it fetches all the DB info from the VCAPS, and therefore reads a "jdbc:mysql" url and farts.

So I'd like to know if you know how I can force the deactivation of the cloud profile on the PaaS? If not, normally, if this mr is delivered in a future version, it should solve my initial problem, accepting jdbc:mysql urls.

PS: I've gone through the MR, and it seems ok to be merged.

Thank you very much for what you do.

@dipsk2
Copy link

dipsk2 commented Oct 12, 2023

@anthonydahanne we are waiting for this to be merged. Is there a planned timeline?

@anthonydahanne
Copy link
Member

@anthonydahanne we are waiting for this to be merged. Is there a planned timeline?

sorry about that; I just want to run those changes in 2 different Cloud Foundries instances using mysql and spring-music

this week hopefully

Update MySqlJdbcUrlCreator to add MariaDB schemes, tags and labels
Update MySqlJdbcUrlCreator to override createJdbcUrl from AbstractJdbcUrlCreator
Update MySqlJdbcUrlCreator to add detection of MariaDB service based on CF environment tags, labels and MariaDB uri
Conditionally update the JDBC URL that was either generated or obtained from the CF Service if the current driver class name matches the MariaDB driver and any of the specific MariaDB detection cases
Overload existsByLabelStartsWith method in CfService to allow checking if one of many labels matches the CF service label
@dipsk2
Copy link

dipsk2 commented May 23, 2024

@anthonydahanne Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants