@@ -24,7 +24,6 @@ package cluster
24
24
25
25
import (
26
26
"context"
27
- "fmt"
28
27
"math"
29
28
"net/http"
30
29
"sort"
@@ -131,12 +130,10 @@ func (c *clusterConnection) Do(ctx context.Context, req driver.Request) (driver.
131
130
var specificServer driver.Connection
132
131
if v := ctx .Value (keyEndpoint ); v != nil {
133
132
if endpoint , ok := v .(string ); ok {
134
- // Specific endpoint specified
135
- serverCount = 1
136
- var err error
137
- specificServer , err = c .getSpecificServer (endpoint )
138
- if err != nil {
139
- return nil , driver .WithStack (err )
133
+ // Override pool to only specific server if it is found
134
+ if s , ok := c .getSpecificServer (endpoint ); ok {
135
+ serverCount = 1
136
+ specificServer = s
140
137
}
141
138
}
142
139
}
@@ -332,25 +329,20 @@ func (c *clusterConnection) getCurrentServer() driver.Connection {
332
329
}
333
330
334
331
// getSpecificServer returns the server with the given endpoint.
335
- func (c * clusterConnection ) getSpecificServer (endpoint string ) (driver.Connection , error ) {
332
+ func (c * clusterConnection ) getSpecificServer (endpoint string ) (driver.Connection , bool ) {
336
333
c .mutex .RLock ()
337
334
defer c .mutex .RUnlock ()
338
335
339
336
for _ , s := range c .servers {
340
- endpoints := s .Endpoints ()
341
- found := false
342
- for _ , x := range endpoints {
337
+ for _ , x := range s .Endpoints () {
343
338
if x == endpoint {
344
- found = true
345
- break
339
+ return s , true
346
340
}
347
341
}
348
- if found {
349
- return s , nil
350
- }
351
342
}
352
343
353
- return nil , driver .WithStack (driver.InvalidArgumentError {Message : fmt .Sprintf ("unknown endpoint: %s" , endpoint )})
344
+ // If endpoint is not found allow to use default connection pool - request will be routed thru coordinators
345
+ return nil , false
354
346
}
355
347
356
348
// getNextServer changes the currently used server and returns the new server.
0 commit comments