feat(spanner): make affinity keys configurable via spanner_grpc_confi…#8157
feat(spanner): make affinity keys configurable via spanner_grpc_confi…#8157alkatrivedi wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
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.
| // Bypass createGcpApiConfig to preserve our custom metadata fields | ||
| 'grpc.gcpApiConfig': gcpApiConfig, |
There was a problem hiding this comment.
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.
| // Bypass createGcpApiConfig to preserve our custom metadata fields | |
| 'grpc.gcpApiConfig': gcpApiConfig, | |
| 'grpc.gcpApiConfig': grpcGcp.createGcpApiConfig(gcpApiConfig), |
There was a problem hiding this comment.
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
62ad6bb to
77436fe
Compare
No description provided.