Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ parameters:
default: "gcr.io/gcr-for-testing/golang:1.22.12"
arangodbImage:
type: string
default: "gcr.io/gcr-for-testing/arangodb/enterprise-preview:devel-nightly"
default: "gcr.io/gcr-for-testing/arangodb/enterprise-preview:latest"
alpineImage:
type: string
default: "gcr.io/gcr-for-testing/alpine:3.21"
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.debug
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG GOVERSION
FROM golang:${GOVERSION} as builder

ARG GOTOOLCHAIN=local
ENV GOTOOLCHAIN=${GOTOOLCHAIN}
ARG TESTS_DIRECTORY
ARG TESTS_ROOT_PATH="."

Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GOVERSION ?= 1.22.12
GOTOOLCHAIN ?= auto
GOIMAGE ?= golang:$(GOVERSION)
GOV2IMAGE ?= $(GOIMAGE)
ALPINE_IMAGE ?= alpine:3.17
ALPINE_IMAGE ?= alpine:3.21
TMPDIR := ${SCRIPTDIR}/.tmp

DOCKER_CMD:=docker run
Expand Down Expand Up @@ -139,10 +139,10 @@ endif

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

DOCKER_RUN_CMD := $(DOCKER_DEBUG_ARGS) $(GOIMAGE) /go/bin/dlv --listen=:$(DEBUG_PORT) --headless=true --api-version=2 exec /test_debug.test -- $(TESTOPTIONS)
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)
DOCKER_V2_RUN_CMD := $(DOCKER_RUN_CMD)
else
DOCKER_RUN_CMD := $(GOIMAGE) go test -timeout 120m $(GOBUILDTAGSOPT) $(TESTOPTIONS) $(TESTVERBOSEOPTIONS) $(TESTS)
Expand Down Expand Up @@ -461,12 +461,12 @@ __test_v2_go_test:

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

__test_v2_debug__:
ifeq ("$(DEBUG)", "true")
@docker build -f Dockerfile.debug --build-arg GOVERSION=$(GOVERSION) --build-arg "TESTS_DIRECTORY=./tests" --build-arg "TESTS_ROOT_PATH=v2" -t $(GOIMAGE) .
@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) .
endif

__dir_setup:
Expand Down
5 changes: 5 additions & 0 deletions v2/arangodb/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ type Collection interface {
// Properties fetches extended information about the collection.
Properties(ctx context.Context) (CollectionProperties, error)

// Deprecated: use 'SetPropertiesV2' instead
//
// SetProperties allows modifying collection parameters
SetProperties(ctx context.Context, options SetCollectionPropertiesOptions) error

// SetProperties allows modifying collection parameters
SetPropertiesV2(ctx context.Context, options SetCollectionPropertiesOptionsV2) error

// Count fetches the number of document in the collection.
Count(ctx context.Context) (int64, error)

Expand Down
20 changes: 20 additions & 0 deletions v2/arangodb/collection_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ func (c collection) SetProperties(ctx context.Context, options SetCollectionProp
}
}

func (c collection) SetPropertiesV2(ctx context.Context, options SetCollectionPropertiesOptionsV2) error {
urlEndpoint := c.url("collection", "properties")

var response struct {
shared.ResponseStruct `json:",inline"`
}

resp, err := connection.CallPut(ctx, c.connection(), urlEndpoint, &response, options, c.withModifiers()...)
if err != nil {
return errors.WithStack(err)
}

switch code := resp.Code(); code {
case http.StatusOK:
return nil
default:
return response.AsArangoErrorWithCode(code)
}
}

func (c collection) Name() string {
return c.name
}
Expand Down
30 changes: 30 additions & 0 deletions v2/arangodb/collection_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ func (p *CollectionProperties) IsSatellite() bool {
return p.ReplicationFactor == ReplicationFactorSatellite
}

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

type SetCollectionPropertiesOptionsV2 struct {
// If true then creating or changing a document will wait until the data has been synchronized to disk.
WaitForSync *bool `json:"waitForSync,omitempty"`

// 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.
JournalSize *int64 `json:"journalSize,omitempty"`

// ReplicationFactor contains how many copies of each shard are kept on different DBServers.
// Only available in cluster setup.
ReplicationFactor *ReplicationFactor `json:"replicationFactor,omitempty"`

// Deprecated: use 'WriteConcern' instead
MinReplicationFactor *int `json:"minReplicationFactor,omitempty"`

// WriteConcern contains how many copies must be available before a collection can be written.
// Available from 3.6 arangod version.
WriteConcern *int `json:"writeConcern,omitempty"`

// CacheEnabled set cacheEnabled option in collection properties
CacheEnabled *bool `json:"cacheEnabled,omitempty"`

// Schema for collection validation
Schema *CollectionSchemaOptions `json:"schema,omitempty"`

// ComputedValues let configure collections to generate document attributes when documents are created or modified, using an AQL expression
ComputedValues *[]ComputedValue `json:"computedValues,omitempty"`
}

