forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
naming.go
76 lines (66 loc) · 1.88 KB
/
naming.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package topo
/*
Handle logical name resolution - sort of like DNS but tailored to
vt and using the topology server.
Naming is disconnected from the backend discovery and is used for
front end clients.
The common query is "resolve keyspace.shard.db_type" and return a list
of host:port tuples that export our default server (vttablet). You can
get all shards with "keyspace.*.db_type".
In zk, this is in /zk/local/vt/ns/<keyspace>/<shard>/<db type>
*/
import topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
const (
// DefaultPortName is the port named used by SrvEntries
// if "" is given as the named port.
DefaultPortName = "vt"
)
// NewEndPoint returns a new empty EndPoint
func NewEndPoint(uid uint32, host string) *topodatapb.EndPoint {
return &topodatapb.EndPoint{
Uid: uid,
Host: host,
PortMap: make(map[string]int32),
}
}
// EndPointEquality returns true iff two EndPoint are representing the same data
func EndPointEquality(left, right *topodatapb.EndPoint) bool {
if left.Uid != right.Uid {
return false
}
if left.Host != right.Host {
return false
}
if len(left.PortMap) != len(right.PortMap) {
return false
}
for key, lvalue := range left.PortMap {
rvalue, ok := right.PortMap[key]
if !ok {
return false
}
if lvalue != rvalue {
return false
}
}
if len(left.HealthMap) != len(right.HealthMap) {
return false
}
for key, lvalue := range left.HealthMap {
rvalue, ok := right.HealthMap[key]
if !ok {
return false
}
if lvalue != rvalue {
return false
}
}
return true
}
// NewEndPoints creates a EndPoints with a pre-allocated slice for Entries.
func NewEndPoints() *topodatapb.EndPoints {
return &topodatapb.EndPoints{Entries: make([]*topodatapb.EndPoint, 0, 8)}
}