Skip to content

chore(spanner): de-duplicate multiplexed session affinity gax options - #9337

Open
olavloite wants to merge 1 commit into
mainfrom
spanner-deduplicate-affinity-options
Open

olavloite wants to merge 1 commit into
mainfrom
spanner-deduplicate-affinity-options

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Snapshot#request and Snapshot#requestStream each contained their own copy of the same logic for adding the multiplexed session affinity key to the gax options of a request. Both now call a single private helper.

The helper assigns the affinity key to the request descriptor instead of copying it first. That descriptor is built by the caller for one specific RPC, and prepareGapicRequest_ already modifies it in place, so the copy served no purpose. It removes one object allocation per request. The caller's own gax options are still never modified.

@olavloite
olavloite requested a review from a team as a code owner September 15, 2026 13:12
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Sep 15, 2026

@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 refactors the Snapshot class in handwritten/spanner/src/transaction.ts by introducing a private helper method, _applyAffinityGaxOpts, to handle binding the multiplexed session affinity key to outgoing request options. It also adds unit tests to ensure that request and requestStream remain usable when detached and that caller-supplied options are not mutated. The review feedback highlights two key improvements: first, to prevent accidental mutation of the shared internal configuration, this._bindGaxOpts should be deep-copied rather than directly assigned; second, the type of config should be changed from {} to any and the unnecessary non-null assertion on callback should be removed to improve type safety.

Comment thread handwritten/spanner/src/transaction.ts
Comment thread handwritten/spanner/src/transaction.ts Outdated
@olavloite
olavloite force-pushed the spanner-deduplicate-affinity-options branch from ccbc15d to a2df4f2 Compare September 15, 2026 13:38
@olavloite

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 refactors the Snapshot class in transaction.ts by extracting the logic for binding the multiplexed session affinity key to gaxOpts into a private helper method _applyAffinityGaxOpts. It also adds corresponding unit tests to verify that detached requests function correctly and that caller-supplied options are not mutated. However, in the refactoring, the callback parameter of this.request was incorrectly changed from optional to required, which could break TypeScript compilation for callers expecting a Promise; this should be reverted to optional.

Comment thread handwritten/spanner/src/transaction.ts
Snapshot#request and Snapshot#requestStream each contained their own
copy of the same logic for adding the multiplexed session affinity key
to the gax options of a request. Both now call a single private helper.

The helper assigns the affinity key to the request descriptor instead of
copying it first. That descriptor is built by the caller for one
specific RPC, and prepareGapicRequest_ already modifies it in place, so
the copy served no purpose. It removes one object allocation per
request. The caller's own gax options are still never modified.
@olavloite
olavloite force-pushed the spanner-deduplicate-affinity-options branch from a2df4f2 to 7bdeff8 Compare September 15, 2026 14:02
@olavloite

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 refactors the Snapshot class in transaction.ts by extracting the multiplexed session affinity key binding logic into a new private helper method _applyAffinityGaxOpts, and adds corresponding unit tests to verify its behavior and ensure request and requestStream remain usable when detached. Feedback was provided regarding the potential side effects of mutating the user-supplied config object directly in _applyAffinityGaxOpts, suggesting the use of a deep copy instead.

Comment thread handwritten/spanner/src/transaction.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant