-
Notifications
You must be signed in to change notification settings - Fork 33
Add Asynchronous Token Refresh to RefreshableTokenSource
#455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
renaudhartert-db
requested changes
Jun 2, 2025
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/Token.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Outdated
Show resolved
Hide resolved
parthban-db
reviewed
Jun 2, 2025
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Show resolved
Hide resolved
parthban-db
reviewed
Jun 2, 2025
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Outdated
Show resolved
Hide resolved
parthban-db
reviewed
Jun 2, 2025
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Outdated
Show resolved
Hide resolved
parthban-db
reviewed
Jun 2, 2025
databricks-sdk-java/src/test/java/com/databricks/sdk/core/oauth/RefreshableTokenSourceTest.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/test/java/com/databricks/sdk/core/oauth/RefreshableTokenSourceTest.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Show resolved
Hide resolved
databricks-sdk-java/src/test/java/com/databricks/sdk/core/oauth/RefreshableTokenSourceTest.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/Token.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/test/java/com/databricks/sdk/core/oauth/RefreshableTokenSourceTest.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/Token.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/test/java/com/databricks/sdk/core/oauth/RefreshableTokenSourceTest.java
Outdated
Show resolved
Hide resolved
parthban-db
reviewed
Jun 16, 2025
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Outdated
Show resolved
Hide resolved
parthban-db
reviewed
Jun 16, 2025
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/RefreshableTokenSource.java
Outdated
Show resolved
Hide resolved
parthban-db
approved these changes
Jun 16, 2025
Contributor
parthban-db
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo comments.
renaudhartert-db
approved these changes
Jun 16, 2025
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jun 18, 2025
## What changes are proposed in this pull request? This PR introduces a new environment variable `DATABRICKS_ENABLE_EXPERIMENTAL_ASYNC_TOKEN_REFRESH` to enable asynchronous token refresh in the Databricks SDK for Java. This feature improves performance by allowing token refresh operations to happen in the background, reducing latency for API calls. This change activates the asynchronous refresh capability that was previously added in #455. When enabled, stale tokens will trigger a background refresh while expired tokens will still block until a new token is fetched. ### How to Enable Async Token Refresh Set the environment variable: ```bash export DATABRICKS_ENABLE_EXPERIMENTAL_ASYNC_TOKEN_REFRESH=true ``` This setting will be automatically picked up by the SDK and applied to all token refresh operations. ## How is this tested? Manual verification that existing unit tests and integration tests pass with both async refresh disabled and enabled.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Synchronous token refresh introduces unnecessary blocking and latency, which becomes especially problematic in high QPS (Queries Per Second) workloads. In such scenarios, blocking token refresh operations can create bottlenecks, impact throughput, and cause request queuing.
Solution
This PR introduces asynchronous token refresh to improve responsiveness and reliability, with particular benefits for high-throughput applications.
What changes are proposed in this pull request?
Async Refresh Option: Added
withAsyncRefresh(boolean enabled)method to enable/disable asynchronous token refresh. When enabled, tokens are refreshed in the background when they become "stale" (close to expiry).Token State Management
FRESH: Token is valid and not close to expirySTALE: Token is valid but will expire soon (triggers async refresh if enabled)EXPIRED: Token has expired (requires blocking refresh)Tokenclass is now a pure data class, holding only token information (access token, refresh token, expiry time).TokenSourceimplementations are responsible for token state management and refresh logic.Performance Optimizations
Thread Safety & Reliability
Configuration Options
Experimental Features (may change in future releases):
Testing
The
RefreshableTokenSourceclass can be configured with a custom clock supplier viawithClockSupplier(ClockSupplier clockSupplier), allowing tests to precisely control and simulate token expiry and refresh timing. This enables deterministic testing of token state transitions and refresh behavior without relying on real system time.NO_CHANGELOG=true