Skip to content

feat(spanner): make affinity keys configurable via spanner_grpc_confi…#8157

Open
alkatrivedi wants to merge 2 commits intomainfrom
configurable-affinity-keys
Open

feat(spanner): make affinity keys configurable via spanner_grpc_confi…#8157
alkatrivedi wants to merge 2 commits intomainfrom
configurable-affinity-keys

Conversation

@alkatrivedi
Copy link
Copy Markdown
Contributor

No description provided.

@alkatrivedi alkatrivedi requested a review from a team as a code owner May 3, 2026 00:58
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label May 3, 2026
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 multiplexed session affinity for Spanner by generating unique UUID-based affinity keys for transactions and snapshots. It updates the gRPC configuration to support metadata-based affinity and modifies the Snapshot and Transaction classes to inject these keys into request headers, as well as handling the unbinding of keys during commit or rollback operations. Feedback is provided regarding the potential risks of bypassing the grpcGcp.createGcpApiConfig helper, performance inefficiencies caused by repeated linear searches in the configuration, and the need to avoid direct mutation of request configuration objects to prevent side effects.

Comment on lines +426 to +427
// Bypass createGcpApiConfig to preserve our custom metadata fields
'grpc.gcpApiConfig': gcpApiConfig,
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.

high

Bypassing grpcGcp.createGcpApiConfig can lead to issues with the grpc-gcp library, as it typically expects a validated and processed ApiConfig object to correctly initialize channel management and affinity. Since the custom metadata fields added to the config are read directly from the JSON file in transaction.ts, they do not need to be preserved within the grpc.gcpApiConfig channel option. Bypassing this helper may inadvertently break standard affinity behavior (e.g., for regular sessions) if the library fails to parse the raw object.

Suggested change
// Bypass createGcpApiConfig to preserve our custom metadata fields
'grpc.gcpApiConfig': gcpApiConfig,
'grpc.gcpApiConfig': grpcGcp.createGcpApiConfig(gcpApiConfig),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

grpcGcp.createGcpApiConfig(gcpApiConfig) will drop our custom configuration fields (like unbindMetadataKey or affinityKeyLocation). This is because createGcpApiConfig converts the raw JSON object into a strictly typed Protobuf message instance based on the grpc_gcp.proto schema. Any fields present in the JSON that are not explicitly defined in the proto file will be filtered out and ignored." Hence, this bypassing is required

Comment thread handwritten/spanner/src/transaction.ts Outdated
Comment thread handwritten/spanner/src/transaction.ts
Comment thread handwritten/spanner/src/transaction.ts
Comment thread handwritten/spanner/src/transaction.ts Outdated
@alkatrivedi alkatrivedi force-pushed the configurable-affinity-keys branch from 62ad6bb to 77436fe Compare May 3, 2026 01:55
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