Skip to content

[Server] Follow-ups to the schema upgrade retry - #2285

Merged
yili-db merged 11 commits into
unitycatalog:mainfrom
shba24:stack/uc-upgrade-retry-followups
Nov 19, 2026
Merged

yili-db merged 11 commits into
unitycatalog:mainfrom
shba24:stack/uc-upgrade-retry-followups

Conversation

@shba24

@shba24 shba24 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-ups to #2114 from its review, which came in after it merged.

  • A failed schema step whose script was edited after it failed is now refused, not retried. Flyway reports a failed step before it compares checksums, so the retry also forgave an edited step and recorded it with the new checksum; the edit was never reported. The history check now compares the stored checksum with the step's before it lets the step run again. A published step is never changed: a fix for a failed step ships as a new step.
  • When the migrator can't restore a connection's auto-commit setting, it discards the connection with a warning, so no pool hands it out again with the wrong setting: through the pool when the connection is Hikari's own or unwraps to it (evictConnection), otherwise by aborting it and closing the connection underneath (H2's abort does nothing). Hikari, which the server uses, resets the setting itself on close.
  • Cleanup never replaces the outcome of the failed-record delete: a failed delete reports its own error, and a failure while restoring the setting or closing the connection does not fail a delete that worked.
  • RunLock.close() restores the connection's auto-commit setting only after a successful unlock. When the unlock fails, it discards the connection straight away and never touches it again.
  • A caller's DataSource that wraps a Hikari pool gets the same eviction: the migrator unwraps the connection to Hikari's own before evicting it.

Tests

  • SchemaMigratorTest.keepsTheRecordOfAFailedStepWhenTheRunRefuses has a new row, EDITED_FAILED_STEP. It failed before the fix and passes after.
  • New SchemaMigratorTest.cleansUpTheConnectionWhenItCannotBeRestored, one row per ConnectionState:
    • HEALTHY and BROKEN: a Hikari pool where the restore fails on a working or an already lost connection. The pool evicts the connection (no abort), the database connection underneath gets closed, and the pool still hands out a working one.
    • UNPOOLED: a data source that keeps its connections; the connection is aborted and closed.
    • WRAPPED_POOL: a Hikari pool behind another DataSource whose connections unwrap to Hikari's: the pool evicts the connection, and the next borrow is a different, working connection. Runs on all three databases.
    • DELETE_FAILS: the delete and the restore both fail; the delete's error is reported and the failed record stays.
    • CLOSE_FAILS: closing the connection throws after a working delete; the run succeeds.
    • LOCK_CONNECTION: the restore fails on the connection that took the run lock (PostgreSQL and MySQL; H2 has no run lock connection).
  • stopsWhenTheLockIsNotReleased also checks that the discarded connection is not used again.
  • Before the fixes, EDITED_FAILED_STEP failed, and so did HEALTHY, BROKEN, UNPOOLED and WRAPPED_POOL (the connection was handed out again, or the abort fallback ran) and the discarded-connection check in stopsWhenTheLockIsNotReleased. DELETE_FAILS, CLOSE_FAILS and LOCK_CONNECTION cover paths that already worked.
  • SchemaMigratorTest passes on H2, PostgreSQL 18 and MySQL 8.
📐 Design notes & details
  • The edit check uses Flyway's MigrationInfo.getAppliedChecksum() and getResolvedChecksum() (Flyway 13.10.3), only for failed rows of pending steps, which are the only failed rows the upgrade forgives. Its note is added only to Flyway's failed-step error (FAILED_VERSIONED_MIGRATION).
  • Discarding reuses the run lock's closeUnderlying, which an unlock failure also uses. It is a best effort to end the session: it evicts through Hikari when the connection is Hikari's own, also behind a caller's wrapping DataSource that can unwrap to it (Hikari's evictConnection ignores any other connection), and Hikari then closes the database connection on a thread of its own. Otherwise it aborts the connection and closes the connection underneath if it is still open. Either way the session ends, and with it a PostgreSQL or MySQL run lock. The run lock keeps its DataSource for this.

This pull request and its description were written by Isaac.

shba24 and others added 3 commits November 18, 2026 01:02
…iled

Flyway reports a failed step before it compares checksums, so the retry of
a failed step also forgave a row whose step script had been edited, and
recorded the step with the new checksum. The history check now compares the
stored checksum with the step's before it lets the step be tried again.

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

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
(cherry picked from commit e7cef8d)
…be restored

A failed restore left the connection open with auto-commit on, so a pool
that does not reset connections could hand it out again with the wrong
setting. The connection underneath is now closed, with a warning.

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

shba24 commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

/review

shba24 and others added 3 commits November 18, 2026 03:16
…ails

Deleting the record of a failed schema step could report "Could not delete
the record of a failed schema step" even though the DELETE had worked: when
the connection's auto-commit setting could not be put back, the connection was
closed and the pool's own close then threw. The cleanup now only logs its
failures, so the run goes on after a successful DELETE, and a failed DELETE
still reports its own error.

The connection whose cleanup failed is now aborted instead of closed behind the
pool's back, so a pool drops it instead of handing the closed connection out
again. The test fails the restore on a Hikari pool configured like the
server's, for a connection that stays open and for one that is lost.

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

When a migrator connection could not get its auto-commit setting back, it was
aborted. H2's abort does nothing, so the connection stayed open with
auto-commit on, and a Hikari pool did not drop it.

The connection is now evicted from a Hikari pool, which closes it and keeps
the pool from handing it out again. For any other pool it is aborted and, if
that left it open, closed directly. Closing a connection that a pool evicted
can throw; that is now logged instead of failing the run.

The test covers a Hikari pool (connection kept or lost) and a pool that keeps
its connections as they are, and checks that the pool still works afterwards.

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

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[AI Assisted] Approving, with a rebase request. #2115 has merged, so this PR now conflicts with main in SchemaMigrator.java and SchemaMigratorTest.java. Please rebase on main. #2115 and this PR overlap in those two files, so whichever lands second rebases.

Covered from #2114: the checksum edit of a failed step, the swallowed auto-commit restore, and the non-resetting pool tests. Still open, as follow-ups: the runs() Javadoc invariant, the version 0 wording in the refusal, and caching the cumulative snapshots. Those can come later.

@timothyw553 timothyw553 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the checksum guard makes sense to me. i left a few comments on the cleanup test coverage, wrapped-pool eviction, and a couple of minor cleanup and logging nits.

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
@shba24
shba24 marked this pull request as draft November 18, 2026 17:19
shba24 and others added 2 commits November 18, 2026 17:50
Count a connection as evicted only when it is a Hikari proxy, skip the
auto-commit restore on a connection that was already discarded, word the
cleanup messages for the schema migration's connection, and cover the
delete-and-restore failure, a failing close, a wrapped pool and the run
lock's connection in the restore test.

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
…onnection's auto-commit only after a successful unlock

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

shba24 commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

/review

…up docs and test

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

shba24 commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

/review

…ot be restored

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

shba24 commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@shba24
shba24 marked this pull request as ready for review November 18, 2026 20:46

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[AI Assisted] Follow-ups from my review of this PR, all non-blocking. The approval stands. Two are inline, both about the new tests.

@yili-db
yili-db merged commit e277438 into unitycatalog:main Nov 19, 2026
27 checks passed
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.

3 participants