Skip to content

[Server] Back up the database before the schema upgrade and restore it on failure - #2052

Closed
shba24 wants to merge 89 commits into
unitycatalog:mainfrom
shba24:stack/uc-flyway-backup
Closed

shba24 wants to merge 89 commits into
unitycatalog:mainfrom
shba24:stack/uc-flyway-backup

Conversation

@shba24

@shba24 shba24 commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


PR Checklist

  • 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.
  • 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

Reviewing: this PR's own changes are shba24/unitycatalog@stack/uc-flyway-bad-row-checks...stack/uc-flyway-backup. GitHub's Files changed tab also shows #2009, #2044, #2045, #2046, #2051, #2047, #2050, which this PR builds on, until they merge.

With server.migration.backup=true, the server copies the whole database before the schema upgrade changes anything, and puts the copy back if the upgrade fails, so the previous release can start again. Off by default.

  • Turning it on: server.migration.backup=true in server.properties. It needs a database user that can create and drop databases (PostgreSQL: the owner with CREATEDB), room for a full copy on the same database server, and, for H2, a file database (in-memory H2 is refused while it's on).
  • When: under the run lock, after the refusals, failed-step recovery and bad-row checks (a refused upgrade takes no copy), before the first change. Only when something is pending. A database part-way through this release's steps keeps its existing copy; otherwise an old copy is dropped and a fresh one taken. After a successful upgrade (steps applied, schema check passed) the copy is dropped.
  • How, per database (every table, including the schema history and Casbin's table):
    • PostgreSQL: CREATE DATABASE <db>_uc_backup TEMPLATE <db>; restore DROP DATABASE <db> and rename the copy back. The pool's connections to <db> are closed first and the run lock moves to the companion database <db>_uc_upgrade. Another connected session (an old server still running) fails the run before any change, saying to stop the other servers.
    • MySQL: a sibling database <db>_uc_backup, each table re-created from SHOW CREATE TABLE and filled in one consistent snapshot; restore drops the upgraded tables and moves the copies back with RENAME TABLE (foreign keys point at <db> again).
    • H2: the database file is copied with the database shut down; restore puts it back.
  • Restore when: a step fails, the schema check after the steps fails, or SIGTERM stops the migration (the restore finishes before the process exits; the grace period must cover 60 seconds plus the restore). The start then fails with what went wrong and "The database was restored from the backup taken before the upgrade; the previous release can start on it."
  • Restored mark (Helm): when UC_CHART_REVISION is set, a restore writes a mark in the companion database (H2: a file next to the database) naming the release and chart revision. A later start of the same release and revision refuses instead of restoring in a loop; a new revision clears the mark. Without UC_CHART_REVISION no mark is written: a person reruns by hand.
  • Docs: docs/server/upgrades.md "Backup before the upgrade": requirements, a failed upgrade, stopping during a restore (and restoring by hand), the mark with Helm; five new message entries.

Testing

BackupTest on H2, PostgreSQL 18 and MySQL 8.4, with test-only steps on their own tables (migrate.*: H2 70 passed, PostgreSQL 72, MySQL 72; skipped tests are for other databases):

  • A step fails after one succeeded → the schema, a seeded table's rows and the schema history equal the pre-upgrade state; no copy left; on MySQL the foreign keys point at the restored tables.
  • The schema check fails after the steps → restored the same way.
  • With a chart revision: the mark is written; the same revision is refused with nothing changed; a new revision proceeds and clears the mark.
  • At the previous release a fresh copy is taken; part-way through this release the existing copy is reused.
  • After success the copy is dropped. In-memory H2 with the backup on is refused. PostgreSQL with another session connected fails before any change.
  • DataStepTest.serverRestoresTheBackupOnSigterm (PostgreSQL, MySQL): a child server JVM gets SIGTERM during a batch and restores before it exits.
  • Tests that passed before the code existed were each shown to catch a deliberate break (no drop after success; forced reuse; forced fresh copy; a 1 ms SIGTERM wait).

From the final review (each finding reproduced first): the MySQL restore is one atomic RENAME TABLE (the live tables move to <db>_uc_trash, the copies back), so a restore that fails partway changes nothing; a copy is never dropped while the live database lacks its tables. Copies are marked complete (uc_backup_complete) as their last statement, and an incomplete copy is never reused or restored. PostgreSQL copies are built as <db>_uc_backup_part and carry the database's owner, connection limit, grants and ALTER DATABASE … SET settings. SIGTERM after the last step still restores. The restored mark lives in public.uc_restored (works with currentSchema). The run lock's own connection has no lock-wait cap; --check-schema takes the lock the same way as a server with the same backup setting. A backup is reused only while this release's own steps are part-way applied (a clean 0.7.5 database gets a fresh copy).

📐 Design notes & details

Why off by default. UC doesn't own its database; the copy needs a user that can create and drop databases and room for a full copy.

Why restore only while the servers are stopped. Writes since the copy are lost on restore; the upgrade guide stops all servers first. After a successful upgrade nothing is restored automatically: new servers may already have written data.

Why the PostgreSQL lock moves to a companion database. CREATE DATABASE … TEMPLATE and DROP DATABASE need no other session on <db>, including the lock's.

Why a separate Backup class. The per-database copy, restore and mark code is about 670 lines; inside SchemaMigrator it would nearly double that class.

Known limits. If the process is killed with SIGKILL during a restore, the guide gives the manual restore per database. A partial MySQL copy left by a SIGKILL during the copy is dropped by the next run with the backup on, unless that run finds the database part-way through this release's steps.

Not in this PR: the Helm values that turn it on and set UC_CHART_REVISION (the Helm PR at the top of this stack).

This pull request and its description were written by Isaac.

shba24 and others added 30 commits October 25, 2026 01:53
Adds MySQL 8.4 to the test database harness (testMySQL8) and a CI job. Test
databases use the case-sensitive utf8mb4_0900_bin collation. The isolation
test now reads the database's default level instead of assuming
READ_COMMITTED.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Without an ORDER BY, MySQL returned columns (and function parameters) in
its own order.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Storage paths and names are case-sensitive, but MySQL's default collation is
not. Log a warning at startup and document the utf8mb4_0900_bin collation.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
MySQL and PostgreSQL now share one harness: Hibernate builds the schema once
per JVM into a template and each test clones it. Both containers keep their
data in memory with durability off.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Fix harness comments and docs, assign the cached database only after it
started, drop duplicate test dependencies, request a different isolation
level in the restore test, check the MySQL template has every mapped
table, and cover parameter order in the function CRUD test.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
The MYSQL_8 CI row runs SdkDeltaCommitsCRUDTest on MySQL, so the class that started its own MySQL container is no longer needed. Its lock-reading test moves into SdkDeltaCommitsCRUDTest and runs on every database.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
A @TempDatabase field gets a fresh TestDatabase, per test for an instance field and per class for a static one. The extension stores it in the JUnit store, which closes it after every @AfterEach, so a test's server always closes before its database is dropped, and a failing setUp still drops it.

TestDatabase no longer takes a ServerProperties (it overwrote everything the properties set) and offers hibernateProperties(), hibernateConfigurator() and sessionFactory(). All tests that made their own database now use the annotation.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…eSQL containers

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…lt_on_error

The isolation test asks for a level other than the default, because asking for
the default would pass even if nothing were restored. The MySQL template keeps
halt_on_error off only for the one index InnoDB rejects; a TODO removes it once
the schema migration steps build the template.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Adds Flyway 13.10.3, the V1 baseline of the 0.7 schema and V2 (type_json
widening) for H2, PostgreSQL and MySQL; empty test databases,
@TempDatabase and TestDatabase.dataSource()/kind() in the harness; and a
schema snapshot check that the steps build the schema the entities
expect.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Adds Migrator, which classifies a database (empty, current, pending,
newer than this release, an unversioned 0.7 database, not a Unity Catalog
database, failed step) and, under a run lock, sets up an empty database,
adopts a 0.7 one (version 1 recorded as the baseline) and applies the
pending steps. The run lock is pg_advisory_lock on PostgreSQL, GET_LOCK on
MySQL and an in-process lock per database file on H2. bin/uc-migrate runs
`migrate` and `info` against the database in etc/conf/hibernate.properties.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…ases with Flyway

The server sets up an empty database itself (a second server starting at the
same time waits on the run lock) and refuses any other schema version with a
message that names the fix. Hibernate never alters the schema: hbm2ddl.auto is
forced to none, even if an old hibernate.properties says update.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…ases

Adds V3. On MySQL it converts the database and every Unity Catalog table
(and casbin_rule, when it exists) to utf8mb4_0900_bin, so a database
created with MySQL's case-insensitive default compares names and storage
paths like PostgreSQL and H2. Converting is safe to repeat, so the step
holds several statements. On PostgreSQL and H2, V3 does nothing.

The startup collation warning skips Flyway's history table, which keeps
the database's original collation. Test-only steps move to version 1000
and tests read the latest version instead of hard-coding it.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Every test database now gets its schema from Migrator, never from
Hibernate DDL: the PostgreSQL and MySQL templates are migrated once, and
each H2 test database is migrated when it is created. Hibernate runs
with hbm2ddl.auto=none in every test.

MySQL clones now also copy the template's rows (Flyway's history), as
PostgreSQL's TEMPLATE does, so a clone is at the current version. The
MySQL template no longer needs halt_on_error=false or the check that
every mapped table exists: Flyway stops on any failed statement.
PopulateTestDatabase migrates its database before opening it.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Describe how Flyway manages the schema, how to upgrade without Helm with
bin/uc-migrate, the first start on an empty database, the MySQL
case-sensitivity change, going back to 0.7, and each error message with what
to do. Replace the outdated Hibernate auto-update paragraph in the deployment
guide with a link to the guide.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
- The server and bin/uc-migrate print the same refusal for a foreign,
  newer or failed schema (Migrator.refusal); "Stop the servers and run
  bin/uc-migrate migrate" is kept for a 0.7 or pending database.
- bin/uc-migrate runs from the repository or tarball root, so it reads
  etc/conf/hibernate.properties from any directory; it exits 1 when it
  finds neither, and builds a missing classpath file.
- The MySQL run lock is per database, not per MySQL server.
- Flyway fails on missing step locations; a jar without steps says so.
- uc-migrate reuses the server's Hikari settings.
- The shaded server jar keeps META-INF/services (merged), so Flyway
  finds its database support in connector tests.
- The Helm chart no longer sets hibernate.hbm2ddl.auto=update.
- Tests: release-to-release upgrade, casbin_rule conversion on MySQL,
  server properties always turn Hibernate schema updates off.
- Docs: messages say who prints them; going back to 0.7 needs no
  restore; waiting applies to PostgreSQL and MySQL.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…6 via 0.7

RealUpgradeTest runs real server images on each UpgradePath and test
database: the first image writes a data set through the API with
authorization on, later images just start, then the current server
refuses the database until Migrator.migrate() upgrades it to the fresh
install schema, and the data reads back.

The test kit gains AcrossUpgradePaths, UpgradePath (BASE built from
UC_TEST_BASE_REF by dev/build-image.sh, LATEST, V0_6_VIA_0_7), OldImage,
OldServer and DataSet. The tests are tagged "upgrades": the default test
and coverage runs leave them out, and testUpgrades,
testUpgradesPostgres18 and testUpgradesMySQL8 run them, also in a new CI
job.

Real 0.7 databases showed that Hibernate's auto-update names the unique
constraints of uc_columns, uc_delta_commits and uc_properties, so the H2
and PostgreSQL baselines now name them the same way, and the baseline
check builds its reference schema with "update", as 0.7 installs did.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
The classpath file used by bin/start-uc-server and bin/uc-migrate listed both
server/target/classes and the server jar, so Flyway found every migration step
twice ("Found more than one migration with version 1") when running from a
source checkout or the Docker image. The jar holds the same classes.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
etc/db/h2db (the quickstart database) was created before 0.7 and had 10 of the
0.7 schema's 18 tables; older servers added the rest at startup with Hibernate
auto-update, which this release turns off, so the server refused it.

Upgraded the way a user upgrades: started v0.7.0 on it once (its auto-update
added the missing tables), then ran bin/uc-migrate migrate (0.7 baseline, then
steps 2 and 3). The sample data is unchanged.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
MigrationOutcome, SchemaState and DatabaseKind become nested types of
SchemaMigrator, and RunLock a private nested class. No behaviour change.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Every server start now sets up an empty database, adopts a database
without schema history and applies the pending steps, under the run lock;
it still refuses a newer, foreign or failed schema. Every start path
(bin/start-uc-server, the Docker image, a Helm pod) goes through it, so
bin/uc-migrate and UcMigrate are removed. The upgrade guide describes the
new procedure: stop the servers, back up the database, start the new
release.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…ore it

SchemaMigrator.BASELINE_RELEASE (0.7.0) is the one place the baseline
release is named; messages use it and comments say "the baseline
release". Before adopting a database without schema history, the
migrator checks that it has every table the baseline step creates, and
otherwise refuses it, naming the missing tables: such a database is from
an earlier release, which has to be started on 0.7.0 once first. The
upgrade guide says so.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
… built image

UpgradePath.BASE now runs the base commit's shaded server jar as a child
process on the test database, so the upgrade tests build no Docker image
(dev/build-image.sh is removed). The jar comes from UC_TEST_BASE_JAR, the
local cache ~/.cache/uc-upgrade-base/<sha>.jar, or is built once there
from git archive. CI saves the jar of every main commit in the Actions
cache and the upgrade job restores the one of the merge commit's first
parent; the job runs only when schema-related paths change. Published
releases keep their Docker Hub images, now pinned by digest; the moving
"latest" path becomes a pinned V0_7.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Move the upgrade tests out of unit-tests.yml into upgrade-tests.yml, which runs only
when a change touches the schema, its migration code or the upgrade test kit. A base-jar
job builds the server jar of the commit the PR starts from and shares it as an artifact.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
The upgrade tests now have two paths, and every old server is a server jar run
as a child process (no release images, no Docker container mode):

- BASE: the jar of the code this change starts from (UC_TEST_BASE_REF).
- RELEASE_CHAIN: one jar per release, oldest first, from the release tags:
  strict vX.Y.Z, from SchemaMigrator.BASELINE_RELEASE up to, not including,
  this build's version, latest patch per minor. UC_TEST_RELEASE_CHAIN sets the
  tags (CI computes them once); unset, the kit computes them from git.

Each jar is found by its commit: UC_TEST_JAR_DIR/<sha>.jar, else
~/.cache/uc-upgrade-base/<sha>.jar, else built once from that commit and
cached. This replaces UC_TEST_BASE_JAR.

The first jar writes the data set; every later jar reads it back, then the
current server upgrades the database and reads it back; failures name the
server that read it. The data set now has one column (and one function
parameter) per column type, with every field set, and is compared as whole
objects, ignoring only the fields a server fills in itself. The managed table
is Delta, whose columns can't have the types Delta lacks (interval, void,
user-defined, table), so it has the other 18; the external table is Parquet
and has all 22.

