Skip to content

[Server] Return INVALID_ARGUMENT for PostgreSQL limit errors and upgrade the driver to 42.7.14 - #1993

Merged
yili-db merged 5 commits into
unitycatalog:mainfrom
shba24:uc-pg-production
Oct 22, 2026
Merged

yili-db merged 5 commits into
unitycatalog:mainfrom
shba24:uc-pg-production

Conversation

@shba24

@shba24 shba24 commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

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

This PR makes two changes for running the server on PostgreSQL.

1. Return 400 when a value exceeds a PostgreSQL limit

On PostgreSQL, creating a staging table with a very long location returns a 500:

index row size 3888 exceeds btree version 4 maximum 2704 for index "idx_staging_location"

PostgreSQL limits an index entry to 2,704 bytes, and staging_location is indexed. The request caused the error, so the server should return 400.

The new DatabaseErrors lists database errors by database, SQLSTATE and the error code to return. TransactionManager uses that code and falls back to INTERNAL. The only entry is PostgreSQL's 54000 (program_limit_exceeded), mapped to INVALID_ARGUMENT. Every other database error is still INTERNAL, and the message is unchanged.

2. Upgrade the PostgreSQL JDBC driver to 42.7.14

The server ships driver 42.7.2 because jdbc-adapter 2.13.0 depends on it. That version is affected by CVE-2026-42198, fixed in 42.7.11. Tests use a different version, 42.7.13. This PR pins the driver to 42.7.14 as a server dependency and removes the test-only line, so the server and the tests use the same driver.

The deployment guide told PostgreSQL users to download the driver and add it to jars/classpath. The server already ships one, so following it put two drivers on the classpath. The guide now says the server ships the driver.

User impact

  • A request that exceeds a PostgreSQL limit now gets a 400 with the same message. This covers every repository that runs through TransactionManager; ModelRepository manages its own transactions and still returns INTERNAL. Nothing that works today changes.
  • PostgreSQL deployments run driver 42.7.14 instead of 42.7.2. Nothing to configure.

Tests

  • TransactionManagerTest.testDatabaseErrorCode: 54000 on PostgreSQL is INVALID_ARGUMENT; 54000 on H2 and another SQLSTATE on PostgreSQL stay INTERNAL.
  • TransactionManagerTest.testDatabaseErrorWithoutSqlStateIsInternal and testTransactionWithRuntimeException: a database error without a SQLSTATE, and an error that isn't from the database, stay INTERNAL.
  • PostgresDeltaCommitsCRUDTest.testValueOverIndexLimitIsInvalidArgument (Testcontainers): inserting a staging table whose location is over the index limit on real PostgreSQL gives INVALID_ARGUMENT. It fails without this change.
  • The PostgreSQL Testcontainers tests run on driver 42.7.14.
  • Full suite (build/sbt test) passes.
📐 Design notes & details

When the error happens

  • A staging location is its parent's storage location plus /tables/<uuid>. Catalog and schema storage locations are at most 255 characters, so locations under them fit.
  • When the catalog and schema have no storage location, the parent is <storage-root.tables>/__unitystorage, and that property has no length limit.
  • staging_location is varchar(2048), which counts characters, while the index limit counts bytes. So only multi-byte characters can reach the index limit. PostgreSQL also compresses an index entry before checking its size, so repetitive values can be longer and still fit.

Why map the error instead of adding a limit

  • Any new limit applied to every database rejects values that work today on H2 or MySQL, or values that compress well enough on PostgreSQL. Mapping the error changes only the status code of requests that already fail.
  • PostgreSQL's page size, and so the 2,704-byte limit, is fixed at compile time, and managed services such as RDS and Cloud SQL don't allow changing it.
  • A hash index has no length limit, but the path-overlap check in ExternalLocationUtils runs a LIKE 'prefix%' query on staging_location, which a hash index can't serve.

400 for a configuration-caused error

  • The long part of the location usually comes from storage-root.tables, which an operator sets, so the client sending the request can't fix it. It is still a 400: the server is working, and retrying the same request fails the same way. Alerts on 5xx won't see these requests.

How the error is recognized

  • The database comes from the Hibernate dialect, which Hibernate picks from the JDBC connection at startup. PostgreSQLDialect.class.isInstance(...) also matches subclasses.
  • The SQLSTATE comes from the first SQLException among the exception's causes, so it works whether the error comes from persist or from commit. The message is not parsed.
  • An entry names both the database and the SQLSTATE because the same code means different things on different databases. Each entry also names its error code, since different errors need different codes. Adding a case is one entry in DatabaseErrors.

Test values

  • The PostgreSQL test uses a location with 1,900 seeded random letters from U+0100 to U+02AF, 2 bytes each in UTF-8: 1,917 characters and 3,817 bytes. Random letters keep PostgreSQL from compressing the entry below the limit.
  • It writes the row through TransactionManager instead of the API, so it doesn't need a long storage-root.tables, and it reuses the existing PostgreSQL container.

Driver

  • main already ships postgresql-42.7.2.jar in jars/classpath, so deployments may rely on the bundled driver. Excluding it would break them on upgrade. pgjdbc is BSD-2-Clause.
  • jdbc-adapter doesn't use the driver directly. Its classes have no references to org.postgresql, and it gets connections from the DataSource we pass in, so it needs no upgrade.
  • The version is pinned with dependencyOverrides, so a dependency that brings another version, such as 42.7.2 from jdbc-adapter, can't change it. server/Runtime/externalDependencyClasspath and server/Test/externalDependencyClasspath each contain one driver, postgresql-42.7.14.jar.
  • 42.7.13, which tests used before, is affected by CVE-2026-107314 and CVE-2026-107315, both fixed in 42.7.14.

