Skip to content

[Build] Run all tests on PostgreSQL 18 in CI - #2009

Merged
yili-db merged 5 commits into
unitycatalog:mainfrom
shba24:stack/uc-one-suite-ci
Oct 27, 2026
Merged

yili-db merged 5 commits into
unitycatalog:mainfrom
shba24:stack/uc-one-suite-ci

Conversation

@shba24

@shba24 shba24 commented Oct 17, 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

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.
📐 Design notes & details

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.

This pull request and its description were written by Isaac.

@shba24
shba24 force-pushed the stack/uc-one-suite-ci branch from f1847e1 to 74ca513 Compare October 19, 2026 03:51
@shba24
shba24 marked this pull request as ready for review October 19, 2026 03:54
@shba24
shba24 force-pushed the stack/uc-one-suite-ci branch from 74ca513 to 85155fa Compare October 19, 2026 04:29
@yili-db

yili-db commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

/review

@shba24

shba24 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

AI review, run locally on the stack (#2008 → #2009)

I ran this repository's AI reviewer locally: the six roles in .github/omnigent/reviewer (domain, two maintainer passes, architecture, test coverage, docs), then the disprove gate over their combined findings. Read-only source review; the reviewers built and posted nothing.

Reviewed heads: a579920 (#2008), 85155fa (#2009).

No other findings. Current heads: 2a3d936 (#2008), e3ed9aa (#2009).

@shba24

shba24 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@shba24
shba24 force-pushed the stack/uc-one-suite-ci branch 3 times, most recently from 1148fb0 to 3388771 Compare October 20, 2026 21:30
@shba24
shba24 force-pushed the stack/uc-one-suite-ci branch 5 times, most recently from 7753e80 to 2b724ef Compare October 23, 2026 19:23
yili-db pushed a commit that referenced this pull request Oct 24, 2026
## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2008/files) to
review incremental changes.
-
[**stack/uc-one-suite**](#2008)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2008/files)]
← _this PR_
-
[stack/uc-one-suite-ci](#2009)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2009/files/ac4a580b797df2634ebe449d60bb5308ed0dc32f..2b724ef4188544b5a6ec18cce0f18f174e62a94b)]

---------
**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 test can now run on PostgreSQL 18, not just H2.**
`UC_TEST_DATABASE=POSTGRES_18 build/sbt test`, or `build/sbt
testPostgres18`, runs the server, cli, spark and hadoop tests on
`postgres: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: `MySQLDeltaCommitsCRUDTest` runs on its own MySQL
container; `HibernateConfiguratorTest` and `PopulateTestDatabase` build
their own database; `UserRepositoryTest` and
`TransactionManagerTest.IsolationLevelWithRealDatabaseTest` share 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:

- **Concurrent Iceberg commits on PostgreSQL returned 500 instead of
409.** A commit read the table before it held the lock.
`lockTableForCommit` now locks the row first, then re-reads it.
- **Dropping a table during a commit could deadlock, or fail the commit
with 500.** `deleteTable` now 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 type `ServiceUnavailableException`. The Iceberg REST spec lists
503 for drop table, and both the Iceberg and UC clients retry it.
- **Lock failures from the new lock query returned 500.** The query
reports them as JPA exceptions, and a deadlock arrives as
`OptimisticLockException`. They now map to the caller's error code (409
for Iceberg, `COMMIT_STATE_UNKNOWN` for Delta, `UNAVAILABLE` (503) for a
drop).

Everything else is test code and `build.sbt`. #2009 runs the PostgreSQL
suite in CI.

**Tests**

- Full suite on H2: 0 failures. #2009's CI runs the full suite on
PostgreSQL 18.
-
`IcebergRestCatalogTest.testConcurrentCommitsSerializeWithCompareAndSwap`
failed 3 of 3 runs on PostgreSQL before the fix.
- `ManagedTableCleanupTaskTest.dropBlockedByCommitLockIsUnavailable` and
`forceSchemaDeleteBlockedByCommitLockDeletesNothing` (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, and
`ServiceUnavailableException` (503) on the Iceberg and Delta APIs.
-
`ManagedTableCleanupTaskTest.commitOnATableDroppedAfterItWasReadIsNotFound`
(new): a commit on a table dropped after it was read gets
`TABLE_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.
- `RepositoryUtilsTest` builds its lock failures with Hibernate's own
exception converter. Against the old catch, its deadlock case fails.

<details>
<summary>🔒 Commit races: what failed and why</summary>

**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 a `LEFT JOIN`, and
`PostgreSQLDialect.supportsOuterJoinForUpdate()` is `false`, so
Hibernate reads first and locks in separate statements afterwards
(warning `HHH000444`). H2 locks the join in one statement.

```
     commit A                               commit B
t1   read: location v1
t2   lock ✓                                 read: location v1   (stale soon)
t3   check v1 ✓; replace columns; set v2    lock … waits for A
t4   commit → 200                           lock ✓
t5                                          check v1 ✓  (should have seen v2 → 409)
t6                                          delete old columns → 0 rows → 500
```

Fix: lock with `from TableInfoDAO where id = :id` (no join; PostgreSQL
runs `for no key update`), then re-read it with `refresh(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 `deleteTable` did
not:

```
     commit C (holds the table lock)        drop D (no lock)
t1   lock ✓; read columns
t2                                          delete columns
t3                                          delete table → waits for C
t4   delete columns → waits for D           → deadlock; one request gets 500
```

Fix: `deleteTable` takes the same lock first. A drop that can't get it
within the lock timeout returns `UNAVAILABLE` (503). Not 409: the
Iceberg REST spec lists 503, not 409, for drop table, and the Iceberg
client maps a 409 on drop to `AlreadyExistsException` and does not retry
it. Apache Polaris returns 503 for the same reason
([apache/polaris#4646](apache/polaris#4646)).
The Delta API gets a new `ServiceUnavailableException` (503) error type
for it, listed on the Delta `deleteTable` in `api/delta.yaml` and 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 `PessimisticLockException` or `LockTimeoutException`,
and a deadlock becomes `OptimisticLockException`, each wrapping
Hibernate's exception. `lockTableForCommit` checks the exception and its
cause.

</details>

<details>
<summary>📐 Design notes & details</summary>

- **A template database per test**, not one schema emptied between
tests. Every test still starts on an empty database, and background
threads from the previous test can't write into it, because its database
is dropped (`WITH (FORCE)`). On PostgreSQL 18 a copy takes about 46 ms
and a drop 55 ms.
- **`halt_on_error`** is safe on H2 and PostgreSQL, where nothing
harmless fails on a fresh database. MySQL's drop step does fail
harmlessly (no `DROP FOREIGN KEY IF EXISTS`), so only the MySQL classes
set `halt_on_error=false`, themselves. MySQL isn't a selectable database
yet.
- **`PostgresDeltaCommitsCRUDTest`** stays here so CI keeps PostgreSQL
coverage; #2009 removes it.
- **Local runs:** `testPostgres18` sets `Test / envVars` for the sbt
session, so in an interactive shell a later `test` keeps using
PostgreSQL until `reload`. The full run needs `-J-Xmx6G`.

</details>

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
@shba24
shba24 force-pushed the stack/uc-one-suite-ci branch from 2b724ef to 16b44a6 Compare October 24, 2026 06:04
@yili-db

yili-db commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

/review

@shba24
shba24 force-pushed the stack/uc-one-suite-ci branch from 59ade4d to a5c4e05 Compare October 26, 2026 21:19
@shba24
shba24 requested a review from yili-db October 26, 2026 21:32
shba24 and others added 4 commits October 26, 2026 22:47
The PostgreSQL index-limit test checks how a database error is reported,
not isolation levels, so it moves out of IsolationLevelWithRealDatabaseTest
into its own class. That class's comments no longer say H2 only.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
An exhaustive switch on the database says whether the value is over its
index-entry limit, so the test runs on every row, and a new database does
not compile until it picks a case.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24
shba24 force-pushed the stack/uc-one-suite-ci branch from 82e84de to e74ddcc Compare October 26, 2026 22:50
@yili-db
yili-db merged commit 750b699 into unitycatalog:main Oct 27, 2026
18 checks passed
yili-db pushed a commit that referenced this pull request Oct 29, 2026
## 🥞 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]>
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.

2 participants