mongo 2.2.7 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE +1 -1
  5. data/README.md +1 -1
  6. data/Rakefile +1 -1
  7. data/lib/mongo.rb +1 -1
  8. data/lib/mongo/address.rb +1 -1
  9. data/lib/mongo/address/ipv4.rb +1 -1
  10. data/lib/mongo/address/ipv6.rb +1 -1
  11. data/lib/mongo/address/unix.rb +1 -1
  12. data/lib/mongo/auth.rb +1 -1
  13. data/lib/mongo/auth/cr.rb +1 -1
  14. data/lib/mongo/auth/ldap.rb +1 -1
  15. data/lib/mongo/auth/roles.rb +1 -1
  16. data/lib/mongo/auth/user.rb +1 -1
  17. data/lib/mongo/auth/user/view.rb +5 -5
  18. data/lib/mongo/auth/x509.rb +1 -1
  19. data/lib/mongo/bson.rb +1 -1
  20. data/lib/mongo/bulk_write.rb +4 -4
  21. data/lib/mongo/bulk_write/combineable.rb +1 -1
  22. data/lib/mongo/bulk_write/ordered_combiner.rb +1 -1
  23. data/lib/mongo/bulk_write/result.rb +1 -1
  24. data/lib/mongo/bulk_write/result_combiner.rb +1 -1
  25. data/lib/mongo/bulk_write/transformable.rb +1 -1
  26. data/lib/mongo/bulk_write/unordered_combiner.rb +1 -1
  27. data/lib/mongo/bulk_write/validatable.rb +1 -1
  28. data/lib/mongo/client.rb +2 -2
  29. data/lib/mongo/cluster.rb +15 -3
  30. data/lib/mongo/cluster/cursor_reaper.rb +174 -0
  31. data/lib/mongo/cluster/topology.rb +1 -1
  32. data/lib/mongo/cluster/topology/replica_set.rb +1 -1
  33. data/lib/mongo/cluster/topology/sharded.rb +1 -1
  34. data/lib/mongo/cluster/topology/single.rb +1 -1
  35. data/lib/mongo/cluster/topology/unknown.rb +1 -1
  36. data/lib/mongo/collection.rb +5 -4
  37. data/lib/mongo/collection/view.rb +4 -4
  38. data/lib/mongo/collection/view/aggregation.rb +2 -2
  39. data/lib/mongo/collection/view/builder.rb +1 -1
  40. data/lib/mongo/collection/view/builder/aggregation.rb +1 -1
  41. data/lib/mongo/collection/view/builder/find_command.rb +1 -1
  42. data/lib/mongo/collection/view/builder/flags.rb +1 -1
  43. data/lib/mongo/collection/view/builder/map_reduce.rb +1 -1
  44. data/lib/mongo/collection/view/builder/modifiers.rb +1 -1
  45. data/lib/mongo/collection/view/builder/op_query.rb +1 -1
  46. data/lib/mongo/collection/view/explainable.rb +1 -1
  47. data/lib/mongo/collection/view/immutable.rb +1 -1
  48. data/lib/mongo/collection/view/iterable.rb +2 -2
  49. data/lib/mongo/collection/view/map_reduce.rb +3 -3
  50. data/lib/mongo/collection/view/readable.rb +23 -6
  51. data/lib/mongo/collection/view/writable.rb +3 -3
  52. data/lib/mongo/cursor.rb +50 -7
  53. data/lib/mongo/cursor/builder.rb +1 -1
  54. data/lib/mongo/cursor/builder/get_more_command.rb +1 -1
  55. data/lib/mongo/cursor/builder/kill_cursors_command.rb +29 -1
  56. data/lib/mongo/cursor/builder/op_get_more.rb +1 -1
  57. data/lib/mongo/cursor/builder/op_kill_cursors.rb +29 -1
  58. data/lib/mongo/database.rb +4 -4
  59. data/lib/mongo/database/view.rb +2 -2
  60. data/lib/mongo/dbref.rb +4 -3
  61. data/lib/mongo/error.rb +1 -1
  62. data/lib/mongo/error/bulk_write_error.rb +1 -1
  63. data/lib/mongo/error/closed_stream.rb +1 -1
  64. data/lib/mongo/error/extra_file_chunk.rb +1 -1
  65. data/lib/mongo/error/file_not_found.rb +1 -1
  66. data/lib/mongo/error/invalid_bulk_operation.rb +1 -1
  67. data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -1
  68. data/lib/mongo/error/invalid_collection_name.rb +1 -1
  69. data/lib/mongo/error/invalid_database_name.rb +1 -1
  70. data/lib/mongo/error/invalid_document.rb +1 -1
  71. data/lib/mongo/error/invalid_file.rb +1 -1
  72. data/lib/mongo/error/invalid_file_revision.rb +1 -1
  73. data/lib/mongo/error/invalid_nonce.rb +1 -1
  74. data/lib/mongo/error/invalid_replacement_document.rb +1 -1
  75. data/lib/mongo/error/invalid_server_preference.rb +1 -1
  76. data/lib/mongo/error/invalid_signature.rb +1 -1
  77. data/lib/mongo/error/invalid_update_document.rb +1 -1
  78. data/lib/mongo/error/invalid_uri.rb +1 -1
  79. data/lib/mongo/error/invalid_write_concern.rb +1 -1
  80. data/lib/mongo/error/max_bson_size.rb +1 -1
  81. data/lib/mongo/error/max_message_size.rb +1 -1
  82. data/lib/mongo/error/missing_file_chunk.rb +1 -1
  83. data/lib/mongo/error/multi_index_drop.rb +1 -1
  84. data/lib/mongo/error/need_primary_server.rb +1 -1
  85. data/lib/mongo/error/no_server_available.rb +4 -2
  86. data/lib/mongo/error/operation_failure.rb +1 -1
  87. data/lib/mongo/error/parser.rb +1 -1
  88. data/lib/mongo/error/socket_error.rb +1 -1
  89. data/lib/mongo/error/socket_timeout_error.rb +1 -1
  90. data/lib/mongo/error/unchangeable_collection_option.rb +1 -1
  91. data/lib/mongo/error/unexpected_chunk_length.rb +1 -1
  92. data/lib/mongo/error/unexpected_response.rb +1 -1
  93. data/lib/mongo/error/unsupported_features.rb +1 -1
  94. data/lib/mongo/event.rb +1 -1
  95. data/lib/mongo/event/description_changed.rb +1 -1
  96. data/lib/mongo/event/publisher.rb +1 -1
  97. data/lib/mongo/event/subscriber.rb +1 -1
  98. data/lib/mongo/grid.rb +1 -1
  99. data/lib/mongo/grid/file.rb +6 -2
  100. data/lib/mongo/grid/file/chunk.rb +6 -4
  101. data/lib/mongo/grid/file/info.rb +7 -3
  102. data/lib/mongo/grid/fs_bucket.rb +12 -6
  103. data/lib/mongo/grid/stream.rb +1 -1
  104. data/lib/mongo/grid/stream/read.rb +2 -4
  105. data/lib/mongo/grid/stream/write.rb +4 -3
  106. data/lib/mongo/index.rb +1 -1
  107. data/lib/mongo/index/view.rb +5 -4
  108. data/lib/mongo/loggable.rb +1 -1
  109. data/lib/mongo/logger.rb +1 -1
  110. data/lib/mongo/monitoring.rb +1 -1
  111. data/lib/mongo/operation.rb +1 -1
  112. data/lib/mongo/operation/commands.rb +1 -1
  113. data/lib/mongo/operation/commands/aggregate.rb +7 -7
  114. data/lib/mongo/operation/commands/aggregate/result.rb +1 -1
  115. data/lib/mongo/operation/commands/collections_info.rb +10 -9
  116. data/lib/mongo/operation/commands/collections_info/result.rb +1 -1
  117. data/lib/mongo/operation/commands/command.rb +1 -1
  118. data/lib/mongo/operation/commands/indexes.rb +12 -11
  119. data/lib/mongo/operation/commands/list_collections.rb +1 -1
  120. data/lib/mongo/operation/commands/list_collections/result.rb +1 -1
  121. data/lib/mongo/operation/commands/list_indexes.rb +1 -1
  122. data/lib/mongo/operation/commands/list_indexes/result.rb +1 -1
  123. data/lib/mongo/operation/commands/map_reduce.rb +1 -1
  124. data/lib/mongo/operation/commands/map_reduce/result.rb +1 -1
  125. data/lib/mongo/operation/commands/user_query.rb +11 -10
  126. data/lib/mongo/operation/commands/users_info.rb +2 -2
  127. data/lib/mongo/operation/commands/users_info/result.rb +1 -1
  128. data/lib/mongo/operation/executable.rb +8 -7
  129. data/lib/mongo/operation/kill_cursors.rb +2 -2
  130. data/lib/mongo/operation/limited.rb +1 -1
  131. data/lib/mongo/operation/read.rb +1 -1
  132. data/lib/mongo/operation/read/get_more.rb +2 -2
  133. data/lib/mongo/operation/read/query.rb +1 -1
  134. data/lib/mongo/operation/read/query/result.rb +1 -1
  135. data/lib/mongo/operation/read_preference.rb +10 -10
  136. data/lib/mongo/operation/result.rb +1 -1
  137. data/lib/mongo/operation/specifiable.rb +2 -2
  138. data/lib/mongo/operation/write.rb +1 -1
  139. data/lib/mongo/operation/write/bulk.rb +1 -1
  140. data/lib/mongo/operation/write/bulk/bulkable.rb +9 -9
  141. data/lib/mongo/operation/write/bulk/delete.rb +3 -3
  142. data/lib/mongo/operation/write/bulk/delete/result.rb +1 -1
  143. data/lib/mongo/operation/write/bulk/insert.rb +5 -5
  144. data/lib/mongo/operation/write/bulk/insert/result.rb +1 -1
  145. data/lib/mongo/operation/write/bulk/legacy_mergable.rb +1 -1
  146. data/lib/mongo/operation/write/bulk/mergable.rb +1 -1
  147. data/lib/mongo/operation/write/bulk/update.rb +3 -3
  148. data/lib/mongo/operation/write/bulk/update/result.rb +1 -1
  149. data/lib/mongo/operation/write/command.rb +1 -1
  150. data/lib/mongo/operation/write/command/create_index.rb +1 -1
  151. data/lib/mongo/operation/write/command/create_user.rb +1 -1
  152. data/lib/mongo/operation/write/command/delete.rb +1 -1
  153. data/lib/mongo/operation/write/command/drop_index.rb +1 -1
  154. data/lib/mongo/operation/write/command/insert.rb +11 -1
  155. data/lib/mongo/operation/write/command/remove_user.rb +1 -1
  156. data/lib/mongo/operation/write/command/update.rb +1 -1
  157. data/lib/mongo/operation/write/command/update_user.rb +1 -1
  158. data/lib/mongo/operation/write/command/writable.rb +7 -6
  159. data/lib/mongo/operation/write/create_index.rb +1 -1
  160. data/lib/mongo/operation/write/create_user.rb +1 -1
  161. data/lib/mongo/operation/write/delete.rb +1 -1
  162. data/lib/mongo/operation/write/delete/result.rb +1 -1
  163. data/lib/mongo/operation/write/drop_index.rb +5 -5
  164. data/lib/mongo/operation/write/gle.rb +3 -3
  165. data/lib/mongo/operation/write/idable.rb +1 -1
  166. data/lib/mongo/operation/write/insert.rb +5 -5
  167. data/lib/mongo/operation/write/insert/result.rb +1 -1
  168. data/lib/mongo/operation/write/remove_user.rb +1 -1
  169. data/lib/mongo/operation/write/update.rb +1 -1
  170. data/lib/mongo/operation/write/update/result.rb +1 -1
  171. data/lib/mongo/operation/write/update_user.rb +1 -1
  172. data/lib/mongo/operation/write/write_command_enabled.rb +10 -9
  173. data/lib/mongo/protocol/bit_vector.rb +2 -2
  174. data/lib/mongo/protocol/delete.rb +1 -1
  175. data/lib/mongo/protocol/get_more.rb +1 -1
  176. data/lib/mongo/protocol/insert.rb +5 -1
  177. data/lib/mongo/protocol/kill_cursors.rb +1 -1
  178. data/lib/mongo/protocol/message.rb +9 -5
  179. data/lib/mongo/protocol/query.rb +1 -1
  180. data/lib/mongo/protocol/reply.rb +1 -1
  181. data/lib/mongo/protocol/serializers.rb +8 -8
  182. data/lib/mongo/protocol/update.rb +1 -1
  183. data/lib/mongo/server.rb +40 -3
  184. data/lib/mongo/server/connectable.rb +1 -1
  185. data/lib/mongo/server/connection.rb +4 -2
  186. data/lib/mongo/server/connection_pool.rb +1 -1
  187. data/lib/mongo/server/connection_pool/queue.rb +1 -1
  188. data/lib/mongo/server/context.rb +3 -1
  189. data/lib/mongo/server/description.rb +1 -1
  190. data/lib/mongo/server/description/inspector/description_changed.rb +1 -1
  191. data/lib/mongo/server/monitor.rb +1 -1
  192. data/lib/mongo/server_selector.rb +2 -1
  193. data/lib/mongo/server_selector/nearest.rb +1 -1
  194. data/lib/mongo/server_selector/primary.rb +1 -1
  195. data/lib/mongo/server_selector/primary_preferred.rb +1 -1
  196. data/lib/mongo/server_selector/secondary.rb +1 -1
  197. data/lib/mongo/server_selector/secondary_preferred.rb +1 -1
  198. data/lib/mongo/server_selector/selectable.rb +12 -7
  199. data/lib/mongo/socket.rb +1 -1
  200. data/lib/mongo/socket/ssl.rb +1 -1
  201. data/lib/mongo/socket/tcp.rb +1 -1
  202. data/lib/mongo/socket/unix.rb +1 -1
  203. data/lib/mongo/uri.rb +1 -1
  204. data/lib/mongo/version.rb +2 -2
  205. data/lib/mongo/write_concern/acknowledged.rb +1 -1
  206. data/lib/mongo/write_concern/normalizable.rb +1 -1
  207. data/lib/mongo/write_concern/unacknowledged.rb +1 -1
  208. data/mongo.gemspec +1 -1
  209. data/spec/mongo/client_spec.rb +2 -2
  210. data/spec/mongo/cluster/cursor_reaper_spec.rb +216 -0
  211. data/spec/mongo/cluster_spec.rb +36 -5
  212. data/spec/mongo/collection/view/aggregation_spec.rb +2 -2
  213. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
  214. data/spec/mongo/collection/view/readable_spec.rb +203 -5
  215. data/spec/mongo/collection/view_spec.rb +10 -0
  216. data/spec/mongo/collection_spec.rb +64 -18
  217. data/spec/mongo/cursor_spec.rb +89 -0
  218. data/spec/mongo/database_spec.rb +79 -13
  219. data/spec/mongo/grid/fs_bucket_spec.rb +119 -1
  220. data/spec/mongo/grid/stream/write_spec.rb +63 -12
  221. data/spec/mongo/index/view_spec.rb +19 -0
  222. data/spec/mongo/operation/commands/aggregate_spec.rb +10 -7
  223. data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
  224. data/spec/mongo/operation/commands/command_spec.rb +3 -3
  225. data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
  226. data/spec/mongo/operation/commands/map_reduce_spec.rb +2 -2
  227. data/spec/mongo/operation/kill_cursors_spec.rb +10 -19
  228. data/spec/mongo/operation/read/get_more_spec.rb +13 -25
  229. data/spec/mongo/operation/read/query_spec.rb +26 -30
  230. data/spec/mongo/operation/read_preference_spec.rb +11 -11
  231. data/spec/mongo/operation/specifiable_spec.rb +31 -0
  232. data/spec/mongo/operation/write/bulk/delete_spec.rb +16 -18
  233. data/spec/mongo/operation/write/bulk/insert_spec.rb +17 -18
  234. data/spec/mongo/operation/write/bulk/update_spec.rb +20 -25
  235. data/spec/mongo/operation/write/command/delete_spec.rb +26 -32
  236. data/spec/mongo/operation/write/command/insert_spec.rb +24 -31
  237. data/spec/mongo/operation/write/command/update_spec.rb +24 -32
  238. data/spec/mongo/operation/write/create_index_spec.rb +4 -4
  239. data/spec/mongo/operation/write/create_user_spec.rb +3 -3
  240. data/spec/mongo/operation/write/delete_spec.rb +51 -22
  241. data/spec/mongo/operation/write/drop_index_spec.rb +2 -2
  242. data/spec/mongo/operation/write/insert_spec.rb +42 -11
  243. data/spec/mongo/operation/write/remove_user_spec.rb +4 -4
  244. data/spec/mongo/operation/write/update_spec.rb +34 -6
  245. data/spec/mongo/operation/write/update_user_spec.rb +1 -1
  246. data/spec/mongo/server/connection_spec.rb +22 -14
  247. data/spec/mongo/server_selection_spec.rb +2 -2
  248. data/spec/mongo/server_selector/nearest_spec.rb +4 -4
  249. data/spec/mongo/server_selector/primary_preferred_spec.rb +4 -4
  250. data/spec/mongo/server_selector/primary_spec.rb +2 -2
  251. data/spec/mongo/server_selector/secondary_preferred_spec.rb +4 -4
  252. data/spec/mongo/server_selector/secondary_spec.rb +3 -3
  253. data/spec/mongo/server_selector_spec.rb +82 -3
  254. data/spec/mongo/server_spec.rb +0 -20
  255. data/spec/support/command_monitoring.rb +1 -1
  256. data/spec/support/connection_string.rb +1 -1
  257. data/spec/support/crud.rb +1 -1
  258. data/spec/support/crud/read.rb +1 -1
  259. data/spec/support/crud/write.rb +1 -1
  260. data/spec/support/gridfs.rb +1 -1
  261. data/spec/support/shared/server_selector.rb +3 -3
  262. metadata +7 -10
  263. metadata.gz.sig +0 -0
  264. data/lib/csasl/csasl.bundle +0 -0
  265. data/spec/mongo/operation/write/response_spec.rb +0 -85
  266. data/spec/support/shared/operation.rb +0 -100
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82e2963414b68a630d0784e70921c1d44775934e
4
- data.tar.gz: db5398568a322af951e6b7ce3dfe7a22ddb8eb42
3
+ metadata.gz: 5da2e7df100dcc00d786b3839cce847de888bb3d
4
+ data.tar.gz: 858a508aa78ac85c6fc5a7506bdd660cdc384a9f
5
5
  SHA512:
