Skip to content

feat(spanner): independent-affinity-keys#8153

Draft
alkatrivedi wants to merge 1 commit intomainfrom
independent-affinity-keys
Draft

feat(spanner): independent-affinity-keys#8153
alkatrivedi wants to merge 1 commit intomainfrom
independent-affinity-keys

Conversation

@alkatrivedi
Copy link
Copy Markdown
Contributor

@alkatrivedi alkatrivedi commented May 1, 2026

do not review[experimental PR]

@alkatrivedi alkatrivedi requested a review from a team as a code owner May 1, 2026 23:20
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label May 1, 2026
@alkatrivedi alkatrivedi marked this pull request as draft May 1, 2026 23:20
Copy link
Copy Markdown
Contributor

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

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 implements affinity key support for multiplexed sessions in the Spanner client. It introduces logic to generate and attach a UUID as an affinity key to snapshots and transactions, which is then included in gRPC request headers (x-grpc-gcp-affinity-key). The changes also include unbinding logic during commit and rollback operations. Review feedback suggests using 'import type' to maintain type safety for the Spanner class without circular dependencies and recommends avoiding direct mutation of configuration objects to prevent unintended side effects during request execution.

Comment on lines +370 to +384
this.request = (config: any, callback: Function) => {
if (this._affinityKey) {
config.headers = config.headers || {};
config.headers['x-grpc-gcp-affinity-key'] = this._affinityKey;
}
return session.request(config, callback);
};

this.requestStream = (config: any) => {
if (this._affinityKey) {
config.headers = config.headers || {};
config.headers['x-grpc-gcp-affinity-key'] = this._affinityKey;
}
return session.requestStream(config);
};
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.

medium

The current implementation mutates the config object by directly modifying its headers property. This can lead to unexpected side effects if the caller reuses the configuration object for multiple requests. It is safer to create a shallow copy of the configuration and its headers to ensure immutability of the input.

    this.request = (config: any, callback: Function) => {
      const requestConfig = this._affinityKey
        ? Object.assign({}, config, {
            headers: Object.assign({}, config.headers, {
              'x-grpc-gcp-affinity-key': this._affinityKey,
            }),
          })
        : config;
      return session.request(requestConfig, callback);
    };

    this.requestStream = (config: any) => {
      const requestConfig = this._affinityKey
        ? Object.assign({}, config, {
            headers: Object.assign({}, config.headers, {
              'x-grpc-gcp-affinity-key': this._affinityKey,
            }),
          })
        : config;
      return session.requestStream(requestConfig);
    };

@alkatrivedi alkatrivedi force-pushed the independent-affinity-keys branch 2 times, most recently from 200d880 to 48edbb9 Compare May 2, 2026 00:21
@googleapis googleapis deleted a comment from gemini-code-assist Bot May 2, 2026
@googleapis googleapis deleted a comment from gemini-code-assist Bot May 2, 2026
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels May 2, 2026
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label May 2, 2026
@alkatrivedi alkatrivedi force-pushed the independent-affinity-keys branch from 48edbb9 to 5cab403 Compare May 2, 2026 04:08
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 2, 2026
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.

2 participants