Add Enhanced Routing support for Hyperscale reader endpoints (TDS FEATUREEXT 0x0F / ENVCHANGE type 21) - #2935
Merged
Ananya Garg (Ananya2) merged 15 commits intoApr 27, 2026
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2935 +/- ##
============================================
+ Coverage 60.79% 60.85% +0.05%
- Complexity 4958 4988 +30
============================================
Files 151 151
Lines 35175 35221 +46
Branches 5882 5900 +18
============================================
+ Hits 21385 21433 +48
- Misses 10931 10933 +2
+ Partials 2859 2855 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…uting and routing info capture for load balancing
Ananya Garg (Ananya2)
force-pushed
the
user/anagarg/enhanced-routing-load-balancing
branch
2 times, most recently
from
April 17, 2026 06:48
c34c4d3 to
2708847
Compare
Ananya Garg (Ananya2)
force-pushed
the
user/anagarg/enhanced-routing-load-balancing
branch
from
April 17, 2026 06:58
2708847 to
6186e4e
Compare
…edgment; now logs a warning instead.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds JDBC driver support for Hyperscale “Enhanced Routing” by negotiating FEATUREEXT 0x0F, parsing ENVCHANGE 0x21 (server/port + alternate database), and ensuring routed reconnections use the routed database name in Login7.
Changes:
- Always request Enhanced Routing via Login7 feature extensions and handle
FEATUREEXTACKfor0x0F. - Parse
ENVCHANGE 21to capture routed server/port/database and propagate it throughServerPortPlaceHolder. - Add targeted tests and a new test tag for enhanced routing scenarios.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java |
Negotiates Enhanced Routing, parses ENVCHANGE 21, adds login routing guard, and overrides Login7 DB name during routed reconnects. |
src/main/java/com/microsoft/sqlserver/jdbc/ServerPortPlaceHolder.java |
Extends routing placeholder to carry a database name for enhanced routing. |
src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java |
Adds TDS feature constant 0x0F and token name mapping. |
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java |
Adds localized strings for enhanced routing ack/validation errors. |
src/test/java/com/microsoft/sqlserver/jdbc/EnhancedRoutingIntegrationTest.java |
Adds mocked-protocol tests for feature ack parsing, ENVCHANGE 21 validation, and routing guard behavior. |
src/test/java/com/microsoft/sqlserver/testframework/Constants.java |
Adds enhancedRouting test tag constant. |
Divang Sharma (divang)
left a comment
Contributor
There was a problem hiding this comment.
minor comment
Mahendra Chavan (machavan)
previously approved these changes
Apr 27, 2026
Muskan Gupta (muskan124947)
previously approved these changes
Apr 27, 2026
Ananya Garg (Ananya2)
dismissed stale reviews from Muskan Gupta (muskan124947) and Mahendra Chavan (machavan)
via
April 27, 2026 07:09
a15f434
Divang Sharma (divang)
approved these changes
Apr 27, 2026
Mahendra Chavan (machavan)
approved these changes
Apr 27, 2026
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
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.
Overview
Hyperscale is introducing reader endpoints that load balance connections across named replicas. Unlike standard gateway routing (ENVCHANGE type 20 0x14) which only carries server and port, reader endpoints need to route connections to both a target network location and a specific database — since the client doesn't know the database ahead of time.
This PR implements the full TDS protocol changes required for the JDBC driver to support this scenario.
Changes
Feature negotiation:
The driver now always sends
FEATUREEXT 0x0F(EnhancedRouting) in the Login7 feature extension block, regardless of the target server. When the server acknowledges with a 1-byte payload (data[0]=1), the driver enables enhanced routing support for the session. This ensures backward compatibility — older servers that don't recognize the token simply ignore it.ENVCHANGE 0x21 parsing:
A new ENVCHANGE type 21 (EnhancedRouting) is now parsed alongside the existing type 20 (Routing). The enhanced payload includes all standard routing fields plus a required
AlternateDatabasefield (≤128 characters). The driver validates port number and database name, and updateshostNameInCertificatefor the routed server domain.Routing guard in login():
When the server sends ENVCHANGE type 21 0X15 with a database name but did not acknowledge the enhanced routing feature, the driver discards the routing info and stays on the original server. This is the critical safety mechanism that prevents an unverified server from redirecting the client to an arbitrary database.
Login7 database name override:
On the reconnection to the routed target, the driver uses the database name from the routing info (not the connection string) in the Login7 packet. This ensures the routed replica receives the correct database context.
ServerPortPlaceHolder extension:
The routing placeholder now carries a
databaseNamefield, enabling the routing info to flow through the existing connection lifecycle without structural changes.Test coverage
13 tests organized into 3 groups, using crafted TDS packets injected via mocked
TDSReader/TDSPacket:Routing behavior:
Feature negotiation:
[1]sets flag true[0]leaves flag falseENVCHANGE 21 validation:
hostNameInCertificateupdated for routed server domainManual testing
Validated end-to-end against an Azure Hyperscale database on a OneBox server with 3 named replicas behind a reader endpoint:
DB_NAME()on each target replica