Dropped: V0_7, V0_6_VIA_0_7 and the pinned release images.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
A refs job picks the base commit (the merge commit's first parent) and the
release chain from the tags; a build-jars matrix builds each one's server jar
and uploads it as jar-<sha>; the upgrade tests download them all and find each
by its commit through UC_TEST_JAR_DIR.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…iting its own data

The upgrade test now takes one path: every release tag from the baseline
release up to this build's version, in version order (not only the latest
patch of each minor), then the current server. Each release writes its own
copy of the data set, named for the release (catalog, user email, sibling
storage directories); the current server checks the schema against a fresh
install and reads every copy back. The path from the PR's base commit is
gone, with its jar in CI: unreleased code never writes a user's database.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
shba24 and others added 2 commits October 25, 2026 10:41
… check its whole schema

etc/db/h2db was first created by a release before 0.4.1, so its CHECKs on
uc_function_params.type_name and uc_functions.data_type still allowed
column types 0..20 (VARIANT, 21, came in 0.4.1), and the name columns of
uc_catalogs, uc_schemas, uc_tables and uc_volumes were nullable. The schema
check on start refused it, so bin/start-uc-server failed on the sample
database and with it the Python client tests.

The repair widens the two CHECKs to 0..21 under their existing names and
makes the four name columns NOT NULL (no row has a NULL name). Data and
schema history rows are unchanged. SampleDatabaseIsCurrentTest now also
compares the sample database's whole schema with the H2 dump of a fresh
install, so drift in it fails a test instead of the server start.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…d sample database

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
shba24 added a commit to shba24/unitycatalog that referenced this pull request Oct 25, 2026
shba24 and others added 15 commits October 25, 2026 11:11
…r's pool