This pull request and its description were written by Isaac.

@shba24 shba24 changed the title [Server] Ship the PostgreSQL driver and bound the table storage root [Server] Upgrade the PostgreSQL driver to 42.7.14 and check storage-root.tables length at startup Oct 16, 2026
@shba24 shba24 changed the title [Server] Upgrade the PostgreSQL driver to 42.7.14 and check storage-root.tables length at startup [Server] Return INVALID_ARGUMENT when a value exceeds a PostgreSQL limit Oct 16, 2026
@shba24
shba24 force-pushed the uc-pg-production branch 4 times, most recently from 8c0dbaf to 148395f Compare October 16, 2026 05:16
@shba24 shba24 changed the title [Server] Return INVALID_ARGUMENT when a value exceeds a PostgreSQL limit [Server] Return INVALID_ARGUMENT for PostgreSQL limit errors and upgrade the driver to 42.7.14 Oct 16, 2026
@shba24
shba24 force-pushed the uc-pg-production branch 2 times, most recently from a8dd80d to 434131d Compare October 16, 2026 08:15

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

Thanks @shba24 for the contribution. Generally looks good, please have a look at my one comment.

@yili-db

yili-db commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

/review

@timothyw553

Copy link
Copy Markdown
Collaborator

@shba24

shba24 commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks @timothyw553 for the stamp! I went through the three AI notes. My take is below; tell me if you see any of them differently.

1. A driver operators added before. Agreed. I pushed 4a89e5d, which adds one line to the PostgreSQL prerequisites in deployment.md: "If you added a PostgreSQL driver to jars/classpath before, remove it." Two caveats: main already ships 42.7.2 through jdbc-adapter, so operators who followed the old guide already have two drivers today. And jars/classpath is generated by the build, so an entry added by hand doesn't survive an upgrade to a new tarball.

2. The 54000 Javadoc. I'd leave it. The match is exact on purpose, as we discussed in the thread: 54001, 54011 and 54023 still return 500. The Javadoc says "for example an index entry", so it doesn't claim the index is the only case. Would you like it to say explicitly that the subclasses are excluded? That's a one-line change.

3. The driver pinned in two places. I'd keep both lines, because they do different things. The direct dependency makes the server ship the driver. dependencyOverrides holds it at 42.7.14: without it, sbt would quietly switch to a newer version that another library brings in. There's no comment because I thought the override itself says it's a pin. Do you think a short comment would help, like the ones on caffeineVersion and micrometerVersion?

shba24 and others added 3 commits October 19, 2026 18:56
Creating a staging table whose location is longer than PostgreSQL's
2,704-byte limit on an index entry returned a 500. This can happen when
the catalog and schema have no storage location and storage-root.tables
is long.

DatabaseErrors lists database errors by database, SQLSTATE and the error
code to return. TransactionManager uses that code and falls back to
INTERNAL. The only entry is PostgreSQL's 54000 (program_limit_exceeded),
mapped to INVALID_ARGUMENT. The message is unchanged.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
The server ships the PostgreSQL driver that jdbc-adapter brings in,
42.7.2, which is affected by CVE-2026-42198. Declare the driver as a
direct dependency at 42.7.14 so the server and the tests use the same
version, and fix the deployment guide, which asked users to add a driver
the server already ships.

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

shba24 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

AI review, run locally (#1993)

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 head: 58faa91 (current head).

@shba24

shba24 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

/review

The guide named jdbc-adapter 2.7.0, but the build uses 2.13.0. Name the
adapter without a version so the text stays correct on upgrades.

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

shba24 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

Re: AI review (today's run)

Thanks. My take on each; tell me if you see any differently:

  • Blocker1, 54000 being broader than index entries: no change, as discussed in this thread. The examples the review gives, jsonb or array size limits and the per-transaction command limit, aren't reachable in UC: the schema has no jsonb or array columns, and UC transactions are short. Matching on the message text ("index row size") would break when PostgreSQL's messages are translated (lc_messages) or reworded in a later version.
  • Nit1, dialect subclasses: CockroachDialect extends Dialect, not PostgreSQLDialect, in Hibernate 6.5. PostgresPlusDialect does extend it, and that's a PostgreSQL-compatible server, so the mapping is right there.
  • Nit2, the first SQLException wins: the method's Javadoc already says so ("the SQLSTATE of the first SQLException among the causes").
  • Nit3, the raw database message on the 400: this is the same message the 500 carried before. Fine to trim in a follow-up.
  • Nit4, jdbc-adapter version in the guide: fixed in 68a0ac7. The text now says "the Casbin JDBC adapter", without a version.

@shba24
shba24 requested a review from timothyw553 October 20, 2026 20:23
@shba24

shba24 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

/review

Notes that DatabaseErrors entries match dialect subclasses and the whole
54000 code, explains the PostgreSQL dependencyOverrides entry, and states
the deployment guide's driver rule directly.

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

shba24 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@shba24

shba24 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

Re: AI review (68a0ac7)

Addressed in 7fb2387:

  • Nit2: the description now says the 400 covers repositories that run through TransactionManager; ModelRepository still returns INTERNAL.
  • Nit3: the DatabaseErrors Javadoc says dialect subclasses and the whole 54000 code are mapped on purpose.
  • Nit6: build.sbt explains the dependencyOverrides entry.
  • Nit7: the deployment guide states the driver rule directly.

No change needed for the rest:

  • Nit1 (dialect lookup throwing): SessionFactoryImpl doesn't throw there.
  • Nit4 (400 for a configuration-derived location): intended; see "400 for a configuration-caused error" in the description.
  • Nit5: kept as is.

@yili-db
yili-db merged commit 8715cd5 into unitycatalog:main Oct 22, 2026
17 of 18 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