mongo 2.15.0 → 2.16.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (328) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +1 -1
  3. data/README.md +1 -1
  4. data/lib/mongo/bulk_write.rb +2 -2
  5. data/lib/mongo/client.rb +45 -5
  6. data/lib/mongo/cluster/periodic_executor.rb +4 -3
  7. data/lib/mongo/cluster/reapers/cursor_reaper.rb +76 -43
  8. data/lib/mongo/cluster/sdam_flow.rb +9 -3
  9. data/lib/mongo/cluster/topology/base.rb +13 -9
  10. data/lib/mongo/cluster/topology/load_balanced.rb +102 -0
  11. data/lib/mongo/cluster/topology.rb +28 -8
  12. data/lib/mongo/cluster.rb +136 -51
  13. data/lib/mongo/collection/view/aggregation.rb +5 -10
  14. data/lib/mongo/collection/view/builder/aggregation.rb +6 -5
  15. data/lib/mongo/collection/view/builder/map_reduce.rb +12 -49
  16. data/lib/mongo/collection/view/builder.rb +0 -4
  17. data/lib/mongo/collection/view/iterable.rb +58 -24
  18. data/lib/mongo/collection/view/map_reduce.rb +39 -15
  19. data/lib/mongo/collection/view/readable.rb +60 -51
  20. data/lib/mongo/collection/view/writable.rb +178 -175
  21. data/lib/mongo/collection/view.rb +15 -21
  22. data/lib/mongo/collection.rb +13 -13
  23. data/lib/mongo/cursor/kill_spec.rb +38 -0
  24. data/lib/mongo/cursor.rb +72 -31
  25. data/lib/mongo/database/view.rb +1 -1
  26. data/lib/mongo/error/bad_load_balancer_target.rb +26 -0
  27. data/lib/mongo/error/missing_service_id.rb +26 -0
  28. data/lib/mongo/error/no_service_connection_available.rb +49 -0
  29. data/lib/mongo/error/notable.rb +7 -0
  30. data/lib/mongo/error.rb +3 -0
  31. data/lib/mongo/grid/fs_bucket.rb +21 -2
  32. data/lib/mongo/id.rb +7 -5
  33. data/lib/mongo/index/view.rb +22 -41
  34. data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +7 -4
  35. data/lib/mongo/monitoring/event/command_failed.rb +1 -1
  36. data/lib/mongo/monitoring/event/command_started.rb +2 -0
  37. data/lib/mongo/monitoring/publishable.rb +2 -2
  38. data/lib/mongo/operation/aggregate/command.rb +8 -0
  39. data/lib/mongo/operation/context.rb +19 -1
  40. data/lib/mongo/operation/count/command.rb +6 -0
  41. data/lib/mongo/operation/count/op_msg.rb +6 -0
  42. data/lib/mongo/operation/create/command.rb +7 -1
  43. data/lib/mongo/operation/create/op_msg.rb +7 -0
  44. data/lib/mongo/operation/create_index/command.rb +17 -1
  45. data/lib/mongo/operation/create_index/op_msg.rb +17 -4
  46. data/lib/mongo/operation/delete/command.rb +6 -3
  47. data/lib/mongo/operation/delete/legacy.rb +9 -2
  48. data/lib/mongo/operation/delete/op_msg.rb +8 -1
  49. data/lib/mongo/operation/distinct/command.rb +6 -0
  50. data/lib/mongo/operation/distinct/op_msg.rb +7 -0
  51. data/lib/mongo/operation/explain/command.rb +13 -1
  52. data/lib/mongo/operation/explain/legacy.rb +12 -5
  53. data/lib/mongo/operation/explain/op_msg.rb +9 -1
  54. data/lib/mongo/operation/find/builder/command.rb +110 -0
  55. data/lib/mongo/{collection/view → operation/find}/builder/flags.rb +10 -14
  56. data/lib/mongo/operation/find/builder/legacy.rb +123 -0
  57. data/lib/mongo/{collection/view → operation/find}/builder/modifiers.rb +31 -25
  58. data/lib/mongo/{cursor → operation/find}/builder.rb +4 -4
  59. data/lib/mongo/operation/find/command.rb +9 -0
  60. data/lib/mongo/operation/find/legacy.rb +10 -1
  61. data/lib/mongo/operation/find/op_msg.rb +12 -0
  62. data/lib/mongo/operation/find.rb +1 -0
  63. data/lib/mongo/operation/get_more/command.rb +1 -0
  64. data/lib/mongo/operation/get_more/command_builder.rb +38 -0
  65. data/lib/mongo/operation/get_more/op_msg.rb +1 -0
  66. data/lib/mongo/operation/get_more.rb +1 -0
  67. data/lib/mongo/operation/kill_cursors/command.rb +8 -0
  68. data/lib/mongo/operation/kill_cursors/command_builder.rb +35 -0
  69. data/lib/mongo/operation/kill_cursors/legacy.rb +2 -1
  70. data/lib/mongo/operation/kill_cursors/op_msg.rb +10 -0
  71. data/lib/mongo/operation/kill_cursors.rb +1 -0
  72. data/lib/mongo/operation/map_reduce/command.rb +8 -0
  73. data/lib/mongo/operation/map_reduce/op_msg.rb +1 -1
  74. data/lib/mongo/operation/shared/executable.rb +15 -1
  75. data/lib/mongo/operation/shared/polymorphic_operation.rb +1 -1
  76. data/lib/mongo/operation/shared/read_preference_supported.rb +3 -1
  77. data/lib/mongo/operation/shared/response_handling.rb +1 -0
  78. data/lib/mongo/operation/shared/sessions_supported.rb +12 -12
  79. data/lib/mongo/operation/shared/specifiable.rb +11 -29
  80. data/lib/mongo/operation/shared/validatable.rb +87 -0
  81. data/lib/mongo/operation/shared/write.rb +1 -1
  82. data/lib/mongo/operation/update/command.rb +6 -3
  83. data/lib/mongo/operation/update/legacy.rb +19 -11
  84. data/lib/mongo/operation/update/op_msg.rb +7 -4
  85. data/lib/mongo/operation/write_command/command.rb +51 -0
  86. data/lib/mongo/operation/write_command/op_msg.rb +43 -0
  87. data/lib/mongo/operation/write_command.rb +32 -0
  88. data/lib/mongo/operation.rb +10 -0
  89. data/lib/mongo/protocol/query.rb +35 -18
  90. data/lib/mongo/server/connection.rb +25 -3
  91. data/lib/mongo/server/connection_base.rb +12 -1
  92. data/lib/mongo/server/connection_common.rb +38 -1
  93. data/lib/mongo/server/connection_pool/generation_manager.rb +71 -0
  94. data/lib/mongo/server/connection_pool.rb +100 -27
  95. data/lib/mongo/server/description/features.rb +17 -16
  96. data/lib/mongo/server/description/load_balancer.rb +33 -0
  97. data/lib/mongo/server/description.rb +85 -6
  98. data/lib/mongo/server/monitor/connection.rb +5 -6
  99. data/lib/mongo/server/monitor.rb +2 -1
  100. data/lib/mongo/server/pending_connection.rb +47 -31
  101. data/lib/mongo/server/push_monitor.rb +6 -0
  102. data/lib/mongo/server.rb +73 -26
  103. data/lib/mongo/server_selector/base.rb +5 -1
  104. data/lib/mongo/session/session_pool.rb +11 -0
  105. data/lib/mongo/session.rb +21 -1
  106. data/lib/mongo/socket/ocsp_verifier.rb +6 -37
  107. data/lib/mongo/uri/options_mapper.rb +1 -0
  108. data/lib/mongo/uri/srv_protocol.rb +6 -8
  109. data/lib/mongo/uri.rb +18 -0
  110. data/lib/mongo/utils.rb +0 -7
  111. data/lib/mongo/version.rb +1 -1
  112. data/mongo.gemspec +1 -1
  113. data/spec/integration/auth_spec.rb +31 -1
  114. data/spec/integration/awaited_ismaster_spec.rb +1 -1
  115. data/spec/integration/bulk_write_spec.rb +1 -1
  116. data/spec/integration/change_stream_spec.rb +3 -3
  117. data/spec/integration/client_construction_spec.rb +54 -0
  118. data/spec/integration/client_side_encryption/auto_encryption_bulk_writes_spec.rb +1 -1
  119. data/spec/integration/client_side_encryption/auto_encryption_command_monitoring_spec.rb +1 -1
  120. data/spec/integration/client_side_encryption/bson_size_limit_spec.rb +1 -1
  121. data/spec/integration/client_side_encryption/data_key_spec.rb +1 -1
  122. data/spec/integration/client_spec.rb +2 -0
  123. data/spec/integration/command_monitoring_spec.rb +1 -1
  124. data/spec/integration/command_spec.rb +1 -1
  125. data/spec/integration/connection_spec.rb +52 -35
  126. data/spec/integration/crud_spec.rb +174 -1
  127. data/spec/integration/cursor_pinning_spec.rb +121 -0
  128. data/spec/integration/cursor_reaping_spec.rb +8 -4
  129. data/spec/integration/fork_reconnect_spec.rb +1 -5
  130. data/spec/integration/get_more_spec.rb +1 -1
  131. data/spec/integration/heartbeat_events_spec.rb +1 -1
  132. data/spec/integration/map_reduce_spec.rb +77 -0
  133. data/spec/integration/query_cache_spec.rb +47 -2
  134. data/spec/integration/query_cache_transactions_spec.rb +1 -1
  135. data/spec/integration/read_concern_spec.rb +1 -1
  136. data/spec/integration/read_preference_spec.rb +1 -1
  137. data/spec/integration/reconnect_spec.rb +30 -12
  138. data/spec/integration/retryable_errors_spec.rb +1 -1
  139. data/spec/integration/retryable_writes/retryable_writes_36_and_older_spec.rb +1 -1
  140. data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -1
  141. data/spec/integration/sdam_error_handling_spec.rb +5 -3
  142. data/spec/integration/sdam_events_spec.rb +35 -19
  143. data/spec/integration/sdam_prose_spec.rb +1 -1
  144. data/spec/integration/server_monitor_spec.rb +1 -0
  145. data/spec/integration/server_selector_spec.rb +22 -5
  146. data/spec/integration/server_spec.rb +2 -0
  147. data/spec/integration/srv_monitoring_spec.rb +1 -1
  148. data/spec/integration/step_down_spec.rb +1 -1
  149. data/spec/integration/transaction_pinning_spec.rb +120 -0
  150. data/spec/integration/versioned_api_examples_spec.rb +45 -0
  151. data/spec/integration/x509_auth_spec.rb +1 -1
  152. data/spec/lite_spec_helper.rb +1 -2
  153. data/spec/mongo/address/unix_spec.rb +1 -0
  154. data/spec/mongo/auth/cr_spec.rb +2 -3
  155. data/spec/mongo/auth/ldap_spec.rb +2 -3
  156. data/spec/mongo/auth/scram_spec.rb +2 -3
  157. data/spec/mongo/auth/user/view_spec.rb +1 -1
  158. data/spec/mongo/auth/x509_spec.rb +2 -3
  159. data/spec/mongo/bulk_write_spec.rb +3 -3
  160. data/spec/mongo/client_construction_spec.rb +259 -28
  161. data/spec/mongo/client_spec.rb +6 -4
  162. data/spec/mongo/cluster/cursor_reaper_spec.rb +36 -21
  163. data/spec/mongo/cluster/periodic_executor_spec.rb +3 -1
  164. data/spec/mongo/cluster_spec.rb +44 -3
  165. data/spec/mongo/collection/view/aggregation_spec.rb +1 -1
  166. data/spec/mongo/collection/view/builder/find_command_spec.rb +4 -0
  167. data/spec/mongo/collection/view/builder/op_query_spec.rb +4 -0
  168. data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
  169. data/spec/mongo/collection_crud_spec.rb +7 -2
  170. data/spec/mongo/collection_ddl_spec.rb +1 -1
  171. data/spec/mongo/collection_spec.rb +1 -1
  172. data/spec/mongo/cursor/builder/get_more_command_spec.rb +4 -0
  173. data/spec/mongo/cursor/builder/op_get_more_spec.rb +4 -0
  174. data/spec/mongo/cursor_spec.rb +15 -5
  175. data/spec/mongo/database_spec.rb +15 -15
  176. data/spec/mongo/error/operation_failure_heavy_spec.rb +1 -1
  177. data/spec/mongo/grid/fs_bucket_spec.rb +18 -12
  178. data/spec/mongo/grid/stream/write_spec.rb +3 -9
  179. data/spec/mongo/grid/stream_spec.rb +1 -1
  180. data/spec/mongo/index/view_spec.rb +2 -2
  181. data/spec/mongo/operation/delete/op_msg_spec.rb +1 -1
  182. data/spec/mongo/{collection/view → operation/find}/builder/flags_spec.rb +2 -2
  183. data/spec/mongo/{collection/view → operation/find}/builder/modifiers_spec.rb +2 -2
  184. data/spec/mongo/operation/find/legacy_spec.rb +1 -0
  185. data/spec/mongo/operation/insert/bulk_spec.rb +1 -1
  186. data/spec/mongo/operation/insert/op_msg_spec.rb +1 -1
  187. data/spec/mongo/operation/kill_cursors_spec.rb +4 -1
  188. data/spec/mongo/operation/read_preference_legacy_spec.rb +4 -0
  189. data/spec/mongo/operation/read_preference_op_msg_spec.rb +2 -0
  190. data/spec/mongo/operation/update/bulk_spec.rb +1 -1
  191. data/spec/mongo/operation/update/op_msg_spec.rb +1 -1
  192. data/spec/mongo/query_cache_spec.rb +6 -2
  193. data/spec/mongo/server/connection_common_spec.rb +62 -11
  194. data/spec/mongo/server/connection_pool_spec.rb +73 -7
  195. data/spec/mongo/server/connection_spec.rb +138 -43
  196. data/spec/mongo/server/description_spec.rb +1 -1
  197. data/spec/mongo/server/monitor_spec.rb +4 -3
  198. data/spec/mongo/session/session_pool_spec.rb +42 -10
  199. data/spec/mongo/session_transaction_spec.rb +15 -30
  200. data/spec/mongo/socket/unix_spec.rb +1 -0
  201. data/spec/mongo/uri_option_parsing_spec.rb +38 -5
  202. data/spec/runners/change_streams/test.rb +1 -1
  203. data/spec/runners/cmap.rb +1 -1
  204. data/spec/runners/connection_string.rb +7 -3
  205. data/spec/runners/crud/operation.rb +5 -3
  206. data/spec/runners/crud/requirement.rb +1 -0
  207. data/spec/runners/crud.rb +1 -1
  208. data/spec/runners/sdam.rb +2 -1
  209. data/spec/runners/transactions/test.rb +2 -2
  210. data/spec/runners/unified/assertions.rb +2 -3
  211. data/spec/runners/unified/event_subscriber.rb +2 -2
  212. data/spec/runners/unified/test.rb +3 -0
  213. data/spec/runners/unified.rb +1 -1
  214. data/spec/shared/lib/mrss/constraints.rb +11 -5
  215. data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
  216. data/spec/shared/lib/mrss/server_version_registry.rb +17 -12
  217. data/spec/shared/share/Dockerfile.erb +2 -1
  218. data/spec/shared/shlib/server.sh +70 -20
  219. data/spec/spec_tests/change_streams_spec.rb +1 -1
  220. data/spec/spec_tests/cmap_spec.rb +4 -1
  221. data/spec/spec_tests/command_monitoring_spec.rb +2 -2
  222. data/spec/spec_tests/data/command_monitoring/find.yml +9 -9
  223. data/spec/spec_tests/data/crud/read/aggregate-collation.yml +2 -1
  224. data/spec/spec_tests/data/crud/read/aggregate-out.yml +1 -0
  225. data/spec/spec_tests/data/crud/read/count-collation.yml +2 -1
  226. data/spec/spec_tests/data/crud/read/distinct-collation.yml +2 -1
  227. data/spec/spec_tests/data/crud/read/find-collation.yml +2 -1
  228. data/spec/spec_tests/data/crud/write/bulkWrite-collation.yml +2 -1
  229. data/spec/spec_tests/data/crud/write/deleteMany-collation.yml +2 -1
  230. data/spec/spec_tests/data/crud/write/deleteOne-collation.yml +2 -1
  231. data/spec/spec_tests/data/crud/write/findOneAndDelete-collation.yml +3 -2
  232. data/spec/spec_tests/data/crud/write/findOneAndReplace-collation.yml +2 -1
  233. data/spec/spec_tests/data/crud/write/findOneAndUpdate-collation.yml +3 -2
  234. data/spec/spec_tests/data/crud/write/replaceOne-collation.yml +3 -2
  235. data/spec/spec_tests/data/crud/write/updateMany-collation.yml +2 -1
  236. data/spec/spec_tests/data/crud/write/updateOne-collation.yml +2 -1
  237. data/spec/spec_tests/data/load_balancers/event-monitoring.yml +99 -0
  238. data/spec/spec_tests/data/load_balancers/lb-connection-establishment.yml +36 -0
  239. data/spec/spec_tests/data/load_balancers/non-lb-connection-establishment.yml +56 -0
  240. data/spec/spec_tests/data/load_balancers/server-selection.yml +50 -0
  241. data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch-serverErrors.yml +1 -1
  242. data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch.yml +1 -1
  243. data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch-serverErrors.yml +1 -1
  244. data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch.yml +1 -1
  245. data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch-serverErrors.yml +1 -1
  246. data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch.yml +1 -1
  247. data/spec/spec_tests/data/retryable_reads/mapReduce.yml +3 -1
  248. data/spec/spec_tests/data/sdam/load-balanced/discover_load_balancer.yml +25 -0
  249. data/spec/spec_tests/data/sdam_integration/find-network-error.yml +2 -0
  250. data/spec/spec_tests/data/sdam_integration/find-shutdown-error.yml +2 -0
  251. data/spec/spec_tests/data/sdam_integration/hello-command-error.yml +3 -1
  252. data/spec/spec_tests/data/sdam_integration/hello-network-error.yml +3 -1
  253. data/spec/spec_tests/data/sdam_integration/hello-timeout.yml +2 -0
  254. data/spec/spec_tests/data/sdam_integration/insert-network-error.yml +2 -0
  255. data/spec/spec_tests/data/sdam_integration/insert-shutdown-error.yml +2 -0
  256. data/spec/spec_tests/data/sdam_monitoring/load_balancer.yml +65 -0
  257. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-directConnection.yml +13 -0
  258. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-replicaSet-errors.yml +6 -0
  259. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-true-multiple-hosts.yml +5 -0
  260. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-true-txt.yml +10 -0
  261. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/direct-connection-false.yml +0 -0
  262. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/direct-connection-true.yml +0 -0
  263. data/spec/spec_tests/data/seed_list_discovery/replica-set/encoded-userinfo-and-db.yml +15 -0
  264. data/spec/spec_tests/data/seed_list_discovery/replica-set/loadBalanced-false-txt.yml +10 -0
  265. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/longer-parent-in-return.yml +0 -0
  266. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/misformatted-option.yml +0 -0
  267. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/no-results.yml +0 -0
  268. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/not-enough-parts.yml +0 -0
  269. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-result-default-port.yml +0 -0
  270. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-txt-record-multiple-strings.yml +0 -0
  271. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-txt-record.yml +0 -0
  272. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch1.yml +0 -0
  273. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch2.yml +0 -0
  274. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch3.yml +0 -0
  275. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch4.yml +0 -0
  276. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch5.yml +0 -0
  277. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/returned-parent-too-short.yml +0 -0
  278. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/returned-parent-wrong.yml +0 -0
  279. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-results-default-port.yml +0 -0
  280. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-results-nonstandard-port.yml +0 -0
  281. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-txt-records.yml +0 -0
  282. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-not-allowed-option.yml +0 -0
  283. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-overridden-ssl-option.yml +0 -0
  284. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-overridden-uri-option.yml +0 -0
  285. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-unallowed-option.yml +0 -0
  286. data/spec/spec_tests/data/seed_list_discovery/replica-set/uri-with-admin-database.yml +13 -0
  287. data/spec/spec_tests/data/seed_list_discovery/replica-set/uri-with-auth.yml +12 -0
  288. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/uri-with-port.yml +0 -0
  289. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/uri-with-two-hosts.yml +0 -0
  290. data/spec/spec_tests/data/transactions/retryable-abort-errorLabels.yml +2 -0
  291. data/spec/spec_tests/data/transactions/retryable-abort.yml +2 -0
  292. data/spec/spec_tests/data/transactions/retryable-commit-errorLabels.yml +2 -0
  293. data/spec/spec_tests/data/transactions/retryable-commit.yml +2 -0
  294. data/spec/spec_tests/data/transactions/retryable-writes.yml +2 -0
  295. data/spec/spec_tests/data/uri_options/connection-options.yml +60 -0
  296. data/spec/spec_tests/load_balancers_spec.rb +15 -0
  297. data/spec/spec_tests/retryable_reads_spec.rb +2 -2
  298. data/spec/spec_tests/retryable_writes_spec.rb +1 -1
  299. data/spec/spec_tests/sdam_integration_spec.rb +1 -1
  300. data/spec/spec_tests/sdam_monitoring_spec.rb +10 -5
  301. data/spec/spec_tests/sdam_spec.rb +1 -1
  302. data/spec/spec_tests/seed_list_discovery_spec.rb +118 -0
  303. data/spec/spec_tests/uri_options_spec.rb +4 -4
  304. data/spec/stress/fork_reconnect_stress_spec.rb +1 -5
  305. data/spec/stress/push_monitor_close_spec.rb +44 -0
  306. data/spec/support/certificates/atlas-ocsp-ca.crt +82 -90
  307. data/spec/support/certificates/atlas-ocsp.crt +127 -122
  308. data/spec/support/common_shortcuts.rb +2 -3
  309. data/spec/support/matchers.rb +13 -0
  310. data/spec/support/shared/auth_context.rb +16 -0
  311. data/spec/support/shared/session.rb +2 -2
  312. data/spec/support/spec_config.rb +9 -10
  313. data/spec/support/using_hash.rb +31 -0
  314. data/spec/support/utils.rb +1 -1
  315. data.tar.gz.sig +2 -4
  316. metadata +1050 -1004
  317. metadata.gz.sig +0 -0
  318. data/lib/mongo/collection/view/builder/find_command.rb +0 -173
  319. data/lib/mongo/collection/view/builder/op_query.rb +0 -94
  320. data/lib/mongo/cursor/builder/get_more_command.rb +0 -80
  321. data/lib/mongo/cursor/builder/kill_cursors_command.rb +0 -111
  322. data/lib/mongo/cursor/builder/op_get_more.rb +0 -64
  323. data/lib/mongo/cursor/builder/op_kill_cursors.rb +0 -106
  324. data/lib/mongo/server/context.rb +0 -72
  325. data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +0 -66
  326. data/spec/runners/unified/using_hash.rb +0 -34
  327. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +0 -79
  328. data/spec/support/event_subscriber.rb +0 -221