The server's pool doesn't autocommit (Hibernate manages transactions), and
the migration took its connections from it. On PostgreSQL the lock-wait SET
then opened a transaction, so a bad-row check's setReadOnly(true) failed
("Cannot change transaction read-only property in the middle of a
transaction") and every check refused the start. A statement run on such a
connection outside Flyway would also never be committed.

connection() now sets autocommit before the SET, as the backup's connections
do; a check still runs in its own read-only transaction. Flyway gets the same
autocommit connections the tests always gave it. The new test runs the checks
and the upgrade on a pool built like the server's.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…plete copies

The MySQL restore dropped the database's tables one by one, then moved
the copies back. A restore that failed partway (a lock a client held
past the lock-wait cap) left dropped tables, and the next start, seeing
a database at the previous release, dropped the only good copy and
backed up the gutted database.

- The restore moves the database's tables to <db>_uc_trash and the
  copy's tables back in one RENAME TABLE, which MySQL runs whole or not
  at all, then drops the trash and the copy.
- The copy is complete once it has the table uc_backup_complete, the
  last statement of the copy. A copy without it (a server killed or
  disconnected while copying) is replaced at the previous release and
  refused partway through the steps, instead of being restored over the
  database.
- A complete copy that has tables the database lacks is never dropped:
  the start refuses and names the copy.

PostgreSQL's CREATE DATABASE and H2's .part file plus atomic move are
whole or nothing, so their copies need no mark.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
The type-change probe compared only the type and size, so a step that
restates them and changes something else was recorded without running: a
MySQL MODIFY c varchar(64) NOT NULL over a nullable varchar(64), or a
PostgreSQL ALTER COLUMN c TYPE varchar(64) COLLATE "C".

The probe now recognises a type change only when nothing but NULL or NOT NULL
follows the type; any other clause (DEFAULT, COLLATE, CHARACTER SET, USING,
...) gets no probe, so the step runs. A NULL or NOT NULL must match the
column's nullability. MySQL's MODIFY and H2's ALTER COLUMN c <type> restate
the column: they drop its default, and MySQL's makes it nullable unless it
says NOT NULL, so for them the column must also have no default, and on MySQL
be nullable when the statement says nothing.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
The run checks for SIGTERM before each step and between a data step's
batches, but not after the last step. SIGTERM during the last step let
the run pass the schema check and drop the backup, so the process
exited with the upgraded database and no backup, although the docs
promise a restore.

The run now checks once more after the steps and the schema check,
before it drops the backup, and restores when a stop was requested.
The new test sends SIGTERM to a server process during a slow last SQL
step (PostgreSQL and MySQL; H2 has no sleep function).

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…tore

CREATE DATABASE ... TEMPLATE copies the tables, not the database's own
attributes, and the restore renames the copy in place of the dropped
database. A restore therefore lost ALTER DATABASE ... SET settings (a
search_path that selects UC's schema among them, after which the
previous release sees an empty catalog), ALTER ROLE ... IN DATABASE
settings, GRANTs on the database, its owner and its connection limit.

The backup now creates the copy as <db>_uc_backup_part, gives it those
attributes of <db>, then renames it to <db>_uc_backup, so a copy under
the backup's name is always complete. A copy restored by hand keeps
them too. List settings such as search_path are re-quoted element by
element, as pg_dump does.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
… in the URL

Connections to the companion database <db>_uc_upgrade take the
server's URL, parameters included. With ?currentSchema=uc there, the
companion has no such schema, so creating or reading the restored mark
failed ("no schema has been selected to create in") and, with
UC_CHART_REVISION set, every start with the backup on refused.

The mark's table is now public.uc_restored on PostgreSQL.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…set step

The release before this build's was the highest listed release below it. A
patch release without steps of its own then moved it: with 0.7.0=1, 0.8.0=3
and 0.8.1=3, a 0.8.2 build refused a 0.7.0 database and a 0.8.0 upgrade that
stopped midway ("Upgrade to 0.8.1 first"), and no step was this release's, so
the every-start schema check compared no table.

The release before is now the first listed release of the minor line before
this build's: any release of that line, or a later one such as an earlier
patch of this build's own line, upgrades, and this release's steps are those
above that release's last step. This follows the project's policy of testing
upgrades from the latest patch of each minor line. The refusal names the
line: "... upgrades only from 0.7.0 or a later 0.7 release (version 3 or
later). Upgrade to the latest 0.7 release first, ...". upgrades.md and the
releases.properties header say so.

