mongo 2.4.0.rc1 → 2.4.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongo/auth/cr/conversation.rb +1 -1
- data/lib/mongo/auth/ldap/conversation.rb +1 -1
- data/lib/mongo/auth/scram/conversation.rb +1 -1
- data/lib/mongo/auth/x509/conversation.rb +4 -2
- data/lib/mongo/client.rb +7 -4
- data/lib/mongo/cluster.rb +55 -5
- data/lib/mongo/cluster/app_metadata.rb +7 -1
- data/lib/mongo/cluster/topology.rb +7 -6
- data/lib/mongo/cluster/topology/replica_set.rb +48 -2
- data/lib/mongo/cluster/topology/sharded.rb +47 -1
- data/lib/mongo/cluster/topology/single.rb +55 -4
- data/lib/mongo/cluster/topology/unknown.rb +65 -9
- data/lib/mongo/error/invalid_server_preference.rb +3 -1
- data/lib/mongo/event.rb +8 -0
- data/lib/mongo/event/description_changed.rb +20 -2
- data/lib/mongo/event/member_discovered.rb +65 -0
- data/lib/mongo/event/primary_elected.rb +3 -1
- data/lib/mongo/event/standalone_discovered.rb +1 -1
- data/lib/mongo/monitoring.rb +41 -0
- data/lib/mongo/monitoring/event.rb +6 -0
- data/lib/mongo/monitoring/event/server_closed.rb +46 -0
- data/lib/mongo/monitoring/event/server_description_changed.rb +58 -0
- data/lib/mongo/monitoring/event/server_opening.rb +46 -0
- data/lib/mongo/monitoring/event/topology_changed.rb +46 -0
- data/lib/mongo/monitoring/event/topology_closed.rb +41 -0
- data/lib/mongo/monitoring/event/topology_opening.rb +41 -0
- data/lib/mongo/monitoring/publishable.rb +12 -0
- data/lib/mongo/monitoring/sdam_log_subscriber.rb +54 -0
- data/lib/mongo/monitoring/server_closed_log_subscriber.rb +30 -0
- data/lib/mongo/monitoring/server_description_changed_log_subscriber.rb +33 -0
- data/lib/mongo/monitoring/server_opening_log_subscriber.rb +30 -0
- data/lib/mongo/monitoring/topology_changed_log_subscriber.rb +40 -0
- data/lib/mongo/monitoring/topology_opening_log_subscriber.rb +30 -0
- data/lib/mongo/server.rb +6 -0
- data/lib/mongo/server/connection.rb +1 -1
- data/lib/mongo/server/description.rb +23 -3
- data/lib/mongo/server/description/inspector.rb +4 -2
- data/lib/mongo/server/description/inspector/description_changed.rb +2 -2
- data/lib/mongo/server/description/inspector/member_discovered.rb +59 -0
- data/lib/mongo/server/description/inspector/primary_elected.rb +2 -0
- data/lib/mongo/server_selector.rb +10 -5
- data/lib/mongo/server_selector/nearest.rb +1 -1
- data/lib/mongo/server_selector/primary_preferred.rb +1 -1
- data/lib/mongo/server_selector/secondary.rb +1 -1
- data/lib/mongo/server_selector/secondary_preferred.rb +1 -1
- data/lib/mongo/server_selector/selectable.rb +24 -12
- data/lib/mongo/uri.rb +1 -1
- data/lib/mongo/version.rb +1 -1
- data/mongo.gemspec +1 -1
- data/spec/mongo/auth/cr_spec.rb +6 -1
- data/spec/mongo/auth/ldap_spec.rb +6 -1
- data/spec/mongo/auth/scram_spec.rb +6 -1
- data/spec/mongo/auth/x509/conversation_spec.rb +69 -0
- data/spec/mongo/auth/x509_spec.rb +9 -4
- data/spec/mongo/client_spec.rb +40 -2
- data/spec/mongo/cluster/topology/replica_set_spec.rb +218 -9
- data/spec/mongo/cluster/topology/sharded_spec.rb +17 -2
- data/spec/mongo/cluster/topology/single_spec.rb +19 -4
- data/spec/mongo/cluster/topology/unknown_spec.rb +19 -1
- data/spec/mongo/cluster/topology_spec.rb +11 -7
- data/spec/mongo/cluster_spec.rb +25 -7
- data/spec/mongo/max_staleness_spec.rb +40 -22
- data/spec/mongo/monitoring_spec.rb +2 -2
- data/spec/mongo/sdam_monitoring_spec.rb +60 -0
- data/spec/mongo/sdam_spec.rb +77 -0
- data/spec/mongo/server/connection_pool_spec.rb +6 -1
- data/spec/mongo/server/connection_spec.rb +6 -1
- data/spec/mongo/server/description_spec.rb +90 -1
- data/spec/mongo/server_selection_spec.rb +7 -6
- data/spec/mongo/server_selector/nearest_spec.rb +7 -7
- data/spec/mongo/server_selector/primary_preferred_spec.rb +7 -7
- data/spec/mongo/server_selector/primary_spec.rb +4 -4
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +6 -6
- data/spec/mongo/server_selector/secondary_spec.rb +6 -6
- data/spec/mongo/server_selector_spec.rb +8 -0
- data/spec/mongo/server_spec.rb +6 -1
- data/spec/mongo/uri_spec.rb +4 -4
- data/spec/spec_helper.rb +2 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Incompatible.yml +4 -4
- data/spec/support/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest2.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetNoPrimary/NoKnownServers.yml +15 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.yml +1 -1
- data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Secondary.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.yml +1 -1
- data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetNoPrimary/ZeroMaxStaleness.yml +23 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Incompatible.yml +4 -4
- data/spec/support/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.yml +5 -5
- data/spec/support/max_staleness/ReplicaSetWithPrimary/{ShortHeartbeartShortMaxStaleness2.yml → LongHeartbeat.yml} +4 -4
- data/spec/support/max_staleness/ReplicaSetWithPrimary/{ShortHeartbeartShortMaxStaleness.yml → LongHeartbeat2.yml} +6 -10
- data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.yml +3 -2
- data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.yml +2 -2
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest2.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest_tags.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.yml +2 -2
- data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.yml +1 -1
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.yml +3 -3
- data/spec/support/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.yml +7 -11
- data/spec/support/max_staleness/Sharded/Incompatible.yml +4 -4
- data/spec/support/max_staleness/Sharded/SmallMaxStaleness.yml +10 -2
- data/spec/support/max_staleness/Single/Incompatible.yml +4 -4
- data/spec/support/max_staleness/Single/SmallMaxStaleness.yml +2 -2
- data/spec/support/max_staleness/Unknown/SmallMaxStaleness.yml +14 -0
- data/spec/support/sdam/rs/primary_mismatched_me.yml +2 -2
- data/spec/support/sdam/rs/secondary_mismatched_me.yml +2 -2
- data/spec/support/sdam_monitoring.rb +144 -0
- data/spec/support/sdam_monitoring/replica_set_with_no_primary.yml +112 -0
- data/spec/support/sdam_monitoring/replica_set_with_primary.yml +111 -0
- data/spec/support/sdam_monitoring/replica_set_with_removal.yml +106 -0
- data/spec/support/sdam_monitoring/required_replica_set.yml +84 -0
- data/spec/support/sdam_monitoring/standalone.yml +70 -0
- data/spec/support/server_discovery_and_monitoring.rb +34 -1
- data/spec/support/server_selection.rb +14 -11
- data/spec/support/shared/server_selector.rb +6 -0
- metadata +49 -13
- metadata.gz.sig +0 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +0 -115
|
@@ -20,15 +20,22 @@ module Mongo
|
|
|
20
20
|
#
|
|
21
21
|
# @since 2.0.0
|
|
22
22
|
class Single
|
|
23
|
-
|
|
24
|
-
# @return [ String ] seed The seed address.
|
|
25
|
-
attr_reader :seed
|
|
23
|
+
include Monitoring::Publishable
|
|
26
24
|
|
|
27
25
|
# The display name for the topology.
|
|
28
26
|
#
|
|
29
27
|
# @since 2.0.0
|
|
30
28
|
NAME = 'Single'.freeze
|
|
31
29
|
|
|
30
|
+
# @return [ Hash ] options The options.
|
|
31
|
+
attr_reader :options
|
|
32
|
+
|
|
33
|
+
# @return [ String ] seed The seed address.
|
|
34
|
+
attr_reader :seed
|
|
35
|
+
|
|
36
|
+
# @return [ monitoring ] monitoring the monitoring.
|
|
37
|
+
attr_reader :monitoring
|
|
38
|
+
|
|
32
39
|
# Get the display name.
|
|
33
40
|
#
|
|
34
41
|
# @example Get the display name.
|
|
@@ -54,16 +61,47 @@ module Mongo
|
|
|
54
61
|
# @return [ Single ] The topology.
|
|
55
62
|
def elect_primary(description, servers); self; end
|
|
56
63
|
|
|
64
|
+
# Determine if the topology would select a readable server for the
|
|
65
|
+
# provided candidates and read preference.
|
|
66
|
+
#
|
|
67
|
+
# @example Is a readable server present?
|
|
68
|
+
# topology.has_readable_server?(cluster, server_selector)
|
|
69
|
+
#
|
|
70
|
+
# @param [ Cluster ] cluster The cluster.
|
|
71
|
+
# @param [ ServerSelector ] server_selector The server
|
|
72
|
+
# selector.
|
|
73
|
+
#
|
|
74
|
+
# @return [ true ] A standalone always has a readable server.
|
|
75
|
+
#
|
|
76
|
+
# @since 2.4.0
|
|
77
|
+
def has_readable_server?(cluster, server_selector = nil); true; end
|
|
78
|
+
|
|
79
|
+
# Determine if the topology would select a writable server for the
|
|
80
|
+
# provided candidates.
|
|
81
|
+
#
|
|
82
|
+
# @example Is a writable server present?
|
|
83
|
+
# topology.has_writable_server?(servers)
|
|
84
|
+
#
|
|
85
|
+
# @param [ Cluster ] cluster The cluster.
|
|
86
|
+
#
|
|
87
|
+
# @return [ true ] A standalone always has a writable server.
|
|
88
|
+
#
|
|
89
|
+
# @since 2.4.0
|
|
90
|
+
def has_writable_server?(cluster); true; end
|
|
91
|
+
|
|
57
92
|
# Initialize the topology with the options.
|
|
58
93
|
#
|
|
59
94
|
# @example Initialize the topology.
|
|
60
95
|
# Single.new(options)
|
|
61
96
|
#
|
|
62
97
|
# @param [ Hash ] options The options.
|
|
98
|
+
# @param [ Monitoring ] monitoring The monitoring.
|
|
99
|
+
# @param [ Array<String> ] seeds The seeds.
|
|
63
100
|
#
|
|
64
101
|
# @since 2.0.0
|
|
65
|
-
def initialize(options, seeds = [])
|
|
102
|
+
def initialize(options, monitoring, seeds = [])
|
|
66
103
|
@options = options
|
|
104
|
+
@monitoring = monitoring
|
|
67
105
|
@seed = seeds.first
|
|
68
106
|
end
|
|
69
107
|
|
|
@@ -181,6 +219,19 @@ module Mongo
|
|
|
181
219
|
#
|
|
182
220
|
# @since 2.0.6
|
|
183
221
|
def standalone_discovered; self; end
|
|
222
|
+
|
|
223
|
+
# Publish that a member of this topology was discovered.
|
|
224
|
+
#
|
|
225
|
+
# @example Publish that a member was discovered.
|
|
226
|
+
# topology.member_discovered
|
|
227
|
+
#
|
|
228
|
+
# @since 2.4.0
|
|
229
|
+
def member_discovered
|
|
230
|
+
publish_sdam_event(
|
|
231
|
+
Monitoring::TOPOLOGY_CHANGED,
|
|
232
|
+
Monitoring::Event::TopologyChanged.new(self, self)
|
|
233
|
+
)
|
|
234
|
+
end
|
|
184
235
|
end
|
|
185
236
|
end
|
|
186
237
|
end
|
|
@@ -21,6 +21,7 @@ module Mongo
|
|
|
21
21
|
# @since 2.0.0
|
|
22
22
|
class Unknown
|
|
23
23
|
include Loggable
|
|
24
|
+
include Monitoring::Publishable
|
|
24
25
|
|
|
25
26
|
# The display name for the topology.
|
|
26
27
|
#
|
|
@@ -30,6 +31,9 @@ module Mongo
|
|
|
30
31
|
# @return [ Hash ] options The options.
|
|
31
32
|
attr_reader :options
|
|
32
33
|
|
|
34
|
+
# @return [ Monitoring ] monitoring The monitoring.
|
|
35
|
+
attr_reader :monitoring
|
|
36
|
+
|
|
33
37
|
# Get the display name.
|
|
34
38
|
#
|
|
35
39
|
# @example Get the display name.
|
|
@@ -55,23 +59,55 @@ module Mongo
|
|
|
55
59
|
# @return [ Sharded, ReplicaSet ] The new topology.
|
|
56
60
|
def elect_primary(description, servers)
|
|
57
61
|
if description.mongos?
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
sharded = Sharded.new(options, monitoring)
|
|
63
|
+
topology_changed(sharded)
|
|
64
|
+
sharded
|
|
60
65
|
else
|
|
61
66
|
initialize_replica_set(description, servers)
|
|
62
67
|
end
|
|
63
68
|
end
|
|
64
69
|
|
|
70
|
+
# Determine if the topology would select a readable server for the
|
|
71
|
+
# provided candidates and read preference.
|
|
72
|
+
#
|
|
73
|
+
# @example Is a readable server present?
|
|
74
|
+
# topology.has_readable_server?(cluster, server_selector)
|
|
75
|
+
#
|
|
76
|
+
# @param [ Cluster ] cluster The cluster.
|
|
77
|
+
# @param [ ServerSelector ] server_selector The server
|
|
78
|
+
# selector.
|
|
79
|
+
#
|
|
80
|
+
# @return [ false ] An Unknown topology will never have a readable server.
|
|
81
|
+
#
|
|
82
|
+
# @since 2.4.0
|
|
83
|
+
def has_readable_server?(cluster, server_selector = nil); false; end
|
|
84
|
+
|
|
85
|
+
# Determine if the topology would select a writable server for the
|
|
86
|
+
# provided candidates.
|
|
87
|
+
#
|
|
88
|
+
# @example Is a writable server present?
|
|
89
|
+
# topology.has_writable_server?(servers)
|
|
90
|
+
#
|
|
91
|
+
# @param [ Cluster ] cluster The cluster.
|
|
92
|
+
#
|
|
93
|
+
# @return [ false ] An Unknown topology will never have a writable server.
|
|
94
|
+
#
|
|
95
|
+
# @since 2.4.0
|
|
96
|
+
def has_writable_server?(cluster); false; end
|
|
97
|
+
|
|
65
98
|
# Initialize the topology with the options.
|
|
66
99
|
#
|
|
67
100
|
# @example Initialize the topology.
|
|
68
101
|
# Unknown.new(options)
|
|
69
102
|
#
|
|
70
103
|
# @param [ Hash ] options The options.
|
|
104
|
+
# @param [ Monitoring ] monitoring The monitoring.
|
|
105
|
+
# @param [ Array<String> ] seeds The seeds.
|
|
71
106
|
#
|
|
72
107
|
# @since 2.0.0
|
|
73
|
-
def initialize(options, seeds = [])
|
|
108
|
+
def initialize(options, monitoring, seeds = [])
|
|
74
109
|
@options = options
|
|
110
|
+
@monitoring = monitoring
|
|
75
111
|
@seeds = seeds
|
|
76
112
|
end
|
|
77
113
|
|
|
@@ -195,25 +231,45 @@ module Mongo
|
|
|
195
231
|
# @since 2.0.6
|
|
196
232
|
def standalone_discovered
|
|
197
233
|
if @seeds.size == 1
|
|
198
|
-
Single.new(options, @seeds)
|
|
234
|
+
single = Single.new(options, monitoring, @seeds)
|
|
235
|
+
topology_changed(single)
|
|
236
|
+
single
|
|
199
237
|
else
|
|
200
238
|
self
|
|
201
239
|
end
|
|
202
240
|
end
|
|
203
241
|
|
|
242
|
+
# Notify the topology that a member was discovered.
|
|
243
|
+
#
|
|
244
|
+
# @example Notify the topology that a member was discovered.
|
|
245
|
+
# topology.member_discovered
|
|
246
|
+
#
|
|
247
|
+
# @since 2.4.0
|
|
248
|
+
def member_discovered
|
|
249
|
+
publish_sdam_event(
|
|
250
|
+
Monitoring::TOPOLOGY_CHANGED,
|
|
251
|
+
Monitoring::Event::TopologyChanged.new(self, self)
|
|
252
|
+
)
|
|
253
|
+
end
|
|
254
|
+
|
|
204
255
|
private
|
|
205
256
|
|
|
206
257
|
def initialize_replica_set(description, servers)
|
|
207
|
-
log_debug(
|
|
208
|
-
"Server #{description.address.to_s} discovered as primary in replica set: " +
|
|
209
|
-
"'#{description.replica_set_name}'. Changing topology to replica set."
|
|
210
|
-
)
|
|
211
258
|
servers.each do |server|
|
|
212
259
|
if server.standalone? && server.address != description.address
|
|
213
260
|
server.description.unknown!
|
|
214
261
|
end
|
|
215
262
|
end
|
|
216
|
-
ReplicaSet.new(options.merge(:replica_set => description.replica_set_name))
|
|
263
|
+
replica_set = ReplicaSet.new(options.merge(:replica_set => description.replica_set_name), monitoring)
|
|
264
|
+
topology_changed(replica_set)
|
|
265
|
+
replica_set
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def topology_changed(new_topology)
|
|
269
|
+
publish_sdam_event(
|
|
270
|
+
Monitoring::TOPOLOGY_CHANGED,
|
|
271
|
+
Monitoring::Event::TopologyChanged.new(self, new_topology)
|
|
272
|
+
)
|
|
217
273
|
end
|
|
218
274
|
end
|
|
219
275
|
end
|
|
@@ -33,7 +33,9 @@ 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
|
-
INVALID_MAX_STALENESS = "max_staleness must be at least
|
|
36
|
+
INVALID_MAX_STALENESS = "`max_staleness` value is too small. It must be at least " +
|
|
37
|
+
"`ServerSelector::SMALLEST_MAX_STALENESS_SECONDS` and (the cluster's heartbeat_frequency " +
|
|
38
|
+
"setting + `Cluster::IDLE_WRITE_PERIOD_SECONDS`).".freeze
|
|
37
39
|
|
|
38
40
|
# Error message when max staleness cannot be used because one or more servers has version < 3.4.
|
|
39
41
|
#
|
data/lib/mongo/event.rb
CHANGED
|
@@ -16,6 +16,7 @@ require 'mongo/event/listeners'
|
|
|
16
16
|
require 'mongo/event/publisher'
|
|
17
17
|
require 'mongo/event/subscriber'
|
|
18
18
|
require 'mongo/event/primary_elected'
|
|
19
|
+
require 'mongo/event/member_discovered'
|
|
19
20
|
require 'mongo/event/description_changed'
|
|
20
21
|
require 'mongo/event/standalone_discovered'
|
|
21
22
|
|
|
@@ -30,8 +31,15 @@ module Mongo
|
|
|
30
31
|
# When a server is elected primary.
|
|
31
32
|
#
|
|
32
33
|
# @since 2.0.0
|
|
34
|
+
#
|
|
35
|
+
# @deprecated. Will be removed in 3.0
|
|
33
36
|
PRIMARY_ELECTED = 'primary_elected'.freeze
|
|
34
37
|
|
|
38
|
+
# When a server is discovered to be a member of a topology.
|
|
39
|
+
#
|
|
40
|
+
# @since 2.4.0
|
|
41
|
+
MEMBER_DISCOVERED = 'member_discovered'.freeze
|
|
42
|
+
|
|
35
43
|
# When a server is to be removed from a cluster.
|
|
36
44
|
#
|
|
37
45
|
# @since 2.0.6
|
|
@@ -20,10 +20,17 @@ module Mongo
|
|
|
20
20
|
#
|
|
21
21
|
# @since 2.0.6
|
|
22
22
|
class DescriptionChanged
|
|
23
|
+
include Monitoring::Publishable
|
|
23
24
|
|
|
24
|
-
# @return [ Mongo::Cluster ] cluster The
|
|
25
|
+
# @return [ Mongo::Cluster ] cluster The cluster.
|
|
25
26
|
attr_reader :cluster
|
|
26
27
|
|
|
28
|
+
# @return [ Hash ] options The options.
|
|
29
|
+
attr_reader :options
|
|
30
|
+
|
|
31
|
+
# @return [ Monitoring ] monitoring The monitoring.
|
|
32
|
+
attr_reader :monitoring
|
|
33
|
+
|
|
27
34
|
# Initialize the new host added event handler.
|
|
28
35
|
#
|
|
29
36
|
# @example Create the new handler.
|
|
@@ -34,6 +41,8 @@ module Mongo
|
|
|
34
41
|
# @since 2.0.0
|
|
35
42
|
def initialize(cluster)
|
|
36
43
|
@cluster = cluster
|
|
44
|
+
@options = cluster.options
|
|
45
|
+
@monitoring = cluster.monitoring
|
|
37
46
|
end
|
|
38
47
|
|
|
39
48
|
# This event publishes an event to add the cluster and logs the
|
|
@@ -45,7 +54,16 @@ module Mongo
|
|
|
45
54
|
# @param [ Server::Description ] updated The changed description.
|
|
46
55
|
#
|
|
47
56
|
# @since 2.0.0
|
|
48
|
-
def handle(updated)
|
|
57
|
+
def handle(previous, updated)
|
|
58
|
+
publish_sdam_event(
|
|
59
|
+
Monitoring::SERVER_DESCRIPTION_CHANGED,
|
|
60
|
+
Monitoring::Event::ServerDescriptionChanged.new(
|
|
61
|
+
updated.address,
|
|
62
|
+
cluster.topology,
|
|
63
|
+
previous,
|
|
64
|
+
updated
|
|
65
|
+
)
|
|
66
|
+
)
|
|
49
67
|
cluster.add_hosts(updated)
|
|
50
68
|
cluster.remove_hosts(updated)
|
|
51
69
|
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Copyright (C) 2015 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
|
+
module Event
|
|
17
|
+
|
|
18
|
+
# This handles member discovered events for server descriptions.
|
|
19
|
+
#
|
|
20
|
+
# @since 2.4.0
|
|
21
|
+
class MemberDiscovered
|
|
22
|
+
include Monitoring::Publishable
|
|
23
|
+
|
|
24
|
+
# @return [ Mongo::Cluster ] cluster The cluster.
|
|
25
|
+
attr_reader :cluster
|
|
26
|
+
|
|
27
|
+
# @return [ Hash ] options The options.
|
|
28
|
+
attr_reader :options
|
|
29
|
+
|
|
30
|
+
# @return [ Monitoring ] monitoring The monitoring.
|
|
31
|
+
attr_reader :monitoring
|
|
32
|
+
|
|
33
|
+
# Initialize the new member discovered event handler.
|
|
34
|
+
#
|
|
35
|
+
# @example Create the new handler.
|
|
36
|
+
# MemberDiscovered.new(cluster)
|
|
37
|
+
#
|
|
38
|
+
# @param [ Mongo::Cluster ] cluster The cluster to publish from.
|
|
39
|
+
#
|
|
40
|
+
# @since 2.0.0
|
|
41
|
+
def initialize(cluster)
|
|
42
|
+
@cluster = cluster
|
|
43
|
+
@options = cluster.options
|
|
44
|
+
@monitoring = cluster.monitoring
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# This event tells the cluster that a member of a topology is discovered.
|
|
48
|
+
#
|
|
49
|
+
# @example Handle the event.
|
|
50
|
+
# member_discovered.handle(previous_description, description)
|
|
51
|
+
#
|
|
52
|
+
# @param [ Server::Description ] previous The previous description of the server.
|
|
53
|
+
# @param [ Server::Description ] updated The updated description of the server.
|
|
54
|
+
#
|
|
55
|
+
# @since 2.4.0
|
|
56
|
+
def handle(previous, updated)
|
|
57
|
+
if updated.primary? || updated.mongos?
|
|
58
|
+
cluster.elect_primary!(updated)
|
|
59
|
+
else
|
|
60
|
+
cluster.member_discovered
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -18,9 +18,11 @@ module Mongo
|
|
|
18
18
|
# This handles primary elected events for server descriptions.
|
|
19
19
|
#
|
|
20
20
|
# @since 2.0.0
|
|
21
|
+
#
|
|
22
|
+
# @deprecated. Will be removed in 3.0
|
|
21
23
|
class PrimaryElected
|
|
22
24
|
|
|
23
|
-
# @return [ Mongo::Cluster ] cluster The
|
|
25
|
+
# @return [ Mongo::Cluster ] cluster The cluster.
|
|
24
26
|
attr_reader :cluster
|
|
25
27
|
|
|
26
28
|
# Initialize the new primary elected event handler.
|
|
@@ -20,7 +20,7 @@ module Mongo
|
|
|
20
20
|
# @since 2.0.6
|
|
21
21
|
class StandaloneDiscovered
|
|
22
22
|
|
|
23
|
-
# @return [ Mongo::Cluster ] cluster The
|
|
23
|
+
# @return [ Mongo::Cluster ] cluster The cluster.
|
|
24
24
|
attr_reader :cluster
|
|
25
25
|
|
|
26
26
|
# Initialize the new standalone discovered event handler.
|
data/lib/mongo/monitoring.rb
CHANGED
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
require 'mongo/monitoring/event'
|
|
16
16
|
require 'mongo/monitoring/publishable'
|
|
17
17
|
require 'mongo/monitoring/command_log_subscriber'
|
|
18
|
+
require 'mongo/monitoring/sdam_log_subscriber'
|
|
19
|
+
require 'mongo/monitoring/server_description_changed_log_subscriber'
|
|
20
|
+
require 'mongo/monitoring/server_closed_log_subscriber'
|
|
21
|
+
require 'mongo/monitoring/server_opening_log_subscriber'
|
|
22
|
+
require 'mongo/monitoring/topology_changed_log_subscriber'
|
|
23
|
+
require 'mongo/monitoring/topology_opening_log_subscriber'
|
|
18
24
|
|
|
19
25
|
module Mongo
|
|
20
26
|
|
|
@@ -28,6 +34,36 @@ module Mongo
|
|
|
28
34
|
# @since 2.1.0
|
|
29
35
|
COMMAND = 'Command'.freeze
|
|
30
36
|
|
|
37
|
+
# Server closed topic.
|
|
38
|
+
#
|
|
39
|
+
# @since 2.4.0
|
|
40
|
+
SERVER_CLOSED = 'ServerClosed'.freeze
|
|
41
|
+
|
|
42
|
+
# Server description changed topic.
|
|
43
|
+
#
|
|
44
|
+
# @since 2.4.0
|
|
45
|
+
SERVER_DESCRIPTION_CHANGED = 'ServerDescriptionChanged'.freeze
|
|
46
|
+
|
|
47
|
+
# Server opening topic.
|
|
48
|
+
#
|
|
49
|
+
# @since 2.4.0
|
|
50
|
+
SERVER_OPENING = 'ServerOpening'.freeze
|
|
51
|
+
|
|
52
|
+
# Topology changed topic.
|
|
53
|
+
#
|
|
54
|
+
# @since 2.4.0
|
|
55
|
+
TOPOLOGY_CHANGED = 'TopologyChanged'.freeze
|
|
56
|
+
|
|
57
|
+
# Topology closed topic.
|
|
58
|
+
#
|
|
59
|
+
# @since 2.4.0
|
|
60
|
+
TOPOLOGY_CLOSED = 'TopologyClosed'.freeze
|
|
61
|
+
|
|
62
|
+
# Topology opening topic.
|
|
63
|
+
#
|
|
64
|
+
# @since 2.4.0
|
|
65
|
+
TOPOLOGY_OPENING = 'TopologyOpening'.freeze
|
|
66
|
+
|
|
31
67
|
@@operation_id = 0
|
|
32
68
|
@@operation_id_lock = Mutex.new
|
|
33
69
|
|
|
@@ -101,6 +137,11 @@ module Mongo
|
|
|
101
137
|
end
|
|
102
138
|
end
|
|
103
139
|
subscribe(COMMAND, CommandLogSubscriber.new(options))
|
|
140
|
+
subscribe(SERVER_OPENING, ServerOpeningLogSubscriber.new(options))
|
|
141
|
+
subscribe(SERVER_CLOSED, ServerClosedLogSubscriber.new(options))
|
|
142
|
+
subscribe(SERVER_DESCRIPTION_CHANGED, ServerDescriptionChangedLogSubscriber.new(options))
|
|
143
|
+
subscribe(TOPOLOGY_OPENING, TopologyOpeningLogSubscriber.new(options))
|
|
144
|
+
subscribe(TOPOLOGY_CHANGED, TopologyChangedLogSubscriber.new(options))
|
|
104
145
|
end
|
|
105
146
|
end
|
|
106
147
|
|