Repository navigation
fix(spanner): attach routing hints to read-write transaction requests - #14786
Draft
samyakpjgoogle wants to merge 2 commits into
Draft
samyakpjgoogle wants to merge 2 commits into
samyakpjgoogle wants to merge 2 commits into
Conversation
Requests that belong to a read-write transaction are pinned to the transaction's affinity endpoint. In that case KeyAwareChannel skipped ChannelFinder.findServer() and sent reads and queries without a routing hint (no operation UID, key or target range). As a result the client never learned key recipes for statements that only run inside read-write transactions, and those requests could never use the server fastpath. Populate the routing hint for these requests as well, while ignoring the endpoint selected by the finder so that transaction affinity is preserved.
Contributor
There was a problem hiding this comment.
Code Review
This pull request ensures that routing hints are populated for read-write transactions in KeyAwareChannel, even when they remain pinned to their affinity endpoints, with corresponding unit tests added. The review feedback points out an inconsistency in how the preferLeader state is managed and updated within the new conditional blocks for both read and query requests, and provides suggestions to align this behavior with the existing routing logic.
This branch has not been deployed
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.
Problem
When location-aware routing is enabled,
KeyAwareChannelpins every request that belongsto a read-write transaction to the transaction's affinity endpoint. In that case
routeFromRequestskippedChannelFinder.findServer(...)entirely, so these reads andqueries were sent without a routing hint: no
operation_uid, no key, no target range.As a result:
transactions. The server only returns key recipes for requests that carry an
operation_uid, so the client can never build a routing hint for these statement shapes.transaction owner. The server falls back to the slow path for every one of them.
In a TPC-C run on a 9-node Spanner Omni deployment (3 nodes per zone), only about 10% of
requests used the fastpath. With this change it went up to about 35%.
Fix
For requests pinned to a read-write transaction's affinity endpoint, still call
finder.findServer(reqBuilder, ...)so the routing hint (operation UID, database ID, schemageneration, key and target range) is populated. The endpoint returned by the finder is
ignored, so transaction affinity is unchanged and the request still goes to the
transaction owner.
The hint is attached even when the key's leader is not the affinity endpoint. In that case
the transaction owner can forward the request through the fastpath.
Tests
Added to
KeyAwareChannelTest:readWriteTransactionReadAttachesRoutingHintWhilePinnedToAffinityEndpointreadWriteTransactionQueryAttachesRoutingHintWhilePinnedToAffinityEndpointBoth pin a read-write transaction to
server-a, send a read or query for a key owned byserver-b, and check two things: the request still goes toserver-a, and it carries afull routing hint (non-zero operation UID, database ID, key, group UID).