-
Notifications
You must be signed in to change notification settings - Fork 104
/
cluster_bucketmgr.go
271 lines (218 loc) · 10 KB
/
cluster_bucketmgr.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
package gocb
import (
"context"
"time"
)
// BucketType specifies the kind of bucket.
type BucketType string
const (
// CouchbaseBucketType indicates a Couchbase bucket type.
CouchbaseBucketType BucketType = "membase"
// MemcachedBucketType indicates a Memcached bucket type.
MemcachedBucketType BucketType = "memcached"
// EphemeralBucketType indicates an Ephemeral bucket type.
EphemeralBucketType BucketType = "ephemeral"
)
// ConflictResolutionType specifies the kind of conflict resolution to use for a bucket.
type ConflictResolutionType string
const (
// ConflictResolutionTypeTimestamp specifies to use timestamp conflict resolution on the bucket.
ConflictResolutionTypeTimestamp ConflictResolutionType = "lww"
// ConflictResolutionTypeSequenceNumber specifies to use sequence number conflict resolution on the bucket.
ConflictResolutionTypeSequenceNumber ConflictResolutionType = "seqno"
// ConflictResolutionTypeCustom specifies to use a custom bucket conflict resolution.
// In Couchbase Server 7.1, this feature is only available in "developer-preview" mode. See the UI XDCR settings
// for the custom conflict resolution properties.
// VOLATILE: This API is subject to change at any time.
ConflictResolutionTypeCustom ConflictResolutionType = "custom"
)
// EvictionPolicyType specifies the kind of eviction policy to use for a bucket.
type EvictionPolicyType string
const (
// EvictionPolicyTypeFull specifies to use full eviction for a couchbase bucket.
EvictionPolicyTypeFull EvictionPolicyType = "fullEviction"
// EvictionPolicyTypeValueOnly specifies to use value only eviction for a couchbase bucket.
EvictionPolicyTypeValueOnly EvictionPolicyType = "valueOnly"
// EvictionPolicyTypeNotRecentlyUsed specifies to use not recently used (nru) eviction for an ephemeral bucket.
EvictionPolicyTypeNotRecentlyUsed EvictionPolicyType = "nruEviction"
// EvictionPolicyTypeNoEviction specifies to use no eviction for an ephemeral bucket.
EvictionPolicyTypeNoEviction EvictionPolicyType = "noEviction"
)
// CompressionMode specifies the kind of compression to use for a bucket.
type CompressionMode string
const (
// CompressionModeOff specifies to use no compression for a bucket.
CompressionModeOff CompressionMode = "off"
// CompressionModePassive specifies to use passive compression for a bucket.
CompressionModePassive CompressionMode = "passive"
// CompressionModeActive specifies to use active compression for a bucket.
CompressionModeActive CompressionMode = "active"
)
// StorageBackend specifies the storage type to use for the bucket.
type StorageBackend string
const (
// StorageBackendCouchstore specifies to use the couchstore storage type.
StorageBackendCouchstore StorageBackend = "couchstore"
// StorageBackendMagma specifies to use the magma storage type. EE only.
StorageBackendMagma StorageBackend = "magma"
)
// HistoryRetentionCollectionDefault specifies whether history is enabled on the bucket.
// This API is UNCOMMITTED and may change in the future.
type HistoryRetentionCollectionDefault uint8
const (
// HistoryRetentionCollectionDefaultUnset specifies that history is not set and defaults to the default
// server value.
// This API is UNCOMMITTED and may change in the future.
HistoryRetentionCollectionDefaultUnset HistoryRetentionCollectionDefault = iota
// HistoryRetentionCollectionDefaultEnabled specifies that history is enabled.
// This API is UNCOMMITTED and may change in the future.
HistoryRetentionCollectionDefaultEnabled
// HistoryRetentionCollectionDefaultDisabled specifies that history is disabled.
// This API is UNCOMMITTED and may change in the future.
HistoryRetentionCollectionDefaultDisabled
)
// BucketSettings holds information about the settings for a bucket.
type BucketSettings struct {
Name string
FlushEnabled bool
ReplicaIndexDisabled bool // inverted so that zero value matches server default.
RAMQuotaMB uint64
NumReplicas uint32 // NOTE: If not set this will set 0 replicas.
BucketType BucketType // Defaults to CouchbaseBucketType.
EvictionPolicy EvictionPolicyType
// Deprecated: Use MaxExpiry instead.
MaxTTL time.Duration
MaxExpiry time.Duration
CompressionMode CompressionMode
MinimumDurabilityLevel DurabilityLevel
StorageBackend StorageBackend
// Specifies whether history retention should be enabled or disabled by default on collections in the bucket.
HistoryRetentionCollectionDefault HistoryRetentionCollectionDefault
HistoryRetentionBytes uint64
HistoryRetentionDuration time.Duration
}
// BucketManager provides methods for performing bucket management operations.
// See BucketManager for methods that allow creating and removing buckets themselves.
type BucketManager struct {
controller *providerController[bucketManagementProvider]
}
// GetBucketOptions is the set of options available to the bucket manager GetBucket operation.
type GetBucketOptions struct {
Timeout time.Duration
RetryStrategy RetryStrategy
ParentSpan RequestSpan
// Using a deadlined Context alongside a Timeout will cause the shorter of the two to cause cancellation, this
// also applies to global level timeouts.
// UNCOMMITTED: This API may change in the future.
Context context.Context
}
// GetBucket returns settings for a bucket on the cluster.
func (bm *BucketManager) GetBucket(bucketName string, opts *GetBucketOptions) (*BucketSettings, error) {
return autoOpControl(bm.controller, "manager_bucket_get_bucket", func(provider bucketManagementProvider) (*BucketSettings, error) {
if opts == nil {
opts = &GetBucketOptions{}
}
return provider.GetBucket(bucketName, opts)
})
}
// GetAllBucketsOptions is the set of options available to the bucket manager GetAll operation.
type GetAllBucketsOptions struct {
Timeout time.Duration
RetryStrategy RetryStrategy
ParentSpan RequestSpan
// Using a deadlined Context alongside a Timeout will cause the shorter of the two to cause cancellation, this
// also applies to global level timeouts.
// UNCOMMITTED: This API may change in the future.
Context context.Context
}
// GetAllBuckets returns a list of all active buckets on the cluster.
func (bm *BucketManager) GetAllBuckets(opts *GetAllBucketsOptions) (map[string]BucketSettings, error) {
return autoOpControl(bm.controller, "manager_bucket_get_all_buckets", func(provider bucketManagementProvider) (map[string]BucketSettings, error) {
if opts == nil {
opts = &GetAllBucketsOptions{}
}
return provider.GetAllBuckets(opts)
})
}
// CreateBucketSettings are the settings available when creating a bucket.
type CreateBucketSettings struct {
BucketSettings
ConflictResolutionType ConflictResolutionType
}
// CreateBucketOptions is the set of options available to the bucket manager CreateBucket operation.
type CreateBucketOptions struct {
Timeout time.Duration
RetryStrategy RetryStrategy
ParentSpan RequestSpan
// Using a deadlined Context alongside a Timeout will cause the shorter of the two to cause cancellation, this
// also applies to global level timeouts.
// UNCOMMITTED: This API may change in the future.
Context context.Context
}
// CreateBucket creates a bucket on the cluster.
func (bm *BucketManager) CreateBucket(settings CreateBucketSettings, opts *CreateBucketOptions) error {
return autoOpControlErrorOnly(bm.controller, "manager_bucket_create_bucket", func(provider bucketManagementProvider) error {
if opts == nil {
opts = &CreateBucketOptions{}
}
return provider.CreateBucket(settings, opts)
})
}
// UpdateBucketOptions is the set of options available to the bucket manager UpdateBucket operation.
type UpdateBucketOptions struct {
Timeout time.Duration
RetryStrategy RetryStrategy
ParentSpan RequestSpan
// Using a deadlined Context alongside a Timeout will cause the shorter of the two to cause cancellation, this
// also applies to global level timeouts.
// UNCOMMITTED: This API may change in the future.
Context context.Context
}
// UpdateBucket updates a bucket on the cluster.
func (bm *BucketManager) UpdateBucket(settings BucketSettings, opts *UpdateBucketOptions) error {
return autoOpControlErrorOnly(bm.controller, "manager_bucket_update_bucket", func(provider bucketManagementProvider) error {
if opts == nil {
opts = &UpdateBucketOptions{}
}
return provider.UpdateBucket(settings, opts)
})
}
// DropBucketOptions is the set of options available to the bucket manager DropBucket operation.
type DropBucketOptions struct {
Timeout time.Duration
RetryStrategy RetryStrategy
ParentSpan RequestSpan
// Using a deadlined Context alongside a Timeout will cause the shorter of the two to cause cancellation, this
// also applies to global level timeouts.
// UNCOMMITTED: This API may change in the future.
Context context.Context
}
// DropBucket will delete a bucket from the cluster by name.
func (bm *BucketManager) DropBucket(name string, opts *DropBucketOptions) error {
return autoOpControlErrorOnly(bm.controller, "manager_bucket_drop_bucket", func(provider bucketManagementProvider) error {
if opts == nil {
opts = &DropBucketOptions{}
}
return provider.DropBucket(name, opts)
})
}
// FlushBucketOptions is the set of options available to the bucket manager FlushBucket operation.
type FlushBucketOptions struct {
Timeout time.Duration
RetryStrategy RetryStrategy
ParentSpan RequestSpan
// Using a deadlined Context alongside a Timeout will cause the shorter of the two to cause cancellation, this
// also applies to global level timeouts.
// UNCOMMITTED: This API may change in the future.
Context context.Context
}
// FlushBucket will delete all the of the data from a bucket.
// Keep in mind that you must have flushing enabled in the buckets configuration.
func (bm *BucketManager) FlushBucket(name string, opts *FlushBucketOptions) error {
return autoOpControlErrorOnly(bm.controller, "manager_bucket_flush_bucket", func(provider bucketManagementProvider) error {
if opts == nil {
opts = &FlushBucketOptions{}
}
return provider.FlushBucket(name, opts)
})
}