couchbase 3.4.3 → 3.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/couchbase/CMakeLists.txt +22 -1
  4. data/ext/couchbase/core/bucket.cxx +183 -152
  5. data/ext/couchbase/core/bucket.hxx +17 -4
  6. data/ext/couchbase/core/cluster.hxx +41 -13
  7. data/ext/couchbase/core/cluster_options.hxx +3 -0
  8. data/ext/couchbase/core/crud_component.cxx +51 -22
  9. data/ext/couchbase/core/error_context/key_value.cxx +2 -1
  10. data/ext/couchbase/core/error_context/key_value.hxx +10 -12
  11. data/ext/couchbase/core/impl/build_deferred_query_indexes.cxx +115 -50
  12. data/ext/couchbase/core/impl/cluster.cxx +6 -0
  13. data/ext/couchbase/core/impl/create_bucket.cxx +158 -0
  14. data/ext/couchbase/core/impl/create_collection.cxx +83 -0
  15. data/ext/couchbase/core/impl/create_query_index.cxx +172 -59
  16. data/ext/couchbase/core/impl/create_scope.cxx +69 -0
  17. data/ext/couchbase/core/impl/dns_srv_tracker.cxx +2 -1
  18. data/ext/couchbase/core/impl/drop_bucket.cxx +66 -0
  19. data/ext/couchbase/core/impl/drop_collection.cxx +76 -0
  20. data/ext/couchbase/core/impl/drop_query_index.cxx +138 -59
  21. data/ext/couchbase/core/impl/drop_scope.cxx +68 -0
  22. data/ext/couchbase/core/impl/flush_bucket.cxx +66 -0
  23. data/ext/couchbase/core/impl/get_all_buckets.cxx +178 -0
  24. data/ext/couchbase/core/impl/get_all_query_indexes.cxx +67 -37
  25. data/ext/couchbase/core/impl/get_all_scopes.cxx +94 -0
  26. data/ext/couchbase/core/impl/get_bucket.cxx +168 -0
  27. data/ext/couchbase/core/impl/internal_manager_error_context.cxx +113 -0
  28. data/ext/couchbase/core/impl/internal_manager_error_context.hxx +60 -0
  29. data/ext/couchbase/core/impl/key_value_error_category.cxx +2 -4
  30. data/ext/couchbase/core/impl/key_value_error_context.cxx +98 -0
  31. data/ext/couchbase/core/impl/lookup_in.cxx +1 -0
  32. data/ext/couchbase/core/impl/lookup_in_all_replicas.cxx +178 -0
  33. data/ext/couchbase/core/impl/lookup_in_all_replicas.hxx +80 -0
  34. data/ext/couchbase/core/impl/lookup_in_any_replica.cxx +169 -0
  35. data/ext/couchbase/core/impl/lookup_in_any_replica.hxx +75 -0
  36. data/ext/couchbase/core/impl/lookup_in_replica.cxx +104 -0
  37. data/ext/couchbase/core/impl/lookup_in_replica.hxx +67 -0
  38. data/ext/couchbase/core/impl/manager_error_context.cxx +100 -0
  39. data/ext/couchbase/core/impl/query.cxx +1 -0
  40. data/ext/couchbase/core/impl/query_error_context.cxx +75 -0
  41. data/ext/couchbase/core/impl/update_bucket.cxx +133 -0
  42. data/ext/couchbase/core/impl/update_collection.cxx +83 -0
  43. data/ext/couchbase/core/impl/watch_query_indexes.cxx +53 -29
  44. data/ext/couchbase/core/io/dns_client.cxx +111 -40
  45. data/ext/couchbase/core/io/dns_config.cxx +5 -4
  46. data/ext/couchbase/core/io/http_session.hxx +24 -1
  47. data/ext/couchbase/core/io/mcbp_command.hxx +9 -2
  48. data/ext/couchbase/core/io/mcbp_session.cxx +80 -43
  49. data/ext/couchbase/core/io/mcbp_session.hxx +4 -3
  50. data/ext/couchbase/core/logger/custom_rotating_file_sink.cxx +1 -1
  51. data/ext/couchbase/core/logger/logger.cxx +80 -20
  52. data/ext/couchbase/core/logger/logger.hxx +31 -0
  53. data/ext/couchbase/core/management/bucket_settings.hxx +8 -5
  54. data/ext/couchbase/core/management/bucket_settings_json.hxx +12 -2
  55. data/ext/couchbase/core/meta/features.hxx +42 -0
  56. data/ext/couchbase/core/operations/document_lookup_in.cxx +8 -1
  57. data/ext/couchbase/core/operations/document_lookup_in_all_replicas.hxx +192 -0
  58. data/ext/couchbase/core/operations/document_lookup_in_any_replica.hxx +188 -0
  59. data/ext/couchbase/core/operations/document_query.cxx +11 -0
  60. data/ext/couchbase/core/operations/document_query.hxx +1 -0
  61. data/ext/couchbase/core/operations/management/CMakeLists.txt +1 -0
  62. data/ext/couchbase/core/operations/management/bucket_create.cxx +30 -9
  63. data/ext/couchbase/core/operations/management/bucket_update.cxx +27 -6
  64. data/ext/couchbase/core/operations/management/collection_create.cxx +5 -1
  65. data/ext/couchbase/core/operations/management/collection_create.hxx +1 -0
  66. data/ext/couchbase/core/operations/management/collection_update.cxx +87 -0
  67. data/ext/couchbase/core/operations/management/collection_update.hxx +54 -0
  68. data/ext/couchbase/core/operations/management/collections.hxx +1 -0
  69. data/ext/couchbase/core/operations.hxx +2 -0
  70. data/ext/couchbase/core/origin.cxx +270 -0
  71. data/ext/couchbase/core/origin.hxx +2 -0
  72. data/ext/couchbase/core/protocol/client_response.hxx +1 -0
  73. data/ext/couchbase/core/protocol/cmd_hello.hxx +1 -0
  74. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.cxx +107 -0
  75. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.hxx +137 -0
  76. data/ext/couchbase/core/protocol/hello_feature.hxx +6 -0
  77. data/ext/couchbase/core/protocol/hello_feature_fmt.hxx +3 -0
  78. data/ext/couchbase/core/protocol/status.cxx +2 -2
  79. data/ext/couchbase/core/range_scan_options.cxx +3 -27
  80. data/ext/couchbase/core/range_scan_options.hxx +13 -17
  81. data/ext/couchbase/core/range_scan_orchestrator.cxx +388 -170
  82. data/ext/couchbase/core/range_scan_orchestrator.hxx +13 -2
  83. data/ext/couchbase/core/range_scan_orchestrator_options.hxx +5 -3
  84. data/ext/couchbase/core/scan_options.hxx +0 -19
  85. data/ext/couchbase/core/scan_result.cxx +19 -5
  86. data/ext/couchbase/core/scan_result.hxx +5 -2
  87. data/ext/couchbase/core/timeout_defaults.hxx +3 -4
  88. data/ext/couchbase/core/topology/capabilities.hxx +4 -0
  89. data/ext/couchbase/core/topology/capabilities_fmt.hxx +11 -0
  90. data/ext/couchbase/core/topology/collections_manifest.hxx +2 -0
  91. data/ext/couchbase/core/topology/collections_manifest_fmt.hxx +1 -1
  92. data/ext/couchbase/core/topology/collections_manifest_json.hxx +3 -0
  93. data/ext/couchbase/core/topology/configuration.hxx +20 -0
  94. data/ext/couchbase/core/topology/configuration_json.hxx +8 -1
  95. data/ext/couchbase/core/utils/connection_string.cxx +62 -47
  96. data/ext/couchbase/core/utils/connection_string.hxx +1 -0
  97. data/ext/couchbase/couchbase/analytics_error_context.hxx +1 -1
  98. data/ext/couchbase/couchbase/behavior_options.hxx +19 -2
  99. data/ext/couchbase/couchbase/bucket.hxx +14 -0
  100. data/ext/couchbase/couchbase/bucket_manager.hxx +135 -0
  101. data/ext/couchbase/couchbase/build_query_index_options.hxx +0 -30
  102. data/ext/couchbase/couchbase/cluster.hxx +14 -0
  103. data/ext/couchbase/couchbase/collection.hxx +111 -0
  104. data/ext/couchbase/couchbase/collection_manager.hxx +160 -0
  105. data/ext/couchbase/couchbase/collection_query_index_manager.hxx +7 -48
  106. data/ext/couchbase/couchbase/create_bucket_options.hxx +41 -0
  107. data/ext/couchbase/couchbase/create_collection_options.hxx +44 -0
  108. data/ext/couchbase/couchbase/create_primary_query_index_options.hxx +0 -29
  109. data/ext/couchbase/couchbase/create_query_index_options.hxx +0 -33
  110. data/ext/couchbase/couchbase/create_scope_options.hxx +41 -0
  111. data/ext/couchbase/couchbase/drop_bucket_options.hxx +41 -0
  112. data/ext/couchbase/couchbase/drop_collection_options.hxx +41 -0
  113. data/ext/couchbase/couchbase/drop_primary_query_index_options.hxx +0 -30
  114. data/ext/couchbase/couchbase/drop_query_index_options.hxx +0 -31
  115. data/ext/couchbase/couchbase/drop_scope_options.hxx +41 -0
  116. data/ext/couchbase/couchbase/error_codes.hxx +1 -2
  117. data/ext/couchbase/couchbase/error_context.hxx +10 -2
  118. data/ext/couchbase/couchbase/flush_bucket_options.hxx +41 -0
  119. data/ext/couchbase/{core/topology/error_map_fmt.hxx → couchbase/fmt/key_value_error_map_attribute.hxx} +21 -21
  120. data/ext/couchbase/couchbase/get_all_buckets_options.hxx +44 -0
  121. data/ext/couchbase/couchbase/get_all_query_indexes_options.hxx +0 -30
  122. data/ext/couchbase/couchbase/get_all_scopes_options.hxx +44 -0
  123. data/ext/couchbase/couchbase/get_and_lock_options.hxx +2 -2
  124. data/ext/couchbase/couchbase/get_and_touch_options.hxx +2 -2
  125. data/ext/couchbase/couchbase/get_bucket_options.hxx +43 -0
  126. data/ext/couchbase/couchbase/get_options.hxx +2 -2
  127. data/ext/couchbase/couchbase/insert_options.hxx +3 -3
  128. data/ext/couchbase/couchbase/key_value_error_context.hxx +7 -2
  129. data/ext/couchbase/couchbase/lookup_in_all_replicas_options.hxx +109 -0
  130. data/ext/couchbase/couchbase/lookup_in_any_replica_options.hxx +101 -0
  131. data/ext/couchbase/couchbase/lookup_in_options.hxx +2 -2
  132. data/ext/couchbase/couchbase/lookup_in_replica_result.hxx +74 -0
  133. data/ext/couchbase/couchbase/lookup_in_result.hxx +26 -0
  134. data/ext/couchbase/couchbase/management/bucket_settings.hxx +119 -0
  135. data/ext/couchbase/couchbase/management/collection_spec.hxx +29 -0
  136. data/ext/couchbase/couchbase/management/scope_spec.hxx +29 -0
  137. data/ext/couchbase/couchbase/manager_error_context.hxx +29 -53
  138. data/ext/couchbase/couchbase/mutate_in_options.hxx +2 -2
  139. data/ext/couchbase/couchbase/query_error_context.hxx +3 -1
  140. data/ext/couchbase/couchbase/query_index_manager.hxx +16 -83
  141. data/ext/couchbase/couchbase/query_options.hxx +18 -0
  142. data/ext/couchbase/couchbase/remove_options.hxx +2 -2
  143. data/ext/couchbase/couchbase/replace_options.hxx +3 -3
  144. data/ext/couchbase/couchbase/security_options.hxx +15 -0
  145. data/ext/couchbase/couchbase/subdocument_error_context.hxx +4 -2
  146. data/ext/couchbase/couchbase/touch_options.hxx +2 -2
  147. data/ext/couchbase/couchbase/unlock_options.hxx +2 -2
  148. data/ext/couchbase/couchbase/update_bucket_options.hxx +41 -0
  149. data/ext/couchbase/couchbase/update_collection_options.hxx +44 -0
  150. data/ext/couchbase/couchbase/upsert_options.hxx +3 -3
  151. data/ext/couchbase/couchbase/watch_query_indexes_options.hxx +0 -31
  152. data/ext/couchbase/test/CMakeLists.txt +1 -0
  153. data/ext/couchbase/test/test_integration_collections.cxx +6 -0
  154. data/ext/couchbase/test/test_integration_crud.cxx +5 -0
  155. data/ext/couchbase/test/test_integration_examples.cxx +137 -1
  156. data/ext/couchbase/test/test_integration_management.cxx +1009 -309
  157. data/ext/couchbase/test/test_integration_query.cxx +19 -7
  158. data/ext/couchbase/test/test_integration_range_scan.cxx +351 -112
  159. data/ext/couchbase/test/test_integration_search.cxx +10 -1
  160. data/ext/couchbase/test/test_integration_subdoc.cxx +721 -7
  161. data/ext/couchbase/test/test_transaction_public_async_api.cxx +13 -12
  162. data/ext/couchbase/test/test_transaction_public_blocking_api.cxx +27 -21
  163. data/ext/couchbase/test/test_unit_connection_string.cxx +29 -0
  164. data/ext/couchbase/test/test_unit_query.cxx +75 -0
  165. data/ext/couchbase.cxx +735 -60
  166. data/ext/revisions.rb +3 -3
  167. data/lib/couchbase/cluster.rb +1 -1
  168. data/lib/couchbase/collection.rb +108 -0
  169. data/lib/couchbase/collection_options.rb +100 -1
  170. data/lib/couchbase/errors.rb +5 -0
  171. data/lib/couchbase/key_value_scan.rb +125 -0
  172. data/lib/couchbase/management/bucket_manager.rb +22 -15
  173. data/lib/couchbase/management/collection_manager.rb +158 -9
  174. data/lib/couchbase/options.rb +151 -0
  175. data/lib/couchbase/scope.rb +1 -1
  176. data/lib/couchbase/utils/time.rb +14 -1
  177. data/lib/couchbase/version.rb +1 -1
  178. metadata +59 -8
  179. data/ext/couchbase/core/impl/collection_query_index_manager.cxx +0 -93
