@@ -96,15 +96,12 @@ func (cs *ClientSet) HealthyClientsCount() int {
96
96
97
97
}
98
98
99
- func (cs * ClientSet ) hasIDLocked (serverID string ) bool {
100
- _ , ok := cs .clients [serverID ]
101
- return ok
102
- }
103
-
99
+ // HasID returns true if the ClientSet has a client to the specified serverID.
104
100
func (cs * ClientSet ) HasID (serverID string ) bool {
105
101
cs .mu .Lock ()
106
102
defer cs .mu .Unlock ()
107
- return cs .hasIDLocked (serverID )
103
+ _ , exists := cs .clients [serverID ]
104
+ return exists
108
105
}
109
106
110
107
type DuplicateServerError struct {
@@ -115,20 +112,19 @@ func (dse *DuplicateServerError) Error() string {
115
112
return "duplicate server: " + dse .ServerID
116
113
}
117
114
118
- func (cs * ClientSet ) addClientLocked (serverID string , c * Client ) error {
119
- if cs .hasIDLocked (serverID ) {
115
+ // AddClient adds the specified client to our set of clients.
116
+ // If we already have a connection with the same serverID, we will return *DuplicateServerError.
117
+ func (cs * ClientSet ) AddClient (serverID string , c * Client ) error {
118
+ cs .mu .Lock ()
119
+ defer cs .mu .Unlock ()
120
+
121
+ _ , exists := cs .clients [serverID ]
122
+ if exists {
120
123
return & DuplicateServerError {ServerID : serverID }
121
124
}
122
125
cs .clients [serverID ] = c
123
126
metrics .Metrics .SetServerConnectionsCount (len (cs .clients ))
124
127
return nil
125
-
126
- }
127
-
128
- func (cs * ClientSet ) AddClient (serverID string , c * Client ) error {
129
- cs .mu .Lock ()
130
- defer cs .mu .Unlock ()
131
- return cs .addClientLocked (serverID , c )
132
128
}
133
129
134
130
func (cs * ClientSet ) RemoveClient (serverID string ) {
0 commit comments