Skip to content

test(spanner): unflake ITSqlMusicScriptTest - #14814

Merged
sakthivelmanii merged 2 commits into
mainfrom
unflake-test01-runscript
Nov 2, 2026
Merged

sakthivelmanii merged 2 commits into
mainfrom
unflake-test01-runscript

Conversation

@sakthivelmanii

@sakthivelmanii sakthivelmanii commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  • When location-aware routing is enabled, BeginTransactionRequest calls with TransactionOptions.PartitionedDml recorded transaction affinity in KeyAwareChannel, leaking affinity entries for 10 minutes because Partitioned DML transactions are never committed or rolled back.
  • Subsequent Partitioned DML ExecuteSql and ExecuteStreamingSql calls entered KeyAwareChannel via partitionedDmlStub, causing routeFromRequest(ExecuteSqlRequest.Builder) to attach a RoutingHint and route the statement to the server fastpath, which rejects Partitioned DML transactions with INVALID_ARGUMENT: PartitionedDml Transactions may only be used to execute DML statements.

Solution

  • Configure GapicSpannerRpc's partitionedDmlStub with a ClientContext backed directly by KeyAwareChannel.defaultChannel() when KeyAwareChannel is active so Partitioned DML ExecuteSql and ExecuteStreamingSql requests bypass KeyAwareChannel and always use the default channel without routing hints.
  • Update KeyAwareChannel so BeginTransactionRequest and inline TransactionSelector.begin calls with TransactionOptions.PartitionedDml set shouldRecordTransactionAffinity = false.
  • Add unit tests in GapicSpannerRpcTest and KeyAwareChannelTest verifying that Partitioned DML requests bypass KeyAwareChannel and do not record transaction affinity.

KeyAwareChannel incorrectly attached routing hints to ExecuteSqlRequest calls inside Partitioned DML transactions when pinned to an affinity endpoint. The fix tracks Partitioned DML transaction IDs from BeginTransaction options so routeFromRequest(ExecuteSqlRequest) skips attaching routing hints for Partitioned DML queries.
@sakthivelmanii
sakthivelmanii enabled auto-merge (squash) October 28, 2026 18:54
@sakthivelmanii
sakthivelmanii requested a review from a team as a code owner October 28, 2026 18:54
@sakthivelmanii

Copy link
Copy Markdown
Contributor Author

/gemini review

@sakthivelmanii
sakthivelmanii requested a review from a team as a code owner October 28, 2026 18:55

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that routing hints are never attached to Partitioned DML requests in KeyAwareChannel. It introduces a cache to track Partitioned DML transaction IDs and bypasses attaching routing hints for these transactions, routing them to the affinity or default endpoint instead. A unit test has been added to verify this behavior. I have no feedback to provide.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that Partitioned DML transactions do not carry routing hints by introducing a cache to track Partitioned DML transaction IDs in KeyAwareChannel. Requests for these transactions are routed without a routing hint, preventing them from being executed on the fastpath which does not support Partitioned DML. A unit test has been added to verify this behavior. I have no feedback to provide on these changes.

@sakthivelmanii

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that Partitioned DML transactions and operations bypass the KeyAwareChannel routing and affinity mechanisms, executing directly on the default channel. It achieves this by configuring the partitionedDmlStub with a ClientContext using the default transport channel and updating KeyAwareChannel to disable transaction affinity tracking when Partitioned DML options are present. Comprehensive unit and integration tests have been added to verify these changes. I have no additional feedback to provide as the implementation is clean and well-tested.

@sakthivelmanii
sakthivelmanii merged commit d2f0713 into main Nov 2, 2026
203 checks passed
@sakthivelmanii
sakthivelmanii deleted the unflake-test01-runscript branch November 2, 2026 15:28
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