@@ -173,6 +173,10 @@ module Mongo
173
173
  #
174
174
  # @since 2.0.0
175
175
  def select_server(cluster, ping = nil, session = nil)
176
+ if cluster.topology.is_a?(Cluster::Topology::LoadBalanced)
177
+ return cluster.servers.first
178
+ end
179
+
176
180
  server_selection_timeout = cluster.options[:server_selection_timeout] || SERVER_SELECTION_TIMEOUT
177
181
 
178
182
  # Special handling for zero timeout: if we have to select a server,
@@ -247,7 +251,7 @@ module Mongo
247
251
  end
248
252
 
249
253
  if session && session.starting_transaction? && cluster.sharded?
250
- session.pin(server)
254
+ session.pin_to_server(server)
251
255
  end
252
256
 
253
257
  return server
@@ -133,6 +133,13 @@ module Mongo
133
133
  private
134
134
 
135
135
  def about_to_expire?(session)
136
+ # Load balancers spec explicitly requires to ignore the logical session
137
+ # timeout value.
138
+ # No rationale is provided as of the time of this writing.
139
+ if @cluster.load_balanced?
140
+ return false
141
+ end
142
+
136
143
  logical_session_timeout = @cluster.logical_session_timeout
137
144
 
138
145
  if logical_session_timeout
@@ -142,6 +149,10 @@ module Mongo
142
149
  end
143
150
 
144
151
  def prune!
152
+ # Load balancers spec explicitly requires not to prune sessions.
153
+ # No rationale is provided as of the time of this writing.
154
+ return if @cluster.load_balanced?
155
+
145
156
  while !@queue.empty?
146
157
  if about_to_expire?(@queue[-1])
147
158
  @queue.pop
data/lib/mongo/session.rb CHANGED
@@ -208,6 +208,12 @@ module Mongo
208
208
  # @api private
209
209
  attr_reader :pinned_server
210
210
 
211
+ # @return [ Object | nil ] The service id that this session is pinned to,
212
+ # if any.
213
+ #
214
+ # @api private
215
+ attr_reader :pinned_service_id
216
+
211
217
  # @return [ BSON::Document | nil ] Recovery token for the sharded
212
218
  # transaction being executed on this session, if any.
213
219
  #
@@ -430,6 +436,7 @@ module Mongo
430
436
  transaction_in_progress = false
431
437
  raise
432
438
  end
439
+ @state = NO_TRANSACTION_STATE
433
440
  next
434
441
  else
435
442
  transaction_in_progress = false
@@ -695,7 +702,7 @@ module Mongo
695
702
  # @param [ Server ] server The server to pin this session to.
696
703
  #
697
704
  # @api private
698
- def pin(server)
705
+ def pin_to_server(server)
699
706
  if server.nil?
700
707
  raise ArgumentError, 'Cannot pin to a nil server'
701
708
  end
@@ -707,11 +714,24 @@ module Mongo
707
714
  @pinned_server = server
708
715
  end
709
716
 
717
+ # Pins this session to the specified service.
718
+ #
719
+ # @param [ Object ] service_id The service id to pin this session to.
720
+ #
721
+ # @api private
722
+ def pin_to_service(service_id)
723
+ if service_id.nil?
724
+ raise ArgumentError, 'Cannot pin to a nil service id'
725
+ end
726
+ @pinned_service_id = service_id
727
+ end
728
+
710
729
  # Unpins this session from the pinned server, if the session was pinned.
711
730
  #
712
731
  # @api private
713
732
  def unpin
714
733
  @pinned_server = nil
734
+ @pinned_service_id = nil
715
735
  end
716
736
 
717
737
  # Unpins this session from the pinned server, if the session was pinned
@@ -237,43 +237,12 @@ module Mongo
237
237
  return false
238
238
  end
239
239
 
240
- if resp.respond_to?(:find_response)
241
- # Ruby 2.4+
242
- resp = resp.find_response(cert_id)
243
- # TODO make a new class instead of patching the stdlib one?
244
- resp.instance_variable_set('@uri', uri)
245
- resp.instance_variable_set('@original_uri', original_uri)
246
- class << resp
247
- attr_reader :uri, :original_uri
248
- end
249
- else
250
- # Ruby 2.3
251
- found = nil
252
- resp.status.each do |_cert_id, cert_status, revocation_reason, revocation_time, this_update, next_update, extensions|
253
- if _cert_id.cmp(cert_id)
254
- found = OpenStruct.new(
255
- cert_status: cert_status,
256
- certid: _cert_id,
257
- next_update: next_update,
258
- this_update: this_update,
259
- revocation_reason: revocation_reason,
260
- revocation_time: revocation_time,
261
- extensions: extensions,
262
- uri: uri,
263
- original_uri: original_uri,
264
- )
265
- class << found
266
- # Unlike the stdlib method, this one doesn't accept
267
- # any arguments.
268
- def check_validity
269
- now = Time.now
270
- this_update <= now && next_update >= now
271
- end
272
- end
273
- break
274
- end
275
- end
276
- resp = found
240
+ resp = resp.find_response(cert_id)
241
+ # TODO make a new class instead of patching the stdlib one?
242
+ resp.instance_variable_set('@uri', uri)
243
+ resp.instance_variable_set('@original_uri', original_uri)
244
+ class << resp
245
+ attr_reader :uri, :original_uri
277
246
  end
