mongo 2.2.7 → 2.3.0
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/LICENSE +1 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/mongo.rb +1 -1
- data/lib/mongo/address.rb +1 -1
- data/lib/mongo/address/ipv4.rb +1 -1
- data/lib/mongo/address/ipv6.rb +1 -1
- data/lib/mongo/address/unix.rb +1 -1
- data/lib/mongo/auth.rb +1 -1
- data/lib/mongo/auth/cr.rb +1 -1
- data/lib/mongo/auth/ldap.rb +1 -1
- data/lib/mongo/auth/roles.rb +1 -1
- data/lib/mongo/auth/user.rb +1 -1
- data/lib/mongo/auth/user/view.rb +5 -5
- data/lib/mongo/auth/x509.rb +1 -1
- data/lib/mongo/bson.rb +1 -1
- data/lib/mongo/bulk_write.rb +4 -4
- data/lib/mongo/bulk_write/combineable.rb +1 -1
- data/lib/mongo/bulk_write/ordered_combiner.rb +1 -1
- data/lib/mongo/bulk_write/result.rb +1 -1
- data/lib/mongo/bulk_write/result_combiner.rb +1 -1
- data/lib/mongo/bulk_write/transformable.rb +1 -1
- data/lib/mongo/bulk_write/unordered_combiner.rb +1 -1
- data/lib/mongo/bulk_write/validatable.rb +1 -1
- data/lib/mongo/client.rb +2 -2
- data/lib/mongo/cluster.rb +15 -3
- data/lib/mongo/cluster/cursor_reaper.rb +174 -0
- data/lib/mongo/cluster/topology.rb +1 -1
- data/lib/mongo/cluster/topology/replica_set.rb +1 -1
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/cluster/topology/single.rb +1 -1
- data/lib/mongo/cluster/topology/unknown.rb +1 -1
- data/lib/mongo/collection.rb +5 -4
- data/lib/mongo/collection/view.rb +4 -4
- data/lib/mongo/collection/view/aggregation.rb +2 -2
- data/lib/mongo/collection/view/builder.rb +1 -1
- data/lib/mongo/collection/view/builder/aggregation.rb +1 -1
- data/lib/mongo/collection/view/builder/find_command.rb +1 -1
- data/lib/mongo/collection/view/builder/flags.rb +1 -1
- data/lib/mongo/collection/view/builder/map_reduce.rb +1 -1
- data/lib/mongo/collection/view/builder/modifiers.rb +1 -1
- data/lib/mongo/collection/view/builder/op_query.rb +1 -1
- data/lib/mongo/collection/view/explainable.rb +1 -1
- data/lib/mongo/collection/view/immutable.rb +1 -1
- data/lib/mongo/collection/view/iterable.rb +2 -2
- data/lib/mongo/collection/view/map_reduce.rb +3 -3
- data/lib/mongo/collection/view/readable.rb +23 -6
- data/lib/mongo/collection/view/writable.rb +3 -3
- data/lib/mongo/cursor.rb +50 -7
- data/lib/mongo/cursor/builder.rb +1 -1
- data/lib/mongo/cursor/builder/get_more_command.rb +1 -1
- data/lib/mongo/cursor/builder/kill_cursors_command.rb +29 -1
- data/lib/mongo/cursor/builder/op_get_more.rb +1 -1
- data/lib/mongo/cursor/builder/op_kill_cursors.rb +29 -1
- data/lib/mongo/database.rb +4 -4
- data/lib/mongo/database/view.rb +2 -2
- data/lib/mongo/dbref.rb +4 -3
- data/lib/mongo/error.rb +1 -1
- data/lib/mongo/error/bulk_write_error.rb +1 -1
- data/lib/mongo/error/closed_stream.rb +1 -1
- data/lib/mongo/error/extra_file_chunk.rb +1 -1
- data/lib/mongo/error/file_not_found.rb +1 -1
- data/lib/mongo/error/invalid_bulk_operation.rb +1 -1
- data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -1
- data/lib/mongo/error/invalid_collection_name.rb +1 -1
- data/lib/mongo/error/invalid_database_name.rb +1 -1
- data/lib/mongo/error/invalid_document.rb +1 -1
- data/lib/mongo/error/invalid_file.rb +1 -1
- data/lib/mongo/error/invalid_file_revision.rb +1 -1
- data/lib/mongo/error/invalid_nonce.rb +1 -1
- data/lib/mongo/error/invalid_replacement_document.rb +1 -1
- data/lib/mongo/error/invalid_server_preference.rb +1 -1
- data/lib/mongo/error/invalid_signature.rb +1 -1
- data/lib/mongo/error/invalid_update_document.rb +1 -1
- data/lib/mongo/error/invalid_uri.rb +1 -1
- data/lib/mongo/error/invalid_write_concern.rb +1 -1
- data/lib/mongo/error/max_bson_size.rb +1 -1
- data/lib/mongo/error/max_message_size.rb +1 -1
- data/lib/mongo/error/missing_file_chunk.rb +1 -1
- data/lib/mongo/error/multi_index_drop.rb +1 -1
- data/lib/mongo/error/need_primary_server.rb +1 -1
- data/lib/mongo/error/no_server_available.rb +4 -2
- data/lib/mongo/error/operation_failure.rb +1 -1
- data/lib/mongo/error/parser.rb +1 -1
- data/lib/mongo/error/socket_error.rb +1 -1
- data/lib/mongo/error/socket_timeout_error.rb +1 -1
- data/lib/mongo/error/unchangeable_collection_option.rb +1 -1
- data/lib/mongo/error/unexpected_chunk_length.rb +1 -1
- data/lib/mongo/error/unexpected_response.rb +1 -1
- data/lib/mongo/error/unsupported_features.rb +1 -1
- data/lib/mongo/event.rb +1 -1
- data/lib/mongo/event/description_changed.rb +1 -1
- data/lib/mongo/event/publisher.rb +1 -1
- data/lib/mongo/event/subscriber.rb +1 -1
- data/lib/mongo/grid.rb +1 -1
- data/lib/mongo/grid/file.rb +6 -2
- data/lib/mongo/grid/file/chunk.rb +6 -4
- data/lib/mongo/grid/file/info.rb +7 -3
- data/lib/mongo/grid/fs_bucket.rb +12 -6
- data/lib/mongo/grid/stream.rb +1 -1
- data/lib/mongo/grid/stream/read.rb +2 -4
- data/lib/mongo/grid/stream/write.rb +4 -3
- data/lib/mongo/index.rb +1 -1
- data/lib/mongo/index/view.rb +5 -4
- data/lib/mongo/loggable.rb +1 -1
- data/lib/mongo/logger.rb +1 -1
- data/lib/mongo/monitoring.rb +1 -1
- data/lib/mongo/operation.rb +1 -1
- data/lib/mongo/operation/commands.rb +1 -1
- data/lib/mongo/operation/commands/aggregate.rb +7 -7
- data/lib/mongo/operation/commands/aggregate/result.rb +1 -1
- data/lib/mongo/operation/commands/collections_info.rb +10 -9
- data/lib/mongo/operation/commands/collections_info/result.rb +1 -1
- data/lib/mongo/operation/commands/command.rb +1 -1
- data/lib/mongo/operation/commands/indexes.rb +12 -11
- data/lib/mongo/operation/commands/list_collections.rb +1 -1
- data/lib/mongo/operation/commands/list_collections/result.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes/result.rb +1 -1
- data/lib/mongo/operation/commands/map_reduce.rb +1 -1
- data/lib/mongo/operation/commands/map_reduce/result.rb +1 -1
- data/lib/mongo/operation/commands/user_query.rb +11 -10
- data/lib/mongo/operation/commands/users_info.rb +2 -2
- data/lib/mongo/operation/commands/users_info/result.rb +1 -1
- data/lib/mongo/operation/executable.rb +8 -7
- data/lib/mongo/operation/kill_cursors.rb +2 -2
- data/lib/mongo/operation/limited.rb +1 -1
- data/lib/mongo/operation/read.rb +1 -1
- data/lib/mongo/operation/read/get_more.rb +2 -2
- data/lib/mongo/operation/read/query.rb +1 -1
- data/lib/mongo/operation/read/query/result.rb +1 -1
- data/lib/mongo/operation/read_preference.rb +10 -10
- data/lib/mongo/operation/result.rb +1 -1
- data/lib/mongo/operation/specifiable.rb +2 -2
- data/lib/mongo/operation/write.rb +1 -1
- data/lib/mongo/operation/write/bulk.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulkable.rb +9 -9
- data/lib/mongo/operation/write/bulk/delete.rb +3 -3
- data/lib/mongo/operation/write/bulk/delete/result.rb +1 -1
- data/lib/mongo/operation/write/bulk/insert.rb +5 -5
- data/lib/mongo/operation/write/bulk/insert/result.rb +1 -1
- data/lib/mongo/operation/write/bulk/legacy_mergable.rb +1 -1
- data/lib/mongo/operation/write/bulk/mergable.rb +1 -1
- data/lib/mongo/operation/write/bulk/update.rb +3 -3
- data/lib/mongo/operation/write/bulk/update/result.rb +1 -1
- data/lib/mongo/operation/write/command.rb +1 -1
- data/lib/mongo/operation/write/command/create_index.rb +1 -1
- data/lib/mongo/operation/write/command/create_user.rb +1 -1
- data/lib/mongo/operation/write/command/delete.rb +1 -1
- data/lib/mongo/operation/write/command/drop_index.rb +1 -1
- data/lib/mongo/operation/write/command/insert.rb +11 -1
- data/lib/mongo/operation/write/command/remove_user.rb +1 -1
- data/lib/mongo/operation/write/command/update.rb +1 -1
- data/lib/mongo/operation/write/command/update_user.rb +1 -1
- data/lib/mongo/operation/write/command/writable.rb +7 -6
- data/lib/mongo/operation/write/create_index.rb +1 -1
- data/lib/mongo/operation/write/create_user.rb +1 -1
- data/lib/mongo/operation/write/delete.rb +1 -1
- data/lib/mongo/operation/write/delete/result.rb +1 -1
- data/lib/mongo/operation/write/drop_index.rb +5 -5
- data/lib/mongo/operation/write/gle.rb +3 -3
- data/lib/mongo/operation/write/idable.rb +1 -1
- data/lib/mongo/operation/write/insert.rb +5 -5
- data/lib/mongo/operation/write/insert/result.rb +1 -1
- data/lib/mongo/operation/write/remove_user.rb +1 -1
- data/lib/mongo/operation/write/update.rb +1 -1
- data/lib/mongo/operation/write/update/result.rb +1 -1
- data/lib/mongo/operation/write/update_user.rb +1 -1
- data/lib/mongo/operation/write/write_command_enabled.rb +10 -9
- data/lib/mongo/protocol/bit_vector.rb +2 -2
- data/lib/mongo/protocol/delete.rb +1 -1
- data/lib/mongo/protocol/get_more.rb +1 -1
- data/lib/mongo/protocol/insert.rb +5 -1
- data/lib/mongo/protocol/kill_cursors.rb +1 -1
- data/lib/mongo/protocol/message.rb +9 -5
- data/lib/mongo/protocol/query.rb +1 -1
- data/lib/mongo/protocol/reply.rb +1 -1
- data/lib/mongo/protocol/serializers.rb +8 -8
- data/lib/mongo/protocol/update.rb +1 -1
- data/lib/mongo/server.rb +40 -3
- data/lib/mongo/server/connectable.rb +1 -1
- data/lib/mongo/server/connection.rb +4 -2
- data/lib/mongo/server/connection_pool.rb +1 -1
- data/lib/mongo/server/connection_pool/queue.rb +1 -1
- data/lib/mongo/server/context.rb +3 -1
- data/lib/mongo/server/description.rb +1 -1
- data/lib/mongo/server/description/inspector/description_changed.rb +1 -1
- data/lib/mongo/server/monitor.rb +1 -1
- data/lib/mongo/server_selector.rb +2 -1
- data/lib/mongo/server_selector/nearest.rb +1 -1
- data/lib/mongo/server_selector/primary.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 +12 -7
- data/lib/mongo/socket.rb +1 -1
- data/lib/mongo/socket/ssl.rb +1 -1
- data/lib/mongo/socket/tcp.rb +1 -1
- data/lib/mongo/socket/unix.rb +1 -1
- data/lib/mongo/uri.rb +1 -1
- data/lib/mongo/version.rb +2 -2
- data/lib/mongo/write_concern/acknowledged.rb +1 -1
- data/lib/mongo/write_concern/normalizable.rb +1 -1
- data/lib/mongo/write_concern/unacknowledged.rb +1 -1
- data/mongo.gemspec +1 -1
- data/spec/mongo/client_spec.rb +2 -2
- data/spec/mongo/cluster/cursor_reaper_spec.rb +216 -0
- data/spec/mongo/cluster_spec.rb +36 -5
- data/spec/mongo/collection/view/aggregation_spec.rb +2 -2
- data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
- data/spec/mongo/collection/view/readable_spec.rb +203 -5
- data/spec/mongo/collection/view_spec.rb +10 -0
- data/spec/mongo/collection_spec.rb +64 -18
- data/spec/mongo/cursor_spec.rb +89 -0
- data/spec/mongo/database_spec.rb +79 -13
- data/spec/mongo/grid/fs_bucket_spec.rb +119 -1
- data/spec/mongo/grid/stream/write_spec.rb +63 -12
- data/spec/mongo/index/view_spec.rb +19 -0
- data/spec/mongo/operation/commands/aggregate_spec.rb +10 -7
- data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
- data/spec/mongo/operation/commands/command_spec.rb +3 -3
- data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
- data/spec/mongo/operation/commands/map_reduce_spec.rb +2 -2
- data/spec/mongo/operation/kill_cursors_spec.rb +10 -19
- data/spec/mongo/operation/read/get_more_spec.rb +13 -25
- data/spec/mongo/operation/read/query_spec.rb +26 -30
- data/spec/mongo/operation/read_preference_spec.rb +11 -11
- data/spec/mongo/operation/specifiable_spec.rb +31 -0
- data/spec/mongo/operation/write/bulk/delete_spec.rb +16 -18
- data/spec/mongo/operation/write/bulk/insert_spec.rb +17 -18
- data/spec/mongo/operation/write/bulk/update_spec.rb +20 -25
- data/spec/mongo/operation/write/command/delete_spec.rb +26 -32
- data/spec/mongo/operation/write/command/insert_spec.rb +24 -31
- data/spec/mongo/operation/write/command/update_spec.rb +24 -32
- data/spec/mongo/operation/write/create_index_spec.rb +4 -4
- data/spec/mongo/operation/write/create_user_spec.rb +3 -3
- data/spec/mongo/operation/write/delete_spec.rb +51 -22
- data/spec/mongo/operation/write/drop_index_spec.rb +2 -2
- data/spec/mongo/operation/write/insert_spec.rb +42 -11
- data/spec/mongo/operation/write/remove_user_spec.rb +4 -4
- data/spec/mongo/operation/write/update_spec.rb +34 -6
- data/spec/mongo/operation/write/update_user_spec.rb +1 -1
- data/spec/mongo/server/connection_spec.rb +22 -14
- data/spec/mongo/server_selection_spec.rb +2 -2
- data/spec/mongo/server_selector/nearest_spec.rb +4 -4
- data/spec/mongo/server_selector/primary_preferred_spec.rb +4 -4
- data/spec/mongo/server_selector/primary_spec.rb +2 -2
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +4 -4
- data/spec/mongo/server_selector/secondary_spec.rb +3 -3
- data/spec/mongo/server_selector_spec.rb +82 -3
- data/spec/mongo/server_spec.rb +0 -20
- data/spec/support/command_monitoring.rb +1 -1
- data/spec/support/connection_string.rb +1 -1
- data/spec/support/crud.rb +1 -1
- data/spec/support/crud/read.rb +1 -1
- data/spec/support/crud/write.rb +1 -1
- data/spec/support/gridfs.rb +1 -1
- data/spec/support/shared/server_selector.rb +3 -3
- metadata +7 -10
- metadata.gz.sig +0 -0
- data/lib/csasl/csasl.bundle +0 -0
- data/spec/mongo/operation/write/response_spec.rb +0 -85
- data/spec/support/shared/operation.rb +0 -100
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2014-
|
1
|
+
# Copyright (C) 2014-2016 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.
|
@@ -37,7 +37,8 @@ module Mongo
|
|
37
37
|
#
|
38
38
|
# @since 2.0.0
|
39
39
|
def ==(other)
|
40
|
-
name == other.name &&
|
40
|
+
name == other.name &&
|
41
|
+
tag_sets == other.tag_sets
|
41
42
|
end
|
42
43
|
|
43
44
|
# Initialize the server selector.
|
@@ -50,9 +51,6 @@ module Mongo
|
|
50
51
|
#
|
51
52
|
# @param [ Hash ] options The server preference options.
|
52
53
|
#
|
53
|
-
# @option options [ Integer ] :server_selection_timeout The timeout in seconds
|
54
|
-
# for selecting a server.
|
55
|
-
#
|
56
54
|
# @option options [ Integer ] :local_threshold The local threshold boundary for
|
57
55
|
# nearest selection in seconds.
|
58
56
|
#
|
@@ -76,8 +74,7 @@ module Mongo
|
|
76
74
|
#
|
77
75
|
# @since 2.2.0
|
78
76
|
def inspect
|
79
|
-
"#<#{self.class.name}:0x#{object_id} tag_sets=#{tag_sets.inspect}
|
80
|
-
"server_selection_timeout=#{server_selection_timeout} local_threshold=#{local_threshold}>"
|
77
|
+
"#<#{self.class.name}:0x#{object_id} tag_sets=#{tag_sets.inspect}>"
|
81
78
|
end
|
82
79
|
|
83
80
|
# Select a server from eligible candidates.
|
@@ -91,6 +88,8 @@ module Mongo
|
|
91
88
|
#
|
92
89
|
# @since 2.0.0
|
93
90
|
def select_server(cluster, ping = true)
|
91
|
+
@local_threshold = cluster.options[:local_threshold] || LOCAL_THRESHOLD
|
92
|
+
@server_selection_timeout = cluster.options[:server_selection_timeout] || SERVER_SELECTION_TIMEOUT
|
94
93
|
deadline = Time.now + server_selection_timeout
|
95
94
|
while (deadline - Time.now) > 0
|
96
95
|
servers = candidates(cluster)
|
@@ -117,6 +116,9 @@ module Mongo
|
|
117
116
|
# @return [ Float ] The timeout.
|
118
117
|
#
|
119
118
|
# @since 2.0.0
|
119
|
+
#
|
120
|
+
# @deprecated This setting is now taken from the cluster options when a server is selected.
|
121
|
+
# Will be removed in 3.0.
|
120
122
|
def server_selection_timeout
|
121
123
|
@server_selection_timeout ||=
|
122
124
|
(options[:server_selection_timeout] || ServerSelector::SERVER_SELECTION_TIMEOUT)
|
@@ -130,6 +132,9 @@ module Mongo
|
|
130
132
|
# @return [ Float ] The local threshold.
|
131
133
|
#
|
132
134
|
# @since 2.0.0
|
135
|
+
#
|
136
|
+
# @deprecated This setting is now taken from the cluster options when a server is selected.
|
137
|
+
# Will be removed in 3.0.
|
133
138
|
def local_threshold
|
134
139
|
@local_threshold ||= (options[:local_threshold] || ServerSelector::LOCAL_THRESHOLD)
|
135
140
|
end
|
data/lib/mongo/socket.rb
CHANGED
data/lib/mongo/socket/ssl.rb
CHANGED
data/lib/mongo/socket/tcp.rb
CHANGED
data/lib/mongo/socket/unix.rb
CHANGED
data/lib/mongo/uri.rb
CHANGED
data/lib/mongo/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2014-
|
1
|
+
# Copyright (C) 2014-2016 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.
|
@@ -17,5 +17,5 @@ module Mongo
|
|
17
17
|
# The current version of the driver.
|
18
18
|
#
|
19
19
|
# @since 2.0.0
|
20
|
-
VERSION = '2.
|
20
|
+
VERSION = '2.3.0'.freeze
|
21
21
|
end
|
data/mongo.gemspec
CHANGED
data/spec/mongo/client_spec.rb
CHANGED
@@ -411,8 +411,8 @@ describe Mongo::Client do
|
|
411
411
|
expect(preference).to be_a(Mongo::ServerSelector::Primary)
|
412
412
|
end
|
413
413
|
|
414
|
-
it 'passes the options to the
|
415
|
-
expect(
|
414
|
+
it 'passes the options to the cluster' do
|
415
|
+
expect(client.cluster.options[:server_selection_timeout]).to eq(2)
|
416
416
|
end
|
417
417
|
end
|
418
418
|
|
@@ -0,0 +1,216 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongo::Cluster::CursorReaper do
|
4
|
+
|
5
|
+
after do
|
6
|
+
authorized_collection.delete_many
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:reaper) do
|
10
|
+
described_class.new
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:active_cursors) do
|
14
|
+
reaper.instance_variable_get(:@active_cursors)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#intialize' do
|
18
|
+
|
19
|
+
it 'initializes a hash for servers and their kill cursors ops' do
|
20
|
+
expect(reaper.instance_variable_get(:@to_kill)).to be_a(Hash)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'initializes a set for the list of active cursors' do
|
24
|
+
expect(reaper.instance_variable_get(:@active_cursors)).to be_a(Set)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#run' do
|
29
|
+
|
30
|
+
it 'starts a thread calling #kill_cursors' do
|
31
|
+
reaper.run!
|
32
|
+
expect(reaper.instance_variable_get(:@thread)).to be_a(Thread)
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when run is called more than once' do
|
36
|
+
|
37
|
+
let!(:reaper_thread) do
|
38
|
+
reaper.run!
|
39
|
+
reaper.instance_variable_get(:@reaper)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'only starts a thread once' do
|
43
|
+
reaper.run!
|
44
|
+
expect(reaper.instance_variable_get(:@reaper)).to be(reaper_thread)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when there are ops in the list to execute' do
|
49
|
+
|
50
|
+
let(:server) { double('server') }
|
51
|
+
let(:cursor_id) { 1 }
|
52
|
+
let(:op_spec_1) { double('op_spec_1') }
|
53
|
+
let(:op_spec_2) { double('op_spec_2') }
|
54
|
+
let(:to_kill) { reaper.instance_variable_get(:@to_kill)}
|
55
|
+
|
56
|
+
before do
|
57
|
+
reaper.register_cursor(cursor_id)
|
58
|
+
reaper.schedule_kill_cursor(cursor_id, op_spec_1, server)
|
59
|
+
reaper.run!
|
60
|
+
sleep(Mongo::Cluster::CursorReaper::FREQUENCY + 1)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'executes the ops in the thread' do
|
64
|
+
expect(reaper.instance_variable_get(:@to_kill).size).to eq(0)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#schedule_kill_cursor' do
|
70
|
+
|
71
|
+
let(:server) { double('server') }
|
72
|
+
let(:cursor_id) { 1 }
|
73
|
+
let(:op_spec_1) { double('op_spec_1') }
|
74
|
+
let(:op_spec_2) { double('op_spec_2') }
|
75
|
+
let(:to_kill) { reaper.instance_variable_get(:@to_kill)}
|
76
|
+
|
77
|
+
context 'when the cursor is on the list of active cursors' do
|
78
|
+
|
79
|
+
before do
|
80
|
+
reaper.register_cursor(cursor_id)
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'when there is not a list already for the server' do
|
84
|
+
|
85
|
+
before do
|
86
|
+
reaper.schedule_kill_cursor(cursor_id, op_spec_1, server)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'initializes the list of op specs to a set' do
|
90
|
+
expect(to_kill.keys).to eq([ server ])
|
91
|
+
expect(to_kill[server]).to eq(Set.new([op_spec_1]))
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when there is a list of ops already for the server' do
|
96
|
+
|
97
|
+
before do
|
98
|
+
reaper.schedule_kill_cursor(cursor_id, op_spec_1, server)
|
99
|
+
reaper.schedule_kill_cursor(cursor_id, op_spec_2, server)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'adds the op to the server list' do
|
103
|
+
expect(to_kill.keys).to eq([ server ])
|
104
|
+
expect(to_kill[server]).to contain_exactly(op_spec_1, op_spec_2)
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when the same op is added more than once' do
|
108
|
+
|
109
|
+
before do
|
110
|
+
reaper.schedule_kill_cursor(cursor_id, op_spec_2, server)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'does not allow duplicates ops for a server' do
|
114
|
+
expect(to_kill.keys).to eq([ server ])
|
115
|
+
expect(to_kill[server]).to contain_exactly(op_spec_1, op_spec_2)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when the cursor is not on the list of active cursors' do
|
122
|
+
|
123
|
+
before do
|
124
|
+
reaper.schedule_kill_cursor(cursor_id, op_spec_1, server)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'does not add the kill cursors op spec to the list' do
|
128
|
+
expect(to_kill).to eq({})
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#register_cursor' do
|
134
|
+
|
135
|
+
before do
|
136
|
+
reaper.register_cursor(cursor_id)
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'when the cursor id is nil' do
|
140
|
+
|
141
|
+
let(:cursor_id) do
|
142
|
+
nil
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'does not register the cursor' do
|
146
|
+
expect(active_cursors.size).to be(0)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'when the cursor id is 0' do
|
151
|
+
|
152
|
+
let(:cursor_id) do
|
153
|
+
0
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'does not register the cursor' do
|
157
|
+
expect(active_cursors.size).to be(0)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'when the cursor id is a valid id' do
|
162
|
+
|
163
|
+
let(:cursor_id) do
|
164
|
+
2
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'registers the cursor id as active' do
|
168
|
+
expect(active_cursors).to eq(Set.new([2]))
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#unregister_cursor' do
|
174
|
+
|
175
|
+
context 'when the cursor id is in the active cursors list' do
|
176
|
+
|
177
|
+
before do
|
178
|
+
reaper.register_cursor(2)
|
179
|
+
reaper.unregister_cursor(2)
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'removes the cursor id' do
|
183
|
+
expect(active_cursors.size).to eq(0)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe '#stop!' do
|
189
|
+
|
190
|
+
let(:thread) do
|
191
|
+
reaper.run!
|
192
|
+
reaper.stop!
|
193
|
+
sleep(0.5)
|
194
|
+
reaper.instance_variable_get(:@thread)
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'stops the thread from running' do
|
198
|
+
expect(thread.alive?).to be(false)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe '#restart!' do
|
203
|
+
|
204
|
+
let(:thread) do
|
205
|
+
reaper.run!
|
206
|
+
reaper.stop!
|
207
|
+
sleep(0.5)
|
208
|
+
reaper.restart!
|
209
|
+
reaper.instance_variable_get(:@thread)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'restarts the thread' do
|
213
|
+
expect(thread.alive?).to be(true)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
data/spec/mongo/cluster_spec.rb
CHANGED
@@ -62,7 +62,7 @@ describe Mongo::Cluster do
|
|
62
62
|
describe '#inspect' do
|
63
63
|
|
64
64
|
let(:preference) do
|
65
|
-
Mongo::ServerSelector.get
|
65
|
+
Mongo::ServerSelector.get(ServerSelector::PRIMARY)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'displays the cluster seeds and topology' do
|
@@ -74,7 +74,7 @@ describe Mongo::Cluster do
|
|
74
74
|
describe '#replica_set_name' do
|
75
75
|
|
76
76
|
let(:preference) do
|
77
|
-
Mongo::ServerSelector.get
|
77
|
+
Mongo::ServerSelector.get(ServerSelector::PRIMARY)
|
78
78
|
end
|
79
79
|
|
80
80
|
context 'when the option is provided' do
|
@@ -107,7 +107,7 @@ describe Mongo::Cluster do
|
|
107
107
|
describe '#scan!' do
|
108
108
|
|
109
109
|
let(:preference) do
|
110
|
-
Mongo::ServerSelector.get
|
110
|
+
Mongo::ServerSelector.get(ServerSelector::PRIMARY)
|
111
111
|
end
|
112
112
|
|
113
113
|
let(:known_servers) do
|
@@ -223,26 +223,36 @@ describe Mongo::Cluster do
|
|
223
223
|
cluster.instance_variable_get(:@servers)
|
224
224
|
end
|
225
225
|
|
226
|
+
let(:cursor_reaper) do
|
227
|
+
cluster.instance_variable_get(:@cursor_reaper)
|
228
|
+
end
|
229
|
+
|
226
230
|
before do
|
227
231
|
known_servers.each do |server|
|
228
232
|
expect(server).to receive(:disconnect!).and_call_original
|
229
233
|
end
|
234
|
+
expect(cursor_reaper).to receive(:stop!).and_call_original
|
230
235
|
end
|
231
236
|
|
232
|
-
it 'disconnects each server and returns true' do
|
237
|
+
it 'disconnects each server and the cursor reaper and returns true' do
|
233
238
|
expect(cluster.disconnect!).to be(true)
|
234
239
|
end
|
235
240
|
end
|
236
241
|
|
237
242
|
describe '#reconnect!' do
|
238
243
|
|
244
|
+
let(:cursor_reaper) do
|
245
|
+
cluster.instance_variable_get(:@cursor_reaper)
|
246
|
+
end
|
247
|
+
|
239
248
|
before do
|
240
249
|
cluster.servers.each do |server|
|
241
250
|
expect(server).to receive(:reconnect!).and_call_original
|
242
251
|
end
|
252
|
+
expect(cursor_reaper).to receive(:restart!).and_call_original
|
243
253
|
end
|
244
254
|
|
245
|
-
it 'reconnects each server and returns true' do
|
255
|
+
it 'reconnects each server and the cursor reaper and returns true' do
|
246
256
|
expect(cluster.reconnect!).to be(true)
|
247
257
|
end
|
248
258
|
end
|
@@ -432,4 +442,25 @@ describe Mongo::Cluster do
|
|
432
442
|
end
|
433
443
|
end
|
434
444
|
end
|
445
|
+
|
446
|
+
describe '#next_primary' do
|
447
|
+
|
448
|
+
let(:cluster) do
|
449
|
+
authorized_client.cluster
|
450
|
+
end
|
451
|
+
|
452
|
+
let(:primary_candidates) do
|
453
|
+
if cluster.single?
|
454
|
+
cluster.servers
|
455
|
+
elsif cluster.sharded?
|
456
|
+
cluster.servers
|
457
|
+
else
|
458
|
+
cluster.servers.select { |s| s.primary? }
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
it 'always returns the primary, mongos, or standalone' do
|
463
|
+
expect(primary_candidates).to include(cluster.next_primary)
|
464
|
+
end
|
465
|
+
end
|
435
466
|
end
|