MySQL's step 3 converts the character set of every table, which made every
table one this release changes, so the every-start check refused, for
example, an index a DBA added to uc_catalogs. A statement that changes only a
table's character set or collation (not compared by the schema check) no
longer counts as changing the table.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
… like the start

- PostgreSQL applies lock_timeout to advisory-lock waits too. With the
  backup on, the run lock is taken on a companion connection that has
  the run's 60-second lock wait, so a second starting server failed
  ("canceling statement due to lock timeout") instead of waiting, as
  upgrades.md says it does. A pooled connection can keep an earlier
  run's lock wait as well. The run lock's connection now sets
  lock_timeout = 0 before it waits.
- bin/start-uc-server --check-schema ignored server.migration.backup,
  so on PostgreSQL it locked <db> while a start with the backup on held
  the lock in <db>_uc_upgrade: the two didn't exclude each other. It
  now turns the backup on from the same setting, taking the lock where
  the start does. upgrades.md says to give every server of a database
  the same setting.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…ty H2 mark file

- --check-schema with the backup on now prints the restored mark's
  refusal and exits 1 when a start of this release in this chart
  revision would refuse. It exited 0 ("The upgrade would go through")
  while every start refused.
- An H2 mark file without its release or revision (a crash while
  writing it) is no mark. It threw a bare NullPointerException on every
  start.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…e probe

