Repository navigation
[Helm] Support MySQL - #2119
[Helm] Support MySQL#2119
Conversation
server.db.type mysql renders hibernate.properties for MySQL from server.db.mysqlConfig (host, port, dbName, username, the password Secret name and key, and extraParams for the JDBC URL), the same way the chart does it for PostgreSQL, with the driver com.mysql.cj.jdbc.Driver. Hibernate updates the schema at server start, as it does for PostgreSQL. The server image does not include the MySQL JDBC driver: the build uses mysql-connector-j only for tests. server.db.mysqlConfig.driver.volume takes any volume source that holds the driver jar and is required with mysql; driver.subPath mounts one directory of it. The launcher reads the classpath from a file of jar paths in the image, so the chart mounts the volume at /home/unitycatalog/jdbc-drivers and sets JDK_JAVA_OPTIONS to put its entries on the Java module path. That directory must hold one driver jar and nothing else: two driver versions or an unreadable directory, such as a root-owned lost+found, stop the JVM before main. helm/ci/mysql-values.yaml makes ct lint render the MySQL values. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
docs/server/helm.md gets a "Use MySQL" section: the driver volume and what its directory may hold, the binary collation, and an example. The PostgreSQL and graceful shutdown sections now mention MySQL too. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
The Helm chart test job now runs once per database, file, postgresql and mysql, in parallel. For postgresql and mysql it starts the database in the kind cluster from the images that SupportedDatabase pins for the server tests, with a password Secret, then installs the chart with helm/ci/<db>-values.yaml and runs helm test. MySQL starts with character set utf8mb4 and the binary collation utf8mb4_0900_bin, the collation MySqlDatabases creates test databases with. helm/ci/mysql-values.yaml now takes the driver from an emptyDir that an init container fills with mysql-connector-j from Maven Central, at the version build.sbt pins for the tests (passed in a ConfigMap). helm/ci/postgresql-values.yaml is new, so ct lint renders all three databases. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
|
/review |
1 similar comment
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] No blockers from my side. The change mirrors the PostgreSQL path, the password goes through a secretKeyRef, the missing-volume case fails the render with a clear message, and all three matrix jobs passed. A few comments inline: one design question on the module-path contract, a missing "why" in the docs, render-check coverage for the new branches, and the digests copied from the server tests. None of them should hold the PR if you have reasons for the current shape.
timothyw553
left a comment
There was a problem hiding this comment.
two comments, one about test coverage.
- The server mounts the driver jar at subPath in driver.volume as a single file and puts that file on the module path. A second driver jar or an unreadable lost+found on the volume no longer stops the JVM, and a volume can hold several driver versions. subPath is now required and names the jar. - extraParams keys and values are URL-encoded: Connector/J decodes the query, so connectionTimeZone=+05:30 used to reach it as " 05:30". - The values say why the image does not include the driver (GPL). - The render checks cover MySQL: driver.volume and driver.subPath are required, the jar goes on the module path, a "+" parameter is encoded, and other databases get no driver mount. The chart install fails fast when build.sbt has no mysql-connector-j version. Signed-off-by: Shubham Bansal <[email protected]> Co-authored-by: Isaac <[email protected]>
|
/review |
|
/review |
Signed-off-by: Shubham Bansal <[email protected]>
- dbName goes through urlquery: Connector/J form-decodes the URL, the database name too, so a database named uc+test was opened as "uc test". - An empty mysqlConfig.host now fails the render with "host is required" instead of rendering jdbc:mysql://:3306/..., which Connector/J reads as localhost. - The render checks cover both. Signed-off-by: Shubham Bansal <[email protected]> Co-authored-by: Isaac <[email protected]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Thanks for the quick turnaround on 581f6bc and 290e6cb; both read well, and the mysql kind install passing on the single-jar mount is the proof I wanted.
One thing I'd hold on before merge: the PR description still describes the directory design. It says the chart puts "every entry of that directory on the Java module path", requires exactly one jar, mentions lost+found, shows subPath: connector-j, and tells #2117 to add "the driver mount". Since 581f6bc the chart mounts one jar file at a fixed path and points --module-path at that file, and subPath names the jar. Can you rewrite those parts to match? #2117's author will read this description, and the init container there needs the same single-file subPath mount plus JDK_JAVA_OPTIONS.
Two nits inline.
- The "other databases get neither" check captures the render first, so a failing helm template fails the step instead of passing the negated grep. It also renders the PostgreSQL values now. - The URL check sets two extraParams and expects them joined by "&". - docs/server/helm.md says what to check when the server cannot load the driver class: that subPath names the jar file on the volume. Signed-off-by: Shubham Bansal <[email protected]> Co-authored-by: Isaac <[email protected]>
|
/review |
|
@shba24 Please rebase |
Signed-off-by: Shubham Bansal <[email protected]> # Conflicts: # .github/workflows/helm-chart-tests.yml
MySQL from unitycatalog#2119 takes the same password path as PostgreSQL: the chart passes UC_HIBERNATE_CONNECTION_PASSWORD to the server, and neither hibernate.properties nor the init container gets the password. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
## 🥞 Stacked PR Use this [link](https://github.com/unitycatalog/unitycatalog/pull/2117/files/727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f..0a120a3c682986c926845a85ad249df1720e5d4c) to review incremental changes. - [stack/uc-flyway-schema](#2045) (merged) - [stack/uc-upgrade-adopt](#2112) (merged) - [stack/uc-upgrade-merge-checks](#2113) (merged) - [stack/uc-upgrade-retry](#2114) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2114/files)] - [stack/uc-upgrade-check-schema](#2115) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2115/files/d4c1b003a0e576debded4b91a28b256d02507f67..0028bc22bb2e6ebd02e11048a2d7560ad023be19)] - [stack/uc-sample-database-built](#2116) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files/0028bc22bb2e6ebd02e11048a2d7560ad023be19..727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f)] - [**stack/uc-flyway-owns-schema**](#2117) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f..0a120a3c682986c926845a85ad249df1720e5d4c)] ← _this PR_ - [stack/uc-hibernate-fallback](#2118) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/0a120a3c682986c926845a85ad249df1720e5d4c..97bc44b5dfb75eb27fdddc33db6ea208680234ac)] --------- This PR makes the schema steps the only way Unity Catalog's schema changes. The server no longer lets Hibernate build or change the schema at start. Instead, it checks that the database is at this release's schema, and refuses to start otherwise. The Helm chart runs `--upgrade-schema` in an init container before each server pod starts. ### What you see - Before the first start on a new database, run `bin/start-uc-server --upgrade-schema` once. A source checkout's quickstart sample database needs none. An in-memory database (`server.env=test`, or a named `jdbc:h2:mem:<name>;DB_CLOSE_DELAY=-1` URL; unnamed in-memory URLs are refused) is the exception: it lasts only as long as the server, so the server sets it up itself, and `--upgrade-schema` succeeds on it without doing anything. - The server refuses to start on a database that is not at this release's last step, or whose schema history fails Flyway's check (a failed step, also a newer release's, or an edited or missing step). The start refuses what `--check-schema` and `--upgrade-schema` refuse. The message says what to do: the command to run, or, for a history the commands refuse too, to run the release that applied the steps or restore the backup. For example: ```console The database schema is at version none, and this release needs version 2. Stop every server of the previous release, run bin/start-uc-server --upgrade-schema with this release, then start the server. ``` - To upgrade from 0.7.0, stop the servers, back up the database, run `--upgrade-schema` with the new release, then start it. See `docs/server/upgrades.md`. - `etc/conf/hibernate.properties` no longer sets `hibernate.hbm2ddl.auto=update`. If your file still sets `hibernate.hbm2ddl.auto` (to `update` or another value), the server sets it to `none` and logs a warning. Any other schema action setting that isn't `none` (`jakarta.persistence.schema-generation.database.action`, its `javax.` form, or a suffixed form such as `hibernate.hbm2ddl.auto.orm`) makes the start refuse, also when it comes from a JVM system property or a `hibernate.properties` on the classpath. - The start also refuses what `--upgrade-schema` refuses: `hibernate.default_schema` or `hibernate.default_catalog`, H2 in server mode, and a database other than H2, PostgreSQL and MySQL. Before, Hibernate built a schema on any database. - With authorization enabled, the authorization library runs `CREATE TABLE IF NOT EXISTS casbin_rule` at every start, so the database user keeps the CREATE privilege. - A server that sets up its own test database (`server.env=test`, or no `hibernate.properties`) gives it a name of its own and shuts it down when it closes, so a later server in the same JVM starts on an empty one. A database the configuration names is left as it is. - Helm chart: - An `upgrade-schema` init container runs `bin/start-uc-server --upgrade-schema` in each server pod, after `server.deployment.extraInitContainers`. For an in-memory database it does nothing. - The update strategy defaults to `Recreate`, so all old server pods stop before new ones start, which an upgrade with schema steps needs. The server is unavailable during an upgrade until the new pods are ready. `RollingUpdate` can still be set, for an upgrade without schema steps. - `server.deployment.replicaCount` above 1 with the file database fails to render. - The chart no longer renders `hibernate.hbm2ddl.auto=update`. - `docs/server/helm.md` covers backups, the init container's log, database proxies as native sidecars, scaling to 0 and restoring the backup before `helm rollback`, and why not to use `helm upgrade --atomic`. ### Compatibility - A database not at this release's schema no longer starts: run `bin/start-uc-server --upgrade-schema` first. - `hibernate.hbm2ddl.auto` in `hibernate.properties` is ignored with a warning. Any other schema action setting that isn't `none` is refused, also from a JVM system property or a classpath `hibernate.properties`. - `hibernate.default_schema` and `hibernate.default_catalog` are refused: put the schema in the JDBC URL. - The Helm chart's update strategy defaults to `Recreate` (a values file that sets `RollingUpdate` keeps it), and the file database allows one replica. ### What doesn't change yet - There is no way back to Hibernate's `update` yet. #2118 adds `server.schema-management=hibernate` as a temporary fallback. - The Helm upgrade test covers H2 and PostgreSQL. Once the MySQL Helm PR #2119 lands, it should cover MySQL too. ### Tests - `SchemaMigratorTest`: the start refuses a history the commands refuse (a newer release's failed step, edited and missing steps), with advice that gets past each refusal. - `SchemaGateTest`: the start and both commands on a missing H2 file, an empty database, and each in-memory URL form (`mem:`, `.`, `memFS:`, `memLZF:`, `nioMemFS:`, `nioMemLZF:`), where `--upgrade-schema` succeeds without doing anything. - `UnityCatalogServerTest`: a server built from its own configuration refuses a mistyped H2 path without creating a file; two servers with their own test databases don't share one, and a closed one's database is gone; a configured in-memory database, and a file database behind a leftover in-memory URL setting, are left alone; an injected database keeps its tables. - `HibernateConfiguratorTest`: a schema action set as a JVM system property is refused (in a child JVM). - Helm render checks: `Recreate` renders by default and `RollingUpdate` when set, `replicaCount` above 1 is rejected for the file database, and the init container renders for an in-memory configuration and mounts the configuration and database volume. - Ran on H2, PostgreSQL 18 and MySQL 8 locally: the start-gate, migrator, server and configurator tests and the schema migration tests; the full server suite on H2. CI runs the full suite on all three databases and the Helm install and upgrade tests. <details><summary><b>📐 Design notes & details</b></summary> ### Design - Start runs `requireCurrentSchema()` on the migrator's own small pool: the recorded version must be this build's last step, and Flyway's validation must pass. It takes no run lock and changes nothing. A database newer than this release gets the "newer than this release" refusal; an empty one gets "The database has no Unity Catalog schema yet". - `HibernateConfigurator` refuses every schema action but `none` (`hibernate.hbm2ddl.auto`, `jakarta.persistence.schema-generation.database.action` and its `javax.` form, also with a contributor suffix such as `hibernate.hbm2ddl.auto.orm`) before the pool or the session factory exists, and reads JVM system properties and a classpath `hibernate.properties` the way Hibernate does. `validate` is refused too. Only the server's own `etc/conf/hibernate.properties` gets the lenient path (its schema action turned to `none` with a warning, which also overrides a JVM system property for it), so an old file keeps working. - The whole test suite now builds its schemas with the steps: `TemplateDatabases`, `TestDatabases`, `MySqlDatabases` and `TestDatabase` (with `hbm2ddl` set to `none`), plus `KeyMapperTest` and `BaseAccessControlCRUDTest`. `BaselineMatchesEntitiesTest` keeps checking that the steps match the entities. - Helm: the init container shares the server container's volume mounts through a new `unitycatalog.server.volumeMounts` helper. It runs after `extraInitContainers`, so a database proxy run there as a native sidecar (`restartPolicy: Always`) is up first; a proxy in `extraContainers` starts only after the init containers. The update strategy defaults to `Recreate`, also when an upgrade with `--reuse-values` carries no value from an older release: an upgrade with schema steps changes the database schema, so the old servers must stop before the new ones start. `RollingUpdate` can be set for an upgrade without schema steps. - Helm CI: the "Upgrade from the base chart" step builds the server image from the pull request's base (`HEAD^1`), installs the base chart with it, creates a catalog, runs `helm upgrade` to this chart and image, and checks the catalog is still there. It runs on H2 and on PostgreSQL with two replicas, whose init containers both run the upgrade under the run lock. The workflow now also triggers on changes to the migration code, the steps, the effect files, `UnityCatalogServer.java`, `OptionParser.java` and `bin/start-uc-server`. - Helm: the init container's environment has only what `--upgrade-schema` needs to reach the database: the database password as `UC_HIBERNATE_CONNECTION_PASSWORD` (the way #2080 passes it to the server) and, on MySQL, the driver mount and `JDK_JAVA_OPTIONS` from #2119, through the new `unitycatalog.server.dbPasswordEnv` and `unitycatalog.server.mysqlDriverEnv` helpers. Its environment has no storage credentials. It shares the server container's volume mounts, including the GCS key files, through `unitycatalog.server.volumeMounts`, so the two can't drift apart. The server container keeps one `env` list. - `docs/server/deployment.md` drops the manual `ALTER` statements for `uc_properties.property_value`: new installs get the wide column from the steps, and a pre-0.7.0 database gets it from starting 0.7.0 once. ### Test coverage - `SchemaMigratorTest.serverRefusesToStartOnADatabaseNotAtThisReleasesSchema`: a pending step, a failed step, an edited step, a step missing below the recorded one, and a newer schema. - `SchemaGateTest`: refuses to start on a database that is not set up, and sets up an in-memory database at start. - `HibernateConfiguratorTest`: `neverLetsHibernateChangeTheSchema`, `refusesASchemaActionOtherThanNone` (each setting form), and `refusesHibernatesOwnDefaultSchema`. - Local runs: the runs listed above were on this branch before its last merge of `main`, which brought in #1902, #2063, #2084, #2085, #2086 and #2111. CI runs on the merged head. ### Stack Part 7 of 8 of the schema-upgrade stack: 1. #2045 [Server] Add the schema steps and a manual --upgrade-schema command 2. #2112 [Server] Adopt existing databases in --upgrade-schema 3. #2113 [Build] Check the schema steps on every pull request 4. #2114 [Server] Retry a schema upgrade that stopped part way 5. #2115 [Server] Add a read-only --check-schema command 6. #2116 [Build] Build the sample database instead of checking it in 7. #2117 [Server] Let only the schema steps change the schema (this PR) 8. #2118 [Server] Add a temporary fallback to Hibernate schema updates </details> **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [ ] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [x] If you've added or modified a feature, documentation in `docs` is updated This pull request and its description were written by Isaac. --------- Signed-off-by: Shubham Bansal <[email protected]> Co-authored-by: Isaac <[email protected]>
The Helm chart now supports MySQL as the server's database, next to the H2 file database and PostgreSQL. The server image doesn't include the MySQL JDBC driver, because it is licensed under the GPL, so you provide the driver jar on a volume and the chart mounts it.
What you see
server.db.type: mysqlwithserver.db.mysqlConfig(host, port, database name, user, a password Secret, and extra JDBC URL parameters) renders the MySQL JDBC URL and passes the password from the Secret. The database name and the extra parameters are URL-encoded, so a value with+(a databaseuc+test,connectionTimeZone: "+05:30") reaches the driver unchanged.server.db.mysqlConfig.driver.volumeanddriver.subPath(both required for MySQL) name the volume and the driver jar on it. The chart mounts that one jar into the server and puts it on the Java module path, so the volume can hold other files or several driver versions; to change the version, pointsubPathat another jar.mysqlConfig.host,driver.volumeordriver.subPath, the chart fails to render with a message that names the missing value.docs/server/helm.mdhas a new "Use MySQL" section, andvalues.yamland the chart README describe the new values.mainrequires no status checks, so the rename blocks no merge.For example:
What doesn't change
hibernate.hbm2ddl.auto=updatefor every database type, as onmain.Tests
/home/unitycatalog/jdbc-drivers/mysql-connector-j.jar; the database name and two extra parameters render encoded and joined by&; and the file and PostgreSQL values get no driver mount orJDK_JAVA_OPTIONS.helm test) runs on each database in CI; the MySQL one mounts the driver jar throughhelm/ci/mysql-values.yaml.helm lint, the render-check step (it also fails on the previous templates),actionlint, and Connector/J 8.4.0's URL parsing for the encoded database name and parameters.📐 Design notes & details
Design
ReadOnlyMany.driver.subPathas a single file at/home/unitycatalog/jdbc-drivers/mysql-connector-j.jarand setsJDK_JAVA_OPTIONS=--module-path=/home/unitycatalog/jdbc-drivers/mysql-connector-j.jar --add-modules=ALL-MODULE-PATHon the server container. Pointing the module path at one file, not a directory, means other entries on the volume (a second driver version, a new file system's unreadablelost+found) can't stop the JVM.urlqueryfor the database name too: Connector/J form-decodes the whole URL, the database name included, so query escaping round-trips (+→%2B, space →+).helm-chart-tests.ymlrunsdb: [file, postgresql, mysql], the databases the server tests use, with the server tests' pinned image digests, and MySQL with their binary collation (utf8mb4_0900_bin). The MySQL install downloads the driver at the version thatbuild.sbtpins for the tests, through an init container inhelm/ci/mysql-values.yaml, and fails fast ifbuild.sbthas no such version.upgrade-schemainit container and removes thehbm2ddlline. Whichever of this PR and [Server] Let only the schema steps change the schema #2117 merges second must give that init container the same single-filesubPathmount of the driver jar at/home/unitycatalog/jdbc-drivers/mysql-connector-j.jar, the sameJDK_JAVA_OPTIONS, and theDB_PASSWORDenv, and add MySQL to [Server] Let only the schema steps change the schema #2117's Helm upgrade test.mainhas the same gaps (unencodeddbNameandextraParams, norequiredonhost).PR Checklist
docsis updatedThis pull request and its description were written by Isaac.