mongo 2.10.1 → 2.10.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18e71f41caf0b6b8c618c8ea7cedb903ca10248949993c6c25ebf61d6acf3bba
4
- data.tar.gz: bd587a35aadbaf790b61c83867f276bd13858c6469fb8ef26bf3907e58a5703a
3
+ metadata.gz: d640dac0ce599ea7aa742522d55ead0bd20a2f3f4d9a8c632c28eb5090d38b44
4
+ data.tar.gz: cb6993b9aa97c89f93e6e4018aaa7f2f5de0473566162364d5f8beb6f49df2b8
5
5
  SHA512:
6
- metadata.gz: c923c55b783fb6d0a37d90116684afe65c038d1d7c06dfa1ace59a825eeee441ad7384f42ab45cb47bc7f2abedc16faef6f5f8adef68751631dcc57ddbca8be1
7
- data.tar.gz: bff45797b2533f2d842787c9c1d63eef76deab4471244af4d759237ab122b70d3c785d2ad064bf0b79e3d045c86efa5f6f7f47e4b8cdec5607b95ffd323400d3
6
+ metadata.gz: 11e03d68d1209e627911032bc2e818c77d100afde0f7b5b0b3166c4b52be2224f50299d086edbfb41b20151e5ea8985cb1c79b095047d72c313830836fd8b4b3
7
+ data.tar.gz: f450cba2ee21f571c4eb9e94029dc1d883158409fb9e7d2012633466b4445cb659264e0d2f971a0b3b96d699c631cc6d444e20ff5183a18a428b1ced7518f463
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/mongo/client.rb CHANGED
@@ -709,7 +709,7 @@ module Mongo
709
709
  cmd = { listDatabases: 1 }
710
710
  cmd[:nameOnly] = !!name_only
711
711
  cmd[:filter] = filter unless filter.empty?
712
- use(Database::ADMIN).command(cmd, opts).first[Database::DATABASES]
712
+ use(Database::ADMIN).database.read_command(cmd, opts).first[Database::DATABASES]
713
713
  end
714
714
 
715
715
  # Returns a list of Mongo::Database objects.
@@ -212,7 +212,7 @@ module Mongo
212
212
  #
213
213
  # @since 2.0.0
214
214
  def capped?
215
- database.command(:collstats => name).documents[0][CAPPED]
215
+ database.read_command(:collstats => name).documents[0][CAPPED]
216
216
  end
217
217
 
218
218
  # Force the collection to be created in the database.
@@ -159,6 +159,37 @@ module Mongo
159
159
  #
160
160
  # @return [ Hash ] The result of the command execution.
161
161
  def command(operation, opts = {})
162
+ txn_read_pref = if opts[:session] && opts[:session].in_transaction?
163
+ opts[:session].txn_read_preference
164
+ else
165
+ nil
166
+ end
167
+ txn_read_pref ||= opts[:read] || ServerSelector::PRIMARY
168
+ Lint.validate_underscore_read_preference(txn_read_pref)
169
+ selector = ServerSelector.get(txn_read_pref)
170
+
171
+ client.send(:with_session, opts) do |session|
172
+ server = selector.select_server(cluster, nil, session)
173
+ Operation::Command.new({
174
+ :selector => operation.dup,
175
+ :db_name => name,
176
+ :read => selector,
177
+ :session => session
178
+ }).execute(server)
179
+ end
180
+ end
181
+
182
+ # Execute a read command on the database, retrying the read if necessary.
183
+ #
184
+ # @param [ Hash ] operation The command to execute.
185
+ # @param [ Hash ] opts The command options.
186
+ #
187
+ # @option opts :read [ Hash ] The read preference for this command.
188
+ # @option opts :session [ Session ] The session to use for this command.
189
+ #
190
+ # @return [ Hash ] The result of the command execution.
191
+ # @api private
192
+ def read_command(operation, opts = {})
162
193
  txn_read_pref = if opts[:session] && opts[:session].in_transaction?
163
194
  opts[:session].txn_read_preference
164
195
  else
@@ -193,6 +193,12 @@ module Mongo
193
193
  servers = candidates(cluster)
194
194
  if Lint.enabled?
195
195
  servers.each do |server|
196
+ # It is possible for a server to have a nil average RTT here
197
+ # because the ARTT comes from description which may be updated
198
+ # by a background thread while server selection is running.
199
+ # Currently lint mode is not a public feature, if/when this
200
+ # changes (https://jira.mongodb.org/browse/RUBY-1576) the
201
+ # requirement for ARTT to be not nil would need to be removed.
196
202
  if server.average_round_trip_time.nil?
197
203
  raise Error::LintError, "Server #{server.address} has nil average rtt"
198
204
  end
@@ -361,11 +367,34 @@ module Mongo
361
367
  # @since 2.0.0
362
368
  def near_servers(candidates = [], local_threshold = nil)
363
369
  return candidates if candidates.empty?
