This repository has been archived by the owner on Feb 23, 2023. It is now read-only.
forked from arangodb/go-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collection.go
256 lines (231 loc) · 12.2 KB
/
collection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//
// DISCLAIMER
//
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//
package driver
import (
"context"
"time"
)
// Collection provides access to the information of a single collection, all its documents and all its indexes.
type Collection interface {
// Name returns the name of the collection.
Name() string
// Database returns the database containing the collection.
Database() Database
// Status fetches the current status of the collection.
Status(ctx context.Context) (CollectionStatus, error)
// 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) (CollectionStatistics, 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) (string, error)
// Properties fetches extended information about the collection.
Properties(ctx context.Context) (CollectionProperties, error)
// SetProperties changes properties of the collection.
SetProperties(ctx context.Context, options SetCollectionPropertiesOptions) error
// Load the collection into memory.
Load(ctx context.Context) error
// UnLoad the collection from memory.
Unload(ctx context.Context) error
// Remove removes the entire collection.
// If the collection does not exist, a NotFoundError is returned.
Remove(ctx context.Context) error
// Truncate removes all documents from the collection, but leaves the indexes intact.
Truncate(ctx context.Context) error
// All index functions
CollectionIndexes
// All document functions
CollectionDocuments
}
// CollectionInfo contains information about a collection
type CollectionInfo struct {
// The identifier of the collection.
ID string `json:"id,omitempty"`
// The name of the collection.
Name string `json:"name,omitempty"`
// The status of the collection
Status CollectionStatus `json:"status,omitempty"`
// The type of the collection
Type CollectionType `json:"type,omitempty"`
// If true then the collection is a system collection.
IsSystem bool `json:"isSystem,omitempty"`
// Global unique name for the collection
GloballyUniqueId string `json:"globallyUniqueId,omitempty"`
}
// CollectionProperties contains extended information about a collection.
type CollectionProperties struct {
CollectionInfo
// WaitForSync; If true then creating, changing or removing documents will wait until the data has been synchronized to disk.
WaitForSync bool `json:"waitForSync,omitempty"`
// DoCompact specifies whether or not the collection will be compacted.
DoCompact bool `json:"doCompact,omitempty"`
// JournalSize is the maximal size setting for journals / datafiles in bytes.
JournalSize int64 `json:"journalSize,omitempty"`
KeyOptions struct {
// Type specifies the type of the key generator. The currently available generators are traditional and autoincrement.
Type KeyGeneratorType `json:"type,omitempty"`
// AllowUserKeys; if set to true, then it is allowed to supply own key values in the _key attribute of a document.
// 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"`
} `json:"keyOptions,omitempty"`
// NumberOfShards is the number of shards of the collection.
// Only available in cluster setup.
NumberOfShards int `json:"numberOfShards,omitempty"`
// ShardKeys contains the names of document attributes that are used to determine the target shard for documents.
// Only available in cluster setup.
ShardKeys []string `json:"shardKeys,omitempty"`
// ReplicationFactor contains how many copies of each shard are kept on different DBServers.
// Only available in cluster setup.
ReplicationFactor int `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.
// It is required that 1 <= WriteConcern <= ReplicationFactor.
// Default is 1. Not available for satellite collections.
// Available from 3.6 arangod version.
WriteConcern int `json:"writeConcern,omitempty"`
// SmartJoinAttribute
// See documentation for smart joins.
// This requires ArangoDB Enterprise Edition.
SmartJoinAttribute string `json:"smartJoinAttribute,omitempty"`
// This attribute specifies the name of the sharding strategy to use for the collection.
// Can not be changed after creation.
ShardingStrategy ShardingStrategy `json:"shardingStrategy,omitempty"`
// This attribute specifies that the sharding of a collection follows that of another
// one.
DistributeShardsLike string `json:"distributeShardsLike,omitempty"`
// This attribute specifies if the new format introduced in 3.7 is used for this
// collection.
UsesRevisionsAsDocumentIds bool `json:"usesRevisionsAsDocumentIds,omitempty"`
// The following attribute specifies if the new MerkleTree based sync protocol
// can be used on the collection.
SyncByRevision bool `json:"syncByRevision,omitempty"`
}
const (
// ReplicationFactorSatellite represents a satellite collection's replication factor
ReplicationFactorSatellite int = -1
)
// IsSatellite returns true if the collection is a satellite collection
func (p *CollectionProperties) IsSatellite() bool {
return p.ReplicationFactor == ReplicationFactorSatellite
}
// 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.
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 int `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"`
}
// CollectionStatus indicates the status of a collection.
type CollectionStatus int
const (
CollectionStatusNewBorn = CollectionStatus(1)
CollectionStatusUnloaded = CollectionStatus(2)
CollectionStatusLoaded = CollectionStatus(3)
CollectionStatusUnloading = CollectionStatus(4)
CollectionStatusDeleted = CollectionStatus(5)
CollectionStatusLoading = CollectionStatus(6)
)
// CollectionStatistics contains the number of documents and additional statistical information about a collection.
type CollectionStatistics struct {
//The number of documents currently present in the collection.
Count int64 `json:"count,omitempty"`
// The maximal size of a journal or datafile in bytes.
JournalSize int64 `json:"journalSize,omitempty"`
Figures struct {
DataFiles struct {
// The number of datafiles.
Count int64 `json:"count,omitempty"`
// The total filesize of datafiles (in bytes).
FileSize int64 `json:"fileSize,omitempty"`
} `json:"datafiles"`
// The number of markers in the write-ahead log for this collection that have not been transferred to journals or datafiles.
UncollectedLogfileEntries int64 `json:"uncollectedLogfileEntries,omitempty"`
// The number of references to documents in datafiles that JavaScript code currently holds. This information can be used for debugging compaction and unload issues.
DocumentReferences int64 `json:"documentReferences,omitempty"`
CompactionStatus struct {
// The action that was performed when the compaction was last run for the collection. This information can be used for debugging compaction issues.
Message string `json:"message,omitempty"`
// The point in time the compaction for the collection was last executed. This information can be used for debugging compaction issues.
Time time.Time `json:"time,omitempty"`
} `json:"compactionStatus"`
Compactors struct {
// The number of compactor files.
Count int64 `json:"count,omitempty"`
// The total filesize of all compactor files (in bytes).
FileSize int64 `json:"fileSize,omitempty"`
} `json:"compactors"`
Dead struct {
// The number of dead documents. This includes document versions that have been deleted or replaced by a newer version. Documents deleted or replaced that are contained the write-ahead log only are not reported in this figure.
Count int64 `json:"count,omitempty"`
// The total number of deletion markers. Deletion markers only contained in the write-ahead log are not reporting in this figure.
Deletion int64 `json:"deletion,omitempty"`
// The total size in bytes used by all dead documents.
Size int64 `json:"size,omitempty"`
} `json:"dead"`
Indexes struct {
// The total number of indexes defined for the collection, including the pre-defined indexes (e.g. primary index).
Count int64 `json:"count,omitempty"`
// The total memory allocated for indexes in bytes.
Size int64 `json:"size,omitempty"`
} `json:"indexes"`
ReadCache struct {
// The number of revisions of this collection stored in the document revisions cache.
Count int64 `json:"count,omitempty"`
// The memory used for storing the revisions of this collection in the document revisions cache (in bytes). This figure does not include the document data but only mappings from document revision ids to cache entry locations.
Size int64 `json:"size,omitempty"`
} `json:"readcache"`
// An optional string value that contains information about which object type is at the head of the collection's cleanup queue. This information can be used for debugging compaction and unload issues.
WaitingFor string `json:"waitingFor,omitempty"`
Alive struct {
// The number of currently active documents in all datafiles and journals of the collection. Documents that are contained in the write-ahead log only are not reported in this figure.
Count int64 `json:"count,omitempty"`
// The total size in bytes used by all active documents of the collection. Documents that are contained in the write-ahead log only are not reported in this figure.
Size int64 `json:"size,omitempty"`
} `json:"alive"`
// The tick of the last marker that was stored in a journal of the collection. This might be 0 if the collection does not yet have a journal.
LastTick int64 `json:"lastTick,omitempty"`
Journals struct {
// The number of journal files.
Count int64 `json:"count,omitempty"`
// The total filesize of all journal files (in bytes).
FileSize int64 `json:"fileSize,omitempty"`
} `json:"journals"`
Revisions struct {
// The number of revisions of this collection managed by the storage engine.
Count int64 `json:"count,omitempty"`
// 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"`
} `json:"figures"`
}