278
247
 
279
248
  unless resp
@@ -268,6 +268,7 @@ module Mongo
268
268
  # Topology options
269
269
  uri_option 'directConnection', :direct_connection, type: :bool
270
270
  uri_option 'connect', :connect, type: :symbol
271
+ uri_option 'loadBalanced', :load_balanced, type: :bool
271
272
 
272
273
  # Auth Options
273
274
  uri_option 'authSource', :auth_source
@@ -80,7 +80,7 @@ module Mongo
80
80
  DOT_PARTITION = '.'.freeze
81
81
 
82
82
  # @return [ Array<String> ] VALID_TXT_OPTIONS The valid options for a TXT record to specify.
83
- VALID_TXT_OPTIONS = ['replicaset', 'authsource'].freeze
83
+ VALID_TXT_OPTIONS = %w(replicaset authsource loadbalanced).freeze
84
84
 
85
85
  # @return [ String ] INVALID_HOST Error message format string indicating that the hostname in
86
86
  # in the URI does not fit the expected form.
@@ -102,11 +102,6 @@ module Mongo
102
102
  # were found.
103
103
  NO_SRV_RECORDS = "The DNS query returned no SRV records for '%s'".freeze
104
104
 
105
- # @return [ String ] INVALID_TXT_RECORD_OPTION Error message format string indicating that an
106
- # unexpected TXT record option was found.
107
- INVALID_TXT_RECORD_OPTION = "TXT records can only specify the options " +
108
- "[#{VALID_TXT_OPTIONS.join(', ')}].".freeze
109
-
110
105
  # @return [ String ] FORMAT The expected SRV URI format.
