Adds some locality stuff

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2020-01-24 13:34:59 +01:00
parent eaa7f0d6eb
commit 2d14fa270b
6 changed files with 86 additions and 25 deletions

View File

@@ -71,7 +71,7 @@ func (a *assignment) clusters() []string {
}
// Select selects a endpoint from cluster load assignments, using weighted random selection. It only selects endpoints that are reporting healthy.
func (a *assignment) Select(cluster string, ignore bool) (*SocketAddress, bool) {
func (a *assignment) Select(cluster string, locality []Locality, ignore bool) (*SocketAddress, bool) {
cla := a.ClusterLoadAssignment(cluster)
if cla == nil {
return nil, false
@@ -126,7 +126,7 @@ func (a *assignment) Select(cluster string, ignore bool) (*SocketAddress, bool)
}
// All returns all healthy endpoints.
func (a *assignment) All(cluster string, ignore bool) ([]*SocketAddress, bool) {
func (a *assignment) All(cluster string, locality []Locality, ignore bool) ([]*SocketAddress, bool) {
cla := a.ClusterLoadAssignment(cluster)
if cla == nil {
return nil, false

View File

@@ -227,17 +227,24 @@ func (c *Client) receive(stream adsStream) error {
// Select returns an address that is deemed to be the correct one for this cluster. The returned
// boolean indicates if the cluster exists.
func (c *Client) Select(cluster string, ignore bool) (*SocketAddress, bool) {
func (c *Client) Select(cluster string, locality []Locality, ignore bool) (*SocketAddress, bool) {
if cluster == "" {
return nil, false
}
return c.assignments.Select(cluster, ignore)
return c.assignments.Select(cluster, locality, ignore)
}
// All returns all endpoints.
func (c *Client) All(cluster string, ignore bool) ([]*SocketAddress, bool) {
func (c *Client) All(cluster string, locality []Locality, ignore bool) ([]*SocketAddress, bool) {
if cluster == "" {
return nil, false
}
return c.assignments.All(cluster, ignore)
return c.assignments.All(cluster, locality, ignore)
}
// Locality holds the locality for this server. It contains a Region, Zone and SubZone.
type Locality struct {
Region string
Zone string
SubZone string
}