Repository navigation
[Server] Follow-ups to the schema upgrade retry - #2285
Conversation
…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]>
|
/review |
…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]>
Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[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
left a comment
There was a problem hiding this comment.
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]>
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]>
|
/review |
…up docs and test Signed-off-by: Shubham Bansal <[email protected]> Co-authored-by: Isaac <[email protected]>
|
/review |
…ot be restored 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] Follow-ups from my review of this PR, all non-blocking. The approval stands. Two are inline, both about the new tests.
Follow-ups to #2114 from its review, which came in after it merged.
evictConnection), otherwise by aborting it and closing the connection underneath (H2'sabortdoes nothing). Hikari, which the server uses, resets the setting itself on close.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.DataSourcethat wraps a Hikari pool gets the same eviction: the migrator unwraps the connection to Hikari's own before evicting it.Tests
SchemaMigratorTest.keepsTheRecordOfAFailedStepWhenTheRunRefuseshas a new row,EDITED_FAILED_STEP. It failed before the fix and passes after.SchemaMigratorTest.cleansUpTheConnectionWhenItCannotBeRestored, one row perConnectionState:HEALTHYandBROKEN: 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 anotherDataSourcewhose 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).stopsWhenTheLockIsNotReleasedalso checks that the discarded connection is not used again.EDITED_FAILED_STEPfailed, and so didHEALTHY,BROKEN,UNPOOLEDandWRAPPED_POOL(the connection was handed out again, or the abort fallback ran) and the discarded-connection check instopsWhenTheLockIsNotReleased.DELETE_FAILS,CLOSE_FAILSandLOCK_CONNECTIONcover paths that already worked.SchemaMigratorTestpasses on H2, PostgreSQL 18 and MySQL 8.📐 Design notes & details
MigrationInfo.getAppliedChecksum()andgetResolvedChecksum()(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).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 wrappingDataSourcethat can unwrap to it (Hikari'sevictConnectionignores 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 itsDataSourcefor this.This pull request and its description were written by Isaac.