The add-column probe also matched ALTER TABLE t ADD UNIQUE (c), ADD PRIMARY
KEY, ADD INDEX and the like, taking the keyword for a column name. It then
reported the change as absent instead of "can't tell", so a failed step of
that form whose change was there was run again: an unnamed unique key was
added twice, and a named index failed again on every start.

These forms now get no probe: a failed one is refused with the "can't tell"
message, a pending one runs.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Conflicts: SchemaMigrator type-change probe keeps the Optional return with
the new end-anchored regex and the nullable/restates hasType arguments;
StepAlreadyInDatabaseTest keeps both test-step directories.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Conflict: BadRowCheckTest imports. SchemaSnapshot is in the migrate package
on this branch, so the kit import goes; the HikariDataSource and
HibernateConfigurator imports of the new pool test stay.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Conflict: SchemaMigrator.connection() keeps the autocommit fix and this
branch's static lockWaitSql(kind, lockWait).

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
… new rule

The release before this build's is now the first listed release of the
minor line before it. BackupTest's map 0.7.0=1, 0.7.5=6000 then made 0.7.0
(version 1) the release before, so a database at 6000 counted as partway
through this release's steps: takesAFreshBackupAtThePreviousRelease reused
the older copy and lost the row written after it. The map is now
0.6.0=1, 0.7.0=6000, which keeps version 6000 as the last step of the
release before this one, as the tests intend.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…way applied

