Skip to content

[Server] Offload blocking catalog work from Armeria event loops - #1918

Merged
yili-db merged 20 commits into
unitycatalog:mainfrom
s-maling-celonis:fix/offload-catalog-jdbc-upstream
Oct 21, 2026
Merged

yili-db merged 20 commits into
unitycatalog:mainfrom
s-maling-celonis:fix/offload-catalog-jdbc-upstream

Conversation

@s-maling-celonis

@s-maling-celonis s-maling-celonis commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Description of changes

Annotated catalog handlers and the authentication/authorization route decorators perform blocking database work. On HTTP/2, streams on one connection share an event loop, so one slow database operation can stall unrelated requests on that connection.

This change:

  • runs annotated handlers on Armeria’s blocking executor;
  • moves authentication and authorization decorators off the event loop;
  • sizes the blocking executor and URL transcoder connection pool to the Hikari maximum pool size;
  • preserves the executor across server stop/start and drains it during close, bounded by server.shutdown-timeout (default 5s);
  • propagates database failures during user lookup instead of converting them to permission denials.

/livez is left to the observability endpoints. There are no REST API changes.

Verification

  • build/sbt javafmtAll
  • build/sbt "server/compile"
  • HibernateConfiguratorTest, ServerPropertiesTest, URLTranscoderVerticleTest, EventLoopStallTest, ArmeriaServerBuilderTest

PR checklist

  • A description of the changes is included.
  • Tests cover event-loop concurrency, URL transcoder pool sizing, Hikari pool sizing, shutdown timeout, and shutdown.
  • No documentation update is needed; server.shutdown-timeout is commented in etc/conf/server.properties.