type ComputedValue struct {
// The name of the target attribute. Can only be a top-level attribute, but you
// may return a nested object. Cannot be `_key`, `_id`, `_rev`, `_from`, `_to`,
Expand Down
12 changes: 12 additions & 0 deletions v2/arangodb/database_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,25 @@ type DatabaseCollection interface {
// Collections returns a list of all collections in the database.
Collections(ctx context.Context) ([]Collection, error)

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

// CreateCollection creates a new collection with given name and options, and opens a connection to it.
// If a collection with given name already exists within the database, a DuplicateError is returned.
CreateCollectionV2(ctx context.Context, name string, props *CreateCollectionPropertiesV2) (Collection, error)

// Deprecated: use CreateCollectionWithOptionsV2 instead
//
// CreateCollectionWithOptions creates a new collection with given name and options, and opens a connection to it.
// If a collection with given name already exists within the database, a DuplicateError is returned.
CreateCollectionWithOptions(ctx context.Context, name string, props *CreateCollectionProperties, options *CreateCollectionOptions) (Collection, error)

// CreateCollectionWithOptions creates a new collection with given name and options, and opens a connection to it.
// If a collection with given name already exists within the database, a DuplicateError is returned.
CreateCollectionWithOptionsV2(ctx context.Context, name string, props *CreateCollectionPropertiesV2, options *CreateCollectionOptions) (Collection, error)
}

type GetCollectionOptions struct {
Expand Down
37 changes: 37 additions & 0 deletions v2/arangodb/database_collection_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,20 @@ func (d databaseCollection) Collections(ctx context.Context) ([]Collection, erro
}
}

// Deprecated: use CreateCollectionV2 instead
//
// CreateCollectionWithOptions
func (d databaseCollection) CreateCollection(ctx context.Context, name string, props *CreateCollectionProperties) (Collection, error) {
return d.CreateCollectionWithOptions(ctx, name, props, nil)
}

func (d databaseCollection) CreateCollectionV2(ctx context.Context, name string, props *CreateCollectionPropertiesV2) (Collection, error) {
return d.CreateCollectionWithOptionsV2(ctx, name, props, nil)
}

// Deprecated: use CreateCollectionWithOptionsV2 instead
//
// CreateCollectionWithOptions
func (d databaseCollection) CreateCollectionWithOptions(ctx context.Context, name string, props *CreateCollectionProperties, options *CreateCollectionOptions) (Collection, error) {
props.Init()

Expand All @@ -143,3 +153,30 @@ func (d databaseCollection) CreateCollectionWithOptions(ctx context.Context, nam
return nil, respData.AsArangoErrorWithCode(code)
}
}

func (d databaseCollection) CreateCollectionWithOptionsV2(ctx context.Context, name string, props *CreateCollectionPropertiesV2, options *CreateCollectionOptions) (Collection, error) {
props.Init()

urlEndpoint := d.db.url("_api", "collection")
reqData := struct {
Name string `json:"name"`
*CreateCollectionPropertiesV2
}{
Name: name,
CreateCollectionPropertiesV2: props,
}

var respData shared.ResponseStruct

resp, err := connection.CallPost(ctx, d.db.connection(), urlEndpoint, &respData, &reqData, append(d.db.modifiers, options.modifyRequest)...)
if err != nil {
return nil, errors.WithStack(err)
}

switch code := resp.Code(); code {
case http.StatusOK:
return newCollection(d.db, name), nil
default:
return nil, respData.AsArangoErrorWithCode(code)
}
}
95 changes: 95 additions & 0 deletions v2/arangodb/database_collection_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/arangodb/go-driver/v2/connection"
)

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