A start with the backup on keeps a copy that is already there only when the
database is partway through this release's steps. That check used the
threshold of the skipped-release rule: the last step of the first release of
the minor line before this build's. With releases 0.6.0=1, 0.7.0=3 and
0.7.5=6000, a clean 0.7.5 database at 6000 counted as partway through an
0.8 upgrade. A complete leftover copy (an earlier upgrade whose drop failed)
was then reused, and a failed upgrade restored it, losing the rows written
after it; an incomplete one made the start refuse.

The check now uses the latest release listed before this build's, the one
the database was at before the upgrade started. The skipped-release refusal
keeps the minor-line threshold.

BackupTest covers a database at 0.7.5's last step with an older copy: the
upgrade fails and the restore brings back the current rows.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
shba24 added a commit to shba24/unitycatalog that referenced this pull request Oct 25, 2026
Conflicts in SchemaMigrator: the class comment keeps the adoption paragraph
and takes the minor-line release rule; checkSchema checks the restored mark,
then the release rule, then lists the adoption's drifts; the backed-up run
passes the drifts to upgrade() and stops at the end of the upgrade on SIGTERM.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
shba24 added a commit to shba24/unitycatalog that referenced this pull request Oct 25, 2026
… mid-upgrade

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24

shba24 commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

Closing this draft. Its code is kept as a reference on ref/pr6-backup; the schema upgrade work continues in smaller pull requests built from it, starting with #2045 and #2046.

@shba24 shba24 closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant