mongo 2.13.0.beta1 → 2.13.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -5
- data/Rakefile +15 -9
- data/lib/mongo.rb +4 -2
- data/lib/mongo/auth/aws/request.rb +4 -2
- data/lib/mongo/bulk_write.rb +1 -0
- data/lib/mongo/client.rb +143 -21
- data/lib/mongo/cluster.rb +53 -17
- data/lib/mongo/cluster/sdam_flow.rb +13 -10
- data/lib/mongo/cluster/topology/replica_set_no_primary.rb +3 -2
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/cluster/topology/single.rb +1 -1
- data/lib/mongo/collection.rb +17 -13
- data/lib/mongo/collection/view/readable.rb +3 -1
- data/lib/mongo/collection/view/writable.rb +41 -5
- data/lib/mongo/database.rb +31 -4
- data/lib/mongo/database/view.rb +19 -4
- data/lib/mongo/distinguishing_semaphore.rb +55 -0
- data/lib/mongo/error.rb +1 -0
- data/lib/mongo/error/invalid_session.rb +2 -1
- data/lib/mongo/error/operation_failure.rb +6 -0
- data/lib/mongo/error/sessions_not_supported.rb +35 -0
- data/lib/mongo/event/base.rb +6 -0
- data/lib/mongo/grid/file.rb +5 -0
- data/lib/mongo/grid/file/chunk.rb +2 -0
- data/lib/mongo/grid/fs_bucket.rb +15 -13
- data/lib/mongo/grid/stream/write.rb +9 -3
- data/lib/mongo/monitoring.rb +38 -0
- data/lib/mongo/monitoring/command_log_subscriber.rb +10 -2
- data/lib/mongo/monitoring/event/command_failed.rb +11 -0
- data/lib/mongo/monitoring/event/command_started.rb +37 -2
- data/lib/mongo/monitoring/event/command_succeeded.rb +11 -0
- data/lib/mongo/monitoring/event/server_closed.rb +1 -1
- data/lib/mongo/monitoring/event/server_description_changed.rb +27 -4
- data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +9 -2
- data/lib/mongo/monitoring/event/server_heartbeat_started.rb +9 -2
- data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +9 -2
- data/lib/mongo/monitoring/event/server_opening.rb +1 -1
- data/lib/mongo/monitoring/event/topology_changed.rb +1 -1
- data/lib/mongo/monitoring/event/topology_closed.rb +1 -1
- data/lib/mongo/monitoring/event/topology_opening.rb +1 -1
- data/lib/mongo/monitoring/publishable.rb +6 -3
- data/lib/mongo/monitoring/server_description_changed_log_subscriber.rb +9 -1
- data/lib/mongo/monitoring/topology_changed_log_subscriber.rb +1 -1
- data/lib/mongo/protocol/message.rb +36 -8
- data/lib/mongo/protocol/msg.rb +14 -0
- data/lib/mongo/protocol/serializers.rb +5 -2
- data/lib/mongo/server.rb +10 -3
- data/lib/mongo/server/connection.rb +4 -4
- data/lib/mongo/server/connection_base.rb +3 -1
- data/lib/mongo/server/description.rb +5 -0
- data/lib/mongo/server/monitor.rb +76 -44
- data/lib/mongo/server/monitor/connection.rb +55 -7
- data/lib/mongo/server/pending_connection.rb +14 -4
- data/lib/mongo/server/push_monitor.rb +173 -0
- data/{spec/runners/transactions/context.rb → lib/mongo/server/push_monitor/connection.rb} +9 -14
- data/lib/mongo/server_selector.rb +0 -1
- data/lib/mongo/server_selector/base.rb +579 -1
- data/lib/mongo/server_selector/nearest.rb +1 -6
- data/lib/mongo/server_selector/primary.rb +1 -6
- data/lib/mongo/server_selector/primary_preferred.rb +7 -10
- data/lib/mongo/server_selector/secondary.rb +1 -6
- data/lib/mongo/server_selector/secondary_preferred.rb +1 -7
- data/lib/mongo/session.rb +2 -0
- data/lib/mongo/socket.rb +20 -8
- data/lib/mongo/socket/ssl.rb +1 -1
- data/lib/mongo/socket/tcp.rb +1 -1
- data/lib/mongo/topology_version.rb +9 -0
- data/lib/mongo/utils.rb +62 -0
- data/lib/mongo/version.rb +1 -1
- data/spec/README.aws-auth.md +2 -2
- data/spec/integration/awaited_ismaster_spec.rb +28 -0
- data/spec/integration/change_stream_examples_spec.rb +6 -2
- data/spec/integration/check_clean_slate_spec.rb +16 -0
- data/spec/integration/client_construction_spec.rb +1 -0
- data/spec/integration/connect_single_rs_name_spec.rb +5 -2
- data/spec/integration/connection_spec.rb +7 -4
- data/spec/integration/crud_spec.rb +4 -4
- data/spec/integration/docs_examples_spec.rb +6 -0
- data/spec/integration/grid_fs_bucket_spec.rb +48 -0
- data/spec/integration/heartbeat_events_spec.rb +4 -23
- data/spec/integration/read_concern_spec.rb +1 -1
- data/spec/integration/retryable_errors_spec.rb +1 -1
- data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +2 -2
- data/spec/integration/retryable_writes/shared/performs_modern_retries.rb +3 -3
- data/spec/integration/retryable_writes/shared/performs_no_retries.rb +2 -2
- data/spec/integration/sdam_error_handling_spec.rb +37 -15
- data/spec/integration/sdam_events_spec.rb +77 -6
- data/spec/integration/sdam_prose_spec.rb +64 -0
- data/spec/integration/server_monitor_spec.rb +25 -1
- data/spec/integration/size_limit_spec.rb +7 -3
- data/spec/integration/size_limit_spec.rb~12e1e9c4f... RUBY-2242 Fix zlib compression (#2021) +98 -0
- data/spec/integration/ssl_uri_options_spec.rb +2 -2
- data/spec/integration/zlib_compression_spec.rb +25 -0
- data/spec/lite_spec_helper.rb +12 -5
- data/spec/mongo/auth/aws/request_spec.rb +76 -0
- data/spec/mongo/auth/scram_spec.rb +1 -1
- data/spec/mongo/client_construction_spec.rb +207 -0
- data/spec/mongo/client_spec.rb +38 -3
- data/spec/mongo/cluster/topology/replica_set_spec.rb +52 -9
- data/spec/mongo/cluster/topology/single_spec.rb +4 -2
- data/spec/mongo/cluster_spec.rb +34 -35
- data/spec/mongo/collection/view/change_stream_resume_spec.rb +6 -6
- data/spec/mongo/collection_spec.rb +500 -0
- data/spec/mongo/database_spec.rb +245 -8
- data/spec/mongo/distinguishing_semaphore_spec.rb +63 -0
- data/spec/mongo/error/operation_failure_spec.rb +40 -0
- data/spec/mongo/index/view_spec.rb +2 -2
- data/spec/mongo/monitoring/event/server_description_changed_spec.rb +1 -4
- data/spec/mongo/protocol/msg_spec.rb +10 -0
- data/spec/mongo/semaphore_spec.rb +51 -0
- data/spec/mongo/server/connection_auth_spec.rb +2 -2
- data/spec/mongo/server_selector/nearest_spec.rb +23 -23
- data/spec/mongo/server_selector/primary_preferred_spec.rb +26 -26
- data/spec/mongo/server_selector/primary_spec.rb +9 -9
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +22 -22
- data/spec/mongo/server_selector/secondary_spec.rb +18 -18
- data/spec/mongo/server_selector_spec.rb +4 -4
- data/spec/mongo/session_spec.rb +35 -0
- data/spec/runners/change_streams/test.rb +2 -2
- data/spec/runners/cmap.rb +1 -1
- data/spec/runners/command_monitoring.rb +3 -34
- data/spec/runners/crud/context.rb +9 -5
- data/spec/runners/crud/operation.rb +59 -27
- data/spec/runners/crud/spec.rb +0 -8
- data/spec/runners/crud/test.rb +1 -1
- data/spec/runners/sdam.rb +2 -2
- data/spec/runners/server_selection.rb +242 -28
- data/spec/runners/transactions.rb +12 -12
- data/spec/runners/transactions/operation.rb +151 -25
- data/spec/runners/transactions/test.rb +60 -16
- data/spec/spec_tests/command_monitoring_spec.rb +22 -12
- data/spec/spec_tests/crud_spec.rb +1 -1
- data/spec/spec_tests/data/change_streams/change-streams-errors.yml +4 -8
- data/spec/spec_tests/data/change_streams/change-streams-resume-whitelist.yml +66 -0
- data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/MaxStalenessTooSmall.yml +15 -0
- data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/NoKnownServers.yml +4 -3
- data/spec/spec_tests/data/max_staleness/Unknown/SmallMaxStaleness.yml +1 -0
- data/spec/spec_tests/data/sdam_integration/cancel-server-check.yml +96 -0
- data/spec/spec_tests/data/sdam_integration/connectTimeoutMS.yml +88 -0
- data/spec/spec_tests/data/sdam_integration/find-network-error.yml +83 -0
- data/spec/spec_tests/data/sdam_integration/find-shutdown-error.yml +116 -0
- data/spec/spec_tests/data/sdam_integration/insert-network-error.yml +86 -0
- data/spec/spec_tests/data/sdam_integration/insert-shutdown-error.yml +115 -0
- data/spec/spec_tests/data/sdam_integration/isMaster-command-error.yml +168 -0
- data/spec/spec_tests/data/sdam_integration/isMaster-network-error.yml +162 -0
- data/spec/spec_tests/data/sdam_integration/isMaster-timeout.yml +229 -0
- data/spec/spec_tests/data/sdam_integration/rediscover-quickly-after-step-down.yml +87 -0
- data/spec/spec_tests/max_staleness_spec.rb +4 -142
- data/spec/spec_tests/retryable_reads_spec.rb +2 -2
- data/spec/spec_tests/sdam_integration_spec.rb +13 -0
- data/spec/spec_tests/sdam_monitoring_spec.rb +1 -2
- data/spec/spec_tests/server_selection_spec.rb +4 -116
- data/spec/stress/cleanup_spec.rb +17 -2
- data/spec/stress/connection_pool_stress_spec.rb +10 -8
- data/spec/support/child_process_helper.rb +78 -0
- data/spec/support/client_registry.rb +1 -0
- data/spec/support/cluster_config.rb +4 -0
- data/spec/support/event_subscriber.rb +123 -33
- data/spec/support/keyword_struct.rb +26 -0
- data/spec/support/shared/server_selector.rb +13 -1
- data/spec/support/spec_config.rb +38 -13
- data/spec/support/spec_organizer.rb +129 -0
- data/spec/support/spec_setup.rb +1 -1
- data/spec/support/utils.rb +46 -0
- metadata +992 -942
- metadata.gz.sig +0 -0
- data/lib/mongo/server_selector/selectable.rb +0 -560
- data/spec/runners/sdam_monitoring.rb +0 -89
@@ -20,7 +20,6 @@ module Mongo
|
|
20
20
|
#
|
21
21
|
# @since 2.0.0
|
22
22
|
class Nearest < Base
|
23
|
-
include Selectable
|
24
23
|
|
25
24
|
# Name of the this read preference in the server's format.
|
26
25
|
#
|
@@ -92,14 +91,10 @@ module Mongo
|
|
92
91
|
# Select the near servers taking into account any defined tag sets and
|
93
92
|
# local threshold between the nearest server and other servers.
|
94
93
|
#
|
95
|
-
# @example Select nearest servers given a list of candidates.
|
96
|
-
# preference = Mongo::ServerSelector::Nearest.new
|
97
|
-
# preference.select_server(cluster)
|
98
|
-
#
|
99
94
|
# @return [ Array ] The nearest servers from the list of candidates.
|
100
95
|
#
|
101
96
|
# @since 2.0.0
|
102
|
-
def
|
97
|
+
def select_in_replica_set(candidates)
|
103
98
|
matching_servers = filter_stale_servers(candidates, primary(candidates).first)
|
104
99
|
matching_servers = match_tag_sets(matching_servers) unless tag_sets.empty?
|
105
100
|
near_servers(matching_servers)
|
@@ -21,7 +21,6 @@ module Mongo
|
|
21
21
|
#
|
22
22
|
# @since 2.0.0
|
23
23
|
class Primary < Base
|
24
|
-
include Selectable
|
25
24
|
|
26
25
|
# Name of the this read preference in the server's format.
|
27
26
|
#
|
@@ -94,14 +93,10 @@ module Mongo
|
|
94
93
|
|
95
94
|
# Select the primary server from a list of candidates.
|
96
95
|
#
|
97
|
-
# @example Select the primary server given a list of candidates.
|
98
|
-
# preference = Mongo::ServerSelector::Primary.new
|
99
|
-
# preference.select([candidate_1, candidate_2])
|
100
|
-
#
|
101
96
|
# @return [ Array ] The primary server from the list of candidates.
|
102
97
|
#
|
103
98
|
# @since 2.0.0
|
104
|
-
def
|
99
|
+
def select_in_replica_set(candidates)
|
105
100
|
primary(candidates)
|
106
101
|
end
|
107
102
|
|
@@ -21,7 +21,6 @@ module Mongo
|
|
21
21
|
#
|
22
22
|
# @since 2.0.0
|
23
23
|
class PrimaryPreferred < Base
|
24
|
-
include Selectable
|
25
24
|
|
26
25
|
# Name of the this read preference in the server's format.
|
27
26
|
#
|
@@ -93,19 +92,17 @@ module Mongo
|
|
93
92
|
# Select servers taking into account any defined tag sets and
|
94
93
|
# local threshold, with the primary preferred.
|
95
94
|
#
|
96
|
-
# @example Select servers given a list of candidates,
|
97
|
-
# with the primary preferred.
|
98
|
-
# preference = Mongo::ServerSelector::PrimaryPreferred.new
|
99
|
-
# preference.select([candidate_1, candidate_2])
|
100
|
-
#
|
101
95
|
# @return [ Array ] A list of servers matching tag sets and acceptable
|
102
96
|
# latency with the primary preferred.
|
103
97
|
#
|
104
98
|
# @since 2.0.0
|
105
|
-
def
|
106
|
-
|
107
|
-
|
108
|
-
|
99
|
+
def select_in_replica_set(candidates)
|
100
|
+
primaries = primary(candidates)
|
101
|
+
if primaries.first
|
102
|
+
primaries
|
103
|
+
else
|
104
|
+
near_servers(secondaries(candidates))
|
105
|
+
end
|
109
106
|
end
|
110
107
|
|
111
108
|
def max_staleness_allowed?
|
@@ -21,7 +21,6 @@ module Mongo
|
|
21
21
|
#
|
22
22
|
# @since 2.0.0
|
23
23
|
class Secondary < Base
|
24
|
-
include Selectable
|
25
24
|
|
26
25
|
# Name of the this read preference in the server's format.
|
27
26
|
#
|
@@ -93,14 +92,10 @@ module Mongo
|
|
93
92
|
# Select the secondary servers taking into account any defined tag sets and
|
94
93
|
# local threshold between the nearest secondary and other secondaries.
|
95
94
|
#
|
96
|
-
# @example Select secondary servers given a list of candidates.
|
97
|
-
# preference = Mongo::ServerSelector::Secondary.new
|
98
|
-
# preference.select([candidate_1, candidate_2])
|
99
|
-
#
|
100
95
|
# @return [ Array ] The secondary servers from the list of candidates.
|
101
96
|
#
|
102
97
|
# @since 2.0.0
|
103
|
-
def
|
98
|
+
def select_in_replica_set(candidates)
|
104
99
|
near_servers(secondaries(candidates))
|
105
100
|
end
|
106
101
|
|
@@ -21,7 +21,6 @@ module Mongo
|
|
21
21
|
#
|
22
22
|
# @since 2.0.0
|
23
23
|
class SecondaryPreferred < Base
|
24
|
-
include Selectable
|
25
24
|
|
26
25
|
# Name of the this read preference in the server's format.
|
27
26
|
#
|
@@ -101,16 +100,11 @@ module Mongo
|
|
101
100
|
# Select servers taking into account any defined tag sets and
|
102
101
|
# local threshold, with secondaries.
|
103
102
|
#
|
104
|
-
# @example Select servers given a list of candidates,
|
105
|
-
# with secondaries preferred.
|
106
|
-
# preference = Mongo::ServerSelector::SecondaryPreferred.new
|
107
|
-
# preference.select([candidate_1, candidate_2])
|
108
|
-
#
|
109
103
|
# @return [ Array ] A list of servers matching tag sets and acceptable
|
110
104
|
# latency with secondaries preferred.
|
111
105
|
#
|
112
106
|
# @since 2.0.0
|
113
|
-
def
|
107
|
+
def select_in_replica_set(candidates)
|
114
108
|
near_servers(secondaries(candidates)) + primary(candidates)
|
115
109
|
end
|
116
110
|
|
data/lib/mongo/session.rb
CHANGED
@@ -227,7 +227,9 @@ module Mongo
|
|
227
227
|
# Error message describing that sessions are not supported by the server version.
|
228
228
|
#
|
229
229
|
# @since 2.5.0
|
230
|
+
# @deprecated
|
230
231
|
SESSIONS_NOT_SUPPORTED = 'Sessions are not supported by the connected servers.'.freeze
|
232
|
+
# Note: SESSIONS_NOT_SUPPORTED is used by Mongoid - do not remove from driver.
|
231
233
|
|
232
234
|
# The state of a session in which the last operation was not related to
|
233
235
|
# any transaction or no operations have yet occurred.
|
data/lib/mongo/socket.rb
CHANGED
@@ -21,6 +21,7 @@ module Mongo
|
|
21
21
|
# Provides additional data around sockets for the driver's use.
|
22
22
|
#
|
23
23
|
# @since 2.0.0
|
24
|
+
# @api private
|
24
25
|
class Socket
|
25
26
|
include ::Socket::Constants
|
26
27
|
|
@@ -105,9 +106,14 @@ module Mongo
|
|
105
106
|
def summary
|
106
107
|
fileno = @socket&.fileno rescue '<no socket>' || '<no socket>'
|
107
108
|
if monitor?
|
108
|
-
|
109
|
+
indicator = if options[:push]
|
110
|
+
'pm'
|
111
|
+
else
|
112
|
+
'm'
|
113
|
+
end
|
114
|
+
"#{connection_address};#{indicator};fd=#{fileno}"
|
109
115
|
else
|
110
|
-
"#{connection_address}
|
116
|
+
"#{connection_address};c:#{connection_generation};fd=#{fileno}"
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
@@ -173,20 +179,21 @@ module Mongo
|
|
173
179
|
# socket.read(4096)
|
174
180
|
#
|
175
181
|
# @param [ Integer ] length The number of bytes to read.
|
182
|
+
# @param [ Numeric ] timeout The timeout to use for each chunk read.
|
176
183
|
#
|
177
184
|
# @raise [ Mongo::SocketError ] If not all data is returned.
|
178
185
|
#
|
179
186
|
# @return [ Object ] The data from the socket.
|
180
187
|
#
|
181
188
|
# @since 2.0.0
|
182
|
-
def read(length)
|
189
|
+
def read(length, timeout: nil)
|
183
190
|
map_exceptions do
|
184
|
-
data = read_from_socket(length)
|
191
|
+
data = read_from_socket(length, timeout: timeout)
|
185
192
|
unless (data.length > 0 || length == 0)
|
186
193
|
raise IOError, "Expected to read > 0 bytes but read 0 bytes"
|
187
194
|
end
|
188
195
|
while data.length < length
|
189
|
-
chunk = read_from_socket(length - data.length)
|
196
|
+
chunk = read_from_socket(length - data.length, timeout: timeout)
|
190
197
|
unless (chunk.length > 0 || length == 0)
|
191
198
|
raise IOError, "Expected to read > 0 bytes but read 0 bytes"
|
192
199
|
end
|
@@ -243,14 +250,19 @@ module Mongo
|
|
243
250
|
|
244
251
|
private
|
245
252
|
|
246
|
-
def read_from_socket(length)
|
253
|
+
def read_from_socket(length, timeout: nil)
|
247
254
|
# Just in case
|
248
255
|
if length == 0
|
249
256
|
return ''.force_encoding('BINARY')
|
250
257
|
end
|
251
258
|
|
252
|
-
|
253
|
-
|
259
|
+
_timeout = timeout || self.timeout
|
260
|
+
if _timeout
|
261
|
+
if _timeout > 0
|
262
|
+
deadline = Time.now + _timeout
|
263
|
+
elsif _timeout < 0
|
264
|
+
raise Errno::ETIMEDOUT, "Negative timeout #{_timeout} given to socket"
|
265
|
+
end
|
254
266
|
end
|
255
267
|
|
256
268
|
# We want to have a fixed and reasonably small size buffer for reads
|
data/lib/mongo/socket/ssl.rb
CHANGED
@@ -137,7 +137,7 @@ module Mongo
|
|
137
137
|
#
|
138
138
|
# @since 2.0.0
|
139
139
|
def connect!
|
140
|
-
Timeout.timeout(options[:connect_timeout], Error::SocketTimeoutError) do
|
140
|
+
Timeout.timeout(options[:connect_timeout], Error::SocketTimeoutError, "The socket took over #{options[:connect_timeout]} seconds to connect") do
|
141
141
|
map_exceptions do
|
142
142
|
@tcp_socket.connect(::Socket.pack_sockaddr_in(port, host))
|
143
143
|
end
|
data/lib/mongo/socket/tcp.rb
CHANGED
@@ -74,7 +74,7 @@ module Mongo
|
|
74
74
|
#
|
75
75
|
# @since 2.0.0
|
76
76
|
def connect!
|
77
|
-
Timeout.timeout(options[:connect_timeout], Error::SocketTimeoutError) do
|
77
|
+
Timeout.timeout(options[:connect_timeout], Error::SocketTimeoutError, "The socket took over #{options[:connect_timeout]} seconds to connect") do
|
78
78
|
socket.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
|
79
79
|
map_exceptions do
|
80
80
|
socket.connect(::Socket.pack_sockaddr_in(port, host))
|
@@ -76,5 +76,14 @@ module Mongo
|
|
76
76
|
counter >= other.counter
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
# Converts the object to a document suitable for being sent to the server.
|
81
|
+
#
|
82
|
+
# @return [ BSON::Document ] The document.
|
83
|
+
#
|
84
|
+
# @api private
|
85
|
+
def to_doc
|
86
|
+
BSON::Document.new(self).merge(counter: BSON::Int64.new(counter))
|
87
|
+
end
|
79
88
|
end
|
80
89
|
end
|
data/lib/mongo/utils.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Copyright (C) 2020 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
|
+
|
17
|
+
# @api private
|
18
|
+
module Utils
|
19
|
+
|
20
|
+
class LocalLogger
|
21
|
+
include Loggable
|
22
|
+
|
23
|
+
def initialize(**opts)
|
24
|
+
@options = opts
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :options
|
28
|
+
end
|
29
|
+
|
30
|
+
# @option opts [ true | false | nil | Integer ] :bg_error_backtrace
|
31
|
+
# Experimental. Set to true to log complete backtraces for errors in
|
32
|
+
# background threads. Set to false or nil to not log backtraces. Provide
|
33
|
+
# a positive integer to log up to that many backtrace lines.
|
34
|
+
# @option opts [ Logger ] :logger A custom logger to use.
|
35
|
+
# @option opts [ String ] :log_prefix A custom log prefix to use when
|
36
|
+
# logging.
|
37
|
+
module_function def warn_monitor_exception(msg, exc, **opts)
|
38
|
+
bt_excerpt = excerpt_backtrace(exc, **opts)
|
39
|
+
logger = LocalLogger.new(**opts)
|
40
|
+
logger.log_warn("#{msg}: #{exc.class}: #{exc}#{bt_excerpt}")
|
41
|
+
end
|
42
|
+
|
43
|
+
# @option opts [ true | false | nil | Integer ] :bg_error_backtrace
|
44
|
+
# Experimental. Set to true to log complete backtraces for errors in
|
45
|
+
# background threads. Set to false or nil to not log backtraces. Provide
|
46
|
+
# a positive integer to log up to that many backtrace lines.
|
47
|
+
module_function def excerpt_backtrace(exc, **opts)
|
48
|
+
case lines = opts[:bg_error_backtrace]
|
49
|
+
when Integer
|
50
|
+
":\n#{exc.backtrace[0..lines].join("\n")}"
|
51
|
+
when false, nil
|
52
|
+
nil
|
53
|
+
else
|
54
|
+
":\n#{exc.backtrace.join("\n")}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module_function def shallow_symbolize_keys(hash)
|
59
|
+
Hash[hash.map { |k, v| [k.to_sym, v] }]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/mongo/version.rb
CHANGED
data/spec/README.aws-auth.md
CHANGED
@@ -233,7 +233,7 @@ To provision the instance for running the driver's test suite via Docker, run:
|
|
233
233
|
To run the AWS auth tests using the EC2 instance role credentials, run:
|
234
234
|
|
235
235
|
./.evergreen/test-docker-remote ubuntu@$ip \
|
236
|
-
MONGODB_VERSION=4.
|
236
|
+
MONGODB_VERSION=4.4 AUTH=aws-ec2 \
|
237
237
|
-s .evergreen/run-tests-aws-auth.sh \
|
238
238
|
-a .env.private
|
239
239
|
|
@@ -299,7 +299,7 @@ If the public IP address is in the `IP` shell variable, provision the task:
|
|
299
299
|
|
300
300
|
To run the credentials retrieval test on the ECS task, execute:
|
301
301
|
|
302
|
-
./.evergreen/test-remote root@$IP env AUTH=aws-ecs RVM_RUBY=ruby-2.7 MONGODB_VERSION=4.
|
302
|
+
./.evergreen/test-remote root@$IP env AUTH=aws-ecs RVM_RUBY=ruby-2.7 MONGODB_VERSION=4.4 TEST_CMD='rspec spec/integration/aws*spec.rb' .evergreen/run-tests.sh
|
303
303
|
|
304
304
|
To run the test again without rebuilding the remote environment, execute:
|
305
305
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'awaited ismaster' do
|
4
|
+
min_server_fcv '4.4'
|
5
|
+
|
6
|
+
# If we send the consecutive ismasters to different mongoses,
|
7
|
+
# they have different process ids, and so the awaited one would return
|
8
|
+
# immediately.
|
9
|
+
require_no_multi_shard
|
10
|
+
|
11
|
+
let(:client) { authorized_client }
|
12
|
+
|
13
|
+
it 'waits' do
|
14
|
+
# Perform a regular ismaster to get topology version
|
15
|
+
resp = client.database.command(ismaster: 1)
|
16
|
+
doc = resp.replies.first.documents.first
|
17
|
+
tv = Mongo::TopologyVersion.new(doc['topologyVersion'])
|
18
|
+
tv.should be_a(BSON::Document)
|
19
|
+
|
20
|
+
elapsed_time = Benchmark.realtime do
|
21
|
+
resp = client.database.command(ismaster: 1,
|
22
|
+
topologyVersion: tv.to_doc, maxAwaitTimeMS: 500)
|
23
|
+
end
|
24
|
+
doc = resp.replies.first.documents.first
|
25
|
+
|
26
|
+
elapsed_time.should > 0.5
|
27
|
+
end
|
28
|
+
end
|
@@ -174,8 +174,10 @@ describe 'change streams examples in Ruby' do
|
|
174
174
|
|
175
175
|
# Start Changestream Example 4
|
176
176
|
|
177
|
-
pipeline = [
|
178
|
-
|
177
|
+
pipeline = [
|
178
|
+
{ "$match" => { 'fullDocument.username' => 'alice' } },
|
179
|
+
{ "$addFields" => { 'newField' => 'this is an added field!' } }
|
180
|
+
];
|
179
181
|
cursor = inventory.watch(pipeline).to_enum
|
180
182
|
cursor.next
|
181
183
|
|
@@ -191,6 +193,8 @@ describe 'change streams examples in Ruby' do
|
|
191
193
|
expect(change['fullDocument']).not_to be_nil
|
192
194
|
expect(change['fullDocument']['_id']).not_to be_nil
|
193
195
|
expect(change['fullDocument']['username']).to eq('alice')
|
196
|
+
expect(change['newField']).not_to be_nil
|
197
|
+
expect(change['newField']).to eq('this is an added field!')
|
194
198
|
expect(change['ns']).not_to be_nil
|
195
199
|
expect(change['ns']['db']).to eq(SpecConfig.instance.test_db)
|
196
200
|
expect(change['ns']['coll']).to eq(inventory.name)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'lite_spec_helper'
|
2
|
+
|
3
|
+
# This test can be used to manually verify that there are no leaked
|
4
|
+
# background threads - execute it after executing another test (in the same
|
5
|
+
# rspec run) that is suspected to leak background threads, such as by
|
6
|
+
# running:
|
7
|
+
#
|
8
|
+
# rspec your_spec.rb spec/integration/check_clean_slate_spec.rb
|
9
|
+
|
10
|
+
describe 'Check clean slate' do
|
11
|
+
clean_slate_for_all_if_possible
|
12
|
+
|
13
|
+
it 'checks' do
|
14
|
+
# Nothing
|
15
|
+
end
|
16
|
+
end
|
@@ -18,7 +18,9 @@ describe 'Direct connection with RS name' do
|
|
18
18
|
new_local_client(
|
19
19
|
[SpecConfig.instance.addresses.first],
|
20
20
|
SpecConfig.instance.test_options.merge(
|
21
|
-
replica_set: replica_set_name, connect: :direct
|
21
|
+
replica_set: replica_set_name, connect: :direct,
|
22
|
+
server_selection_timeout: 3.32,
|
23
|
+
))
|
22
24
|
end
|
23
25
|
|
24
26
|
context 'in replica set' do
|
@@ -31,7 +33,8 @@ describe 'Direct connection with RS name' do
|
|
31
33
|
|
32
34
|
it 'creates a working client' do
|
33
35
|
expect do
|
34
|
-
client.database.command(ismaster: 1)
|
36
|
+
res = client.database.command(ismaster: 1)
|
37
|
+
p res
|
35
38
|
end.not_to raise_error
|
36
39
|
end
|
37
40
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'runners/sdam_monitoring'
|
3
2
|
|
4
3
|
describe 'Connections' do
|
5
4
|
clean_slate
|
@@ -26,6 +25,9 @@ describe 'Connections' do
|
|
26
25
|
# RSpec::Expectations::ExpectationNotMetError: expected Mongo::Error::SocketError, got #<NameError: undefined method `write' for class `Mongo::Socket'>
|
27
26
|
fails_on_jruby
|
28
27
|
|
28
|
+
# 4.4 has two monitors and thus our socket mocks get hit twice
|
29
|
+
max_server_version '4.2'
|
30
|
+
|
29
31
|
let(:exception) { Mongo::Error::SocketError }
|
30
32
|
|
31
33
|
let(:error) do
|
@@ -44,7 +46,8 @@ describe 'Connections' do
|
|
44
46
|
end
|
45
47
|
|
46
48
|
context 'with sdam event subscription' do
|
47
|
-
|
49
|
+
|
50
|
+
let(:subscriber) { EventSubscriber.new }
|
48
51
|
let(:client) do
|
49
52
|
ClientRegistry.instance.global_client('authorized').with(app_name: 'connection_integration').tap do |client|
|
50
53
|
client.subscribe(Mongo::Monitoring::SERVER_OPENING, subscriber)
|
@@ -56,12 +59,12 @@ describe 'Connections' do
|
|
56
59
|
end
|
57
60
|
|
58
61
|
it 'publishes server description changed event' do
|
59
|
-
expect(subscriber.
|
62
|
+
expect(subscriber.succeeded_events).to be_empty
|
60
63
|
|
61
64
|
wait_for_all_servers(client.cluster)
|
62
65
|
|
63
66
|
connection
|
64
|
-
subscriber.
|
67
|
+
subscriber.succeeded_events.clear
|
65
68
|
error
|
66
69
|
|
67
70
|
event = subscriber.first_event('server_description_changed_event')
|