Skip to content

Feature/add mis endpoints in col #695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6c8fbe9
Add Figures method to fetch collection statistics
bluepal-prasanthi-moparthi Jul 23, 2025
fb7648d
collection: Add Revision method to get revision ID
bluepal-prasanthi-moparthi Jul 24, 2025
d0801e3
collection: Add Checksum method to calculate collection metadata
bluepal-prasanthi-moparthi Jul 24, 2025
de50c6d
database: Add support for fetching available key generators
bluepal-prasanthi-moparthi Jul 24, 2025
f914908
collection: Add ResponsibleShard endpoint implementation
bluepal-prasanthi-moparthi Jul 25, 2025
1b57dca
collection: add loadIndexesIntoMemory method
bluepal-prasanthi-moparthi Jul 25, 2025
2b47739
Collection: Add Rename endpoint in V2
bluepal-prasanthi-moparthi Jul 28, 2025
62ed0ae
Collection: Add RecalculateCount endpoint in V2
bluepal-prasanthi-moparthi Jul 28, 2025
4e30a9b
Collection: Add Compact endpoint in V2
bluepal-prasanthi-moparthi Jul 28, 2025
c596573
Collection: fixed failed test case Test_CollectionResponsibleShard
bluepal-prasanthi-moparthi Jul 29, 2025
03b47b7
added pointers
bluepal-prasanthi-moparthi Jul 30, 2025
ec33659
fixed the test case
bluepal-prasanthi-moparthi Jul 30, 2025
245a59e
test case fix
bluepal-prasanthi-moparthi Jul 30, 2025
307a260
fixed failed test case
bluepal-prasanthi-moparthi Jul 30, 2025
8c8663f
add note in CHANGELOG file
bluepal-prasanthi-moparthi Jul 31, 2025
a10ea1f
add the comment and removed unwanted fmt
bluepal-prasanthi-moparthi Jul 31, 2025
1c2f653
Removed pointers and modified test casses accordingly
bluepal-prasanthi-moparthi Aug 5, 2025
5456709
fixed test case Test_CollectionShards
bluepal-prasanthi-moparthi Aug 5, 2025
9b6e560
chore: trigger CircleCI build
bluepal-prasanthi-moparthi Aug 5, 2025
49dedec
Addressed copilot comments
bluepal-prasanthi-moparthi Aug 5, 2025
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
1 change: 1 addition & 0 deletions v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [master](https://github.com/arangodb/go-driver/tree/master) (N/A)
- Add tasks endpoints to v2
- Add missing endpoints from collections to v2

## [2.1.3](https://github.com/arangodb/go-driver/tree/v2.1.3) (2025-02-21)
- Switch to Go 1.22.11
Expand Down
31 changes: 31 additions & 0 deletions v2/arangodb/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,37 @@ type Collection interface {
// Count fetches the number of document in the collection.
Count(ctx context.Context) (int64, error)

// Statistics returns the number of documents and additional statistical information about the collection.
Statistics(ctx context.Context, details bool) (CollectionFigures, error)

// Revision fetches the revision ID of the collection.
// The revision ID is a server-generated string that clients can use to check whether data
// in a collection has changed since the last revision check.
Revision(ctx context.Context) (CollectionProperties, error)

// Checksum returns a checksum for the specified collection
// withRevisions - Whether to include document revision ids in the checksum calculation.
// withData - Whether to include document body data in the checksum calculation.
Checksum(ctx context.Context, withRevisions *bool, withData *bool) (CollectionChecksum, error)

// ResponsibleShard returns the shard responsible for the given options.
ResponsibleShard(ctx context.Context, options map[string]interface{}) (string, error)

// LoadIndexesIntoMemory loads all indexes of the collection into memory.
LoadIndexesIntoMemory(ctx context.Context) (bool, error)

// Renaming collections is not supported in cluster deployments.
// Renaming collections is only supported in single server deployments.
Rename(ctx context.Context, req RenameCollectionRequest) (CollectionInfo, error)

// RecalculateCount recalculates the count of documents in the collection.
RecalculateCount(ctx context.Context) (bool, *int64, error)

//Compacts the data of a collection in order to reclaim disk space.
// This operation is only supported in single server deployments.
// In cluster deployments, the compaction is done automatically by the server.
Compact(ctx context.Context) (CollectionInfo, error)

CollectionDocuments
CollectionIndexes
}
190 changes: 190 additions & 0 deletions v2/arangodb/collection_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,196 @@ func (c collection) Shards(ctx context.Context, details bool) (CollectionShards,
}
}

func (c collection) Statistics(ctx context.Context, details bool) (CollectionFigures, error) {
urlEndpoint := c.url("collection", "figures")

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

resp, err := connection.CallGet(
ctx, c.connection(), urlEndpoint, &response,
c.withModifiers(connection.WithQuery("details", boolToString(details)))...,
)
if err != nil {
return CollectionFigures{}, errors.WithStack(err)
}

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

func (c collection) Revision(ctx context.Context) (CollectionProperties, error) {
urlEndpoint := c.url("collection", "revision")

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

resp, err := connection.CallGet(
ctx, c.connection(), urlEndpoint, &response, c.withModifiers()...,
)

if err != nil {
return CollectionProperties{}, errors.WithStack(err)
}

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

func (c collection) Checksum(ctx context.Context, withRevisions *bool, withData *bool) (CollectionChecksum, error) {
urlEndpoint := c.url("collection", "checksum")

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

// Prepare query modifiers
var modifiers []connection.RequestModifier
if withRevisions != nil && *withRevisions {
modifiers = append(modifiers, connection.WithQuery("withRevisions", boolToString(*withRevisions)))
}
if withData != nil && *withData {
modifiers = append(modifiers, connection.WithQuery("withData", boolToString(*withData)))
}

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

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

func (c collection) ResponsibleShard(ctx context.Context, options map[string]interface{}) (string, error) {
urlEndpoint := c.url("collection", "responsibleShard")

var response struct {
shared.ResponseStruct `json:",inline"`
ShardId string `json:"shardId,omitempty"`
}

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 response.ShardId, nil
default:
return "", response.AsArangoErrorWithCode(code)
}
}

func (c collection) LoadIndexesIntoMemory(ctx context.Context) (bool, error) {
urlEndpoint := c.url("collection", "loadIndexesIntoMemory")

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

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

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

// Renaming collections is not supported in cluster deployments.
func (c collection) Rename(ctx context.Context, req RenameCollectionRequest) (CollectionInfo, error) {
urlEndpoint := c.url("collection", "rename")

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

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

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

func (c collection) RecalculateCount(ctx context.Context) (bool, *int64, error) {
urlEndpoint := c.url("collection", "recalculateCount")

var response struct {
shared.ResponseStruct `json:",inline"`
Count *int64 `json:"count,omitempty"`
Result bool `json:"result"`
}

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

switch code := resp.Code(); code {
case http.StatusOK:
return response.Result, response.Count, nil
default:
zero := int64(0)
return false, &zero, response.AsArangoErrorWithCode(code)
}
}

func (c collection) Compact(ctx context.Context) (CollectionInfo, error) {
urlEndpoint := c.url("collection", "compact")

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

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

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

type RemoveCollectionOptions struct {
// IsSystem when set to true allows to remove system collections.
// Use on your own risk!
Expand Down
34 changes: 34 additions & 0 deletions v2/arangodb/collection_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type CollectionExtendedInfo struct {
// If set to false, then the key generator is solely responsible for generating keys and supplying own key values in
// the _key attribute of documents is considered an error.
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
// The initial value for the key generator. This is only used for autoincrement key generators.
LastValue *uint64 `json:"lastValue,omitempty"`
} `json:"keyOptions,omitempty"`

// NumberOfShards is the number of shards of the collection.
Expand Down Expand Up @@ -149,6 +151,9 @@ type CollectionProperties struct {

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

// The collection revision id as a string.
Revision string `json:"revision,omitempty"`
}

// IsSatellite returns true if the collection is a SatelliteCollection
Expand Down Expand Up @@ -322,6 +327,13 @@ type CollectionStatistics struct {
// The memory used for storing the revisions of this collection in the storage engine (in bytes). This figure does not include the document data but only mappings from document revision ids to storage engine datafile positions.
Size int64 `json:"size,omitempty"`
} `json:"revisions"`

DocumentsSize int64 `json:"documentsSize,omitempty"`

// RocksDB cache statistics
CacheInUse *bool `json:"cacheInUse,omitempty"`
CacheSize *int64 `json:"cacheSize,omitempty"`
CacheUsage *int64 `json:"cacheUsage,omitempty"`
} `json:"figures"`
}

Expand Down Expand Up @@ -370,3 +382,25 @@ func (r *ReplicationFactor) UnmarshalJSON(d []byte) error {
Type: reflect.TypeOf(r).Elem(),
}
}

type CollectionFigures struct {
CollectionProperties
CollectionStatistics
}

// CollectionChecksum contains information about a collection checksum response
type CollectionChecksum struct {
CollectionInfo
// The collection revision id as a string.
Revision string `json:"revision,omitempty"`
}

type ResponsibleShardRequest struct {
// Fill with shard key fields expected
Key string `json:"_key,omitempty"`
// other shard key fields as required
}

type RenameCollectionRequest struct {
Name string `json:"name"`
}
3 changes: 3 additions & 0 deletions v2/arangodb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type Database interface {
// TransactionJS performs a javascript transaction. The result of the transaction function is returned.
TransactionJS(ctx context.Context, options TransactionJSOptions) (interface{}, error)

// Returns the available key generators for collections.
KeyGenerators(ctx context.Context) (KeyGeneratorsResponse, error)

DatabaseCollection
DatabaseTransaction
DatabaseQuery
Expand Down
21 changes: 21 additions & 0 deletions v2/arangodb/database_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,24 @@ func (d database) TransactionJS(ctx context.Context, options TransactionJSOption
return nil, transactionResponse.AsArangoError()
}
}

func (d database) KeyGenerators(ctx context.Context) (KeyGeneratorsResponse, error) {
urlEndpoint := d.url("_api", "key-generators")

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

resp, err := connection.CallGet(ctx, d.client.connection, urlEndpoint, &response)
if err != nil {
return KeyGeneratorsResponse{}, errors.WithStack(err)
}

switch code := resp.Code(); code {
case http.StatusOK:
return response.KeyGeneratorsResponse, nil
default:
return KeyGeneratorsResponse{}, response.AsArangoError()
}
}
4 changes: 4 additions & 0 deletions v2/arangodb/database_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ func (t EngineType) String() string {
type EngineInfo struct {
Type EngineType `json:"name"`
}

type KeyGeneratorsResponse struct {
KeyGenerators []string `json:"keyGenerators"`
}
Loading