Skip to content

Commit 56076ed

Browse files
authored
Set proper type for lastValue field (#401)
1 parent b74bb42 commit 56076ed

File tree

4 files changed

+65
-43
lines changed

4 files changed

+65
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/go-driver/tree/master) (N/A)
4+
- Fix `lastValue` field type
45

56
## [1.3.2](https://github.com/arangodb/go-driver/tree/v1.3.2) (2022-05-16)
6-
77
- Fix selectivityEstimate Index field type
88

99
## [1.3.1](https://github.com/arangodb/go-driver/tree/v1.3.1) (2022-03-23)
10-
1110
- Add support for `exclusive` field for transaction options
1211
- Fix cursor executionTime statistics getter
1312
- Fix cursor warnings field type
1413
- Fix for DocumentMeta name field overrides name field
1514

1615
## [1.3.0](https://github.com/arangodb/go-driver/tree/v1.3.0) (2022-03-17)
17-
1816
- Disallow unknown fields feature
1917
- inBackground parameter in ArangoSearch links
2018
- ZKD indexes

cluster.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,11 @@ type InventoryCollectionParameters struct {
256256
// Deprecated: since 3.7 version. It is related only to MMFiles.
257257
JournalSize int64 `json:"journalSize,omitempty"`
258258
KeyOptions struct {
259-
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
260-
LastValue int64 `json:"lastValue,omitempty"`
261-
Type string `json:"type,omitempty"`
259+
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
260+
// Deprecated: this field has wrong type and will be removed in the future. It is not used anymore since it can cause parsing issues.
261+
LastValue int64 `json:"-"`
262+
LastValueV2 uint64 `json:"lastValue,omitempty"`
263+
Type string `json:"type,omitempty"`
262264
} `json:"keyOptions"`
263265
// Deprecated: use 'WriteConcern' instead.
264266
MinReplicationFactor int `json:"minReplicationFactor,omitempty"`

cluster_impl.go

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type cluster struct {
4343
conn Connection
4444
}
4545

46-
// LoggerState returns the state of the replication logger
46+
// Health returns the state of the cluster
4747
func (c *cluster) Health(ctx context.Context) (ClusterHealth, error) {
4848
req, err := c.conn.NewRequest("GET", "_admin/cluster/health")
4949
if err != nil {
@@ -64,7 +64,7 @@ func (c *cluster) Health(ctx context.Context) (ClusterHealth, error) {
6464
return result, nil
6565
}
6666

67-
// Get the inventory of the cluster containing all collections (with entire details) of a database.
67+
// DatabaseInventory Get the inventory of the cluster containing all collections (with entire details) of a database.
6868
func (c *cluster) DatabaseInventory(ctx context.Context, db Database) (DatabaseInventory, error) {
6969
req, err := c.conn.NewRequest("GET", path.Join("_db", db.Name(), "_api/replication/clusterInventory"))
7070
if err != nil {
@@ -290,7 +290,7 @@ type inventoryCollectionParametersInternal struct {
290290
JournalSize int64 `json:"journalSize,omitempty"`
291291
KeyOptions struct {
292292
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
293-
LastValue int64 `json:"lastValue,omitempty"`
293+
LastValue uint64 `json:"lastValue,omitempty"`
294294
Type string `json:"type,omitempty"`
295295
} `json:"keyOptions"`
296296
// Deprecated: use 'WriteConcern' instead
@@ -322,23 +322,35 @@ type inventoryCollectionParametersInternal struct {
322322
}
323323

324324
func (p *InventoryCollectionParameters) asInternal() inventoryCollectionParametersInternal {
325+
lastValue := p.KeyOptions.LastValueV2
326+
if lastValue == 0 && p.KeyOptions.LastValue != 0 {
327+
lastValue = uint64(p.KeyOptions.LastValue)
328+
}
329+
325330
return inventoryCollectionParametersInternal{
326-
CacheEnabled: p.CacheEnabled,
327-
Deleted: p.Deleted,
328-
DistributeShardsLike: p.DistributeShardsLike,
329-
DoCompact: p.DoCompact,
330-
GloballyUniqueId: p.GloballyUniqueId,
331-
ID: p.ID,
332-
IndexBuckets: p.IndexBuckets,
333-
Indexes: p.Indexes,
334-
InternalValidatorType: p.InternalValidatorType,
335-
IsDisjoint: p.IsDisjoint,
336-
IsSmart: p.IsSmart,
337-
IsSmartChild: p.IsSmartChild,
338-
IsSystem: p.IsSystem,
339-
IsVolatile: p.IsVolatile,
340-
JournalSize: p.JournalSize,
341-
KeyOptions: p.KeyOptions,
331+
CacheEnabled: p.CacheEnabled,
332+
Deleted: p.Deleted,
333+
DistributeShardsLike: p.DistributeShardsLike,
334+
DoCompact: p.DoCompact,
335+
GloballyUniqueId: p.GloballyUniqueId,
336+
ID: p.ID,
337+
IndexBuckets: p.IndexBuckets,
338+
Indexes: p.Indexes,
339+
InternalValidatorType: p.InternalValidatorType,
340+
IsDisjoint: p.IsDisjoint,
341+
IsSmart: p.IsSmart,
342+
IsSmartChild: p.IsSmartChild,
343+
IsSystem: p.IsSystem,
344+
IsVolatile: p.IsVolatile,
345+
JournalSize: p.JournalSize,
346+
KeyOptions: struct {
347+
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
348+
LastValue uint64 `json:"lastValue,omitempty"`
349+
Type string `json:"type,omitempty"`
350+
}{
351+
p.KeyOptions.AllowUserKeys,
352+
lastValue,
353+
p.KeyOptions.Type},
342354
MinReplicationFactor: p.MinReplicationFactor,
343355
Name: p.Name,
344356
NumberOfShards: p.NumberOfShards,
@@ -367,22 +379,32 @@ func (p *InventoryCollectionParameters) fromInternal(i inventoryCollectionParame
367379

368380
func (p *inventoryCollectionParametersInternal) asExternal() InventoryCollectionParameters {
369381
return InventoryCollectionParameters{
370-
CacheEnabled: p.CacheEnabled,
371-
Deleted: p.Deleted,
372-
DistributeShardsLike: p.DistributeShardsLike,
373-
DoCompact: p.DoCompact,
374-
GloballyUniqueId: p.GloballyUniqueId,
375-
ID: p.ID,
376-
IndexBuckets: p.IndexBuckets,
377-
Indexes: p.Indexes,
378-
InternalValidatorType: p.InternalValidatorType,
379-
IsDisjoint: p.IsDisjoint,
380-
IsSmart: p.IsSmart,
381-
IsSmartChild: p.IsSmartChild,
382-
IsSystem: p.IsSystem,
383-
IsVolatile: p.IsVolatile,
384-
JournalSize: p.JournalSize,
385-
KeyOptions: p.KeyOptions,
382+
CacheEnabled: p.CacheEnabled,
383+
Deleted: p.Deleted,
384+
DistributeShardsLike: p.DistributeShardsLike,
385+
DoCompact: p.DoCompact,
386+
GloballyUniqueId: p.GloballyUniqueId,
387+
ID: p.ID,
388+
IndexBuckets: p.IndexBuckets,
389+
Indexes: p.Indexes,
390+
InternalValidatorType: p.InternalValidatorType,
391+
IsDisjoint: p.IsDisjoint,
392+
IsSmart: p.IsSmart,
393+
IsSmartChild: p.IsSmartChild,
394+
IsSystem: p.IsSystem,
395+
IsVolatile: p.IsVolatile,
396+
JournalSize: p.JournalSize,
397+
KeyOptions: struct {
398+
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
399+
LastValue int64 `json:"-"`
400+
LastValueV2 uint64 `json:"lastValue,omitempty"`
401+
Type string `json:"type,omitempty"`
402+
}{
403+
p.KeyOptions.AllowUserKeys,
404+
// cast to int64 to keep backwards compatibility for most cases
405+
int64(p.KeyOptions.LastValue),
406+
p.KeyOptions.LastValue,
407+
p.KeyOptions.Type},
386408
MinReplicationFactor: p.MinReplicationFactor,
387409
Name: p.Name,
388410
NumberOfShards: p.NumberOfShards,

collection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ type CollectionProperties struct {
116116
// AllowUserKeys; if set to true, then it is allowed to supply own key values in the _key attribute of a document.
117117
// If set to false, then the key generator is solely responsible for generating keys and supplying own key values in
118118
// the _key attribute of documents is considered an error.
119-
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
120-
LastValue int64 `json:"lastValue,omitempty"`
119+
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
120+
LastValue uint64 `json:"lastValue,omitempty"`
121121
} `json:"keyOptions,omitempty"`
122122
// NumberOfShards is the number of shards of the collection.
123123
// Only available in cluster setup.

0 commit comments

Comments
 (0)