Repository navigation
[Server] Add the schema steps and a manual --upgrade-schema command #2045
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
Merged
+2,802
−9
Merged
Changes from all commits
Commits
Show all changes
153 commits
Select commit
Hold shift + click to select a range
000f5b7
[Build] Run all tests on PostgreSQL 18 in CI
shba24 59ade4d
[Build] Describe the test-database input in plain words
shba24 19089ee
[Build] Run all tests on MySQL 8.4
shba24 170fdae
[Server] Return table columns in their declared order
shba24 0026554
[Server] Warn when a MySQL database compares text case-insensitively
shba24 7935437
[Build] Build MySQL test databases from a template, like PostgreSQL
shba24 6218571
[Server] Address review comments on the MySQL test harness
shba24 e5f9dc4
[Server] Run the MySQL Delta commit tests through the shared harness
shba24 f76aa8e
[Server] Inject test databases with @TempDatabase
shba24 d9c5f38
[Build] Pin the PostgreSQL and MySQL test images by digest
shba24 5fcf01c
[Build] Explain the test-only server settings of the MySQL and Postgr…
shba24 5542c61
[Server] Explain the isolation-level test and the MySQL template's ha…
shba24 75fa5d8
[Server] Add Flyway with the 0.7 baseline and the first migration step
shba24 fc3717f
[Server] Add bin/uc-migrate to set up and upgrade the schema with Flyway
shba24 3baa9d2
[Server] Start only on the current schema version; set up empty datab…
shba24 0175f4d
[Server] Make text comparisons case-sensitive on existing MySQL datab…
shba24 56e8dbb
[Server] Build test schemas with the migration steps
shba24 b22f20b
[Docs] Add the schema upgrade guide
shba24 8a52b91
[Server] Address review comments on the Flyway migration
shba24 7c21f5a
[Server] Test upgrades from the base code, the latest release, and 0.…
shba24 52dcb6b
[Build] Leave the project's own classes out of the launcher classpath
shba24 30c9cda
[Server] Migrate the sample database to the current schema version
shba24 8347828
[Server] Rename Migrator to SchemaMigrator and nest its small types
shba24 b89c59f
[Server] Upgrade the database schema when the server starts
shba24 e10be63
[Server] Name the baseline release once and refuse databases from bef…
shba24 3260601
[Server] Run the base commit's server jar in the upgrade tests, not a…
shba24 c43e2f1
[Build] Run the upgrade tests in their own path-filtered workflow
shba24 9e96446
[Server] Test upgrades along the release chain, with every column type
shba24 477b3eb
[Build] Build the base and release jars in the upgrade workflow
shba24 fd9b251
[Server] Test upgrades along every release from the baseline, each wr…
shba24 821059a
[Server] Address the review of the Flyway migration
shba24 35993c6
[Server] Leave the Helm chart to its own pull requests
shba24 f8f9f6c
[Server] Name UC's schema history table uc_schema_history and log whi…
shba24 f077d9d
[Server] Leave MySQL's collation to the startup warning for now
shba24 061f718
[Server] Refuse pre-0.7 databases by one table 0.7.0 added (stop-gap)
shba24 fc67536
[Server] Leave failed steps to Flyway's own check
shba24 6697235
[Server] Drop the hibernate.default_schema refusal
shba24 fc0903e
[Server] Drop the connection pool size check
shba24 57f1adb
[Server] Run the migrator on the caller's connection pool only
shba24 7d2ccab
[Server] Keep three server-start tests; MigratorTest covers the rest
shba24 172b4ee
[Server] Drop the test duplicating the not-a-UC-database case
shba24 fdff437
[Server] Take the build's version from VersionUtils in the upgrade tests
shba24 5b6d63f
[Server] Build old server jars only from their tags in the upgrade tests
shba24 c6abb52
[Build] Run the upgrade test in one job per database
shba24 16393fa
[Docs] Fold the first-start section of the upgrade guide into its intro
shba24 09a2eb5
[Server] Keep the upgrade test helpers package-private beside their t…
shba24 4005de2
[Server] Fold the release chain and jar build into OldServer
shba24 35e32bc
[Server] One migrate() entry point and a smaller run lock
shba24 6bcc21b
[Server] Stop on any run lock failure, and test the lock and failed s…
shba24 bbfee7a
[Server] Address the review of the trimmed Flyway migration
shba24 d4d1d2b
[Server] Migrate on the migrator's own pool and refuse Hibernate sche…
shba24 11c2f35
[Server] Run this commit's shaded jar in the upgrade test; drop the h…
shba24 a9adeb3
[Server] Refuse Hibernate's own schema settings and injected schema u…
shba24 f204822
[Server] Test two runs starting at once on an empty database, and a s…
shba24 3efb983
[Server] Bring back the in-JVM H2 run lock and test concurrent runs o…
shba24 6886e88
[Build] Run all tests on MySQL 8.4
shba24 fc98904
[Server] Return table columns in their declared order
shba24 34f8f62
[Server] Warn when a MySQL database compares text case-insensitively
shba24 b2cb4c3
[Build] Build MySQL test databases from a template, like PostgreSQL
shba24 bf6c7b1
[Server] Address review comments on the MySQL test harness
shba24 225f99f
[Server] Run the MySQL Delta commit tests through the shared harness
shba24 e233e6b
[Server] Inject test databases with @TempDatabase
shba24 1a96084
[Build] Pin the PostgreSQL and MySQL test images by digest
shba24 10c4cd7
[Build] Explain the test-only server settings of the MySQL and Postgr…
shba24 944a1dc
[Server] Explain the isolation-level test and the MySQL template's ha…
shba24 ff4e42d
[Build] Run the index-limit test on MySQL
shba24 7acb427
Merge main into stack/uc-flyway-schema
shba24 7964bdf
Merge stack/uc-mysql-suite (rebased #2044) into stack/uc-flyway-schema
shba24 faa1b12
[Docs] Say how to back up the database and find sessions holding locks
shba24 502e521
[Build] Clarify the test database harness comments
shba24 c5de03b
Merge stack/uc-mysql-suite (#2044): harness comment fixes into stack/…
shba24 41fb10e
[Server] Check each database's isolation level in the lock re-read test
shba24 5df45ca
Merge stack/uc-mysql-suite (#2044): per-database isolation check into…
shba24 6c0d604
[Build] Run all tests on MySQL 8.4
shba24 cc70790
[Server] Return table columns in their declared order
shba24 d63d59e
[Server] Warn when a MySQL database compares text case-insensitively
shba24 4b2a438
[Build] Build MySQL test databases from a template, like PostgreSQL
shba24 1fe089f
[Server] Address review comments on the MySQL test harness
shba24 e08c15b
[Server] Run the MySQL Delta commit tests through the shared harness
shba24 ea0ad3b
[Server] Inject test databases with @TempDatabase
shba24 fd79c58
[Build] Pin the PostgreSQL and MySQL test images by digest
shba24 39d29f6
[Build] Explain the test-only server settings of the MySQL and Postgr…
shba24 b859fc3
[Server] Explain the isolation-level test and the MySQL template's ha…
shba24 4efa2fb
[Build] Run the index-limit test on MySQL
shba24 a4092d0
[Build] Clarify the test database harness comments
shba24 3ee212e
[Server] Check each database's isolation level in the lock re-read test
shba24 b41d526
Bridge old #2044 head
shba24 505a3de
Merge stack/uc-mysql-suite (rebased #2044) into stack/uc-flyway-schema
shba24 2ec4ce9
[Server] Describe the MySQL collation without claiming names are case…
shba24 ba61cf5
[Build] Drop the half-built MySQL database when cloning the template …
shba24 3eacb82
[Server] Submit the function parameters out of position order in the …
shba24 421f6d9
[Server] Leave the derived-table DELETE note to DeltaCommitRepository
shba24 f842166
Merge stack/uc-mysql-suite (#2044): review fixes into stack/uc-flyway…
shba24 f000906
[Build] Fail a MySQL test that leaks a transaction instead of hanging…
shba24 b2c9fdf
Merge stack/uc-mysql-suite (#2044): MySQL lock wait timeout into stac…
shba24 469b6fd
[Server] Do not fail startup when the MySQL collation check throws
shba24 ebec639
[Server] Warn about case-insensitive MySQL by reading the columns' co…
shba24 b7d444e
Merge stack/uc-mysql-suite (#2044): collation check into stack/uc-fly…
shba24 627bfc4
[Server] Tidy the MySQL collation check and document converting an ex…
shba24 bd44bb2
Merge stack/uc-mysql-suite (#2044): collation check tidy into stack/u…
shba24 f17599e
Merge main into stack/uc-flyway-schema
shba24 a9cc3e7
Merge main into stack/uc-flyway-schema
shba24 251da42
[Server] Accept jdbc:mysql+srv: URLs and drop an untracked TODO
shba24 9958ebb
[Server] Refuse schema-changing Hibernate settings before Hibernate r…
shba24 e56a084
[Server] Also refuse schema actions from JVM properties and contribut…
shba24 92cd662
[Server] Refuse a default schema from JVM properties too; say the run…
shba24 abadd24
[Server] Drop the explicit cleanDisabled(true) that Flyway 13.10.3 al…
shba24 fe3f8ec
[Server] Restore the hbm2ddl.auto=none line in ManagedTableCleanupTas…
shba24 c5811c0
[Server] Run the pool-by-data-source-class migration test on PostgreS…
shba24 ada162f
[Server] Merge the two run-lock refusal tests into one parameterized …
shba24 aec18e0
[Server] Drop the schema-newer test from SchemaGateTest; MigratorTest…
shba24 5d31c3f
[Server] Test that a database whose driver reports another product is…
shba24 fdf3c05
[Server] Use java.lang.reflect.InvocationHandler for the test proxies
shba24 dee7796
[Server] Name the run lock SQL per database and use if/else for the s…
shba24 30a68ec
[Server] Split SchemaSnapshot.read and OldServer.run into named steps
shba24 4cc2e66
[Server] Shorten the migration test waits to 30 seconds and 1 minute
shba24 93d7f33
[Server] Set hbm2ddl halt-on-error to false only for MySQL in the bas…
shba24 3ead898
[Server] Keep the upgrade test's storage in a temp directory, not /tm…
shba24 1c8b236
[Server] Check the MySQL collation after the schema migration, so a f…
shba24 f3a2ef9
[Server] Fix migration docs and comments: name the upgrade test, drop…
shba24 6493f61
[Server] Rename MigratorTest to SchemaMigratorTest, and the baseline …
shba24 d9f4f80
[Server] Make the baseline test stop on entity DDL errors except on M…
shba24 fe2b66f
[Server] Re-wrap two test comments broken mid-sentence
shba24 df5e590
[Server] Rename SchemaMigrator.BASELINE_RELEASE to ADOPTED_RELEASE
shba24 ce1fc10
[Server] Document that the MySQL run lock is not shared across primaries
shba24 96c9dcf
[Server] Refuse H2 in server mode for the schema migration
shba24 134c444
[Server] Refuse every form of H2 server mode, and drop a stray test d…
shba24 a3de3e4
Merge main into stack/uc-flyway-schema
shba24 b8b8c39
[Server] Give KeyMapperTest a database built by the schema steps
shba24 a80afaa
[Server] Read only the configured schema's tables when classifying th…
shba24 ae832c1
[Helm] Stop rendering hibernate.hbm2ddl.auto=update
shba24 c5f0e52
[Server] Write the baseline step so that it can run again
shba24 a8ebffc
[Server] Run the schema steps only through bin/start-uc-server --upgr…
shba24 4902709
[Server] Leave the real-release upgrade tests to the pull request tha…
shba24 aa4b529
[Docs] Describe the schema steps as an optional command run by hand
shba24 bbc8ae7
[Server] Test that --upgrade-schema refuses a database with a failed …
shba24 dfe0306
Merge main into stack/uc-flyway-schema
shba24 19dc3f4
[Server] Name the clashing table when a step's index is missing
shba24 0e12be7
[Server] Describe what --upgrade-schema does now, and refuse unsafe c…
shba24 1d1bf0a
[Server] Refuse a missing step index, an escaped AUTO_SERVER and jdbc…
shba24 f1a82bc
Merge main into stack/uc-flyway-schema
shba24 3f24789
Merge main into stack/uc-flyway-schema
shba24 2d909b9
[Server] Refuse Unity Catalog tables that the search_path reaches later
shba24 3889418
[Server] Give the index-clash refusal a recovery that works
shba24 e2c270b
[Server] Pin the index-clash recovery in its test
shba24 3bb7bd0
[Server] Drop the unknown-product refusal test
shba24 4eb147b
[Docs] Restore main's MySQL collation paragraph
shba24 315b331
[Server] Drop the unused serverSetting parameter in SchemaGateTest
shba24 89edc7e
[Server] Make indexClashHint private
shba24 fee217f
[Docs] Correct three upgrade-schema claims
shba24 25ddcfb
[Server] Trim comments that restate the code
shba24 69f5961
[Server] Read H2's AUTO_SERVER as on only for H2's true values
shba24 be138b9
[Server] Upgrade the current schema when a later schema has an old copy
shba24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # Upgrading the database schema | ||
|
|
||
| Unity Catalog uses [Flyway](https://flywaydb.org/) to manage the schema of its database. Each | ||
| release ships the schema steps it needs, and each step is applied once and recorded in the | ||
| `uc_schema_history` table. | ||
|
|
||
| For now the schema steps are optional, and you run them by hand. The server still lets Hibernate | ||
| update the schema when it starts (`hibernate.hbm2ddl.auto=update` in | ||
| `etc/conf/hibernate.properties`). The steps build the same schema, so on a database that the steps | ||
| set up, Hibernate changes nothing. | ||
|
|
||
| `bin/start-uc-server --upgrade-schema` brings the database to the schema version of its release, | ||
| then exits without starting the server: with 0 when it succeeds, and with 1 and the reason when it | ||
| refuses. It sets up an empty database (a new install) and applies the steps that are not applied | ||
| yet. It refuses a database that has Unity Catalog's tables but no schema history, such as one that | ||
| a server set up when it started. | ||
|
|
||
| ## Upgrading to a new release | ||
|
|
||
| Run the commands with the new release. | ||
|
|
||
| 1. Stop all servers. | ||
| 2. Back up the database (see [Backing up the database](#backing-up-the-database)). | ||
| 3. Upgrade the schema: | ||
|
|
||
| ```sh | ||
| bin/start-uc-server --upgrade-schema | ||
| ``` | ||
|
|
||
| It applies the pending steps and logs what it applied. | ||
|
|
||
| 4. Start the new release: | ||
|
|
||
| ```sh | ||
| bin/start-uc-server | ||
| ``` | ||
|
|
||
| On PostgreSQL and MySQL, `--upgrade-schema` takes a lock, so when several run at the same time, one | ||
| applies the steps and the others wait for it. It holds that lock on one database session for the | ||
| whole run, so connect to the database directly or through a pooler in session mode, not in | ||
| transaction mode (PgBouncer's `pool_mode = transaction`): there the lock can be released on | ||
| another session, and the command fails. | ||
| On MySQL the lock is a named lock (`GET_LOCK`), which Group Replication in multi-primary mode does | ||
| not share between primaries: there, run `--upgrade-schema` on one host only. | ||
|
|
||
| A step waits for locks that other sessions hold on its table, for example an open transaction of | ||
| a reporting tool. If `--upgrade-schema` stays at a step for long, look for such sessions and end | ||
| them: `SELECT pid, state, query FROM pg_stat_activity WHERE datname = current_database()` on | ||
| PostgreSQL, `SHOW PROCESSLIST` on MySQL. | ||
|
|
||
| ## Backing up the database | ||
|
|
||
| Take the backup with all servers stopped, so that it holds no half-written change. The examples use | ||
| the database `ucdb`. | ||
|
|
||
| - PostgreSQL: `pg_dump -Fc -d ucdb -f uc-backup.dump`. To restore it, create an empty database and | ||
| run `pg_restore -d ucdb uc-backup.dump`. | ||
| - MySQL: `mysqldump --single-transaction --databases ucdb > uc-backup.sql`. To restore it, drop the | ||
| database and run `mysql < uc-backup.sql`. | ||
| - H2: copy the database file, `etc/db/h2db.mv.db` with the default | ||
| `hibernate.connection.url`. To restore it, copy it back. | ||
| - A managed database (for example Amazon RDS or Cloud SQL): a snapshot of the instance works too. | ||
|
|
||
| ## Messages | ||
|
|
||
| Messages that `--upgrade-schema` prints when it refuses, and what to do. | ||
|
|
||
| `The database's schema history does not match this release's schema steps: <reasons>` | ||
| : Flyway's check of `uc_schema_history` failed, for example because a recorded step differs from | ||
| this release's step of the same version (its checksum), or this release lacks a recorded step. | ||
| `<reasons>` may advise Flyway's `repair` command, which Unity Catalog doesn't have. Run the release | ||
| that applied the steps, or restore the backup. Do not edit `uc_schema_history` by hand. On H2 and | ||
| MySQL, a step that failed is reported here too: this release can't retry it, so restore the backup | ||
| and fix the cause, then run the command on the restored database. On PostgreSQL, a failed step | ||
| leaves no history row, so the command runs it again. | ||
|
|
||
| `Step <n> left Unity Catalog index <index> missing on <table>: <hint>` | ||
| : On PostgreSQL and H2, index names are unique within a schema, so the step skipped Unity Catalog's | ||
| index because another object, such as another table's index, already has that name. The step is | ||
| recorded as applied, so renaming the other index and running the command again does not create | ||
| Unity Catalog's index. | ||
| Restore the backup (on a new install, drop the `uc_*` tables and `uc_schema_history`), rename the | ||
| other index or give Unity Catalog its own schema, then run the command again. | ||
|
|
||
| `Could not take the schema migration lock: <reason>` | ||
| : The command could not get the lock that keeps two migration runs apart, so it changed nothing. | ||
| Check that the database is reachable and that its user can run the lock call | ||
| (`pg_advisory_lock` on PostgreSQL, `GET_LOCK` on MySQL), then run the command again. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.