couchbase 3.4.0-arm64-darwin-20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +202 -0
  3. data/README.md +154 -0
  4. data/ext/extconf.rb +0 -0
  5. data/lib/active_support/cache/couchbase_store.rb +339 -0
  6. data/lib/couchbase/analytics_options.rb +107 -0
  7. data/lib/couchbase/authenticator.rb +65 -0
  8. data/lib/couchbase/binary_collection.rb +128 -0
  9. data/lib/couchbase/binary_collection_options.rb +24 -0
  10. data/lib/couchbase/bucket.rb +144 -0
  11. data/lib/couchbase/cluster.rb +439 -0
  12. data/lib/couchbase/cluster_registry.rb +44 -0
  13. data/lib/couchbase/collection.rb +589 -0
  14. data/lib/couchbase/collection_options.rb +300 -0
  15. data/lib/couchbase/config_profiles.rb +55 -0
  16. data/lib/couchbase/configuration.rb +57 -0
  17. data/lib/couchbase/datastructures/couchbase_list.rb +160 -0
  18. data/lib/couchbase/datastructures/couchbase_map.rb +194 -0
  19. data/lib/couchbase/datastructures/couchbase_queue.rb +134 -0
  20. data/lib/couchbase/datastructures/couchbase_set.rb +128 -0
  21. data/lib/couchbase/datastructures.rb +24 -0
  22. data/lib/couchbase/diagnostics.rb +181 -0
  23. data/lib/couchbase/errors.rb +351 -0
  24. data/lib/couchbase/json_transcoder.rb +32 -0
  25. data/lib/couchbase/libcouchbase.bundle +0 -0
  26. data/lib/couchbase/logger.rb +85 -0
  27. data/lib/couchbase/management/analytics_index_manager.rb +1127 -0
  28. data/lib/couchbase/management/bucket_manager.rb +436 -0
  29. data/lib/couchbase/management/collection_manager.rb +321 -0
  30. data/lib/couchbase/management/query_index_manager.rb +520 -0
  31. data/lib/couchbase/management/search_index_manager.rb +408 -0
  32. data/lib/couchbase/management/user_manager.rb +468 -0
  33. data/lib/couchbase/management/view_index_manager.rb +237 -0
  34. data/lib/couchbase/management.rb +27 -0
  35. data/lib/couchbase/mutation_state.rb +63 -0
  36. data/lib/couchbase/options.rb +2580 -0
  37. data/lib/couchbase/query_options.rb +120 -0
  38. data/lib/couchbase/railtie.rb +45 -0
  39. data/lib/couchbase/scope.rb +232 -0
  40. data/lib/couchbase/search_options.rb +1570 -0
  41. data/lib/couchbase/subdoc.rb +290 -0
  42. data/lib/couchbase/utils/generic_logger_adapter.rb +38 -0
  43. data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
  44. data/lib/couchbase/utils/time.rb +56 -0
  45. data/lib/couchbase/utils.rb +21 -0
  46. data/lib/couchbase/version.rb +23 -0
  47. data/lib/couchbase/view_options.rb +65 -0
  48. data/lib/couchbase.rb +20 -0
  49. data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
  50. metadata +101 -0
