couchbase 3.9.0-aarch64-mingw-ucrt

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) 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 +407 -0
  6. data/lib/couchbase/3.4/libcouchbase.so +0 -0
  7. data/lib/couchbase/4.0/libcouchbase.so +0 -0
  8. data/lib/couchbase/analytics_options.rb +109 -0
  9. data/lib/couchbase/authenticator.rb +80 -0
  10. data/lib/couchbase/binary_collection.rb +145 -0
  11. data/lib/couchbase/binary_collection_options.rb +26 -0
  12. data/lib/couchbase/bucket.rb +173 -0
  13. data/lib/couchbase/cluster.rb +555 -0
  14. data/lib/couchbase/cluster_registry.rb +49 -0
  15. data/lib/couchbase/collection.rb +770 -0
  16. data/lib/couchbase/collection_options.rb +401 -0
  17. data/lib/couchbase/config_profiles.rb +57 -0
  18. data/lib/couchbase/configuration.rb +58 -0
  19. data/lib/couchbase/datastructures/couchbase_list.rb +192 -0
  20. data/lib/couchbase/datastructures/couchbase_map.rb +231 -0
  21. data/lib/couchbase/datastructures/couchbase_queue.rb +161 -0
  22. data/lib/couchbase/datastructures/couchbase_set.rb +145 -0
  23. data/lib/couchbase/datastructures.rb +26 -0
  24. data/lib/couchbase/deprecations.rb +61 -0
  25. data/lib/couchbase/diagnostics.rb +183 -0
  26. data/lib/couchbase/errors.rb +438 -0
  27. data/lib/couchbase/fork_hooks.rb +41 -0
  28. data/lib/couchbase/get_replica_strategy.rb +89 -0
  29. data/lib/couchbase/json_transcoder.rb +41 -0
  30. data/lib/couchbase/key_value_scan.rb +119 -0
  31. data/lib/couchbase/libcouchbase.rb +6 -0
  32. data/lib/couchbase/logger.rb +87 -0
  33. data/lib/couchbase/management/analytics_index_manager.rb +1160 -0
  34. data/lib/couchbase/management/bucket_manager.rb +479 -0
  35. data/lib/couchbase/management/collection_manager.rb +515 -0
  36. data/lib/couchbase/management/collection_query_index_manager.rb +247 -0
  37. data/lib/couchbase/management/query_index_manager.rb +671 -0
  38. data/lib/couchbase/management/scope_search_index_manager.rb +267 -0
  39. data/lib/couchbase/management/search_index_manager.rb +649 -0
  40. data/lib/couchbase/management/user_manager.rb +639 -0
  41. data/lib/couchbase/management/view_index_manager.rb +332 -0
  42. data/lib/couchbase/management.rb +31 -0
  43. data/lib/couchbase/metrics/logging_meter.rb +108 -0
  44. data/lib/couchbase/metrics/logging_value_recorder.rb +50 -0
  45. data/lib/couchbase/metrics/meter.rb +27 -0
  46. data/lib/couchbase/metrics/noop_meter.rb +30 -0
  47. data/lib/couchbase/metrics/noop_value_recorder.rb +27 -0
  48. data/lib/couchbase/metrics/value_recorder.rb +25 -0
  49. data/lib/couchbase/mutation_state.rb +65 -0
  50. data/lib/couchbase/options.rb +3097 -0
  51. data/lib/couchbase/protostellar/binary_collection.rb +55 -0
  52. data/lib/couchbase/protostellar/bucket.rb +59 -0
  53. data/lib/couchbase/protostellar/client.rb +97 -0
  54. data/lib/couchbase/protostellar/cluster.rb +182 -0
  55. data/lib/couchbase/protostellar/collection.rb +156 -0
  56. data/lib/couchbase/protostellar/connect_options.rb +63 -0
  57. data/lib/couchbase/protostellar/error_handling.rb +204 -0
  58. data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_pb.rb +54 -0
  59. data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_services_pb.rb +51 -0
  60. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +42 -0
  61. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +51 -0
  62. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +38 -0
  63. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +52 -0
  64. data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +42 -0
  65. data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +55 -0
  66. data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +51 -0
  67. data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +67 -0
  68. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +31 -0
  69. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +40 -0
  70. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +51 -0
  71. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +54 -0
  72. data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_pb.rb +46 -0
  73. data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_services_pb.rb +56 -0
  74. data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +74 -0
  75. data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +93 -0
  76. data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +35 -0
  77. data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +40 -0
  78. data/lib/couchbase/protostellar/generated/routing/v2/routing_pb.rb +26 -0
  79. data/lib/couchbase/protostellar/generated/routing/v2/routing_services_pb.rb +43 -0
  80. data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +78 -0
  81. data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +41 -0
  82. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +36 -0
  83. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +66 -0
  84. data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +30 -0
  85. data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +39 -0
  86. data/lib/couchbase/protostellar/generated.rb +9 -0
  87. data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
  88. data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
  89. data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
  90. data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
  91. data/lib/couchbase/protostellar/management.rb +24 -0
  92. data/lib/couchbase/protostellar/request.rb +79 -0
  93. data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
  94. data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
  95. data/lib/couchbase/protostellar/request_generator/admin/collection.rb +96 -0
  96. data/lib/couchbase/protostellar/request_generator/admin/query.rb +132 -0
  97. data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
  98. data/lib/couchbase/protostellar/request_generator/kv.rb +488 -0
  99. data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
  100. data/lib/couchbase/protostellar/request_generator/search.rb +403 -0
  101. data/lib/couchbase/protostellar/request_generator.rb +26 -0
  102. data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
  103. data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
  104. data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
  105. data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
  106. data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
  107. data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
  108. data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
  109. data/lib/couchbase/protostellar/response_converter.rb +26 -0
  110. data/lib/couchbase/protostellar/retry/action.rb +38 -0
  111. data/lib/couchbase/protostellar/retry/orchestrator.rb +61 -0
  112. data/lib/couchbase/protostellar/retry/reason.rb +67 -0
  113. data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
  114. data/lib/couchbase/protostellar/retry/strategies/fail_fast.rb +33 -0
  115. data/lib/couchbase/protostellar/retry/strategies.rb +27 -0
  116. data/lib/couchbase/protostellar/retry.rb +28 -0
  117. data/lib/couchbase/protostellar/scope.rb +61 -0
  118. data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
  119. data/lib/couchbase/protostellar/timeouts.rb +83 -0
  120. data/lib/couchbase/protostellar.rb +29 -0
  121. data/lib/couchbase/query_options.rb +122 -0
  122. data/lib/couchbase/railtie.rb +47 -0
  123. data/lib/couchbase/raw_binary_transcoder.rb +39 -0
  124. data/lib/couchbase/raw_json_transcoder.rb +40 -0
  125. data/lib/couchbase/raw_string_transcoder.rb +42 -0
  126. data/lib/couchbase/scope.rb +272 -0
  127. data/lib/couchbase/search_options.rb +1744 -0
  128. data/lib/couchbase/subdoc.rb +293 -0
  129. data/lib/couchbase/tracing/noop_span.rb +29 -0
  130. data/lib/couchbase/tracing/noop_tracer.rb +29 -0
  131. data/lib/couchbase/tracing/request_span.rb +34 -0
  132. data/lib/couchbase/tracing/request_tracer.rb +28 -0
  133. data/lib/couchbase/tracing/threshold_logging_span.rb +112 -0
  134. data/lib/couchbase/tracing/threshold_logging_tracer.rb +231 -0
  135. data/lib/couchbase/transcoder_flags.rb +64 -0
  136. data/lib/couchbase/utils/generic_logger_adapter.rb +40 -0
  137. data/lib/couchbase/utils/hdr_histogram.rb +55 -0
  138. data/lib/couchbase/utils/observability.rb +263 -0
  139. data/lib/couchbase/utils/observability_constants.rb +200 -0
  140. data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
  141. data/lib/couchbase/utils/time.rb +71 -0
  142. data/lib/couchbase/utils.rb +23 -0
  143. data/lib/couchbase/version.rb +25 -0
  144. data/lib/couchbase/view_options.rb +67 -0
  145. data/lib/couchbase.rb +32 -0
  146. data/lib/rails/generators/couchbase/config/config_generator.rb +29 -0
  147. metadata +209 -0
