Skip to content

Clean up code for transaction management and auth - #974

Merged
tdas merged 10 commits into
unitycatalog:mainfrom
vikrantpuppala:scel/3-cleanupo
Apr 29, 2025
Merged

tdas merged 10 commits into
unitycatalog:mainfrom
vikrantpuppala:scel/3-cleanupo

Conversation

@vikrantpuppala

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

Clean up code for transaction management and auth

Signed-off-by: Vikrant Puppala <[email protected]>
Signed-off-by: Vikrant Puppala <[email protected]>
Signed-off-by: Vikrant Puppala <[email protected]>
Signed-off-by: Vikrant Puppala <[email protected]>
Signed-off-by: Vikrant Puppala <[email protected]>
Signed-off-by: Vikrant Puppala <[email protected]>
# Conflicts:
#	server/src/main/java/io/unitycatalog/server/service/CredentialService.java
Signed-off-by: Vikrant Puppala <[email protected]>
}

// If we're proceeding with force=true, delete all schemas with pagination
if (force) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why this change in logic?
and is this logic change covered in unit test?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this is only a slight change in how the if conditions are written, the logic is still the same. I don't think we have tests for force specifically.

try {
List<PropertyDAO> propertyDAOList =
PropertyRepository.findProperties(session, UUID.fromString(uuid), entityType);
if (propertyDAOList.isEmpty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how is this logic change tested?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I updated a test case to test this

@tdas tdas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@tdas
tdas merged commit b141f19 into unitycatalog:main Apr 29, 2025
JacquesT2 pushed a commit to JacquesT2/unitycatalog that referenced this pull request May 12, 2025
**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**

<!-- Please state what you've changed and how it might affect the users.
-->
Clean up code for transaction management and auth

---------

Signed-off-by: Vikrant Puppala <[email protected]>
Signed-off-by: JacquesT2 <[email protected]>
shba24 added a commit to shba24/unitycatalog that referenced this pull request Oct 20, 2026
…error

Since unitycatalog#974 moved createUser onto TransactionManager, a database error
arrives as BaseException(INTERNAL), and the SCIM create catch-all
mapped it to BadRequestException, so the error body said 400 and the
5xx was not logged. Map server-side codes to ServerErrorException with
the original exception as the cause.

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
shba24 added a commit to shba24/unitycatalog that referenced this pull request Oct 22, 2026
…error

Since unitycatalog#974 moved createUser onto TransactionManager, a database error
arrives as BaseException(INTERNAL), and the SCIM create catch-all
mapped it to BadRequestException, so the error body said 400 and the
5xx was not logged. Map server-side codes to ServerErrorException with
the original exception as the cause.

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
shba24 added a commit to shba24/unitycatalog that referenced this pull request Oct 25, 2026
…error

Since unitycatalog#974 moved createUser onto TransactionManager, a database error
arrives as BaseException(INTERNAL), and the SCIM create catch-all
mapped it to BadRequestException, so the error body said 400 and the
5xx was not logged. Map server-side codes to ServerErrorException with
the original exception as the cause.

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
yili-db pushed a commit that referenced this pull request Oct 25, 2026
**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**

A failed request left no trace in the server log, and the log lines one
request wrote could not be told apart from another's. With this change:

- Each log line written while serving a request has `request_id=<id>`,
the ID Armeria generates for that request, and every line names the host
(with the shipped log4j2 configs).
- Each 5xx is logged once at `ERROR` with its cause, where the error
response is built (UC, Iceberg, Delta, SCIM).
- Database errors keep their cause. A failed rollback or session close
is attached to the error instead of replacing it, and a replay signal
whose rollback fails returns 500. A custom isolation level is no longer
restored by hand: Hikari resets it when the connection returns to the
pool.
- A failed policy-refresh read is a `WARN`, because revokes from other
instances stop arriving until a read succeeds.
- Bootstrap creates the admin only when the lookup returns not-found.
Any other error fails startup.

**Compatibility:** the API is unchanged; no request or response header
is added. The default log line format gains the host name and
`request_id=`, so log parsers that match the old pattern need updating.
The Helm chart copies the log4j2 config template instead of running
`envsubst` on it, so a `${VAR}` in it is now a Log4j lookup. A 4xx whose
rollback also fails now returns that 4xx; before, it returned 500. A
transaction with a custom isolation level no longer checks out a second
connection after it commits, so a committed write can no longer come
back as a 500 when that checkout fails. Startup now fails if the admin
lookup fails with anything other than not-found, instead of treating it
as "no admin yet". A SCIM create-user that fails in the database now
reports `"status":"500"` in the SCIM error body instead of `"400"`; the
HTTP status stays 500. Log levels that alerts may match on change: the
token-exchange lookup failure moves from `ERROR` with a stack trace to
`WARN` without one, and the Casbin policy-refresh read failures move
from `DEBUG` to `WARN`.

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

- **Request ID:** the Armeria request context's own ID.
`RequestContextDataProvider`, a Log4j `ContextDataProvider`, exports
fields of the current Armeria request through Armeria's
`RequestContextExporter`, the same exporter Armeria's Logback
integration uses. Today it exports only `request_id`; another field is
one more `builtIn(...)` entry. The Armeria context follows the request
onto the blocking executor, where a per-thread MDC would not.
- **No header:** neither the Iceberg REST spec nor `api/all.yaml` /
`api/delta.yaml` defines a request-ID header, so this PR doesn't read
one from callers or return one. That would be new API surface, and it
can come later through the spec if wanted.
- **One place to log:** `BaseExceptionHandler.handleException` (and the
Iceberg handler's override of it, from #1984), using the status the
dialect actually answers with (Delta has its own), so each 5xx is logged
once, with only its cause: the request ID on the line identifies the
request. Token exchange still names the failed lookup (email or client
ID), now as a `WARN` without the stack trace, so the cause isn't logged
twice. A rollback or session-close failure behind a 4xx or a replay
signal, which the handler doesn't log, is a `WARN` from
`TransactionManager`.
- **SCIM:** it answers every error with HTTP 500 (unchanged here) and
logs by the SCIM error's own status, so a duplicate user isn't an
`ERROR`. `createScimUser` labelled database errors 400 since #974
wrapped them as `BaseException(INTERNAL)`; they now map to
`ServerErrorException` with the cause, so they are logged.
- **Armeria flags:** when a `com.linecorp.armeria.*` property is set,
Armeria logs during startup before its context storage exists. The
provider returns no fields for those lines instead of throwing, and
builds the exporter only once a request is served, as Armeria's own
appender does.
- **Not in this PR:** JSON or stdout logging, a setting for the
log-config path, a build check for catch blocks that drop the exception,
the SCIM 500 status, and `DeltaPropertyMapper` dropping its cause.
- **Tests:** an end-to-end test in `AuthServiceTest` makes the database
reject a SCIM user insert and checks the 500 status in the body;
`TransactionManagerTest` fails each point in turn (isolation set,
operation, commit, rollback, session close) and checks the thrown error,
its cause and the suppressed failures; its existing real-database test
checks that the level is back to the original after a transaction; two
bootstrap tests are in `UserRepositoryTest`;
`UnityCatalogServerTest.logLinesCarryTheRequestId` checks that Log4j
finds the provider and that it supplies the request ID inside a request
and nothing outside one. There are no log-output tests. `build/sbt test`
passed at b9cab14, except for one run of
`SdkModelCRUDTest.testModelCRUD`, a known same-millisecond timing flake
in model updates that this PR doesn't touch; it passes on rerun. The
later commits, and the rebase onto main at 4626de6, were checked with
the test classes they touch.

</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