mongo 2.10.5 → 2.11.0.rc0

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 (191) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/lib/mongo.rb +2 -0
  6. data/lib/mongo/address.rb +4 -0
  7. data/lib/mongo/address/validator.rb +99 -0
  8. data/lib/mongo/auth.rb +7 -2
  9. data/lib/mongo/auth/user.rb +1 -7
  10. data/lib/mongo/background_thread.rb +135 -0
  11. data/lib/mongo/bulk_write/transformable.rb +3 -3
  12. data/lib/mongo/client.rb +74 -16
  13. data/lib/mongo/cluster.rb +193 -41
  14. data/lib/mongo/cluster/periodic_executor.rb +31 -43
  15. data/lib/mongo/cluster/sdam_flow.rb +26 -3
  16. data/lib/mongo/cluster/srv_monitor.rb +127 -0
  17. data/lib/mongo/collection/view/readable.rb +3 -5
  18. data/lib/mongo/collection/view/writable.rb +3 -3
  19. data/lib/mongo/cursor/builder/get_more_command.rb +1 -4
  20. data/lib/mongo/cursor/builder/kill_cursors_command.rb +5 -23
  21. data/lib/mongo/cursor/builder/op_get_more.rb +2 -2
  22. data/lib/mongo/cursor/builder/op_kill_cursors.rb +5 -24
  23. data/lib/mongo/error.rb +1 -0
  24. data/lib/mongo/error/auth_error.rb +1 -1
  25. data/lib/mongo/error/connection_check_out_timeout.rb +7 -8
  26. data/lib/mongo/error/invalid_address.rb +24 -0
  27. data/lib/mongo/error/notable.rb +2 -2
  28. data/lib/mongo/error/operation_failure.rb +3 -3
  29. data/lib/mongo/error/pool_closed_error.rb +11 -4
  30. data/lib/mongo/event.rb +1 -1
  31. data/lib/mongo/grid/file.rb +0 -5
  32. data/lib/mongo/grid/file/chunk.rb +0 -2
  33. data/lib/mongo/grid/fs_bucket.rb +13 -15
  34. data/lib/mongo/grid/stream/write.rb +3 -9
  35. data/lib/mongo/loggable.rb +5 -1
  36. data/lib/mongo/monitoring.rb +1 -0
  37. data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +7 -0
  38. data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +11 -3
  39. data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +11 -3
  40. data/lib/mongo/monitoring/event/cmap/pool_closed.rb +11 -3
  41. data/lib/mongo/monitoring/event/cmap/pool_created.rb +12 -3
  42. data/lib/mongo/monitoring/unified_sdam_log_subscriber.rb +62 -0
  43. data/lib/mongo/operation/shared/executable.rb +5 -10
  44. data/lib/mongo/operation/shared/sessions_supported.rb +1 -5
  45. data/lib/mongo/protocol/get_more.rb +1 -2
  46. data/lib/mongo/protocol/kill_cursors.rb +13 -6
  47. data/lib/mongo/protocol/serializers.rb +4 -20
  48. data/lib/mongo/retryable.rb +9 -34
  49. data/lib/mongo/semaphore.rb +1 -1
  50. data/lib/mongo/server.rb +113 -42
  51. data/lib/mongo/server/connection.rb +12 -5
  52. data/lib/mongo/server/connection_pool.rb +250 -40
  53. data/lib/mongo/server/connection_pool/populator.rb +58 -0
  54. data/lib/mongo/server/description.rb +9 -2
  55. data/lib/mongo/server/monitor.rb +68 -93
  56. data/lib/mongo/server/monitor/connection.rb +2 -0
  57. data/lib/mongo/server_selector/selectable.rb +13 -5
  58. data/lib/mongo/session.rb +0 -13
  59. data/lib/mongo/srv.rb +17 -0
  60. data/lib/mongo/srv/monitor.rb +96 -0
  61. data/lib/mongo/srv/resolver.rb +130 -0
  62. data/lib/mongo/srv/result.rb +126 -0
  63. data/lib/mongo/srv/warning_result.rb +35 -0
  64. data/lib/mongo/uri.rb +45 -55
  65. data/lib/mongo/uri/srv_protocol.rb +89 -42
  66. data/lib/mongo/version.rb +1 -1
  67. data/mongo.gemspec +3 -4
  68. data/spec/README.md +6 -1
  69. data/spec/enterprise_auth/kerberos_spec.rb +7 -6
  70. data/spec/integration/change_stream_examples_spec.rb +0 -4
  71. data/spec/integration/client_construction_spec.rb +14 -2
  72. data/spec/integration/connect_single_rs_name_spec.rb +2 -2
  73. data/spec/integration/connection_pool_populator_spec.rb +296 -0
  74. data/spec/integration/connection_spec.rb +31 -22
  75. data/spec/integration/cursor_reaping_spec.rb +1 -2
  76. data/spec/integration/docs_examples_spec.rb +0 -4
  77. data/spec/integration/heartbeat_events_spec.rb +17 -15
  78. data/spec/integration/reconnect_spec.rb +144 -1
  79. data/spec/integration/retryable_writes_errors_spec.rb +0 -4
  80. data/spec/integration/retryable_writes_spec.rb +36 -36
  81. data/spec/integration/sdam_error_handling_spec.rb +31 -25
  82. data/spec/integration/sdam_events_spec.rb +2 -6
  83. data/spec/integration/server_monitor_spec.rb +28 -0
  84. data/spec/integration/server_selector_spec.rb +7 -5
  85. data/spec/integration/srv_monitoring_spec.rb +360 -0
  86. data/spec/integration/step_down_spec.rb +4 -6
  87. data/spec/lite_spec_helper.rb +22 -0
  88. data/spec/mongo/address/validator_spec.rb +51 -0
  89. data/spec/mongo/auth/cr_spec.rb +1 -29
  90. data/spec/mongo/auth/ldap_spec.rb +1 -29
  91. data/spec/mongo/auth/scram/conversation_spec.rb +0 -2
  92. data/spec/mongo/auth/scram/negotiation_spec.rb +1 -1
  93. data/spec/mongo/auth/scram_spec.rb +1 -29
  94. data/spec/mongo/auth/user/view_spec.rb +1 -36
  95. data/spec/mongo/auth/user_spec.rb +0 -12
  96. data/spec/mongo/auth/x509_spec.rb +1 -29
  97. data/spec/mongo/bulk_write_spec.rb +2 -2
  98. data/spec/mongo/client_construction_spec.rb +56 -15
  99. data/spec/mongo/client_spec.rb +31 -27
  100. data/spec/mongo/cluster/periodic_executor_spec.rb +16 -0
  101. data/spec/mongo/cluster/srv_monitor_spec.rb +214 -0
  102. data/spec/mongo/cluster/topology/replica_set_spec.rb +16 -11
  103. data/spec/mongo/cluster/topology/sharded_spec.rb +12 -9
  104. data/spec/mongo/cluster/topology/single_spec.rb +20 -11
  105. data/spec/mongo/cluster_spec.rb +45 -29
  106. data/spec/mongo/collection/view/map_reduce_spec.rb +14 -9
  107. data/spec/mongo/collection/view/readable_spec.rb +0 -16
  108. data/spec/mongo/collection_spec.rb +0 -44
  109. data/spec/mongo/cursor/builder/get_more_command_spec.rb +2 -4
  110. data/spec/mongo/cursor/builder/op_get_more_spec.rb +2 -4
  111. data/spec/mongo/cursor_spec.rb +27 -7
  112. data/spec/mongo/monitoring/event/cmap/connection_checked_in_spec.rb +10 -3
  113. data/spec/mongo/monitoring/event/cmap/connection_checked_out_spec.rb +10 -3
  114. data/spec/mongo/monitoring/event/cmap/pool_closed_spec.rb +10 -3
  115. data/spec/mongo/monitoring/event/cmap/pool_created_spec.rb +10 -3
  116. data/spec/mongo/operation/delete/op_msg_spec.rb +17 -8
  117. data/spec/mongo/operation/insert/op_msg_spec.rb +50 -35
  118. data/spec/mongo/operation/update/op_msg_spec.rb +14 -7
  119. data/spec/mongo/retryable_spec.rb +52 -31
  120. data/spec/mongo/server/app_metadata_spec.rb +0 -8
  121. data/spec/mongo/server/connection_auth_spec.rb +5 -2
  122. data/spec/mongo/server/connection_pool/populator_spec.rb +101 -0
  123. data/spec/mongo/server/connection_pool_spec.rb +256 -107
  124. data/spec/mongo/server/connection_spec.rb +22 -33
  125. data/spec/mongo/server/description_spec.rb +42 -4
  126. data/spec/mongo/server/monitor/connection_spec.rb +22 -11
  127. data/spec/mongo/server/monitor_spec.rb +66 -107
  128. data/spec/mongo/server_spec.rb +82 -60
  129. data/spec/mongo/session/session_pool_spec.rb +1 -5
  130. data/spec/mongo/session_spec.rb +0 -4
  131. data/spec/mongo/socket/ssl_spec.rb +2 -2
  132. data/spec/mongo/srv/monitor_spec.rb +211 -0
  133. data/spec/mongo/srv/result_spec.rb +54 -0
  134. data/spec/mongo/uri/srv_protocol_spec.rb +30 -15
  135. data/spec/mongo/uri_spec.rb +125 -4
  136. data/spec/spec_helper.rb +6 -0
  137. data/spec/spec_tests/auth_spec.rb +39 -0
  138. data/spec/spec_tests/cmap_spec.rb +55 -8
  139. data/spec/spec_tests/connection_string_spec.rb +6 -31
  140. data/spec/spec_tests/data/auth/connection-string.yml +297 -0
  141. data/spec/spec_tests/data/cmap/pool-checkout-error-closed.yml +4 -1
  142. data/spec/spec_tests/data/cmap/pool-create-with-options.yml +1 -0
  143. data/spec/spec_tests/data/command_monitoring/insertMany.yml +1 -1
  144. data/spec/spec_tests/data/connection_string/invalid-uris.yml +20 -0
  145. data/spec/spec_tests/data/connection_string/valid-auth.yml +16 -0
  146. data/spec/spec_tests/data/connection_string/valid-warnings.yml +26 -30
  147. data/spec/spec_tests/data/transactions/abort.yml +3 -3
  148. data/spec/spec_tests/data/transactions/error-labels.yml +3 -3
  149. data/spec/spec_tests/data/transactions_api/callback-retry.yml +3 -3
  150. data/spec/spec_tests/data/uri_options/auth-options.yml +1 -1
  151. data/spec/spec_tests/max_staleness_spec.rb +7 -2
  152. data/spec/spec_tests/retryable_reads_spec.rb +0 -31
  153. data/spec/spec_tests/sdam_monitoring_spec.rb +12 -12
  154. data/spec/spec_tests/sdam_spec.rb +4 -7
  155. data/spec/spec_tests/server_selection_spec.rb +6 -2
  156. data/spec/spec_tests/transactions_spec.rb +0 -2
  157. data/spec/spec_tests/uri_options_spec.rb +4 -2
  158. data/spec/stress/connection_pool_stress_spec.rb +203 -0
  159. data/spec/stress/connection_pool_timing_spec.rb +181 -0
  160. data/spec/support/auth.rb +113 -0
  161. data/spec/support/background_thread_registry.rb +63 -0
  162. data/spec/support/client_registry.rb +11 -2
  163. data/spec/support/cluster_config.rb +65 -46
  164. data/spec/support/cluster_tools.rb +2 -2
  165. data/spec/support/cmap.rb +13 -14
  166. data/spec/support/cmap/verifier.rb +4 -5
  167. data/spec/support/command_monitoring.rb +0 -5
  168. data/spec/support/common_shortcuts.rb +101 -1
  169. data/spec/support/constraints.rb +25 -0
  170. data/spec/support/dns.rb +13 -0
  171. data/spec/support/event_subscriber.rb +0 -7
  172. data/spec/support/json_ext_formatter.rb +5 -1
  173. data/spec/support/lite_constraints.rb +22 -6
  174. data/spec/support/local_resource_registry.rb +34 -0
  175. data/spec/support/sdam_monitoring.rb +115 -0
  176. data/spec/support/spec_config.rb +20 -6
  177. data/spec/support/spec_setup.rb +2 -2
  178. data/spec/support/transactions.rb +1 -1
  179. data/spec/support/transactions/test.rb +1 -1
  180. data/spec/support/utils.rb +1 -16
  181. metadata +685 -659
  182. metadata.gz.sig +0 -0
  183. data/lib/mongo/event/description_changed.rb +0 -52
  184. data/spec/integration/bson_symbol_spec.rb +0 -34
  185. data/spec/integration/crud_spec.rb +0 -45
  186. data/spec/integration/get_more_spec.rb +0 -32
  187. data/spec/integration/grid_fs_bucket_spec.rb +0 -48
  188. data/spec/integration/retryable_errors_spec.rb +0 -265
  189. data/spec/integration/size_limit_spec.rb~12e1e9c4f... RUBY-2242 Fix zlib compression (#2021) +0 -98
  190. data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +0 -56
  191. data/spec/runners/sdam/verifier.rb +0 -88
@@ -28,7 +28,7 @@ class Mongo::Cluster
28
28
  def initialize(cluster, previous_desc, updated_desc)
29
29
  @cluster = cluster
30
30
  @topology = cluster.topology
31
- @previous_desc = previous_desc
31
+ @original_desc = @previous_desc = previous_desc
32
32
  @updated_desc = updated_desc
33
33
  end
34
34
 
@@ -48,6 +48,7 @@ class Mongo::Cluster
48
48
 
49
49
  attr_reader :previous_desc
50
50
  attr_reader :updated_desc
51
+ attr_reader :original_desc
51
52
 
52
53
  def_delegators :topology, :replica_set_name
53
54
 
@@ -57,9 +58,11 @@ class Mongo::Cluster
57
58
  servers_list.each do |server|
58
59
  if server.address == updated_desc.address
59
60
  changed = server.description != updated_desc
60
- # Always update server description, so that fields like
61
- # last_update_time reflect the last ismaster response
61
+ # Always update server description, so that fields that do not
62
+ # affect description equality comparisons but are part of the
63
+ # description are updated.
62
64
  server.update_description(updated_desc)
65
+ server.update_last_scan
63
66
  # But return if there was a content difference between
64
67
  # descriptions, and if there wasn't we'll skip the remainder of
65
68
  # sdam flow
@@ -411,6 +414,7 @@ class Mongo::Cluster
411
414
  # not all processed together.
412
415
 
413
416
  publish_description_change_event
417
+ start_pool_if_data_bearing
414
418
 
415
419
  topology_changed_event_published = false
416
420
  if topology.object_id != cluster.topology.object_id || @need_topology_changed_event
@@ -447,6 +451,18 @@ class Mongo::Cluster
447
451
  cluster.update_topology(topology)
448
452
  end
449
453
 
454
+ # If the server being processed is identified as data bearing, creates the
455
+ # server's connection pool so it can start populating
456
+ def start_pool_if_data_bearing
457
+ return if !updated_desc.data_bearing?
458
+
459
+ servers_list.each do |server|
460
+ if server.address == @updated_desc.address
461
+ server.pool
462
+ end
463
+ end
464
+ end
465
+
450
466
  # Checks if the cluster has a primary, and if not, transitions the topology
451
467
  # to ReplicaSetNoPrimary. Topology must be ReplicaSetWithPrimary when
452
468
  # invoking this method.
@@ -477,5 +493,12 @@ class Mongo::Cluster
477
493
  end
478
494
  false
479
495
  end
496
+
497
+ # Returns whether the server whose description this flow processed
498
+ # was not previously unknown, and is now. Used to decide, in particular,
499
+ # whether to clear the server's connection pool.
500
+ def became_unknown?
501
+ updated_desc.unknown? && !original_desc.unknown?
502
+ end
480
503
  end
481
504
  end
@@ -0,0 +1,127 @@
1
+ # Copyright (C) 2019 MongoDB, 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
+ module Mongo
16
+ class Cluster
17
+
18
+ # Periodically retrieves SRV records for the cluster's SRV URI, and
19
+ # sets the cluster's server list to the SRV lookup result.
20
+ #
21
+ # If an error is encountered during SRV lookup or an SRV record is invalid
22
+ # or disallowed for security reasons, a warning is logged and monitoring
23
+ # continues.
24
+ #
25
+ # @api private
26
+ class SrvMonitor
27
+ include Loggable
28
+ include BackgroundThread
29
+
30
+ MIN_SCAN_INTERVAL = 60
31
+
32
+ DEFAULT_TIMEOUT = 10
33
+
34
+ # Creates the SRV monitor.
35
+ #
36
+ # @param [ Cluster ] cluster The cluster.
37
+ # @param [ Hash ] options The cluster options.
38
+ #
39
+ # @option options [ Float ] :timeout The timeout to use for DNS lookups.
40
+ # @option options [ URI::SRVProtocol ] :srv_uri The SRV URI to monitor.
41
+ # @option options [ Hash ] :resolv_options For internal driver use only.
42
+ # Options to pass through to Resolv::DNS constructor for SRV lookups.
43
+ def initialize(cluster, options = nil)
44
+ options = if options
45
+ options.dup
46
+ else
47
+ {}
48
+ end
49
+ @cluster = cluster
50
+ @resolver = Srv::Resolver.new(options)
51
+ unless @srv_uri = options.delete(:srv_uri)
52
+ raise ArgumentError, 'SRV URI is required'
53
+ end
54
+ @options = options.freeze
55
+ @last_result = @srv_uri.srv_result
56
+ @stop_semaphore = Semaphore.new
57
+ end
58
+
59
+ attr_reader :options
60
+
61
+ attr_reader :cluster
62
+
63
+ # @return [ Srv::Result ] Last known SRV lookup result. Used for
64
+ # determining intervals between SRV lookups, which depend on SRV DNS
65
+ # records' TTL values.
66
+ attr_reader :last_result
67
+
68
+ def start!
69
+ super
70
+ ObjectSpace.define_finalizer(self, self.class.finalize(@thread))
71
+ end
72
+
73
+ private
74
+
75
+ def do_work
76
+ scan!
77
+ @stop_semaphore.wait(scan_interval)
78
+ end
79
+
80
+ def scan!
81
+ old_hosts = last_result.address_strs
82
+
83
+ begin
84
+ last_result = Timeout.timeout(timeout) do
85
+ @resolver.get_records(@srv_uri.query_hostname)
86
+ end
87
+ rescue Resolv::ResolvTimeout => e
88
+ log_warn("SRV monitor: timed out trying to resolve hostname #{@srv_uri.query_hostname}: #{e.class}: #{e}")
89
+ return
90
+ rescue Timeout::Error
91
+ log_warn("SRV monitor: timed out trying to resolve hostname #{@srv_uri.query_hostname} (timeout=#{timeout})")
92
+ return
93
+ rescue Resolv::ResolvError => e
94
+ log_warn("SRV monitor: unable to resolve hostname #{@srv_uri.query_hostname}: #{e.class}: #{e}")
95
+ return
96
+ end
97
+
98
+ if last_result.empty?
99
+ log_warn("SRV monitor: hostname #{@srv_uri.query_hostname} resolved to zero records")
100
+ return
101
+ end
102
+
103
+ @cluster.set_server_list(last_result.address_strs)
104
+ end
105
+
106
+ def self.finalize(thread)
107
+ Proc.new do
108
+ thread.kill
109
+ end
110
+ end
111
+
112
+ def scan_interval
113
+ if last_result.empty?
114
+ [cluster.heartbeat_interval, MIN_SCAN_INTERVAL].min
115
+ elsif last_result.min_ttl.nil?
116
+ MIN_SCAN_INTERVAL
117
+ else
118
+ [last_result.min_ttl, MIN_SCAN_INTERVAL].max
119
+ end
120
+ end
121
+
122
+ def timeout
123
+ options[:timeout] || DEFAULT_TIMEOUT
124
+ end
125
+ end
126
+ end
127
+ end
@@ -185,9 +185,7 @@ module Mongo
185
185
  pipeline << { :'$limit' => opts[:limit] } if opts[:limit]
186
186
  pipeline << { :'$group' => { _id: 1, n: { :'$sum' => 1 } } }
187
187
 
188
- opts = opts.select { |k, _| [:hint, :max_time_ms, :read, :collation, :session].include?(k) }
189
- opts[:collation] ||= collation
190
-
188
+ opts.select! { |k, _| [:hint, :max_time_ms, :read, :collation, :session].include?(k) }
191
189
  first = aggregate(pipeline, opts).first
192
190
  return 0 unless first
193
191
  first['n'].to_i
@@ -604,7 +602,7 @@ module Mongo
604
602
  cmd.execute(server).cursor_ids.map do |cursor_id|
605
603
  result = if server.features.find_command_enabled?
606
604
  Operation::GetMore.new({
607
- :selector => {:getMore => BSON::Int64.new(cursor_id),
605
+ :selector => {:getMore => cursor_id,
608
606
  :collection => collection.name},
609
607
  :db_name => database.name,
610
608
  :session => session,
@@ -612,7 +610,7 @@ module Mongo
612
610
  else
613
611
  Operation::GetMore.new({
614
612
  :to_return => 0,
615
- :cursor_id => BSON::Int64.new(cursor_id),
613
+ :cursor_id => cursor_id,
616
614
  :db_name => database.name,
617
615
  :coll_name => collection.name
618
616
  }).execute(server)
@@ -232,7 +232,7 @@ module Mongo
232
232
  Operation::U => replacement,
233
233
  }
234
234
  if opts[:upsert]
235
- update_doc['upsert'] = true
235
+ update_doc[:upsert] = true
236
236
  end
237
237
  with_session(opts) do |session|
238
238
  write_concern = write_concern_with_session(session)
@@ -279,7 +279,7 @@ module Mongo
279
279
  Operation::MULTI => true,
280
280
  }
281
281
  if opts[:upsert]
282
- update_doc['upsert'] = true
282
+ update_doc[:upsert] = true
283
283
  end
284
284
  with_session(opts) do |session|
285
285
  write_concern = write_concern_with_session(session)
@@ -323,7 +323,7 @@ module Mongo
323
323
  Operation::U => spec,
324
324
  }
325
325
  if opts[:upsert]
326
- update_doc['upsert'] = true
326
+ update_doc[:upsert] = true
327
327
  end
328
328
  with_session(opts) do |session|
329
329
  write_concern = write_concern_with_session(session)
@@ -57,10 +57,7 @@ module Mongo
57
57
  private
58
58
 
59
59
  def get_more_command
60
- command = {
61
- :getMore => BSON::Int64.new(cursor.id),
62
- :collection => collection_name,
63
- }
60
+ command = { :getMore => cursor.id, :collection => collection_name }
64
61
  command[:batchSize] = batch_size.abs if batch_size && batch_size != 0
65
62
  # If the max_await_time_ms option is set, then we set maxTimeMS on
66
63
  # the get more command.
@@ -54,10 +54,7 @@ module Mongo
54
54
  private
55
55
 
56
56
  def kill_cursors_command
57
- {
58
- killCursors: collection_name,
59
- cursors: [ BSON::Int64.new(cursor.id) ],
60
- }
57
+ { :killCursors => collection_name, :cursors => [ cursor.id ] }
61
58
  end
62
59
 
63
60
  class << self
@@ -68,19 +65,11 @@ module Mongo
68
65
  # KillCursorsCommand.update_cursors(spec, ids)
69
66
  #
70
67
  # @return [ Hash ] The specification.
71
- # @return [ Array<Integer> ] The ids to update with.
68
+ # @return [ Array ] The ids to update with.
72
69
  #
73
70
  # @since 2.3.0
74
71
  def update_cursors(spec, ids)
75
- # Ruby 2.5+ can & BSON::Int64 instances.
76
- # Ruby 2.4 and earlier cannot.
77
- # Convert stored ids to Ruby integers for compatibility with
78
- # older Rubies.
79
- ids = get_cursors_list(spec) & ids
80
- ids = ids.map do |cursor_id|
81
- BSON::Int64.new(cursor_id)
82
- end
83
- spec[:selector].merge!(cursors: ids)
72
+ spec[:selector].merge!(cursors: spec[:selector][:cursors] & ids)
84
73
  end
85
74
 
86
75
  # Get the list of cursor ids from a spec generated by this Builder.
@@ -88,18 +77,11 @@ module Mongo
88
77
  # @example Get the list of cursor ids.
89
78
  # KillCursorsCommand.cursors(spec)
90
79
  #
91
- # @return [ Array<Integer> ] The cursor ids.
80
+ # @return [ Hash ] The specification.
92
81
  #
93
82
  # @since 2.3.0
94
83
  def get_cursors_list(spec)
95
- spec[:selector][:cursors].map do |value|
96
- if value.respond_to?(:value)
97
- # bson-ruby >= 4.6.0
98
- value = value.value
99
- else
100
- value = value.instance_variable_get('@integer')
101
- end
102
- end
84
+ spec[:selector][:cursors]
103
85
  end
104
86
  end
105
87
  end
@@ -50,9 +50,9 @@ module Mongo
50
50
  def specification
51
51
  {
52
52
  :to_return => to_return,
53
- :cursor_id => BSON::Int64.new(cursor.id),
53
+ :cursor_id => cursor.id,
54
54
  :db_name => database.name,
55
- :coll_name => collection_name,
55
+ :coll_name => collection_name
56
56
  }
57
57
  end
58
58
  end
@@ -48,11 +48,7 @@ module Mongo
48
48
  #
49
49
  # @since 2.2.0
50
50
  def specification
51
- {
52
- coll_name: collection_name,
53
- db_name: database.name,
54
- cursor_ids: [ BSON::Int64.new(cursor.id) ],
55
- }
51
+ { :coll_name => collection_name, :db_name => database.name, :cursor_ids => [ cursor.id ] }
56
52
  end
57
53
 
58
54
  class << self
@@ -63,19 +59,11 @@ module Mongo
63
59
  # OpKillCursors.update_cursors(spec, ids)
64
60
  #
65
61
  # @return [ Hash ] The specification.
66
- # @return [ Array<Integer> ] The ids to update with.
62
+ # @return [ Array ] The ids to update with.
67
63
  #
68
64
  # @since 2.3.0
69
65
  def update_cursors(spec, ids)
70
- # Ruby 2.5+ can & BSON::Int64 instances.
71
- # Ruby 2.4 and earlier cannot.
72
- # Convert stored ids to Ruby integers for compatibility with
73
- # older Rubies.
74
- ids = get_cursors_list(spec) & ids
75
- ids = ids.map do |cursor_id|
76
- BSON::Int64.new(cursor_id)
77
- end
78
- spec.merge!(cursor_ids: ids)
66
+ spec.merge!(cursor_ids: spec[:cursor_ids] & ids)
79
67
  end
80
68
 
81
69
  # Get the list of cursor ids from a spec generated by this Builder.
@@ -83,18 +71,11 @@ module Mongo
83
71
  # @example Get the list of cursor ids.
84
72
  # OpKillCursors.cursors(spec)
85
73
  #
86
- # @return [ Array<Integer> ] The cursor ids.
74
+ # @return [ Hash ] The specification.
87
75
  #
88
76
  # @since 2.3.0
89
77
  def get_cursors_list(spec)
90
- spec[:cursor_ids].map do |value|
91
- if value.respond_to?(:value)
92
- # bson-ruby >= 4.6.0
93
- value.value
94
- else
95
- value.instance_variable_get('@integer')
96
- end
97
- end
78
+ spec[:cursor_ids]
98
79
  end
99
80
  end
100
81
  end
data/lib/mongo/error.rb CHANGED
@@ -155,6 +155,7 @@ require 'mongo/error/connection_check_out_timeout'
155
155
  require 'mongo/error/extra_file_chunk'
156
156
  require 'mongo/error/file_not_found'
157
157
  require 'mongo/error/operation_failure'
158
+ require 'mongo/error/invalid_address'
158
159
  require 'mongo/error/invalid_bulk_operation'
159
160
  require 'mongo/error/invalid_bulk_operation_type'
160
161
  require 'mongo/error/invalid_collection_name'
@@ -21,7 +21,7 @@ module Mongo
21
21
  # backwards compatibility reasons. It is subject to
22
22
  # change in future major versions of the driver.
23
23
  #
24
- # @since 2.10.1
24
+ # @since 2.11.0
25
25
  class AuthError < RuntimeError
26
26
  include Notable
27
27
  end
@@ -33,16 +33,15 @@ module Mongo
33
33
 
34
34
  # Instantiate the new exception.
35
35
  #
36
- # @param [ Address ] address
37
- # @param [ Float ] wait_timeout
36
+ # @option options [ Address ] :address
38
37
  #
39
- # @since 2.9.0
40
38
  # @api private
41
- def initialize(address, wait_timeout)
42
- @address = address
43
-
44
- super("Timed out when attempting to check out a connection from pool with address " +
45
- "#{address} after #{wait_timeout} sec")
39
+ def initialize(msg, options)
40
+ super(msg)
41
+ @address = options[:address]
42
+ unless @address
43
+ raise ArgumentError, 'Address argument is required'
44
+ end
46
45
  end
47
46
  end
48
47
  end
@@ -0,0 +1,24 @@
1
+ # Copyright (C) 2019 MongoDB, 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
+ module Mongo
16
+ class Error
17
+
18
+ # Raised when validation of addresses in URIs and SRV records fails.
19
+ #
20
+ # @since 2.11.0
21
+ class InvalidAddress < Error
22
+ end
23
+ end
24
+ end