mongo 2.2.7 → 2.3.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/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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5da2e7df100dcc00d786b3839cce847de888bb3d
|
4
|
+
data.tar.gz: 858a508aa78ac85c6fc5a7506bdd660cdc384a9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a017939e8bfdc94ea78635128b71c5b837f725243777cf32f3d46b380cffc9b7c3e40b9558257af917b2eabf58e145dc8af7d36443b3342e55e08e16ff845b3
|
7
|
+
data.tar.gz: e22e1fbfe7908b55d0289f027483d56891f57757c5f29ff23bfaae1dd7140dfe3856b9e936d27402910fb7874d37576878c6d48e4de74765bac37c28251f9342
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/LICENSE
CHANGED
@@ -175,7 +175,7 @@
|
|
175
175
|
|
176
176
|
END OF TERMS AND CONDITIONS
|
177
177
|
|
178
|
-
Copyright (C) 2009-
|
178
|
+
Copyright (C) 2009-2016 MongoDB, Inc.
|
179
179
|
|
180
180
|
Licensed under the Apache License, Version 2.0 (the "License");
|
181
181
|
you may not use this file except in compliance with the License.
|
data/README.md
CHANGED
@@ -63,7 +63,7 @@ Full release notes and release history are available [here](https://github.com/m
|
|
63
63
|
License
|
64
64
|
-----
|
65
65
|
|
66
|
-
Copyright (C) 2009-
|
66
|
+
Copyright (C) 2009-2016 MongoDB, Inc.
|
67
67
|
|
68
68
|
Licensed under the Apache License, Version 2.0 (the "License");
|
69
69
|
you may not use this file except in compliance with the License.
|
data/Rakefile
CHANGED
@@ -36,7 +36,7 @@ task :docs => 'docs:yard'
|
|
36
36
|
namespace :docs do
|
37
37
|
desc "Generate yard documention"
|
38
38
|
task :yard do
|
39
|
-
out = File.join('docs', Mongo::VERSION)
|
39
|
+
out = File.join('yard-docs', Mongo::VERSION)
|
40
40
|
FileUtils.rm_rf(out)
|
41
41
|
system "yardoc -o #{out} --title mongo-#{Mongo::VERSION}"
|
42
42
|
end
|
data/lib/mongo.rb
CHANGED
data/lib/mongo/address.rb
CHANGED
data/lib/mongo/address/ipv4.rb
CHANGED
data/lib/mongo/address/ipv6.rb
CHANGED
data/lib/mongo/address/unix.rb
CHANGED
data/lib/mongo/auth.rb
CHANGED
data/lib/mongo/auth/cr.rb
CHANGED
data/lib/mongo/auth/ldap.rb
CHANGED
data/lib/mongo/auth/roles.rb
CHANGED
data/lib/mongo/auth/user.rb
CHANGED
data/lib/mongo/auth/user/view.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.
|
@@ -44,7 +44,7 @@ module Mongo
|
|
44
44
|
Operation::Write::CreateUser.new(
|
45
45
|
user: user,
|
46
46
|
db_name: database.name
|
47
|
-
).execute(next_primary
|
47
|
+
).execute(next_primary)
|
48
48
|
end
|
49
49
|
|
50
50
|
# Initialize the new user view.
|
@@ -73,7 +73,7 @@ module Mongo
|
|
73
73
|
Operation::Write::RemoveUser.new(
|
74
74
|
user_name: name,
|
75
75
|
db_name: database.name
|
76
|
-
).execute(next_primary
|
76
|
+
).execute(next_primary)
|
77
77
|
end
|
78
78
|
|
79
79
|
# Update a user in the database.
|
@@ -92,7 +92,7 @@ module Mongo
|
|
92
92
|
Operation::Write::UpdateUser.new(
|
93
93
|
user: user,
|
94
94
|
db_name: database.name
|
95
|
-
).execute(next_primary
|
95
|
+
).execute(next_primary)
|
96
96
|
end
|
97
97
|
|
98
98
|
# Get info for a particular user in the database.
|
@@ -115,7 +115,7 @@ module Mongo
|
|
115
115
|
Operation::Commands::UserQuery.new(
|
116
116
|
user_name: name,
|
117
117
|
db_name: database.name
|
118
|
-
).execute(next_primary
|
118
|
+
).execute(next_primary)
|
119
119
|
end
|
120
120
|
|
121
121
|
def generate(user, options)
|
data/lib/mongo/auth/x509.rb
CHANGED
data/lib/mongo/bson.rb
CHANGED
data/lib/mongo/bulk_write.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.
|
@@ -169,7 +169,7 @@ module Mongo
|
|
169
169
|
def delete(documents, server, operation_id)
|
170
170
|
Operation::Write::Bulk::Delete.new(
|
171
171
|
base_spec(operation_id).merge(:deletes => documents)
|
172
|
-
).execute(server
|
172
|
+
).execute(server)
|
173
173
|
end
|
174
174
|
|
175
175
|
alias :delete_one :delete
|
@@ -178,13 +178,13 @@ module Mongo
|
|
178
178
|
def insert_one(documents, server, operation_id)
|
179
179
|
Operation::Write::Bulk::Insert.new(
|
180
180
|
base_spec(operation_id).merge(:documents => documents)
|
181
|
-
).execute(server
|
181
|
+
).execute(server)
|
182
182
|
end
|
183
183
|
|
184
184
|
def update(documents, server, operation_id)
|
185
185
|
Operation::Write::Bulk::Update.new(
|
186
186
|
base_spec(operation_id).merge(:updates => documents)
|
187
|
-
).execute(server
|
187
|
+
).execute(server)
|
188
188
|
end
|
189
189
|
|
190
190
|
alias :replace_one :update
|
data/lib/mongo/client.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.
|
@@ -226,7 +226,7 @@ module Mongo
|
|
226
226
|
#
|
227
227
|
# @since 2.0.0
|
228
228
|
def read_preference
|
229
|
-
@read_preference ||= ServerSelector.get(
|
229
|
+
@read_preference ||= ServerSelector.get(options[:read] || ServerSelector::PRIMARY)
|
230
230
|
end
|
231
231
|
|
232
232
|
# Use the database with the provided name. This will switch the current
|
data/lib/mongo/cluster.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.
|
@@ -13,6 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require 'mongo/cluster/topology'
|
16
|
+
require 'mongo/cluster/cursor_reaper'
|
16
17
|
|
17
18
|
module Mongo
|
18
19
|
|
@@ -42,6 +43,7 @@ module Mongo
|
|
42
43
|
attr_reader :topology
|
43
44
|
|
44
45
|
def_delegators :topology, :replica_set?, :replica_set_name, :sharded?, :single?, :unknown?
|
46
|
+
def_delegators :@cursor_reaper, :register_cursor, :schedule_kill_cursor, :unregister_cursor
|
45
47
|
|
46
48
|
# Determine if this cluster of servers is equal to another object. Checks the
|
47
49
|
# servers currently in the cluster, not what was configured.
|
@@ -113,6 +115,10 @@ module Mongo
|
|
113
115
|
subscribe_to(Event::PRIMARY_ELECTED, Event::PrimaryElected.new(self))
|
114
116
|
|
115
117
|
seeds.each{ |seed| add(seed) }
|
118
|
+
|
119
|
+
@cursor_reaper = CursorReaper.new
|
120
|
+
@cursor_reaper.run!
|
121
|
+
|
116
122
|
ObjectSpace.define_finalizer(self, self.class.finalize(pools))
|
117
123
|
end
|
118
124
|
|
@@ -130,6 +136,8 @@ module Mongo
|
|
130
136
|
# @since 2.2.0
|
131
137
|
def self.finalize(pools)
|
132
138
|
proc do
|
139
|
+
begin; @cursor_reaper.kill_cursors; rescue; end
|
140
|
+
@cursor_reaper.stop!
|
133
141
|
pools.values.each do |pool|
|
134
142
|
pool.disconnect!
|
135
143
|
end
|
@@ -159,7 +167,8 @@ module Mongo
|
|
159
167
|
#
|
160
168
|
# @since 2.0.0
|
161
169
|
def next_primary(ping = true)
|
162
|
-
ServerSelector.get(ServerSelector::PRIMARY
|
170
|
+
@primary_selector ||= ServerSelector.get(ServerSelector::PRIMARY)
|
171
|
+
@primary_selector.select_server(self, ping)
|
163
172
|
end
|
164
173
|
|
165
174
|
# Elect a primary server from the description that has just changed to a
|
@@ -287,6 +296,8 @@ module Mongo
|
|
287
296
|
#
|
288
297
|
# @since 2.1.0
|
289
298
|
def disconnect!
|
299
|
+
begin; @cursor_reaper.kill_cursors; rescue; end
|
300
|
+
@cursor_reaper.stop!
|
290
301
|
@servers.each { |server| server.disconnect! } and true
|
291
302
|
end
|
292
303
|
|
@@ -300,7 +311,8 @@ module Mongo
|
|
300
311
|
# @since 2.1.0
|
301
312
|
def reconnect!
|
302
313
|
scan!
|
303
|
-
servers.each { |server| server.reconnect! }
|
314
|
+
servers.each { |server| server.reconnect! }
|
315
|
+
@cursor_reaper.restart! and true
|
304
316
|
end
|
305
317
|
|
306
318
|
# Add hosts in a description to the cluster.
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# Copyright (C) 2014-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
|
+
require 'set'
|
16
|
+
|
17
|
+
module Mongo
|
18
|
+
class Cluster
|
19
|
+
|
20
|
+
# A manager that sends kill cursors operations at regular intervals to close
|
21
|
+
# cursors that have been garbage collected without being exhausted.
|
22
|
+
#
|
23
|
+
# @since 2.3.0
|
24
|
+
class CursorReaper
|
25
|
+
extend Forwardable
|
26
|
+
include Retryable
|
27
|
+
|
28
|
+
# The default time interval for the cursor reaper to send pending kill cursors operations.
|
29
|
+
#
|
30
|
+
# @since 2.3.0
|
31
|
+
FREQUENCY = 1.freeze
|
32
|
+
|
33
|
+
# Create a cursor reaper.
|
34
|
+
#
|
35
|
+
# @example Create a CursorReaper.
|
36
|
+
# Mongo::Cluster::CursorReaper.new(cluster)
|
37
|
+
#
|
38
|
+
# @api private
|
39
|
+
#
|
40
|
+
# @since 2.3.0
|
41
|
+
def initialize
|
42
|
+
@to_kill = {}
|
43
|
+
@active_cursors = Set.new
|
44
|
+
@mutex = Mutex.new
|
45
|
+
end
|
46
|
+
|
47
|
+
# Start the cursor reaper's thread.
|
48
|
+
#
|
49
|
+
# @example Start the cursor reaper's thread.
|
50
|
+
# reaper.run!
|
51
|
+
#
|
52
|
+
# @api private
|
53
|
+
#
|
54
|
+
# @since 2.3.0
|
55
|
+
def run!
|
56
|
+
@thread && @thread.alive? ? @thread : start!
|
57
|
+
end
|
58
|
+
alias :restart! :run!
|
59
|
+
|
60
|
+
# Schedule a kill cursors operation to be eventually executed.
|
61
|
+
#
|
62
|
+
# @example Schedule a kill cursors operation.
|
63
|
+
# cursor_reaper.schedule_kill_cursor(id, op_spec, server)
|
64
|
+
#
|
65
|
+
# @param [ Integer ] id The id of the cursor to kill.
|
66
|
+
# @param [ Hash ] op_spec The spec for the kill cursors op.
|
67
|
+
# @param [ Mongo::Server ] server The server to send the kill cursors operation to.
|
68
|
+
#
|
69
|
+
# @api private
|
70
|
+
#
|
71
|
+
# @since 2.3.0
|
72
|
+
def schedule_kill_cursor(id, op_spec, server)
|
73
|
+
@mutex.synchronize do
|
74
|
+
if @active_cursors.include?(id)
|
75
|
+
@to_kill[server] ||= Set.new
|
76
|
+
@to_kill[server] << op_spec
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Register a cursor id as active.
|
82
|
+
#
|
83
|
+
# @example Register a cursor as active.
|
84
|
+
# cursor_reaper.register_cursor(id)
|
85
|
+
#
|
86
|
+
# @param [ Integer ] id The id of the cursor to register as active.
|
87
|
+
#
|
88
|
+
# @api private
|
89
|
+
#
|
90
|
+
# @since 2.3.0
|
91
|
+
def register_cursor(id)
|
92
|
+
if id && id > 0
|
93
|
+
@mutex.synchronize do
|
94
|
+
@active_cursors << id
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Unregister a cursor id, indicating that it's no longer active.
|
100
|
+
#
|
101
|
+
# @example Unregister a cursor.
|
102
|
+
# cursor_reaper.unregister_cursor(id)
|
103
|
+
#
|
104
|
+
# @param [ Integer ] id The id of the cursor to unregister.
|
105
|
+
#
|
106
|
+
# @api private
|
107
|
+
#
|
108
|
+
# @since 2.3.0
|
109
|
+
def unregister_cursor(id)
|
110
|
+
@mutex.synchronize do
|
111
|
+
@active_cursors.delete(id)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Stop the cursor reaper's thread.
|
116
|
+
#
|
117
|
+
# @example Stop the cursor reaper's thread.
|
118
|
+
# reaper.stop!
|
119
|
+
#
|
120
|
+
# @api private
|
121
|
+
#
|
122
|
+
# @since 2.3.0
|
123
|
+
def stop!
|
124
|
+
@thread.kill && @thread.stop?
|
125
|
+
end
|
126
|
+
|
127
|
+
# Execute all pending kill cursors operations.
|
128
|
+
#
|
129
|
+
# @example Execute pending kill cursors operations.
|
130
|
+
# cursor_reaper.kill_cursors
|
131
|
+
#
|
132
|
+
# @api private
|
133
|
+
#
|
134
|
+
# @since 2.3.0
|
135
|
+
def kill_cursors
|
136
|
+
to_kill_copy = {}
|
137
|
+
active_cursors_copy = []
|
138
|
+
|
139
|
+
@mutex.synchronize do
|
140
|
+
to_kill_copy = @to_kill.dup
|
141
|
+
active_cursors_copy = @active_cursors.dup
|
142
|
+
@to_kill = {}
|
143
|
+
end
|
144
|
+
|
145
|
+
to_kill_copy.each do |server, op_specs|
|
146
|
+
op_specs.each do |op_spec|
|
147
|
+
if server.features.find_command_enabled?
|
148
|
+
Cursor::Builder::KillCursorsCommand.update_cursors(op_spec, active_cursors_copy.to_a)
|
149
|
+
if Cursor::Builder::KillCursorsCommand.get_cursors_list(op_spec).size > 0
|
150
|
+
Operation::Commands::Command.new(op_spec).execute(server)
|
151
|
+
end
|
152
|
+
else
|
153
|
+
Cursor::Builder::OpKillCursors.update_cursors(op_spec, active_cursors_copy.to_a)
|
154
|
+
if Cursor::Builder::OpKillCursors.get_cursors_list(op_spec).size > 0
|
155
|
+
Operation::KillCursors.new(op_spec).execute(server)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
private
|
163
|
+
|
164
|
+
def start!
|
165
|
+
@thread = Thread.new(FREQUENCY) do |i|
|
166
|
+
loop do
|
167
|
+
sleep(i)
|
168
|
+
kill_cursors
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|