@@ -38,6 +38,8 @@ module Couchbase
38
38
  super
39
39
  yield self if block_given?
40
40
  end
41
+
42
+ DEFAULT = GetAllScopes.new.freeze
41
43
  end
42
44
 
43
45
  # Options for {CollectionManager#create_scope}
@@ -57,6 +59,8 @@ module Couchbase
57
59
  super
58
60
  yield self if block_given?
59
61
  end
62
+
63
+ DEFAULT = CreateScope.new.freeze
60
64
  end
61
65
 
62
66
  # Options for {CollectionManager#drop_scope}
@@ -76,6 +80,8 @@ module Couchbase
76
80
  super
77
81
  yield self if block_given?
78
82
  end
83
+
84
+ DEFAULT = DropScope.new.freeze
79
85
  end
80
86
 
81
87
  # Options for {CollectionManager#create_collection}
@@ -95,6 +101,29 @@ module Couchbase
95
101
  super
96
102
  yield self if block_given?
97
103
  end
104
+
105
+ DEFAULT = CreateCollection.new.freeze
106
+ end
107
+
108
+ # Options for {CollectionManager#update_collection}
109
+ class UpdateCollection < ::Couchbase::Options::Base
110
+ # Creates an instance of options for {CollectionManager#update_collection}
111
+ #
112
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
113
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
114
+ # @param [Hash, nil] client_context the client context data, if set
115
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
116
+ #
117
+ # @yieldparam [UpdateCollection] self
118
+ def initialize(timeout: nil,
119
+ retry_strategy: nil,
120
+ client_context: nil,
121
+ parent_span: nil)
122
+ super
123
+ yield self if block_given?
124
+ end
125
+
126
+ DEFAULT = UpdateCollection.new.freeze
98
127
  end
