mongo 2.17.3 → 2.18.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (622) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +21 -37
  4. data/lib/mongo/auth/base.rb +8 -1
  5. data/lib/mongo/auth.rb +12 -1
  6. data/lib/mongo/bulk_write/result.rb +10 -1
  7. data/lib/mongo/bulk_write/result_combiner.rb +2 -4
  8. data/lib/mongo/bulk_write.rb +108 -28
  9. data/lib/mongo/client.rb +114 -12
  10. data/lib/mongo/client_encryption.rb +30 -9
  11. data/lib/mongo/cluster/reapers/cursor_reaper.rb +11 -1
  12. data/lib/mongo/cluster.rb +20 -24
  13. data/lib/mongo/collection/helpers.rb +43 -0
  14. data/lib/mongo/collection/queryable_encryption.rb +122 -0
  15. data/lib/mongo/collection/view/aggregation.rb +19 -16
  16. data/lib/mongo/collection/view/change_stream.rb +56 -23
  17. data/lib/mongo/collection/view/explainable.rb +1 -1
  18. data/lib/mongo/collection/view/iterable.rb +2 -3
  19. data/lib/mongo/collection/view/map_reduce.rb +18 -9
  20. data/lib/mongo/collection/view/readable.rb +19 -23
  21. data/lib/mongo/collection/view/writable.rb +133 -40
  22. data/lib/mongo/collection.rb +108 -48
  23. data/lib/mongo/config/options.rb +62 -0
  24. data/lib/mongo/config/validators/option.rb +26 -0
  25. data/lib/mongo/config.rb +31 -0
  26. data/lib/mongo/crypt/auto_encrypter.rb +79 -6
  27. data/lib/mongo/crypt/binding.rb +395 -143
  28. data/lib/mongo/crypt/context.rb +5 -2
  29. data/lib/mongo/crypt/data_key_context.rb +7 -104
  30. data/lib/mongo/crypt/encryption_io.rb +28 -60
  31. data/lib/mongo/crypt/explicit_encrypter.rb +27 -25
  32. data/lib/mongo/crypt/explicit_encryption_context.rb +31 -3
  33. data/lib/mongo/crypt/handle.rb +102 -79
  34. data/lib/mongo/crypt/hooks.rb +25 -2
  35. data/lib/mongo/crypt/kms/aws.rb +128 -0
  36. data/lib/mongo/crypt/kms/azure.rb +136 -0
  37. data/lib/mongo/crypt/kms/credentials.rb +81 -0
  38. data/lib/mongo/crypt/kms/gcp.rb +182 -0
  39. data/lib/mongo/crypt/kms/kmip.rb +110 -0
  40. data/lib/mongo/crypt/kms/local.rb +74 -0
  41. data/lib/mongo/crypt/kms/master_key_document.rb +65 -0
  42. data/lib/mongo/crypt/kms.rb +117 -0
  43. data/lib/mongo/crypt.rb +1 -0
  44. data/lib/mongo/cursor/kill_spec.rb +27 -6
  45. data/lib/mongo/cursor.rb +21 -16
  46. data/lib/mongo/database/view.rb +6 -3
  47. data/lib/mongo/database.rb +73 -12
  48. data/lib/mongo/dbref.rb +1 -105
  49. data/lib/mongo/error/bulk_write_error.rb +31 -4
  50. data/lib/mongo/error/invalid_config_option.rb +20 -0
  51. data/lib/mongo/error/invalid_replacement_document.rb +27 -9
  52. data/lib/mongo/error/invalid_update_document.rb +27 -7
  53. data/lib/mongo/error/labelable.rb +72 -0
  54. data/lib/mongo/error/missing_connection.rb +25 -0
  55. data/lib/mongo/error/notable.rb +7 -0
  56. data/lib/mongo/error/operation_failure.rb +34 -86
  57. data/lib/mongo/error/read_write_retryable.rb +108 -0
  58. data/lib/mongo/{operation/kill_cursors/legacy.rb → error/session_not_materialized.rb} +7 -19
  59. data/lib/mongo/error.rb +5 -37
  60. data/lib/mongo/index/view.rb +22 -7
  61. data/lib/mongo/monitoring/event/command_failed.rb +8 -2
  62. data/lib/mongo/monitoring/event/command_started.rb +1 -1
  63. data/lib/mongo/monitoring/event/command_succeeded.rb +9 -2
  64. data/lib/mongo/monitoring/publishable.rb +9 -5
  65. data/lib/mongo/operation/collections_info/result.rb +5 -2
  66. data/lib/mongo/operation/command/op_msg.rb +6 -0
  67. data/lib/mongo/operation/context.rb +24 -6
  68. data/lib/mongo/operation/count/op_msg.rb +4 -1
  69. data/lib/mongo/operation/create/op_msg.rb +16 -1
  70. data/lib/mongo/operation/create_index/op_msg.rb +2 -1
  71. data/lib/mongo/operation/delete/op_msg.rb +1 -0
  72. data/lib/mongo/operation/delete.rb +0 -1
  73. data/lib/mongo/operation/drop_index/op_msg.rb +5 -1
  74. data/lib/mongo/operation/get_more/command_builder.rb +5 -1
  75. data/lib/mongo/operation/insert/bulk_result.rb +5 -1
  76. data/lib/mongo/operation/insert/command.rb +0 -4
  77. data/lib/mongo/operation/insert/op_msg.rb +6 -3
  78. data/lib/mongo/operation/insert/result.rb +6 -3
  79. data/lib/mongo/operation/insert.rb +0 -1
  80. data/lib/mongo/operation/kill_cursors.rb +0 -1
  81. data/lib/mongo/operation/list_collections/op_msg.rb +4 -1
  82. data/lib/mongo/operation/map_reduce/result.rb +16 -0
  83. data/lib/mongo/operation/result.rb +21 -5
  84. data/lib/mongo/operation/shared/executable.rb +21 -6
  85. data/lib/mongo/operation/shared/polymorphic_operation.rb +15 -3
  86. data/lib/mongo/operation/shared/response_handling.rb +6 -5
  87. data/lib/mongo/operation/shared/sessions_supported.rb +3 -7
  88. data/lib/mongo/operation/shared/write.rb +18 -12
  89. data/lib/mongo/operation/update/op_msg.rb +2 -1
  90. data/lib/mongo/operation/update.rb +0 -1
  91. data/lib/mongo/protocol/caching_hash.rb +69 -0
  92. data/lib/mongo/protocol/msg.rb +37 -1
  93. data/lib/mongo/protocol.rb +1 -0
  94. data/lib/mongo/query_cache.rb +15 -0
  95. data/lib/mongo/retryable.rb +78 -30
  96. data/lib/mongo/server/connection.rb +33 -0
  97. data/lib/mongo/server/connection_base.rb +2 -0
  98. data/lib/mongo/server/connection_common.rb +4 -1
  99. data/lib/mongo/server/connection_pool.rb +69 -42
  100. data/lib/mongo/server/description/features.rb +3 -1
  101. data/lib/mongo/server/description.rb +7 -2
  102. data/lib/mongo/server/monitor/connection.rb +5 -10
  103. data/lib/mongo/server/monitor.rb +21 -13
  104. data/lib/mongo/server/push_monitor.rb +9 -3
  105. data/lib/mongo/server.rb +9 -5
  106. data/lib/mongo/session/session_pool.rb +8 -0
  107. data/lib/mongo/session.rb +111 -35
  108. data/lib/mongo/socket/ocsp_verifier.rb +4 -5
  109. data/lib/mongo/socket/tcp.rb +3 -0
  110. data/lib/mongo/srv/resolver.rb +24 -3
  111. data/lib/mongo/uri/options_mapper.rb +2 -0
  112. data/lib/mongo/uri/srv_protocol.rb +1 -1
  113. data/lib/mongo/uri.rb +20 -0
  114. data/lib/mongo/version.rb +1 -1
  115. data/lib/mongo.rb +20 -0
  116. data/mongo.gemspec +10 -4
  117. data/spec/README.md +5 -5
  118. data/spec/integration/aws_lambda_examples_spec.rb +68 -0
  119. data/spec/integration/bulk_write_error_message_spec.rb +32 -0
  120. data/spec/integration/bulk_write_spec.rb +0 -16
  121. data/spec/integration/change_stream_spec.rb +6 -5
  122. data/spec/integration/client_construction_spec.rb +1 -1
  123. data/spec/integration/client_side_encryption/auto_encryption_bulk_writes_spec.rb +9 -9
  124. data/spec/integration/client_side_encryption/auto_encryption_command_monitoring_spec.rb +18 -19
  125. data/spec/integration/client_side_encryption/auto_encryption_mongocryptd_spawn_spec.rb +0 -1
  126. data/spec/integration/client_side_encryption/auto_encryption_reconnect_spec.rb +31 -0
  127. data/spec/integration/client_side_encryption/auto_encryption_spec.rb +108 -1
  128. data/spec/integration/client_side_encryption/bson_size_limit_spec.rb +2 -2
  129. data/spec/integration/client_side_encryption/bypass_mongocryptd_spawn_spec.rb +2 -2
  130. data/spec/integration/client_side_encryption/client_close_spec.rb +1 -1
  131. data/spec/integration/client_side_encryption/corpus_spec.rb +64 -35
  132. data/spec/integration/client_side_encryption/custom_endpoint_spec.rb +39 -42
  133. data/spec/integration/client_side_encryption/data_key_spec.rb +97 -7
  134. data/spec/integration/client_side_encryption/explicit_encryption_spec.rb +59 -0
  135. data/spec/integration/client_side_encryption/explicit_queryable_encryption_spec.rb +147 -0
  136. data/spec/integration/client_side_encryption/external_key_vault_spec.rb +6 -6
  137. data/spec/integration/client_side_encryption/kms_tls_options_spec.rb +394 -0
  138. data/spec/integration/client_side_encryption/kms_tls_spec.rb +92 -0
  139. data/spec/integration/client_side_encryption/queryable_encryption_examples_spec.rb +111 -0
  140. data/spec/integration/client_side_encryption/views_spec.rb +1 -1
  141. data/spec/integration/client_update_spec.rb +2 -2
  142. data/spec/integration/crud_spec.rb +12 -0
  143. data/spec/integration/cursor_pinning_spec.rb +3 -3
  144. data/spec/integration/fork_reconnect_spec.rb +15 -8
  145. data/spec/integration/grid_fs_bucket_spec.rb +3 -3
  146. data/spec/integration/ocsp_verifier_spec.rb +1 -0
  147. data/spec/integration/query_cache_spec.rb +34 -30
  148. data/spec/integration/retryable_writes/retryable_writes_36_and_older_spec.rb +1 -1
  149. data/spec/integration/sdam_events_spec.rb +0 -40
  150. data/spec/integration/server_monitor_spec.rb +2 -1
  151. data/spec/integration/size_limit_spec.rb +4 -1
  152. data/spec/integration/snapshot_query_examples_spec.rb +127 -0
  153. data/spec/integration/srv_monitoring_spec.rb +37 -0
  154. data/spec/integration/step_down_spec.rb +20 -4
  155. data/spec/integration/transaction_pinning_spec.rb +2 -2
  156. data/spec/integration/versioned_api_examples_spec.rb +37 -31
  157. data/spec/lite_spec_helper.rb +14 -5
  158. data/spec/mongo/address/ipv6_spec.rb +7 -0
  159. data/spec/mongo/address_spec.rb +7 -0
  160. data/spec/mongo/auth/scram/conversation_spec.rb +23 -23
  161. data/spec/mongo/auth/scram256/conversation_spec.rb +20 -20
  162. data/spec/mongo/auth/scram_negotiation_spec.rb +1 -0
  163. data/spec/mongo/bulk_write/result_spec.rb +15 -1
  164. data/spec/mongo/bulk_write_spec.rb +128 -20
  165. data/spec/mongo/client_construction_spec.rb +141 -7
  166. data/spec/mongo/client_encryption_spec.rb +11 -11
  167. data/spec/mongo/client_spec.rb +297 -1
  168. data/spec/mongo/cluster/cursor_reaper_spec.rb +21 -3
  169. data/spec/mongo/cluster_spec.rb +0 -44
  170. data/spec/mongo/collection/view/aggregation_spec.rb +2 -2
  171. data/spec/mongo/collection/view/change_stream_spec.rb +2 -2
  172. data/spec/mongo/collection/view/readable_spec.rb +35 -56
  173. data/spec/mongo/collection/view/writable_spec.rb +144 -32
  174. data/spec/mongo/collection_crud_spec.rb +63 -13
  175. data/spec/mongo/config/options_spec.rb +75 -0
  176. data/spec/mongo/config_spec.rb +73 -0
  177. data/spec/mongo/crypt/auto_decryption_context_spec.rb +17 -1
  178. data/spec/mongo/crypt/auto_encrypter_spec.rb +106 -0
  179. data/spec/mongo/crypt/auto_encryption_context_spec.rb +17 -1
  180. data/spec/mongo/crypt/binding/context_spec.rb +99 -17
  181. data/spec/mongo/crypt/binding/mongocrypt_spec.rb +17 -46
  182. data/spec/mongo/crypt/binding/version_spec.rb +25 -0
  183. data/spec/mongo/crypt/binding_unloaded_spec.rb +14 -0
  184. data/spec/mongo/crypt/data_key_context_spec.rb +42 -114
  185. data/spec/mongo/crypt/encryption_io_spec.rb +2 -0
  186. data/spec/mongo/crypt/explicit_decryption_context_spec.rb +32 -1
  187. data/spec/mongo/crypt/explicit_encryption_context_spec.rb +89 -1
  188. data/spec/mongo/crypt/handle_spec.rb +47 -169
  189. data/spec/mongo/crypt/hooks_spec.rb +30 -0
  190. data/spec/mongo/crypt/kms/credentials_spec.rb +404 -0
  191. data/spec/mongo/crypt/kms_spec.rb +59 -0
  192. data/spec/mongo/cursor_spec.rb +37 -51
  193. data/spec/mongo/database_spec.rb +66 -1
  194. data/spec/mongo/error/operation_failure_heavy_spec.rb +49 -0
  195. data/spec/mongo/index/view_spec.rb +69 -0
  196. data/spec/mongo/operation/create/op_msg_spec.rb +286 -0
  197. data/spec/mongo/operation/delete/op_msg_spec.rb +13 -4
  198. data/spec/mongo/operation/delete_spec.rb +0 -30
  199. data/spec/mongo/operation/insert/op_msg_spec.rb +18 -10
  200. data/spec/mongo/operation/insert_spec.rb +0 -32
  201. data/spec/mongo/operation/result_spec.rb +20 -0
  202. data/spec/mongo/operation/update/op_msg_spec.rb +13 -4
  203. data/spec/mongo/operation/update_spec.rb +0 -29
  204. data/spec/mongo/protocol/caching_hash_spec.rb +82 -0
  205. data/spec/mongo/protocol/msg_spec.rb +41 -0
  206. data/spec/mongo/query_cache_spec.rb +1 -0
  207. data/spec/mongo/retryable_spec.rb +32 -3
  208. data/spec/mongo/server/connection_auth_spec.rb +3 -1
  209. data/spec/mongo/server/connection_common_spec.rb +13 -1
  210. data/spec/mongo/server/connection_pool_spec.rb +94 -49
  211. data/spec/mongo/server/connection_spec.rb +50 -159
  212. data/spec/mongo/server/description/features_spec.rb +24 -0
  213. data/spec/mongo/server/push_monitor_spec.rb +2 -8
  214. data/spec/mongo/session_spec.rb +26 -6
  215. data/spec/mongo/session_transaction_spec.rb +2 -1
  216. data/spec/mongo/socket/ssl_spec.rb +15 -4
  217. data/spec/mongo/uri/srv_protocol_spec.rb +101 -2
  218. data/spec/mongo/uri_spec.rb +25 -0
  219. data/spec/runners/connection_string.rb +8 -0
  220. data/spec/runners/crud/operation.rb +12 -3
  221. data/spec/runners/crud/requirement.rb +3 -3
  222. data/spec/runners/crud/spec.rb +5 -0
  223. data/spec/runners/crud/verifier.rb +6 -0
  224. data/spec/runners/transactions/test.rb +33 -14
  225. data/spec/runners/transactions.rb +9 -6
  226. data/spec/runners/unified/assertions.rb +59 -10
  227. data/spec/runners/unified/change_stream_operations.rb +9 -0
  228. data/spec/runners/unified/crud_operations.rb +50 -2
  229. data/spec/runners/unified/ddl_operations.rb +20 -0
  230. data/spec/runners/unified/error.rb +2 -1
  231. data/spec/runners/unified/support_operations.rb +5 -2
  232. data/spec/runners/unified/test.rb +19 -4
  233. data/spec/runners/unified.rb +9 -2
  234. data/spec/shared/lib/mrss/constraints.rb +10 -17
  235. data/spec/shared/lib/mrss/docker_runner.rb +21 -3
  236. data/spec/shared/lib/mrss/lite_constraints.rb +32 -1
  237. data/spec/shared/lib/mrss/session_registry.rb +69 -0
  238. data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
  239. data/spec/shared/share/Dockerfile.erb +56 -54
  240. data/spec/shared/shlib/config.sh +27 -0
  241. data/spec/shared/shlib/distro.sh +2 -1
  242. data/spec/shared/shlib/server.sh +46 -21
  243. data/spec/shared/shlib/set_env.sh +40 -5
  244. data/spec/spec_helper.rb +0 -1
  245. data/spec/spec_tests/crud_spec.rb +0 -10
  246. data/spec/spec_tests/data/change_streams_unified/change-streams-errors.yml +124 -0
  247. data/spec/spec_tests/data/change_streams_unified/change-streams-pre_and_post_images.yml +351 -0
  248. data/spec/spec_tests/data/change_streams_unified/change-streams-resume-allowlist.yml +1171 -0
  249. data/spec/spec_tests/data/change_streams_unified/change-streams-resume-errorLabels.yml +1068 -0
  250. data/spec/spec_tests/data/change_streams_unified/change-streams.yml +859 -4
  251. data/spec/spec_tests/data/client_side_encryption/aggregate.yml +3 -17
  252. data/spec/spec_tests/data/client_side_encryption/azureKMS.yml +46 -0
  253. data/spec/spec_tests/data/client_side_encryption/badQueries.yml +12 -2
  254. data/spec/spec_tests/data/client_side_encryption/basic.yml +3 -17
  255. data/spec/spec_tests/data/client_side_encryption/bulk.yml +1 -8
  256. data/spec/spec_tests/data/client_side_encryption/bypassAutoEncryption.yml +2 -2
  257. data/spec/spec_tests/data/client_side_encryption/count.yml +1 -8
  258. data/spec/spec_tests/data/client_side_encryption/countDocuments.yml +1 -8
  259. data/spec/spec_tests/data/client_side_encryption/delete.yml +2 -16
  260. data/spec/spec_tests/data/client_side_encryption/distinct.yml +1 -8
  261. data/spec/spec_tests/data/client_side_encryption/explain.yml +1 -8
  262. data/spec/spec_tests/data/client_side_encryption/find.yml +2 -16
  263. data/spec/spec_tests/data/client_side_encryption/findOneAndDelete.yml +1 -8
  264. data/spec/spec_tests/data/client_side_encryption/findOneAndReplace.yml +1 -8
  265. data/spec/spec_tests/data/client_side_encryption/findOneAndUpdate.yml +1 -8
  266. data/spec/spec_tests/data/client_side_encryption/fle2-BypassQueryAnalysis.yml +101 -0
  267. data/spec/spec_tests/data/client_side_encryption/fle2-Compact.yml +80 -0
  268. data/spec/spec_tests/data/client_side_encryption/fle2-CreateCollection.yml +1263 -0
  269. data/spec/spec_tests/data/client_side_encryption/fle2-DecryptExistingData.yml +64 -0
  270. data/spec/spec_tests/data/client_side_encryption/fle2-Delete.yml +107 -0
  271. data/spec/spec_tests/data/client_side_encryption/fle2-EncryptedFields-vs-EncryptedFieldsMap.yml +80 -0
  272. data/spec/spec_tests/data/client_side_encryption/fle2-EncryptedFields-vs-jsonSchema.yml +90 -0
  273. data/spec/spec_tests/data/client_side_encryption/fle2-EncryptedFieldsMap-defaults.yml +57 -0
  274. data/spec/spec_tests/data/client_side_encryption/fle2-FindOneAndUpdate.yml +213 -0
  275. data/spec/spec_tests/data/client_side_encryption/fle2-InsertFind-Indexed.yml +86 -0
  276. data/spec/spec_tests/data/client_side_encryption/fle2-InsertFind-Unindexed.yml +83 -0
  277. data/spec/spec_tests/data/client_side_encryption/fle2-MissingKey.yml +41 -0
  278. data/spec/spec_tests/data/client_side_encryption/fle2-NoEncryption.yml +42 -0
  279. data/spec/spec_tests/data/client_side_encryption/fle2-Update.yml +221 -0
  280. data/spec/spec_tests/data/client_side_encryption/fle2-validatorAndPartialFieldExpression.yml +168 -0
  281. data/spec/spec_tests/data/client_side_encryption/gcpKMS.yml +46 -0
  282. data/spec/spec_tests/data/client_side_encryption/getMore.yml +1 -8
  283. data/spec/spec_tests/data/client_side_encryption/insert.yml +2 -16
  284. data/spec/spec_tests/data/client_side_encryption/keyAltName.yml +1 -8
  285. data/spec/spec_tests/data/client_side_encryption/localKMS.yml +1 -8
  286. data/spec/spec_tests/data/client_side_encryption/localSchema.yml +1 -8
  287. data/spec/spec_tests/data/client_side_encryption/maxWireVersion.yml +2 -0
  288. data/spec/spec_tests/data/client_side_encryption/missingKey.yml +2 -9
  289. data/spec/spec_tests/data/client_side_encryption/noSchema.yml +39 -0
  290. data/spec/spec_tests/data/client_side_encryption/replaceOne.yml +1 -8
  291. data/spec/spec_tests/data/client_side_encryption/types.yml +44 -70
  292. data/spec/spec_tests/data/client_side_encryption/updateMany.yml +1 -8
  293. data/spec/spec_tests/data/client_side_encryption/updateOne.yml +1 -8
  294. data/spec/spec_tests/data/collection_management/clustered-indexes.yml +135 -0
  295. data/spec/spec_tests/data/collection_management/createCollection-pre_and_post_images.yml +50 -0
  296. data/spec/spec_tests/data/collection_management/modifyCollection-pre_and_post_images.yml +58 -0
  297. data/spec/spec_tests/data/command_monitoring_unified/pre-42-server-connection-id.yml +56 -0
  298. data/spec/spec_tests/data/command_monitoring_unified/server-connection-id.yml +56 -0
  299. data/spec/spec_tests/data/crud/read/aggregate-collation.yml +1 -1
  300. data/spec/spec_tests/data/crud/read/count-collation.yml +1 -1
  301. data/spec/spec_tests/data/crud/read/distinct-collation.yml +1 -1
  302. data/spec/spec_tests/data/crud/read/find-collation.yml +1 -1
  303. data/spec/spec_tests/data/crud/write/bulkWrite-collation.yml +1 -1
  304. data/spec/spec_tests/data/crud/write/deleteMany-collation.yml +1 -1
  305. data/spec/spec_tests/data/crud/write/deleteOne-collation.yml +1 -1
  306. data/spec/spec_tests/data/crud/write/findOneAndDelete-collation.yml +1 -1
  307. data/spec/spec_tests/data/crud/write/findOneAndReplace-collation.yml +1 -1
  308. data/spec/spec_tests/data/crud/write/findOneAndUpdate-collation.yml +1 -1
  309. data/spec/spec_tests/data/crud/write/replaceOne-collation.yml +1 -1
  310. data/spec/spec_tests/data/crud/write/updateMany-collation.yml +1 -1
  311. data/spec/spec_tests/data/crud/write/updateOne-collation.yml +1 -1
  312. data/spec/spec_tests/data/crud_unified/aggregate-allowdiskuse.yml +75 -0
  313. data/spec/spec_tests/data/crud_unified/aggregate-merge.yml +185 -0
  314. data/spec/spec_tests/data/crud_unified/aggregate-out-readConcern.yml +171 -0
  315. data/spec/spec_tests/data/crud_unified/aggregate.yml +215 -0
  316. data/spec/spec_tests/data/crud_unified/bulkWrite-arrayFilters-clientError.yml +98 -0
  317. data/spec/spec_tests/data/crud_unified/bulkWrite-arrayFilters.yml +174 -0
  318. data/spec/spec_tests/data/crud_unified/bulkWrite-comment.yml +189 -0
  319. data/spec/spec_tests/data/crud_unified/bulkWrite-delete-hint-clientError.yml +113 -0
  320. data/spec/spec_tests/data/crud_unified/bulkWrite-delete-hint-serverError.yml +142 -0
  321. data/spec/spec_tests/data/crud_unified/bulkWrite-delete-hint.yml +154 -0
  322. data/spec/spec_tests/data/crud_unified/bulkWrite-deleteMany-hint-unacknowledged.yml +98 -0
  323. data/spec/spec_tests/data/crud_unified/bulkWrite-deleteMany-let.yml +86 -0
  324. data/spec/spec_tests/data/crud_unified/bulkWrite-deleteOne-hint-unacknowledged.yml +97 -0
  325. data/spec/spec_tests/data/crud_unified/bulkWrite-deleteOne-let.yml +86 -0
  326. data/spec/spec_tests/data/crud_unified/bulkWrite-insertOne-dots_and_dollars.yml +138 -0
  327. data/spec/spec_tests/data/crud_unified/bulkWrite-replaceOne-dots_and_dollars.yml +165 -0
  328. data/spec/spec_tests/data/crud_unified/bulkWrite-replaceOne-hint-unacknowledged.yml +103 -0
  329. data/spec/spec_tests/data/crud_unified/bulkWrite-replaceOne-let.yml +93 -0
  330. data/spec/spec_tests/data/crud_unified/bulkWrite-update-hint-clientError.yml +148 -0
  331. data/spec/spec_tests/data/crud_unified/bulkWrite-update-hint-serverError.yml +239 -0
  332. data/spec/spec_tests/data/crud_unified/bulkWrite-update-hint.yml +256 -0
  333. data/spec/spec_tests/data/crud_unified/bulkWrite-update-validation.yml +73 -0
  334. data/spec/spec_tests/data/crud_unified/bulkWrite-updateMany-dots_and_dollars.yml +150 -0
  335. data/spec/spec_tests/data/crud_unified/bulkWrite-updateMany-hint-unacknowledged.yml +104 -0
  336. data/spec/spec_tests/data/crud_unified/bulkWrite-updateMany-let.yml +96 -0
  337. data/spec/spec_tests/data/crud_unified/bulkWrite-updateOne-dots_and_dollars.yml +150 -0
  338. data/spec/spec_tests/data/crud_unified/bulkWrite-updateOne-hint-unacknowledged.yml +103 -0
  339. data/spec/spec_tests/data/crud_unified/bulkWrite-updateOne-let.yml +95 -0
  340. data/spec/spec_tests/data/crud_unified/countDocuments-comment.yml +92 -0
  341. data/spec/spec_tests/data/crud_unified/db-aggregate.yml +73 -0
  342. data/spec/spec_tests/data/crud_unified/deleteMany-comment.yml +97 -0
  343. data/spec/spec_tests/data/crud_unified/deleteMany-hint-clientError.yml +87 -0
  344. data/spec/spec_tests/data/crud_unified/deleteMany-hint-serverError.yml +107 -0
  345. data/spec/spec_tests/data/crud_unified/deleteMany-hint-unacknowledged.yml +90 -0
  346. data/spec/spec_tests/data/crud_unified/deleteMany-hint.yml +99 -0
  347. data/spec/spec_tests/data/crud_unified/deleteMany-let.yml +2 -0
  348. data/spec/spec_tests/data/crud_unified/deleteOne-comment.yml +98 -0
  349. data/spec/spec_tests/data/crud_unified/deleteOne-hint-clientError.yml +80 -0
  350. data/spec/spec_tests/data/crud_unified/deleteOne-hint-serverError.yml +100 -0
  351. data/spec/spec_tests/data/crud_unified/deleteOne-hint-unacknowledged.yml +89 -0
  352. data/spec/spec_tests/data/crud_unified/deleteOne-hint.yml +95 -0
  353. data/spec/spec_tests/data/crud_unified/deleteOne-let.yml +2 -0
  354. data/spec/spec_tests/data/crud_unified/estimatedDocumentCount-comment.yml +95 -0
  355. data/spec/spec_tests/data/crud_unified/estimatedDocumentCount.yml +5 -135
  356. data/spec/spec_tests/data/crud_unified/find-allowdiskuse-clientError.yml +55 -0
  357. data/spec/spec_tests/data/crud_unified/find-allowdiskuse-serverError.yml +68 -0
  358. data/spec/spec_tests/data/crud_unified/find-allowdiskuse.yml +79 -0
  359. data/spec/spec_tests/data/crud_unified/find-comment.yml +166 -0
  360. data/spec/spec_tests/data/crud_unified/find.yml +68 -0
  361. data/spec/spec_tests/data/crud_unified/findOneAndDelete-comment.yml +96 -0
  362. data/spec/spec_tests/data/crud_unified/findOneAndDelete-hint-clientError.yml +91 -0
  363. data/spec/spec_tests/data/crud_unified/findOneAndDelete-hint-serverError.yml +107 -0
  364. data/spec/spec_tests/data/crud_unified/findOneAndDelete-hint-unacknowledged.yml +88 -0
  365. data/spec/spec_tests/data/crud_unified/findOneAndDelete-hint.yml +102 -0
  366. data/spec/spec_tests/data/crud_unified/findOneAndDelete-let.yml +2 -4
  367. data/spec/spec_tests/data/crud_unified/findOneAndReplace-comment.yml +101 -0
  368. data/spec/spec_tests/data/crud_unified/findOneAndReplace-dots_and_dollars.yml +140 -0
  369. data/spec/spec_tests/data/crud_unified/findOneAndReplace-hint-clientError.yml +83 -0
  370. data/spec/spec_tests/data/crud_unified/findOneAndReplace-hint-serverError.yml +99 -0
  371. data/spec/spec_tests/data/crud_unified/findOneAndReplace-hint-unacknowledged.yml +96 -0
  372. data/spec/spec_tests/data/crud_unified/findOneAndReplace-hint.yml +98 -0
  373. data/spec/spec_tests/data/crud_unified/findOneAndUpdate-comment.yml +95 -0
  374. data/spec/spec_tests/data/crud_unified/findOneAndUpdate-dots_and_dollars.yml +127 -0
  375. data/spec/spec_tests/data/crud_unified/findOneAndUpdate-hint-clientError.yml +84 -0
  376. data/spec/spec_tests/data/crud_unified/findOneAndUpdate-hint-serverError.yml +100 -0
  377. data/spec/spec_tests/data/crud_unified/findOneAndUpdate-hint-unacknowledged.yml +92 -0
  378. data/spec/spec_tests/data/crud_unified/findOneAndUpdate-hint.yml +99 -0
  379. data/spec/spec_tests/data/crud_unified/insertMany-comment.yml +93 -0
  380. data/spec/spec_tests/data/crud_unified/insertMany-dots_and_dollars.yml +128 -0
  381. data/spec/spec_tests/data/crud_unified/insertOne-comment.yml +91 -0
  382. data/spec/spec_tests/data/crud_unified/insertOne-dots_and_dollars.yml +238 -0
  383. data/spec/spec_tests/data/crud_unified/replaceOne-comment.yml +105 -0
  384. data/spec/spec_tests/data/crud_unified/replaceOne-dots_and_dollars.yml +180 -0
  385. data/spec/spec_tests/data/crud_unified/replaceOne-hint-unacknowledged.yml +95 -0
  386. data/spec/spec_tests/data/crud_unified/replaceOne-hint.yml +108 -0
  387. data/spec/spec_tests/data/crud_unified/replaceOne-let.yml +98 -0
  388. data/spec/spec_tests/data/crud_unified/replaceOne-validation.yml +37 -0
  389. data/spec/spec_tests/data/crud_unified/updateMany-comment.yml +104 -0
  390. data/spec/spec_tests/data/crud_unified/updateMany-dots_and_dollars.yml +138 -0
  391. data/spec/spec_tests/data/crud_unified/updateMany-hint-clientError.yml +91 -0
  392. data/spec/spec_tests/data/crud_unified/updateMany-hint-serverError.yml +115 -0
  393. data/spec/spec_tests/data/crud_unified/updateMany-hint-unacknowledged.yml +96 -0
  394. data/spec/spec_tests/data/crud_unified/updateMany-hint.yml +115 -0
  395. data/spec/spec_tests/data/crud_unified/updateMany-let.yml +5 -1
  396. data/spec/spec_tests/data/crud_unified/updateMany-validation.yml +39 -0
  397. data/spec/spec_tests/data/crud_unified/updateOne-comment.yml +104 -0
  398. data/spec/spec_tests/data/crud_unified/updateOne-dots_and_dollars.yml +138 -0
  399. data/spec/spec_tests/data/crud_unified/updateOne-hint-clientError.yml +85 -0
  400. data/spec/spec_tests/data/crud_unified/updateOne-hint-serverError.yml +109 -0
  401. data/spec/spec_tests/data/crud_unified/updateOne-hint-unacknowledged.yml +95 -0
  402. data/spec/spec_tests/data/crud_unified/updateOne-hint.yml +109 -0
  403. data/spec/spec_tests/data/crud_unified/updateOne-let.yml +5 -1
  404. data/spec/spec_tests/data/crud_unified/updateOne-validation.yml +37 -0
  405. data/spec/spec_tests/data/crud_unified/updateWithPipelines.yml +8 -14
  406. data/spec/spec_tests/data/retryable_reads/{aggregate-merge.yml → legacy/aggregate-merge.yml} +0 -0
  407. data/spec/spec_tests/data/retryable_reads/{aggregate-serverErrors.yml → legacy/aggregate-serverErrors.yml} +0 -0
  408. data/spec/spec_tests/data/retryable_reads/{aggregate.yml → legacy/aggregate.yml} +0 -0
  409. data/spec/spec_tests/data/retryable_reads/{changeStreams-client.watch-serverErrors.yml → legacy/changeStreams-client.watch-serverErrors.yml} +0 -0
  410. data/spec/spec_tests/data/retryable_reads/{changeStreams-client.watch.yml → legacy/changeStreams-client.watch.yml} +0 -0
  411. data/spec/spec_tests/data/retryable_reads/{changeStreams-db.coll.watch-serverErrors.yml → legacy/changeStreams-db.coll.watch-serverErrors.yml} +0 -0
  412. data/spec/spec_tests/data/retryable_reads/{changeStreams-db.coll.watch.yml → legacy/changeStreams-db.coll.watch.yml} +0 -0
  413. data/spec/spec_tests/data/retryable_reads/{changeStreams-db.watch-serverErrors.yml → legacy/changeStreams-db.watch-serverErrors.yml} +0 -0
  414. data/spec/spec_tests/data/retryable_reads/{changeStreams-db.watch.yml → legacy/changeStreams-db.watch.yml} +0 -0
  415. data/spec/spec_tests/data/retryable_reads/{count-serverErrors.yml → legacy/count-serverErrors.yml} +0 -0
  416. data/spec/spec_tests/data/retryable_reads/{count.yml → legacy/count.yml} +0 -0
  417. data/spec/spec_tests/data/retryable_reads/{countDocuments-serverErrors.yml → legacy/countDocuments-serverErrors.yml} +0 -0
  418. data/spec/spec_tests/data/retryable_reads/{countDocuments.yml → legacy/countDocuments.yml} +0 -0
  419. data/spec/spec_tests/data/retryable_reads/{distinct-serverErrors.yml → legacy/distinct-serverErrors.yml} +0 -0
  420. data/spec/spec_tests/data/retryable_reads/{distinct.yml → legacy/distinct.yml} +0 -0
  421. data/spec/spec_tests/data/retryable_reads/{estimatedDocumentCount-serverErrors-pre4.9.yml → legacy/estimatedDocumentCount-serverErrors.yml} +0 -2
  422. data/spec/spec_tests/data/retryable_reads/{estimatedDocumentCount-pre4.9.yml → legacy/estimatedDocumentCount.yml} +0 -2
  423. data/spec/spec_tests/data/retryable_reads/{find-serverErrors.yml → legacy/find-serverErrors.yml} +0 -0
  424. data/spec/spec_tests/data/retryable_reads/{find.yml → legacy/find.yml} +0 -0
  425. data/spec/spec_tests/data/retryable_reads/{findOne-serverErrors.yml → legacy/findOne-serverErrors.yml} +0 -0
  426. data/spec/spec_tests/data/retryable_reads/{findOne.yml → legacy/findOne.yml} +0 -0
  427. data/spec/spec_tests/data/retryable_reads/{gridfs-download-serverErrors.yml → legacy/gridfs-download-serverErrors.yml} +0 -0
  428. data/spec/spec_tests/data/retryable_reads/{gridfs-download.yml → legacy/gridfs-download.yml} +0 -0
  429. data/spec/spec_tests/data/retryable_reads/{gridfs-downloadByName-serverErrors.yml → legacy/gridfs-downloadByName-serverErrors.yml} +0 -0
  430. data/spec/spec_tests/data/retryable_reads/{gridfs-downloadByName.yml → legacy/gridfs-downloadByName.yml} +0 -0
  431. data/spec/spec_tests/data/retryable_reads/{listCollectionNames-serverErrors.yml → legacy/listCollectionNames-serverErrors.yml} +0 -0
  432. data/spec/spec_tests/data/retryable_reads/{listCollectionNames.yml → legacy/listCollectionNames.yml} +0 -0
  433. data/spec/spec_tests/data/retryable_reads/{listCollectionObjects-serverErrors.yml → legacy/listCollectionObjects-serverErrors.yml} +0 -0
  434. data/spec/spec_tests/data/retryable_reads/{listCollectionObjects.yml → legacy/listCollectionObjects.yml} +0 -0
  435. data/spec/spec_tests/data/retryable_reads/{listCollections-serverErrors.yml → legacy/listCollections-serverErrors.yml} +0 -0
  436. data/spec/spec_tests/data/retryable_reads/{listCollections.yml → legacy/listCollections.yml} +0 -0
  437. data/spec/spec_tests/data/retryable_reads/{listDatabaseNames-serverErrors.yml → legacy/listDatabaseNames-serverErrors.yml} +0 -0
  438. data/spec/spec_tests/data/retryable_reads/{listDatabaseNames.yml → legacy/listDatabaseNames.yml} +0 -0
  439. data/spec/spec_tests/data/retryable_reads/{listDatabaseObjects-serverErrors.yml → legacy/listDatabaseObjects-serverErrors.yml} +0 -0
  440. data/spec/spec_tests/data/retryable_reads/{listDatabaseObjects.yml → legacy/listDatabaseObjects.yml} +0 -0
  441. data/spec/spec_tests/data/retryable_reads/{listDatabases-serverErrors.yml → legacy/listDatabases-serverErrors.yml} +0 -0
  442. data/spec/spec_tests/data/retryable_reads/{listDatabases.yml → legacy/listDatabases.yml} +0 -0
  443. data/spec/spec_tests/data/retryable_reads/{listIndexNames-serverErrors.yml → legacy/listIndexNames-serverErrors.yml} +0 -0
  444. data/spec/spec_tests/data/retryable_reads/{listIndexNames.yml → legacy/listIndexNames.yml} +0 -0
  445. data/spec/spec_tests/data/retryable_reads/{listIndexes-serverErrors.yml → legacy/listIndexes-serverErrors.yml} +0 -0
  446. data/spec/spec_tests/data/retryable_reads/{listIndexes.yml → legacy/listIndexes.yml} +0 -0
  447. data/spec/spec_tests/data/retryable_reads/{mapReduce.yml → legacy/mapReduce.yml} +0 -0
  448. data/spec/spec_tests/data/retryable_reads/unified/handshakeError.yml +129 -0
  449. data/spec/spec_tests/data/retryable_writes/{bulkWrite-errorLabels.yml → legacy/bulkWrite-errorLabels.yml} +0 -0
  450. data/spec/spec_tests/data/retryable_writes/{bulkWrite-serverErrors.yml → legacy/bulkWrite-serverErrors.yml} +1 -1
  451. data/spec/spec_tests/data/retryable_writes/{bulkWrite.yml → legacy/bulkWrite.yml} +0 -0
  452. data/spec/spec_tests/data/retryable_writes/{deleteMany.yml → legacy/deleteMany.yml} +0 -0
  453. data/spec/spec_tests/data/retryable_writes/{deleteOne-errorLabels.yml → legacy/deleteOne-errorLabels.yml} +0 -0
  454. data/spec/spec_tests/data/retryable_writes/{deleteOne-serverErrors.yml → legacy/deleteOne-serverErrors.yml} +1 -1
  455. data/spec/spec_tests/data/retryable_writes/{deleteOne.yml → legacy/deleteOne.yml} +0 -0
  456. data/spec/spec_tests/data/retryable_writes/{findOneAndDelete-errorLabels.yml → legacy/findOneAndDelete-errorLabels.yml} +0 -0
  457. data/spec/spec_tests/data/retryable_writes/{findOneAndDelete-serverErrors.yml → legacy/findOneAndDelete-serverErrors.yml} +1 -1
  458. data/spec/spec_tests/data/retryable_writes/{findOneAndDelete.yml → legacy/findOneAndDelete.yml} +0 -0
  459. data/spec/spec_tests/data/retryable_writes/{findOneAndReplace-errorLabels.yml → legacy/findOneAndReplace-errorLabels.yml} +0 -0
  460. data/spec/spec_tests/data/retryable_writes/{findOneAndReplace-serverErrors.yml → legacy/findOneAndReplace-serverErrors.yml} +1 -1
  461. data/spec/spec_tests/data/retryable_writes/{findOneAndReplace.yml → legacy/findOneAndReplace.yml} +0 -0
  462. data/spec/spec_tests/data/retryable_writes/{findOneAndUpdate-errorLabels.yml → legacy/findOneAndUpdate-errorLabels.yml} +0 -0
  463. data/spec/spec_tests/data/retryable_writes/{findOneAndUpdate-serverErrors.yml → legacy/findOneAndUpdate-serverErrors.yml} +1 -1
  464. data/spec/spec_tests/data/retryable_writes/{findOneAndUpdate.yml → legacy/findOneAndUpdate.yml} +0 -0
  465. data/spec/spec_tests/data/retryable_writes/{insertMany-errorLabels.yml → legacy/insertMany-errorLabels.yml} +0 -0
  466. data/spec/spec_tests/data/retryable_writes/{insertMany-serverErrors.yml → legacy/insertMany-serverErrors.yml} +1 -1
  467. data/spec/spec_tests/data/retryable_writes/{insertMany.yml → legacy/insertMany.yml} +0 -0
  468. data/spec/spec_tests/data/retryable_writes/{insertOne-errorLabels.yml → legacy/insertOne-errorLabels.yml} +0 -0
  469. data/spec/spec_tests/data/retryable_writes/{insertOne-serverErrors.yml → legacy/insertOne-serverErrors.yml} +5 -5
  470. data/spec/spec_tests/data/retryable_writes/{insertOne.yml → legacy/insertOne.yml} +0 -0
  471. data/spec/spec_tests/data/retryable_writes/{replaceOne-errorLabels.yml → legacy/replaceOne-errorLabels.yml} +0 -0
  472. data/spec/spec_tests/data/retryable_writes/{replaceOne-serverErrors.yml → legacy/replaceOne-serverErrors.yml} +1 -1
  473. data/spec/spec_tests/data/retryable_writes/{replaceOne.yml → legacy/replaceOne.yml} +0 -0
  474. data/spec/spec_tests/data/retryable_writes/{updateMany.yml → legacy/updateMany.yml} +0 -0
  475. data/spec/spec_tests/data/retryable_writes/{updateOne-errorLabels.yml → legacy/updateOne-errorLabels.yml} +0 -0
  476. data/spec/spec_tests/data/retryable_writes/{updateOne-serverErrors.yml → legacy/updateOne-serverErrors.yml} +1 -1
  477. data/spec/spec_tests/data/retryable_writes/{updateOne.yml → legacy/updateOne.yml} +0 -0
  478. data/spec/spec_tests/data/retryable_writes/unified/bulkWrite-serverErrors.yml +96 -0
  479. data/spec/spec_tests/data/retryable_writes/unified/handshakeError.yml +137 -0
  480. data/spec/spec_tests/data/retryable_writes/unified/insertOne-serverErrors.yml +78 -0
  481. data/spec/spec_tests/data/sdam/errors/prefer-error-code.yml +2 -2
  482. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-no-results.yml +5 -0
  483. data/spec/spec_tests/data/seed_list_discovery/load-balanced/srvMaxHosts-conflicts_with_loadBalanced-true-txt.yml +5 -0
  484. data/spec/spec_tests/data/seed_list_discovery/load-balanced/srvMaxHosts-conflicts_with_loadBalanced-true.yml +5 -0
  485. data/spec/spec_tests/data/seed_list_discovery/load-balanced/srvMaxHosts-zero-txt.yml +10 -0
  486. data/spec/spec_tests/data/seed_list_discovery/load-balanced/srvMaxHosts-zero.yml +10 -0
  487. data/spec/spec_tests/data/seed_list_discovery/replica-set/srv-service-name.yml +11 -0
  488. data/spec/spec_tests/data/seed_list_discovery/replica-set/srvMaxHosts-conflicts_with_replicaSet-txt.yml +5 -0
  489. data/spec/spec_tests/data/seed_list_discovery/replica-set/srvMaxHosts-conflicts_with_replicaSet.yml +5 -0
  490. data/spec/spec_tests/data/seed_list_discovery/replica-set/srvMaxHosts-equal_to_srv_records.yml +16 -0
  491. data/spec/spec_tests/data/seed_list_discovery/replica-set/srvMaxHosts-greater_than_srv_records.yml +15 -0
  492. data/spec/spec_tests/data/seed_list_discovery/replica-set/srvMaxHosts-less_than_srv_records.yml +15 -0
  493. data/spec/spec_tests/data/seed_list_discovery/replica-set/srvMaxHosts-zero-txt.yml +15 -0
  494. data/spec/spec_tests/data/seed_list_discovery/replica-set/srvMaxHosts-zero.yml +15 -0
  495. data/spec/spec_tests/data/seed_list_discovery/sharded/srvMaxHosts-equal_to_srv_records.yml +13 -0
  496. data/spec/spec_tests/data/seed_list_discovery/sharded/srvMaxHosts-greater_than_srv_records.yml +12 -0
  497. data/spec/spec_tests/data/seed_list_discovery/sharded/srvMaxHosts-less_than_srv_records.yml +10 -0
  498. data/spec/spec_tests/data/seed_list_discovery/sharded/srvMaxHosts-zero.yml +11 -0
  499. data/spec/spec_tests/data/server_selection/Unknown/read/ghost.yml +11 -0
  500. data/spec/spec_tests/data/server_selection/Unknown/write/ghost.yml +11 -0
  501. data/spec/spec_tests/data/sessions_unified/driver-sessions-server-support.yml +123 -0
  502. data/spec/spec_tests/data/sessions_unified/snapshot-sessions-not-supported-client-error.yml +9 -3
  503. data/spec/spec_tests/data/transactions/error-labels.yml +1 -1
  504. data/spec/spec_tests/data/transactions/errors-client.yml +8 -9
  505. data/spec/spec_tests/data/transactions/mongos-recovery-token.yml +1 -1
  506. data/spec/spec_tests/data/transactions/retryable-abort-errorLabels.yml +0 -2
  507. data/spec/spec_tests/data/transactions/retryable-abort.yml +7 -9
  508. data/spec/spec_tests/data/transactions/retryable-commit-errorLabels.yml +0 -2
  509. data/spec/spec_tests/data/transactions/retryable-commit.yml +7 -9
  510. data/spec/spec_tests/data/transactions/retryable-writes.yml +0 -2
  511. data/spec/spec_tests/data/unified/invalid/expectedEventsForClient-ignoreExtraEvents-type.yml +15 -0
  512. data/spec/spec_tests/data/unified/valid-fail/operation-unsupported.yml +13 -0
  513. data/spec/spec_tests/data/unified/valid-pass/expectedEventsForClient-ignoreExtraEvents.yml +78 -0
  514. data/spec/spec_tests/data/unified/valid-pass/poc-change-streams.yml +4 -1
  515. data/spec/spec_tests/data/unified/valid-pass/poc-command-monitoring.yml +3 -3
  516. data/spec/spec_tests/data/unified/valid-pass/poc-transactions.yml +3 -2
  517. data/spec/spec_tests/data/uri_options/srv-options.yml +96 -0
  518. data/spec/spec_tests/data/versioned_api/crud-api-version-1-strict.yml +6 -4
  519. data/spec/spec_tests/data/versioned_api/crud-api-version-1.yml +7 -5
  520. data/spec/spec_tests/retryable_reads_spec.rb +4 -1
  521. data/spec/spec_tests/retryable_reads_unified_spec.rb +22 -0
  522. data/spec/spec_tests/retryable_writes_spec.rb +4 -1
  523. data/spec/spec_tests/retryable_writes_unified_spec.rb +21 -0
  524. data/spec/spec_tests/seed_list_discovery_spec.rb +10 -1
  525. data/spec/spec_tests/unified_spec.rb +6 -1
  526. data/spec/stress/connection_pool_timing_spec.rb +2 -1
  527. data/spec/stress/fork_reconnect_stress_spec.rb +3 -2
  528. data/spec/support/authorization.rb +1 -1
  529. data/spec/support/certificates/atlas-ocsp-ca.crt +47 -40
  530. data/spec/support/certificates/atlas-ocsp.crt +106 -101
  531. data/spec/support/cluster_tools.rb +1 -1
  532. data/spec/support/common_shortcuts.rb +22 -0
  533. data/spec/support/crypt/corpus/corpus-encrypted.json +9515 -0
  534. data/spec/support/crypt/corpus/corpus-key-aws.json +32 -32
  535. data/spec/support/crypt/corpus/corpus-key-azure.json +33 -0
  536. data/spec/support/crypt/corpus/corpus-key-gcp.json +35 -0
  537. data/spec/support/crypt/corpus/corpus-key-kmip.json +32 -0
  538. data/spec/support/crypt/corpus/corpus-key-local.json +30 -30
  539. data/spec/support/crypt/corpus/corpus-schema.json +4399 -121
  540. data/spec/support/crypt/corpus/corpus.json +4999 -37
  541. data/spec/support/crypt/data_keys/key_document_azure.json +33 -0
  542. data/spec/support/crypt/data_keys/key_document_gcp.json +37 -0
  543. data/spec/support/crypt/data_keys/key_document_kmip.json +32 -0
  544. data/spec/support/crypt/encryptedFields.json +33 -0
  545. data/spec/support/crypt/keys/key1-document.json +30 -0
  546. data/spec/support/crypt/schema_maps/schema_map_azure.json +17 -0
  547. data/spec/support/crypt/schema_maps/schema_map_azure_key_alt_names.json +12 -0
  548. data/spec/support/crypt/schema_maps/schema_map_gcp.json +17 -0
  549. data/spec/support/crypt/schema_maps/schema_map_gcp_key_alt_names.json +12 -0
  550. data/spec/support/crypt/schema_maps/schema_map_kmip.json +17 -0
  551. data/spec/support/crypt/schema_maps/schema_map_kmip_key_alt_names.json +12 -0
  552. data/spec/support/crypt.rb +207 -6
  553. data/spec/support/macros.rb +18 -0
  554. data/spec/support/mongos_macros.rb +17 -0
  555. data/spec/support/shared/scram_conversation.rb +2 -1
  556. data/spec/support/shared/session.rb +13 -7
  557. data/spec/support/spec_config.rb +82 -1
  558. data/spec/support/utils.rb +25 -4
  559. data.tar.gz.sig +0 -0
  560. metadata +1468 -1214
  561. metadata.gz.sig +0 -0
  562. data/lib/mongo/operation/delete/legacy.rb +0 -64
  563. data/lib/mongo/operation/insert/legacy.rb +0 -68
  564. data/lib/mongo/operation/update/legacy/result.rb +0 -112
  565. data/lib/mongo/operation/update/legacy.rb +0 -76
  566. data/spec/mongo/dbref_spec.rb +0 -152
  567. data/spec/mongo/operation/kill_cursors_spec.rb +0 -47
  568. data/spec/spec_tests/change_streams_spec.rb +0 -93
  569. data/spec/spec_tests/data/change_streams/change-streams-errors.yml +0 -101
  570. data/spec/spec_tests/data/change_streams/change-streams-resume-allowlist.yml +0 -1173
  571. data/spec/spec_tests/data/change_streams/change-streams-resume-errorLabels.yml +0 -1105
  572. data/spec/spec_tests/data/change_streams/change-streams.yml +0 -535
  573. data/spec/spec_tests/data/crud_v2/aggregate-merge.yml +0 -103
  574. data/spec/spec_tests/data/crud_v2/aggregate-out-readConcern.yml +0 -111
  575. data/spec/spec_tests/data/crud_v2/bulkWrite-arrayFilters.yml +0 -103
  576. data/spec/spec_tests/data/crud_v2/bulkWrite-delete-hint-clientError.yml +0 -63
  577. data/spec/spec_tests/data/crud_v2/bulkWrite-delete-hint-serverError.yml +0 -92
  578. data/spec/spec_tests/data/crud_v2/bulkWrite-delete-hint.yml +0 -103
  579. data/spec/spec_tests/data/crud_v2/bulkWrite-update-hint-clientError.yml +0 -90
  580. data/spec/spec_tests/data/crud_v2/bulkWrite-update-hint-serverError.yml +0 -147
  581. data/spec/spec_tests/data/crud_v2/bulkWrite-update-hint.yml +0 -164
  582. data/spec/spec_tests/data/crud_v2/db-aggregate.yml +0 -39
  583. data/spec/spec_tests/data/crud_v2/deleteMany-hint-clientError.yml +0 -43
  584. data/spec/spec_tests/data/crud_v2/deleteMany-hint-serverError.yml +0 -62
  585. data/spec/spec_tests/data/crud_v2/deleteMany-hint.yml +0 -58
  586. data/spec/spec_tests/data/crud_v2/deleteOne-hint-clientError.yml +0 -41
  587. data/spec/spec_tests/data/crud_v2/deleteOne-hint-serverError.yml +0 -60
  588. data/spec/spec_tests/data/crud_v2/deleteOne-hint.yml +0 -57
  589. data/spec/spec_tests/data/crud_v2/find-allowdiskuse-clientError.yml +0 -28
  590. data/spec/spec_tests/data/crud_v2/find-allowdiskuse-serverError.yml +0 -44
  591. data/spec/spec_tests/data/crud_v2/find-allowdiskuse.yml +0 -50
  592. data/spec/spec_tests/data/crud_v2/findOneAndDelete-hint-clientError.yml +0 -45
  593. data/spec/spec_tests/data/crud_v2/findOneAndDelete-hint-serverError.yml +0 -60
  594. data/spec/spec_tests/data/crud_v2/findOneAndDelete-hint.yml +0 -56
  595. data/spec/spec_tests/data/crud_v2/findOneAndReplace-hint-clientError.yml +0 -40
  596. data/spec/spec_tests/data/crud_v2/findOneAndReplace-hint-serverError.yml +0 -59
  597. data/spec/spec_tests/data/crud_v2/findOneAndReplace-hint.yml +0 -55
  598. data/spec/spec_tests/data/crud_v2/findOneAndUpdate-hint-clientError.yml +0 -40
  599. data/spec/spec_tests/data/crud_v2/findOneAndUpdate-hint-serverError.yml +0 -58
  600. data/spec/spec_tests/data/crud_v2/findOneAndUpdate-hint.yml +0 -55
  601. data/spec/spec_tests/data/crud_v2/replaceOne-hint.yml +0 -61
  602. data/spec/spec_tests/data/crud_v2/unacknowledged-bulkWrite-delete-hint-clientError.yml +0 -60
  603. data/spec/spec_tests/data/crud_v2/unacknowledged-bulkWrite-update-hint-clientError.yml +0 -88
  604. data/spec/spec_tests/data/crud_v2/unacknowledged-deleteMany-hint-clientError.yml +0 -40
  605. data/spec/spec_tests/data/crud_v2/unacknowledged-deleteOne-hint-clientError.yml +0 -38
  606. data/spec/spec_tests/data/crud_v2/unacknowledged-findOneAndDelete-hint-clientError.yml +0 -42
  607. data/spec/spec_tests/data/crud_v2/unacknowledged-findOneAndReplace-hint-clientError.yml +0 -40
  608. data/spec/spec_tests/data/crud_v2/unacknowledged-findOneAndUpdate-hint-clientError.yml +0 -40
  609. data/spec/spec_tests/data/crud_v2/unacknowledged-replaceOne-hint-clientError.yml +0 -40
  610. data/spec/spec_tests/data/crud_v2/unacknowledged-updateMany-hint-clientError.yml +0 -43
  611. data/spec/spec_tests/data/crud_v2/unacknowledged-updateOne-hint-clientError.yml +0 -40
  612. data/spec/spec_tests/data/crud_v2/updateMany-hint-clientError.yml +0 -45
  613. data/spec/spec_tests/data/crud_v2/updateMany-hint-serverError.yml +0 -66
  614. data/spec/spec_tests/data/crud_v2/updateMany-hint.yml +0 -65
  615. data/spec/spec_tests/data/crud_v2/updateOne-hint-clientError.yml +0 -43
  616. data/spec/spec_tests/data/crud_v2/updateOne-hint-serverError.yml +0 -62
  617. data/spec/spec_tests/data/crud_v2/updateOne-hint.yml +0 -61
  618. data/spec/spec_tests/data/crud_v2/updateWithPipelines.yml +0 -157
  619. data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-4.9.yml +0 -60
  620. data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-serverErrors-4.9.yml +0 -146
  621. data/spec/support/crypt/corpus/corpus_encrypted.json +0 -4152
  622. data/spec/support/session_registry.rb +0 -55
@@ -18,7 +18,6 @@
18
18
  require 'mongo/operation/kill_cursors/command_builder'
19
19
  require 'mongo/operation/kill_cursors/command'
20
20
  require 'mongo/operation/kill_cursors/op_msg'
21
- require 'mongo/operation/kill_cursors/legacy'
22
21
 
23
22
  module Mongo
24
23
  module Operation
@@ -31,7 +31,10 @@ module Mongo
31
31
  private
32
32
 
33
33
  def selector(connection)
34
- (spec[SELECTOR] || {}).merge(listCollections: 1)
34
+ (spec[SELECTOR] || {}).merge({
35
+ listCollections: 1,
36
+ comment: spec[:comment]
37
+ }).compact
35
38
  end
36
39
  end
37
40
  end
@@ -131,6 +131,22 @@ module Mongo
131
131
  0
132
132
  end
133
133
 
134
+ # Get the number of documents returned by the server in this batch.
135
+ #
136
+ # Map/Reduce operation returns documents inline without using
137
+ # cursors; as such, the standard Mongo::Reply#returned_count does
138
+ # not work correctly for Map/Reduce.
139
+ #
140
+ # Note that the Map/Reduce operation is limited to max BSON document
141
+ # size (16 MB) in its inline result set.
142
+ #
143
+ # @return [ Integer ] The number of documents returned.
144
+ #
145
+ # @api public
146
+ def returned_count
147
+ reply.documents.length
148
+ end
149
+
134
150
  private
135
151
 
136
152
  def first_document
@@ -97,9 +97,12 @@ module Mongo
97
97
  # this result is for. This parameter is allowed to be nil for
98
98
  # compatibility with existing mongo_kerberos library, but should
99
99
  # always be not nil in the driver proper.
100
+ # @param [ Integer ] connection_global_id
101
+ # Global id of the connection on which the operation that
102
+ # this result is for was performed.
100
103
  #
101
104
  # @api private
102
- def initialize(replies, connection_description = nil)
105
+ def initialize(replies, connection_description = nil, connection_global_id = nil)
103
106
  if replies
104
107
  if replies.is_a?(Array)
105
108
  if replies.length != 1
@@ -114,6 +117,7 @@ module Mongo
114
117
  end
115
118
  @replies = [ reply ]
116
119
  @connection_description = connection_description
120
+ @connection_global_id = connection_global_id
117
121
  end
118
122
  end
119
123
 
@@ -128,6 +132,12 @@ module Mongo
128
132
  # @api private
129
133
  attr_reader :connection_description
130
134
 
135
+ # @return [ Object ] Global is of the connection that
136
+ # the operation was performed on that this result is for.
137
+ #
138
+ # @api private
139
+ attr_reader :connection_global_id
140
+
131
141
  # @api private
132
142
  def_delegators :parser,
133
143
  :not_master?, :node_recovering?, :node_shutting_down?
@@ -148,6 +158,15 @@ module Mongo
148
158
  !!@replies
149
159
  end
150
160
 
161
+ # Whether the result contains cursor_id
162
+ #
163
+ # @return [ true, false ] If the result contains cursor_id.
164
+ #
165
+ # @api private
166
+ def has_cursor_id?
167
+ acknowledged? && replies.last.respond_to?(:cursor_id)
168
+ end
169
+
151
170
  # Get the cursor id if the response is acknowledged.
152
171
  #
153
172
  # @note Cursor ids of 0 indicate there is no cursor on the server.
@@ -238,10 +257,7 @@ module Mongo
238
257
  end
239
258
  end
240
259
 
241
- # Get the count of documents returned by the server.
242
- #
243
- # @example Get the number returned.
244
- # result.returned_count
260
+ # Get the number of documents returned by the server in this batch.
245
261
  #
246
262
  # @return [ Integer ] The number of documents returned.
247
263
  #
@@ -27,7 +27,8 @@ module Mongo
27
27
  include ResponseHandling
28
28
 
29
29
  def do_execute(connection, context, options = {})
30
- unpin_maybe(session) do
30
+ session&.materialize_if_needed
31
+ unpin_maybe(session, connection) do
31
32
  add_error_labels(connection, context) do
32
33
  add_server_diagnostics(connection) do
33
34
  get_result(connection, context, options).tap do |result|
@@ -35,12 +36,16 @@ module Mongo
35
36
  if session.in_transaction? &&
36
37
  connection.description.load_balancer?
37
38
  then
38
- if session.pinned_service_id
39
- unless session.pinned_service_id == connection.service_id
40
- raise Error::InternalDriverError, "Expected operation to use service #{session.pinned_session_id} but it used #{connection.service_id}"
39
+ if session.pinned_connection_global_id
40
+ unless session.pinned_connection_global_id == connection.global_id
41
+ raise(
42
+ Error::InternalDriverError,
43
+ "Expected operation to use connection #{session.pinned_connection_global_id} but it used #{connection.global_id}"
44
+ )
41
45
  end
42
46
  else
43
- session.pin_to_service(connection.service_id)
47
+ session.pin_to_connection(connection.global_id)
48
+ connection.pin
44
49
  end
45
50
  end
46
51
 
@@ -48,6 +53,16 @@ module Mongo
48
53
  session.snapshot_timestamp = result.snapshot_timestamp
49
54
  end
50
55
  end
56
+
57
+ if result.has_cursor_id? &&
58
+ connection.description.load_balancer?
59
+ then
60
+ if result.cursor_id == 0
61
+ connection.unpin
62
+ else
63
+ connection.pin
64
+ end
65
+ end
51
66
  process_result(result, connection)
52
67
  end
53
68
  end
@@ -82,7 +97,7 @@ module Mongo
82
97
  message = build_message(connection, context)
83
98
  message = message.maybe_encrypt(connection, context)
84
99
  reply = connection.dispatch([ message ], context, options)
85
- [reply, connection.description]
100
+ [reply, connection.description, connection.global_id]
86
101
  end
87
102
 
88
103
  # @param [ Mongo::Server::Connection ] connection The connection on which
@@ -32,11 +32,23 @@ module Mongo
32
32
  #
33
33
  # @return [ Mongo::Operation::Result ] The operation result.
34
34
  def execute(server, context:, options: {})
35
- server.with_connection(service_id: context.service_id) do |connection|
36
- operation = final_operation(connection)
37
- operation.execute(connection, context: context, options: options)
35
+ server.with_connection(connection_global_id: context.connection_global_id) do |connection|
36
+ execute_with_connection(connection, context: context, options: options)
38
37
  end
39
38
  end
39
+
40
+ # Execute the operation.
41
+ #
42
+ # @param [ Mongo::Server::Connection ] connection The connection to send
43
+ # the operation through.
44
+ # @param [ Operation::Context ] context The operation context.
45
+ # @param [ Hash ] options Operation execution options.
46
+ #
47
+ # @return [ Mongo::Operation::Result ] The operation result.
48
+ def execute_with_connection(connection, context:, options: {})
49
+ operation = final_operation(connection)
50
+ operation.execute(connection, context: context, options: options)
51
+ end
40
52
  end
41
53
  end
42
54
  end
@@ -30,7 +30,7 @@ module Mongo
30
30
  # the operation is performed.
31
31
  # @param [ Mongo::Operation::Context ] context The operation context.
32
32
  def validate_result(result, connection, context)
33
- unpin_maybe(context.session) do
33
+ unpin_maybe(context.session, connection) do
34
34
  add_error_labels(connection, context) do
35
35
  add_server_diagnostics(connection) do
36
36
  result.validate!
@@ -81,19 +81,20 @@ module Mongo
81
81
  end
82
82
  end
83
83
 
84
- # Unpins the session if the session is pinned and the yielded to block
85
- # raises errors that are required to unpin the session.
84
+ # Unpins the session and/or the connection if the yielded to block
85
+ # raises errors that are required to unpin the session and the connection.
86
86
  #
87
87
  # @note This method takes the session as an argument because this module
88
88
  # is included in BulkWrite which does not store the session in the
89
89
  # receiver (despite Specifiable doing so).
90
90
  #
91
91
  # @param [ Session | nil ] session Session to consider.
92
- def unpin_maybe(session)
92
+ # @param [ Connection | nil ] connection Connection to unpin.
93
+ def unpin_maybe(session, connection)
93
94
  yield
94
95
  rescue Mongo::Error => e
95
96
  if session
96
- session.unpin_maybe(e)
97
+ session.unpin_maybe(e, connection)
97
98
  end
98
99
  raise
99
100
  end
@@ -257,14 +257,10 @@ module Mongo
257
257
  super.tap do |message|
258
258
  if session = context.session
259
259
  # Serialize the message to detect client-side problems,
260
- # such as invalid BSON keys or too large messages.
261
- # The message will be serialized again
260
+ # such as invalid BSON keys. The message will be serialized again
262
261
  # later prior to being sent to the connection.
263
- buf = BSON::ByteBuffer.new
264
- message.serialize(buf)
265
- if buf.length > connection.max_message_size
266
- raise Error::MaxMessageSize.new(connection.max_message_size)
267
- end
262
+ message.serialize(BSON::ByteBuffer.new)
263
+
268
264
  session.update_state!
269
265
  end
270
266
  end
@@ -35,21 +35,27 @@ module Mongo
35
35
  #
36
36
  # @since 2.5.2
37
37
  def execute(server, context:)
38
- server.with_connection(service_id: context.service_id) do |connection|
39
- validate!(connection)
40
- op = if connection.features.op_msg_enabled?
41
- self.class::OpMsg.new(spec)
42
- elsif !acknowledged_write?
43
- self.class::Legacy.new(spec)
44
- else
45
- self.class::Command.new(spec)
46
- end
47
-
48
- result = op.execute(connection, context: context)
49
- validate_result(result, connection, context)
38
+ server.with_connection(connection_global_id: context.connection_global_id) do |connection|
39
+ execute_with_connection(connection, context: context)
50
40
  end
51
41
  end
52
42
 
43
+ # Execute the operation.
44
+ #
45
+ # @param [ Mongo::Server::Connection ] connection The connection to send
46
+ # the operation through.
47
+ # @param [ Operation::Context ] context The operation context.
48
+ # @param [ Hash ] options Operation execution options.
49
+ #
50
+ # @return [ Mongo::Operation::Result ] The operation result.
51
+ def execute_with_connection(connection, context:)
52
+ validate!(connection)
53
+ op = self.class::OpMsg.new(spec)
54
+
55
+ result = op.execute(connection, context: context)
56
+ validate_result(result, connection, context)
57
+ end
58
+
53
59
  # Execute the bulk write operation.
54
60
  #
55
61
  # @param [ Mongo::Server::Connection ] connection The connection over
@@ -37,7 +37,8 @@ module Mongo
37
37
  {
38
38
  update: coll_name,
39
39
  ordered: ordered?,
40
- let: spec[:let]
40
+ let: spec[:let],
41
+ comment: spec[:comment]
41
42
  }.compact
42
43
  end
43
44
 
@@ -17,7 +17,6 @@
17
17
 
18
18
  require 'mongo/operation/update/command'
19
19
  require 'mongo/operation/update/op_msg'
20
- require 'mongo/operation/update/legacy'
21
20
  require 'mongo/operation/update/result'
22
21
  require 'mongo/operation/update/bulk_result'
23
22
 
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ # Copyright (C) 2014-2022 MongoDB Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Mongo
19
+ module Protocol
20
+
21
+ # A Hash that caches the results of #to_bson.
22
+ #
23
+ # @api private
24
+ class CachingHash
25
+
26
+ def initialize(hash)
27
+ @hash = hash
28
+ end
29
+
30
+ def bson_type
31
+ Hash::BSON_TYPE
32
+ end
33
+
34
+ # Caches the result of to_bson and writes it to the given buffer on subsequent
35
+ # calls to this method. If this method is originally called without validation,
36
+ # and then is subsequently called with validation, we will want to recalculate
37
+ # the to_bson to trigger the validations.
38
+ #
39
+ # @param [ BSON::ByteBuffer ] buffer The encoded BSON buffer to append to.
40
+ # @param [ true, false ] validating_keys Whether keys should be validated when serializing.
41
+ #
42
+ # @return [ BSON::ByteBuffer ] The buffer with the encoded object.
43
+ def to_bson(buffer = BSON::ByteBuffer.new, validating_keys = BSON::Config.validating_keys?)
44
+ if !@bytes
45
+ @bytes = @hash.to_bson(BSON::ByteBuffer.new, validating_keys).to_s
46
+ elsif needs_validation?(validating_keys)
47
+ @validated = true
48
+ return @hash.to_bson(buffer, validating_keys)
49
+ end
50
+ @validated ||= validating_keys
51
+ buffer.put_bytes(@bytes)
52
+ end
53
+
54
+ private
55
+
56
+ # Checks the current value for validating keys, and whether or not this
57
+ # bson has been validated in the past, and decides if we need to recalculate
58
+ # the to_bson to check the validations.
59
+ #
60
+ # @param [ true, false ] validating_keys Whether keys should be validated when serializing.
61
+ #
62
+ # @return [ true, false ] Whether or not the bson needs to be recalculated
63
+ # with validation.
64
+ def needs_validation?(validating_keys)
65
+ !@validated && validating_keys
66
+ end
67
+ end
68
+ end
69
+ end
@@ -87,7 +87,9 @@ module Mongo
87
87
  ] + @sequences.map do |section|
88
88
  {type: 1, payload: {
89
89
  identifier: section.identifier,
90
- sequence: section.documents,
90
+ sequence: section.documents.map do |doc|
91
+ CachingHash.new(doc)
92
+ end,
91
93
  }}
92
94
  end
93
95
  @request_id = nil
@@ -227,6 +229,22 @@ module Mongo
227
229
  if cmd.key?('$db') && !enc_cmd.key?('$db')
228
230
  enc_cmd['$db'] = cmd['$db']
229
231
  end
232
+ # This code MUST be removed as soon as server starts accepting
233
+ # contention as int32.
234
+ if schema = enc_cmd.dig('encryptionInformation', 'schema')
235
+ enc_cmd['encryptionInformation']['schema'] = schema.map do |coll, params|
236
+ if params['fields']
237
+ params['fields'] = params['fields'].map do |field|
238
+ if contention = field.dig('queries', 'contention')
239
+ field['queries']['contention'] = BSON::Int64.new(contention)
240
+ end
241
+ field
242
+ end
243
+ end
244
+ [coll, params]
245
+ end.to_h
246
+ end
247
+ # End of code to be removed
230
248
 
231
249
  Msg.new(@flags, @options, enc_cmd)
232
250
  else
@@ -298,6 +316,24 @@ module Mongo
298
316
  Msg.new(@flags, @options, main_document, *@sequences)
299
317
  end
300
318
 
319
+ # Returns the number of documents returned from the server.
320
+ #
321
+ # The Msg instance must be for a server reply and the reply must return
322
+ # an active cursor (either a newly created one or one whose iteration is
323
+ # continuing via getMore).
324
+ #
325
+ # @return [ Integer ] Number of returned documents.
326
+ def number_returned
327
+ if doc = documents.first
328
+ if cursor = doc['cursor']
329
+ if batch = cursor['firstBatch'] || cursor['nextBatch']
330
+ return batch.length
331
+ end
332
+ end
333
+ end
334
+ raise NotImplementedError, "number_returned is only defined for cursor replies"
335
+ end
336
+
301
337
  private
302
338
 
303
339
  # Validate that the documents in this message are all smaller than the
@@ -6,6 +6,7 @@ require 'mongo/protocol/serializers'
6
6
  require 'mongo/protocol/registry'
7
7
  require 'mongo/protocol/bit_vector'
8
8
  require 'mongo/protocol/message'
9
+ require 'mongo/protocol/caching_hash'
9
10
 
10
11
  # Client Requests
11
12
  require 'mongo/protocol/compressed'
@@ -280,6 +280,21 @@ module Mongo
280
280
  ensure
281
281
  QueryCache.clear
282
282
  end
283
+
284
+ # ActiveJob middleware that activates the query cache for each job.
285
+ module ActiveJob
286
+ def self.included(base)
287
+ base.class_eval do
288
+ around_perform do |_job, block|
289
+ QueryCache.cache do
290
+ block.call
291
+ end
292
+ ensure
293
+ QueryCache.clear
294
+ end
295
+ end
296
+ end
297
+ end
283
298
  end
284
299
  end
285
300
  end
@@ -191,25 +191,29 @@ module Mongo
191
191
  # @note This only retries operations on not master failures, since it is
192
192
  # the only case we can be sure a partial write did not already occur.
193
193
  #
194
- # @param [ nil | Session ] session Optional session to use with the operation.
195
194
  # @param [ nil | Hash | WriteConcern::Base ] write_concern The write concern.
196
- # @param [ true | false ] ending_transaction True if the write operation is abortTransaction or
197
- # commitTransaction, false otherwise.
195
+ # @param [ true | false ] ending_transaction True if the write operation is
196
+ # abortTransaction or commitTransaction, false otherwise.
197
+ # @param [ Context ] context The context for the operation.
198
198
  # @param [ Proc ] block The block to execute.
199
199
  #
200
- # @yieldparam [ Server ] server The server to which the write should be sent.
200
+ # @yieldparam [ Connection ] connection The connection through which the
201
+ # write should be sent.
201
202
  # @yieldparam [ Integer ] txn_num Transaction number (NOT the ACID kind).
203
+ # @yieldparam [ Operation::Context ] context The operation context.
202
204
  #
203
205
  # @return [ Result ] The result of the operation.
204
206
  #
205
207
  # @since 2.1.0
206
- def write_with_retry(session, write_concern, ending_transaction = false, &block)
208
+ def write_with_retry(write_concern, ending_transaction: false, context:, &block)
209
+ session = context.session
210
+
207
211
  if ending_transaction && !session
208
212
  raise ArgumentError, 'Cannot end a transaction without a session'
209
213
  end
210
214
 
211
215
  unless ending_transaction || retry_write_allowed?(session, write_concern)
212
- return legacy_write_with_retry(nil, session, &block)
216
+ return legacy_write_with_retry(nil, context: context, &block)
213
217
  end
214
218
 
215
219
  # If we are here, session is not nil. A session being nil would have
@@ -218,23 +222,46 @@ module Mongo
218
222
  server = select_server(cluster, ServerSelector.primary, session)
219
223
 
220
224
  unless ending_transaction || server.retry_writes?
221
- return legacy_write_with_retry(server, session, &block)
225
+ return legacy_write_with_retry(server, context: context, &block)
222
226
  end
223
227
 
224
- txn_num = if session.in_transaction?
225
- session.txn_num
226
- else
227
- session.next_txn_num
228
- end
228
+ txn_num = nil
229
+
229
230
  begin
230
- yield(server, txn_num, false)
231
- rescue Error::SocketError, Error::SocketTimeoutError => e
231
+ connection_succeeded = false
232
+ server.with_connection(connection_global_id: context.connection_global_id) do |connection|
233
+ connection_succeeded = true
234
+
235
+ session.materialize_if_needed
236
+ txn_num = if session.in_transaction?
237
+ session.txn_num
238
+ else
239
+ session.next_txn_num
240
+ end
241
+
242
+ # The context needs to be duplicated here because we will be using
243
+ # it later for the retry as well.
244
+ yield(connection, txn_num, context.dup)
245
+ end
246
+ rescue Error::SocketError, Error::SocketTimeoutError, Auth::Unauthorized => e
232
247
  e.add_note('modern retry')
233
248
  e.add_note("attempt 1")
234
249
  if !e.label?('RetryableWriteError')
235
- raise e
250
+ # If we get an auth error, it was raised when connecting the connection
251
+ # and therefore we didn't have the connection yet to add labels.
252
+ # Therefore, check if it is retryable, and if it is, add the label
253
+ # and retry it. We also want to retry this if there was a Socket error
254
+ # when trying to create the connection.
255
+ if !connection_succeeded && !session.in_transaction? && e.write_retryable?
256
+ e.add_label('RetryableWriteError')
257
+ else
258
+ raise e
259
+ end
236
260
  end
237
- retry_write(e, session, txn_num, &block)
261
+
262
+ # Context#with creates a new context, which is not necessary here
263
+ # but the API is less prone to misuse this way.
264
+ retry_write(e, txn_num, context: context.with(is_retry: true), &block)
238
265
  rescue Error::OperationFailure => e
239
266
  e.add_note('modern retry')
240
267
  e.add_note("attempt 1")
@@ -244,7 +271,9 @@ module Mongo
244
271
  raise e
245
272
  end
246
273
 
247
- retry_write(e, session, txn_num, &block)
274
+ # Context#with creates a new context, which is not necessary here
275
+ # but the API is less prone to misuse this way.
276
+ retry_write(e, txn_num, context: context.with(is_retry: true), &block)
248
277
  end
249
278
  end
250
279
 
@@ -258,23 +287,30 @@ module Mongo
258
287
  # delegates to legacy_write_with_retry which performs write retries using
259
288
  # legacy logic.
260
289
  #
261
- # @param [ nil | Session ] session Optional session to use with the operation.
262
290
  # @param [ nil | Hash | WriteConcern::Base ] write_concern The write concern.
291
+ # @param [ Context ] context The context for the operation.
263
292
  #
264
- # @yieldparam [ Server ] server The server to which the write should be sent.
293
+ # @yieldparam [ Connection ] connection The connection through which the
294
+ # write should be sent.
295
+ # @yieldparam [ nil ] txn_num nil as transaction number.
296
+ # @yieldparam [ Operation::Context ] context The operation context.
265
297
  #
266
298
  # @api private
267
- def nro_write_with_retry(session, write_concern, &block)
299
+ def nro_write_with_retry(write_concern, context:, &block)
300
+ session = context.session
301
+
302
+ server = select_server(cluster, ServerSelector.primary, session)
268
303
  if session && session.client.options[:retry_writes]
269
- server = select_server(cluster, ServerSelector.primary, session)
270
304
  begin
271
- yield server
305
+ server.with_connection(connection_global_id: context.connection_global_id) do |connection|
306
+ yield connection, nil, context
307
+ end
272
308
  rescue Error::SocketError, Error::SocketTimeoutError, Error::OperationFailure => e
273
309
  e.add_note('retries disabled')
274
310
  raise e
275
311
  end
276
312
  else
277
- legacy_write_with_retry(nil, session, &block)
313
+ legacy_write_with_retry(server, context: context, &block)
278
314
  end
279
315
  end
280
316
 
@@ -287,12 +323,17 @@ module Mongo
287
323
  # @param [ Server ] server The server which should be used for the
288
324
  # operation. If not provided, the current primary will be retrieved from
289
325
  # the cluster.
290
- # @param [ nil | Session ] session Optional session to use with the operation.
326
+ # @param [ Context ] context The context for the operation.
291
327
  #
292
- # @yieldparam [ Server ] server The server to which the write should be sent.
328
+ # @yieldparam [ Connection ] connection The connection through which the
329
+ # write should be sent.
330
+ # @yieldparam [ nil ] txn_num nil as transaction number.
331
+ # @yieldparam [ Operation::Context ] context The operation context.
293
332
  #
294
333
  # @api private
295
- def legacy_write_with_retry(server = nil, session = nil)
334
+ def legacy_write_with_retry(server = nil, context:)
335
+ session = context.session
336
+
296
337
  # This is the pre-session retry logic, and is not subject to
297
338
  # current retryable write specifications.
298
339
  # In particular it does not retry on SocketError and SocketTimeoutError.
@@ -300,7 +341,10 @@ module Mongo
300
341
  begin
301
342
  attempt += 1
302
343
  server ||= select_server(cluster, ServerSelector.primary, session)
303
- yield server
344
+ server.with_connection(connection_global_id: context.connection_global_id) do |connection|
345
+ # Legacy retries do not use txn_num
346
+ yield connection, nil, context.dup
347
+ end
304
348
  rescue Error::OperationFailure => e
305
349
  e.add_note('legacy retry')
306
350
  e.add_note("attempt #{attempt}")
@@ -331,7 +375,7 @@ module Mongo
331
375
  raise e
332
376
  end
333
377
  retry_read(e, server_selector, session, &block)
334
- rescue Error::OperationFailure => e
378
+ rescue Error::OperationFailure, Auth::Unauthorized => e
335
379
  e.add_note('modern retry')
336
380
  e.add_note("attempt 1")
337
381
  if session.in_transaction? || !e.write_retryable?
@@ -423,7 +467,9 @@ module Mongo
423
467
  raise original_error
424
468
  end
425
469
 
426
- def retry_write(original_error, session, txn_num, &block)
470
+ def retry_write(original_error, txn_num, context:, &block)
471
+ session = context.session
472
+
427
473
  # We do not request a scan of the cluster here, because error handling
428
474
  # for the error which triggered the retry should have updated the
429
475
  # server description and/or topology as necessary (specifically,
@@ -444,7 +490,9 @@ module Mongo
444
490
  raise Error::RaiseOriginalError
445
491
  end
446
492
  log_retry(original_error, message: 'Write retry')
447
- yield(server, txn_num, true)
493
+ server.with_connection(connection_global_id: context.connection_global_id) do |connection|
494
+ yield(connection, txn_num, context)
495
+ end
448
496
  rescue Error::SocketError, Error::SocketTimeoutError => e
449
497
  e.add_note('modern retry')
450
498
  e.add_note('attempt 2')