Repository navigation
[Server] Let only the schema steps change the schema - #2117
Conversation
|
/review |
|
/review |
1 similar comment
|
/review |
Squashes unitycatalog#2118's own commits on top of unitycatalog#2117 so the PR stays under the DCO app's 250-commit limit. The tree is unchanged. 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: mysql` with `server.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 database `uc+test`, `connectionTimeZone: "+05:30"`) reaches the
driver unchanged.
- `server.db.mysqlConfig.driver.volume` and `driver.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, point `subPath` at another jar.
- Without `mysqlConfig.host`, `driver.volume` or `driver.subPath`, the
chart fails to render with a message that names the missing value.
- `docs/server/helm.md` has a new "Use MySQL" section, and `values.yaml`
and the chart README describe the new values.
- CI: the Helm chart test job now runs once for each database, so its
check names change from "Lint and install the Helm chart" to "Lint and
install the Helm chart (file)", "(postgresql)" and "(mysql)". `main`
requires no status checks, so the rename blocks no merge.
For example:
```yaml
server:
db:
type: mysql
mysqlConfig:
host: my-mysql.example.com
passwordSecretName: db-password
driver:
volume:
persistentVolumeClaim:
claimName: mysql-driver
subPath: mysql-connector-j-8.4.0.jar
```
### What doesn't change
- The file database and PostgreSQL render as before. The chart still
sets `hibernate.hbm2ddl.auto=update` for every database type, as on
`main`.
### Tests
- The "Check how non-default values render" step covers the MySQL
branches: the three required values fail the render with their messages;
the jar is mounted at, and put on the module path from,
`/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 or `JDK_JAVA_OPTIONS`.
- The kind install (install and `helm test`) runs on each database in
CI; the MySQL one mounts the driver jar through
`helm/ci/mysql-values.yaml`.
- Ran locally: `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.
<details><summary><b>📐 Design notes & details</b></summary>
### Design
- Why a volume: the driver jar is too large for a ConfigMap, and the
server image ships without it. Any volume source works; for several
replicas, use one that several pods can mount, for example a
PersistentVolumeClaim with access mode `ReadOnlyMany`.
- Why one jar file on the module path: the image's launcher lists the
classpath jars in a file, so a mounted jar can't join the classpath. The
chart mounts `driver.subPath` as a single file at
`/home/unitycatalog/jdbc-drivers/mysql-connector-j.jar` and sets
`JDK_JAVA_OPTIONS=--module-path=/home/unitycatalog/jdbc-drivers/mysql-connector-j.jar
--add-modules=ALL-MODULE-PATH` on 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 unreadable
`lost+found`) can't stop the JVM.
- Why `urlquery` for the database name too: Connector/J form-decodes the
whole URL, the database name included, so query escaping round-trips
(`+` → `%2B`, space → `+`).
- CI matrix: `helm-chart-tests.yml` runs `db: [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 that `build.sbt` pins for the tests, through an init container
in `helm/ci/mysql-values.yaml`, and fails fast if `build.sbt` has no
such version.
- Interplay with the schema-upgrade stack (#2045 to #2118): #2117 adds
an `upgrade-schema` init container and removes the `hbm2ddl` line.
Whichever of this PR and #2117 merges second must give that init
container the same single-file `subPath` mount of the driver jar at
`/home/unitycatalog/jdbc-drivers/mysql-connector-j.jar`, the same
`JDK_JAVA_OPTIONS`, and the `DB_PASSWORD` env, and add MySQL to #2117's
Helm upgrade test.
- Follow-up, not in this PR: the PostgreSQL URL on `main` has the same
gaps (unencoded `dbName` and `extraParams`, no `required` on `host`).
</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]>
…2045) ## 🥞 Stacked PR Use this [link](https://github.com/unitycatalog/unitycatalog/pull/2045/files) to review incremental changes. - [**stack/uc-flyway-schema**](#2045) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2045/files)] ← _this PR_ - [stack/uc-upgrade-adopt](#2112) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2112/files/dfe03066ca3f748f42b916b6908d7ad23e50b7af..187be0b86367b2fe7cb3db852b33039bb534bbfe)] - [stack/uc-upgrade-merge-checks](#2113) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2113/files/b2982d514290d5a7cbb70010c31686d681f732d0..837c49999da9d021a385b5878dd5724f902b8ac0)] - [stack/uc-upgrade-retry](#2114) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2114/files/86b2b75709c1378fb7d199dabf453033849885c1..6aed4147e2b76bc45b076c5d1769a85461d9aaaf)] - [stack/uc-upgrade-check-schema](#2115) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2115/files/8ba3b07ae080f5d07518392679ddba696074afab..b7a8d07fbeae61d80e3518336ad7290b20cd6770)] - [stack/uc-sample-database-built](#2116) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files/6a59493c75da317dfde80776cd29f6ae030eeabf..4221ea5224ceaf8b1122c0b00ba41eeaa6003840)] - [stack/uc-flyway-owns-schema](#2117) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/ccb5e69e8b53596d6f2925797970c9828505edba..b1e7a896aa2e48163e9a750265d99abf69c52371)] - [stack/uc-hibernate-fallback](#2118) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/861ca93eabac0bee2f40ebd4d0976dfd964929cf..0ed55964bab3e0d505fc330f41cdf00c48ff40b9)] --------- This PR adds Unity Catalog's database schema as Flyway steps, and a command that you run by hand to apply them: `bin/start-uc-server --upgrade-schema`. The command is optional for now. The server still sets up and updates its schema with Hibernate when it starts. This PR now only adds the steps and the manual command. The rest of what this PR held at the last review moved to the next PRs of the stack: adopting existing databases to #2112, the merge checks and contributor rules to #2113, the built sample database to #2116, and the start-time schema check, the Hibernate refusals, the Helm init container and the step-built test schemas to #2117. "What moved out of this PR" in the details lists each piece. ### What you see - The schema is a list of steps for each supported database: H2, PostgreSQL and MySQL. Step 1 is the schema of release 0.7.0. Step 2 widens the function parameter type column (#2013). - `bin/start-uc-server --upgrade-schema` applies the steps that are not applied yet, records each one in the `uc_schema_history` table, and exits without starting the server. It exits with 0 and prints `The database schema is at version 2.` on success, and exits with 1 and prints the reason otherwise. - It sets up an empty database, also one that holds only other applications' tables, which it leaves alone. It upgrades a database that it set up earlier. - It refuses, and changes nothing, in these cases: - The database has Unity Catalog's tables but no schema history, for example one that a server set up at start. The message says that adopting such a database is not supported yet; #2112 adds it. - The database's schema is newer than this release. - Flyway's check of the schema history fails, for example after a failed step. - The configuration uses H2 in server mode, `hibernate.default_schema` or `hibernate.default_catalog`, an in-memory database, or a database other than H2, PostgreSQL and MySQL, or a configuration file is missing. - On PostgreSQL and MySQL, a run lock lets only one command apply steps at a time. A second command waits for the first. - The new page `docs/server/upgrades.md` describes the command, backups, the lock, and the messages. ### What doesn't change yet - Server start still runs Hibernate's `update` (`hibernate.hbm2ddl.auto=update` in `etc/conf/hibernate.properties`), and the Helm chart still sets it. The steps build the same schema that Hibernate builds from the entities, so on a database that the steps set up, Hibernate changes nothing. - The test suite still builds its schemas with Hibernate, and the sample database `etc/db/h2db.mv.db` is the same as on `main`. - #2117 makes the steps the only way the schema changes. ### Tests Ran locally on H2: compiled all modules and their tests with checkstyle, and ran the schema migration tests, the option parser, Hibernate configurator and key mapper tests, and the catalog SDK tests (46 passed). The four run-lock tests skip on H2, which takes no run lock; they ran locally on PostgreSQL 18 and MySQL 8 only at the top of the stack (#2118). CI runs the full suite on H2, PostgreSQL 18 and MySQL 8. <details><summary><b>📐 Design notes & details</b></summary> ### Design - `SchemaMigrator` classifies the database from its `uc_*` tables only: `EMPTY` (no `uc_*` table), `CURRENT`, `PENDING`, `AHEAD`, or `UNVERSIONED_UC` (Unity Catalog's tables without history). Other applications' tables, such as Casbin's, don't count, so the steps run next to them. On a database with only other tables, Flyway records a baseline at version 0, below step 1, so that step 1 runs. - `upgradeSchema()` is a plain Flyway run under the run lock: refuse `AHEAD` and `UNVERSIONED_UC`, validate the history, migrate, then check that the database ends `CURRENT` with a valid history. Retrying a run that stopped part way comes in #2114. - Every statement of step 1 skips what is already there (for example `create table if not exists`), so that a later run can run it again after a run that stopped in the middle. #2114 relies on this. - The run lock covers the whole run, from classifying the database to the last step; Flyway's own lock is taken per step. PostgreSQL uses `pg_advisory_lock` on a fixed key, and MySQL uses `GET_LOCK` on a name derived from the database name. H2 takes no lock, because one process opens an H2 file; for the same reason H2 in server mode (`AUTO_SERVER`, `jdbc:h2:tcp:`, `jdbc:h2:ssl:`) is refused. The lock lives on one database session, so a pooler in transaction mode (PgBouncer `pool_mode = transaction`) is not supported for the command. A failed lock release closes the connection underneath the pooled one, which ends the session and so releases the lock. - The migrator opens its own pool of 4 connections (the lock's connection, Flyway's two on PostgreSQL, and one for reading the schema) and closes it at the end, so the server's pool size doesn't limit it. - The database kind comes from the name that its JDBC driver reports, not from the URL, so wrapping drivers (`jdbc:aws-wrapper:`, `jdbc:p6spy:`) and pools set up with `hibernate.hikari.dataSourceClassName` work. - Metadata lookups pass the configured schema as an exact pattern (`exactPattern`), since `_` and `%` are wildcards there and `uc_a` would also match `ucxa`. - `hibernate.default_schema` and `hibernate.default_catalog` are refused, also from JVM system properties, because Flyway uses the connection's schema. Set the schema in the JDBC URL instead. In this PR only the command refuses them; #2117 adds the same refusal at server start. - `HibernateConfigurator` gains only helpers here: `hikariConfig()` (the pool settings without opening a pool), `requireSchemaFromConnection()`, and a `setupHibernateProperties()` overload that takes the file path. - Build: the shaded jar merges Flyway's ServiceLoader file; other service files are still dropped. The launcher classpath leaves out the project's class directory, because the jar holds the same steps and Flyway would find each one twice. - `BaselineMatchesEntitiesTest` checks that the steps build the schema that Hibernate builds from the entities. It runs in the normal suite here; #2113 moves it behind `UC_TEST_MIGRATION_CHECKS=true` with the other step checks. - Test plumbing for the migrator tests: `@TempDatabase(empty = true)`, `TestDatabase.dataSource()`, `newEmptyDatabase`, and H2 file databases. The normal suite still builds its schema with Hibernate's `update`. - `deployment.md`: the MySQL collation advice now changes the database default together with every table, so that tables that later steps create also get the binary collation. ### Test coverage - `SchemaMigratorTest`: an empty database, one with only the authorization rules table, one next to another application's tables, a wrapping driver, a pool set up by data source class, a versioned database with a pending step, reading only the configured schema, and the refusals of a database without history, a newer schema, a failed step, and H2 server mode. Run-lock tests on PostgreSQL and MySQL: two runs on an empty database take turns, a refused lock, and a lock that is not released. - `SchemaGateTest`: the command sets up the configured database, and refuses a missing `server.properties` or `hibernate.properties`, an in-memory database and `hibernate.default_schema`. - `OptionParserTest`: `--upgrade-schema`. - 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. ### What moved out of this PR Compared with the head at the last review (ae832c1): - To #2117: - Running the steps at server start. It is now a start-time check (`requireCurrentSchema()`) that refuses a database not at this release's schema; the command applies the steps. - The Hibernate schema-action refusals in `HibernateConfigurator` (`requireNoSchemaChanges`, `isSchemaAction`, `isNone`, `withSchemaUpdatesOff`, the constructor checks, and `setupHibernateProperties` turning `update` into `none`). - `etc/conf/hibernate.properties` without `update`. - The removal of `hibernate.hbm2ddl.auto=update` from the Helm chart's `_config.tpl`. This PR reverts ae832c1's last commit, so the chart is as on `main`. - Building every test database's schema with the steps: `TemplateDatabases`, `TestDatabases.h2`/`runSteps`, `MySqlDatabases`, `TestDatabase` with `hbm2ddl` set to `none`, `KeyMapperTest` with `@TempDatabase`, and the `BaseAccessControlCRUDTest` comment. - `HibernateConfiguratorTest.neverLetsHibernateChangeTheSchema` and `refusesHibernatesOwnDefaultSchema`, and the start-time tests in `SchemaGateTest`. - To #2112: - Adopting a 0.7.0 database as version 1 (`BASELINE_VERSION`, `baselineFor`). It now adopts only on an exact schema match. - `ADOPTED_RELEASE` and `adoptsABaselineDatabase`. - The real-release tests: `RealUpgradeTest`, `OldServer`, `DataSet`, `TestServer`, `upgrade-tests.yml`, and the Vert.x test dependency. - `SchemaSnapshot`, which moves to the main code. - To #2116: the migrated `etc/db/h2db.mv.db` and the `PopulateTestDatabase` call that ran the steps. The sample database is now built (`SampleDatabase`); this PR keeps `main`'s file. - To #2113: the schema-change rules in `AGENTS.md`, `CODE_REVIEW.md` and the AI reviewer's `REVIEW.md`. - Removed, not moved: - `BEFORE_BASELINE`, `BASELINE_TABLES`, `missingBaselineTables` and `refusesADatabaseFromBeforeTheBaselineRelease`. #2112's schema comparison replaces them; its refusal says that a database from before 0.7.0 must be started on a 0.7.0 server first. - `NOT_UC` and `refusesADatabaseOfAnotherApplication`. `setsUpADatabaseNextToAnotherApplicationsTables` replaces them: other applications' tables are left alone. - The H2 lock inside the JVM, `acceptsHibernatesNoneActionObject`, and the schema-versions table in `upgrades.md`. - Kept in this PR: `exactPattern` and the fix that reads only the configured schema's tables (a80afaa), the H2 server-mode refusal, the lock tests, `refusesADatabaseWithAFailedStep`, `migrate()` (now named `upgradeSchema()`), the pool size (now 4 instead of 3), and step 1 written so that it can run again. ### Stack Part 1 of 8 of the schema-upgrade stack: 1. #2045 [Server] Add the schema steps and a manual --upgrade-schema command (this PR) 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 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]>
## 🥞 Stacked PR Use this [link](https://github.com/unitycatalog/unitycatalog/pull/2112/files/dfe03066ca3f748f42b916b6908d7ad23e50b7af..187be0b86367b2fe7cb3db852b33039bb534bbfe) to review incremental changes. - [stack/uc-flyway-schema](#2045) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2045/files)] - [**stack/uc-upgrade-adopt**](#2112) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2112/files/dfe03066ca3f748f42b916b6908d7ad23e50b7af..187be0b86367b2fe7cb3db852b33039bb534bbfe)] ← _this PR_ - [stack/uc-upgrade-merge-checks](#2113) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2113/files/b2982d514290d5a7cbb70010c31686d681f732d0..837c49999da9d021a385b5878dd5724f902b8ac0)] - [stack/uc-upgrade-retry](#2114) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2114/files/86b2b75709c1378fb7d199dabf453033849885c1..6aed4147e2b76bc45b076c5d1769a85461d9aaaf)] - [stack/uc-upgrade-check-schema](#2115) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2115/files/8ba3b07ae080f5d07518392679ddba696074afab..b7a8d07fbeae61d80e3518336ad7290b20cd6770)] - [stack/uc-sample-database-built](#2116) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files/6a59493c75da317dfde80776cd29f6ae030eeabf..4221ea5224ceaf8b1122c0b00ba41eeaa6003840)] - [stack/uc-flyway-owns-schema](#2117) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/ccb5e69e8b53596d6f2925797970c9828505edba..b1e7a896aa2e48163e9a750265d99abf69c52371)] - [stack/uc-hibernate-fallback](#2118) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/861ca93eabac0bee2f40ebd4d0976dfd964929cf..0ed55964bab3e0d505fc330f41cdf00c48ff40b9)] --------- `bin/start-uc-server --upgrade-schema` now adopts an existing database: one that has Unity Catalog's tables but no schema history, such as a 0.7.0 database or one that a server of this release set up at start with Hibernate. Before this PR, the command refused such a database. ### What you see - A database whose schema is exactly the schema of version 1 (release 0.7.0) gets step 1 recorded without running it, and the later steps run. - A database whose schema is exactly this release's schema gets every step recorded without running it. A server of this release that set up a new database at start leaves such a schema. - Any other schema is refused, with one line for each difference from version 1, and the hint that a database from before 0.7.0 must be started on a 0.7.0 server first. For example, after someone added a column by hand: ```console The database has no schema history, and its schema is neither the schema of version 1 nor that of version 2. It differs from version 1 in: unexpected column uc_catalogs.extra ... ``` - At the end of every run, the command compares the whole schema with the schema that the steps build, and fails with the differences if they don't match. - `docs/server/upgrades.md` describes the baseline release, how to repair a database from before 0.7.0 (two CHECK constraints differ; the page gives the SQL for each database), and why not to start 0.7.0 again on an upgraded database. ### What doesn't change yet - Server start still runs Hibernate's `update`, and the command is still optional and run by hand. #2117 switches that. ### Tests Ran locally on H2: compiled all modules and their tests with checkstyle, and ran the schema migration tests and the catalog SDK tests. The real-release upgrade tests need `UC_TEST_UPGRADES=true` and did not run locally; the new path-filtered workflow runs them in CI on H2, PostgreSQL 18 and MySQL 8. CI also runs the full suite on all three databases. <details><summary><b>📐 Design notes & details</b></summary> ### Design - Adoption needs an exact match. A database that matches neither version 1 nor the latest version can't be told apart from one that someone changed by hand, so the command refuses it and lists the differences instead of guessing. - To compare schemas, `SchemaSnapshot` moves from the tests to the server, and renders what a one-statement step can change: CHECK constraints by clause, MySQL enum values, column collations, numeric scale, foreign key rules, descending index columns, and PostgreSQL's partial indexes. It reads only Unity Catalog's `uc_*` tables, so the test-only step's table is now `uc_test_only_step`. - Each step has an effect file per database, `schema-effects/<database>/V<n>.txt`, that lists what the step changes. The schema of a version is the sum of the effect files up to it (`SchemaMigrator.expected()`). The effect files ship in the server jar, so the installed command compares without building a reference database. - `MigrationStepRulesTest.eachStepHasItsEffectFile` checks each effect file against what the step does on a new database. `build/sbt updateSchemaDumps` rewrites the files on all three databases (PostgreSQL and MySQL need Docker). This test lands here, not in #2113, because the effect files and the rendering must exist before #2113 freezes merged effect files. - The record-without-running uses Flyway's `target` with `skipExecutingMigrations`, so Flyway writes the history records itself. - `adoptsADatabaseWithThisReleasesSchemaWithoutHistory` is a temporary test: it drops the history table to stand in for a database that Hibernate set up. #2118 removes it, because its hibernate-mode tests cover the same case with a real Hibernate setup. - `docs/server/upgrades.md` also says why not to start 0.7.0 on an upgraded database: its Hibernate `update` narrows the column that step 2 widened, while the history still records step 2. ### Test coverage - `SchemaMigratorTest`: adopts a version 1 database, adopts a database with this release's schema, and refuses a version 1 database with an extra column. - `SchemaSnapshotTest`: tells apart schemas that differ only in each rendered detail (some rows run only on PostgreSQL or MySQL), applies an effect file with no changes, and counts duplicate checks once. - `RealUpgradeTest` (`UC_TEST_UPGRADES=true`, workflow `upgrade-tests.yml`): each release tag from 0.7.0 up to, but not including, this build's version writes a data set, then this build upgrades the database and reads every copy back. A database that 0.4.0 set up and 0.7.0 upgraded is refused, then repaired with the documented SQL (`db/repair-0.7.0/*.sql`) and upgraded. This build's shaded jar sets up an empty database with `--upgrade-schema` and serves it. `OldServer`, `DataSet` and `TestServer` support it; the Vert.x test dependency is there because older releases read Vert.x's version file at start. - 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, and before #2045 added `refusesADatabaseWithAFailedStep`. CI runs on the merged head. ### Stack Part 2 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 (this PR) 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 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]>
Squashes unitycatalog#2113's own commits on top of main and the PRs below it in the stack, so the PR stays under the DCO app's 250-commit limit. The tree is the same as the merge of main into the branch (backup/uc-upgrade-merge-checks-merged-20261110). Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Squashes unitycatalog#2114's own commits on top of main and the PRs below it in the stack, so the PR stays under the DCO app's 250-commit limit. The tree is the same as the merge of main into the branch (backup/uc-upgrade-retry-merged-20261110). Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Squashes unitycatalog#2115's own commits on top of main and the PRs below it in the stack, so the PR stays under the DCO app's 250-commit limit. The tree is the same as the merge of main into the branch (backup/uc-upgrade-check-schema-merged-20261110). Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Squashes unitycatalog#2116's own commits on top of main and the PRs below it in the stack, so the PR stays under the DCO app's 250-commit limit. The tree is the same as the merge of main into the branch (backup/uc-sample-database-built-merged-20261110). Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Squashes unitycatalog#2117's own commits on top of main and the PRs below it in the stack, so the PR stays under the DCO app's 250-commit limit. The tree is the same as the merge of main into the branch (backup/uc-flyway-owns-schema-merged-20261110). Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
54c88da to
22b13fb
Compare
Signed-off-by: Shubham Bansal <[email protected]> Co-authored-by: Isaac <[email protected]> # Conflicts: # server/src/main/java/io/unitycatalog/server/migrate/SchemaMigrator.java
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Verdict: comment. No correctness blocker found in the start gate or the schema-action refusal. The points below are for the author; the first two need a decision.
Not anchored to a diff line:
-
The description says an
etc/conf/hibernate.propertieswith any schema action is set tononewith a warning. Onlyhibernate.hbm2ddl.autogets that treatment (withSchemaUpdatesOff). Thejakarta.persistence.schema-generation.database.actionform (and itsjavax.and suffixed forms) makes the start refuse, asdocs/server/upgrades.mdsays. Could the description be aligned with the code and the docs? -
nit: the private static
requireCurrentSchema(DataSource, DatabaseKind)inSchemaMigratoronly checks the PostgreSQL search path, while the new publicrequireCurrentSchema()checks the schema version. Same name, different checks. Could the private one say what it checks, for examplerequireUsableSearchPath?
Follow-up items are the nits inline. The Helm restriction (inline) is the one I would like resolved before merge.
|
On the AI review findings that are still open:
|
…t the sample database Signed-off-by: Shubham Bansal <[email protected]> Co-authored-by: Isaac <[email protected]>
|
On the two points from the review summary:
Also in 185acf0: in a source checkout, the missing-H2-file refusal now also says how the quickstart's sample database is built ( |
## 🥞 Stacked PR #2115 has merged, so this PR's own changes are its whole diff against `main`. - [stack/uc-flyway-schema](#2045) (merged) - [stack/uc-upgrade-adopt](#2112) (merged) - [stack/uc-upgrade-merge-checks](#2113) (merged) - [stack/uc-upgrade-retry](#2114) (merged) - [stack/uc-upgrade-check-schema](#2115) (merged) - [**stack/uc-sample-database-built**](#2116) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files)] ← _this PR_ - [stack/uc-flyway-owns-schema](#2117) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f..0a120a3c682986c926845a85ad249df1720e5d4c)] - [stack/uc-hibernate-fallback](#2118) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/0a120a3c682986c926845a85ad249df1720e5d4c..97bc44b5dfb75eb27fdddc33db6ea208680234ac)] --------- The quickstart's sample database, `etc/db/h2db.mv.db`, is no longer checked in to git. The build makes it from the schema steps and the sample data, so it always has this release's schema and schema history. ### What you see - `build/sbt buildSampleDatabase` builds `etc/db/h2db.mv.db`, and keeps a file that exists. To reset the sample data, move the file aside and build again (the quickstart says how). The folder must be on a file system that supports hard links. - In a source checkout, `bin/start-uc-server` builds the sample database when it is missing, but only for a command line that starts the server: one with only the port options, in any spelling the option parser takes and with a value it accepts as a port number. `--check-schema`, `--upgrade-schema`, `--version`, `--help` and their short or abbreviated forms don't build it. It builds the file whatever database the configuration uses, and starts the server even when that build fails. - The tarball and the Docker image ship a sample database that their own build makes, never a local copy that a local server may have changed. - The build ignores the environment's `UC_SERVER_*` variables, so a deployment's settings don't change or break the sample database. - The Python client's tests build the sample database before they start the server. - `tests/test_tutorial.py` refuses to run when `etc/db/h2db.mv.db` exists, since git no longer shows whether a local copy changed. - The quickstart now says `build/sbt package buildSampleDatabase`. ### Compatibility - `etc/db/h2db.mv.db` is no longer in git. If you changed the sample database in a checkout from before this change, copy it somewhere safe before you update the checkout: git deletes the file, or refuses to update while it has local changes. ### What doesn't change yet - Server start still runs Hibernate's `update`. On the built sample database, it changes nothing, because the steps build the same schema. #2117 switches start to a schema check. ### Tests - `SampleDatabaseTest`: - builds the sample database, runs `--check-schema` on it and checks the sample catalog, tables, volumes and functions; - refuses an existing file and leaves its bytes unchanged; two builds at the same time leave one file, and the other build fails because the file exists; - builds with a deployment environment variable set that would make any other server configuration invalid; - checks `bin/start-uc-server` against the real `OptionParser` for each kind of command line (the port options in their spellings, signed, overflowing and non-numeric values, schema commands, `--version`, `--help`, unknown options, `--`), that the launcher knows every option the parser has, and that a failed build still starts the server. - Ran locally on H2. `build/sbt buildSampleDatabase` run twice keeps the file. The tarball was not built locally, and no enabled CI job builds it. In CI, the Helm chart tests build the Docker image, the Python client tests run, and the full suite runs on H2, PostgreSQL 18 and MySQL 8. <details><summary><b>📐 Design notes & details</b></summary> ### Design - A checked-in database would need a manual rebuild for every new schema step. Building it from the steps keeps it at this release's schema, with a schema history that `--upgrade-schema` and #2117's start check accept. - `SampleDatabase` (formerly the test class `PopulateTestDatabase`) lives in its own sbt project, `examples/sample-database`, with a compile-scope dependency on the server. Neither the server jar nor the server's test classes hold it. - It sets up the schema with the schema steps, as `--upgrade-schema` does, then writes the sample data through the repositories. It builds into a file next to the target and links it into place only when it is done (a hard link never replaces a file that exists), so a failed or concurrent build leaves no partial file that `bin/start-uc-server` would take for the sample database. - The tarball task builds a fresh copy under `target/` and replaces any `etc/db/h2db.*` it copied. The Dockerfile's build stage does not copy `etc/`; it runs `buildSampleDatabase`, and the runtime image takes `etc/` from the build context (`.dockerignore` leaves out `etc/db/h2db.*` and `etc/db/building-*`) and the built database from the build stage. - `bin/start-uc-server` builds the file only when `build/sbt` is there and executable, and the command line starts the server (`starts_server`, a copy of the parser's rules for the port options). The Docker image holds the server's sources but not `build/sbt`, and a volume mounted over `etc/db` stays empty. - The `populateTestDB` sbt task is gone; `buildSampleDatabase` replaces it. ### Stack Part 6 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 (this PR) 7. #2117 [Server] Let only the schema steps change the schema 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]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Verdict: comment. The start gate and the schema-action refusal look right. Most earlier items are addressed or conceded. The remaining points are below, with inline comments on each.
- Finding 2 (PR description, not anchored): line 64 still says
Recreateis the only allowed update strategy. Lines 31 and 41 sayRollingUpdatecan be set, so please align line 64 with them. Low risk, but the description is the operator's reference. - Finding 4 (normal): a named in-memory H2 URL without
DB_CLOSE_DELAY=-1is accepted and loses its schema when the last connection closes (inline onrequireNamedMemoryDatabase). - Findings 1, 3 and 6 are inline. Findings 3 and 6 are reasoning only, not run.
- Finding 5 is a nit (inline on
starts_server). - The Javadoc nit from the first review is still open. I replied in that thread rather than repeating it here.
- The
requireCurrentSchemanaming point is not re-raised.
An upgrade with --reuse-values from an older release carries its updateStrategy value, which was null, so the chart rendered no strategy and Kubernetes fell back to RollingUpdate. The chart now renders type: Recreate whenever the value is unset or empty. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
|
Thanks for the review. Finding 2: the description line about the update strategy now matches the other two: |
Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
|
/review |
timothyw553
left a comment
There was a problem hiding this comment.
the overall design makes sense, thanks for the thorough work here. i left a few comments, mainly around two startup issues (in-memory migration with a 1-connection pool and h2 lock keys for equivalent urls) plus some smaller cleanup, test, and doc nits.
|
Thanks for the review, @timothyw553. The inline threads are answered. Here are the two points from your summary, and the AI review findings that have no thread. I checked each one with a local run at cf6f2ff. In-memory start with a pool smaller than 4 (your summary, and AI review Nit1). I started the server with H2 lock keys for equivalent URLs (your summary). The key is the connection's own URL, AI Blocker2: AI Nit5: a user-set AI Nit6: the docs say the lock is taken on PostgreSQL and MySQL. That's still true for what it protects: servers in different processes. The H2 lock is in-process only, and H2's server mode, the only way several processes share an H2 database, is refused. AI Nit7: CI runs the scenarios in each matrix job, and MySQL has no upgrade run. Main's workflow already runs the checks that don't depend on the database in every matrix job, for example the MySQL render checks (helm-chart-tests.yml:127-143), and it checks MySQL by render only. This follows that. It's a CI-time and coverage choice, not a correctness gap. AI Blocker1, Nit2 and Nit3 are the same points as the earlier review: start advice for a pending database with an edited step (thread), RollingUpdate with the file database (thread) and a named in-memory URL without |
|
/review |
Main now has unitycatalog#2117 squashed; the conflicting files keep this branch's version, which is unitycatalog#2117's head plus this PR's changes. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
## 🥞 Stacked PR Use this [link](https://github.com/unitycatalog/unitycatalog/pull/2169/files) to review incremental changes. - [stack/s3compat_spec](#2170) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2170/files)] [MERGED] - [stack/s3compat_credentials](#2171) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2171/files)] [MERGED] - [stack/s3compat_vending](#2172) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2172/files)] [MERGED] - [stack/s3compat_hadoop_cli](#2173) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2173/files)] [MERGED] - [stack/s3compat_test_storage](#2174) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2174/files)] [MERGED] - [stack/s3compat_helm_key](#2175) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2175/files)] [MERGED] - [**stack/s3compat_credentials_text**](#2169) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2169/files)] ← _this PR_ - [stack/s3compat_location_endpoint](#2289) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2289/files/76859fc160061ad821312ef6bc69f986e9c44e5f..708dcb589fb36067a3e15464c2fd5513cddab4cb)] --------- Last of a stack adding experimental S3-compatible storage (MinIO, Ceph, SeaweedFS, RustFS, Garage): #2170 to #2175 are merged. **Description of changes** Stores credentials as text instead of PostgreSQL large objects, and widens the column on MySQL, where `tinytext` (255 bytes) is too small for real `s3_compatible` credentials with `assume_role`. It makes the change #1928 plans for `uc_credentials.credential`, and is a placeholder until #1928 and its follow-up merge. Builds on #2117 (merged): the server starts only once the steps have run, so it never sees the column before step V4. - `CredentialDAO.credential` drops `@Lob` and adds `length = 16777215` - Schema step `V4__credentials_credential_as_text`, one statement per database: - MySQL: `tinytext` to `mediumtext` - PostgreSQL: large object (`oid`) to `text`, through `convert_from(lo_get(credential), 'UTF8')` - H2: no change - Schema effect files for V4 - `docs/server/upgrades.md`: - the PostgreSQL step reads every credential's large object as UTF-8, as `hibernate.connection.username`; a missing or unreadable one fails it, with how to recover - the large objects stay (still holding the earlier stored values) for `vacuumlo`, and a release from before the step cannot read the converted column on PostgreSQL - Removes the `TODO(#2169)` on `CredentialDAO.setS3Compatible` - `SchemaMigratorTest.upgradeKeepsStoredCredentialsAndFitsLongerOnes`: a credential stored before the step (a large object on PostgreSQL, with two-, three- and four-byte characters) reads back as the same text, and one longer than 255 bytes fits, on all three databases; on PostgreSQL the old row is written through pgjdbc's large object path - `SchemaMigratorTest.upgradeWithAMissingLargeObjectChangesNothing`: on PostgreSQL, a credential whose large object is missing fails the step and leaves the column and the row as they were - `MigrationStepRulesTest`: MySQL `tinytext` widens to `text`, `mediumtext` or `longtext`; on PostgreSQL an `oid` column may change only as `TYPE text USING convert_from(lo_get(c), 'UTF8')`, the one allowed change that rows can fail, with cases for it; a plain type change of an `oid` column is refused - `SchemaMigratorTest.refusesAStepThatDropsAConstraintTheDatabaseNoLongerHasByThatName` brings the database to step 3 itself instead of to the newest step, so a later step no longer leaves a gap in its schema history - `BaseCredentialCRUDTest.testLongS3CompatibleCredential`: a credential over 1000 bytes, with non-ASCII text, round-trips through the server on every database Compatibility: no API change. Going back to an earlier release needs the database backup. Tests: `SchemaMigratorTest`, `BaselineMatchesEntitiesTest`, `MigrationStepRulesTest` and the credential and external location CRUD tests on H2, PostgreSQL 18 and MySQL 8 (`MigrationStepRulesTest` with `UC_TEST_MIGRATION_CHECKS=true`); all pass. **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: Yi Li <[email protected]> Co-authored-by: Isaac <[email protected]>
… are not (#2334) **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! - [ ] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** After the tests run, `server/jacoco.exec` and `examples/sample-database/jacoco.exec` show up in `git status` as untracked files. They come from two tests that start a child JVM: `HibernateConfiguratorTest.refusesASchemaActionSetAsASystemProperty` (added in #2117) and `SampleDatabaseTest.ignoresTheDeploymentEnvironmentVariables` (added in #2116). Each starts a child JVM with the test's classpath, which holds the coverage-instrumented classes, but not the `-Djacoco-agent.destfile` option that sbt-jacoco gives the test JVM. Without it, JaCoCo writes its default `jacoco.exec` to the working directory. Both tests now pass the option on to the child when it is set, so the child's coverage goes into the module's `target/jacoco/data/jacoco.exec` with the rest. The other tests that start processes are fine: the upgrade tests' `OldServer` runs a released jar without coverage classes, and the `start-uc-server` tests use a fake `java`. So it does not come back, the unit test action now records `git status` before the coverage tests and fails if they create or change a file in the checkout that git does not ignore (as the Helm workflow does for `helm/`), and AGENTS.md's testing conventions say where tests may write. <details> <summary>How I checked</summary> `build/sbt "server/testOnly io.unitycatalog.server.persist.utils.HibernateConfiguratorTest"`: - On `main` (dcec3cf): 21 passed, then `git status` shows `?? server/jacoco.exec`. That file lists only `HibernateConfigurator` and `RequestContextDataProvider`, the classes the child JVM loads. - With this change: 21 passed, `git status` shows no new file, and `server/target/jacoco/data/jacoco.exec` now holds the child's `HibernateConfigurator` data. `build/sbt "sampleDatabase/testOnly io.unitycatalog.server.utils.SampleDatabaseTest"`: - On `main`: 65 passed, then `git status` shows `?? examples/sample-database/jacoco.exec`. - With this change: 65 passed, and `git status` shows no new file. `server/javafmtCheckAll` and `sampleDatabase/javafmtCheckAll` pass. `dev/run-tests.py` with these fixes: 237 suites, 3851 tests, 0 failed, and no file in the checkout is new or changed afterwards, so the new CI check passes on `main` plus this PR. The check's comparison was also run on a scratch repository: a file present before the tests passes, a new untracked file fails, and a tracked file that was clean before the tests and changed after fails. </details> This pull request and its description were written by Isaac. --------- Signed-off-by: Shubham Bansal <[email protected]> Co-authored-by: Isaac <[email protected]>
🥞 Stacked PR
Use this link to review incremental changes.
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-schemain 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-schemaonce. A source checkout's quickstart sample database needs none. An in-memory database (server.env=test, or a namedjdbc:h2:mem:<name>;DB_CLOSE_DELAY=-1URL; 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-schemasucceeds 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-schemaand--upgrade-schemarefuse. 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: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-schemawith the new release, then start it. Seedocs/server/upgrades.md.etc/conf/hibernate.propertiesno longer setshibernate.hbm2ddl.auto=update. If your file still setshibernate.hbm2ddl.auto(toupdateor another value), the server sets it tononeand logs a warning. Any other schema action setting that isn'tnone(jakarta.persistence.schema-generation.database.action, itsjavax.form, or a suffixed form such ashibernate.hbm2ddl.auto.orm) makes the start refuse, also when it comes from a JVM system property or ahibernate.propertieson the classpath.The start also refuses what
--upgrade-schemarefuses:hibernate.default_schemaorhibernate.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_ruleat every start, so the database user keeps the CREATE privilege.A server that sets up its own test database (
server.env=test, or nohibernate.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:
upgrade-schemainit container runsbin/start-uc-server --upgrade-schemain each server pod, afterserver.deployment.extraInitContainers. For an in-memory database it does nothing.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.RollingUpdatecan still be set, for an upgrade without schema steps.server.deployment.replicaCountabove 1 with the file database fails to render.hibernate.hbm2ddl.auto=update.docs/server/helm.mdcovers backups, the init container's log, database proxies as native sidecars, scaling to 0 and restoring the backup beforehelm rollback, and why not to usehelm upgrade --atomic.Compatibility
bin/start-uc-server --upgrade-schemafirst.hibernate.hbm2ddl.autoinhibernate.propertiesis ignored with a warning. Any other schema action setting that isn'tnoneis refused, also from a JVM system property or a classpathhibernate.properties.hibernate.default_schemaandhibernate.default_catalogare refused: put the schema in the JDBC URL.Recreate(a values file that setsRollingUpdatekeeps it), and the file database allows one replica.What doesn't change yet
updateyet. [Server] Add a temporary fallback to Hibernate schema updates #2118 addsserver.schema-management=hibernateas a temporary fallback.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-schemasucceeds 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).Recreaterenders by default andRollingUpdatewhen set,replicaCountabove 1 is rejected for the file database, and the init container renders for an in-memory configuration and mounts the configuration and database volume.📐 Design notes & details
Design
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".HibernateConfiguratorrefuses every schema action butnone(hibernate.hbm2ddl.auto,jakarta.persistence.schema-generation.database.actionand itsjavax.form, also with a contributor suffix such ashibernate.hbm2ddl.auto.orm) before the pool or the session factory exists, and reads JVM system properties and a classpathhibernate.propertiesthe way Hibernate does.validateis refused too. Only the server's ownetc/conf/hibernate.propertiesgets the lenient path (its schema action turned tononewith a warning, which also overrides a JVM system property for it), so an old file keeps working.TemplateDatabases,TestDatabases,MySqlDatabasesandTestDatabase(withhbm2ddlset tonone), plusKeyMapperTestandBaseAccessControlCRUDTest.BaselineMatchesEntitiesTestkeeps checking that the steps match the entities.unitycatalog.server.volumeMountshelper. It runs afterextraInitContainers, so a database proxy run there as a native sidecar (restartPolicy: Always) is up first; a proxy inextraContainersstarts only after the init containers. The update strategy defaults toRecreate, also when an upgrade with--reuse-valuescarries 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.RollingUpdatecan be set for an upgrade without schema steps.HEAD^1), installs the base chart with it, creates a catalog, runshelm upgradeto 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.javaandbin/start-uc-server.--upgrade-schemaneeds to reach the database: the database password asUC_HIBERNATE_CONNECTION_PASSWORD(the way [Server] Read the database password from an environment variable #2080 passes it to the server) and, on MySQL, the driver mount andJDK_JAVA_OPTIONSfrom [Helm] Support MySQL #2119, through the newunitycatalog.server.dbPasswordEnvandunitycatalog.server.mysqlDriverEnvhelpers. Its environment has no storage credentials. It shares the server container's volume mounts, including the GCS key files, throughunitycatalog.server.volumeMounts, so the two can't drift apart. The server container keeps oneenvlist.docs/server/deployment.mddrops the manualALTERstatements foruc_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), andrefusesHibernatesOwnDefaultSchema.main, which brought in [UI] Scaffold /ui-new for the new console experience #1902, [Helm] Start the server with the observability port and probe /readyz #2063, [Server] Add WRITE VOLUME permission #2084, [Server] Add CREATE MODEL VERSION permission #2085, [Server] Add READ METADATA permission #2086 and Add owner for .gitignore #2111. CI runs on the merged head.Stack
Part 7 of 8 of the schema-upgrade stack:
PR Checklist
docsis updatedThis pull request and its description were written by Isaac.