99
128
 
100
129
  # Options for {CollectionManager#drop_collection}
@@ -114,6 +143,8 @@ module Couchbase
114
143
  super
115
144
  yield self if block_given?
116
145
  end
146
+
147
+ DEFAULT = DropCollection.new.freeze
117
148
  end
118
149
 
119
150
  # rubocop:disable Naming/MethodName constructor shortcuts
@@ -184,6 +215,8 @@ module Couchbase
184
215
  CollectionSpec.new do |collection|
185
216
  collection.name = c[:name]
186
217
  collection.scope_name = s[:name]
218
+ collection.max_expiry = c[:max_expiry]
219
+ collection.history = c[:history]
187
220
  end
188
221
  end
189
222
  end
@@ -232,29 +265,88 @@ module Couchbase
232
265
  end
233
266
 
234
267
  # Creates a new collection
268
+ # @overload create_collection(scope_name, collection_name, settings = CreateCollectionSettings::DEFAULT,
269
+ # options = Options::Collection::CreateCollection::DEFAULT)
270
+ # @param [String] scope_name the name of the scope the collection will be created in
271
+ # @param [String] collection_name the name of the collection to be created
272
+ # @param [CreateCollectionSettings] settings settings for the new collection
273
+ # @param [Options::Collection::CreateCollection] options
235
274
  #