111
106
  FORMAT = 'mongodb+srv://[username:password@]host[/[database][?options]]'.freeze
112
107
 
@@ -222,8 +217,11 @@ module Mongo
222
217
  def parse_txt_options!(string)
223
218
  string.split(INDIV_URI_OPTS_DELIM).reduce({}) do |txt_options, opt|
224
219
  raise Error::InvalidTXTRecord.new(INVALID_OPTS_VALUE_DELIM) unless opt.index(URI_OPTS_VALUE_DELIM)
225
- key, value = opt.split(URI_OPTS_VALUE_DELIM)
226
- raise Error::InvalidTXTRecord.new(INVALID_TXT_RECORD_OPTION) unless VALID_TXT_OPTIONS.include?(key.downcase)
220
+ key, value = opt.split('=')
221
+ unless VALID_TXT_OPTIONS.include?(key.downcase)
222
+ msg = "TXT records can only specify the options [#{VALID_TXT_OPTIONS.join(', ')}]: #{string}"
223
+ raise Error::InvalidTXTRecord.new(msg)
224
+ end
227
225
  options_mapper.add_uri_option(key, value, txt_options)
228
226
  txt_options
229
227
  end
data/lib/mongo/uri.rb CHANGED
@@ -520,6 +520,24 @@ module Mongo
520
520
  elsif uri_options[:direct_connection] == false && uri_options[:connect].to_s == 'direct'
