Repository navigation
[Server] Run every test on H2 or PostgreSQL 18 - #2008
Conversation
46c7dac to
9d1449b
Compare
9d1449b to
a579920
Compare
|
/review |
a579920 to
b6b3d4f
Compare
|
AI review, run locally on the stack (#2008 → #2009) I ran this repository's AI reviewer locally: the six roles in Reviewed heads: a579920 (#2008), 85155fa (#2009).
No other findings. Current heads: 2a3d936 (#2008), e3ed9aa (#2009). |
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Thanks for the quick fix on the MySQL stale read; refresh(dao, PESSIMISTIC_WRITE) after the lock query looks right on all three databases, and the rebase onto 1.21.4 is clean.
The main open item is the drop error code (inline on TableRepository.deleteTable): Iceberg clients would see a lock-contended drop as AlreadyExistsException. Everything else inline is non-blocking.
One more that isn't in the diff: AGENTS.md (line 149) still says PostgreSQL is covered per class via Testcontainers. Since this PR introduces UC_TEST_DATABASE and build/sbt testPostgres18, can we add a line on how to run it, that it fails (not skips) without Docker, and the -J-Xmx6G it needs? The description's "every test can now run on PostgreSQL 18" also has exceptions (MySQLDeltaCommitsCRUDTest, HibernateConfiguratorTest, PopulateTestDatabase).
| if (locked == null) { | ||
| throw new BaseException(ErrorCode.TABLE_NOT_FOUND, "Table not found: " + tableName); | ||
| } | ||
| session.refresh(dao, LockMode.PESSIMISTIC_WRITE); |
There was a problem hiding this comment.
[AI Assisted] Fix looks good. You mentioned the two-session MySQL test reproduced it (m0 before, m1 after) but isn't in the PR because the suite runs on H2 and PostgreSQL only. MySQLDeltaCommitsCRUDTest already starts a MySQL container via Testcontainers and runs in CI, so could the repro go in as a small MySQL-only class following that pattern? This regression is invisible on H2 and PostgreSQL, so without it a later refactor of this method can bring it back silently.
There was a problem hiding this comment.
Added in 10cbce9 as MySQLTableLockTest, following MySQLDeltaCommitsCRUDTest. It first asserts the connection is at REPEATABLE READ, so it can't pass without testing anything. It fails with a plain refresh (the commit sees the old m0) and passes with the locking one. It's single-threaded with a fixed order, and passed 5 runs in a row.
There was a problem hiding this comment.
Update: in 48109fa this moved into the existing MySQLDeltaCommitsCRUDTest, as testCommitThatWaitedForTheLockReadsTheOtherCommit, and MySQLTableLockTest is gone.
| // A commit rewrites the table's columns under this lock; waiting for it keeps the cascade below | ||
| // from deleting column rows the commit is replacing. | ||
| RepositoryUtils.lockTableForCommit( | ||
| session, tableInfoDAO, tableInfoDAO.getId(), Optional.of(tableName), ErrorCode.ABORTED); |
There was a problem hiding this comment.
[AI Assisted] What does an Iceberg client see when this fails? ABORTED is 409, IcebergRestExceptionHandler maps it to a generic RESTException with that status, and in iceberg-core 1.11 RESTSessionCatalog.dropTable/purgeTable use ErrorHandlers.tableErrorHandler(), which maps 409 to AlreadyExistsException. So a Spark DROP TABLE that loses the lock race fails with "table already exists". The DELETE specs don't list a 409 either. Can we pick a code whose status both clients treat as retryable (cc the Iceberg REST owners)?
Smaller:
tableNamehere is the bare name, so the message reads "Concurrent commit in progress on table t"; can we pass the full name?- "Concurrent commit" is wrong when the holder is another drop.
- Force schema delete (
SchemaRepository) goes through this too, so one contended child table now fails the whole schema delete. Fine if intended, but worth a test.
There was a problem hiding this comment.
Good catch, thanks. Confirmed in iceberg-core 1.11: dropTable and purgeTable use tableErrorHandler(), which maps 409 to AlreadyExistsException. Changed in 2d05986: a drop that times out waiting for the lock now returns a new UNAVAILABLE (503). cc @openinx, since there's no separate Iceberg REST owner in CODEOWNERS: does 503 look right to you for Iceberg clients?
How we picked 503:
- Iceberg REST spec:
dropTablelists 204, 400, 401, 403, 404, 419, 503 and 5XX. 503 is the only "retry later" status there; 409 isn't listed for drop, and 429 isn't used anywhere in the spec. - Clients: Iceberg's HTTP client retries a 503 on idempotent requests such as
DELETE(5 retries by default), then raisesServiceUnavailableException. The UC Java client retries every 5xx. - Other Iceberg REST catalogs:
- Polaris returns 503 for concurrent modifications on drop and rename, and chose it deliberately in apache/polaris#4646, for the same reason: 409 "would collide with that meaning, so a spec-compliant client would surface it as
AlreadyExistsExceptionrather than retrying". - Lakekeeper and Nessie return 409 for drop conflicts, so Iceberg clients see
AlreadyExistsException, which is the issue you found. - Gravitino and Iceberg's reference
RESTCatalogAdapterfall through to 500.
- Polaris returns 503 for concurrent modifications on drop and rename, and chose it deliberately in apache/polaris#4646, for the same reason: 409 "would collide with that meaning, so a spec-compliant client would surface it as
- Delta API: its error types have no 503, so
UNAVAILABLEanswers Delta clients withTooManyRequestsException(429), the spec's "retry after a delay" type. 515582c lists that 429 on the DeltadeleteTable, which previously listed only 204/401/403/404.
One caveat raised in the Polaris thread: some proxies read 503 as "server down". In UC the drop first waits on the server for the lock: PostgreSQL's default lock_timeout is 0 (no limit), H2 waits 2 s by default, and MySQL waits innodb_lock_wait_timeout (50 s). So the 503 appears only after that wait, with a configured lock timeout, or on a deadlock.
On the smaller points:
- Full name: I left it. The caller asked to drop that exact table, so it knows which one.
- "Concurrent commit": now "Concurrent modification in progress on table …" for every caller, since the lock holder can be a commit or a drop.
- Force schema delete: intended, since it runs in one transaction.
forceSchemaDeleteBlockedByCommitLockDeletesNothingnow covers it.
There was a problem hiding this comment.
Update: the Delta API now has a ServiceUnavailableException (503) error type, and UNAVAILABLE uses it (6532321). A drop that times out on the lock is 503 on UC REST, Iceberg and Delta.
| } | ||
|
|
||
| @Test | ||
| void dropWaitsForTheTableLockThatCommitsHold() { |
There was a problem hiding this comment.
[AI Assisted] What is this actually testing? It asserts the drop gives up with ABORTED, not that it waits and then succeeds, and the table has no columns, so moving the lock below the column cascade (the deadlock this PR fixes) would still pass. Could the fixture have columns, one session hold the lock, replace the columns and commit, then assert the drop completes? If this case stays, a name like dropBlockedByCommitLockIsAborted matches what it checks.
There was a problem hiding this comment.
Agreed. Renamed it to dropBlockedByCommitLockIsUnavailable and gave the table a column. The lock holder now replaces the columns, as a commit does. A drop that deleted the columns before taking the lock would block on those rows and fail as INTERNAL. I checked that this mutant fails this test, and the new force-schema-delete test, on H2 and on PostgreSQL.
I kept it single-threaded rather than "waits, then succeeds": that needs a second thread blocked on the lock, and that's what made the earlier version flaky.
| } | ||
|
|
||
| @Test | ||
| public void tableDeletedWhileWaitingIsNotFound() { |
There was a problem hiding this comment.
[AI Assisted] This branch is only covered with a mock returning null. A two-session test on the real database (a commit has loaded the DAO, waits on the lock while a drop commits, then gets TABLE_NOT_FOUND) would pin the lock-then-read ordering. Also, nothing now exercises a lock failure thrown by the refresh inside the try, which matters a bit more now that it takes PESSIMISTIC_WRITE.
nit: ExceptionConverterImpl is org.hibernate.internal, so this may break on a Hibernate upgrade.
There was a problem hiding this comment.
Added both:
commitOnATableDroppedAfterItWasReadIsNotFound, on the real database: the commit reads the table, a drop commits, then the commit's lock finds no row and getsTABLE_NOT_FOUND. The read takes no lock, so the drop doesn't wait and the test needs no threads.lockFailureOnTheReReadRaisesTheCallerSuppliedError, for a lock failure thrown by therefresh.
On ExceptionConverterImpl: I kept it so the test feeds in exactly what Hibernate's converter produces. If an upgrade moves or changes it, the test fails to compile or fails, rather than passing silently.
| SessionFactory sessionFactory = hibernateConfigurator.getSessionFactory(); | ||
| Session session = sessionFactory.openSession(); | ||
| Transaction tx = session.beginTransaction(); | ||
| session.createMutationQuery("delete from FunctionParameterInfoDAO").executeUpdate(); |
There was a problem hiding this comment.
[AI Assisted] Do we still need these deletes? Every test now gets its own database that is dropped in testDatabase.close(), so this block only costs time and has to be kept in FK order when an entity is added. The removed TODO ("figure out a better way to clear the database") is answered by this PR. Removing it also avoids the unclosed session/transaction if a delete throws.
There was a problem hiding this comment.
Removed in 061856f. Every test database now starts empty: the default ones are dropped after each test, and the classes with their own container use create-drop.
| hibernateConfigurator = new HibernateConfigurator(hibernateProperties); | ||
| if (!testDatabase | ||
| .jdbcUrl() | ||
| .equals(hibernateProperties.getProperty("hibernate.connection.url"))) { |
There was a problem hiding this comment.
[AI Assisted] Inferring "subclass brought its own database" from a URL mismatch is fragile: a subclass that only appends a URL parameter (like the lock-timeout pool in ManagedTableCleanupTaskTest) would silently get create-drop and halt_on_error=false. The only user is MySQLDeltaCommitsCRUDTest; could it set those two properties itself, or use an explicit hook? Also the javadoc above says the hook "defaults to this test's database", but the method body is empty.
There was a problem hiding this comment.
Agreed, removed the URL check in 061856f:
- The MySQL classes set
create-dropandhalt_on_error=falsethemselves, with the reason. PostgresDeltaCommitsCRUDTestsets onlycreate-dropand keepshalt_on_error=true.
I checked that false is really needed on MySQL: with true, all 11 MySQLDeltaCommitsCRUDTest tests fail on alter table uc_columns drop foreign key …, while PostgreSQL passes with true. Fixed the hook's Javadoc too.
| this.failure = failure; | ||
| } | ||
|
|
||
| static synchronized PostgresDatabases get(SupportedDatabase database) { |
There was a problem hiding this comment.
[AI Assisted] nit: after the first call this ignores database, so a second PostgreSQL constant would silently reuse the first container. Key the cache by constant, or drop the parameter until there's a second one.
There was a problem hiding this comment.
Dropped the parameter in 061856f; get() now uses the selected database.
|
Thanks @yili-db. All the inline points are addressed in 2d05986, 10cbce9, 061856f and 515582c; replies are in each thread. On the two from the summary:
|
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Thanks, the revision addresses everything from the last round. Two small test follow-ups inline.
| } | ||
|
|
||
| @Test | ||
| public void tableDeletedWhileWaitingIsNotFound() { |
There was a problem hiding this comment.
[AI Assisted] Is this still needed? ManagedTableCleanupTaskTest.commitOnATableDroppedAfterItWasReadIsNotFound now covers the same locked == null branch on the real database, so this mock version doesn't add anything. Can we delete it?
There was a problem hiding this comment.
Removed in 537e947. commitOnATableDroppedAfterItWasReadIsNotFound now also checks the table's full name in the message, which was the only thing the mock test added.
| e -> assertThat(e.getErrorCode()).isEqualTo(ErrorCode.UNAVAILABLE)); | ||
| // Iceberg clients retry a 503 on drop table. The Delta API has no 503 error type, so it | ||
| // answers with its "retry after a delay" type. | ||
| AggregatedHttpResponse iceberg = |
There was a problem hiding this comment.
[AI Assisted] Can the HTTP mapping move out of this persistence test? This method now checks both that the drop stops at the lock and how UNAVAILABLE renders on Iceberg and Delta, while the UC REST surface (also 503) isn't tested anywhere. A small test that maps UNAVAILABLE on all three surfaces (UC REST 503, Iceberg 503, Delta 429) would keep this test about the lock and cover the missing one.
There was a problem hiding this comment.
Added the UC REST check (503, "error_code":"UNAVAILABLE") in 79b04ae, next to the Iceberg and Delta ones, so the test checks the drop's own failure through each handler. No test checks how each ErrorCode maps to a status on the three surfaces today, so I'll add a generic mapping test over all codes in a follow-up.
| setUpCredentialOperations(initServerProperties); | ||
| Properties hibernateProperties = | ||
| HibernateConfigurator.setupHibernateProperties(initServerProperties); | ||
| testDatabase = TestDatabases.newDatabase(); |
There was a problem hiding this comment.
[AI Assisted] Could the per-test database be injected like @TempDir, with the configurator boilerplate folded into TestDatabase? A typical test would end up as:
class ManagedVolumeCleanupTaskTest {
@TempDatabase TestDatabase testDatabase;
private SessionFactory sessionFactory;
@BeforeEach
void setUp() {
sessionFactory = testDatabase.sessionFactory();
repositories = new Repositories(sessionFactory, serverProperties);
...
}
// No @AfterEach: the database is closed and dropped after the test.
}This class would declare @TempDatabase protected TestDatabase testDatabase; too, and tearDown would keep only unityCatalogServer.close().
What it takes:
/** Injects a fresh TestDatabase: per test for an instance field, per class for a static one. */
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(TempDatabaseExtension.class)
public @interface TempDatabase {}
final class TempDatabaseExtension implements BeforeAllCallback, BeforeEachCallback {
// beforeAll: static @TempDatabase fields; beforeEach: instance fields.
// For each field: TestDatabases.newDatabase(), put it in the context's Store, set the field.
}
public final class TestDatabase implements AutoCloseable {
public Properties hibernateProperties(); // no ServerProperties argument
public HibernateConfigurator hibernateConfigurator(); // the default one, opened on first use
public SessionFactory sessionFactory(); // hibernateConfigurator().getSessionFactory()
public HibernateConfigurator openHibernateConfigurator(Properties hibernateProperties); // unchanged
}Why:
- Ordering by construction.
BeforeEachCallbackruns before any@BeforeEach, and the Store closesAutoCloseablevalues when the context ends (JUnit 5.13, which we're on), after every@AfterEach. So the server always closes before its database is dropped, andtearDownhere loses the nestedtry/finallyand its ordering comment. - Cleanup when setup fails. The database is registered before any
@BeforeEachruns, so asetUpthat throws partway still drops it. - The
ServerPropertiesargument does nothing.setupHibernatePropertiesreads onlyserver.envfrom it, to set the driver, URL andhbm2ddl.auto, andhibernatePropertiesoverwrites all three. That's why the callers that passnew ServerProperties(new Properties())(StorageCleanupTaskRepositoryTest,TransactionManagerTest, the template build inPostgresDatabases) get the same database as the ones that setserver.env=test. - Less boilerplate. The 12 classes that create and close a
TestDatabaseby hand declare the field instead, and most of them need onlysessionFactory(). A static field covers the two@BeforeAllusers (UserRepositoryTest,TransactionManagerTest.IsolationLevelWithRealDatabaseTest).openHibernateConfigurator(Properties)stays for the callers that change properties first: this class,ExternalLocationUtilsTest(pool_size=1), and the lock-timeout pool inManagedTableCleanupTaskTest.
Since this PR introduces TestDatabases and already touches all of its callers, now is the cheapest time to do it. But it changes no behavior, so a follow-up right after this PR is fine too. Your call.
There was a problem hiding this comment.
Agreed, I'll do it in a follow-up right after this PR.
Signed-off-by: Shubham Bansal <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…abase Signed-off-by: Shubham Bansal <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Use the wording the spec already gives TooManyRequestsException. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
- Check what Iceberg and Delta clients get for a drop that lost the lock (503 ServiceUnavailableException, 429 TooManyRequestsException) in dropBlockedByCommitLockIsUnavailable, from the drop's own failure, instead of a separate UnavailableErrorResponseTest. - Move the MySQL stale-read test into MySQLDeltaCommitsCRUDTest, the existing MySQL-only class, instead of a separate MySQLTableLockTest. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…l one commitOnATableDroppedAfterItWasReadIsNotFound covers the same branch on the real database, so it now also checks the table's full name in the message, and the mock test is removed. 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]>
…se dependencies Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
79b04ae to
673b486
Compare
|
build and yaml changes LGTM |
…ble lock Adds ServiceUnavailableException (503) to the Delta error types, so UNAVAILABLE is 503 on UC REST, Iceberg REST and the Delta API alike. The Delta deleteTable lists 503 instead of 429, and the protocol spec lists the new type among the errors any endpoint can return. 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 |
|
[AI Assisted] @shba24 LGTM. A reminder of the follow-ups from this review, so they don't get lost after merge:
|
|
Filed the follow-up from the review as #2043: a test that maps every ErrorCode to its status on UC REST, Iceberg and Delta. Once it exists, the per-handler assertions in dropBlockedByCommitLockIsUnavailable can go. |
#2049) **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] 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 (not needed, test-only change) **Description of changes** Closes #2043. #2008 added per-handler assertions to `ManagedTableCleanupTaskTest.dropBlockedByCommitLockIsUnavailable` for how one error code (`UNAVAILABLE`) reaches clients on each API. This PR replaces those with a single test that pins the response for every `ErrorCode` on all three APIs. Changes: - New `server/src/test/java/io/unitycatalog/server/exception/ErrorCodeTest`. It runs every `ErrorCode` (`@EnumSource`) through `GlobalExceptionHandler`, `IcebergRestExceptionHandler` and `DeltaApiExceptionHandler`, and checks: - UC REST: the HTTP status and `error_code` - Iceberg REST: the HTTP status, plus the `ErrorResponse` `code` and `type` - Delta: the HTTP status, plus `error.code` and `error.type` - The expected responses come from an exhaustive `switch` over `ErrorCode`. A new error code therefore won't compile until its responses on all three APIs are written down, and changing any existing mapping fails the test. The table also documents the intended differences between the APIs: - the legacy `*_ALREADY_EXISTS` codes are 400 on UC REST and 409 on Delta. On Iceberg, `SCHEMA_ALREADY_EXISTS` and `TABLE_ALREADY_EXISTS` are 409, and the other legacy codes are 400. - `UNPROCESSABLE_ENTITY` is 422 on Iceberg and 400 (`InvalidParameterValueException`) on Delta. - `dropBlockedByCommitLockIsUnavailable` drops its per-handler assertions and the `errorResponse` helper. It still checks that the drop fails as `UNAVAILABLE`. No production code changes. Tests: - `build/sbt "server/javafmtCheckAll" "server/testOnly io.unitycatalog.server.exception.ErrorCodeTest io.unitycatalog.server.persist.ManagedTableCleanupTaskTest"`: 27 + 7 tests passed, format check clean. - As a sanity check I changed `UNAVAILABLE` to 500 in `ErrorCode`. `ErrorCodeTest` then failed for that code (`expected: 503`). I reverted the change. Signed-off-by: NopeCharon <[email protected]>
## 🥞 Stacked PR Use this [link](https://github.com/unitycatalog/unitycatalog/pull/2009/files) to review incremental changes. - [stack/uc-one-suite](#2008) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2008/files)] [MERGED] - [**stack/uc-one-suite-ci**](#2009) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2009/files)] ← _this PR_ - [stack/uc-mysql-suite](#2044) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2044/files/fdb96ee0da3b187dc47908de3f8cfc0eabdb12ac..bcd8db4d29d3c67461fcb045b4ee829e9a62afad)] - [stack/uc-flyway-schema](#2045) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2045/files/5542c615b9b5af8925439fe9021ef7c6b2868238..3efb98336a796a03fa69e1699760e5ef646749f5)] - [stack/uc-flyway-merge-checks](#2046) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2046/files/3efb98336a796a03fa69e1699760e5ef646749f5..faabc3d450357bdd37a79fe1409a9dfedc0e4ed2)] --------- **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** **Every pull request now also runs the whole test suite on PostgreSQL 18.** #2008 lets any test run pick PostgreSQL with `UC_TEST_DATABASE=POSTGRES_18`. This PR adds that run to CI: - `unit-tests.yml` gets one blocking row: the primary combo (Spark 4.0.0, Delta 4.3.1, all tests) with `test-database: POSTGRES_18`. Its job is named `All tests (Spark 4.0.0, Delta 4.3.1, POSTGRES_18)`. The other rows stay on H2. - The `run-uc-unit-tests` action takes a `test-database` input (default `H2`) and passes it to the test step as `UC_TEST_DATABASE`. The license check runs only on the H2 row, so it isn't duplicated. - `PostgresDeltaCommitsCRUDTest` is removed. It ran the Delta commit tests against its own PostgreSQL 16 container; the new row runs those same tests, and every other test, on PostgreSQL 18. Its index-limit test moves to `TransactionManagerTest.DatabaseErrorWithRealDatabaseTest` and runs on every database: it expects `INVALID_ARGUMENT` on PostgreSQL and a successful insert on H2. ### Testing - Both workflow files parse as YAML. - The new row's first real run is this PR's CI. <details> <summary>📐 Design notes & details</summary> **Why one PostgreSQL row, not one per Spark version.** Database behavior doesn't depend on the Spark version, and the primary combo already runs every project (server, cli, spark, hadoop). The row adds one "All tests" job (about 49 minutes) that runs in parallel with the others, so wall-clock time per PR stays about the same. **Why the row is blocking from day one.** #2008 fixes the PostgreSQL-only failure the first full run found (concurrent Iceberg commits returning 500 instead of 409). A non-blocking row would let new PostgreSQL-only failures merge unnoticed. **Why remove `PostgresDeltaCommitsCRUDTest` here and not in #2008.** Until this row exists, that class is the only PostgreSQL coverage in default CI. Removing it in the same PR that adds the row means coverage never drops in between. </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](https://github.com/unitycatalog/unitycatalog/pull/2044/files) to review incremental changes. - [stack/uc-one-suite](#2008) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2008/files)] [MERGED] - [stack/uc-one-suite-ci](#2009) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2009/files)] [MERGED] - [**stack/uc-mysql-suite**](#2044) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2044/files)] ← _this PR_ - [stack/uc-flyway-schema](#2045) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2045/files/5542c615b9b5af8925439fe9021ef7c6b2868238..3efb98336a796a03fa69e1699760e5ef646749f5)] - [stack/uc-flyway-merge-checks](#2046) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2046/files/3efb98336a796a03fa69e1699760e5ef646749f5..faabc3d450357bdd37a79fe1409a9dfedc0e4ed2)] --------- **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 **Description of changes** **Every pull request now also runs the whole test suite on MySQL 8.4, and the bugs that run found are fixed.** #2008 and #2009 run every test on PostgreSQL 18. This PR does the same for MySQL: - `SupportedDatabase.MYSQL_8`, `build/sbt testMySQL8`, and one blocking CI row, `All tests (Spark 4.0.0, Delta 4.3.1, MYSQL_8)`. - PostgreSQL and MySQL test databases now come from one shared harness (`TemplateDatabases`): the schema is built once per JVM, and each test gets its own copy. - `@TempDatabase` injects a per-test database (from the #2008 review). The 12 classes that created and closed one by hand now declare a field. - `MySQLDeltaCommitsCRUDTest`, which started its own MySQL container, is removed. Its lock test moves into `SdkDeltaCommitsCRUDTest`, so it runs on every database. Bugs the MySQL run found: - **Columns came back in the wrong order.** `GET` on a table returned columns in MySQL's primary-key order (random UUIDs), so Spark could build the table schema with columns swapped. Function parameters had the same problem. Both collections are now ordered by position with `@OrderBy`: the table columns by #2031 on main, the function parameters here. No schema change. - **Storage paths were compared case-insensitively.** MySQL's default collation treats `s3://b/RESERVED` and `s3://b/reserved` as equal, unlike S3, Linux, PostgreSQL and H2. The deployment docs and the example compose file now create the database with `utf8mb4_0900_bin`, and the server logs a warning at startup when the database or its tables compare text case-insensitively. ### Testing - `server/test` passes on H2, PostgreSQL 18 and MySQL 8.4. - The whole MySQL suite (all projects) passes. Before the fixes, 6 Spark `testTableWithSupportedDataTypes` cases failed on column order and `ExternalLocationUtilsTest` failed on path case. - `BaseFunctionCRUDTest` now creates a function with 4 parameters submitted out of position order and checks they come back in position order, so a missing `ORDER BY position` fails on every database (the old test passed on MySQL about 1 time in 24). <details> <summary>📐 Design notes & details</summary> **Why `@OrderBy` and not sorting in Java.** The order is a property of the data, so the entity's list is ordered for every reader, not only for callers that remember to sort. For tables, the existing unique key `(table_id, ordinal_position, name)` lets MySQL read the rows in order. PostgreSQL and H2 returned insertion order only by luck: a PostgreSQL `UPDATE` writes a new row version at the end of the table, so the same unsorted query reorders after one update. **Why a database collation, not query changes.** A session or connection collation (for example JDBC `connectionCollation`) doesn't change how a column compares: the column's own collation wins. A database created with `COLLATE utf8mb4_0900_bin` gives every table created in it that collation, so every `=`, `LIKE` and unique key becomes case-sensitive with no code change. `utf8mb4_0900_bin` is NO PAD, like PostgreSQL and H2 (`utf8mb4_bin` would treat `'a'` and `'a '` as equal). `ALTER DATABASE` doesn't convert existing tables, so existing installs keep working as before and get the warning. **How MySQL test databases are copied.** MySQL has no `CREATE DATABASE … TEMPLATE`. The template's `SHOW CREATE TABLE` statements are captured once and replayed into each new database with foreign key checks off. The replay keeps primary keys, unique keys, indexes, foreign keys and check constraints. The template build checks that every mapped table exists, because MySQL rejects one Hibernate index (`idx_staging_location`, a 2048-character column is over InnoDB's 3072-byte key limit) and the build must continue past that error. **Pinned test images.** The PostgreSQL and MySQL test images are pinned by digest (tag in a comment), like the repo's actions and Dockerfile base images. **Test container settings.** Both containers keep their data in memory and skip disk syncs (PostgreSQL `fsync=off`, MySQL InnoDB flush and binary log off). Schema setup per test drops from about 1.2 s to 0.5 s on MySQL. </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.
PR Checklist
docsis updatedDescription of changes
Every test can now run on PostgreSQL 18, not just H2.
UC_TEST_DATABASE=POSTGRES_18 build/sbt test, orbuild/sbt testPostgres18, runs the server, cli, spark and hadoop tests onpostgres:18-alpine(it needs Docker, fails rather than skips without it, and needs-J-Xmx6G). Without the variable, tests run on H2 as before, with no Docker needed. Each test gets a fresh database, and a schema statement that fails now fails the test instead of logging a warning. Exceptions:MySQLDeltaCommitsCRUDTestruns on its own MySQL container;HibernateConfiguratorTestandPopulateTestDatabasebuild their own database;UserRepositoryTestandTransactionManagerTest.IsolationLevelWithRealDatabaseTestshare one database per class.Running the suite on PostgreSQL found three bugs in how writers of a table take its lock. This PR fixes them:
lockTableForCommitnow locks the row first, then re-reads it.deleteTablenow takes the same lock. A commit whose table was dropped while it waited returns 404. A drop that times out waiting for the lock returns 503 (UNAVAILABLE) on every API, with a new Delta error typeServiceUnavailableException. The Iceberg REST spec lists 503 for drop table, and both the Iceberg and UC clients retry it.OptimisticLockException. They now map to the caller's error code (409 for Iceberg,COMMIT_STATE_UNKNOWNfor Delta,UNAVAILABLE(503) for a drop).Everything else is test code and
build.sbt. #2009 runs the PostgreSQL suite in CI.Tests
IcebergRestCatalogTest.testConcurrentCommitsSerializeWithCompareAndSwapfailed 3 of 3 runs on PostgreSQL before the fix.ManagedTableCleanupTaskTest.dropBlockedByCommitLockIsUnavailableandforceSchemaDeleteBlockedByCommitLockDeletesNothing(new): the lock holder replaces the table's columns, as a commit does, so a drop that deleted columns before taking the lock fails them on both databases. The drop test also checks what clients get: 503 on UC REST, andServiceUnavailableException(503) on the Iceberg and Delta APIs.ManagedTableCleanupTaskTest.commitOnATableDroppedAfterItWasReadIsNotFound(new): a commit on a table dropped after it was read getsTABLE_NOT_FOUND, on the real database.MySQLDeltaCommitsCRUDTest.testCommitThatWaitedForTheLockReadsTheOtherCommit(new): fails on MySQL with a plain re-read after the lock (it sees the old metadata location), passes with the locking re-read.RepositoryUtilsTestbuilds its lock failures with Hibernate's own exception converter. Against the old catch, its deadlock case fails.🔒 Commit races: what failed and why
Race 1: a commit read the table before it held the lock (PostgreSQL only). The lock was
session.refresh(dao, PESSIMISTIC_WRITE). A refresh also loads the table's columns with aLEFT JOIN, andPostgreSQLDialect.supportsOuterJoinForUpdate()isfalse, so Hibernate reads first and locks in separate statements afterwards (warningHHH000444). H2 locks the join in one statement.Fix: lock with
from TableInfoDAO where id = :id(no join; PostgreSQL runsfor no key update), then re-read it withrefresh(dao, PESSIMISTIC_WRITE). The re-read sees A's commit, so B gets 409. It stays a locking read because on MySQL's default REPEATABLE READ a plain read returns the transaction's first snapshot, from before A's commit.Race 2: a drop deleted column rows without the lock (PostgreSQL and H2). The three commit paths take the table lock, but
deleteTabledid not:Fix:
deleteTabletakes the same lock first. A drop that can't get it within the lock timeout returnsUNAVAILABLE(503). Not 409: the Iceberg REST spec lists 503, not 409, for drop table, and the Iceberg client maps a 409 on drop toAlreadyExistsExceptionand does not retry it. Apache Polaris returns 503 for the same reason (apache/polaris#4646). The Delta API gets a newServiceUnavailableException(503) error type for it, listed on the DeltadeleteTableinapi/delta.yamland in the protocol spec, so all three APIs answer 503.Lock exceptions. The new lock query passes Hibernate's lock exception through its exception converter: a lock-wait failure or timeout becomes
PessimisticLockExceptionorLockTimeoutException, and a deadlock becomesOptimisticLockException, each wrapping Hibernate's exception.lockTableForCommitchecks the exception and its cause.📐 Design notes & details
WITH (FORCE)). On PostgreSQL 18 a copy takes about 46 ms and a drop 55 ms.halt_on_erroris safe on H2 and PostgreSQL, where nothing harmless fails on a fresh database. MySQL's drop step does fail harmlessly (noDROP FOREIGN KEY IF EXISTS), so only the MySQL classes sethalt_on_error=false, themselves. MySQL isn't a selectable database yet.PostgresDeltaCommitsCRUDTeststays here so CI keeps PostgreSQL coverage; [Build] Run all tests on PostgreSQL 18 in CI #2009 removes it.testPostgres18setsTest / envVarsfor the sbt session, so in an interactive shell a latertestkeeps using PostgreSQL untilreload. The full run needs-J-Xmx6G.This pull request and its description were written by Isaac.