// CreateCollectionProperties contains options that customize the creating of a collection.
type CreateCollectionPropertiesV2 struct {
// CacheEnabled set cacheEnabled option in collection properties
CacheEnabled *bool `json:"cacheEnabled,omitempty"`
// This field is used for internal purposes only. DO NOT USE.
DistributeShardsLike *string `json:"distributeShardsLike,omitempty"`
// DoCompact checks if the collection will be compacted (default is true)
DoCompact *bool `json:"doCompact,omitempty"`
// 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
// of 2 and less than or equal to 1024. For very large collections one should increase this to avoid long pauses when the hash
// table has to be initially built or resized, since buckets are resized individually and can be initially built in parallel.
// For example, 64 might be a sensible value for a collection with 100 000 000 documents.
// Currently, only the edge index respects this value, but other index types might follow in future ArangoDB versions.
// Changes are applied when the collection is loaded the next time.
IndexBuckets *int `json:"indexBuckets,omitempty"`
// Available from 3.9 ArangoD version.
InternalValidatorType *int `json:"internalValidatorType,omitempty"`
// IsDisjoint set isDisjoint flag for Graph. Required ArangoDB 3.7+
IsDisjoint *bool `json:"isDisjoint,omitempty"`
// Set to create a smart edge or vertex collection.
// This requires ArangoDB Enterprise Edition.
IsSmart *bool `json:"isSmart,omitempty"`
// If true, create a system collection. In this case collection-name should start with an underscore.
// End users should normally create non-system collections only. API implementors may be required to create system
// collections in very special occasions, but normally a regular collection will do. (The default is false)
IsSystem *bool `json:"isSystem,omitempty"`
// If true then the collection data is kept in-memory only and not made persistent.
// Unloading the collection will cause the collection data to be discarded. Stopping or re-starting the server will also
// cause full loss of data in the collection. Setting this option will make the resulting collection be slightly faster
// than regular collections because ArangoDB does not enforce any synchronization to disk and does not calculate any
// CRC checksums for datafiles (as there are no datafiles). This option should therefore be used for cache-type collections only,
// and not for data that cannot be re-created otherwise. (The default is false)
IsVolatile *bool `json:"isVolatile,omitempty"`
// 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)
JournalSize *int64 `json:"journalSize,omitempty"`
// Specifies how keys in the collection are created.
KeyOptions *CollectionKeyOptions `json:"keyOptions,omitempty"`
// Deprecated: use 'WriteConcern' instead
MinReplicationFactor *int `json:"minReplicationFactor,omitempty"`
// 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)
NumberOfShards *int `json:"numberOfShards,omitempty"`
// ReplicationFactor in a cluster (default is 1), this attribute determines how many copies of each shard are kept on different DBServers.
// The value 1 means that only one copy (no synchronous replication) is kept.
// A value of k means that k-1 replicas are kept. Any two copies reside on different DBServers.
// Replication between them is synchronous, that is, every write operation to the "leader" copy will be replicated to all "follower" replicas,
// before the write operation is reported successful. If a server fails, this is detected automatically
// and one of the servers holding copies take over, usually without an error being reported.
ReplicationFactor *ReplicationFactor `json:"replicationFactor,omitempty"`
// Schema for collection validation
Schema *CollectionSchemaOptions `json:"schema,omitempty"`
// This attribute specifies the name of the sharding strategy to use for the collection.
// Must be one of ShardingStrategy* values.
ShardingStrategy *ShardingStrategy `json:"shardingStrategy,omitempty"`
// In a cluster, this attribute determines which document attributes are used to
// determine the target shard for documents. Documents are sent to shards based on the values of their shard key attributes.
// The values of all shard key attributes in a document are hashed, and the hash value is used to determine the target shard.
// Note: Values of shard key attributes cannot be changed once set. This option is meaningless in a single server setup.
// The default is []string{"_key"}.
ShardKeys *[]string `json:"shardKeys,omitempty"`
// This field must be set to the attribute that will be used for sharding or SmartGraphs.
// All vertices are required to have this attribute set. Edges derive the attribute from their connected vertices.
// This requires ArangoDB Enterprise Edition.
SmartGraphAttribute *string `json:"smartGraphAttribute,omitempty"`
// SmartJoinAttribute
// In the specific case that the two collections have the same number of shards, the data of the two collections can
// 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.
// See documentation for SmartJoins.
// This requires ArangoDB Enterprise Edition.
SmartJoinAttribute *string `json:"smartJoinAttribute,omitempty"`
// Available from 3.7 ArangoDB version
SyncByRevision *bool `json:"syncByRevision,omitempty"`
// The type of the collection to create. (default is CollectionTypeDocument)
Type *CollectionType `json:"type,omitempty"`
// If true then the data is synchronized to disk before returning from a document create, update, replace or removal operation. (default: false)
WaitForSync *bool `json:"waitForSync,omitempty"`
// WriteConcern contains how many copies must be available before a collection can be written.
// It is required that 1 <= WriteConcern <= ReplicationFactor.
// Default is 1. Not available for SatelliteCollections.
// Available from 3.6 ArangoDB version.
WriteConcern *int `json:"writeConcern,omitempty"`
// ComputedValues let configure collections to generate document attributes when documents are created or modified, using an AQL expression
ComputedValues *[]ComputedValue `json:"computedValues,omitempty"`
}

// Init translate deprecated fields into current one for backward compatibility
func (c *CreateCollectionProperties) Init() {
if c == nil {
Expand All @@ -117,6 +203,15 @@ func (c *CreateCollectionProperties) Init() {
c.KeyOptions.Init()
}

// Init translate deprecated fields into current one for backward compatibility
func (c *CreateCollectionPropertiesV2) Init() {
if c == nil {
return
}

c.KeyOptions.Init()
}

// CreateCollectionOptions specifies additional options to be provided while creating collection
type CreateCollectionOptions struct {
// EnforceReplicationFactor the default is true, which means the server checks if there are enough replicas available
Expand Down
Loading