-
Notifications
You must be signed in to change notification settings - Fork 22
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
Multiendpoint #63
Multiendpoint #63
Conversation
grpcgcp/gcp_multiendpoint.go
Outdated
var meKey contextMEKey | ||
|
||
// NewMEContext returns a new Context that carries Multiendpoint name meName. | ||
func NewMEContext(ctx context.Context, meName string) context.Context { |
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.
I think the function argument can just be called name. Since the package is called multiendpoint I don't think you need to preface all the variables with me.
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.
Yeah, I was worried that the name can be confused with an endpoint (although endpoints don't have a name and we never refer to an endpoint address and port as a name). Will change the name and doc comment.
} | ||
|
||
// SetEndpointAvailable updates the state of an endpoint. | ||
func (me *multiEndpoint) SetEndpointAvailable(e string, avail bool) { |
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.
Maybe we can change the name to SetEndpointAvailability since you are taking in a boolean.
The purposes of GcpMultiEndpoint are:
endpoint is completely unavailable.
A group of endpoints is called a [multiendpoint.MultiEndpoint] and is essentially a list of endpoints where priority is defined by the position in the list with the first endpoint having top priority. A MultiEndpoint tracks endpoints' availability. When a MultiEndpoint is picked for an RPC call, it picks the top priority endpoint that is currently available. More information on the [multiendpoint.MultiEndpoint].
GCPMultiEndpoint can have one or more MultiEndpoint identified by its name -- arbitrary string provided in the [GCPMultiEndpointOptions] when configuring MultiEndpoints. This name can be used to route an RPC call to this MultiEndpoint by using the [NewMEContext].
GCPMultiEndpoint uses [GCPMultiEndpointOptions] for initial configuration. An updated configuration can be provided at any time later using [UpdateMultiEndpoints].
Example:
Let's assume we have a service with read and write operations and the following backends:
Example configuration:
MultiEndpoint named "default" with endpoints:
service.example.com:443
service-fallback.example.com:443
MultiEndpoint named "read" with endpoints:
ro-service.example.com:443
service-fallback.example.com:443
service.example.com:443
With the configuration above GCPMultiEndpoint will use the "default" MultiEndpoint by default. It means that RPC calls by default will use the main endpoint and if it is not available then the read-write replica.
To offload some read calls to the read-only replica we can specify "read" MultiEndpoint in the context. Then these calls will use the read-only replica endpoint and if it is not available then the read-write replica and if it is also not available then the main endpoint.
GCPMultiEndpoint creates a [grpcgcp] connection pool for every unique endpoint. For the example above three connection pools will be created.
[GCPMultiEndpoint] implements [grpc.ClientConnInterface] and can be used as a [grpc.ClientConn] when creating gRPC clients.