@@ -0,0 +1,436 @@
1
+ # Copyright 2020-2021 Couchbase, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "rubygems/deprecate"
16
+
17
+ require "couchbase/errors"
18
+ require "couchbase/options"
19
+
20
+ module Couchbase
21
+ module Management
22
+ module Options
23
+ module Bucket
24
+ # Options for {BucketManager#create_bucket}
25
+ class CreateBucket < ::Couchbase::Options::Base
26
+ # Creates an instance of options for {BucketManager#create_bucket}
27
+ #
28
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
29
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
30
+ # @param [Hash, nil] client_context the client context data, if set
31
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
32
+ #
33
+ # @yieldparam [CreateBucket] self
34
+ def initialize(timeout: nil,
35
+ retry_strategy: nil,
36
+ client_context: nil,
37
+ parent_span: nil)
38
+ super
39
+ yield self if block_given?
40
+ end
41
+ end
42
+
43
+ # Options for {BucketManager#update_bucket}
44
+ class UpdateBucket < ::Couchbase::Options::Base
45
+ # Creates an instance of options for {BucketManager#update_bucket}
46
+ #
47
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
48
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
49
+ # @param [Hash, nil] client_context the client context data, if set
50
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
51
+ #
52
+ # @yieldparam [UpdateBucket] self
53
+ def initialize(timeout: nil,
54
+ retry_strategy: nil,
55
+ client_context: nil,
56
+ parent_span: nil)
57
+ super
58
+ yield self if block_given?
59
+ end
60
+ end
61
+
62
+ # Options for {BucketManager#drop_bucket}
63
+ class DropBucket < ::Couchbase::Options::Base
64
+ # Creates an instance of options for {BucketManager#drop_bucket}
65
+ #
66
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
67
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
68
+ # @param [Hash, nil] client_context the client context data, if set
69
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
70
+ #
71
+ # @yieldparam [DropBucket] self
72
+ def initialize(timeout: nil,
73
+ retry_strategy: nil,
74
+ client_context: nil,
75
+ parent_span: nil)
76
+ super
77
+ yield self if block_given?
78
+ end
79
+ end
80
+
81
+ # Options for {BucketManager#get_bucket}
82
+ class GetBucket < ::Couchbase::Options::Base
83
+ # Creates an instance of options for {BucketManager#get_bucket}
84
+ #
85
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
86
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
87
+ # @param [Hash, nil] client_context the client context data, if set
88
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
89
+ #
90
+ # @yieldparam [GetBucket] self
91
+ def initialize(timeout: nil,
92
+ retry_strategy: nil,
93
+ client_context: nil,
94
+ parent_span: nil)
95
+ super
96
+ yield self if block_given?
97
+ end
98
+ end
99
+
100
+ # Options for {BucketManager#get_all_buckets}
101
+ class GetAllBuckets < ::Couchbase::Options::Base
102
+ # Creates an instance of options for {BucketManager#get_all_buckets}
103
+ #
104
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
105
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
106
+ # @param [Hash, nil] client_context the client context data, if set
107
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
108
+ #
109
+ # @yieldparam [GetAllBuckets] self
110
+ def initialize(timeout: nil,
111
+ retry_strategy: nil,
112
+ client_context: nil,
113
+ parent_span: nil)
114
+ super
115
+ yield self if block_given?
116
+ end
117
+ end
118
+
119
+ # Options for {BucketManager#flush_bucket}
120
+ class FlushBucket < ::Couchbase::Options::Base
121
+ # Creates an instance of options for {BucketManager#flush_bucket}
122
+ #
123
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
124
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
125
+ # @param [Hash, nil] client_context the client context data, if set
126
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
127
+ #
128
+ # @yieldparam [FlushBucket] self
129
+ def initialize(timeout: nil,
130
+ retry_strategy: nil,
131
+ client_context: nil,
132
+ parent_span: nil)
133
+ super
134
+ yield self if block_given?
135
+ end
136
+ end
137
+
138
+ # rubocop:disable Naming/MethodName constructor shortcuts
139
+ module_function
140
+
141
+ # Construct {CreateBucket} options for {BucketManager#create_bucket}
142
+ #
143
+ # @return [CreateBucket]
144
+ def CreateBucket(**args)
145
+ CreateBucket.new(**args)
146
+ end
147
+
148
+ # Construct {UpdateBucket} options for {BucketManager#update_bucket}
149
+ #
150
+ # @return [UpdateBucket]
151
+ def UpdateBucket(**args)
152
+ UpdateBucket.new(**args)
153
+ end
154
+
155
+ # Construct {DropBucket} options for {BucketManager#drop_bucket}
156
+ #
157
+ # @return [DropBucket]
158
+ def DropBucket(**args)
159
+ DropBucket.new(**args)
160
+ end
161
+
162
+ # Construct {GetBucket} options for {BucketManager#get_bucket}
163
+ #
164
+ # @return [GetBucket]
165
+ def GetBucket(**args)
166
+ GetBucket.new(**args)
167
+ end
168
+
169
+ # Construct {GetAllBuckets} options for {BucketManager#get_all_buckets}
170
+ #
171
+ # @return [GetAllBuckets]
172
+ def GetAllBuckets(**args)
173
+ GetAllBuckets.new(**args)
174
+ end
175
+
176
+ # Construct {FlushBucket} options for {BucketManager#flush_bucket}
177
+ #
178
+ # @return [FlushBucket]
179
+ def FlushBucket(**args)
180
+ FlushBucket.new(**args)
181
+ end
182
+
183
+ # rubocop:enable Naming/MethodName
184
+ end
185
+ end
186
+
187
+ class BucketManager
188
+ alias inspect to_s
189
+
190
+ # @param [Couchbase::Backend] backend
191
+ def initialize(backend)
192
+ @backend = backend
193
+ end
194
+
195
+ # Creates new bucket
196
+ #
197
+ # @param [BucketSettings] settings bucket settings
198
+ # @param [Options::Bucket::CreateBucket] options
199
+ #
200
+ # @return void
201
+ #
202
+ # @raise [ArgumentError]
203
+ # @raise [Error::BucketExists]
204
+ def create_bucket(settings, options = Options::Bucket::CreateBucket.new)
205
+ @backend.bucket_create(
206
+ {
207
+
208
+ name: settings.name,
209
+ flush_enabled: settings.flush_enabled,
210
+ ram_quota_mb: settings.ram_quota_mb,
211
+ num_replicas: settings.num_replicas,
212
+ replica_indexes: settings.replica_indexes,
213
+ bucket_type: settings.bucket_type,
214
+ ejection_policy: settings.ejection_policy,
215
+ max_expiry: settings.max_expiry,
216
+ compression_mode: settings.compression_mode,
217
+ minimum_durability_level: settings.minimum_durability_level,
218
+ conflict_resolution_type: settings.conflict_resolution_type,
219
+ storage_backend: settings.storage_backend,
220
+ }, options.to_backend
221
+ )
222
+ end
223
+
224
+ # Updates the bucket settings
225
+ #
226
+ # @param [BucketSettings] settings bucket settings
227
+ # @param [Options::Bucket::UpdateBucket] options
228
+ #
229
+ # @return void
230
+ #
231
+ # @raise [ArgumentError]
232
+ # @raise [Error::BucketNotFound]
233
+ def update_bucket(settings, options = Options::Bucket::UpdateBucket.new)
234
+ @backend.bucket_update(
235
+ {
236
+ name: settings.name,
237
+ flush_enabled: settings.flush_enabled,
238
+ ram_quota_mb: settings.ram_quota_mb,
239
+ num_replicas: settings.num_replicas,
240
+ replica_indexes: settings.replica_indexes,
241
+ bucket_type: settings.bucket_type,
242
+ ejection_policy: settings.ejection_policy,
243
+ max_expiry: settings.max_expiry,
244
+ compression_mode: settings.compression_mode,
245
+ minimum_durability_level: settings.minimum_durability_level,
246
+ storage_backend: settings.storage_backend,
247
+ }, options.to_backend
248
+ )
249
+ end
250
+
251
+ # Removes a bucket
252
+ #
253
+ # @param [String] bucket_name name of the bucket
254
+ # @param [Options::Bucket::DropBucket] options
255
+ #
256
+ # @return void
257
+ #
258
+ # @raise [ArgumentError]
259
+ # @raise [Error::BucketNotFound]
260
+ def drop_bucket(bucket_name, options = Options::Bucket::DropBucket.new)
261
+ @backend.bucket_drop(bucket_name, options.to_backend)
262
+ end
263
+
264
+ # Fetch settings of the bucket
265
+ #
266
+ # @param [String] bucket_name name of the bucket
267
+ # @param [Options::Bucket::GetBucket] options
268
+ #
269
+ # @return [BucketSettings]
270
+ #
271
+ # @raise [ArgumentError]
272
+ # @raise [Error::BucketNotFound]
273
+ def get_bucket(bucket_name, options = Options::Bucket::GetBucket.new)
274
+ extract_bucket_settings(@backend.bucket_get(bucket_name, options.to_backend))
275
+ end
276
+
277
+ # Get settings for all buckets
278
+ #
279
+ # @param [Options::Bucket::GetAllBuckets] options
280
+ # @return [Array<BucketSettings>]
281
+ def get_all_buckets(options = Options::Bucket::GetAllBuckets.new)
282
+ @backend.bucket_get_all(options.to_backend)
283
+ .map { |entry| extract_bucket_settings(entry) }
284
+ end
285
+
286
+ # @param [String] bucket_name name of the bucket
287
+ # @param [Options::Bucket::FlushBucket] options
288
+ #
289
+ # @return void
290
+ #
291
+ # @raise [ArgumentError]
292
+ # @raise [Error::BucketNotFound]
293
+ # @raise [Error::BucketNotFlushable]
294
+ def flush_bucket(bucket_name, options = Options::Bucket::FlushBucket.new)
295
+ @backend.bucket_flush(bucket_name, options.to_backend)
296
+ end
297
+
298
+ # @api private
299
+ # TODO: deprecate after 3.2
300
+ CreateBucketOptions = ::Couchbase::Management::Options::Bucket::CreateBucket
301
+
302
+ # @api private
303
+ # TODO: deprecate after 3.2
304
+ UpdateBucketOptions = ::Couchbase::Management::Options::Bucket::UpdateBucket
305
+
306
+ # @api private
307
+ # TODO: deprecate after 3.2
308
+ DropBucketOptions = ::Couchbase::Management::Options::Bucket::DropBucket
309
+
310
+ # @api private
311
+ # TODO: deprecate after 3.2
312
+ GetBucketOptions = ::Couchbase::Management::Options::Bucket::GetBucket
313
+
314
+ # @api private
315
+ # TODO: deprecate after 3.2
316
+ GetAllBucketsOptions = ::Couchbase::Management::Options::Bucket::GetAllBuckets
317
+
318
+ # @api private
319
+ # TODO: deprecate after 3.2
320
+ FlushBucketOptions = ::Couchbase::Management::Options::Bucket::FlushBucket
321
+
322
+ private
323
+
324
+ def extract_bucket_settings(entry)
325
+ BucketSettings.new do |bucket|
326
+ bucket.name = entry[:name]
327
+ bucket.flush_enabled = entry[:flush_enabled]
328
+ bucket.ram_quota_mb = entry[:ram_quota_mb]
329
+ bucket.num_replicas = entry[:num_replicas]
330
+ bucket.replica_indexes = entry[:replica_indexes]
331
+ bucket.bucket_type = entry[:bucket_type]
332
+ bucket.max_expiry = entry[:max_expiry]
333
+ bucket.eviction_policy = entry[:eviction_policy]
334
+ bucket.minimum_durability_level = entry[:minimum_durability_level]
335
+ bucket.compression_mode = entry[:compression_mode]
336
+ bucket.instance_variable_set(:@healthy, entry[:nodes].all? { |node| node[:status] == "healthy" })
337
+ end
338
+ end
339
+ end
340
+
341
+ class BucketSettings
342
+ extend Gem::Deprecate
343
+
344
+ # @return [String] name of the bucket
345
+ attr_accessor :name
346
+
347
+ # @return [Boolean] whether or not flush should be enabled on the bucket. Defaults to false.
348
+ attr_accessor :flush_enabled
349
+
350
+ # @return [Integer] RAM quota in megabytes for the bucket
351
+ attr_accessor :ram_quota_mb
352
+
353
+ # @return [Integer] number of replicas for documents
354
+ attr_accessor :num_replicas
355
+
356
+ # @return [Boolean] whether replica indexes should be enabled for the bucket
357
+ attr_accessor :replica_indexes
358
+
359
+ # @return [:couchbase, :memcached, :ephemeral] the type of the bucket. Defaults to +:couchbase+
360
+ attr_accessor :bucket_type
361
+
362
+ # @return [nil, :couchstore, :magma] the type of the storage backend of the bucket
363
+ attr_accessor :storage_backend
364
+
365
+ # Eviction policy to use
366
+ #
367
+ # :full:: During ejection, only the value will be ejected (key and metadata will remain in memory). Value Ejection
368
+ # needs more system memory, but provides better performance than Full Ejection. This value is only valid for
369
+ # buckets of type +:couchbase+.
370
+ #
371
+ # :value_only:: During ejection, everything (including key, metadata, and value) will be ejected. Full Ejection
372
+ # reduces the memory overhead requirement, at the cost of performance. This value is only valid for
373
+ # buckets of type +:couchbase+.
374
+ #
375
+ # :no_eviction:: Couchbase Server keeps all data until explicitly deleted, but will reject any new data if you
376
+ # reach the quota (dedicated memory) you set for your bucket. This value is only valid for buckets
377
+ # of type +:ephemeral+.
378
+ #
379
+ # :not_recently_used:: When the memory quota is reached, Couchbase Server ejects data that has not been used
380
+ # recently. This value is only valid for buckets of type +:ephemeral+.
381
+ #
382
+ # @return [:full, :value_only, :no_eviction, :not_recently_used] the eviction policy to use
383
+ attr_accessor :eviction_policy
384
+
385
+ # @return [Integer] value of TTL (expiration) in seconds for new documents created without expiration
386
+ attr_accessor :max_expiry
387
+
388
+ # @return [:off, :passive, :active] the compression mode to use
389
+ attr_accessor :compression_mode
390
+
391
+ # @return [:timestamp, :sequence_number, :custom] conflict resolution policy
392
+ attr_accessor :conflict_resolution_type
393
+
394
+ # @return [nil, :none, :majority, :majority_and_persist_to_active, :persist_to_majority] the minimum durability level
395
+ attr_accessor :minimum_durability_level
396
+
397
+ # @api private
398
+ # @return [Boolean] false if status of the bucket is not healthy
399
+ def healthy?
400
+ @healthy
401
+ end
402
+
403
+ # @deprecated Use {#eviction_policy} instead
404
+ def ejection_policy
405
+ @eviction_policy
406
+ end
407
+
408
+ deprecate :ejection_policy, :eviction_policy, 2021, 1
409
+
410
+ # @deprecated Use {#eviction_policy=} instead
411
+ def ejection_policy=(val)
412
+ @eviction_policy = val
413
+ end
414
+
415
+ deprecate :ejection_policy=, :eviction_policy=, 2021, 1
416
+
417
+ # @yieldparam [BucketSettings] self
418
+ def initialize
419
+ @bucket_type = :couchbase
420
+ @name = nil
421
+ @minimum_durability_level = nil
422
+ @healthy = true
423
+ @flush_enabled = false
424
+ @ram_quota_mb = 100
425
+ @num_replicas = 1
426
+ @replica_indexes = false
427
+ @max_expiry = 0
428
+ @compression_mode = :passive
429
+ @conflict_resolution_type = :sequence_number
430
+ @eviction_policy = :value_only
431
+ @storage_backend = nil
432
+ yield self if block_given?
433
+ end
434
+ end
435
+ end
436
+ end