236
- # @param [CollectionSpec] collection specification of the collection
237
- # @param [Options::Collection::CreateCollection] options
275
+ # @overload create_collection(collection, options = Options::Collection::CreateCollection)
276
+ # @param [CollectionSpec] collection specification of the collection
277
+ # @param [Options::Collection::CreateCollection] options
278
+ #
279
+ # @deprecated Use +#create_collection(scope_name, collection_name, settings, options)+ instead
238
280
  #
239
281
  # @return void
240
282
  #
241
283
  # @raise [ArgumentError]
242
- # @raise [Error::CollectionExist]
284
+ # @raise [Error::CollectionExists]
285
+ # @raise [Error::ScopeNotFound]
286
+ def create_collection(*args)
287
+ if args[0].is_a?(CollectionSpec)
288
+ collection = args[0]
289
+ options = args[1] || Options::Collection::CreateCollection::DEFAULT
290
+ settings = CreateCollectionSettings.new(max_expiry: collection.max_expiry, history: collection.history)
291
+
292
+ warn "Calling create_collection with a CollectionSpec object has been deprecated, supply scope name, " \
293
+ "collection name and optionally a CreateCollectionSettings instance"
294
+
295
+ @backend.collection_create(@bucket_name, collection.scope_name, collection.name, settings.to_backend, options.to_backend)
296
+ else
297
+ scope_name = args[0]
298
+ collection_name = args[1]
299
+ settings = args[2] || CreateCollectionSettings::DEFAULT
300
+ options = args[3] || Options::Collection::CreateCollection::DEFAULT
301
+ @backend.collection_create(@bucket_name, scope_name, collection_name, settings.to_backend, options.to_backend)
302
+ end
303
+ end
304
+
305
+ # Updates the settings of an existing collection
306
+ #
307
+ # @param [String] scope_name the name of the scope the collection is in
308
+ # @param [String] collection_name the name of the collection to be updated
309
+ # @param [UpdateCollectionSettings] settings the settings that should be updated
310
+ #
311
+ # @raise [ArgumentError]
312
+ # @raise [Error::CollectionNotFound]
243
313
  # @raise [Error::ScopeNotFound]