6
- metadata.gz: 108c89ec2a1e2849fc76a9d71b50307fd3fa6eca10389572a675d5065a700c0a48308e594f48cde6bb901f748387e0dae845ebd281afc6d96970024563cfb7a5
7
- data.tar.gz: 47be1ace716e50c8020cc53599a9fd82e7c9f88ace2dfdd5d157a086f65002ae51d524a424e483795c9db6e7465a4ab04b79089315f140844f44d86f74a610e7
6
+ metadata.gz: 7a017939e8bfdc94ea78635128b71c5b837f725243777cf32f3d46b380cffc9b7c3e40b9558257af917b2eabf58e145dc8af7d36443b3342e55e08e16ff845b3
7
+ data.tar.gz: e22e1fbfe7908b55d0289f027483d56891f57757c5f29ff23bfaae1dd7140dfe3856b9e936d27402910fb7874d37576878c6d48e4de74765bac37c28251f9342
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-2015 MongoDB, Inc.
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-2015 MongoDB, Inc.
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
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
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.context)
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.context)
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.context)
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.context)
118
+ ).execute(next_primary)
119
119
  end
120
120
 
121
121
  def generate(user, options)
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 MongoDB, Inc.
1
+ # Copyright (C) 2015-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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
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.context)
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.context)
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.context)
187
+ ).execute(server)
188
188
  end
189
189
 
190
190
  alias :replace_one :update
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 MongoDB, Inc.
1
+ # Copyright (C) 2015-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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 MongoDB, Inc.
1
+ # Copyright (C) 2015-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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 MongoDB, Inc.
1
+ # Copyright (C) 2015-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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 MongoDB, Inc.
1
+ # Copyright (C) 2015-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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 MongoDB, Inc.
1
+ # Copyright (C) 2015-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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 MongoDB, Inc.
1
+ # Copyright (C) 2015-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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 MongoDB, Inc.
1
+ # Copyright (C) 2015-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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
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(Options::Redacted.new(options[:read] || {}).merge(options))
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
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
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.merge(options)).select_server(self, ping)
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! } and true
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