Skip to content

Commit 2a189ad

Browse files
authored
[Bugfix] Coordinator Cursor internal routing (#272)
1 parent e3d8ec1 commit 2a189ad

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/go-driver/tree/master) (N/A)
4+
- Use internal coordinator communication for cursors if specified coordinator was not found on endpoint list
45

56
## [1.0.0](https://github.com/arangodb/go-driver/tree/1.0.0) (N/A)
67
- Enable proper CHANGELOG and versioning

cluster/cluster.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ package cluster
2424

2525
import (
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

Comments
 (0)