244
- def create_collection(collection, options = Options::Collection::CreateCollection.new)
245
- @backend.collection_create(@bucket_name, collection.scope_name, collection.name, collection.max_expiry, options.to_backend)
314
+ def update_collection(scope_name, collection_name, settings = UpdateCollectionSettings::DEFAULT,
315
+ options = Options::Collection::UpdateCollection::DEFAULT)
316
+ @backend.collection_update(@bucket_name, scope_name, collection_name, settings.to_backend, options.to_backend)
246
317
  end
247
318
 
248
319
  # Removes a collection
320
+ # @overload drop_collection(scope_name, collection_name, settings = CreateCollectionSettings::DEFAULT,
321
+ # options = Options::Collection::CreateCollection::DEFAULT)
322
+ # @param [String] scope_name the name of the scope the collection is in
323
+ # @param [String] collection_name the name of the collection to be removed
249
324
  #
250
- # @param [CollectionSpec] collection specification of the collection
251
- # @param [Options::Collection::DropCollection] options
325
+ # @overload drop_collection(collection, options = Options::Collection::CreateCollection)
326
+ # @param [CollectionSpec] collection specification of the collection
327
+ # @param [Options::Collection::CreateCollection] options
328
+ #
329
+ # @deprecated Use +#drop_collection(scope_name, collection_name, options)+ instead
252
330
  #
253
331
  # @return void
254
332
  #
333
+ # @raise [ArgumentError]
255
334
  # @raise [Error::CollectionNotFound]
256
- def drop_collection(collection, options = Options::Collection::DropCollection.new)
257
- @backend.collection_drop(@bucket_name, collection.scope_name, collection.name, options.to_backend)
335
+ # @raise [Error::ScopeNotFound]
336
+ def drop_collection(*args)
337
+ if args[0].is_a?(CollectionSpec)
338
+ collection = args[0]
339
+ options = args[1] || Options::Collection::CreateCollection::DEFAULT
340
+
341
+ warn "Calling drop_collection with a CollectionSpec object has been deprecated, supply scope name and collection name"
342
+
343
+ @backend.collection_drop(@bucket_name, collection.scope_name, collection.name, options.to_backend)
344
+ else
345
+ scope_name = args[0]
346
+ collection_name = args[1]
347
+ options = args[2] || Options::Collection::CreateCollection::DEFAULT
348
+ @backend.collection_drop(@bucket_name, scope_name, collection_name, options.to_backend)
349
+ end
258
350
  end
259
351
 
260
352
  # @deprecated use {CollectionManager#get_all_scopes} instead
@@ -289,6 +381,60 @@ module Couchbase
289
381
  DropCollectionOptions = ::Couchbase::Management::Options::Collection::DropCollection