521
521
  raise_invalid_error_no_fmt!("directConnection=false cannot be used with connect=direct")
522
522
  end
523
+
524
+ if uri_options[:load_balanced]
525
+ if servers.length > 1
526
+ raise_invalid_error_no_fmt!("loadBalanced=true cannot be used with multiple seeds")
527
+ end
528
+
529
+ if uri_options[:direct_connection]
530
+ raise_invalid_error_no_fmt!("directConnection=true cannot be used with loadBalanced=true")
531
+ end
532
+
533
+ if uri_options[:connect] && uri_options[:connect].to_sym == :direct
534
+ raise_invalid_error_no_fmt!("connect=direct cannot be used with loadBalanced=true")
535
+ end
536
+
537
+ if uri_options[:replica_set]
538
+ raise_invalid_error_no_fmt!("loadBalanced=true cannot be used with replicaSet option")
539
+ end
540
+ end
523
541
  end
524
542
  end
525
543
  end
data/lib/mongo/utils.rb CHANGED
@@ -102,13 +102,6 @@ module Mongo
102
102
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
103
103
  end
104
104
 
105
- # Hash#compact implementation for Ruby 2.3
106
- module_function def compact_hash(hash)
107
- Hash[hash.reject do |k, v|
108
- v.nil?
109
- end]
110
- end
111
-
112
105
  # Hash#compact implementation for Ruby 2.3/2.4
113
106
  # Implementation based on activesupport 5.2.3
114
107
  module_function def slice_hash(hash, *keys)
data/lib/mongo/version.rb CHANGED
@@ -20,5 +20,5 @@ module Mongo
20
20
  # The current version of the driver.
21
21
  #
22
22
  # @since 2.0.0
23
- VERSION = '2.15.0'.freeze
23
+ VERSION = '2.16.0.alpha1'.freeze
24
24
  end
data/mongo.gemspec CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
36
36
  s.require_paths = ['lib']
37
37
  s.bindir = 'bin'
38
38
 
39
- s.required_ruby_version = ">= 2.3"
39
+ s.required_ruby_version = ">= 2.4"
40
40
 
41
41
  s.add_dependency 'bson', '>=4.8.2', '<5.0.0'
42
42
  end
@@ -14,7 +14,7 @@ describe 'Auth' do
14
14
  end
15
15
 
16
16
  let(:base_options) do
17
- SpecConfig.instance.monitoring_options
17
+ SpecConfig.instance.monitoring_options.merge(connect: SpecConfig.instance.test_options[:connect])
18
18
  end
19
19
 
20
20
  let(:connection) do
@@ -276,4 +276,34 @@ describe 'Auth' do
276
276
  client.database.command(ping: 1)
277
277
  end
278
278
  end
279
+
280
+ context 'in lb topology' do
281
+ require_topology :load_balanced
282
+
283
+ context 'when authentication fails with network error' do
284
+ let(:server) do
285
+ authorized_client.cluster.next_primary
286
+ end
287
+
288
+ let(:base_options) do
289
+ SpecConfig.instance.monitoring_options.merge(connect: SpecConfig.instance.test_options[:connect])
290
+ end
291
+
292
+ let(:connection) do
293
+ Mongo::Server::Connection.new(server, base_options)
294
+ end
295
+
296
+ it 'includes service id in exception' do
297
+ expect_any_instance_of(Mongo::Server::PendingConnection).to receive(:authenticate!).and_raise(Mongo::Error::SocketError)
298
+
299
+ begin
300
+ connection.connect!
301
+ rescue Mongo::Error::SocketError => exc
302
+ exc.service_id.should_not be nil
303
+ else
304
+ fail 'Expected the SocketError to be raised'
305
+ end
306
+ end
307
+ end
308
+ end
279
309
  end
@@ -9,7 +9,7 @@ describe 'awaited hello' do
9
9
  # If we send the consecutive hello commands to different mongoses,
10
10
  # they have different process ids, and so the awaited one would return
11
11
  # immediately.
