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
@@ -63,6 +63,13 @@ module Mongo
63
63
  # @return [ Integer | nil ] Connection pool generation.
64
64
  attr_accessor :generation
65
65
 
66
+ # Returns service id for the connection on which the error occurred.
67
+ #
68
+ # @return [ Object | nil ] Service id.
69
+ #
70
+ # @api experimental
71
+ attr_accessor :service_id
72
+
66
73
  # @api public
67
74
  def to_s
68
75
  super + notes_tail
data/lib/mongo/error.rb CHANGED
@@ -168,6 +168,7 @@ module Mongo
168
168
  end
169
169
 
170
170
  require 'mongo/error/auth_error'
171
+ require 'mongo/error/bad_load_balancer_target'
171
172
  require 'mongo/error/sdam_error_detection'
172
173
  require 'mongo/error/parser'
173
174
  require 'mongo/error/write_retryable'
@@ -217,6 +218,7 @@ require 'mongo/error/mismatched_domain'
217
218
  require 'mongo/error/mongocryptd_spawn_error'
218
219
  require 'mongo/error/multi_index_drop'
219
220
  require 'mongo/error/need_primary_server'
221
+ require 'mongo/error/no_service_connection_available'
220
222
  require 'mongo/error/no_server_available'
221
223
  require 'mongo/error/no_srv_records'
222
224
  require 'mongo/error/session_ended'
@@ -235,6 +237,7 @@ require 'mongo/error/missing_file_chunk'
235
237
  require 'mongo/error/missing_password'
236
238
  require 'mongo/error/missing_resume_token'
237
239
  require 'mongo/error/missing_scram_server_signature'
240
+ require 'mongo/error/missing_service_id'
238
241
  require 'mongo/error/server_api_conflict'
239
242
  require 'mongo/error/server_api_not_supported'
240
243
  require 'mongo/error/unknown_payload_type'
@@ -508,8 +508,27 @@ module Mongo
508
508
 
509
509
  def ensure_indexes!
510
510
  if files_collection.find({}, limit: 1, projection: { _id: 1 }).first.nil?
511
- chunks_collection.indexes.create_one(FSBucket::CHUNKS_INDEX, :unique => true)
512
- files_collection.indexes.create_one(FSBucket::FILES_INDEX)
511
+ create_index_if_missing!(files_collection, FSBucket::FILES_INDEX)
512
+ end
513
+
514
+ if chunks_collection.find({}, limit: 1, projection: { _id: 1 }).first.nil?
515
+ create_index_if_missing!(chunks_collection, FSBucket::CHUNKS_INDEX, :unique => true)
516
+ end
517
+ end
518
+
519
+ def create_index_if_missing!(collection, index_spec, options = {})
520
+ indexes_view = collection.indexes
521
+ begin
522
+ if indexes_view.get(index_spec).nil?
523
+ indexes_view.create_one(index_spec, options)
524
+ end
525
+ rescue Mongo::Error::OperationFailure => e
526
+ # proceed with index creation if a NamespaceNotFound error is thrown
527
+ if e.code == 26
528
+ indexes_view.create_one(index_spec, options)
529
+ else
530
+ raise
531
+ end
513
532
  end
514
533
  end
515
534
  end
data/lib/mongo/id.rb CHANGED
@@ -16,9 +16,10 @@
16
16
  # limitations under the License.
17
17
 
18
18
  module Mongo
19
- # This module abstracts the functionality for generating sequential unique integer IDs for
20
- # instances of the class. It defines the method #next_id on the class that includes it. The
21
- # implementation ensures that the IDs will be unique even when called from multiple threads.
19
+ # This module abstracts the functionality for generating sequential
20
+ # unique integer IDs for instances of the class. It defines the method
21
+ # #next_id on the class that includes it. The implementation ensures that
22
+ # the IDs will be unique even when called from multiple threads.
22
23
  #
23
24
  # @example Include the Id module.
24
25
  # class Foo
@@ -29,8 +30,9 @@ module Mongo
29
30
  # foo.next_id # => 1
30
31
  # foo.next_id # => 2
31
32
  #
32
- # Classes which include Id should _not_ access `@@id` or `@@id_lock` directly; instead, they
33
- # should call `#next_id` in `#initialize` and save the result in the instance being created.
33
+ # Classes which include Id should _not_ access `@@id` or `@@id_lock`
34
+ # directly; instead, they should call `#next_id` in `#initialize` and save
35
+ # the result in the instance being created.
34
36
  #
35
37
  # @example Save the ID in the instance of the including class.
36
38
  # class Bar
@@ -129,7 +129,10 @@ module Mongo
129
129
  # @option options [ String | Integer ] :commit_quorum Specify how many
130
130
  # data-bearing members of a replica set, including the primary, must
131
131
  # complete the index builds successfully before the primary marks
132
- # the indexes as ready.
132
+ # the indexes as ready. Potential values are:
133
+ # - an integer from 0 to the number of members of the replica set
134
+ # - "majority" indicating that a majority of data bearing nodes must vote
135
+ # - "votingMembers" which means that all voting data bearing nodes must vote
133
136
  # @option options [ Session ] :session The session to use for the operation.
134
137
  #
135
138
  # @note Note that the options listed may be subset of those available.
@@ -177,7 +180,10 @@ module Mongo
177
180
  # The following options are accepted:
178
181
  # - commit_quorum: Specify how many data-bearing members of a replica set,
179
182
  # including the primary, must complete the index builds successfully
180
- # before the primary marks the indexes as ready.
183
+ # before the primary marks the indexes as ready. Potential values are:
184
+ # - an integer from 0 to the number of members of the replica set
185
+ # - "majority" indicating that a majority of data bearing nodes must vote
186
+ # - "votingMembers" which means that all voting data bearing nodes must vote
181
187
  # - session: The session to use.
182
188
  #
183
189
  # @return [ Result ] The result of the command.
@@ -193,17 +199,6 @@ module Mongo
193
199
  client.send(:with_session, @options.merge(options)) do |session|
194
200
  server = next_primary(nil, session)
195
201
 
196
- # While server versions 3.4 and newer generally perform option
197
- # validation, there was a bug on server versions 4.2.0 - 4.2.5 where
198
- # the server would accept the commitQuorum option and use it internally
199
- # (see SERVER-47193). As a result, the drivers specifications require
200
- # drivers to perform validation and raise an error when the commitQuorum
201
- # option is passed to servers that don't support it.
202
- description = server.with_connection { |connection| connection.description }
203
- if description.max_wire_version < 9 && options[:commit_quorum]
204
- raise Error::UnsupportedOption.commit_quorum_error
205
- end
206
-
207
202
  indexes = normalize_models(models, server)
208
203
  indexes.each do |index|
209
204
  if index[:bucketSize] || index['bucketSize']
@@ -216,10 +211,9 @@ module Mongo
216
211
  db_name: database.name,
217
212
  coll_name: collection.name,
218
213
  session: session,
219
- commit_quorum: options[:commit_quorum]
220
- }
221
-
222
- spec[:write_concern] = write_concern if description.features.collation_enabled?
214
+ commit_quorum: options[:commit_quorum],
215
+ write_concern: write_concern,
216
+ }
223
217
 
224
218
  Operation::CreateIndex.new(spec).execute(server, context: Operation::Context.new(client: client, session: session))
225
219
  end
@@ -292,13 +286,13 @@ module Mongo
292
286
  def drop_by_name(name)
293
287
  client.send(:with_session, @options) do |session|
294
288
  spec = {
295
- db_name: database.name,
296
- coll_name: collection.name,
297
- index_name: name,
298
- session: session
299
- }
289
+ db_name: database.name,
290
+ coll_name: collection.name,
291
+ index_name: name,
292
+ session: session,
293
+ write_concern: write_concern,
294
+ }
300
295
  server = next_primary(nil, session)
301
- spec[:write_concern] = write_concern if server.with_connection { |connection| connection.features }.collation_enabled?
302
296
  Operation::DropIndex.new(spec).execute(server, context: Operation::Context.new(client: client, session: session))
303
297
  end
304
298
  end
@@ -329,30 +323,17 @@ module Mongo
329
323
  end
330
324
 
331
325
  def normalize_models(models, server)
332
- with_generated_names(models, server).map do |model|
333
- Options::Mapper.transform(model, OPTIONS)
326
+ models.map do |model|
327
+ # Transform options first which gives us a mutable hash
328
+ Options::Mapper.transform(model, OPTIONS).tap do |model|
329
+ model[:name] ||= index_name(model.fetch(:key))
330
+ end
334
331
  end
335
332
  end
336
333
 
337
334
  def send_initial_query(server, session)
338
335
  initial_query_op(session).execute(server, context: Operation::Context.new(client: client, session: session))
339
336
  end
340
-
341
- def with_generated_names(models, server)
342
- models.dup.each do |model|
343
- validate_collation!(model, server)
344
- unless model[:name]
345
- model[:name] = index_name(model[:key])
346
- end
347
- end
348
- end
349
-
350
- def validate_collation!(model, server)
351
- if (model[:collation] || model[Operation::COLLATION]) &&
352
- !server.with_connection { |connection| connection.features }.collation_enabled?
353
- raise Error::UnsupportedCollation.new
354
- end
355
- end
356
337
  end
357
338
  end
358
339
  end
@@ -31,15 +31,18 @@ module Mongo
31
31
  # @since 2.9.0
32
32
  attr_reader :address
33
33
 
34
+ # @return [ nil | Object ] The service id, if any.
35
+ attr_reader :service_id
36
+
34
37
  # Create the event.
35
38
  #
36
- # @example Create the event.
37
- # PoolCleared.new(address)
39
+ # @param [ Address ] address
40
+ # @param [ Object ] service_id The service id, if any.
38
41
  #
39
- # @since 2.9.0
40
42
  # @api private
41
- def initialize(address)
43
+ def initialize(address, service_id: nil)
42
44
  @address = address
45
+ @service_id = service_id
43
46
  end
44
47
 
45
48
  # Returns a concise yet useful summary of the event.
@@ -88,11 +88,11 @@ module Mongo
88
88
  @address = address
89
89
  @request_id = request_id
90
90
  @operation_id = operation_id
91
+ @service_id = service_id
91
92
  @message = message
92
93
  @started_event = started_event
93
94
  @failure = redacted(command_name, failure)
94
95
  @duration = duration
95
- @service_id = service_id
96
96
  end
97
97
 
98
98
  # Returns a concise yet useful summary of the event.
@@ -78,6 +78,7 @@ module Mongo
78
78
  # @param [ Integer ] request_id The request id.
79
79
  # @param [ Integer ] operation_id The operation id.
80
80
  # @param [ BSON::Document ] command The command arguments.
81
+ # @param [ Object ] service_id The service id, if any.
81
82
  #
82
83
  # @since 2.1.0
83
84
  # @api private
@@ -140,6 +141,7 @@ module Mongo
140
141
  # @param [ Server::Address ] address The server address.
141
142
  # @param [ Integer ] operation_id The operation id.
142
143
  # @param [ Hash ] payload The message payload.
144
+ # @param [ Object ] service_id The service id, if any.
143
145
  #
144
146
  # @return [ CommandStarted ] The event.
145
147
  #
@@ -35,7 +35,6 @@ module Mongo
35
35
  def publish_sdam_event(topic, event)
36
36
  return unless monitoring?
37
37
 
38
- #log_debug("EVENT: #{event.summary}")
39
38
  monitoring.succeeded(topic, event)
40
39
  end
41
40
 
@@ -49,12 +48,13 @@ module Mongo
49
48
 
50
49
  def command_started(address, operation_id, payload,
51
50
  socket_object_id: nil, connection_id: nil, connection_generation: nil,
52
- server_connection_id: nil
51
+ server_connection_id: nil, service_id: nil
53
52
  )
54
53
  event = Event::CommandStarted.generate(address, operation_id, payload,
55
54
  socket_object_id: socket_object_id, connection_id: connection_id,
56
55
  connection_generation: connection_generation,
57
56
  server_connection_id: server_connection_id,
57
+ service_id: service_id,
58
58
  )
59
59
  monitoring.started(
60
60
  Monitoring::COMMAND,
@@ -34,6 +34,14 @@ module Mongo
34
34
 
35
35
  private
36
36
 
37
+ def selector(connection)
38
+ super.tap do |selector|
39
+ if selector[:collation] && !connection.features.collation_enabled?
40
+ raise Error::UnsupportedCollation
41
+ end
42
+ end
43
+ end
44
+
37
45
  def write_concern_supported?(connection)
38
46
  connection.features.collation_enabled?
39
47
  end
@@ -24,9 +24,18 @@ module Mongo
24
24
  # in a single container, and provides facade methods for the contained
25
25
  # objects.
26
26
  #
27
+ # The context contains parameters for operations, and as such while an
28
+ # operation is being prepared nothing in the context should change.
29
+ # When the result of the operation is being processed, the data
30
+ # returned by the context may change (for example, because a transaction
31
+ # is aborted), but at that point the operation should no longer read
32
+ # anything from the context. Because context data may change during
33
+ # operation execution, context objects should not be reused for multiple
34
+ # operations.
35
+ #
27
36
  # @api private
28
37
  class Context
29
- def initialize(client: nil, session: nil, options: nil)
38
+ def initialize(client: nil, session: nil, service_id: nil, options: nil)
30
39
  if options
31
40
  if client
32
41
  raise ArgumentError, 'Client and options cannot both be specified'
@@ -37,8 +46,13 @@ module Mongo
37
46
  end
38
47
  end
39
48
 
49
+ if service_id && session&.pinned_service_id
50
+ raise ArgumentError, 'Trying to pin context to a service when the session is already pinned to a service'
51
+ end
52
+
40
53
  @client = client
41
54
  @session = session
55
+ @service_id = service_id
42
56
  @options = options
43
57
  end
44
58
 
@@ -46,6 +60,10 @@ module Mongo
46
60
  attr_reader :session
47
61
  attr_reader :options
48
62
 
63
+ def service_id
64
+ @service_id || session&.pinned_service_id
65
+ end
66
+
49
67
  def in_transaction?
50
68
  session&.in_transaction? || false
51
69
  end
@@ -32,6 +32,12 @@ module Mongo
32
32
 
33
33
  private
34
34
 
35
+ def selector(connection)
36
+ selector = spec[:selector]
37
+ selector = apply_collation(selector, connection, spec[:collation])
38
+ selector
39
+ end
40
+
35
41
  def message(connection)
36
42
  Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection))
37
43
  end
@@ -26,6 +26,12 @@ module Mongo
26
26
  # @since 2.5.2
27
27
  class OpMsg < OpMsgBase
28
28
  include CausalConsistencySupported
29
+
30
+ private
31
+
32
+ def selector(connection)
33
+ spec[:selector].merge(collation: spec[:collation]).compact
34
+ end
29
35
  end
30
36
  end
31
37
  end
@@ -19,7 +19,7 @@ module Mongo
19
19
  module Operation
20
20
  class Create
21
21
 
22
- # A MongoDB count operation sent as a command message.
22
+ # A MongoDB create collection operation sent as a command message.
23
23
  #
24
24
  # @api private
25
25
  #
@@ -32,6 +32,12 @@ module Mongo
32
32
 
33
33
  private
34
34
 
35
+ def selector(connection)
36
+ selector = spec[:selector]
37
+ selector = apply_collation(selector, connection, spec[:collation])
38
+ selector
39
+ end
40
+
35
41
  def message(connection)
36
42
  Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection))
37
43
  end
@@ -26,6 +26,13 @@ module Mongo
26
26
  # @since 2.5.2
27
27
  class OpMsg < OpMsgBase
28
28
  include ExecutableTransactionLabel
29
+
30
+ private
31
+
32
+ def selector(connection)
33
+ # Collation is always supported on 3.6+ servers that would use OP_MSG.
34
+ spec[:selector].merge(collation: spec[:collation]).compact
35
+ end
29
36
  end
30
37
  end
31
38
  end
@@ -33,7 +33,23 @@ module Mongo
33
33
  private
34
34
 
35
35
  def selector(connection)
36
- { :createIndexes => coll_name, :indexes => indexes }
36
+ indexes.each do |index|
37
+ if index[:collation] && !connection.features.collation_enabled?
38
+ raise Error::UnsupportedCollation
39
+ end
40
+ end
41
+
42
+ {
43
+ createIndexes: coll_name,
44
+ indexes: indexes,
45
+ }.tap do |selector|
46
+ if commit_quorum = spec[:commit_quorum]
47
+ unless connection.features.commit_quorum_enabled?
48
+ raise Error::UnsupportedOption.commit_quorum_error
49
+ end
50
+ selector[:commitQuorum] = commit_quorum
51
+ end
52
+ end
37
53
  end
38
54
 
39
55
  def message(connection)
@@ -30,10 +30,23 @@ module Mongo
30
30
  private
31
31
 
32
32
  def selector(connection)
33
- selector = { :createIndexes => coll_name, :indexes => indexes }
34
- selector[:commitQuorum] = commit_quorum if commit_quorum
35
-
36
- selector
33
+ {
34
+ createIndexes: coll_name,
35
+ indexes: indexes,
36
+ }.tap do |selector|
37
+ if commit_quorum = spec[:commit_quorum]
38
+ # While server versions 3.4 and newer generally perform option
39
+ # validation, there was a bug on server versions 4.2.0 - 4.2.5 where
40
+ # the server would accept the commitQuorum option and use it internally
41
+ # (see SERVER-47193). As a result, the drivers specifications require
42
+ # drivers to perform validation and raise an error when the commitQuorum
43
+ # option is passed to servers that don't support it.
44
+ unless connection.features.commit_quorum_enabled?
45
+ raise Error::UnsupportedOption.commit_quorum_error
46
+ end
47
+ selector[:commitQuorum] = commit_quorum
48
+ end
49
+ end
37
50
  end
38
51
  end
39
52
  end