Skip to content

Threading refactor (8/8): reuse user-configured executor for user-callback dispatch#8

Open
igorbernstein2 wants to merge 2 commits into
threading-refactor-phase-7from
threading-refactor-phase-8
Open

Threading refactor (8/8): reuse user-configured executor for user-callback dispatch#8
igorbernstein2 wants to merge 2 commits into
threading-refactor-phase-7from
threading-refactor-phase-8

Conversation

@igorbernstein2

Copy link
Copy Markdown
Owner

Summary

Phase 8 of 8. When the caller configures an executor on their StubSettings or InstantiatingGrpcChannelProvider, reuse it for user-callback dispatch instead of always allocating a separate bigtable-callback-shim cached pool. Closes the TODO at Client.java:92-94 that had been blocked on a missing gax API (now landed via googleapis/google-cloud-java#13557).

What's in here

Commit What it does
refactor: reuse user-configured executor for user-callback dispatch ShimImpl.create now picks the user-callback executor via a new selectUserCallbackExecutor(transportProvider, executorProvider) helper. Priority: transport-set executor (InstantiatingGrpcChannelProvider#getExecutor, exposed by gax PR googleapis#13557) → legacy StubSettings#getExecutorProvider → fresh cached pool. Ownership follows the source: transport-set is borrowed (Resource.createShared); legacy honors ExecutorProvider#shouldAutoClose(); the fallback cached pool is owned by Client as before. Client.userCallbackExecutor widens from Resource<ExecutorService> to Resource<Executor> to accept the borrowed handle.

Detection signals

Both are crisp without class-identity checks:

  • transportProvider.getExecutor() != null → user called setExecutor on the channel provider.
  • stubSettings.getExecutorProvider() != null → user called the deprecated setExecutorProvider (gax tracks this via deprecatedExecutorProviderSet in StubSettings.java:139-141, returning null from getExecutorProvider() otherwise).

Tests

ShimImplTest (new) covers all four branches of selectUserCallbackExecutor: transport-set, legacy with shouldAutoClose=false, legacy with shouldAutoClose=true, and the fallback owned pool (asserts thread-name prefix and that close() shuts it down).

The standalone Client.create(ClientSettings) path is unchanged — ClientSettings carries no executor wiring to source from.

Stack position

  • Base: threading-refactor-phase-7
  • Next: end of stack

@igorbernstein2
igorbernstein2 force-pushed the threading-refactor-phase-8 branch from 482fd48 to 80158c8 Compare June 30, 2026 15:39
ShimImpl now sources the userCallbackExecutor from the StubSettings when the
caller has configured one — either via InstantiatingGrpcChannelProvider's
setExecutor (PR googleapis#13557 exposed the getter on TransportChannelProvider) or the
legacy StubSettings#setExecutorProvider. Ownership follows the source:
transport-set is borrowed by convention; the legacy ExecutorProvider honors
shouldAutoClose(). When neither is set the existing behavior is preserved —
ShimImpl owns a dedicated bigtable-callback-shim cached pool.

Client.userCallbackExecutor widens from Resource<ExecutorService> to
Resource<Executor> to accept the borrowed handle; downstream consumers
already require only Executor.

The standalone Client.create(ClientSettings) path is unchanged: ClientSettings
carries no executor wiring to source from.
@igorbernstein2
igorbernstein2 force-pushed the threading-refactor-phase-7 branch from 62b89be to 39bbfb4 Compare June 30, 2026 17:49
@igorbernstein2
igorbernstein2 force-pushed the threading-refactor-phase-8 branch from 80158c8 to dad737a Compare June 30, 2026 17:49
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