@@ -24,7 +24,6 @@ package cluster
2424
2525import (
2626 "context"
27- "fmt"
2827 "math"
2928 "net/http"
3029 "sort"
@@ -131,12 +130,10 @@ func (c *clusterConnection) Do(ctx context.Context, req driver.Request) (driver.
131130 var specificServer driver.Connection
132131 if v := ctx .Value (keyEndpoint ); v != nil {
133132 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
140137 }
141138 }
142139 }
@@ -332,25 +329,20 @@ func (c *clusterConnection) getCurrentServer() driver.Connection {
332329}
333330
334331// 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 ) {
336333 c .mutex .RLock ()
337334 defer c .mutex .RUnlock ()
338335
339336 for _ , s := range c .servers {
340- endpoints := s .Endpoints ()
341- found := false
342- for _ , x := range endpoints {
337+ for _ , x := range s .Endpoints () {
343338 if x == endpoint {
344- found = true
345- break
339+ return s , true
346340 }
347341 }
348- if found {
349- return s , nil
350- }
351342 }
352343
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
354346}
355347
356348// getNextServer changes the currently used server and returns the new server.
0 commit comments