-
Notifications
You must be signed in to change notification settings - Fork 135
feat(spanner): set manual affinity incase of gRPC-GCP extenstion #3215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -56,8 +56,10 @@ | |||
| import com.google.api.pathtemplate.PathTemplate; | ||||
| import com.google.cloud.RetryHelper; | ||||
| import com.google.cloud.RetryHelper.RetryHelperException; | ||||
| import com.google.cloud.grpc.GcpManagedChannel; | ||||
| import com.google.cloud.grpc.GcpManagedChannelBuilder; | ||||
| import com.google.cloud.grpc.GcpManagedChannelOptions; | ||||
| import com.google.cloud.grpc.GcpManagedChannelOptions.GcpChannelPoolOptions; | ||||
| import com.google.cloud.grpc.GcpManagedChannelOptions.GcpMetricsOptions; | ||||
| import com.google.cloud.grpc.GrpcTransportOptions; | ||||
| import com.google.cloud.spanner.AdminRequestsPerMinuteExceededException; | ||||
|
|
@@ -529,6 +531,10 @@ private static String parseGrpcGcpApiConfig() { | |||
| private static GcpManagedChannelOptions grpcGcpOptionsWithMetrics(SpannerOptions options) { | ||||
| GcpManagedChannelOptions grpcGcpOptions = | ||||
| MoreObjects.firstNonNull(options.getGrpcGcpOptions(), new GcpManagedChannelOptions()); | ||||
| GcpChannelPoolOptions gcpChanelPoolOptions = | ||||
| GcpChannelPoolOptions.newBuilder() | ||||
| .setAffinityKeyLifetime(java.time.Duration.ofMinutes(60L)) | ||||
| .build(); | ||||
| GcpMetricsOptions metricsOptions = | ||||
| MoreObjects.firstNonNull( | ||||
| grpcGcpOptions.getMetricsOptions(), GcpMetricsOptions.newBuilder().build()); | ||||
|
|
@@ -542,6 +548,7 @@ private static GcpManagedChannelOptions grpcGcpOptionsWithMetrics(SpannerOptions | |||
| } | ||||
| return GcpManagedChannelOptions.newBuilder(grpcGcpOptions) | ||||
| .withMetricsOptions(metricsOptionsBuilder.build()) | ||||
| .withChannelPoolOptions(gcpChanelPoolOptions) | ||||
| .build(); | ||||
| } | ||||
|
|
||||
|
|
@@ -1950,7 +1957,17 @@ <ReqT, RespT> GrpcCallContext newCallContext( | |||
| boolean routeToLeader) { | ||||
| GrpcCallContext context = GrpcCallContext.createDefault(); | ||||
| if (options != null) { | ||||
| // Set channel affinity in GAX. This is a no-op for gRPC-GCP. | ||||
| context = context.withChannelAffinity(Option.CHANNEL_HINT.getLong(options).intValue()); | ||||
|
|
||||
| // Set channel affinity in gRPC-GCP. This is a no-op for GAX. | ||||
|
||||
| context = | ||||
| context.withCallOptions( | ||||
| context | ||||
| .getCallOptions() | ||||
| .withOption( | ||||
| GcpManagedChannel.AFFINITY_KEY, | ||||
| Option.CHANNEL_HINT.getLong(options).toString())); | ||||
|
||||
| this.channelHint = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.