290
382
  end
291
383
 
384
+ class CreateCollectionSettings
385
+ # @return [Integer, nil] time in seconds of the maximum expiration time for new documents in the collection
386
+ # (set to +nil+ to disable it)
387
+ attr_accessor :max_expiry
388
+
389
+ # @return [Boolean, nil] whether history retention override should be enabled in the collection (set to +nil+ to
390
+ # default to the bucket-level setting)
391
+ attr_accessor :history
392
+
393
+ def initialize(max_expiry: nil, history: nil)
394
+ @max_expiry = max_expiry
395
+ @history = history
396
+
397
+ yield self if block_given?
398
+ end
399
+
400
+ # @api private
401
+ def to_backend
402
+ {
403
+ max_expiry: @max_expiry,
404
+ history: @history,
405
+ }
406
+ end
407
+
408
+ DEFAULT = CreateCollectionSettings.new.freeze
409
+ end
410
+
411
+ class UpdateCollectionSettings
412
+ # @return [Integer, nil] time in seconds of the maximum expiration time for new documents in the collection
413
+ # (set to +nil+ to disable it)
414
+ attr_accessor :max_expiry
415
+
416
+ # @return [Boolean, nil] whether history retention override should be enabled in the collection (set to +nil+ to
417
+ # default to the bucket-level setting)
418
+ attr_accessor :history
419
+
420
+ def initialize(max_expiry: nil, history: nil)
421
+ @max_expiry = max_expiry
422
+ @history = history
423
+
424
+ yield self if block_given?
425
+ end
426
+
427
+ # @api private
428
+ def to_backend
429
+ {
430
+ max_expiry: @max_expiry,
431
+ history: @history,
432
+ }
433
+ end
434
+
435
+ DEFAULT = UpdateCollectionSettings.new.freeze
436
+ end
437
+
292
438
  class ScopeSpec
293
439
  # @return [String] name of the scope
294
440
  attr_accessor :name
@@ -312,6 +458,9 @@ module Couchbase
312
458
  # @return [Integer] time in seconds of the expiration for new documents in the collection (set to +nil+ to disable it)
313
459
  attr_accessor :max_expiry
314
460
 
461
+ # @return [Boolean, nil] whether history retention is enabled for this collection
462
+ attr_accessor :history
463
+
315
464
  # @yieldparam [CollectionSpec] self
316
465
  def initialize
317
466
  yield self if block_given?
@@ -1026,6 +1026,151 @@ module Couchbase
1026
1026
  DEFAULT = LookupIn.new.freeze
1027
1027
  end
1028
1028
 
