-
Notifications
You must be signed in to change notification settings - Fork 104
/
collection.go
134 lines (106 loc) · 3.55 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
package gocb
// Collection represents a single collection.
type Collection struct {
collectionName string
scope string
bucket *Bucket
timeoutsConfig TimeoutsConfig
transcoder Transcoder
retryStrategyWrapper *coreRetryStrategyWrapper
compressor *compressor
useMutationTokens bool
keyspace keyspace
opController opController
getKvProvider func() (kvProvider, error)
getKvBulkProvider func() (kvBulkProvider, error)
getQueryIndexProvider func() (queryIndexProvider, error)
}
func newCollection(scope *Scope, collectionName string) *Collection {
return &Collection{
collectionName: collectionName,
scope: scope.Name(),
bucket: scope.bucket,
timeoutsConfig: scope.timeoutsConfig,
transcoder: scope.transcoder,
retryStrategyWrapper: scope.retryStrategyWrapper,
compressor: scope.compressor,
useMutationTokens: scope.useMutationTokens,
keyspace: keyspace{
bucketName: scope.BucketName(),
scopeName: scope.Name(),
collectionName: collectionName,
},
opController: scope.opController,
getKvProvider: scope.getKvProvider,
getKvBulkProvider: scope.getKvBulkProvider,
getQueryIndexProvider: scope.getQueryIndexProvider,
}
}
func (c *Collection) name() string {
return c.collectionName
}
// ScopeName returns the name of the scope to which this collection belongs.
func (c *Collection) ScopeName() string {
return c.scope
}
// Bucket returns the bucket to which this collection belongs.
// UNCOMMITTED: This API may change in the future.
func (c *Collection) Bucket() *Bucket {
return c.bucket
}
// Name returns the name of the collection.
func (c *Collection) Name() string {
return c.collectionName
}
// QueryIndexes returns a CollectionQueryIndexManager for managing query indexes.
// UNCOMMITTED: This API may change in the future.
func (c *Collection) QueryIndexes() *CollectionQueryIndexManager {
return &CollectionQueryIndexManager{
controller: &providerController[queryIndexProvider]{
get: c.getQueryIndexProvider,
opController: c.opController,
meter: c.bucket.connectionManager.getMeter(),
service: serviceValueManagement,
keyspace: &c.keyspace,
},
c: c,
}
}
func (c *Collection) startKvOpTrace(operationName string, parentSpan RequestSpan, tracer *tracerWrapper, noAttributes bool) RequestSpan {
var span RequestSpan
if noAttributes {
span = tracer.createSpan(parentSpan, operationName, "")
} else {
span = tracer.createSpan(parentSpan, operationName, "kv")
span.SetAttribute(spanAttribOperationKey, operationName)
span.SetAttribute(spanAttribDBNameKey, c.bucket.Name())
span.SetAttribute(spanAttribDBCollectionNameKey, c.Name())
span.SetAttribute(spanAttribDBScopeNameKey, c.ScopeName())
}
return span
}
func (c *Collection) bucketName() string {
return c.bucket.Name()
}
func (c *Collection) isDefault() bool {
return (c.scope == "" || c.scope == "_default") && (c.collectionName == "" || c.collectionName == "_default")
}
func (c *Collection) kvController() *providerController[kvProvider] {
var meter *meterWrapper
if c.bucket.connectionManager != nil {
meter = c.bucket.connectionManager.getMeter()
}
return &providerController[kvProvider]{
get: c.getKvProvider,
opController: c.opController,
meter: meter,
service: serviceValueKV,
keyspace: &c.keyspace,
}
}
func (c *Collection) kvBulkController() *providerController[kvBulkProvider] {
return &providerController[kvBulkProvider]{
get: c.getKvBulkProvider,
opController: c.opController,
}
}