Skip to content

Commit fb851e3

Browse files
authored
Merge pull request #312 from arangodb/go-driver-update
Updated Go-Driver to latest version.
2 parents ec72b87 + c4623b5 commit fb851e3

40 files changed

+1867
-193
lines changed

dashboard/assets.go

+59-59
Large diffs are not rendered by default.

deps/github.com/arangodb/go-driver/.envrc

-8
This file was deleted.

deps/github.com/arangodb/go-driver/.gitignore

-1
This file was deleted.

deps/github.com/arangodb/go-driver/.travis.yml

-14
This file was deleted.

deps/github.com/arangodb/go-driver/.vscode/settings.json

-37
This file was deleted.

deps/github.com/arangodb/go-driver/client.go

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ type Client interface {
4040
// This function requires ArangoDB 3.1.15 or up.
4141
SynchronizeEndpoints(ctx context.Context) error
4242

43+
// SynchronizeEndpoints2 fetches all endpoints from an ArangoDB cluster and updates the
44+
// connection to use those endpoints.
45+
// When this client is connected to a single server, nothing happens.
46+
// When this client is connected to a cluster of servers, the connection will be updated to reflect
47+
// the layout of the cluster.
48+
// Compared to SynchronizeEndpoints, this function expects a database name as additional parameter.
49+
// This database name is used to call `_db/<dbname>/_api/cluster/endpoints`. SynchronizeEndpoints uses
50+
// the default database, i.e. `_system`. In the case the user does not have access to `_system`,
51+
// SynchronizeEndpoints does not work with earlier versions of arangodb.
52+
SynchronizeEndpoints2(ctx context.Context, dbname string) error
53+
4354
// Connection returns the connection used by this client
4455
Connection() Connection
4556

deps/github.com/arangodb/go-driver/client_impl.go

+28-12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package driver
2424

2525
import (
2626
"context"
27+
"path"
2728
"time"
2829

2930
"github.com/arangodb/go-driver/util"
@@ -67,19 +68,28 @@ func (c *client) Connection() Connection {
6768
// When this client is connected to a cluster of servers, the connection will be updated to reflect
6869
// the layout of the cluster.
6970
func (c *client) SynchronizeEndpoints(ctx context.Context) error {
70-
role, err := c.ServerRole(ctx)
71-
if err != nil {
72-
return WithStack(err)
73-
}
74-
if role == ServerRoleSingle {
75-
// Standalone server, do nothing
76-
return nil
77-
}
71+
return c.SynchronizeEndpoints2(ctx, "")
72+
}
7873

74+
// SynchronizeEndpoints2 fetches all endpoints from an ArangoDB cluster and updates the
75+
// connection to use those endpoints.
76+
// When this client is connected to a single server, nothing happens.
77+
// When this client is connected to a cluster of servers, the connection will be updated to reflect
78+
// the layout of the cluster.
79+
// Compared to SynchronizeEndpoints, this function expects a database name as additional parameter.
80+
// This database name is used to call `_db/<dbname>/_api/cluster/endpoints`. SynchronizeEndpoints uses
81+
// the default database, i.e. `_system`. In the case the user does not have access to `_system`,
82+
// SynchronizeEndpoints does not work with earlier versions of arangodb.
83+
func (c *client) SynchronizeEndpoints2(ctx context.Context, dbname string) error {
7984
// Cluster mode, fetch endpoints
80-
cep, err := c.clusterEndpoints(ctx)
85+
cep, err := c.clusterEndpoints(ctx, dbname)
8186
if err != nil {
82-
return WithStack(err)
87+
// ignore Forbidden: automatic failover is not enabled errors
88+
if !IsArangoErrorWithErrorNum(err, 403, 0, 11) { // 3.2 returns no error code, thus check for 0
89+
return WithStack(err)
90+
}
91+
92+
return nil
8393
}
8494
var endpoints []string
8595
for _, ep := range cep.Endpoints {
@@ -114,8 +124,14 @@ type clusterEndpoint struct {
114124
}
115125

116126
// clusterEndpoints returns the endpoints of a cluster.
117-
func (c *client) clusterEndpoints(ctx context.Context) (clusterEndpointsResponse, error) {
118-
req, err := c.conn.NewRequest("GET", "_api/cluster/endpoints")
127+
func (c *client) clusterEndpoints(ctx context.Context, dbname string) (clusterEndpointsResponse, error) {
128+
var url string
129+
if dbname == "" {
130+
url = "_api/cluster/endpoints"
131+
} else {
132+
url = path.Join("_db", pathEscape(dbname), "_api/cluster/endpoints")
133+
}
134+
req, err := c.conn.NewRequest("GET", url)
119135
if err != nil {
120136
return clusterEndpointsResponse{}, WithStack(err)
121137
}

deps/github.com/arangodb/go-driver/cluster.go

+28
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ type ServerHealth struct {
7575
Status ServerStatus `json:"Status"`
7676
CanBeDeleted bool `json:"CanBeDeleted"`
7777
HostID string `json:"Host,omitempty"`
78+
Version Version `json:"Version,omitempty"`
79+
Engine EngineType `json:"Engine,omitempty"`
7880
}
7981

8082
// ServerStatus describes the health status of a server
@@ -93,6 +95,8 @@ const (
9395
type DatabaseInventory struct {
9496
// Details of all collections
9597
Collections []InventoryCollection `json:"collections,omitempty"`
98+
// Details of all views
99+
Views []InventoryView `json:"views,omitempty"`
96100
}
97101

98102
// IsReady returns true if the IsReady flag of all collections is set.
@@ -124,6 +128,17 @@ func (i DatabaseInventory) CollectionByName(name string) (InventoryCollection, b
124128
return InventoryCollection{}, false
125129
}
126130

131+
// ViewByName returns the InventoryView with given name.
132+
// Return false if not found.
133+
func (i DatabaseInventory) ViewByName(name string) (InventoryView, bool) {
134+
for _, v := range i.Views {
135+
if v.Name == name {
136+
return v, true
137+
}
138+
}
139+
return InventoryView{}, false
140+
}
141+
127142
// InventoryCollection is a single element of a DatabaseInventory, containing all information
128143
// of a specific collection.
129144
type InventoryCollection struct {
@@ -196,6 +211,19 @@ func (i InventoryIndex) FieldsEqual(fields []string) bool {
196211
return stringSliceEqualsIgnoreOrder(i.Fields, fields)
197212
}
198213

214+
// InventoryView is a single element of a DatabaseInventory, containing all information
215+
// of a specific view.
216+
type InventoryView struct {
217+
Name string `json:"name,omitempty"`
218+
Deleted bool `json:"deleted,omitempty"`
219+
ID string `json:"id,omitempty"`
220+
IsSystem bool `json:"isSystem,omitempty"`
221+
PlanID string `json:"planId,omitempty"`
222+
Type ViewType `json:"type,omitempty"`
223+
// Include all properties from an arangosearch view.
224+
ArangoSearchViewProperties
225+
}
226+
199227
// stringSliceEqualsIgnoreOrder returns true when the given lists contain the same elements.
200228
// The order of elements is irrelevant.
201229
func stringSliceEqualsIgnoreOrder(a, b []string) bool {

deps/github.com/arangodb/go-driver/collection_document_impl.go

+7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ func (c *collection) ReadDocument(ctx context.Context, key string, result interf
5959
if err != nil {
6060
return DocumentMeta{}, WithStack(err)
6161
}
62+
// This line introduces a lot of side effects. In particular If-Match headers are now set (which is a bugfix)
63+
// and invalid query parameters like waitForSync (which is potentially breaking change)
64+
cs := applyContextSettings(ctx, req)
6265
resp, err := c.conn.Do(ctx, req)
6366
if err != nil {
6467
return DocumentMeta{}, WithStack(err)
@@ -71,6 +74,8 @@ func (c *collection) ReadDocument(ctx context.Context, key string, result interf
7174
if err := resp.ParseBody("", &meta); err != nil {
7275
return DocumentMeta{}, WithStack(err)
7376
}
77+
// load context response values
78+
loadContextResponseValues(cs, resp)
7479
// Parse result
7580
if result != nil {
7681
if err := resp.ParseBody("", result); err != nil {
@@ -120,6 +125,8 @@ func (c *collection) ReadDocuments(ctx context.Context, keys []string, results i
120125
if err := resp.CheckStatus(200); err != nil {
121126
return nil, nil, WithStack(err)
122127
}
128+
// load context response values
129+
loadContextResponseValues(cs, resp)
123130
// Parse response array
124131
metas, errs, err := parseResponseArray(resp, resultCount, cs, results)
125132
if err != nil {

deps/github.com/arangodb/go-driver/collection_indexes_impl.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ type indexData struct {
3838
MinLength int `json:"minLength,omitempty"`
3939
}
4040

41+
type genericIndexData struct {
42+
ID string `json:"id,omitempty"`
43+
Type string `json:"type"`
44+
}
45+
4146
type indexListResponse struct {
42-
Indexes []indexData `json:"indexes,omitempty"`
47+
Indexes []genericIndexData `json:"indexes,omitempty"`
4348
}
4449

4550
// Index opens a connection to an existing index within the collection.
@@ -60,7 +65,7 @@ func (c *collection) Index(ctx context.Context, name string) (Index, error) {
6065
if err := resp.ParseBody("", &data); err != nil {
6166
return nil, WithStack(err)
6267
}
63-
idx, err := newIndex(data.ID, c)
68+
idx, err := newIndex(data.ID, data.Type, c)
6469
if err != nil {
6570
return nil, WithStack(err)
6671
}
@@ -106,7 +111,7 @@ func (c *collection) Indexes(ctx context.Context) ([]Index, error) {
106111
}
107112
result := make([]Index, 0, len(data.Indexes))
108113
for _, x := range data.Indexes {
109-
idx, err := newIndex(x.ID, c)
114+
idx, err := newIndex(x.ID, x.Type, c)
110115
if err != nil {
111116
return nil, WithStack(err)
112117
}
@@ -121,7 +126,7 @@ func (c *collection) Indexes(ctx context.Context) ([]Index, error) {
121126
// The index is returned, together with a boolean indicating if the index was newly created (true) or pre-existing (false).
122127
func (c *collection) EnsureFullTextIndex(ctx context.Context, fields []string, options *EnsureFullTextIndexOptions) (Index, bool, error) {
123128
input := indexData{
124-
Type: "fulltext",
129+
Type: string(FullTextIndex),
125130
Fields: fields,
126131
}
127132
if options != nil {
@@ -146,7 +151,7 @@ func (c *collection) EnsureFullTextIndex(ctx context.Context, fields []string, o
146151
// The index is returned, together with a boolean indicating if the index was newly created (true) or pre-existing (false).
147152
func (c *collection) EnsureGeoIndex(ctx context.Context, fields []string, options *EnsureGeoIndexOptions) (Index, bool, error) {
148153
input := indexData{
149-
Type: "geo",
154+
Type: string(GeoIndex),
150155
Fields: fields,
151156
}
152157
if options != nil {
@@ -164,7 +169,7 @@ func (c *collection) EnsureGeoIndex(ctx context.Context, fields []string, option
164169
// The index is returned, together with a boolean indicating if the index was newly created (true) or pre-existing (false).
165170
func (c *collection) EnsureHashIndex(ctx context.Context, fields []string, options *EnsureHashIndexOptions) (Index, bool, error) {
166171
input := indexData{
167-
Type: "hash",
172+
Type: string(HashIndex),
168173
Fields: fields,
169174
}
170175
off := false
@@ -187,7 +192,7 @@ func (c *collection) EnsureHashIndex(ctx context.Context, fields []string, optio
187192
// The index is returned, together with a boolean indicating if the index was newly created (true) or pre-existing (false).
188193
func (c *collection) EnsurePersistentIndex(ctx context.Context, fields []string, options *EnsurePersistentIndexOptions) (Index, bool, error) {
189194
input := indexData{
190-
Type: "persistent",
195+
Type: string(PersistentIndex),
191196
Fields: fields,
192197
}
193198
if options != nil {
@@ -206,7 +211,7 @@ func (c *collection) EnsurePersistentIndex(ctx context.Context, fields []string,
206211
// The index is returned, together with a boolean indicating if the index was newly created (true) or pre-existing (false).
207212
func (c *collection) EnsureSkipListIndex(ctx context.Context, fields []string, options *EnsureSkipListIndexOptions) (Index, bool, error) {
208213
input := indexData{
209-
Type: "skiplist",
214+
Type: string(SkipListIndex),
210215
Fields: fields,
211216
}
212217
off := false
@@ -248,7 +253,7 @@ func (c *collection) ensureIndex(ctx context.Context, options indexData) (Index,
248253
if err := resp.ParseBody("", &data); err != nil {
249254
return nil, false, WithStack(err)
250255
}
251-
idx, err := newIndex(data.ID, c)
256+
idx, err := newIndex(data.ID, data.Type, c)
252257
if err != nil {
253258
return nil, false, WithStack(err)
254259
}

deps/github.com/arangodb/go-driver/connection.go

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ type Request interface {
7979
Written() bool
8080
// Clone creates a new request containing the same data as this request
8181
Clone() Request
82+
// Path returns the Request path
83+
Path() string
84+
// Method returns the Request method
85+
Method() string
8286
}
8387

8488
// Response represents the response from the server on a given request.

0 commit comments

Comments
 (0)