Skip to content

Commit bad8428

Browse files
author
Lars Maier
authored
Add replication version option for database creation. (#494)
1 parent a0500c8 commit bad8428

7 files changed

+92
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [V2] Fix: Plain Connection doesn't work with JWT authentication
88
- Support for new error codes if write concern is not fulfilled
99
- Support for geo_s2 analyzers
10+
- Add replication V2 option for database creation
1011

1112
## [1.5.2](https://github.com/arangodb/go-driver/tree/v1.5.2) (2023-03-01)
1213
- Bump `DRIVER_VERSION`

client_databases.go

+13
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ type CreateDatabaseOptions struct {
6262
Options CreateDatabaseDefaultOptions `json:"options,omitempty"`
6363
}
6464

65+
// DatabaseReplicationVersion defines replication protocol version to use for this database
66+
// Available since ArangoDB version 3.11
67+
// Note: this feature is still considered experimental and should not be used in production
68+
type DatabaseReplicationVersion string
69+
70+
const (
71+
DatabaseReplicationVersionOne DatabaseReplicationVersion = "1"
72+
DatabaseReplicationVersionTwo DatabaseReplicationVersion = "2"
73+
)
74+
6575
// CreateDatabaseDefaultOptions contains options that change defaults for collections
6676
type CreateDatabaseDefaultOptions struct {
6777
// Default replication factor for collections in database
@@ -70,6 +80,9 @@ type CreateDatabaseDefaultOptions struct {
7080
WriteConcern int `json:"writeConcern,omitempty"`
7181
// Default sharding for collections in database
7282
Sharding DatabaseSharding `json:"sharding,omitempty"`
83+
// Replication version to use for this database
84+
// Available since ArangoDB version 3.11
85+
ReplicationVersion DatabaseReplicationVersion `json:"replicationVersion,omitempty"`
7386
}
7487

7588
// CreateDatabaseUserOptions contains options for creating a single user for a database.

database.go

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ type DatabaseInfo struct {
9494
WriteConcern int `json:"writeConcern,omitempty"`
9595
// Default sharding for collections in database
9696
Sharding DatabaseSharding `json:"sharding,omitempty"`
97+
// Replication version used for this database
98+
ReplicationVersion DatabaseReplicationVersion `json:"replicationVersion,omitempty"`
9799
}
98100

99101
// EngineType indicates type of database engine being used.

test/database_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,44 @@ func TestDatabaseNameUnicode(t *testing.T) {
204204
require.NoErrorf(t, db.Remove(ctx), "failed to remove testing database")
205205
}
206206

207+
// TestCreateDatabaseReplication2 creates a database with replication version two.
208+
func TestCreateDatabaseReplication2(t *testing.T) {
209+
ctx := context.Background()
210+
c := createClientFromEnv(t, true)
211+
version, _ := c.Version(ctx)
212+
if version.Version.CompareTo("3.11.0") < 0 {
213+
t.Skipf("Version of the ArangoDB should be at least 3.11.0")
214+
}
215+
216+
name := "create_test1"
217+
opts := driver.CreateDatabaseOptions{Options: driver.CreateDatabaseDefaultOptions{
218+
ReplicationVersion: driver.DatabaseReplicationVersionTwo,
219+
}}
220+
if _, err := c.CreateDatabase(nil, name, &opts); err != nil {
221+
t.Fatalf("Failed to create database '%s': %s", name, describe(err))
222+
}
223+
// Database must exist now
224+
if found, err := c.DatabaseExists(nil, name); err != nil {
225+
t.Errorf("DatabaseExists('%s') failed: %s", name, describe(err))
226+
} else if !found {
227+
t.Errorf("DatabaseExists('%s') return false, expected true", name)
228+
}
229+
230+
// Read database properties
231+
db, err := c.Database(nil, name)
232+
if err != nil {
233+
t.Fatal("Failed to get database ")
234+
}
235+
info, err := db.Info(nil)
236+
if err != nil {
237+
t.Fatal("Failed to get database name")
238+
}
239+
240+
if info.ReplicationVersion != driver.DatabaseReplicationVersionTwo {
241+
t.Errorf("Wrong replication version, expected %s, found %s", driver.DatabaseReplicationVersionTwo, info.ReplicationVersion)
242+
}
243+
}
244+
207245
// databaseExtendedNamesRequired skips test if the version is < 3.9.0 or the ArangoDB has not been launched
208246
// with the option --database.extended-names-databases=true.
209247
func databaseExtendedNamesRequired(t *testing.T, c driver.Client) {

v2/arangodb/client_database.go

+13
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ type CreateDatabaseOptions struct {
6363
Options CreateDatabaseDefaultOptions `json:"options,omitempty"`
6464
}
6565

66+
// DatabaseReplicationVersion defines replication protocol version to use for this database
67+
// Available since ArangoDB version 3.11
68+
// Note: this feature is still considered experimental and should not be used in production
69+
type DatabaseReplicationVersion string
70+
71+
const (
72+
DatabaseReplicationVersionOne DatabaseReplicationVersion = "1"
73+
DatabaseReplicationVersionTwo DatabaseReplicationVersion = "2"
74+
)
75+
6676
// CreateDatabaseDefaultOptions contains options that change defaults for collections
6777
type CreateDatabaseDefaultOptions struct {
6878
// Default replication factor for collections in database
@@ -71,6 +81,9 @@ type CreateDatabaseDefaultOptions struct {
7181
WriteConcern int `json:"writeConcern,omitempty"`
7282
// Default sharding for collections in database
7383
Sharding DatabaseSharding `json:"sharding,omitempty"`
84+
// Replication version to use for this database
85+
// Available since ArangoDB version 3.11
86+
ReplicationVersion DatabaseReplicationVersion `json:"replicationVersion,omitempty"`
7487
}
7588

7689
// CreateDatabaseUserOptions contains options for creating a single user for a database.

v2/arangodb/database_opts.go

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type DatabaseInfo struct {
3838
WriteConcern int `json:"writeConcern,omitempty"`
3939
// Default sharding for collections in database
4040
Sharding DatabaseSharding `json:"sharding,omitempty"`
41+
// Replication version used for this database
42+
ReplicationVersion DatabaseReplicationVersion `json:"replicationVersion,omitempty"`
4143
}
4244

4345
// EngineType indicates type of database engine being used.

v2/tests/database_transactions_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,29 @@ import (
3535
"github.com/arangodb/go-driver/v2/arangodb/shared"
3636
)
3737

38+
func Test_DatabaseCreateReplicationV2(t *testing.T) {
39+
client := newClient(t, connectionJsonHttp(t))
40+
skipBelowVersion(client, context.Background(), "3.11.0", t)
41+
42+
Wrap(t, func(t *testing.T, client arangodb.Client) {
43+
opts := arangodb.CreateDatabaseOptions{
44+
Users: nil,
45+
Options: arangodb.CreateDatabaseDefaultOptions{
46+
ReplicationVersion: arangodb.DatabaseReplicationVersionTwo,
47+
},
48+
}
49+
WithDatabase(t, client, &opts, func(db arangodb.Database) {
50+
t.Run("Transaction", func(t *testing.T) {
51+
withContextT(t, 30*time.Second, func(ctx context.Context, t testing.TB) {
52+
info, err := db.Info(ctx)
53+
require.NoErrorf(t, err, "failed to get database info")
54+
require.Equal(t, arangodb.DatabaseReplicationVersionTwo, info.ReplicationVersion)
55+
})
56+
})
57+
})
58+
})
59+
}
60+
3861
func Test_DatabaseTransactions_DataIsolation(t *testing.T) {
3962
Wrap(t, func(t *testing.T, client arangodb.Client) {
4063
WithDatabase(t, client, nil, func(db arangodb.Database) {

0 commit comments

Comments
 (0)