-
Notifications
You must be signed in to change notification settings - Fork 104
/
constants.go
420 lines (328 loc) · 14.2 KB
/
constants.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
package gocb
import (
"fmt"
"time"
"github.com/couchbase/goprotostellar/genproto/kv_v1"
gocbcore "github.com/couchbase/gocbcore/v10"
"github.com/couchbase/gocbcore/v10/memd"
)
const (
goCbVersionStr = "v2.9.2"
durabilityTimeoutFloor = 1500 * time.Millisecond
)
// QueryIndexType provides information on the type of indexer used for an index.
type QueryIndexType string
const (
// QueryIndexTypeGsi indicates that GSI was used to build the index.
QueryIndexTypeGsi QueryIndexType = "gsi"
// QueryIndexTypeView indicates that views were used to build the index.
QueryIndexTypeView QueryIndexType = "views"
)
// QueryStatus provides information about the current status of a query.
type QueryStatus string
const (
// QueryStatusRunning indicates the query is still running
QueryStatusRunning QueryStatus = "running"
// QueryStatusSuccess indicates the query was successful.
QueryStatusSuccess QueryStatus = "success"
// QueryStatusErrors indicates a query completed with errors.
QueryStatusErrors QueryStatus = "errors"
// QueryStatusCompleted indicates a query has completed.
QueryStatusCompleted QueryStatus = "completed"
// QueryStatusStopped indicates a query has been stopped.
QueryStatusStopped QueryStatus = "stopped"
// QueryStatusTimeout indicates a query timed out.
QueryStatusTimeout QueryStatus = "timeout"
// QueryStatusClosed indicates that a query was closed.
QueryStatusClosed QueryStatus = "closed"
// QueryStatusFatal indicates that a query ended with a fatal error.
QueryStatusFatal QueryStatus = "fatal"
// QueryStatusAborted indicates that a query was aborted.
QueryStatusAborted QueryStatus = "aborted"
// QueryStatusUnknown indicates that the query status is unknown.
QueryStatusUnknown QueryStatus = "unknown"
)
// ServiceType specifies a particular Couchbase service type.
type ServiceType gocbcore.ServiceType
const (
// ServiceTypeManagement represents a management service.
ServiceTypeManagement ServiceType = ServiceType(gocbcore.MgmtService)
// ServiceTypeKeyValue represents a memcached service.
ServiceTypeKeyValue ServiceType = ServiceType(gocbcore.MemdService)
// ServiceTypeViews represents a views service.
ServiceTypeViews ServiceType = ServiceType(gocbcore.CapiService)
// ServiceTypeQuery represents a query service.
ServiceTypeQuery ServiceType = ServiceType(gocbcore.N1qlService)
// ServiceTypeSearch represents a full-text-search service.
ServiceTypeSearch ServiceType = ServiceType(gocbcore.FtsService)
// ServiceTypeAnalytics represents an analytics service.
ServiceTypeAnalytics ServiceType = ServiceType(gocbcore.CbasService)
// ServiceTypeEventing represents an eventing service.
ServiceTypeEventing ServiceType = ServiceType(gocbcore.EventingService)
)
// QueryProfileMode specifies the profiling mode to use during a query.
type QueryProfileMode string
const (
// QueryProfileModeNone disables query profiling
QueryProfileModeNone QueryProfileMode = "off"
// QueryProfileModePhases includes phase profiling information in the query response
QueryProfileModePhases QueryProfileMode = "phases"
// QueryProfileModeTimings includes timing profiling information in the query response
QueryProfileModeTimings QueryProfileMode = "timings"
)
// SubdocFlag provides special handling flags for sub-document operations
type SubdocFlag memd.SubdocFlag
const (
// SubdocFlagNone indicates no special behaviours
SubdocFlagNone SubdocFlag = SubdocFlag(memd.SubdocFlagNone)
// SubdocFlagCreatePath indicates you wish to recursively create the tree of paths
// if it does not already exist within the document.
SubdocFlagCreatePath SubdocFlag = SubdocFlag(memd.SubdocFlagMkDirP)
// SubdocFlagXattr indicates your path refers to an extended attribute rather than the document.
SubdocFlagXattr SubdocFlag = SubdocFlag(memd.SubdocFlagXattrPath)
// SubdocFlagUseMacros indicates that you wish macro substitution to occur on the value
SubdocFlagUseMacros SubdocFlag = SubdocFlag(memd.SubdocFlagExpandMacros)
)
// SubdocDocFlag specifies document-level flags for a sub-document operation.
type SubdocDocFlag memd.SubdocDocFlag
const (
// SubdocDocFlagNone indicates no special behaviours
SubdocDocFlagNone SubdocDocFlag = SubdocDocFlag(memd.SubdocDocFlagNone)
// SubdocDocFlagMkDoc indicates that the document should be created if it does not already exist.
SubdocDocFlagMkDoc SubdocDocFlag = SubdocDocFlag(memd.SubdocDocFlagMkDoc)
// SubdocDocFlagAddDoc indices that the document should be created only if it does not already exist.
SubdocDocFlagAddDoc SubdocDocFlag = SubdocDocFlag(memd.SubdocDocFlagAddDoc)
// SubdocDocFlagAccessDeleted indicates that you wish to receive soft-deleted documents.
// Internal: This should never be used and is not supported.
SubdocDocFlagAccessDeleted SubdocDocFlag = SubdocDocFlag(memd.SubdocDocFlagAccessDeleted)
// SubdocDocFlagCreateAsDeleted indicates that you wish to create a document in deleted state.
// Internal: This should never be used and is not supported.
SubdocDocFlagCreateAsDeleted SubdocDocFlag = SubdocDocFlag(memd.SubdocDocFlagCreateAsDeleted)
)
// DurabilityLevel specifies the level of synchronous replication to use.
type DurabilityLevel uint8
const (
// DurabilityLevelUnknown specifies that the durability level is not set and will default to the default durability level.
DurabilityLevelUnknown DurabilityLevel = iota
// DurabilityLevelNone specifies that no durability level should be applied.
DurabilityLevelNone
// DurabilityLevelMajority specifies that a mutation must be replicated (held in memory) to a majority of nodes.
DurabilityLevelMajority
// DurabilityLevelMajorityAndPersistOnMaster specifies that a mutation must be replicated (held in memory) to a
// majority of nodes and also persisted (written to disk) on the active node.
DurabilityLevelMajorityAndPersistOnMaster
// DurabilityLevelPersistToMajority specifies that a mutation must be persisted (written to disk) to a majority
// of nodes.
DurabilityLevelPersistToMajority
)
func (dl DurabilityLevel) toManagementAPI() (string, error) {
switch dl {
case DurabilityLevelNone:
return "none", nil
case DurabilityLevelMajority:
return "majority", nil
case DurabilityLevelMajorityAndPersistOnMaster:
return "majorityAndPersistActive", nil
case DurabilityLevelPersistToMajority:
return "persistToMajority", nil
default:
return "", invalidArgumentsError{
message: fmt.Sprintf("unknown durability level: %d", dl),
}
}
}
func (dl DurabilityLevel) toMemd() (memd.DurabilityLevel, error) {
switch dl {
case DurabilityLevelNone:
return memd.DurabilityLevel(0), nil
case DurabilityLevelMajority:
return memd.DurabilityLevelMajority, nil
case DurabilityLevelMajorityAndPersistOnMaster:
return memd.DurabilityLevelMajorityAndPersistOnMaster, nil
case DurabilityLevelPersistToMajority:
return memd.DurabilityLevelPersistToMajority, nil
case DurabilityLevelUnknown:
return 0, makeInvalidArgumentsError("unexpected unset durability level")
default:
return 0, makeInvalidArgumentsError("unexpected durability level")
}
}
func (dl DurabilityLevel) toProtostellar() (*kv_v1.DurabilityLevel, error) {
var level kv_v1.DurabilityLevel
switch dl {
case DurabilityLevelNone:
return nil, nil
case DurabilityLevelMajority:
level = kv_v1.DurabilityLevel_DURABILITY_LEVEL_MAJORITY
case DurabilityLevelMajorityAndPersistOnMaster:
level = kv_v1.DurabilityLevel_DURABILITY_LEVEL_MAJORITY_AND_PERSIST_TO_ACTIVE
case DurabilityLevelPersistToMajority:
level = kv_v1.DurabilityLevel_DURABILITY_LEVEL_PERSIST_TO_MAJORITY
case DurabilityLevelUnknown:
return nil, makeInvalidArgumentsError("unexpected unset durability level")
default:
return nil, makeInvalidArgumentsError("unexpected durability level")
}
return &level, nil
}
func durabilityLevelFromManagementAPI(level string) DurabilityLevel {
switch level {
case "majority":
return DurabilityLevelMajority
case "majorityAndPersistActive":
return DurabilityLevelMajorityAndPersistOnMaster
case "persistToMajority":
return DurabilityLevelPersistToMajority
default:
return DurabilityLevelNone
}
}
// MutationMacro can be supplied to MutateIn operations to perform ExpandMacros operations.
type MutationMacro string
const (
// MutationMacroCAS can be used to tell the server to use the CAS macro.
MutationMacroCAS MutationMacro = "\"${Mutation.CAS}\""
// MutationMacroSeqNo can be used to tell the server to use the seqno macro.
MutationMacroSeqNo MutationMacro = "\"${Mutation.seqno}\""
// MutationMacroValueCRC32c can be used to tell the server to use the value_crc32c macro.
MutationMacroValueCRC32c MutationMacro = "\"${Mutation.value_crc32c}\""
)
// ClusterState specifies the current state of the cluster
type ClusterState uint
const (
// ClusterStateOnline indicates that all nodes are online and reachable.
ClusterStateOnline ClusterState = iota + 1
// ClusterStateDegraded indicates that all services will function, but possibly not optimally.
ClusterStateDegraded
// ClusterStateOffline indicates that no nodes were reachable.
ClusterStateOffline
)
// EndpointState specifies the current state of an endpoint.
type EndpointState uint
const (
// EndpointStateDisconnected indicates the endpoint socket is unreachable.
EndpointStateDisconnected EndpointState = iota + 1
// EndpointStateConnecting indicates the endpoint socket is connecting.
EndpointStateConnecting
// EndpointStateConnected indicates the endpoint socket is connected and ready.
EndpointStateConnected
// EndpointStateDisconnecting indicates the endpoint socket is disconnecting.
EndpointStateDisconnecting
)
// PingState specifies the result of the ping operation
type PingState uint
const (
// PingStateOk indicates that the ping operation was successful.
PingStateOk PingState = iota + 1
// PingStateTimeout indicates that the ping operation timed out.
PingStateTimeout
// PingStateError indicates that the ping operation failed.
PingStateError
)
// SaslMechanism represents a type of auth that can be performed.
type SaslMechanism string
const (
// PlainSaslMechanism represents that PLAIN auth should be performed.
PlainSaslMechanism SaslMechanism = SaslMechanism(gocbcore.PlainAuthMechanism)
// ScramSha1SaslMechanism represents that SCRAM SHA1 auth should be performed.
ScramSha1SaslMechanism SaslMechanism = SaslMechanism(gocbcore.ScramSha1AuthMechanism)
// ScramSha256SaslMechanism represents that SCRAM SHA256 auth should be performed.
ScramSha256SaslMechanism SaslMechanism = SaslMechanism(gocbcore.ScramSha256AuthMechanism)
// ScramSha512SaslMechanism represents that SCRAM SHA512 auth should be performed.
ScramSha512SaslMechanism SaslMechanism = SaslMechanism(gocbcore.ScramSha512AuthMechanism)
)
// Capability represents a server capability.
// Internal: This should never be used and is not supported.
type Capability uint32
const (
CapabilityDurableWrites Capability = iota + 1
CapabilityCreateAsDeleted
CapabilityReplaceBodyWithXattr
)
// CapabilityStatus represents a status for a server capability.
// Internal: This should never be used and is not supported.
type CapabilityStatus uint32
const (
CapabilityStatusUnknown CapabilityStatus = CapabilityStatus(gocbcore.CapabilityStatusUnknown)
CapabilityStatusSupported CapabilityStatus = CapabilityStatus(gocbcore.CapabilityStatusSupported)
CapabilityStatusUnsupported CapabilityStatus = CapabilityStatus(gocbcore.CapabilityStatusUnsupported)
)
const (
spanNameDispatchToServer = "dispatch_to_server"
spanNameRequestEncoding = "request_encoding"
spanAttribDBSystemKey = "db.system"
spanAttribDBSystemValue = "couchbase"
spanAttribOperationIDKey = "db.couchbase.operation_id"
spanAttribOperationKey = "db.operation"
spanAttribRetries = "db.couchbase.retries"
spanAttribLocalIDKey = "db.couchbase.local_id"
spanAttribNetTransport = "net.transport"
spanAttribNetHostNameKey = "net.host.name"
spanAttribNetHostPortKey = "net.host.port"
spanAttribNetPeerNameKey = "net.peer.name"
spanAttribNetPeerPortKey = "net.peer.port"
spanAttribServerDurationKey = "db.couchbase.server_duration"
spanAttribServiceKey = "db.couchbase.service"
spanAttribDBNameKey = "db.name"
spanAttribDBCollectionNameKey = "db.couchbase.collection"
spanAttribDBScopeNameKey = "db.couchbase.scope"
spanAttribDBDurability = "db.couchbase.durability"
spanAttribNumRetries = "db.couchbase.retries"
spanAttribClusterUUIDKey = "db.couchbase.cluster_uuid"
spanAttribClusterNameKey = "db.couchbase.cluster_name"
meterNameCBOperations = "db.couchbase.operations"
meterAttribServiceKey = "db.couchbase.service"
meterAttribOperationKey = "db.operation"
meterAttribBucketNameKey = "db.name"
meterAttribScopeNameKey = "db.couchbase.scope"
meterAttribCollectionNameKey = "db.couchbase.collection"
meterAttribOutcomeKey = "outcome"
meterAttribClusterUUIDKey = "db.couchbase.cluster_uuid"
meterAttribClusterNameKey = "db.couchbase.cluster_name"
serviceValueKV = "kv"
serviceValueQuery = "query"
serviceValueAnalytics = "analytics"
serviceValueSearch = "search"
serviceValueViews = "views"
serviceValueManagement = "management"
serviceValueEventing = "eventing"
)
type AnalyticsLinkType string
const (
AnalyticsLinkTypeS3External AnalyticsLinkType = "s3"
AnalyticsLinkTypeAzureExternal AnalyticsLinkType = "azureblob"
AnalyticsLinkTypeCouchbaseRemote AnalyticsLinkType = "couchbase"
)
type AnalyticsEncryptionLevel uint8
const (
AnalyticsEncryptionLevelNone AnalyticsEncryptionLevel = iota
AnalyticsEncryptionLevelHalf
AnalyticsEncryptionLevelFull
)
func (ael AnalyticsEncryptionLevel) String() string {
switch ael {
case AnalyticsEncryptionLevelNone:
return "none"
case AnalyticsEncryptionLevelHalf:
return "half"
case AnalyticsEncryptionLevelFull:
return "full"
}
return ""
}
func analyticsEncryptionLevelFromString(level string) AnalyticsEncryptionLevel {
switch level {
case "none":
return AnalyticsEncryptionLevelNone
case "half":
return AnalyticsEncryptionLevelHalf
case "full":
return AnalyticsEncryptionLevelFull
}
return AnalyticsEncryptionLevelNone
}
type ReadPreference uint8
const (
ReadPreferenceNone ReadPreference = iota + 1
ReadPreferenceSelectedServerGroup
)