@@ -0,0 +1,671 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020-2021 Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "couchbase/errors"
18
+ require "couchbase/options"
19
+ require "couchbase/utils/time"
20
+
21
+ module Couchbase
22
+ module Management
23
+ module Options
24
+ module Query
25
+ # Options for {QueryIndexManager#get_all_indexes}
26
+ class GetAllIndexes < ::Couchbase::Options::Base
27
+ attr_accessor :scope_name # @return [String, nil]
28
+ attr_accessor :collection_name # @return [String, nil]
29
+
30
+ # Creates an instance of options for {QueryIndexManager#get_all_indexes}
31
+ #
32
+ # @param [String, nil] scope_name the name of the scope
33
+ # @param [String, nil] collection_name the name of the collection
34
+ #
35
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
36
+ # @param [Symbol, nil] retry_strategy ignored by this operation
37
+ # @param [Hash, nil] client_context the client context data, if set
38
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
39
+ #
40
+ # @yieldparam [GetAllScopes] self
41
+ def initialize(scope_name: nil,
42
+ collection_name: nil,
43
+ timeout: nil,
44
+ retry_strategy: nil,
45
+ client_context: nil,
46
+ parent_span: nil)
47
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
48
+ @scope_name = scope_name
49
+ @collection_name = collection_name
50
+ yield self if block_given?
51
+ end
52
+
53
+ # @api private
54
+ def to_backend
55
+ {
56
+ timeout: Utils::Time.extract_duration(@timeout),
57
+ scope_name: @scope_name,
58
+ collection_name: @collection_name,
59
+ }
60
+ end
61
+ end
62
+
63
+ # Options for {QueryIndexManager#create_index}
64
+ class CreateIndex < ::Couchbase::Options::Base
65
+ attr_accessor :ignore_if_exists # @return [Boolean]
66
+ attr_accessor :num_replicas # @return [Integer, nil]
67
+ attr_accessor :deferred # @return [Boolean]
68
+ attr_accessor :condition # @return [String, nil]
69
+ attr_accessor :scope_name # @return [String, nil]
70
+ attr_accessor :collection_name # @return [String, nil]
71
+
72
+ # Creates an instance of options for {QueryIndexManager#create_index}
73
+ #
74
+ # @param [Boolean] ignore_if_exists do not raise error if the index already exist
75
+ # @param [Integer] num_replicas the number of replicas that this index should have
76
+ # @param [Boolean] deferred whether the index should be created as a deferred index.
77
+ # @param [String, nil] condition to apply to the index
78
+ # @param [String, nil] scope_name the name of the scope
79
+ # @param [String, nil] collection_name the name of the collection
80
+ #
81
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
82
+ # @param [Symbol, nil] retry_strategy ignored by this operation
83
+ # @param [Hash, nil] client_context the client context data, if set
84
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
85
+ #
86
+ # @yieldparam [CreateIndex] self
87
+ def initialize(ignore_if_exists: false,
88
+ num_replicas: nil,
89
+ deferred: false,
90
+ condition: nil,
91
+ scope_name: nil,
92
+ collection_name: nil,
93
+ timeout: nil,
94
+ retry_strategy: nil,
95
+ client_context: nil,
96
+ parent_span: nil)
97
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
98
+ @ignore_if_exists = ignore_if_exists
99
+ @num_replicas = num_replicas
100
+ @deferred = deferred
101
+ @condition = condition
102
+ @scope_name = scope_name
103
+ @collection_name = collection_name
104
+ yield self if block_given?
105
+ end
106
+
107
+ # @api private
108
+ def to_backend
109
+ {
110
+ timeout: Utils::Time.extract_duration(@timeout),
111
+ ignore_if_exists: @ignore_if_exists,
112
+ condition: @condition,
113
+ deferred: @deferred,
114
+ num_replicas: @num_replicas,
115
+ scope_name: @scope_name,
116
+ collection_name: @collection_name,
117
+ }
118
+ end
119
+ end
120
+
121
+ # Options for {QueryIndexManager#create_primary_index}
122
+ class CreatePrimaryIndex < ::Couchbase::Options::Base
123
+ attr_accessor :ignore_if_exists # @return [Boolean]
124
+ attr_accessor :num_replicas # @return [Integer, nil]
125
+ attr_accessor :deferred # @return [Boolean]
126
+ attr_accessor :index_name # @return [String. nil]
127
+ attr_accessor :scope_name # @return [String, nil]
128
+ attr_accessor :collection_name # @return [String, nil]
129
+
130
+ # Creates an instance of options for {QueryIndexManager#create_primary_index}
131
+ #
132
+ # @param [Boolean] ignore_if_exists do not raise error if the index already exist
133
+ # @param [Integer] num_replicas the number of replicas that this index should have
134
+ # @param [Boolean] deferred whether the index should be created as a deferred index.
135
+ # @param [String, nil] index_name the custom name of the primary index.
136
+ # @param [String, nil] scope_name the name of the scope
137
+ # @param [String, nil] collection_name the name of the collection
138
+ #
139
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
140
+ # @param [Symbol, nil] retry_strategy ignored by this operation
141
+ # @param [Hash, nil] client_context the client context data, if set
142
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
143
+ #
144
+ # @yieldparam [CreatePrimaryIndex] self
145
+ def initialize(ignore_if_exists: false,
146
+ num_replicas: nil,
147
+ deferred: false,
148
+ index_name: nil,
149
+ scope_name: nil,
150
+ collection_name: nil,
151
+ timeout: nil,
152
+ retry_strategy: nil,
153
+ client_context: nil,
154
+ parent_span: nil)
155
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
156
+ @ignore_if_exists = ignore_if_exists
157
+ @num_replicas = num_replicas
158
+ @deferred = deferred
159
+ @index_name = index_name
160
+ @scope_name = scope_name
161
+ @collection_name = collection_name
162
+ yield self if block_given?
163
+ end
164
+
165
+ # @api private
166
+ def to_backend
167
+ {
168
+ timeout: Utils::Time.extract_duration(@timeout),
169
+ ignore_if_exists: @ignore_if_exists,
170
+ deferred: @deferred,
171
+ num_replicas: @num_replicas,
172
+ index_name: @index_name,
173
+ scope_name: @scope_name,
174
+ collection_name: @collection_name,
175
+ }
176
+ end
177
+ end
178
+
179
+ # Options for {QueryIndexManager#drop_index}
180
+ class DropIndex < ::Couchbase::Options::Base
181
+ attr_accessor :ignore_if_does_not_exist # @return [Boolean]
182
+ attr_accessor :scope_name # @return [String, nil]
183
+ attr_accessor :collection_name # @return [String, nil]
184
+
185
+ # Creates an instance of options for {QueryIndexManager#drop_index}
186
+ #
187
+ # @param [Boolean] ignore_if_does_not_exist do not raise error if the index does not exist
188
+ # @param [String, nil] scope_name the name of the scope
189
+ # @param [String, nil] collection_name the name of the collection
190
+ #
191
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
192
+ # @param [Symbol, nil] retry_strategy ignored by this operation
193
+ # @param [Hash, nil] client_context the client context data, if set
194
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
195
+ #
196
+ # @yieldparam [DropIndex] self
197
+ def initialize(ignore_if_does_not_exist: false,
198
+ scope_name: nil,
199
+ collection_name: nil,
200
+ timeout: nil,
201
+ retry_strategy: nil,
202
+ client_context: nil,
203
+ parent_span: nil)
204
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
205
+ @ignore_if_does_not_exist = ignore_if_does_not_exist
206
+ @scope_name = scope_name
207
+ @collection_name = collection_name
208
+ yield self if block_given?
209
+ end
210
+
211
+ # @api private
212
+ def to_backend
213
+ {
214
+ timeout: Utils::Time.extract_duration(@timeout),
215
+ ignore_if_does_not_exist: @ignore_if_does_not_exist,
216
+ scope_name: @scope_name,
217
+ collection_name: @collection_name,
218
+ }
219
+ end
220
+ end
221
+
222
+ # Options for {QueryIndexManager#drop_primary_index}
223
+ class DropPrimaryIndex < ::Couchbase::Options::Base
224
+ attr_accessor :ignore_if_does_not_exist # @return [Boolean]
225
+ attr_accessor :scope_name # @return [String, nil]
226
+ attr_accessor :collection_name # @return [String, nil]
227
+
228
+ # Creates an instance of options for {QueryIndexManager#drop_primary_index}
229
+ #
230
+ # @param [Boolean] ignore_if_does_not_exist do not raise error if the index does not exist
231
+ # @param [String, nil] scope_name the name of the scope
232
+ # @param [String, nil] collection_name the name of the collection
233
+ #
234
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
235
+ # @param [Symbol, nil] retry_strategy ignored by this operation
236
+ # @param [Hash, nil] client_context the client context data, if set
237
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
238
+ #
239
+ # @yieldparam [DropPrimaryIndex] self
240
+ def initialize(ignore_if_does_not_exist: false,
241
+ scope_name: nil,
242
+ collection_name: nil,
243
+ timeout: nil,
244
+ retry_strategy: nil,
245
+ client_context: nil,
246
+ parent_span: nil)
247
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
248
+ @ignore_if_does_not_exist = ignore_if_does_not_exist
249
+ @scope_name = scope_name
250
+ @collection_name = collection_name
251
+ yield self if block_given?
252
+ end
253
+
254
+ # @api private
255
+ def to_backend
256
+ {
257
+ timeout: Utils::Time.extract_duration(@timeout),
258
+ ignore_if_does_not_exist: @ignore_if_does_not_exist,
259
+ scope_name: @scope_name,
260
+ collection_name: @collection_name,
261
+ }
262
+ end
263
+ end
264
+
265
+ # Options for {QueryIndexManager#build_deferred_indexes}
266
+ class BuildDeferredIndexes < ::Couchbase::Options::Base
267
+ attr_accessor :scope_name # @return [String, nil]
268
+ attr_accessor :collection_name # @return [String, nil]
269
+
270
+ # Creates an instance of options for {QueryIndexManager#build_deferred_indexes}
271
+ # @param [String, nil] scope_name the name of the scope
272
+ # @param [String, nil] collection_name the name of the collection
273
+ #
274
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
275
+ # @param [Symbol, nil] retry_strategy ignored by this operation
276
+ # @param [Hash, nil] client_context the client context data, if set
277
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
278
+ #
279
+ # @yieldparam [GetAllScopes] self
280
+ def initialize(scope_name: nil,
281
+ collection_name: nil,
282
+ timeout: nil,
283
+ retry_strategy: nil,
284
+ client_context: nil,
285
+ parent_span: nil)
286
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
287
+ @scope_name = scope_name
288
+ @collection_name = collection_name
289
+ yield self if block_given?
290
+ end
291
+
292
+ # @api private
293
+ def to_backend
294
+ {
295
+ timeout: Utils::Time.extract_duration(@timeout),
296
+ scope_name: @scope_name,
297
+ collection_name: @collection_name,
298
+ }
299
+ end
300
+ end
301
+
302
+ # Options for {QueryIndexManager#watch_indexes}
303
+ class WatchIndexes < ::Couchbase::Options::Base
304
+ attr_accessor :watch_primary # @return [Boolean]
305
+ attr_accessor :scope_name # @return [String, nil]
306
+ attr_accessor :collection_name # @return [String, nil]
307
+
308
+ # Creates an instance of options for {QueryIndexManager#watch_indexes}
309
+ #
310
+ # @param [Boolean] watch_primary whether or not to watch the primary index
311
+ # @param [String, nil] scope_name the name of the scope
312
+ # @param [String, nil] collection_name the name of the collection
313
+ #
314
+ # @param [Symbol, nil] retry_strategy ignored by this operation
315
+ # @param [Hash, nil] client_context the client context data, if set
316
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
317
+ #
318
+ # @yieldparam [GetAllScopes] self
319
+ def initialize(watch_primary: false,
320
+ scope_name: nil,
321
+ collection_name: nil,
322
+ retry_strategy: nil,
323
+ client_context: nil,
324
+ parent_span: nil)
325
+ super(timeout: nil, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
326
+ @watch_primary = watch_primary
327
+ @scope_name = scope_name
328
+ @collection_name = collection_name
329
+ yield self if block_given?
330
+ end
331
+
332
+ # @api private
333
+ def to_backend
334
+ {
335
+ watch_primary: @watch_primary,
336
+ scope_name: @scope_name,
337
+ collection_name: @collection_name,
338
+ }
339
+ end
340
+ end
341
+
342
+ # rubocop:disable Naming/MethodName -- constructor shortcuts
343
+ module_function
344
+
345
+ # Construct {GetAllIndexes} options for {QueryIndexManager#get_all_indexes}
346
+ #
347
+ # @return [GetAllIndexes]
348
+ def GetAllIndexes(**args)
349
+ GetAllIndexes.new(**args)
350
+ end
351
+
352
+ # Construct {CreateIndex} options for {QueryIndexManager#create_index}
353
+ #
354
+ # @return [CreateIndex]
355
+ def CreateIndex(**args)
356
+ CreateIndex.new(**args)
357
+ end
358
+
359
+ # Construct {CreatePrimaryIndex} options for {QueryIndexManager#create_index}
360
+ #
361
+ # @return [CreatePrimaryIndex]
362
+ def CreatePrimaryIndex(**args)
363
+ CreatePrimaryIndex.new(**args)
364
+ end
365
+
366
+ # Construct {DropIndex} options for {QueryIndexManager#drop_index}
367
+ #
368
+ # @return [DropIndex]
369
+ def DropIndex(**args)
370
+ DropIndex.new(**args)
371
+ end
372
+
373
+ # Construct {DropPrimaryIndex} options for {QueryIndexManager#drop_primary_index}
374
+ #
375
+ # @return [DropPrimaryIndex]
376
+ def DropPrimaryIndex(**args)
377
+ DropPrimaryIndex.new(**args)
378
+ end
379
+
380
+ # rubocop:enable Naming/MethodName
381
+ end
382
+ end
383
+
384
+ class QueryIndexManager
385
+ alias inspect to_s
386
+
387
+ # @param [Couchbase::Backend] backend
388
+ # @param [Couchbase::Observability::Wrapper] observability wrapper
389
+ #
390
+ # @api private
391
+ def initialize(backend, observability)
392
+ @backend = backend
393
+ @observability = observability
394
+ end
395
+
396
+ # Fetches all indexes from the server
397
+ #
398
+ # @param [String] bucket_name name of the bucket
399
+ # @param [Options::Query::GetAllIndexes] options
400
+ #
401
+ # @return [Array<QueryIndex>]
402
+ #
403
+ # @raise [ArgumentError]
404
+ def get_all_indexes(bucket_name, options = GetAllIndexOptions.new)
405
+ unless options.scope_name.nil? && options.collection_name.nil?
406
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
407
+ end
408
+
409
+ @observability.record_operation(Observability::OP_QM_GET_ALL_INDEXES, options.parent_span, self, :query) do |obs_handler|
410
+ obs_handler.add_bucket_name(bucket_name)
411
+ obs_handler.add_scope_name(options.scope_name) unless options.scope_name.nil?
412
+ obs_handler.add_collection_name(options.collection_name) unless options.collection_name.nil?
413
+
414
+ res = @backend.query_index_get_all(bucket_name, options.to_backend, obs_handler)
415
+ res[:indexes].map do |idx|
416
+ QueryIndex.new do |index|
417
+ index.name = idx[:name]
418
+ index.is_primary = idx[:is_primary]
419
+ index.type = idx[:type]
420
+ index.state = idx[:state]
421
+ index.bucket = idx[:bucket_name]
422
+ index.scope = idx[:scope_name]
423
+ index.collection = idx[:collection_name]
424
+ index.index_key = idx[:index_key]
425
+ index.condition = idx[:condition]
426
+ index.partition = idx[:partition]
427
+ end
428
+ end
429
+ end
430
+ end
431
+
432
+ # Creates a new index
433
+ #
434
+ # @param [String] bucket_name name of the bucket
435
+ # @param [String] index_name name of the index
436
+ # @param [Array<String>] fields the lists of fields to create th index over
437
+ # @param [Options::Query::CreateIndex] options
438
+ #
439
+ # @return void
440
+ #
441
+ # @raise [ArgumentError]
442
+ # @raise [Error::IndexExists]
443
+ def create_index(bucket_name, index_name, fields, options = Options::Query::CreateIndex.new)
444
+ unless options.scope_name.nil? && options.collection_name.nil?
445
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
446
+ end
447
+
448
+ @observability.record_operation(Observability::OP_QM_CREATE_INDEX, options.parent_span, self, :query) do |obs_handler|
449
+ obs_handler.add_bucket_name(bucket_name)
450
+ obs_handler.add_scope_name(options.scope_name) unless options.scope_name.nil?
451
+ obs_handler.add_collection_name(options.collection_name) unless options.collection_name.nil?
452
+
453
+ @backend.query_index_create(bucket_name, index_name, fields, options.to_backend, obs_handler)
454
+ end
455
+ end
456
+
457
+ # Creates new primary index
458
+ #
459
+ # @param [String] bucket_name name of the bucket
460
+ # @param [Options::Query::CreatePrimaryIndex] options
461
+ #
462
+ # @return void
463
+ #
464
+ # @raise [ArgumentError]
465
+ # @raise [Error::IndexExists]
466
+ def create_primary_index(bucket_name, options = Options::Query::CreatePrimaryIndex.new)
467
+ unless options.scope_name.nil? && options.collection_name.nil?
468
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
469
+ end
470
+
471
+ @observability.record_operation(Observability::OP_QM_CREATE_PRIMARY_INDEX, options.parent_span, self, :query) do |obs_handler|
472
+ obs_handler.add_bucket_name(bucket_name)
473
+ obs_handler.add_scope_name(options.scope_name) unless options.scope_name.nil?
474
+ obs_handler.add_collection_name(options.collection_name) unless options.collection_name.nil?
475
+
476
+ @backend.query_index_create_primary(bucket_name, options.to_backend, obs_handler)
477
+ end
478
+ end
479
+
480
+ # Drops the index
481
+ #
482
+ # @param [String] bucket_name name of the bucket
483
+ # @param [String] index_name name of the index
484
+ # @param [Options::Query::DropIndex] options
485
+ #
486
+ # @return void
487
+ #
488
+ # @raise [ArgumentError]
489
+ # @raise [Error::IndexNotFound]
490
+ def drop_index(bucket_name, index_name, options = Options::Query::DropIndex.new)
491
+ unless options.scope_name.nil? && options.collection_name.nil?
492
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
493
+ end
494
+
495
+ @observability.record_operation(Observability::OP_QM_DROP_INDEX, options.parent_span, self, :query) do |obs_handler|
496
+ obs_handler.add_bucket_name(bucket_name)
497
+ obs_handler.add_scope_name(options.scope_name) unless options.scope_name.nil?
498
+ obs_handler.add_collection_name(options.collection_name) unless options.collection_name.nil?
499
+
500
+ @backend.query_index_drop(bucket_name, index_name, options.to_backend, obs_handler)
501
+ end
502
+ end
503
+
504
+ # Drops the primary index
505
+ #
506
+ # @param [String] bucket_name name of the bucket
507
+ # @param [Options::Query::DropPrimaryIndex] options
508
+ #
509
+ # @return void
510
+ #
511
+ # @raise [ArgumentError]
512
+ # @raise [Error::IndexNotFound]
513
+ def drop_primary_index(bucket_name, options = Options::Query::DropPrimaryIndex.new)
514
+ unless options.scope_name.nil? && options.collection_name.nil?
515
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
516
+ end
517
+
518
+ @observability.record_operation(Observability::OP_QM_DROP_PRIMARY_INDEX, options.parent_span, self, :query) do |obs_handler|
519
+ obs_handler.add_bucket_name(bucket_name)
520
+ obs_handler.add_scope_name(options.scope_name) unless options.scope_name.nil?
521
+ obs_handler.add_collection_name(options.collection_name) unless options.collection_name.nil?
522
+
523
+ @backend.query_index_drop_primary(bucket_name, options.to_backend, obs_handler)
524
+ end
525
+ end
526
+
527
+ # Build all indexes which are currently in deferred state
528
+ #
529
+ # @param [String] bucket_name name of the bucket
530
+ # @param [Options::Query::BuildDeferredIndexes] options
531
+ #
532
+ # @return
533
+ #
534
+ # @raise [ArgumentError]
535
+ def build_deferred_indexes(bucket_name, options = Options::Query::BuildDeferredIndexes.new)
536
+ unless options.scope_name.nil? && options.collection_name.nil?
537
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
538
+ end
539
+
540
+ @observability.record_operation(Observability::OP_QM_BUILD_DEFERRED_INDEXES, options.parent_span, self, :query) do |obs_handler|
541
+ obs_handler.add_bucket_name(bucket_name)
542
+ obs_handler.add_scope_name(options.scope_name) unless options.scope_name.nil?
543
+ obs_handler.add_collection_name(options.collection_name) unless options.collection_name.nil?
544
+
545
+ @backend.query_index_build_deferred(bucket_name, options.to_backend, obs_handler)
546
+ end
547
+ end
548
+
549
+ # Polls indexes until they are online
550
+ #
551
+ # @param [String] bucket_name name of the bucket
552
+ # @param [Array<String>] index_names names of the indexes to watch
553
+ # @param [Integer, #in_milliseconds] timeout the time in milliseconds allowed for the operation to complete
554
+ # @param [Options::Query::WatchIndexes] options
555
+ #
556
+ # @raise [ArgumentError]
557
+ # @raise [Error::IndexNotFound]
558
+ def watch_indexes(bucket_name, index_names, timeout, options = Options::Query::WatchIndexes.new)
559
+ unless options.scope_name.nil? && options.collection_name.nil?
560
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
561
+ end
562
+
563
+ @observability.record_operation(Observability::OP_QM_WATCH_INDEXES, options.parent_span, self, :query) do |obs_handler|
564
+ obs_handler.add_bucket_name(bucket_name)
565
+ obs_handler.add_scope_name(options.scope_name) unless options.scope_name.nil?
566
+ obs_handler.add_collection_name(options.collection_name) unless options.collection_name.nil?
567
+
568
+ index_names.append("#primary") if options.watch_primary
569
+
570
+ interval_millis = 50
571
+ deadline = Time.now + (Utils::Time.extract_duration(timeout) * 0.001)
572
+ all_online = false
573
+ while Time.now <= deadline
574
+ get_all_opts = Options::Query::GetAllIndexes.new(
575
+ timeout: ((deadline - Time.now) * 1000).round,
576
+ scope_name: options.scope_name,
577
+ collection_name: options.collection_name,
578
+ parent_span: obs_handler.op_span,
579
+ )
580
+ indexes = get_all_indexes(bucket_name, get_all_opts).select { |idx| index_names.include? idx.name }
581
+ indexes_not_found = index_names - indexes.map(&:name)
582
+ raise Error::IndexNotFound, "Failed to find the indexes: #{indexes_not_found.join(', ')}" unless indexes_not_found.empty?
583
+
584
+ all_online = indexes.all? { |idx| idx.state == :online }
585
+ break if all_online
586
+
587
+ sleep(interval_millis / 1000)
588
+ interval_millis += 500
589
+ interval_millis = 1000 if interval_millis > 1000
590
+ end
591
+ raise Error::UnambiguousTimeout, "Failed to find all indexes online within the allotted time" unless all_online
592
+ end
593
+ end
594
+
595
+ # @api private
596
+ # TODO: deprecate after 3.2
597
+ GetAllIndexOptions = ::Couchbase::Management::Options::Query::GetAllIndexes
598
+
599
+ # @api private
600
+ # TODO: deprecate after 3.2
601
+ CreateIndexOptions = ::Couchbase::Management::Options::Query::CreateIndex
602
+
603
+ # @api private
604
+ # TODO: deprecate after 3.2
605
+ CreatePrimaryIndexOptions = ::Couchbase::Management::Options::Query::CreatePrimaryIndex
606
+
607
+ # @api private
608
+ # TODO: deprecate after 3.2
609
+ DropIndexOptions = ::Couchbase::Management::Options::Query::DropIndex
610
+
611
+ # @api private
612
+ # TODO: deprecate after 3.2
613
+ DropPrimaryIndexOptions = ::Couchbase::Management::Options::Query::DropPrimaryIndex
614
+
615
+ # @api private
616
+ # TODO: deprecate after 3.2
617
+ BuildDeferredIndexOptions = ::Couchbase::Management::Options::Query::BuildDeferredIndexes
618
+
619
+ # @api private
620
+ # TODO: deprecate after 3.2
621
+ WatchIndexesOptions = ::Couchbase::Management::Options::Query::WatchIndexes
622
+ end
623
+
624
+ class QueryIndex
625
+ # @return [String] name of the index
626
+ attr_accessor :name
627
+
628
+ # @return [Boolean] true if this is a primary index
629
+ attr_accessor :is_primary
630
+ alias primary? is_primary
631
+
632
+ # @return [:gsi, :view] type of the index
633
+ attr_accessor :type
634
+
635
+ # @return [Symbol] state
636
+ attr_accessor :state
637
+
638
+ # @return [String, nil] the name of the bucket
639
+ attr_accessor :bucket
640
+
641
+ # @return [String, nil] the name of the scope
642
+ attr_accessor :scope
643
+
644
+ # @return [String, nil] the name of the collection
645
+ attr_accessor :collection
646
+
647
+ # @return [Array<String>] an array of Strings that represent the index key(s). The array is empty in the case of a
648
+ # PRIMARY INDEX.
649
+ #
650
+ # @note the query service can present the key in a slightly different manner from when you declared the index: for
651
+ # instance, it will show the indexed fields in an escaped format (surrounded by backticks).
652
+ attr_accessor :index_key
653
+
654
+ # @return [String] the string representation of the index's condition (the WHERE clause of the index),
655
+ # or an empty Optional if no condition was set.
656
+ #
657
+ # @note that the query service can present the condition in a slightly different manner from when you declared the
658
+ # index. For instance it will wrap expressions with parentheses and show the fields in an escaped format
659
+ # (surrounded by backticks).
660
+ attr_accessor :condition
661
+
662
+ # @return [String] the string representation of the index's partition
663
+ attr_accessor :partition
664
+
665
+ # @yieldparam [QueryIndex] self
666
+ def initialize
667
+ yield self if block_given?
668
+ end
669
+ end
670
+ end
671
+ end