mongo 2.10.5 → 2.11.0.rc0
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 +0 -0
- data/CONTRIBUTING.md +1 -1
- data/lib/mongo.rb +2 -0
- data/lib/mongo/address.rb +4 -0
- data/lib/mongo/address/validator.rb +99 -0
- data/lib/mongo/auth.rb +7 -2
- data/lib/mongo/auth/user.rb +1 -7
- data/lib/mongo/background_thread.rb +135 -0
- data/lib/mongo/bulk_write/transformable.rb +3 -3
- data/lib/mongo/client.rb +74 -16
- data/lib/mongo/cluster.rb +193 -41
- data/lib/mongo/cluster/periodic_executor.rb +31 -43
- data/lib/mongo/cluster/sdam_flow.rb +26 -3
- data/lib/mongo/cluster/srv_monitor.rb +127 -0
- data/lib/mongo/collection/view/readable.rb +3 -5
- data/lib/mongo/collection/view/writable.rb +3 -3
- data/lib/mongo/cursor/builder/get_more_command.rb +1 -4
- data/lib/mongo/cursor/builder/kill_cursors_command.rb +5 -23
- data/lib/mongo/cursor/builder/op_get_more.rb +2 -2
- data/lib/mongo/cursor/builder/op_kill_cursors.rb +5 -24
- data/lib/mongo/error.rb +1 -0
- data/lib/mongo/error/auth_error.rb +1 -1
- data/lib/mongo/error/connection_check_out_timeout.rb +7 -8
- data/lib/mongo/error/invalid_address.rb +24 -0
- data/lib/mongo/error/notable.rb +2 -2
- data/lib/mongo/error/operation_failure.rb +3 -3
- data/lib/mongo/error/pool_closed_error.rb +11 -4
- data/lib/mongo/event.rb +1 -1
- data/lib/mongo/grid/file.rb +0 -5
- data/lib/mongo/grid/file/chunk.rb +0 -2
- data/lib/mongo/grid/fs_bucket.rb +13 -15
- data/lib/mongo/grid/stream/write.rb +3 -9
- data/lib/mongo/loggable.rb +5 -1
- data/lib/mongo/monitoring.rb +1 -0
- data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +7 -0
- data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +11 -3
- data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +11 -3
- data/lib/mongo/monitoring/event/cmap/pool_closed.rb +11 -3
- data/lib/mongo/monitoring/event/cmap/pool_created.rb +12 -3
- data/lib/mongo/monitoring/unified_sdam_log_subscriber.rb +62 -0
- data/lib/mongo/operation/shared/executable.rb +5 -10
- data/lib/mongo/operation/shared/sessions_supported.rb +1 -5
- data/lib/mongo/protocol/get_more.rb +1 -2
- data/lib/mongo/protocol/kill_cursors.rb +13 -6
- data/lib/mongo/protocol/serializers.rb +4 -20
- data/lib/mongo/retryable.rb +9 -34
- data/lib/mongo/semaphore.rb +1 -1
- data/lib/mongo/server.rb +113 -42
- data/lib/mongo/server/connection.rb +12 -5
- data/lib/mongo/server/connection_pool.rb +250 -40
- data/lib/mongo/server/connection_pool/populator.rb +58 -0
- data/lib/mongo/server/description.rb +9 -2
- data/lib/mongo/server/monitor.rb +68 -93
- data/lib/mongo/server/monitor/connection.rb +2 -0
- data/lib/mongo/server_selector/selectable.rb +13 -5
- data/lib/mongo/session.rb +0 -13
- data/lib/mongo/srv.rb +17 -0
- data/lib/mongo/srv/monitor.rb +96 -0
- data/lib/mongo/srv/resolver.rb +130 -0
- data/lib/mongo/srv/result.rb +126 -0
- data/lib/mongo/srv/warning_result.rb +35 -0
- data/lib/mongo/uri.rb +45 -55
- data/lib/mongo/uri/srv_protocol.rb +89 -42
- data/lib/mongo/version.rb +1 -1
- data/mongo.gemspec +3 -4
- data/spec/README.md +6 -1
- data/spec/enterprise_auth/kerberos_spec.rb +7 -6
- data/spec/integration/change_stream_examples_spec.rb +0 -4
- data/spec/integration/client_construction_spec.rb +14 -2
- data/spec/integration/connect_single_rs_name_spec.rb +2 -2
- data/spec/integration/connection_pool_populator_spec.rb +296 -0
- data/spec/integration/connection_spec.rb +31 -22
- data/spec/integration/cursor_reaping_spec.rb +1 -2
- data/spec/integration/docs_examples_spec.rb +0 -4
- data/spec/integration/heartbeat_events_spec.rb +17 -15
- data/spec/integration/reconnect_spec.rb +144 -1
- data/spec/integration/retryable_writes_errors_spec.rb +0 -4
- data/spec/integration/retryable_writes_spec.rb +36 -36
- data/spec/integration/sdam_error_handling_spec.rb +31 -25
- data/spec/integration/sdam_events_spec.rb +2 -6
- data/spec/integration/server_monitor_spec.rb +28 -0
- data/spec/integration/server_selector_spec.rb +7 -5
- data/spec/integration/srv_monitoring_spec.rb +360 -0
- data/spec/integration/step_down_spec.rb +4 -6
- data/spec/lite_spec_helper.rb +22 -0
- data/spec/mongo/address/validator_spec.rb +51 -0
- data/spec/mongo/auth/cr_spec.rb +1 -29
- data/spec/mongo/auth/ldap_spec.rb +1 -29
- data/spec/mongo/auth/scram/conversation_spec.rb +0 -2
- data/spec/mongo/auth/scram/negotiation_spec.rb +1 -1
- data/spec/mongo/auth/scram_spec.rb +1 -29
- data/spec/mongo/auth/user/view_spec.rb +1 -36
- data/spec/mongo/auth/user_spec.rb +0 -12
- data/spec/mongo/auth/x509_spec.rb +1 -29
- data/spec/mongo/bulk_write_spec.rb +2 -2
- data/spec/mongo/client_construction_spec.rb +56 -15
- data/spec/mongo/client_spec.rb +31 -27
- data/spec/mongo/cluster/periodic_executor_spec.rb +16 -0
- data/spec/mongo/cluster/srv_monitor_spec.rb +214 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +16 -11
- data/spec/mongo/cluster/topology/sharded_spec.rb +12 -9
- data/spec/mongo/cluster/topology/single_spec.rb +20 -11
- data/spec/mongo/cluster_spec.rb +45 -29
- data/spec/mongo/collection/view/map_reduce_spec.rb +14 -9
- data/spec/mongo/collection/view/readable_spec.rb +0 -16
- data/spec/mongo/collection_spec.rb +0 -44
- data/spec/mongo/cursor/builder/get_more_command_spec.rb +2 -4
- data/spec/mongo/cursor/builder/op_get_more_spec.rb +2 -4
- data/spec/mongo/cursor_spec.rb +27 -7
- data/spec/mongo/monitoring/event/cmap/connection_checked_in_spec.rb +10 -3
- data/spec/mongo/monitoring/event/cmap/connection_checked_out_spec.rb +10 -3
- data/spec/mongo/monitoring/event/cmap/pool_closed_spec.rb +10 -3
- data/spec/mongo/monitoring/event/cmap/pool_created_spec.rb +10 -3
- data/spec/mongo/operation/delete/op_msg_spec.rb +17 -8
- data/spec/mongo/operation/insert/op_msg_spec.rb +50 -35
- data/spec/mongo/operation/update/op_msg_spec.rb +14 -7
- data/spec/mongo/retryable_spec.rb +52 -31
- data/spec/mongo/server/app_metadata_spec.rb +0 -8
- data/spec/mongo/server/connection_auth_spec.rb +5 -2
- data/spec/mongo/server/connection_pool/populator_spec.rb +101 -0
- data/spec/mongo/server/connection_pool_spec.rb +256 -107
- data/spec/mongo/server/connection_spec.rb +22 -33
- data/spec/mongo/server/description_spec.rb +42 -4
- data/spec/mongo/server/monitor/connection_spec.rb +22 -11
- data/spec/mongo/server/monitor_spec.rb +66 -107
- data/spec/mongo/server_spec.rb +82 -60
- data/spec/mongo/session/session_pool_spec.rb +1 -5
- data/spec/mongo/session_spec.rb +0 -4
- data/spec/mongo/socket/ssl_spec.rb +2 -2
- data/spec/mongo/srv/monitor_spec.rb +211 -0
- data/spec/mongo/srv/result_spec.rb +54 -0
- data/spec/mongo/uri/srv_protocol_spec.rb +30 -15
- data/spec/mongo/uri_spec.rb +125 -4
- data/spec/spec_helper.rb +6 -0
- data/spec/spec_tests/auth_spec.rb +39 -0
- data/spec/spec_tests/cmap_spec.rb +55 -8
- data/spec/spec_tests/connection_string_spec.rb +6 -31
- data/spec/spec_tests/data/auth/connection-string.yml +297 -0
- data/spec/spec_tests/data/cmap/pool-checkout-error-closed.yml +4 -1
- data/spec/spec_tests/data/cmap/pool-create-with-options.yml +1 -0
- data/spec/spec_tests/data/command_monitoring/insertMany.yml +1 -1
- data/spec/spec_tests/data/connection_string/invalid-uris.yml +20 -0
- data/spec/spec_tests/data/connection_string/valid-auth.yml +16 -0
- data/spec/spec_tests/data/connection_string/valid-warnings.yml +26 -30
- data/spec/spec_tests/data/transactions/abort.yml +3 -3
- data/spec/spec_tests/data/transactions/error-labels.yml +3 -3
- data/spec/spec_tests/data/transactions_api/callback-retry.yml +3 -3
- data/spec/spec_tests/data/uri_options/auth-options.yml +1 -1
- data/spec/spec_tests/max_staleness_spec.rb +7 -2
- data/spec/spec_tests/retryable_reads_spec.rb +0 -31
- data/spec/spec_tests/sdam_monitoring_spec.rb +12 -12
- data/spec/spec_tests/sdam_spec.rb +4 -7
- data/spec/spec_tests/server_selection_spec.rb +6 -2
- data/spec/spec_tests/transactions_spec.rb +0 -2
- data/spec/spec_tests/uri_options_spec.rb +4 -2
- data/spec/stress/connection_pool_stress_spec.rb +203 -0
- data/spec/stress/connection_pool_timing_spec.rb +181 -0
- data/spec/support/auth.rb +113 -0
- data/spec/support/background_thread_registry.rb +63 -0
- data/spec/support/client_registry.rb +11 -2
- data/spec/support/cluster_config.rb +65 -46
- data/spec/support/cluster_tools.rb +2 -2
- data/spec/support/cmap.rb +13 -14
- data/spec/support/cmap/verifier.rb +4 -5
- data/spec/support/command_monitoring.rb +0 -5
- data/spec/support/common_shortcuts.rb +101 -1
- data/spec/support/constraints.rb +25 -0
- data/spec/support/dns.rb +13 -0
- data/spec/support/event_subscriber.rb +0 -7
- data/spec/support/json_ext_formatter.rb +5 -1
- data/spec/support/lite_constraints.rb +22 -6
- data/spec/support/local_resource_registry.rb +34 -0
- data/spec/support/sdam_monitoring.rb +115 -0
- data/spec/support/spec_config.rb +20 -6
- data/spec/support/spec_setup.rb +2 -2
- data/spec/support/transactions.rb +1 -1
- data/spec/support/transactions/test.rb +1 -1
- data/spec/support/utils.rb +1 -16
- metadata +685 -659
- metadata.gz.sig +0 -0
- data/lib/mongo/event/description_changed.rb +0 -52
- data/spec/integration/bson_symbol_spec.rb +0 -34
- data/spec/integration/crud_spec.rb +0 -45
- data/spec/integration/get_more_spec.rb +0 -32
- data/spec/integration/grid_fs_bucket_spec.rb +0 -48
- data/spec/integration/retryable_errors_spec.rb +0 -265
- data/spec/integration/size_limit_spec.rb~12e1e9c4f... RUBY-2242 Fix zlib compression (#2021) +0 -98
- data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +0 -56
- data/spec/runners/sdam/verifier.rb +0 -88
data/lib/mongo/error/notable.rb
CHANGED
@@ -18,7 +18,7 @@ module Mongo
|
|
18
18
|
# A module encapsulating note tracking functionality, since currently
|
19
19
|
# the driver does not have a single exception hierarchy root.
|
20
20
|
#
|
21
|
-
# @since 2.
|
21
|
+
# @since 2.11.0
|
22
22
|
# @api private
|
23
23
|
module Notable
|
24
24
|
|
@@ -27,7 +27,7 @@ module Mongo
|
|
27
27
|
#
|
28
28
|
# @return [ Array<String> ] Additional information strings.
|
29
29
|
#
|
30
|
-
# @since 2.
|
30
|
+
# @since 2.11.0
|
31
31
|
# @api public
|
32
32
|
def notes
|
33
33
|
if @notes
|
@@ -80,15 +80,15 @@ module Mongo
|
|
80
80
|
# @since 2.6.0
|
81
81
|
attr_reader :code_name
|
82
82
|
|
83
|
-
# Whether the error is a retryable error according to the legacy
|
84
|
-
#
|
83
|
+
# Whether the error is a retryable error according to the legacy read retry
|
84
|
+
# logic.
|
85
85
|
#
|
86
86
|
# @return [ true, false ]
|
87
87
|
#
|
88
88
|
# @since 2.1.1
|
89
89
|
# @deprecated
|
90
90
|
def retryable?
|
91
|
-
|
91
|
+
RETRY_MESSAGES.any?{ |m| message.include?(m) }
|
92
92
|
end
|
93
93
|
|
94
94
|
# Whether the error is a retryable error according to the modern retryable
|
@@ -26,17 +26,24 @@ module Mongo
|
|
26
26
|
# @since 2.9.0
|
27
27
|
attr_reader :address
|
28
28
|
|
29
|
+
# @return [ Mongo::Server::ConnectionPool ] pool The pool that is closed.
|
30
|
+
#
|
31
|
+
# @since 2.11.0
|
32
|
+
# @api experimental
|
33
|
+
attr_reader :pool
|
34
|
+
|
29
35
|
# Instantiate the new exception.
|
30
36
|
#
|
31
37
|
# @example Instantiate the exception.
|
32
|
-
# Mongo::Error::PoolClosedError.new(address)
|
38
|
+
# Mongo::Error::PoolClosedError.new(address, pool)
|
33
39
|
#
|
34
40
|
# @since 2.9.0
|
35
41
|
# @api private
|
36
|
-
def initialize(address)
|
42
|
+
def initialize(address, pool)
|
37
43
|
@address = address
|
38
|
-
|
39
|
-
super("Attempted to use a connection pool which has been closed (for #{address}
|
44
|
+
@pool = pool
|
45
|
+
super("Attempted to use a connection pool which has been closed (for #{address} " +
|
46
|
+
"with pool 0x#{pool.object_id})")
|
40
47
|
end
|
41
48
|
end
|
42
49
|
end
|
data/lib/mongo/event.rb
CHANGED
@@ -36,6 +36,7 @@ module Mongo
|
|
36
36
|
# When a server is to be removed from a cluster.
|
37
37
|
#
|
38
38
|
# @since 2.0.6
|
39
|
+
# @deprecated Will be removed in 3.0
|
39
40
|
DESCRIPTION_CHANGED = 'description_changed'.freeze
|
40
41
|
end
|
41
42
|
end
|
@@ -44,4 +45,3 @@ require 'mongo/event/base'
|
|
44
45
|
require 'mongo/event/listeners'
|
45
46
|
require 'mongo/event/publisher'
|
46
47
|
require 'mongo/event/subscriber'
|
47
|
-
require 'mongo/event/description_changed'
|
data/lib/mongo/grid/file.rb
CHANGED
@@ -104,11 +104,6 @@ module Mongo
|
|
104
104
|
# chunk objects and assemble the data. If we have an IO object, then
|
105
105
|
# it's the original file data and we must split it into chunks and set
|
106
106
|
# the original data itself.
|
107
|
-
#
|
108
|
-
# @param [ IO, String, Array<BSON::Document> ] value The file object,
|
109
|
-
# file contents or chunk documents.
|
110
|
-
#
|
111
|
-
# @return [ Array<Grid::File::Chunk> ] Array of chunks.
|
112
107
|
def initialize_chunks!(value)
|
113
108
|
if value.is_a?(Array)
|
114
109
|
@chunks = value.map{ |doc| Chunk.new(doc) }
|
@@ -151,7 +151,6 @@ module Mongo
|
|
151
151
|
# @return [ String ] The assembled data.
|
152
152
|
#
|
153
153
|
# @since 2.0.0
|
154
|
-
# @api private
|
155
154
|
def assemble(chunks)
|
156
155
|
chunks.reduce(''){ |data, chunk| data << chunk.data.data }
|
157
156
|
end
|
@@ -168,7 +167,6 @@ module Mongo
|
|
168
167
|
# @return [ Array<Chunk> ] The chunks of the data.
|
169
168
|
#
|
170
169
|
# @since 2.0.0
|
171
|
-
# @api private
|
172
170
|
def split(io, file_info, offset = 0)
|
173
171
|
io = StringIO.new(io) if io.is_a?(String)
|
174
172
|
parts = Enumerator.new { |y| y << io.read(file_info.chunk_size) until io.eof? }
|
data/lib/mongo/grid/fs_bucket.rb
CHANGED
@@ -177,7 +177,7 @@ module Mongo
|
|
177
177
|
#
|
178
178
|
# @since 2.0.0
|
179
179
|
def prefix
|
180
|
-
@options[:fs_name] || @options[:bucket_name]
|
180
|
+
@options[:fs_name] || @options[:bucket_name]|| DEFAULT_ROOT
|
181
181
|
end
|
182
182
|
|
183
183
|
# Remove a single file from the GridFS.
|
@@ -230,8 +230,7 @@ module Mongo
|
|
230
230
|
#
|
231
231
|
# @since 2.1.0
|
232
232
|
def open_download_stream(id, options = nil)
|
233
|
-
|
234
|
-
read_stream(id, **options).tap do |stream|
|
233
|
+
read_stream(id, options).tap do |stream|
|
235
234
|
if block_given?
|
236
235
|
begin
|
237
236
|
yield stream
|
@@ -349,15 +348,15 @@ module Mongo
|
|
349
348
|
download_to_stream(open_download_stream_by_name(filename, opts).file_id, io)
|
350
349
|
end
|
351
350
|
|
352
|
-
# Opens an upload stream to GridFS to which the contents of a file
|
353
|
-
# blob can be written.
|
351
|
+
# Opens an upload stream to GridFS to which the contents of a user file came be written.
|
354
352
|
#
|
355
|
-
# @
|
353
|
+
# @example Open a stream to which the contents of a file came be written.
|
354
|
+
# fs.open_upload_stream('a-file.txt')
|
355
|
+
#
|
356
|
+
# @param [ String ] filename The filename of the file to upload.
|
356
357
|
# @param [ Hash ] opts The options for the write stream.
|
357
358
|
#
|
358
|
-
# @option opts [ Object ] :file_id An optional unique file id.
|
359
|
-
# A BSON::ObjectId is automatically generated if a file id is not
|
360
|
-
# provided.
|
359
|
+
# @option opts [ Object ] :file_id An optional unique file id. An ObjectId is generated otherwise.
|
361
360
|
# @option opts [ Integer ] :chunk_size Override the default chunk size.
|
362
361
|
# @option opts [ Hash ] :metadata User data for the 'metadata' field of the files
|
363
362
|
# collection document.
|
@@ -376,8 +375,7 @@ module Mongo
|
|
376
375
|
#
|
377
376
|
# @since 2.1.0
|
378
377
|
def open_upload_stream(filename, opts = {})
|
379
|
-
|
380
|
-
write_stream(filename, **opts).tap do |stream|
|
378
|
+
write_stream(filename, opts).tap do |stream|
|
381
379
|
if block_given?
|
382
380
|
begin
|
383
381
|
yield stream
|
@@ -464,12 +462,12 @@ module Mongo
|
|
464
462
|
#
|
465
463
|
# @option opts [ BSON::Document ] :file_info_doc For internal
|
466
464
|
# driver use only. A BSON document to use as file information.
|
467
|
-
def read_stream(id,
|
468
|
-
Stream.get(self, Stream::READ_MODE, { file_id: id }.update(options).update(opts))
|
465
|
+
def read_stream(id, opts = nil)
|
466
|
+
Stream.get(self, Stream::READ_MODE, { file_id: id }.update(options).update(opts || {}))
|
469
467
|
end
|
470
468
|
|
471
|
-
def write_stream(filename,
|
472
|
-
Stream.get(self, Stream::WRITE_MODE, { filename: filename }.
|
469
|
+
def write_stream(filename, opts)
|
470
|
+
Stream.get(self, Stream::WRITE_MODE, { filename: filename }.merge!(options).merge!(opts))
|
473
471
|
end
|
474
472
|
|
475
473
|
def chunks_name
|
@@ -82,12 +82,12 @@ module Mongo
|
|
82
82
|
@open = true
|
83
83
|
end
|
84
84
|
|
85
|
-
# Write to the GridFS bucket from the source stream
|
85
|
+
# Write to the GridFS bucket from the source stream.
|
86
86
|
#
|
87
87
|
# @example Write to GridFS.
|
88
88
|
# stream.write(io)
|
89
89
|
#
|
90
|
-
# @param [
|
90
|
+
# @param [ IO ] io The source io stream to upload from.
|
91
91
|
#
|
92
92
|
# @return [ Stream::Write ] self The write stream itself.
|
93
93
|
#
|
@@ -95,13 +95,7 @@ module Mongo
|
|
95
95
|
def write(io)
|
96
96
|
ensure_open!
|
97
97
|
@indexes ||= ensure_indexes!
|
98
|
-
@length +=
|
99
|
-
# String objects
|
100
|
-
io.bytesize
|
101
|
-
else
|
102
|
-
# IO objects
|
103
|
-
io.size
|
104
|
-
end
|
98
|
+
@length += io.size
|
105
99
|
chunks = File::Chunk.split(io, file_info, @n)
|
106
100
|
@n += chunks.size
|
107
101
|
chunks_collection.insert_many(chunks) unless chunks.empty?
|
data/lib/mongo/loggable.rb
CHANGED
@@ -99,7 +99,11 @@ module Mongo
|
|
99
99
|
private
|
100
100
|
|
101
101
|
def format_message(message)
|
102
|
-
format("%s | %s".freeze,
|
102
|
+
format("%s | %s".freeze, _mongo_log_prefix, message)
|
103
|
+
end
|
104
|
+
|
105
|
+
def _mongo_log_prefix
|
106
|
+
(options && options[:log_prefix]) || PREFIX
|
103
107
|
end
|
104
108
|
end
|
105
109
|
end
|
data/lib/mongo/monitoring.rb
CHANGED
@@ -326,3 +326,4 @@ require 'mongo/monitoring/server_opening_log_subscriber'
|
|
326
326
|
require 'mongo/monitoring/topology_changed_log_subscriber'
|
327
327
|
require 'mongo/monitoring/topology_opening_log_subscriber'
|
328
328
|
require 'mongo/monitoring/topology_closed_log_subscriber'
|
329
|
+
require 'mongo/monitoring/unified_sdam_log_subscriber'
|
@@ -35,6 +35,13 @@ module Mongo
|
|
35
35
|
# @since 2.9.0
|
36
36
|
TIMEOUT = :timeout
|
37
37
|
|
38
|
+
# @return [ Symbol ] CONNECTION_ERROR Indicates that the connection
|
39
|
+
# check out failed due to an error encountered while setting up a
|
40
|
+
# new connection.
|
41
|
+
#
|
42
|
+
# @since 2.10.0
|
43
|
+
CONNECTION_ERROR = :connection_error
|
44
|
+
|
38
45
|
# @return [ Mongo::Address ] address The address of the server the
|
39
46
|
# connection would have connected to.
|
40
47
|
#
|
@@ -32,16 +32,24 @@ module Mongo
|
|
32
32
|
# @since 2.9.0
|
33
33
|
attr_reader :connection_id
|
34
34
|
|
35
|
+
# @return [ Mongo::Server::ConnectionPool ] pool The pool that the connection
|
36
|
+
# was checked in to.
|
37
|
+
#
|
38
|
+
# @since 2.11.0
|
39
|
+
# @api experimental
|
40
|
+
attr_reader :pool
|
41
|
+
|
35
42
|
# Create the event.
|
36
43
|
#
|
37
44
|
# @example Create the event.
|
38
|
-
# ConnectionCheckedIn.new(address, id)
|
45
|
+
# ConnectionCheckedIn.new(address, id, pool)
|
39
46
|
#
|
40
47
|
# @since 2.9.0
|
41
48
|
# @api private
|
42
|
-
def initialize(address, id)
|
49
|
+
def initialize(address, id, pool)
|
43
50
|
@address = address
|
44
51
|
@connection_id = id
|
52
|
+
@pool = pool
|
45
53
|
end
|
46
54
|
|
47
55
|
# Returns a concise yet useful summary of the event.
|
@@ -54,7 +62,7 @@ module Mongo
|
|
54
62
|
# @api experimental
|
55
63
|
def summary
|
56
64
|
"#<#{self.class.name.sub(/^Mongo::Monitoring::Event::Cmap::/, '')} " +
|
57
|
-
"address=#{address} connection_id=#{connection_id}>"
|
65
|
+
"address=#{address} connection_id=#{connection_id} pool=0x#{pool.object_id}>"
|
58
66
|
end
|
59
67
|
end
|
60
68
|
end
|
@@ -33,16 +33,24 @@ module Mongo
|
|
33
33
|
# @since 2.9.0
|
34
34
|
attr_reader :connection_id
|
35
35
|
|
36
|
+
# @return [ Mongo::Server::ConnectionPool ] pool The pool that the connection
|
37
|
+
# was checked out from.
|
38
|
+
#
|
39
|
+
# @since 2.11.0
|
40
|
+
# @api experimental
|
41
|
+
attr_reader :pool
|
42
|
+
|
36
43
|
# Create the event.
|
37
44
|
#
|
38
45
|
# @example Create the event.
|
39
|
-
# ConnectionCheckedOut.new(address, id)
|
46
|
+
# ConnectionCheckedOut.new(address, id, pool)
|
40
47
|
#
|
41
48
|
# @since 2.9.0
|
42
49
|
# @api private
|
43
|
-
def initialize(address, id)
|
50
|
+
def initialize(address, id, pool)
|
44
51
|
@address = address
|
45
52
|
@connection_id = id
|
53
|
+
@pool = pool
|
46
54
|
end
|
47
55
|
|
48
56
|
# Returns a concise yet useful summary of the event.
|
@@ -55,7 +63,7 @@ module Mongo
|
|
55
63
|
# @api experimental
|
56
64
|
def summary
|
57
65
|
"#<#{self.class.name.sub(/^Mongo::Monitoring::Event::Cmap::/, '')} " +
|
58
|
-
"address=#{address} connection_id=#{connection_id}>"
|
66
|
+
"address=#{address} connection_id=#{connection_id} pool=0x#{pool.object_id}>"
|
59
67
|
end
|
60
68
|
end
|
61
69
|
end
|
@@ -28,15 +28,22 @@ module Mongo
|
|
28
28
|
# @since 2.9.0
|
29
29
|
attr_reader :address
|
30
30
|
|
31
|
+
# @return [ Mongo::Server::ConnectionPool ] pool The pool that was closed.
|
32
|
+
#
|
33
|
+
# @since 2.11.0
|
34
|
+
# @api experimental
|
35
|
+
attr_reader :pool
|
36
|
+
|
31
37
|
# Create the event.
|
32
38
|
#
|
33
39
|
# @example Create the event.
|
34
|
-
# PoolClosed.new(address)
|
40
|
+
# PoolClosed.new(address, pool)
|
35
41
|
#
|
36
42
|
# @since 2.9.0
|
37
43
|
# @api private
|
38
|
-
def initialize(address)
|
44
|
+
def initialize(address, pool)
|
39
45
|
@address = address
|
46
|
+
@pool = pool
|
40
47
|
end
|
41
48
|
|
42
49
|
# Returns a concise yet useful summary of the event.
|
@@ -48,7 +55,8 @@ module Mongo
|
|
48
55
|
# @since 2.9.0
|
49
56
|
# @api experimental
|
50
57
|
def summary
|
51
|
-
"#<#{self.class.name.sub(/^Mongo::Monitoring::Event::Cmap::/, '')}
|
58
|
+
"#<#{self.class.name.sub(/^Mongo::Monitoring::Event::Cmap::/, '')} " +
|
59
|
+
"address=#{address} pool=0x#{pool.object_id}>"
|
52
60
|
end
|
53
61
|
end
|
54
62
|
end
|
@@ -33,16 +33,24 @@ module Mongo
|
|
33
33
|
# @since 2.9.0
|
34
34
|
attr_reader :options
|
35
35
|
|
36
|
+
# @return [ Mongo::Server::ConnectionPool ] pool The pool that was just
|
37
|
+
# created.
|
38
|
+
#
|
39
|
+
# @since 2.11.0
|
40
|
+
# @api experimental
|
41
|
+
attr_reader :pool
|
42
|
+
|
36
43
|
# Create the event.
|
37
44
|
#
|
38
45
|
# @example Create the event.
|
39
|
-
# PoolCreated.new(address, options)
|
46
|
+
# PoolCreated.new(address, options, pool)
|
40
47
|
#
|
41
48
|
# @since 2.9.0
|
42
49
|
# @api private
|
43
|
-
def initialize(address, options)
|
50
|
+
def initialize(address, options, pool)
|
44
51
|
@address = address
|
45
52
|
@options = options.dup.freeze
|
53
|
+
@pool = pool
|
46
54
|
end
|
47
55
|
|
48
56
|
# Returns a concise yet useful summary of the event.
|
@@ -54,7 +62,8 @@ module Mongo
|
|
54
62
|
# @since 2.9.0
|
55
63
|
# @api experimental
|
56
64
|
def summary
|
57
|
-
"#<#{self.class.name.sub(/^Mongo::Monitoring::Event::Cmap::/, '')}
|
65
|
+
"#<#{self.class.name.sub(/^Mongo::Monitoring::Event::Cmap::/, '')} " +
|
66
|
+
"address=#{address} options=#{options} pool=0x#{pool.object_id}>"
|
58
67
|
end
|
59
68
|
end
|
60
69
|
end
|
@@ -0,0 +1,62 @@
|
|
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 Monitoring
|
17
|
+
|
18
|
+
# Subscribes to SDAM events and logs them.
|
19
|
+
#
|
20
|
+
# @since 2.11.0
|
21
|
+
# @api experimental
|
22
|
+
class UnifiedSdamLogSubscriber
|
23
|
+
include Loggable
|
24
|
+
|
25
|
+
# @return [ Hash ] options The options.
|
26
|
+
#
|
27
|
+
# @since 2.11.0
|
28
|
+
attr_reader :options
|
29
|
+
|
30
|
+
# Create the new log subscriber.
|
31
|
+
#
|
32
|
+
# @param [ Hash ] options The options.
|
33
|
+
#
|
34
|
+
# @option options [ Logger ] :logger An optional custom logger.
|
35
|
+
#
|
36
|
+
# @since 2.11.0
|
37
|
+
def initialize(options = {})
|
38
|
+
@options = options
|
39
|
+
end
|
40
|
+
|
41
|
+
# Handle an event.
|
42
|
+
#
|
43
|
+
# @param [ Event ] event The event.
|
44
|
+
#
|
45
|
+
# @since 2.11.0
|
46
|
+
def published(event)
|
47
|
+
log_debug("EVENT: #{event.summary}") if logger.debug?
|
48
|
+
end
|
49
|
+
|
50
|
+
alias :succeeded :published
|
51
|
+
|
52
|
+
def subscribe(client)
|
53
|
+
client.subscribe(Mongo::Monitoring::TOPOLOGY_OPENING, self)
|
54
|
+
client.subscribe(Mongo::Monitoring::SERVER_OPENING, self)
|
55
|
+
client.subscribe(Mongo::Monitoring::SERVER_DESCRIPTION_CHANGED, self)
|
56
|
+
client.subscribe(Mongo::Monitoring::TOPOLOGY_CHANGED, self)
|
57
|
+
client.subscribe(Mongo::Monitoring::SERVER_CLOSED, self)
|
58
|
+
client.subscribe(Mongo::Monitoring::TOPOLOGY_CLOSED, self)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|