mongo 2.7.0 → 2.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +39 -14
  5. data/Rakefile +1 -0
  6. data/lib/mongo/auth.rb +4 -1
  7. data/lib/mongo/client.rb +4 -3
  8. data/lib/mongo/cluster.rb +1 -1
  9. data/lib/mongo/collection/view/readable.rb +5 -2
  10. data/lib/mongo/database.rb +1 -0
  11. data/lib/mongo/error/invalid_server_preference.rb +1 -0
  12. data/lib/mongo/error/operation_failure.rb +10 -0
  13. data/lib/mongo/error/parser.rb +10 -0
  14. data/lib/mongo/event.rb +1 -2
  15. data/lib/mongo/operation/result.rb +4 -1
  16. data/lib/mongo/operation/shared/executable_transaction_label.rb +3 -1
  17. data/lib/mongo/operation/shared/sessions_supported.rb +1 -1
  18. data/lib/mongo/protocol/msg.rb +1 -1
  19. data/lib/mongo/protocol/query.rb +2 -2
  20. data/lib/mongo/retryable.rb +20 -6
  21. data/lib/mongo/server.rb +6 -0
  22. data/lib/mongo/server/connection.rb +4 -4
  23. data/lib/mongo/server/monitor/connection.rb +9 -5
  24. data/lib/mongo/server_selector/selectable.rb +86 -32
  25. data/lib/mongo/session.rb +98 -15
  26. data/lib/mongo/version.rb +1 -1
  27. data/spec/README.md +85 -0
  28. data/spec/integration/bulk_insert_spec.rb +1 -1
  29. data/spec/integration/change_stream_examples_spec.rb +3 -1
  30. data/spec/integration/change_stream_spec.rb +10 -14
  31. data/spec/integration/client_construction_spec.rb +1 -0
  32. data/spec/integration/command_monitoring_spec.rb +37 -1
  33. data/spec/integration/command_spec.rb +141 -0
  34. data/spec/integration/connection_spec.rb +4 -2
  35. data/spec/integration/cursor_reaping_spec.rb +1 -1
  36. data/spec/integration/docs_examples_spec.rb +1 -1
  37. data/spec/integration/retryable_writes_spec.rb +33 -42
  38. data/spec/integration/server_description_spec.rb +3 -3
  39. data/spec/integration/server_selector_spec.rb +79 -0
  40. data/spec/lite_spec_helper.rb +4 -2
  41. data/spec/mongo/address_spec.rb +8 -0
  42. data/spec/mongo/auth/cr_spec.rb +5 -2
  43. data/spec/mongo/auth/invalid_mechanism_spec.rb +11 -0
  44. data/spec/mongo/auth/scram/conversation_spec.rb +3 -2
  45. data/spec/mongo/auth/scram/negotiation_spec.rb +1 -2
  46. data/spec/mongo/auth/scram_spec.rb +11 -6
  47. data/spec/mongo/auth/user/view_spec.rb +13 -6
  48. data/spec/mongo/bulk_write_spec.rb +81 -104
  49. data/spec/mongo/client_construction_spec.rb +18 -7
  50. data/spec/mongo/client_spec.rb +11 -7
  51. data/spec/mongo/cluster_spec.rb +30 -1
  52. data/spec/mongo/collection/view/aggregation_spec.rb +18 -10
  53. data/spec/mongo/collection/view/change_stream_spec.rb +28 -8
  54. data/spec/mongo/collection/view/map_reduce_spec.rb +24 -10
  55. data/spec/mongo/collection/view/readable_spec.rb +37 -19
  56. data/spec/mongo/collection/view/writable_spec.rb +64 -32
  57. data/spec/mongo/collection/view_spec.rb +4 -2
  58. data/spec/mongo/collection_spec.rb +163 -73
  59. data/spec/mongo/cursor_spec.rb +5 -2
  60. data/spec/mongo/database_spec.rb +41 -19
  61. data/spec/mongo/error/no_server_available_spec.rb +1 -1
  62. data/spec/mongo/error/parser_spec.rb +29 -0
  63. data/spec/mongo/grid/stream/write_spec.rb +2 -1
  64. data/spec/mongo/index/view_spec.rb +42 -24
  65. data/spec/mongo/operation/delete/op_msg_spec.rb +11 -7
  66. data/spec/mongo/operation/insert/op_msg_spec.rb +10 -6
  67. data/spec/mongo/operation/update/op_msg_spec.rb +10 -6
  68. data/spec/mongo/protocol/compressed_spec.rb +1 -1
  69. data/spec/mongo/protocol/msg_spec.rb +1 -1
  70. data/spec/mongo/server/app_metadata_spec.rb +2 -1
  71. data/spec/mongo/server/connection_auth_spec.rb +1 -1
  72. data/spec/mongo/server/monitor/connection_spec.rb +42 -0
  73. data/spec/mongo/server_selector_spec.rb +17 -0
  74. data/spec/mongo/server_spec.rb +110 -0
  75. data/spec/mongo/session/session_pool_spec.rb +1 -1
  76. data/spec/mongo/session_spec.rb +1 -1
  77. data/spec/mongo/session_transaction_spec.rb +162 -1
  78. data/spec/mongo/socket/ssl_spec.rb +14 -7
  79. data/spec/mongo/uri/srv_protocol_spec.rb +41 -34
  80. data/spec/spec_helper.rb +3 -191
  81. data/spec/spec_tests/change_streams_spec.rb +3 -6
  82. data/spec/spec_tests/data/transactions/abort.yml +3 -1
  83. data/spec/spec_tests/data/transactions/commit.yml +4 -3
  84. data/spec/spec_tests/data/transactions/error-labels.yml +17 -13
  85. data/spec/spec_tests/data/transactions/read-concern.yml +611 -0
  86. data/spec/spec_tests/data/transactions/retryable-commit.yml +126 -21
  87. data/spec/spec_tests/data/transactions_api/callback-aborts.yml +42 -39
  88. data/spec/spec_tests/data/transactions_api/callback-commits.yml +52 -50
  89. data/spec/spec_tests/data/transactions_api/callback-retry.yml +33 -31
  90. data/spec/spec_tests/data/transactions_api/commit-retry.yml +42 -39
  91. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +13 -12
  92. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +15 -26
  93. data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +25 -33
  94. data/spec/spec_tests/data/transactions_api/commit.yml +44 -42
  95. data/spec/spec_tests/data/transactions_api/transaction-options.yml +25 -23
  96. data/spec/spec_tests/max_staleness_spec.rb +2 -0
  97. data/spec/spec_tests/retryable_writes_spec.rb +2 -6
  98. data/spec/spec_tests/sdam_spec.rb +2 -0
  99. data/spec/spec_tests/server_selection_spec.rb +3 -0
  100. data/spec/spec_tests/transactions_api_spec.rb +7 -1
  101. data/spec/spec_tests/transactions_spec.rb +6 -0
  102. data/spec/spec_tests/uri_options_spec.rb +4 -26
  103. data/spec/support/certificates/ca.pem +21 -16
  104. data/spec/support/certificates/client.pem +90 -90
  105. data/spec/support/certificates/client_cert.pem +21 -20
  106. data/spec/support/certificates/client_key.pem +27 -28
  107. data/spec/support/certificates/client_key_encrypted.pem +26 -26
  108. data/spec/support/certificates/crl.pem +10 -8
  109. data/spec/support/certificates/crl_client_revoked.pem +11 -10
  110. data/spec/support/certificates/server.pem +48 -33
  111. data/spec/support/change_streams.rb +12 -32
  112. data/spec/support/client_registry.rb +12 -1
  113. data/spec/support/cluster_config.rb +48 -2
  114. data/spec/support/common_shortcuts.rb +73 -7
  115. data/spec/support/connection_string.rb +0 -3
  116. data/spec/support/constraints.rb +87 -22
  117. data/spec/support/crud.rb +2 -1
  118. data/spec/support/shared/server_selector.rb +0 -28
  119. data/spec/support/shared/session.rb +25 -14
  120. data/spec/support/transactions.rb +4 -8
  121. data/spec/support/transactions/operation.rb +26 -4
  122. data/spec/support/transactions/verifier.rb +5 -2
  123. metadata +496 -488
  124. metadata.gz.sig +5 -2
  125. data/spec/support/certificates/password_protected.pem +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 214950396907cff6d304b018e77a65ced231d8afcb281efda921d077dc88ece7
