-
Notifications
You must be signed in to change notification settings - Fork 104
/
bucket.go
317 lines (250 loc) · 7.45 KB
/
bucket.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
package gocb
import (
"time"
)
// Bucket represents a single bucket within a cluster.
type Bucket struct {
bucketName string
timeoutsConfig TimeoutsConfig
transcoder Transcoder
retryStrategyWrapper *coreRetryStrategyWrapper
compressor *compressor
useServerDurations bool
useMutationTokens bool
bootstrapError error
connectionManager connectionManager
getTransactions func() *Transactions
}
func newBucket(c *Cluster, bucketName string) *Bucket {
return &Bucket{
bucketName: bucketName,
timeoutsConfig: c.timeoutsConfig,
transcoder: c.transcoder,
retryStrategyWrapper: c.retryStrategyWrapper,
compressor: c.compressor,
useServerDurations: c.useServerDurations,
useMutationTokens: c.useMutationTokens,
connectionManager: c.connectionManager,
getTransactions: c.Transactions,
}
}
func (b *Bucket) setBootstrapError(err error) {
b.bootstrapError = err
}
func (b *Bucket) getKvProvider() (kvProvider, error) {
if b.bootstrapError != nil {
return nil, b.bootstrapError
}
agent, err := b.connectionManager.getKvProvider(b.bucketName)
if err != nil {
return nil, err
}
return agent, nil
}
func (b *Bucket) getKvCapabilitiesProvider() (kvCapabilityVerifier, error) {
if b.bootstrapError != nil {
return nil, b.bootstrapError
}
agent, err := b.connectionManager.getKvCapabilitiesProvider(b.bucketName)
if err != nil {
return nil, err
}
return agent, nil
}
func (b *Bucket) getKvBulkProvider() (kvBulkProvider, error) {
if b.bootstrapError != nil {
return nil, b.bootstrapError
}
agent, err := b.connectionManager.getKvBulkProvider(b.bucketName)
if err != nil {
return nil, err
}
return agent, nil
}
func (b *Bucket) getQueryProvider() (queryProvider, error) {
if b.bootstrapError != nil {
return nil, b.bootstrapError
}
agent, err := b.connectionManager.getQueryProvider()
if err != nil {
return nil, err
}
return agent, nil
}
func (b *Bucket) getQueryIndexProvider() (queryIndexProvider, error) {
if b.bootstrapError != nil {
return nil, b.bootstrapError
}
provider, err := b.connectionManager.getQueryIndexProvider()
if err != nil {
return nil, err
}
return provider, nil
}
func (b *Bucket) getSearchProvider() (searchProvider, error) {
if b.bootstrapError != nil {
return nil, b.bootstrapError
}
provider, err := b.connectionManager.getSearchProvider()
if err != nil {
return nil, err
}
return provider, nil
}
func (b *Bucket) getSearchIndexProvider() (searchIndexProvider, error) {
provider, err := b.connectionManager.getSearchIndexProvider()
if err != nil {
return nil, err
}
return provider, nil
}
func (b *Bucket) getAnalyticsProvider() (analyticsProvider, error) {
if b.bootstrapError != nil {
return nil, b.bootstrapError
}
agent, err := b.connectionManager.getAnalyticsProvider()
if err != nil {
return nil, err
}
return agent, nil
}
func (b *Bucket) getEventingManagementProvider() (eventingManagementProvider, error) {
if b.bootstrapError != nil {
return nil, b.bootstrapError
}
provider, err := b.connectionManager.getEventingManagementProvider()
if err != nil {
return nil, err
}
return provider, nil
}
func (b *Bucket) getViewProvider() (viewProvider, error) {
if b.bootstrapError != nil {
return nil, b.bootstrapError
}
provider, err := b.connectionManager.getViewProvider(b.Name())
if err != nil {
return nil, err
}
return provider, nil
}
func (b *Bucket) getViewIndexProvider() (viewIndexProvider, error) {
if b.bootstrapError != nil {
return nil, b.bootstrapError
}
provider, err := b.connectionManager.getViewIndexProvider(b.Name())
if err != nil {
return nil, err
}
return provider, nil
}
func (b *Bucket) getCollectionsManagementProvider() (collectionsManagementProvider, error) {
if b.bootstrapError != nil {
return nil, b.bootstrapError
}
provider, err := b.connectionManager.getCollectionsManagementProvider(b.Name())
if err != nil {
return nil, err
}
return provider, nil
}
func (b *Bucket) getDiagnosticsProvider() (diagnosticsProvider, error) {
provider, err := b.connectionManager.getDiagnosticsProvider(b.Name())
if err != nil {
return nil, err
}
return provider, nil
}
func (b *Bucket) getWaitUntilReadyProvider() (waitUntilReadyProvider, error) {
provider, err := b.connectionManager.getWaitUntilReadyProvider(b.Name())
if err != nil {
return nil, err
}
return provider, nil
}
func (b *Bucket) diagnosticsController() *providerController[diagnosticsProvider] {
return &providerController[diagnosticsProvider]{
get: b.getDiagnosticsProvider,
opController: b.connectionManager,
}
}
func (b *Bucket) viewController() *providerController[viewProvider] {
return &providerController[viewProvider]{
get: b.getViewProvider,
opController: b.connectionManager,
}
}
func (b *Bucket) waitUntilReadyController() *providerController[waitUntilReadyProvider] {
return &providerController[waitUntilReadyProvider]{
get: b.getWaitUntilReadyProvider,
opController: b.connectionManager,
}
}
// Name returns the name of the bucket.
func (b *Bucket) Name() string {
return b.bucketName
}
// Scope returns an instance of a Scope.
func (b *Bucket) Scope(scopeName string) *Scope {
return newScope(b, scopeName)
}
// DefaultScope returns an instance of the default scope.
func (b *Bucket) DefaultScope() *Scope {
return b.Scope("_default")
}
// Collection returns an instance of a collection from within the default scope.
func (b *Bucket) Collection(collectionName string) *Collection {
return b.DefaultScope().Collection(collectionName)
}
// DefaultCollection returns an instance of the default collection.
func (b *Bucket) DefaultCollection() *Collection {
return b.DefaultScope().Collection("_default")
}
// ViewIndexes returns a ViewIndexManager instance for managing views.
func (b *Bucket) ViewIndexes() *ViewIndexManager {
return &ViewIndexManager{
controller: &providerController[viewIndexProvider]{
get: b.getViewIndexProvider,
opController: b.connectionManager,
},
}
}
// CollectionsV2 provides functions for managing collections.
func (b *Bucket) CollectionsV2() *CollectionManagerV2 {
return &CollectionManagerV2{
controller: &providerController[collectionsManagementProvider]{
get: b.getCollectionsManagementProvider,
opController: b.connectionManager,
},
}
}
// Collections provides functions for managing collections.
// Deprecated: See CollectionsV2.
func (b *Bucket) Collections() *CollectionManager {
// TODO: return error for unsupported collections
return &CollectionManager{
managerV2: b.CollectionsV2(),
}
}
// WaitUntilReady will wait for the bucket object to be ready for use.
// At present this will wait until memd connections have been established with the server and are ready
// to be used before performing a ping against the specified services (except KeyValue) which also
// exist in the cluster map.
// If no services are specified then will wait until KeyValue is ready.
// Valid service types are: ServiceTypeKeyValue, ServiceTypeManagement, ServiceTypeQuery, ServiceTypeSearch,
// ServiceTypeAnalytics, ServiceTypeViews.
func (b *Bucket) WaitUntilReady(timeout time.Duration, opts *WaitUntilReadyOptions) error {
return autoOpControlErrorOnly(b.waitUntilReadyController(), func(provider waitUntilReadyProvider) error {
if opts == nil {
opts = &WaitUntilReadyOptions{}
}
if b.bootstrapError != nil {
return b.bootstrapError
}
return provider.WaitUntilReady(
opts.Context,
time.Now().Add(timeout),
opts,
)
})
}