static int connectionPoolSize(Properties hibernateProperties) {
return Integer.parseInt(
hibernateProperties.getProperty(
"hibernate.connection.pool_size", Integer.toString(DEFAULT_CONNECTION_POOL_SIZE)));

@yili-db yili-db Sep 28, 2026 •

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.

Should this read hibernate.hikari.maximumPoolSize from #1863?
It's already available via this.dataSource.getMaximumPoolSize()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. getConnectionPoolSize now returns dataSource.getMaximumPoolSize(), so hibernate.hikari.maximumPoolSize wins and hibernate.connection.pool_size stays the fallback. The tests cover both.

// One HTTP/2 connection is pinned to one event loop. JDBC runs on this pool instead.
// UnityCatalogServer owns it so stop/start can reuse it; only close shuts it down.
// Keep stop() request-safe even though it no longer shuts down the executor.
.gracefulShutdownTimeoutMillis(1, Long.MAX_VALUE)

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.

Should still apply a timeout limit here to avoid blocking shutdown forever?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. The quiet period stays 1ms so an idle server still stops immediately. The timeout is server.shutdown-timeout, default PT5S.

executor.shutdown();
while (!executor.isTerminated()) {
try {
executor.awaitTermination(1, TimeUnit.HOURS);

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.

The loop waits for termination indefinitely, and the 1 HOUR cap is far longer than the grace period we run under: k8s SIGKILLs at terminationGracePeriodSeconds (default 30s), docker stop at 10s. So a wedged JDBC task just gets hard-killed mid-drain, and we never reach the timeout or get to log/clean up. Can we bound this to seconds (under the grace period, ideally configurable) and LOGGER.warn + proceed on timeout, instead of waiting indefinitely?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Close waits once for that same timeout, logs a warning if the executor is still running, and continues. shutdown() already rejects new work, so a wedged JDBC task no longer holds shutdown until the grace period kills the process.

private static final Logger LOGGER = LoggerFactory.getLogger(URLTranscoderVerticle.class);

/** Liveness endpoint answered by the transcoder itself. Readiness should keep probing Armeria. */
static final String LIVENESS_PATH = "/livez";

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.

There is already #1906 adding /livez as well as /readyz and /metrics.
Can you please remove it from this PR to make this PR focused on thread pool?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Removed /livez from the URL transcoder and its tests. Liveness stays with #1906.

@s-maling-celonis
s-maling-celonis force-pushed the fix/offload-catalog-jdbc-upstream branch from febb464 to eea703e Compare September 28, 2026 08:56
@s-maling-celonis

Copy link
Copy Markdown
Contributor Author

Thanks for the comments, @yili-db. The four points are addressed and the branch is rebased onto latest main. Ready for re-review.

@s-maling-celonis
s-maling-celonis force-pushed the fix/offload-catalog-jdbc-upstream branch from eea703e to 659f485 Compare September 29, 2026 08:48
closeAuthorizer(null);
} finally {
try {
closeBlockingTaskExecutor(blockingTaskExecutor, null);

@yili-db yili-db Sep 30, 2026 •

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.

The timeout is applied to both the graceful stop and the executor drain, so worst case is ~2× — should they share one deadline so that later shutdown timeout be reduced according to how much has already been spent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, done in af9a5fb. close() now sets one deadline from server.shutdown-timeout before stop(), and the executor drain only gets what is left, so the worst case is about 1× the timeout. The server.properties and ServerProperties comments now describe it as one total budget.

executor.shutdown();
try {
if (!executor.awaitTermination(shutdownTimeout.toMillis(), TimeUnit.MILLISECONDS)) {
LOGGER.warn(

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.

This bounded drain (await → warn → continue) is the behavior we asked for, but nothing tests it. stopWaitsForBlockedRequestAndExecutorRemainsActive always releases the task, so the timeout branch never runs. Can you please add a case with a small server.shutdown-timeout (e.g. PT1S) and a task that stays wedged, asserting close() returns within roughly the timeout and logs the warning? That way a later revert to an unbounded wait auto-breaks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added UnityCatalogServerShutdownTest in af9a5fb. It starts a server with server.shutdown-timeout=PT1S, wedges a task on the server's blocking executor, and asserts that close() returns within about the timeout and logs the "did not stop within" warning. I checked that it fails if the drain waits 30s instead of the remaining budget.

One limit: it wedges an executor task, not an in-flight HTTP request, so stop() itself returns quickly and the test does not exercise the case where stop uses part of the budget. Wedging a real request needs a hook into a handler, which I did not want to add to production code just for this. Happy to add one if you think it is worth it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Follow-up in 07dca14: the test now holds a real request rather than an executor task, so the package-private blockingTaskExecutor() accessor is gone. A test CloudCredentialVendor, passed in through the existing credentialOperations(...) builder hook, blocks inside vendCredential, and the test sends a POST /temporary-path-credentials that gets stuck there on the blocking executor. Because a request is in flight, graceful stop now uses the whole budget, so the test also covers the shared deadline from your other comment.

Doing it this way showed that Armeria adds a fixed ~2s to every stop(), idle or not. After the graceful drain it calls the no-argument shutdownGracefully() on its internal boss event loop, which uses Netty's default 2s quiet period, and that loop cannot be configured. Measured with server.shutdown-timeout=PT2S:

  • idle server: ~2s
  • stuck request, shared deadline: ~4s (test passes, bound is 5s)
  • stuck request, separate budgets for stop and drain: ~6s (test fails)

So the real worst case is server.shutdown-timeout + ~2s. server.properties now says to keep the timeout plus 2s under the orchestrator grace period. With the default PT5S that is about 7s, still under docker stop's 10s.

s-maling-celonis and others added 13 commits October 6, 2026 12:44
Signed-off-by: Simon Maling <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
Signed-off-by: Simon Maling <[email protected]>

Signed-off-by: s-maling-celonis <[email protected]>
Signed-off-by: Simon Maling <[email protected]>

Signed-off-by: s-maling-celonis <[email protected]>
Signed-off-by: Simon Maling <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
Signed-off-by: Simon Maling <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
Signed-off-by: Simon Maling <[email protected]>

Signed-off-by: s-maling-celonis <[email protected]>
Signed-off-by: Simon Maling <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
A probe that waits for a backend pool slot can time out under load and
restart a saturated process, dropping every in-flight request.

Signed-off-by: s-maling-celonis <[email protected]>
Co-authored-by: Cursor <[email protected]>
stop() can RST the in-flight HTTP/2 stream, so EventLoopStallTest
flaked on a client 500 even when the blocked handler completed.

Signed-off-by: s-maling-celonis <[email protected]>
Co-authored-by: Cursor <[email protected]>
stop() and the blocking-executor drain share server.shutdown-timeout
(default 5s) and continue after a warning. /livez is removed here so it
can land with the observability endpoints.

Signed-off-by: s-maling-celonis <[email protected]>
Co-authored-by: Cursor <[email protected]>
close() now starts the server.shutdown-timeout budget before stop() and gives
the blocking-executor drain only what is left, so a wedged request cannot make
shutdown take about twice the timeout. UnityCatalogServerShutdownTest wedges a
task on the server's executor with a PT1S timeout and checks that close()
returns within that budget and logs the warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
…utor.

UnityCatalogServerShutdownTest now wedges a temporary-path-credentials request
inside a test CloudCredentialVendor, supplied through the existing
credentialOperations builder hook, so the blockingTaskExecutor() accessor is
gone. With a request in flight, graceful stop uses the whole budget, so the test
also covers the shared deadline: it fails at about 6s if stop and the drain get
separate budgets.

Armeria adds a fixed ~2s to every stop (the default quiet period on its internal
boss event loop), so the test allows for it and server.properties now says to
keep the timeout plus 2s under the orchestrator grace period.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
…servability.

Upstream's UnityCatalogServerTest builds an ArmeriaServerBuilder directly, so it now passes a
blocking executor. The API surface is a port-based virtual host, which rejects port 0, so
EventLoopStallTest picks a free port instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
@s-maling-celonis
s-maling-celonis force-pushed the fix/offload-catalog-jdbc-upstream branch from 07dca14 to 4dc2a77 Compare October 6, 2026 10:52
// A missing user is a denial. Pool exhaustion and other database failures are BaseException
// INTERNAL from TransactionManager; mapping those to PERMISSION_DENIED reports a 403 for an
// outage.
if (failure.getErrorCode() != ErrorCode.NOT_FOUND) {

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.

Can we add a test for this? Nothing covers either branch today, and narrowing the catch from Exception to BaseException also means a non-BaseException now propagates instead of becoming a 403.

The DB-failure branch is easiest as a small AuthDecoratorTest (mock UserRepository like TokenExchangeSubjectTokenHandlerTest, real SecurityContext from etc/conf), parameterized over NOT_FOUND → PERMISSION_DENIED, INTERNAL → rethrown, and a non-BaseException → propagates. The missing-user 403 could alternatively sit next to unauthenticatedRequestIsRejected in PermissionServiceTest, since createTestUserServerConfig already mints a token for a user that doesn't exist.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, added both in 0be5d22:

  1. AuthDecoratorTest, with a real internal token signed with the etc/conf keys and a mocked UserRepository. It is parameterized over NOT_FOUND → PERMISSION_DENIED, INTERNAL → rethrown with its own code, and a non-BaseException → propagates as is. Two more cases cover a disabled user (403) and an enabled user (served). Each failure case also checks the request never reaches the delegate.
  2. PermissionServiceTest.tokenForAMissingUserIsDenied, next to unauthenticatedRequestIsRejected: a createTestUserServerConfig token for a user that does not exist gets a 403 "User not allowed", recorded in the request metric.

With the old catch (Exception e) put back, the INTERNAL and non-BaseException cases fail.

A missing user is denied with PERMISSION_DENIED, a database failure keeps
its INTERNAL error instead of becoming a 403, and an exception that is not
a BaseException propagates. Also cover a disabled and an enabled user, and
a valid token for a user that was never created in PermissionServiceTest.

Signed-off-by: s-maling-celonis <[email protected]>

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

thank you @s-maling-celonis for the contribution! left two comments.

Comment on lines +504 to +505
* <p>{@code server.shutdown-timeout} is one budget for the whole call: the executor drain only
* gets what the graceful HTTP stop left over, so a wedged request cannot double the wait.

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.

the timeout does not cover the whole shutdown call. Storage cleanup can wait five seconds before HTTP shutdown starts. HTTP shutdown then receives its full configured timeout. Authorizer and database cleanup have separate waits. the new configuration instructions at etc/conf/server.properties also imply that the configured timeout plus two seconds is sufficient.

keep the implementation focused: describe this as a request-drain budget, not a total shutdown deadline. correct the configuration instructions too.

-   * <p>{@code server.shutdown-timeout} is one budget for the whole call: the executor drain only
-   * gets what the graceful HTTP stop left over, so a wedged request cannot double the wait.
+   * <p>The blocking-executor drain uses the time remaining from {@code server.shutdown-timeout}.
+   * This is not a total shutdown deadline: other resource cleanup and Armeria's final shutdown
+   * can add time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, thanks. Fixed in 4553a34, with the docs only and no behavior change:

  • The close() Javadoc uses your wording. The executor drain gets what is left of server.shutdown-timeout, and this is not a total shutdown deadline.
  • etc/conf/server.properties now describes the setting as the graceful request-drain wait. It lists what adds time on top (storage cleanup stop, Armeria's ~2s final shutdown, authorizer and pool close) and says to leave headroom under the grace period, instead of "timeout plus 2s".
  • The SHUTDOWN_TIMEOUT comment in ServerProperties said "one shared bound", so I corrected it the same way.

.isInstanceOf(TimeoutException.class);

release.countDown();
// stop() can RST the HTTP/2 stream, so the client may see 500 even when hold() returned.

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.

Armeria has a separate two-second shutdown quiet period. Therefore, shutdown can take longer than 250 milliseconds even when it does not wait for the request.

Retain the response future and verify a successful HTTP response after releasing the handler. Confirm that disabling graceful request draining makes the test fail.

-      client.get("/api/probe/hold").aggregate();
+      CompletableFuture<AggregatedHttpResponse> response =
+          client.get("/api/probe/hold").aggregate();
@@
       release.countDown();
-      // stop() can RST the HTTP/2 stream, so the client may see 500 even when hold() returned.
+      assertThat(response.get(5, TimeUnit.SECONDS).status()).isEqualTo(HttpStatus.OK);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks. Fixed in 4553a34. The test now keeps the response future and asserts 200 OK after release, and the finished latch is gone.

I did the check you asked for, setting gracefulShutdownTimeoutMillis(0, 0). With only the suggested diff, the test still passed. Armeria's ~2s quiet period meant stop was still running at 250 ms, and the handler was released before the connection closed, so the response still arrived. A diagnostic run showed that with draining off, stop() completes after ~1.8s and the client gets ClosedSessionException. With draining on, stop is still waiting at 3s and the client gets 200.

So the test now waits 3s, past the quiet period and within the 5s default timeout, before releasing the handler. Results:

  • draining off: the test fails
  • draining on: 30 repeated runs pass

This adds about 3s to the test.

server.shutdown-timeout bounds the graceful HTTP drain, and close gives
the blocking-executor drain what is left. It is not a total shutdown
deadline: storage cleanup, Armeria's final shutdown and resource
cleanup add time. Say so in the Javadoc, ServerProperties and
server.properties.

stopWaitsForBlockedRequestAndExecutorRemainsActive now asserts the held
request gets a 200 after release, and waits past Armeria's ~2s quiet
period first, so it fails when graceful draining is disabled.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: s-maling-celonis <[email protected]>
@yili-db

yili-db commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

/review

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

[AI Assisted] Thanks for addressing the earlier threads; the core change looks sound. The main remaining item is the shutdown ordering in close() (drain the executor before closing the authorizer). The offEventLoop cancellation check can be a tracked follow-up; the rest are comment-accuracy fixes and nits.

try {
stop();
} finally {
closeQuietly(metrics, null, "the metrics registry");

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.

[AI Assisted] The authorizer, cleanup worker and metrics are closed before the executor drain. If stop() times out while a request is still in flight, that handler keeps running and can then use a closed Casbin adapter (for example initializeBasicAuthorization after a create) or enqueue onto a stopped cleanup worker. Can we drain the executor first? In the normal case stop() has already waited for in-flight requests, so the drain is almost free and moving it costs nothing.

Also, the Javadoc still says only a server that owns its configurator can't be restarted. Since the executor is shut down too, no server can be restarted after close() now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, thanks. Fixed in 14d8f31: close() now drains the blocking executor first, then closes metrics, the cleanup worker, the authorizer and the owned configurator, so a handler that outlived stop() can't reach a closed Casbin adapter or cleanup worker. Each close still catches its own failure, so one failing close doesn't skip the rest. I also corrected the Javadoc: since the executor is shut down, no server can be restarted after close().

I didn't add a test for the order: neither the authorizer nor the cleanup worker can be injected through the builder, so a test would need a test-only hook.

} catch (Exception e) {
} catch (BaseException failure) {
// A missing user is a denial. Pool exhaustion and other database failures are BaseException
// INTERNAL from TransactionManager; mapping those to PERMISSION_DENIED reports a 403 for an

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.

[AI Assisted] This comment isn't accurate. In TransactionManager.executeWithTransaction, openSession() and beginTransaction() sit outside the catch, so a Hikari pool timeout comes out as a raw Hibernate exception, not BaseException INTERNAL. It still propagates as a 500 (your non-BaseException test case covers that), so only the wording is wrong. Maybe: "Anything other than NOT_FOUND is a server failure, not a denial; let it propagate."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, openSession() is outside the catch, so a pool timeout surfaces as the raw Hibernate exception. Changed to your wording in 14d8f31.

return blocking.serve(delegate, ctx, req);
}
CompletableFuture<HttpResponse> response = new CompletableFuture<>();
ctx.blockingTaskExecutor()

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.

[AI Assisted] This queue is unbounded. Under load a request can sit here past Armeria's request timeout: the client gets a 503, then auth and the handler still run and may commit. A handler that runs long already has this problem, but the queue makes the window wider. Should we check ctx.isCancelled() before blocking.serve(...) and fail with ctx.cancellationCause()? It's cheap. Not a blocker; a tracked follow-up is fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was cheap enough to do here rather than as a follow-up. In 14d8f31 the queued task checks ctx.isCancelled() first and fails with ctx.cancellationCause(), so neither auth nor the handler runs for a request the client has already given up on. New test: EventLoopStallTest.requestCancelledWhileQueuedDoesNotRunAuthOrHandler. One thread is held, a second request times out on the client while it's queued, and after release neither auth nor the handler ran for it. The test fails without the check.

}

private Server initializeServer(UnityCatalogServer.Builder unityCatalogServerBuilder) {
// One blocking thread per JDBC connection. Extra threads only wait in getConnection().

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.

[AI Assisted] "Extra threads only wait in getConnection()" isn't quite true. Every annotated handler runs on this pool, including the credential-vending paths that make STS/Azure/GCS calls with no connection held. Is the cap at the Hikari size meant as backpressure? If so, can the comment say that it also caps cloud credential calls?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, the cap is meant as backpressure. Updated in 14d8f31: the comment now says every annotated handler runs on this pool, so it also caps concurrent handlers that hold no connection, such as cloud credential vending.

}

/** Number of JDBC connections available to serve blocking requests. */
public int getConnectionPoolSize() {

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.

[AI Assisted] nit: getConnectionPoolSize() just wraps getDataSource().getMaximumPoolSize(), which is already public, and HibernateConfiguratorTest now asserts both. Could we inline it? Relatedly, main works out the transcoder pool size separately from the executor size; one value would keep the "transcoder = executor size" rule in one place.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 14d8f31: removed it, along with the duplicate assertions in HibernateConfiguratorTest. The server now reads the pool size once into a blockingThreads field, which sizes both the executor and the URL transcoder, so the "transcoder = executor size" rule lives in one place. (#1979 removes the transcoder entirely.)

return Duration.parse(get(Property.READINESS_DB_TIMEOUT));
}

/** How long stop and close wait for in-flight HTTP and blocking work. Default 5 seconds. */

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.

[AI Assisted] nit: "How long stop and close wait" sounds like each gets the full budget. The enum comment above it already describes the shared budget correctly; can this match?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 14d8f31 to match the enum comment: one shared budget, bounding the HTTP drain in stop, with close's executor drain getting what is left.

…ueued requests

close() drained the blocking executor only after closing the metrics
registry, cleanup worker, and authorizer, so a handler that outlived
stop() could reach a closed Casbin adapter or a stopped cleanup worker.
Drain first, then close the rest. No server can be restarted after
close(), since the executor is shut down; say so in the Javadoc.

A request cancelled while queued for the blocking executor (for example,
after the request timeout) now fails without running auth or the
handler, so it cannot commit work the client was told failed.

Remove HibernateConfigurator.getConnectionPoolSize(), which only wrapped
getDataSource().getMaximumPoolSize(), and size the executor and the URL
transcoder from one field. Correct the AuthDecorator, blocking-pool, and
shutdown-timeout comments.

Signed-off-by: s-maling-celonis <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>

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

two small nits, but LGTM!

Comment on lines +310 to +323
.execute(
() -> {
// A request that timed out while queued has already been answered; running auth
// and the handler now could commit work the client was told failed.
if (ctx.isCancelled()) {
response.completeExceptionally(ctx.cancellationCause());
return;
}
try {
response.complete(blocking.serve(delegate, ctx, req));
} catch (Throwable failure) {
response.completeExceptionally(failure);
}
});

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.

nit: Armeria 1.41.1 already has HttpResponse.of(Supplier<? extends HttpResponse>, Executor). we should use it to maintain less custom concurrency code:

-      CompletableFuture<HttpResponse> response = new CompletableFuture<>();
-      ctx.blockingTaskExecutor()
-          .execute(
-              () -> {
-                ...
-              });
-      return HttpResponse.of(response);
+      return HttpResponse.of(
+          () -> {
+            if (ctx.isCancelled()) {
+              return Exceptions.throwUnsafely(ctx.cancellationCause());
+            }
+            try {
+              return blocking.serve(delegate, ctx, req);
+            } catch (Exception e) {
+              return Exceptions.throwUnsafely(e);
+            }
+          },
+          ctx.blockingTaskExecutor());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call, thanks. Switched to it in 95116f6, essentially as you suggested: the cancellation check is the first thing in the supplier, and a failure from serve is rethrown with Exceptions.throwUnsafely so Armeria aborts the response with it. EventLoopStallTest.requestCancelledWhileQueuedDoesNotRunAuthOrHandler still fails without the check.

READINESS_DB_TIMEOUT("server.readiness.db-timeout", "PT2S", POSITIVE_DURATION_VALIDATOR),
// Bounds Armeria's graceful request drain; the blocking-executor drain gets what is left.
// Not a total shutdown deadline, so leave headroom under the orchestrator grace period.
SHUTDOWN_TIMEOUT("server.shutdown-timeout", "PT5S", POSITIVE_DURATION_VALIDATOR),

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.

nit: i wonder if server.graceful-shutdown-timeout is a better name? up to you haha

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I'd keep server.shutdown-timeout: the same budget also bounds close()'s blocking-executor drain after the graceful HTTP drain, so graceful- would suggest it covers only the first part.

Armeria already runs a supplier on an executor and aborts the response
if it throws, so drop the hand-rolled CompletableFuture. The cancellation
check stays first in the supplier.

Signed-off-by: s-maling-celonis <[email protected]>
@yili-db

yili-db commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

/review

@s-maling-celonis

s-maling-celonis commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@yili-db review did not work?

@yili-db

yili-db commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

@yili-db review did not work?

/review does not post automatically. It is by design for now. Human triage is always needed.

@yili-db
yili-db merged commit ce3f0a5 into unitycatalog:main Oct 21, 2026
17 of 18 checks passed
yili-db pushed a commit that referenced this pull request Oct 26, 2026
…L transcoder (#1979)

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

Today the launcher runs a Vert.x verticle on the client port. It
forwards every request over HTTP/1.1 to Armeria on `port + 1`. It does
one rewrite: Iceberg's nested-namespace separator `%1F` becomes `.`, in
the path and in query values. Unity Catalog has no nested namespaces, so
that rewrite doesn't make any request succeed. It only changes which
error a client gets for a name it could never resolve.

#1918 had to size the transcoder's connection pool to the JDBC pool, and
answer `/livez` in front of it, so a saturated proxy wouldn't become the
bottleneck. Removing the transcoder makes all of that unnecessary.

This change:
- removes `URLTranscoderVerticle` and the `vertx-core`, `vertx-web` and
`vertx-web-client` dependencies;
- binds Armeria to the `-p` port in `main`, instead of `port + 1`, and
closes the server if it can't start;
- binds the API port on all interfaces. Clients now connect to it
directly, and the loopback bind from #1750 only existed because the
transcoder sat in front;
- drops the `port + 1` handling from the observability-port check;
- updates `docs/server/observability.md`, which described the client
port and the internal `port + 1` API port.

**Reasons**

- **Simpler implementation:** the server runs as one Armeria process on
one port, with no Vert.x proxy in front.
  - About 410 lines go, including the transcoder and its 250-line test.
- **Removes the unused `\^_` transcoding:** Unity Catalog has no nested
namespaces, so rewriting `%1F` to `.` never made a request succeed.
- **Fewer dependencies:** `vertx-core`, `vertx-web` and
`vertx-web-client` are removed, so there are fewer libraries to patch
for CVEs.
- **No proxy pool to size:** the workarounds #1918 needed go away, i.e.
matching the proxy pool to JDBC and answering `/livez` in front of it.
- **Better tail latency under load:** cheap requests no longer queue for
a shared HTTP/1.1 connection pool or run through a single Vert.x thread.
- The saving per request is small, under a millisecond; the gain is
mostly in p99 under concurrency.
- **Fixes Datadog spans:** spans aren't closed properly, likely because
the Datadog agent doesn't support the Vert.x transcoder, so they stay
open until the client drops the idle connection about 30s later.
- **No more hidden proxy behaviour:** request and response bodies are no
longer held in memory, there are no unconfigurable timeouts, and the
code that caused bugs #1716 and #1855 is gone.
- **Real client addresses:** Armeria sees the caller's actual IP instead
of `127.0.0.1`, which helps logging and metrics.
- **HTTP/2 end to end:** HTTP/2 clients reach Armeria directly instead
of being downgraded to HTTP/1.1.

**Behavior changes**

- The server listens on one API port. Nothing binds `port + 1` any more.
- The API port is reachable from other machines again, as it was before
#1750. Deployments that put a network policy in front of it are
unaffected.
- `GET /v1/catalogs/{c}/namespaces/a%1Fb` and `GET
/v1/catalogs/{c}/namespaces?parent=a%1Fb` now return `404
NoSuchNamespaceException` instead of `400`. Neither form ever matched a
schema.
- The `hostname_pattern` label of `http_server_requests_total` now names
the `-p` port (`*:8080` by default) instead of `port + 1` (`*:8081`).
Dashboards or alerts that filter on `*:8081` need updating.
- One fewer hop and one fewer HTTP/1.1 connection pool per request.
HTTP/2 clients now reach Armeria directly.

No REST API, property, or CLI changes.

**Verification**

- `build/sbt javafmtAll`
- `build/sbt "server/testOnly
io.unitycatalog.server.ArmeriaServerBuilderTest
io.unitycatalog.server.UnityCatalogServerTest
io.unitycatalog.server.UnityCatalogServerShutdownTest
io.unitycatalog.server.EventLoopStallTest
io.unitycatalog.server.service.IcebergRestCatalogTest"`: 42 tests. The
first run had one `ServerPortBindException` on a random test port.
`IcebergRestCatalogTest` then passed 26/26 on rerun.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: s-maling-celonis <[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.

3 participants