12
- require_no_multi_shard
12
+ require_no_multi_mongos
13
13
 
14
14
  let(:client) { authorized_client }
15
15
 
@@ -21,7 +21,7 @@ describe 'Bulk writes' do
21
21
  end
22
22
 
23
23
  context 'when bulk write needs to be split' do
24
- let(:subscriber) { EventSubscriber.new }
24
+ let(:subscriber) { Mrss::EventSubscriber.new }
25
25
 
26
26
  let(:max_bson_size) { Mongo::Server::ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE }
27
27
 
@@ -53,7 +53,7 @@ describe 'Change stream integration', retry: 4 do
53
53
  it 'raises an exception and does not attempt to resume' do
54
54
  change_stream
55
55
 
56
- subscriber = EventSubscriber.new
56
+ subscriber = Mrss::EventSubscriber.new
57
57
  authorized_client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
58
58
 
59
59
  expect do
@@ -523,7 +523,7 @@ describe 'Change stream integration', retry: 4 do
523
523
  let(:events) do
524
524
  start_after
525
525
 
526
- subscriber = EventSubscriber.new
526
+ subscriber = Mrss::EventSubscriber.new
527
527
  authorized_client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
528
528
  use_stream
529
529
 
@@ -582,7 +582,7 @@ describe 'Change stream integration', retry: 4 do
582
582
  let(:stream) { authorized_collection.watch }
583
583
 
584
584
  let(:events) do
585
- subscriber = EventSubscriber.new
585
+ subscriber = Mrss::EventSubscriber.new
586
586
  authorized_client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
587
587
  use_stream
588
588
  subscriber.succeeded_events.select { |e|
@@ -236,4 +236,58 @@ describe 'Client construction' do
236
236
  expect(client.cluster.addresses).to eq([Mongo::Address.new(primary_address)])
237
237
  end
238
238
  end
239
+
240
+ context 'when deployment is not a sharded cluster' do
241
+ require_topology :single, :replica_set
242
+
243
+ let(:client) do
244
+ ClientRegistry.instance.new_local_client(
245
+ [SpecConfig.instance.addresses.first],
246
+ SpecConfig.instance.test_options.merge(options),
247
+ )
248
+ end
249
+
250
+ context 'when load-balanced topology is requested' do
251
+ let(:options) do
252
+ {connect: :load_balanced, replica_set: nil}
253
+ end
254
+
255
+ it 'creates the client successfully' do
256
+ client.should be_a(Mongo::Client)
257
+ end
258
+
259
+ it 'fails all operations' do
260
+ lambda do
261
+ client.command(ping: true)
262
+ end.should raise_error(Mongo::Error::BadLoadBalancerTarget)
263
+ end
264
+ end
265
+ end
266
+
267
+ context 'when in load-balanced mode' do
268
+ require_topology :load_balanced
269
+
270
+ let(:client) do
271
+ ClientRegistry.instance.new_local_client(
272
+ [SpecConfig.instance.addresses.first],
273
+ SpecConfig.instance.test_options.merge(options),
274
+ )
275
+ end
276
+
277
+ context 'when load-balanced topology is requested via the URI option' do
278
+ let(:options) do
279
+ {connect: nil, load_balanced: true}
280
+ end
281
+
282
+ it 'creates the client successfully' do
283
+ client.should be_a(Mongo::Client)
284
+ end
285
+
286
+ it 'fails all operations' do
287
+ lambda do
288
+ client.command(ping: true)
289
+ end.should raise_error(Mongo::Error::MissingServiceId)
290
+ end
291
+ end
292
+ end
239
293
  end
@@ -11,7 +11,7 @@ describe 'Bulk writes with auto-encryption enabled' do
11
11
  include_context 'define shared FLE helpers'
12
12
  include_context 'with local kms_providers'
13
13
 
14
- let(:subscriber) { EventSubscriber.new }
14
+ let(:subscriber) { Mrss::EventSubscriber.new }
15
15
 
16
16
  let(:client) do
17
17
  new_local_client(
@@ -15,7 +15,7 @@ describe 'Auto Encryption' do
15
15
  include_context 'define shared FLE helpers'
16
16
  include_context 'with local kms_providers'
17
17
 
18
- let(:subscriber) { EventSubscriber.new }
18
+ let(:subscriber) { Mrss::EventSubscriber.new }
19
19
  let(:db_name) { 'auto_encryption' }
20
20
 
21
21
  let(:encryption_client) do
@@ -11,7 +11,7 @@ describe 'Client-Side Encryption' do
11
11
 
12
12
  include_context 'define shared FLE helpers'
13
13
 
14
- let(:subscriber) { EventSubscriber.new }
14
+ let(:subscriber) { Mrss::EventSubscriber.new }
15
15
 
16
16
  let(:client) do
17
17
  authorized_client.use('db')
@@ -11,7 +11,7 @@ describe 'Client-Side Encryption' do
11
11
 
12
12
  include_context 'define shared FLE helpers'
13
13
 
14
- let(:subscriber) { EventSubscriber.new }
14
+ let(:subscriber) { Mrss::EventSubscriber.new }
15
15
 
16
16
  let(:client) do
17
17
  new_local_client(