Skip to content

Commit 9993f28

Browse files
author
enikon
authored
OAS-10816 set properties does not allow removing a computed value in go driver (#678)
Github Issue: #669
1 parent 257739b commit 9993f28

31 files changed

+633
-135
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ parameters:
2222
default: "gcr.io/gcr-for-testing/golang:1.22.12"
2323
arangodbImage:
2424
type: string
25-
default: "gcr.io/gcr-for-testing/arangodb/enterprise-preview:devel-nightly"
25+
default: "gcr.io/gcr-for-testing/arangodb/enterprise-preview:latest"
2626
alpineImage:
2727
type: string
2828
default: "gcr.io/gcr-for-testing/alpine:3.21"

Dockerfile.debug

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
ARG GOVERSION
22
FROM golang:${GOVERSION} as builder
33

4+
ARG GOTOOLCHAIN=local
5+
ENV GOTOOLCHAIN=${GOTOOLCHAIN}
46
ARG TESTS_DIRECTORY
57
ARG TESTS_ROOT_PATH="."
68

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ GOVERSION ?= 1.22.12
88
GOTOOLCHAIN ?= auto
99
GOIMAGE ?= golang:$(GOVERSION)
1010
GOV2IMAGE ?= $(GOIMAGE)
11-
ALPINE_IMAGE ?= alpine:3.17
11+
ALPINE_IMAGE ?= alpine:3.21
1212
TMPDIR := ${SCRIPTDIR}/.tmp
1313

1414
DOCKER_CMD:=docker run
@@ -139,10 +139,10 @@ endif
139139

140140
ifeq ("$(DEBUG)", "true")
141141
GOIMAGE := go-driver-tests:debug
142-
DOCKER_DEBUG_ARGS := --security-opt=seccomp:unconfined
142+
DOCKER_DEBUG_ARGS := --security-opt=seccomp:unconfined -e GOTOOLCHAIN=$(GOTOOLCHAIN)
143143
DEBUG_PORT := 2345
144144

145-
DOCKER_RUN_CMD := $(DOCKER_DEBUG_ARGS) $(GOIMAGE) /go/bin/dlv --listen=:$(DEBUG_PORT) --headless=true --api-version=2 exec /test_debug.test -- $(TESTOPTIONS)
145+
DOCKER_RUN_CMD := $(DOCKER_DEBUG_ARGS) $(GOIMAGE) /go/bin/dlv --listen=:$(DEBUG_PORT) --headless=true --api-version=2 --accept-multiclient exec /test_debug.test -- $(TESTOPTIONS)
146146
DOCKER_V2_RUN_CMD := $(DOCKER_RUN_CMD)
147147
else
148148
DOCKER_RUN_CMD := $(GOIMAGE) go test -timeout 120m $(GOBUILDTAGSOPT) $(TESTOPTIONS) $(TESTVERBOSEOPTIONS) $(TESTS)
@@ -461,12 +461,12 @@ __test_v2_go_test:
461461

462462
__test_debug__:
463463
ifeq ("$(DEBUG)", "true")
464-
@docker build -f Dockerfile.debug --build-arg GOVERSION=$(GOVERSION) --build-arg "TESTS_DIRECTORY=./test" -t $(GOIMAGE) .
464+
@docker build -f Dockerfile.debug --build-arg GOVERSION=$(GOVERSION) --build-arg GOTOOLCHAIN=$(GOTOOLCHAIN) --build-arg "TESTS_DIRECTORY=./test" -t $(GOIMAGE) .
465465
endif
466466

467467
__test_v2_debug__:
468468
ifeq ("$(DEBUG)", "true")
469-
@docker build -f Dockerfile.debug --build-arg GOVERSION=$(GOVERSION) --build-arg "TESTS_DIRECTORY=./tests" --build-arg "TESTS_ROOT_PATH=v2" -t $(GOIMAGE) .
469+
@docker build -f Dockerfile.debug --build-arg GOVERSION=$(GOVERSION) --build-arg GOTOOLCHAIN=$(GOTOOLCHAIN) --build-arg "TESTS_DIRECTORY=./tests" --build-arg "TESTS_ROOT_PATH=v2" -t $(GOIMAGE) .
470470
endif
471471

472472
__dir_setup:

v2/arangodb/collection.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ type Collection interface {
4545
// Properties fetches extended information about the collection.
4646
Properties(ctx context.Context) (CollectionProperties, error)
4747

48+
// Deprecated: use 'SetPropertiesV2' instead
49+
//
4850
// SetProperties allows modifying collection parameters
4951
SetProperties(ctx context.Context, options SetCollectionPropertiesOptions) error
5052

53+
// SetProperties allows modifying collection parameters
54+
SetPropertiesV2(ctx context.Context, options SetCollectionPropertiesOptionsV2) error
55+
5156
// Count fetches the number of document in the collection.
5257
Count(ctx context.Context) (int64, error)
5358

v2/arangodb/collection_impl.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@ func (c collection) SetProperties(ctx context.Context, options SetCollectionProp
159159
}
160160
}
161161

162+
func (c collection) SetPropertiesV2(ctx context.Context, options SetCollectionPropertiesOptionsV2) error {
163+
urlEndpoint := c.url("collection", "properties")
164+
165+
var response struct {
166+
shared.ResponseStruct `json:",inline"`
167+
}
168+
169+
resp, err := connection.CallPut(ctx, c.connection(), urlEndpoint, &response, options, c.withModifiers()...)
170+
if err != nil {
171+
return errors.WithStack(err)
172+
}
173+
174+
switch code := resp.Code(); code {
175+
case http.StatusOK:
176+
return nil
177+
default:
178+
return response.AsArangoErrorWithCode(code)
179+
}
180+
}
181+
162182
func (c collection) Name() string {
163183
return c.name
164184
}

v2/arangodb/collection_opts.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ func (p *CollectionProperties) IsSatellite() bool {
184184
return p.ReplicationFactor == ReplicationFactorSatellite
185185
}
186186

187+
// Deprecated: use 'SetCollectionPropertiesOptionsV2' instead
188+
//
187189
// SetCollectionPropertiesOptions contains data for Collection.SetProperties.
188190
type SetCollectionPropertiesOptions struct {
189191
// If true then creating or changing a document will wait until the data has been synchronized to disk.
@@ -213,6 +215,34 @@ type SetCollectionPropertiesOptions struct {
213215
ComputedValues []ComputedValue `json:"computedValues,omitempty"`
214216
}
215217

218+
type SetCollectionPropertiesOptionsV2 struct {
219+
// If true then creating or changing a document will wait until the data has been synchronized to disk.
220+
WaitForSync *bool `json:"waitForSync,omitempty"`
221+
222+
// The maximal size of a journal or datafile in bytes. The value must be at least 1048576 (1 MB). Note that when changing the journalSize value, it will only have an effect for additional journals or datafiles that are created. Already existing journals or datafiles will not be affected.
223+
JournalSize *int64 `json:"journalSize,omitempty"`
224+
225+
// ReplicationFactor contains how many copies of each shard are kept on different DBServers.
226+
// Only available in cluster setup.
227+
ReplicationFactor *ReplicationFactor `json:"replicationFactor,omitempty"`
228+
229+
// Deprecated: use 'WriteConcern' instead
230+
MinReplicationFactor *int `json:"minReplicationFactor,omitempty"`
231+
232+
// WriteConcern contains how many copies must be available before a collection can be written.
233+
// Available from 3.6 arangod version.
234+
WriteConcern *int `json:"writeConcern,omitempty"`
235+
236+
// CacheEnabled set cacheEnabled option in collection properties
237+
CacheEnabled *bool `json:"cacheEnabled,omitempty"`
238+
239+
// Schema for collection validation
240+
Schema *CollectionSchemaOptions `json:"schema,omitempty"`
241+
242+
// ComputedValues let configure collections to generate document attributes when documents are created or modified, using an AQL expression
243+
ComputedValues *[]ComputedValue `json:"computedValues,omitempty"`
244+
}
245+
216246
type ComputedValue struct {
217247
// The name of the target attribute. Can only be a top-level attribute, but you
218248
// may return a nested object. Cannot be `_key`, `_id`, `_rev`, `_from`, `_to`,

v2/arangodb/database_collection.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,25 @@ type DatabaseCollection interface {
4141
// Collections returns a list of all collections in the database.
4242
Collections(ctx context.Context) ([]Collection, error)
4343

44+
// Deprecated: use CreateCollectionV2 instead
45+
//
4446
// CreateCollection creates a new collection with given name and options, and opens a connection to it.
4547
// If a collection with given name already exists within the database, a DuplicateError is returned.
4648
CreateCollection(ctx context.Context, name string, props *CreateCollectionProperties) (Collection, error)
4749

50+
// CreateCollection creates a new collection with given name and options, and opens a connection to it.
51+
// If a collection with given name already exists within the database, a DuplicateError is returned.
52+
CreateCollectionV2(ctx context.Context, name string, props *CreateCollectionPropertiesV2) (Collection, error)
53+
54+
// Deprecated: use CreateCollectionWithOptionsV2 instead
55+
//
4856
// CreateCollectionWithOptions creates a new collection with given name and options, and opens a connection to it.
4957
// If a collection with given name already exists within the database, a DuplicateError is returned.
5058
CreateCollectionWithOptions(ctx context.Context, name string, props *CreateCollectionProperties, options *CreateCollectionOptions) (Collection, error)
59+
60+
// CreateCollectionWithOptions creates a new collection with given name and options, and opens a connection to it.
61+
// If a collection with given name already exists within the database, a DuplicateError is returned.
62+
CreateCollectionWithOptionsV2(ctx context.Context, name string, props *CreateCollectionPropertiesV2, options *CreateCollectionOptions) (Collection, error)
5163
}
5264

5365
type GetCollectionOptions struct {

v2/arangodb/database_collection_impl.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,20 @@ func (d databaseCollection) Collections(ctx context.Context) ([]Collection, erro
113113
}
114114
}
115115

116+
// Deprecated: use CreateCollectionV2 instead
117+
//
118+
// CreateCollectionWithOptions
116119
func (d databaseCollection) CreateCollection(ctx context.Context, name string, props *CreateCollectionProperties) (Collection, error) {
117120
return d.CreateCollectionWithOptions(ctx, name, props, nil)
118121
}
119122

123+
func (d databaseCollection) CreateCollectionV2(ctx context.Context, name string, props *CreateCollectionPropertiesV2) (Collection, error) {
124+
return d.CreateCollectionWithOptionsV2(ctx, name, props, nil)
125+
}
126+
127+
// Deprecated: use CreateCollectionWithOptionsV2 instead
128+
//
129+
// CreateCollectionWithOptions
120130
func (d databaseCollection) CreateCollectionWithOptions(ctx context.Context, name string, props *CreateCollectionProperties, options *CreateCollectionOptions) (Collection, error) {
121131
props.Init()
122132

@@ -143,3 +153,30 @@ func (d databaseCollection) CreateCollectionWithOptions(ctx context.Context, nam
143153
return nil, respData.AsArangoErrorWithCode(code)
144154
}
145155
}
156+
157+
func (d databaseCollection) CreateCollectionWithOptionsV2(ctx context.Context, name string, props *CreateCollectionPropertiesV2, options *CreateCollectionOptions) (Collection, error) {
158+
props.Init()
159+
160+
urlEndpoint := d.db.url("_api", "collection")
161+
reqData := struct {
162+
Name string `json:"name"`
163+
*CreateCollectionPropertiesV2
164+
}{
165+
Name: name,
166+
CreateCollectionPropertiesV2: props,
167+
}
168+
169+
var respData shared.ResponseStruct
170+
171+
resp, err := connection.CallPost(ctx, d.db.connection(), urlEndpoint, &respData, &reqData, append(d.db.modifiers, options.modifyRequest)...)
172+
if err != nil {
173+
return nil, errors.WithStack(err)
174+
}
175+
176+
switch code := resp.Code(); code {
177+
case http.StatusOK:
178+
return newCollection(d.db, name), nil
179+
default:
180+
return nil, respData.AsArangoErrorWithCode(code)
181+
}
182+
}

v2/arangodb/database_collection_opts.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"github.com/arangodb/go-driver/v2/connection"
2525
)
2626

27+
// Deprecated: Use CreateCollectionProprtiesV2 instead
28+
//
2729
// CreateCollectionProperties contains options that customize the creating of a collection.
2830
type CreateCollectionProperties struct {
2931
// CacheEnabled set cacheEnabled option in collection properties
@@ -108,6 +110,90 @@ type CreateCollectionProperties struct {
108110
ComputedValues []ComputedValue `json:"computedValues,omitempty"`
109111
}
110112

113+
// CreateCollectionProperties contains options that customize the creating of a collection.
114+
type CreateCollectionPropertiesV2 struct {
115+
// CacheEnabled set cacheEnabled option in collection properties
116+
CacheEnabled *bool `json:"cacheEnabled,omitempty"`
117+
// This field is used for internal purposes only. DO NOT USE.
118+
DistributeShardsLike *string `json:"distributeShardsLike,omitempty"`
119+
// DoCompact checks if the collection will be compacted (default is true)
120+
DoCompact *bool `json:"doCompact,omitempty"`
121+
// The number of buckets into which indexes using a hash table are split. The default is 16 and this number has to be a power
122+
// of 2 and less than or equal to 1024. For very large collections one should increase this to avoid long pauses when the hash
123+
// table has to be initially built or resized, since buckets are resized individually and can be initially built in parallel.
124+
// For example, 64 might be a sensible value for a collection with 100 000 000 documents.
125+
// Currently, only the edge index respects this value, but other index types might follow in future ArangoDB versions.
126+
// Changes are applied when the collection is loaded the next time.
127+
IndexBuckets *int `json:"indexBuckets,omitempty"`
128+
// Available from 3.9 ArangoD version.
129+
InternalValidatorType *int `json:"internalValidatorType,omitempty"`
130+
// IsDisjoint set isDisjoint flag for Graph. Required ArangoDB 3.7+
131+
IsDisjoint *bool `json:"isDisjoint,omitempty"`
132+
// Set to create a smart edge or vertex collection.
133+
// This requires ArangoDB Enterprise Edition.
134+
IsSmart *bool `json:"isSmart,omitempty"`
135+
// If true, create a system collection. In this case collection-name should start with an underscore.
136+
// End users should normally create non-system collections only. API implementors may be required to create system
137+
// collections in very special occasions, but normally a regular collection will do. (The default is false)
138+
IsSystem *bool `json:"isSystem,omitempty"`
139+
// If true then the collection data is kept in-memory only and not made persistent.
140+
// Unloading the collection will cause the collection data to be discarded. Stopping or re-starting the server will also
141+
// cause full loss of data in the collection. Setting this option will make the resulting collection be slightly faster
142+
// than regular collections because ArangoDB does not enforce any synchronization to disk and does not calculate any
143+
// CRC checksums for datafiles (as there are no datafiles). This option should therefore be used for cache-type collections only,
144+
// and not for data that cannot be re-created otherwise. (The default is false)
145+
IsVolatile *bool `json:"isVolatile,omitempty"`
146+
// The maximal size of a journal or datafile in bytes. The value must be at least 1048576 (1 MiB). (The default is a configuration parameter)
147+
JournalSize *int64 `json:"journalSize,omitempty"`
148+
// Specifies how keys in the collection are created.
149+
KeyOptions *CollectionKeyOptions `json:"keyOptions,omitempty"`
150+
// Deprecated: use 'WriteConcern' instead
151+
MinReplicationFactor *int `json:"minReplicationFactor,omitempty"`
152+
// In a cluster, this value determines the number of shards to create for the collection. In a single server setup, this option is meaningless. (default is 1)
153+
NumberOfShards *int `json:"numberOfShards,omitempty"`
154+
// ReplicationFactor in a cluster (default is 1), this attribute determines how many copies of each shard are kept on different DBServers.
155+
// The value 1 means that only one copy (no synchronous replication) is kept.
156+
// A value of k means that k-1 replicas are kept. Any two copies reside on different DBServers.
157+
// Replication between them is synchronous, that is, every write operation to the "leader" copy will be replicated to all "follower" replicas,
158+
// before the write operation is reported successful. If a server fails, this is detected automatically
159+
// and one of the servers holding copies take over, usually without an error being reported.
160+
ReplicationFactor *ReplicationFactor `json:"replicationFactor,omitempty"`
161+
// Schema for collection validation
162+
Schema *CollectionSchemaOptions `json:"schema,omitempty"`
163+
// This attribute specifies the name of the sharding strategy to use for the collection.
164+
// Must be one of ShardingStrategy* values.
165+
ShardingStrategy *ShardingStrategy `json:"shardingStrategy,omitempty"`
166+
// In a cluster, this attribute determines which document attributes are used to
167+
// determine the target shard for documents. Documents are sent to shards based on the values of their shard key attributes.
168+
// The values of all shard key attributes in a document are hashed, and the hash value is used to determine the target shard.
169+
// Note: Values of shard key attributes cannot be changed once set. This option is meaningless in a single server setup.
170+
// The default is []string{"_key"}.
171+
ShardKeys *[]string `json:"shardKeys,omitempty"`
172+
// This field must be set to the attribute that will be used for sharding or SmartGraphs.
173+
// All vertices are required to have this attribute set. Edges derive the attribute from their connected vertices.
174+
// This requires ArangoDB Enterprise Edition.
175+
SmartGraphAttribute *string `json:"smartGraphAttribute,omitempty"`
176+
// SmartJoinAttribute
177+
// In the specific case that the two collections have the same number of shards, the data of the two collections can
178+
// be co-located on the same server for the same shard key values. In this case the extra hop via the coordinator will not be necessary.
179+
// See documentation for SmartJoins.
180+
// This requires ArangoDB Enterprise Edition.
181+
SmartJoinAttribute *string `json:"smartJoinAttribute,omitempty"`
182+
// Available from 3.7 ArangoDB version
183+
SyncByRevision *bool `json:"syncByRevision,omitempty"`
184+
// The type of the collection to create. (default is CollectionTypeDocument)
185+
Type *CollectionType `json:"type,omitempty"`
186+
// If true then the data is synchronized to disk before returning from a document create, update, replace or removal operation. (default: false)
187+
WaitForSync *bool `json:"waitForSync,omitempty"`
188+
// WriteConcern contains how many copies must be available before a collection can be written.
189+
// It is required that 1 <= WriteConcern <= ReplicationFactor.
190+
// Default is 1. Not available for SatelliteCollections.
191+
// Available from 3.6 ArangoDB version.
192+
WriteConcern *int `json:"writeConcern,omitempty"`
193+
// ComputedValues let configure collections to generate document attributes when documents are created or modified, using an AQL expression
194+
ComputedValues *[]ComputedValue `json:"computedValues,omitempty"`
195+
}
196+
111197
// Init translate deprecated fields into current one for backward compatibility
112198
func (c *CreateCollectionProperties) Init() {
113199
if c == nil {
@@ -117,6 +203,15 @@ func (c *CreateCollectionProperties) Init() {
117203
c.KeyOptions.Init()
118204
}
119205

206+
// Init translate deprecated fields into current one for backward compatibility
207+
func (c *CreateCollectionPropertiesV2) Init() {
208+
if c == nil {
209+
return
210+
}
211+
212+
c.KeyOptions.Init()
213+
}
214+
120215
// CreateCollectionOptions specifies additional options to be provided while creating collection
121216
type CreateCollectionOptions struct {
122217
// EnforceReplicationFactor the default is true, which means the server checks if there are enough replicas available

0 commit comments

Comments
 (0)