1029
+ # Options for {Collection#lookup_in_any_replica}
1030
+ class LookupInAnyReplica < Base
1031
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String)]
1032
+
1033
+ # Creates an instance of options for {Collection#lookup_in_any_replica}
1034
+ #
1035
+ # @param [JsonTranscoder, #decode(String)] transcoder used for encoding
1036
+ #
1037
+ # @param [Integer, #in_milliseconds, nil] timeout
1038
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
1039
+ # @param [Hash, nil] client_context the client context data, if set
1040
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
1041
+ #
1042
+ # @yieldparam [LookupIn] self
1043
+ def initialize(transcoder: JsonTranscoder.new,
1044
+ timeout: nil,
1045
+ retry_strategy: nil,
1046
+ client_context: nil,
1047
+ parent_span: nil)
1048
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
1049
+ @transcoder = transcoder
1050
+ yield self if block_given?
1051
+ end
1052
+
1053
+ # @api private
1054
+ def to_backend
1055
+ {
1056
+ timeout: Utils::Time.extract_duration(@timeout),
1057
+ }
1058
+ end
1059
+
1060
+ # @api private
1061
+ # @return [Boolean]
1062
+ attr_accessor :access_deleted
1063
+
1064
+ # @api private
1065
+ DEFAULT = LookupInAnyReplica.new.freeze
1066
+ end
1067
+
1068
+ # Options for {Collection#lookup_in_all_replicas}
1069
+ class LookupInAllReplicas < Base
1070
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String)]
1071
+
1072
+ # Creates an instance of options for {Collection#lookup_in_all_replicas}
1073
+ #
1074
+ # @param [JsonTranscoder, #decode(String)] transcoder used for encoding
1075
+ #
1076
+ # @param [Integer, #in_milliseconds, nil] timeout
1077
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
1078
+ # @param [Hash, nil] client_context the client context data, if set
1079
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
1080
+ #
1081
+ # @yieldparam [LookupInAllReplicas] self
1082
+ def initialize(transcoder: JsonTranscoder.new,
1083
+ timeout: nil,
1084
+ retry_strategy: nil,
1085
+ client_context: nil,
1086
+ parent_span: nil)
1087
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
1088
+ @transcoder = transcoder
1089
+ yield self if block_given?
1090
+ end
1091
+
1092
+ # @api private
1093
+ def to_backend
1094
+ {
1095
+ timeout: Utils::Time.extract_duration(@timeout),
1096
+ }
1097
+ end
1098
+
1099
+ # @api private
1100
+ DEFAULT = LookupInAllReplicas.new.freeze
1101
+ end
1102
+
1103
+ # Options for {Collection#scan}
1104
+ class Scan < Base
1105
+ attr_accessor :ids_only # @return [Boolean]
1106
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String)]
1107
+ attr_accessor :mutation_state # @return [MutationState, nil]
1108
+ attr_accessor :batch_byte_limit # @return [Integer, nil]
1109
+ attr_accessor :batch_item_limit # @return [Integer, nil]
1110
+ attr_accessor :concurrency # @return [Integer, nil]
1111
+
1112
+ # Creates an instance of options for {Collection#scan}
1113
+ #
1114
+ # @param [Boolean] ids_only if set to true, the content of the documents is not included in the results
1115
+ # @param [JsonTranscoder, #decode(String)] transcoder used for decoding
1116
+ # @param [MutationState, nil] mutation_state sets the mutation tokens this scan should be consistent with
1117
+ # @param [Integer, nil] batch_byte_limit allows to limit the maximum amount of bytes that are sent from the server
1118
+ # to the client on each partition batch, defaults to 15,000
1119
+ # @param [Integer, nil] batch_item_limit allows to limit the maximum amount of items that are sent from the server
1120
+ # to the client on each partition batch, defaults to 50
1121
+ # @param [Integer, nil] concurrency specifies the maximum number of partitions that can be scanned concurrently,
1122
+ # defaults to 1
1123
+ #
1124
+ # @param [Integer, #in_milliseconds, nil] timeout
1125
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
1126
+ # @param [Hash, nil] client_context the client context data, if set
1127
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
1128
+ #
1129
+ # @yieldparam [LookupIn] self
1130
+ def initialize(ids_only: false,
1131
+ transcoder: JsonTranscoder.new,
1132
+ mutation_state: nil,
1133
+ batch_byte_limit: nil,
1134
+ batch_item_limit: nil,
1135
+ concurrency: nil,
1136
+ timeout: nil,
1137
+ retry_strategy: nil,
1138
+ client_context: nil,
1139
+ parent_span: nil)
1140
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
1141
+ @ids_only = ids_only
1142
+ @transcoder = transcoder
1143
+ @mutation_state = mutation_state
1144
+ @batch_byte_limit = batch_byte_limit
1145
+ @batch_item_limit = batch_item_limit
1146
+ @concurrency = concurrency
1147
+ yield self if block_given?
1148
+ end
1149
+
1150
+ # Sets the mutation tokens this query should be consistent with
1151
+ #
1152
+ # @note overrides consistency level set by {#scan_consistency=}
1153
+ #
1154
+ # @param [MutationState] mutation_state the mutation state containing the mutation tokens
1155
+ def consistent_with(mutation_state)
1156
+ @mutation_state = mutation_state
1157
+ end
1158
+
1159
+ # @api private
1160
+ def to_backend
1161
+ {
1162
+ timeout: Utils::Time.extract_duration(@timeout),
1163
+ ids_only: @ids_only,
1164
+ mutation_state: @mutation_state.to_a,
1165
+ batch_byte_limit: @batch_byte_limit,
1166
+ batch_item_limit: @batch_item_limit,
1167
+ concurrency: @concurrency,
1168
+ }
1169
+ end
1170
+
1171
+ DEFAULT = Scan.new.freeze
1172
+ end
1173
+
1029
1174
  # Options for {BinaryCollection#append}
1030
1175
  class Append < Base
1031
1176
  attr_accessor :cas # @return [Integer]
@@ -1849,6 +1994,7 @@ module Couchbase
1849
1994
  attr_accessor :profile # @return [Symbol]
1850
1995
  attr_accessor :flex_index # @return [Boolean]
1851
1996
  attr_accessor :preserve_expiry # @return [Boolean]
1997
+ attr_accessor :use_replica # @return [Boolean, nil]
1852
1998
  attr_accessor :scope_qualifier # @return [String]