364
- nearest_server = candidates.min_by(&:average_round_trip_time)
370
+
371
+ # Average RTT on any server may change at any time by the server
372
+ # monitor's background thread. ARTT may also become nil if the
373
+ # server is marked unknown. Take a snapshot of ARTTs for the duration
374
+ # of this method.
375
+
376
+ candidates = candidates.map do |server|
377
+ {server: server, artt: server.average_round_trip_time}
378
+ end.reject do |candidate|
379
+ candidate[:artt].nil?
380
+ end
381
+
382
+ return candidates if candidates.empty?
383
+
384
+ nearest_candidate = candidates.min_by do |candidate|
385
+ candidate[:artt]
386
+ end
387
+
365
388
  # Default for legacy signarure
366
389
  local_threshold ||= self.local_threshold
367
- threshold = nearest_server.average_round_trip_time + local_threshold
368
- candidates.select { |server| server.average_round_trip_time <= threshold }.shuffle!
390
+
391
+ threshold = nearest_candidate[:artt] + local_threshold
392
+
393
+ candidates.select do |candidate|
394
+ candidate[:artt] <= threshold
395
+ end.map do |candidate|
396
+ candidate[:server]
397
+ end.shuffle!
369
398
  end
370
399
 
371
400
  # Select the servers matching the defined tag sets.
data/lib/mongo/version.rb CHANGED
@@ -17,5 +17,5 @@ module Mongo
17
17
  # The current version of the driver.
18
18
  #
19
19
  # @since 2.0.0
20
- VERSION = '2.10.1'.freeze
20
+ VERSION = '2.10.2'.freeze
21
21
  end
@@ -737,4 +737,21 @@ describe 'Retryable writes integration tests' do
737
737
 
738
738
  it_behaves_like 'an operation that does not support retryable writes'
739
739
  end
740
+
741
+ context 'when the operation is database#command' do
742
+
743
+ let(:operation) do
744
+ collection.database.command(ping: 1)
745
+ end
746
+
747
+ let(:expectation) do
748
+ 0
749
+ end
750
+
751
+ let(:unsuccessful_retry_value) do
752
+ 0
753
+ end
754
+
755
+ it_behaves_like 'an operation that does not support retryable writes'
756
+ end
740
757
  end
@@ -564,4 +564,49 @@ describe Mongo::ServerSelector do
564
564
  it_behaves_like 'staleness filter'
565
565
  end
566
566
  end
567
+
568
+ describe '#candidates' do
569
+ let(:selector) { Mongo::ServerSelector::Primary.new(options) }
570
+
571
+ let(:cluster) { double('cluster') }
572
+
573
+ let(:options) { {} }
574
+
575
+ context 'sharded' do
576
+ let(:servers) do
577
+ [make_server(:mongos)]
578
+ end
579
+
580
+ before do
581
+ allow(cluster).to receive(:single?).and_return(false)
582
+ allow(cluster).to receive(:sharded?).and_return(true)
583
+ allow(cluster).to receive(:options).and_return({})
584
+ allow(cluster).to receive(:servers).and_return(servers)
585
+ end
586
+
587
+ it 'returns the servers' do
588
+ expect(selector.candidates(cluster)).to eq(servers)
589
+ end
590
+
591
+ context 'with local threshold' do
592
+ let(:options) do
593
+ {local_threshold: 1}
594
+ end
595
+
596
+ it 'returns the servers' do
597
+ expect(selector.candidates(cluster)).to eq(servers)
598
+ end
599
+
600
+ context 'when servers become unknown' do
601
+ let(:servers) do
602
+ [make_server(:unknown)]
603
+ end
604
+
605
+ it 'returns an empty list' do
606
+ expect(selector.candidates(cluster)).to eq([])
607
+ end
608
+ end
609
+ end
610
+ end
611
+ end
567
612
  end
@@ -74,7 +74,11 @@ module CommonShortcuts
74
74
 
75
75
  def make_server(mode, options = {})
76
76
  tags = options[:tags] || {}
77
- average_round_trip_time = options[:average_round_trip_time] || 0
77
+ average_round_trip_time = if mode == :unknown
78
+ nil
79
+ else
80
+ options[:average_round_trip_time] || 0
81
+ end
78
82
 
79
83
  if mode == :unknown
80
84
  ismaster = {}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.1
4
+ version: 2.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Brock
@@ -31,7 +31,7 @@ cert_chain:
31
31
  bMYVwXXhV8czdzgkQB/ZPWHSbEWXnmkze1mzvqWBCPOVXYrcnL9cnEl/RoxtS1hr
32
32
  Db6Ac6mCUSYfYHBWpWqxjc45n70i5Xi1
33
33
  -----END CERTIFICATE-----
34
- date: 2019-08-29 00:00:00.000000000 Z
34
+ date: 2019-09-23 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bson
metadata.gz.sig CHANGED
Binary file