4
- data.tar.gz: dcdec16fe1704883635275793cff2220fcce139d7df695e325c1cb0cbff040da
3
+ metadata.gz: f14ee6d7ece598841ae7a4a02261946837f515d4ce4106846ba33bda33756901
4
+ data.tar.gz: a574886854063a619a26581b45a963e57fb3e2f55c322cbf65329aa19559e7c9
5
5
  SHA512:
6
- metadata.gz: 1ae9252559ab6ffe1c9b30cea9928b6dd597364528686f009bd463b0a8612ddf0bd13f9d470d5e0f47cb47087e103d2d3a13a6c5717cc09ef7daa1865b5ececd
7
- data.tar.gz: a9c69b2c4f25828118560939851059775daf91b911d95d579c8e7b61f57e7a71dd8a8e102030b95cbc57f0123eb4adc83f8ceb7f6914bc99592e58da4ee8eae5
6
+ metadata.gz: 8c4898202c6b0982b353c1f569945cda95d726488bd632c3eb5270bc54a6f1f2f8608f2b6a0c4bec548192bed998e34a2c1381b8fe6095a0710113f47e2c9f7a
7
+ data.tar.gz: afff4ce90e7501db6eb63e111efb9814bfeec03aa171a6daf2dc2c4d3a9b621b0ea5161bf55ff8e3fc45548e86345baff35ee8f3038beb0ae53e5d19e6a6e207
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -2,24 +2,27 @@ MongoDB Ruby Driver [![Build Status][travis-img]][travis-url] [![Code Climate][c
2
2
  -----
3
3
  The officially supported Ruby driver for [MongoDB](http://www.mongodb.org).
4
4
 
5
+
5
6
  Documentation
6
- -----
7
+ -------------
7
8
 
8
9
  High level documentation and usage examples are located
9
10
  [here](http://docs.mongodb.org/ecosystem/drivers/ruby/).
10
11
 
11
12
  API docs can be found [here](http://api.mongodb.org/ruby/).
12
13
 
14
+
13
15
  Support & Feedback
14
- -----
16
+ ------------------
15
17
 
16
18
  For issues, questions or feedback related to the Ruby driver, please look into
17
19
  our [support channels](http://www.mongodb.org/about/support). Please
18
20
  do not email any of the Ruby developers directly with issues or
19
21
  questions - you're more likely to get an answer quickly on the [mongodb-user list](http://groups.google.com/group/mongodb-user) on Google Groups.
20
22
 
23
+
21
24
  Bugs & Feature Requests
22
- -----
25
+ -----------------------
23
26
 
24
27
  Do you have a bug to report or a feature request to make?
25
28
 
@@ -41,30 +44,52 @@ When reporting an issue, please keep in mind that all information in JIRA for al
41
44
  * Provide any sensitive data or server logs.
42
45
  * Report potential security issues publicly (see 'Security Issues').
43
46
 
47
+
48
+ Security Issues
49
+ ---------------
50
+
51
+ If you’ve identified a potential security related issue in a driver or any other
52
+ MongoDB project, please report it by following the [instructions here](http://docs.mongodb.org/manual/tutorial/create-a-vulnerability-report).
53
+
54
+
44
55
  Running Tests
45
- -----
56
+ -------------
46
57
 
47
- The driver uses RSpec as it's primary testing tool. To run all tests simple run `rspec`.
58
+ The driver uses RSpec as its primary testing tool. Most tests require a
59
+ running MongoDB server. To test the driver against a single-node (standalone)
60
+ deployment, first launch a server:
48
61
 
49
- If you need to run the tests without making any external connections, set the ENV variable EXTERNAL_DISABLED to 'true'.
62
+ mkdir /tmp/mrb
63
+ mongod --dbpath /tmp/mrb --bind_ip 127.0.0.1 --setParameter enableTestCommands=1
50
64
 
51
- To run a test at a specific location (where `42` is the line number), use:
65
+ ... then run the tests:
52
66
 
53
- rspec path/to/spec.rb:42
67
+ bundle exec rake
54
68
 
55
- Security Issues
56
- -----
69
+ It is possible to run tests in a specific file, as well as use other
70
+ test invocations supported by RSpec:
71
+
72
+ bundle exec rspec path/to/spec.rb:42
73
+
74
+ Note that certain user accounts have to be created for individual tests to
75
+ succeed, and they are not created when the individual tests are run. The
76
+ user accounts are created if you run `rake` as mentioned above, and you can
77
+ also create them by running:
78
+
79
+ bundle exec rake spec:prepare
80
+
81
+ For further information about supported cluster configurations and how to
82
+ configure the test suite, please see the README in the spec directory.
57
83
 
58
- If you’ve identified a potential security related issue in a driver or any other
59
- MongoDB project, please report it by following the [instructions here](http://docs.mongodb.org/manual/tutorial/create-a-vulnerability-report).
60
84
 
61
85
  Release History
62
- -----
86
+ ---------------
63
87
 
64
88
  Full release notes and release history are available [here](https://github.com/mongodb/mongo-ruby-driver/releases).
65
89
 
90
+
66
91
  License
67
- -----
92
+ -------
68
93
 
69
94
  Copyright (C) 2009-2019 MongoDB, Inc.
70
95
 
data/Rakefile CHANGED
@@ -25,6 +25,7 @@ end
25
25
  task :default => ['spec:prepare', :spec]
26
26
 
27
27
  namespace :spec do
28
+ desc 'Creates necessary user accounts in the cluster'
28
29
  task :prepare do
29
30
  $: << File.join(File.dirname(__FILE__), 'spec')
30
31
 
@@ -84,7 +84,10 @@ module Mongo
84
84
  #
85
85
  # @since 2.0.0
86
86
  def initialize(mechanism)
87
- super("#{mechanism.inspect} is invalid, please use mongodb_cr, mongodb_x509, gssapi or plain.")
87
+ known_mechanisms = SOURCES.keys.sort.map do |key|
88
+ key.inspect
89
+ end.join(', ')
90
+ super("#{mechanism.inspect} is invalid, please use one of the following mechanisms: #{known_mechanisms}")
88
91
  end
89
92
  end
90
93
 
@@ -589,10 +589,11 @@ module Mongo
589
589
  # @example Start a session.
590
590
  # client.start_session(causal_consistency: true)
591
591
  #
592
- # @param [ Hash ] options The session options.
592
+ # @param [ Hash ] options The session options. Accepts the options
593
+ # that Session#initialize accepts.
593
594
  #
594
- # @note A Session cannot be used by multiple threads at once; session objects are not
595
- # thread-safe.
595
+ # @note A Session cannot be used by multiple threads at once; session
596
+ # objects are not thread-safe.
596
597
  #
597
598
  # @return [ Session ] The session.
598
599
  #
@@ -337,7 +337,7 @@ module Mongo
337
337
  def summary
338
338
  "#<Cluster " +
339
339
  "topology=#{topology.summary} "+
340
- "servers=[#{servers.map(&:summary).join(',')}]>"
340
+ "servers=[#{servers_list.map(&:summary).join(',')}]>"
341
341
  end
342
342
 
343
343
  # @api private
@@ -122,6 +122,7 @@ module Mongo
122
122
  # command to run.
123
123
  # @option opts [ Hash ] :read The read preference options.
124
124
  # @option opts [ Hash ] :collation The collation to use.
125
+ # @option opts [ Mongo::Session ] :session The session to use for the operation.
125
126
  #
126
127
  # @return [ Integer ] The document count.
127
128
  #
@@ -182,8 +183,10 @@ module Mongo
182
183
  pipeline << { :'$limit' => opts[:limit] } if opts[:limit]
183
184
  pipeline << { :'$group' => { _id: nil, n: { :'$sum' => 1 } } }
184
185
 
185
- opts.select! { |k, _| [:hint, :max_time_ms, :read, :collation].include?(k) }
186
- aggregate(pipeline, opts).first['n'].to_i
186
+ opts.select! { |k, _| [:hint, :max_time_ms, :read, :collation, :session].include?(k) }
187
+ first = aggregate(pipeline, opts).first
188
+ return 0 unless first
189
+ first['n'].to_i
187
190
  end
188
191
 
189
192
  # Gets an estimate of the count of documents in a collection using collection metadata.
@@ -150,6 +150,7 @@ module Mongo
150
150
  # @param [ Hash ] opts The command options.
151
151
  #
152
152
  # @option opts :read [ Hash ] The read preference for this command.
153
+ # @option opts :session [ Session ] The session to use for this command.
153
154
  #
154
155
  # @return [ Hash ] The result of the command execution.
155
156
  def command(operation, opts = {})
@@ -33,6 +33,7 @@ module Mongo
33
33
  # Error message for when the max staleness is not at least twice the heartbeat frequency.
34
34
  #
35
35
  # @since 2.4.0
36
+ # @deprecated
36
37
  INVALID_MAX_STALENESS = "`max_staleness` value is too small. It must be at least " +
37
38
  "`ServerSelector::SMALLEST_MAX_STALENESS_SECONDS` and (the cluster's heartbeat_frequency " +
38
39
  "setting + `Cluster::IDLE_WRITE_PERIOD_SECONDS`).".freeze
@@ -182,8 +182,18 @@ module Mongo
182
182
  @code = options[:code]
183
183
  @code_name = options[:code_name]
184
184
  @labels = options[:labels]
185
+ @wtimeout = !!options[:wtimeout]
185
186
  super(message)
186
187
  end
188
+
189
+ # Whether the error was a write concern timeout.
190
+ #
191
+ # @return [ true | false ] Whether the error was a write concern timeout.
192
+ #
193
+ # @since 2.7.1
194
+ def wtimeout?
195
+ @wtimeout
196
+ end
187
197
  end
188
198
  end
189
199
  end
@@ -66,6 +66,9 @@ module Mongo
66
66
  # @since 2.7.0
67
67
  attr_reader :labels
68
68
 
69
+ # @api private
70
+ attr_reader :wtimeout
71
+
69
72
  # Create the new parser with the returned document.
70
73
  #
71
74
  # @example Create the new parser.
@@ -93,6 +96,7 @@ module Mongo
93
96
  parse_flag(@message)
94
97
  parse_code
95
98
  parse_labels
99
+ parse_wtimeout
96
100
  end
97
101
 
98
102
  def parse_single(message, key, doc = document)
@@ -156,6 +160,12 @@ module Mongo
156
160
  def parse_labels
157
161
  @labels = document['errorLabels'] || []
158
162
  end
163
+
164
+ def parse_wtimeout
165
+ @wtimeout = document[WRITE_CONCERN_ERROR] &&
166
+ document[WRITE_CONCERN_ERROR]['errInfo'] &&
167
+ document[WRITE_CONCERN_ERROR]['errInfo']['wtimeout']
168
+ end
159
169
  end
160
170
  end
161
171
  end
@@ -24,8 +24,7 @@ module Mongo
24
24
  # When a server is elected primary.
25
25
  #
26
26
  # @since 2.0.0
27
- #
28
- # @deprecated. Will be removed in 3.0
27
+ # @deprecated Will be removed in 3.0
29
28
  PRIMARY_ELECTED = 'primary_elected'.freeze
30
29
 
31
30
  # When a server is discovered to be a member of a topology.
@@ -267,7 +267,10 @@ module Mongo
267
267
  raise Error::OperationFailure.new(
268
268
  parser.message,
269
269
  self,
270
- :code => parser.code, :code_name => parser.code_name, :labels => parser.labels)
270
+ code: parser.code,
271
+ code_name: parser.code_name,
272
+ labels: parser.labels,
273
+ wtimeout: parser.wtimeout)
271
274
  end
272
275
  private :raise_operation_failure
273
276
 
@@ -26,7 +26,9 @@ module Mongo
26
26
  def execute(server)
27
27
  super
28
28
  rescue Mongo::Error::SocketError => e
29
- e.send(:add_label, Mongo::Error::TRANSIENT_TRANSACTION_ERROR_LABEL) if session.in_transaction?
29
+ if session && session.in_transaction?
30
+ e.send(:add_label, Mongo::Error::TRANSIENT_TRANSACTION_ERROR_LABEL)
31
+ end
30
32
  raise e
31
33
  end
32
34
  end
@@ -128,7 +128,7 @@ module Mongo
128
128
  end
129
129
 
130
130
  def command(server)
131
- sel = selector(server)
131
+ sel = selector(server).dup
132
132
  add_write_concern!(sel)
133
133
  sel[Protocol::Msg::DATABASE_IDENTIFIER] = db_name
134
134
  sel['$readPreference'] = read.to_doc if read
@@ -83,7 +83,7 @@ module Mongo
83
83
  # @since 2.5.0
84
84
  def payload
85
85
  BSON::Document.new(
86
- command_name: command.keys.first,
86
+ command_name: command.keys.first.to_s,
87
87
  database_name: global_args[DATABASE_IDENTIFIER],
88
88
  command: command,
89
89
  request_id: request_id,
@@ -269,11 +269,11 @@ module Mongo
269
269
  # @example Get the command name.
270
270
  # upconverter.command_name
271
271
  #
272
- # @return [ String, Symbol ] The command name.
272
+ # @return [ String ] The command name.
273
273
  #
274
274
  # @since 2.1.0
275
275
  def command_name
276
- (filter[:$query] || !command?) ? FIND : filter.keys.first
276
+ ((filter[:$query] || !command?) ? FIND : filter.keys.first).to_s
277
277
  end
278
278
 
279
279
  private
@@ -69,14 +69,19 @@ module Mongo
69
69
  #
70
70
  # @note This only retries read operations on socket errors.
71
71
  #
72
+ # @param [ Hash ] options Options.
72
73
  # @param [ Proc ] block The block to execute.
73
74
  #
75
+ # @option options [ String ] :retry_message Message to log when retrying.
76
+ #
74
77
  # @return [ Result ] The result of the operation.
75
78
  #
76
79
  # @since 2.2.6
77
- def read_with_one_retry
80
+ def read_with_one_retry(options = nil)
78
81
  yield
79
- rescue Error::SocketError, Error::SocketTimeoutError
82
+ rescue Error::SocketError, Error::SocketTimeoutError => e
83
+ retry_message = options && options[:retry_message]
84
+ log_retry(e, message: retry_message)
80
85
  yield
81
86
  end
82
87
 
@@ -102,6 +107,7 @@ module Mongo
102
107
  # @note This only retries operations on not master failures, since it is
103
108
  # the only case we can be sure a partial write did not already occur.
104
109
  #
110
+ # @param [ nil | Session ] session Optional session to use with the operation.
105
111
  # @param [ nil | Hash | WriteConcern::Base ] write_concern The write concern.
106
112
  # @param [ true | false ] ending_transaction True if the write operation is abortTransaction or
107
113
  # commitTransaction, false otherwise.
@@ -122,6 +128,9 @@ module Mongo
122
128
  return legacy_write_with_retry(nil, session, &block)
123
129
  end
124
130
 
131
+ # If we are here, session is not nil. A session being nil would have
132
+ # failed retry_write_allowed? check.
133
+
125
134
  server = cluster.next_primary
126
135
 
127
136
  unless ending_transaction || server.retry_writes?
@@ -130,7 +139,7 @@ module Mongo
130
139
 
131
140
  begin
132
141
  txn_num = session.in_transaction? ? session.txn_num : session.next_txn_num
133
- yield(server, txn_num)
142
+ yield(server, txn_num, false)
134
143
  rescue Error::SocketError, Error::SocketTimeoutError => e
135
144
  raise e if session.in_transaction? && !ending_transaction
136
145
  retry_write(e, txn_num, &block)
@@ -162,7 +171,7 @@ module Mongo
162
171
  server = cluster.next_primary
163
172
  raise original_error unless (server.retry_writes? && txn_num)
164
173
  log_retry(original_error)
165
- yield(server, txn_num)
174
+ yield(server, txn_num, true)
166
175
  rescue Error::SocketError, Error::SocketTimeoutError => e
167
176
  cluster.scan!(false)
168
177
  raise e
@@ -196,8 +205,13 @@ module Mongo
196
205
  end
197
206
 
198
207
  # Log a warning so that any application slow down is immediately obvious.
199
- def log_retry(e)
200
- Logger.logger.warn "Retry due to: #{e.class.name} #{e.message}"
208
+ def log_retry(e, options = nil)
209
+ message = if options && options[:message]
210
+ options[:message]
211
+ else
212
+ "Retry"
213
+ end
214
+ Logger.logger.warn "#{message} due to: #{e.class.name} #{e.message}"
201
215
  end
202
216
  end
203
217
  end
@@ -253,6 +253,12 @@ module Mongo
253
253
  'GHOST'
254
254
  when other?
255
255
  'OTHER'
256
+ when unknown?
257
+ 'UNKNOWN'
258
+ else
259
+ # Since the summary method is often used for debugging, do not raise
260
+ # an exception in case none of the expected types matched
261
+ ''
256
262
  end
257
263
  if replica_set_name
258
264
  status += " replica_set=#{replica_set_name}"
@@ -1,11 +1,11 @@
1
1
  # Copyright (C) 2014-2019 MongoDB, Inc.
2
-
2
+ #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
-
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
-
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -1,11 +1,11 @@
1
1
  # Copyright (C) 2015-2019 MongoDB, Inc.
2
-
2
+ #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
-
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
-
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -128,7 +128,7 @@ module Mongo
128
128
  # @since 2.2.0
129
129
  def ismaster
130
130
  ensure_connected do |socket|
131
- read_with_one_retry do
131
+ read_with_one_retry(retry_message: retry_message) do
132
132
  socket.write(ISMASTER_BYTES)
133
133
  Protocol::Message.deserialize(socket).documents[0]
134
134
  end
@@ -212,6 +212,10 @@ module Mongo
212
212
  reply
213
213
  end
214
214
  end
215
+
216
+ def retry_message
217
+ "Retrying ismaster on #{address}"
218
+ end
215
219
  end
216
220
  end
217
221
  end