1853
1999
  attr_accessor :transcoder # @return [JsonTranscoder, #decode(String)]
1854
2000
 
@@ -1894,6 +2040,8 @@ module Couchbase
1894
2040
  # @param [Boolean, nil] flex_index Tells the query engine to use a flex index (utilizing the search service)
1895
2041
  # @param [Boolean, nil] preserve_expiry Tells the query engine to preserve expiration values set on any documents
1896
2042
  # modified by this query.
2043
+ # @param [Boolean, nil] use_replica Specifies that the query engine should use replica nodes for KV fetches if
2044
+ # the active node is down. If not provided, the server default will be used
1897
2045
  # @param [String, nil] scope_qualifier Associate scope qualifier (also known as +query_context+) with the query.
1898
2046
  # The qualifier must be in form +{bucket_name}.{scope_name}+ or +default:{bucket_name}.{scope_name}+.
1899
2047
  # @param [JsonTranscoder] transcoder to decode rows
@@ -1925,6 +2073,7 @@ module Couchbase
1925
2073
  profile: :off,
1926
2074
  flex_index: nil,
1927
2075
  preserve_expiry: nil,
2076
+ use_replica: nil,
1928
2077
  scope_qualifier: nil,
1929
2078
  scan_consistency: :not_bounded,
1930
2079
  mutation_state: nil,
@@ -1950,6 +2099,7 @@ module Couchbase
1950
2099
  @profile = profile
1951
2100
  @flex_index = flex_index
1952
2101
  @preserve_expiry = preserve_expiry
2102
+ @use_replica = use_replica
1953
2103
  @scope_qualifier = scope_qualifier
1954
2104
  @scan_consistency = scan_consistency
1955
2105
  @mutation_state = mutation_state
@@ -2043,6 +2193,7 @@ module Couchbase
2043
2193
  readonly: @readonly,
2044
2194
  flex_index: @flex_index,
2045
2195
  preserve_expiry: @preserve_expiry,
2196
+ use_replica: @use_replica,
2046
2197
  scan_wait: Utils::Time.extract_duration(@scan_wait),
2047
2198
  scan_cap: @scan_cap,
2048
2199
  pipeline_batch: @pipeline_batch,
@@ -79,7 +79,7 @@ module Couchbase
79
79
  metrics.warning_count = resp[:meta][:metrics][:warning_count]
80
80
  end
81
81
  end
82
- res[:warnings] = resp[:warnings].map { |warn| Cluster::QueryWarning.new(warn[:code], warn[:message]) } if resp[:warnings]
82
+ meta.warnings = resp[:warnings].map { |warn| Cluster::QueryWarning.new(warn[:code], warn[:message]) } if resp[:warnings]
83
83
  end
84
84
  res.instance_variable_set(:@rows, resp[:rows])
85
85
  end
@@ -48,8 +48,21 @@ module Couchbase
48
48
  end
49
49
  end
50
50
 
51
+ # This method converts its argument to milliseconds
52
+ #
53
+ # 1. Integer values are interpreted as a number of milliseconds
54
+ # 2. If the argument is a Duration-like object and responds to #in_milliseconds,
55
+ # then use it and convert result to Integer
56
+ # 3. Otherwise invoke #to_i on the argument and interpret it as a number of milliseconds
51
57
  def extract_duration(number_or_duration)
52
- number_or_duration.respond_to?(:in_milliseconds) ? number_or_duration.public_send(:in_milliseconds) : number_or_duration
58
+ return unless number_or_duration
59
+ return number_or_duration if number_or_duration.class == Integer # rubocop:disable Style/ClassEqualityComparison avoid overrides of #is_a?, #kind_of?
60
+
61
+ if number_or_duration.respond_to?(:in_milliseconds)
62
+ number_or_duration.public_send(:in_milliseconds)
63
+ else
64
+ number_or_duration
65
+ end.to_i
53
66
  end
54
67
  end
55
68
  end
@@ -19,5 +19,5 @@ module Couchbase
19
19
  # $ ruby -rcouchbase -e 'pp Couchbase::VERSION'
20
20
  # {:sdk=>"3.4.0", :ruby_abi=>"3.1.0", :revision=>"416fe68e6029ec8a4c40611cf6e6b30d3b90d20f"}
21
21
  VERSION = {} unless defined?(VERSION) # rubocop:disable Style/MutableConstant
22
- VERSION.update(:sdk => "3.4.3".freeze)
22
+ VERSION.update(:sdk => "3.4.5".freeze)
23
23
  end