mongo 2.23.0 → 2.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (463) hide show
  1. checksums.yaml +4 -4
  2. data/bin/mongo_console +0 -1
  3. data/lib/mongo/active_support.rb +1 -2
  4. data/lib/mongo/address/ipv4.rb +3 -6
  5. data/lib/mongo/address/ipv6.rb +6 -10
  6. data/lib/mongo/address/unix.rb +1 -4
  7. data/lib/mongo/address/validator.rb +16 -28
  8. data/lib/mongo/address.rb +30 -40
  9. data/lib/mongo/auth/aws/conversation.rb +6 -10
  10. data/lib/mongo/auth/aws/credentials.rb +0 -1
  11. data/lib/mongo/auth/aws/credentials_cache.rb +0 -1
  12. data/lib/mongo/auth/aws/credentials_retriever.rb +45 -59
  13. data/lib/mongo/auth/aws/request.rb +20 -35
  14. data/lib/mongo/auth/aws.rb +1 -2
  15. data/lib/mongo/auth/base.rb +20 -29
  16. data/lib/mongo/auth/conversation_base.rb +14 -18
  17. data/lib/mongo/auth/cr/conversation.rb +0 -3
  18. data/lib/mongo/auth/cr.rb +1 -4
  19. data/lib/mongo/auth/credential_cache.rb +0 -2
  20. data/lib/mongo/auth/gssapi/conversation.rb +3 -8
  21. data/lib/mongo/auth/gssapi.rb +1 -4
  22. data/lib/mongo/auth/ldap/conversation.rb +0 -3
  23. data/lib/mongo/auth/ldap.rb +1 -4
  24. data/lib/mongo/auth/roles.rb +16 -19
  25. data/lib/mongo/auth/sasl_conversation_base.rb +7 -11
  26. data/lib/mongo/auth/scram/conversation.rb +2 -5
  27. data/lib/mongo/auth/scram.rb +5 -10
  28. data/lib/mongo/auth/scram256/conversation.rb +2 -5
  29. data/lib/mongo/auth/scram256.rb +1 -3
  30. data/lib/mongo/auth/scram_conversation_base.rb +18 -24
  31. data/lib/mongo/auth/stringprep/profiles/sasl.rb +17 -18
  32. data/lib/mongo/auth/stringprep/tables.rb +2209 -2210
  33. data/lib/mongo/auth/stringprep/unicode_normalize/normalize.rb +36 -38
  34. data/lib/mongo/auth/stringprep/unicode_normalize/tables.rb +1142 -1150
  35. data/lib/mongo/auth/stringprep.rb +9 -12
  36. data/lib/mongo/auth/user/view.rb +3 -5
  37. data/lib/mongo/auth/user.rb +14 -24
  38. data/lib/mongo/auth/x509/conversation.rb +0 -3
  39. data/lib/mongo/auth/x509.rb +7 -9
  40. data/lib/mongo/auth.rb +18 -30
  41. data/lib/mongo/background_thread.rb +9 -17
  42. data/lib/mongo/bson.rb +0 -2
  43. data/lib/mongo/bulk_write/combineable.rb +0 -3
  44. data/lib/mongo/bulk_write/ordered_combiner.rb +1 -3
  45. data/lib/mongo/bulk_write/result.rb +11 -16
  46. data/lib/mongo/bulk_write/result_combiner.rb +9 -12
  47. data/lib/mongo/bulk_write/transformable.rb +16 -19
  48. data/lib/mongo/bulk_write/unordered_combiner.rb +1 -3
  49. data/lib/mongo/bulk_write/validatable.rb +11 -18
  50. data/lib/mongo/bulk_write.rb +76 -91
  51. data/lib/mongo/caching_cursor.rb +2 -7
  52. data/lib/mongo/client.rb +230 -275
  53. data/lib/mongo/client_encryption.rb +4 -5
  54. data/lib/mongo/cluster/periodic_executor.rb +2 -5
  55. data/lib/mongo/cluster/reapers/cursor_reaper.rb +21 -29
  56. data/lib/mongo/cluster/reapers/socket_reaper.rb +1 -6
  57. data/lib/mongo/cluster/sdam_flow.rb +136 -159
  58. data/lib/mongo/cluster/topology/base.rb +15 -18
  59. data/lib/mongo/cluster/topology/load_balanced.rb +24 -14
  60. data/lib/mongo/cluster/topology/no_replica_set_options.rb +3 -6
  61. data/lib/mongo/cluster/topology/replica_set_no_primary.rb +20 -23
  62. data/lib/mongo/cluster/topology/replica_set_with_primary.rb +0 -2
  63. data/lib/mongo/cluster/topology/sharded.rb +19 -9
  64. data/lib/mongo/cluster/topology/single.rb +24 -14
  65. data/lib/mongo/cluster/topology/unknown.rb +20 -10
  66. data/lib/mongo/cluster/topology.rb +29 -25
  67. data/lib/mongo/cluster.rb +148 -183
  68. data/lib/mongo/cluster_time.rb +14 -31
  69. data/lib/mongo/collection/helpers.rb +5 -8
  70. data/lib/mongo/collection/view/aggregation.rb +5 -10
  71. data/lib/mongo/collection/view/builder/aggregation.rb +6 -9
  72. data/lib/mongo/collection/view/builder/map_reduce.rb +18 -17
  73. data/lib/mongo/collection/view/builder.rb +0 -1
  74. data/lib/mongo/collection/view/change_stream/retryable.rb +3 -8
  75. data/lib/mongo/collection/view/change_stream.rb +59 -58
  76. data/lib/mongo/collection/view/explainable.rb +11 -20
  77. data/lib/mongo/collection/view/immutable.rb +1 -3
  78. data/lib/mongo/collection/view/iterable.rb +35 -28
  79. data/lib/mongo/collection/view/map_reduce.rb +20 -25
  80. data/lib/mongo/collection/view/readable.rb +50 -57
  81. data/lib/mongo/collection/view/writable.rb +56 -72
  82. data/lib/mongo/collection/view.rb +9 -8
  83. data/lib/mongo/collection.rb +63 -76
  84. data/lib/mongo/condition_variable.rb +4 -4
  85. data/lib/mongo/config/options.rb +0 -3
  86. data/lib/mongo/config/validators/option.rb +3 -5
  87. data/lib/mongo/config.rb +2 -4
  88. data/lib/mongo/crypt/auto_decryption_context.rb +0 -3
  89. data/lib/mongo/crypt/auto_encrypter.rb +34 -43
  90. data/lib/mongo/crypt/auto_encryption_context.rb +0 -3
  91. data/lib/mongo/crypt/binary.rb +5 -9
  92. data/lib/mongo/crypt/binding.rb +149 -155
  93. data/lib/mongo/crypt/context.rb +10 -17
  94. data/lib/mongo/crypt/data_key_context.rb +2 -7
  95. data/lib/mongo/crypt/encryption_io.rb +29 -39
  96. data/lib/mongo/crypt/explicit_decryption_context.rb +0 -3
  97. data/lib/mongo/crypt/explicit_encrypter.rb +1 -1
  98. data/lib/mongo/crypt/explicit_encryption_context.rb +19 -30
  99. data/lib/mongo/crypt/explicit_encryption_expression_context.rb +0 -2
  100. data/lib/mongo/crypt/handle.rb +42 -48
  101. data/lib/mongo/crypt/hooks.rb +12 -15
  102. data/lib/mongo/crypt/kms/aws/credentials.rb +12 -16
  103. data/lib/mongo/crypt/kms/aws/master_document.rb +6 -9
  104. data/lib/mongo/crypt/kms/aws.rb +0 -2
  105. data/lib/mongo/crypt/kms/azure/credentials_retriever.rb +2 -7
  106. data/lib/mongo/crypt/kms/azure/master_document.rb +15 -19
  107. data/lib/mongo/crypt/kms/azure.rb +0 -1
  108. data/lib/mongo/crypt/kms/credentials.rb +13 -27
  109. data/lib/mongo/crypt/kms/gcp/credentials.rb +12 -14
  110. data/lib/mongo/crypt/kms/gcp/credentials_retriever.rb +7 -9
  111. data/lib/mongo/crypt/kms/gcp/master_document.rb +12 -16
  112. data/lib/mongo/crypt/kms/gcp.rb +0 -2
  113. data/lib/mongo/crypt/kms/kmip/credentials.rb +7 -8
  114. data/lib/mongo/crypt/kms/kmip/master_document.rb +3 -5
  115. data/lib/mongo/crypt/kms/kmip.rb +0 -1
  116. data/lib/mongo/crypt/kms/local/credentials.rb +7 -8
  117. data/lib/mongo/crypt/kms/local/master_document.rb +2 -6
  118. data/lib/mongo/crypt/kms/local.rb +0 -1
  119. data/lib/mongo/crypt/kms/master_key_document.rb +11 -15
  120. data/lib/mongo/crypt/kms.rb +14 -16
  121. data/lib/mongo/crypt/kms_context.rb +0 -2
  122. data/lib/mongo/crypt/rewrap_many_data_key_context.rb +2 -7
  123. data/lib/mongo/crypt/rewrap_many_data_key_result.rb +2 -4
  124. data/lib/mongo/crypt/status.rb +12 -14
  125. data/lib/mongo/crypt.rb +0 -1
  126. data/lib/mongo/csot_timeout_holder.rb +3 -2
  127. data/lib/mongo/cursor/kill_spec.rb +7 -10
  128. data/lib/mongo/cursor.rb +74 -64
  129. data/lib/mongo/cursor_host.rb +8 -10
  130. data/lib/mongo/database/view.rb +16 -37
  131. data/lib/mongo/database.rb +52 -56
  132. data/lib/mongo/dbref.rb +0 -1
  133. data/lib/mongo/distinguishing_semaphore.rb +0 -1
  134. data/lib/mongo/error/auth_error.rb +0 -2
  135. data/lib/mongo/error/bad_load_balancer_target.rb +0 -2
  136. data/lib/mongo/error/bulk_write_error.rb +7 -10
  137. data/lib/mongo/error/change_stream_resumable.rb +0 -2
  138. data/lib/mongo/error/client_closed.rb +0 -2
  139. data/lib/mongo/error/closed_stream.rb +1 -4
  140. data/lib/mongo/error/connection_check_out_timeout.rb +3 -6
  141. data/lib/mongo/error/connection_perished.rb +0 -2
  142. data/lib/mongo/error/connection_unavailable.rb +0 -2
  143. data/lib/mongo/error/credential_check_error.rb +0 -2
  144. data/lib/mongo/error/crypt_error.rb +0 -2
  145. data/lib/mongo/error/extra_file_chunk.rb +1 -4
  146. data/lib/mongo/error/failed_string_prep_validation.rb +5 -6
  147. data/lib/mongo/error/file_not_found.rb +0 -3
  148. data/lib/mongo/error/handshake_error.rb +0 -2
  149. data/lib/mongo/error/insufficient_iteration_count.rb +1 -4
  150. data/lib/mongo/error/internal_driver_error.rb +0 -2
  151. data/lib/mongo/error/invalid_address.rb +0 -2
  152. data/lib/mongo/error/invalid_application_name.rb +0 -3
  153. data/lib/mongo/error/invalid_bulk_operation.rb +1 -4
  154. data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -4
  155. data/lib/mongo/error/invalid_collection_name.rb +1 -4
  156. data/lib/mongo/error/invalid_config_option.rb +0 -3
  157. data/lib/mongo/error/invalid_cursor_operation.rb +0 -2
  158. data/lib/mongo/error/invalid_database_name.rb +1 -4
  159. data/lib/mongo/error/invalid_document.rb +1 -4
  160. data/lib/mongo/error/invalid_file.rb +0 -3
  161. data/lib/mongo/error/invalid_file_revision.rb +0 -3
  162. data/lib/mongo/error/invalid_min_pool_size.rb +0 -3
  163. data/lib/mongo/error/invalid_nonce.rb +0 -3
  164. data/lib/mongo/error/invalid_read_concern.rb +2 -4
  165. data/lib/mongo/error/invalid_read_option.rb +0 -3
  166. data/lib/mongo/error/invalid_replacement_document.rb +2 -5
  167. data/lib/mongo/error/invalid_server_auth_host.rb +0 -2
  168. data/lib/mongo/error/invalid_server_auth_response.rb +0 -2
  169. data/lib/mongo/error/invalid_server_preference.rb +7 -16
  170. data/lib/mongo/error/invalid_session.rb +1 -4
  171. data/lib/mongo/error/invalid_signature.rb +0 -3
  172. data/lib/mongo/error/invalid_transaction_operation.rb +5 -8
  173. data/lib/mongo/error/invalid_txt_record.rb +0 -2
  174. data/lib/mongo/error/invalid_update_document.rb +2 -5
  175. data/lib/mongo/error/invalid_uri.rb +1 -4
  176. data/lib/mongo/error/invalid_write_concern.rb +2 -5
  177. data/lib/mongo/error/kms_error.rb +0 -2
  178. data/lib/mongo/error/labelable.rb +0 -3
  179. data/lib/mongo/error/lint_error.rb +0 -2
  180. data/lib/mongo/error/max_bson_size.rb +8 -11
  181. data/lib/mongo/error/max_message_size.rb +2 -5
  182. data/lib/mongo/error/mismatched_domain.rb +0 -2
  183. data/lib/mongo/error/missing_connection.rb +0 -2
  184. data/lib/mongo/error/missing_file_chunk.rb +0 -3
  185. data/lib/mongo/error/missing_password.rb +0 -2
  186. data/lib/mongo/error/missing_resume_token.rb +1 -4
  187. data/lib/mongo/error/missing_scram_server_signature.rb +2 -4
  188. data/lib/mongo/error/missing_service_id.rb +0 -2
  189. data/lib/mongo/error/mongocryptd_spawn_error.rb +0 -2
  190. data/lib/mongo/error/multi_index_drop.rb +0 -3
  191. data/lib/mongo/error/need_primary_server.rb +0 -2
  192. data/lib/mongo/error/no_server_available.rb +3 -8
  193. data/lib/mongo/error/no_service_connection_available.rb +1 -3
  194. data/lib/mongo/error/no_srv_records.rb +0 -2
  195. data/lib/mongo/error/notable.rb +8 -16
  196. data/lib/mongo/error/operation_failure.rb +22 -35
  197. data/lib/mongo/error/parser.rb +33 -75
  198. data/lib/mongo/error/pool_cleared_error.rb +1 -3
  199. data/lib/mongo/error/pool_closed_error.rb +0 -3
  200. data/lib/mongo/error/pool_error.rb +0 -3
  201. data/lib/mongo/error/pool_paused_error.rb +0 -2
  202. data/lib/mongo/error/raise_original_error.rb +1 -3
  203. data/lib/mongo/error/read_write_retryable.rb +14 -17
  204. data/lib/mongo/error/sdam_error_detection.rb +3 -5
  205. data/lib/mongo/error/server_api_conflict.rb +0 -2
  206. data/lib/mongo/error/server_certificate_revoked.rb +0 -2
  207. data/lib/mongo/error/server_not_usable.rb +0 -2
  208. data/lib/mongo/error/session_ended.rb +1 -3
  209. data/lib/mongo/error/session_not_materialized.rb +1 -3
  210. data/lib/mongo/error/sessions_not_supported.rb +1 -4
  211. data/lib/mongo/error/snapshot_session_invalid_server_version.rb +1 -4
  212. data/lib/mongo/error/snapshot_session_transaction_prohibited.rb +1 -4
  213. data/lib/mongo/error/socket_error.rb +0 -2
  214. data/lib/mongo/error/socket_timeout_error.rb +0 -2
  215. data/lib/mongo/error/transactions_not_supported.rb +3 -6
  216. data/lib/mongo/error/unchangeable_collection_option.rb +1 -4
  217. data/lib/mongo/error/unexpected_chunk_length.rb +0 -3
  218. data/lib/mongo/error/unexpected_response.rb +1 -4
  219. data/lib/mongo/error/unknown_payload_type.rb +0 -3
  220. data/lib/mongo/error/unmet_dependency.rb +0 -2
  221. data/lib/mongo/error/unsupported_array_filters.rb +3 -24
  222. data/lib/mongo/error/unsupported_collation.rb +3 -24
  223. data/lib/mongo/error/unsupported_features.rb +0 -2
  224. data/lib/mongo/error/unsupported_message_type.rb +0 -2
  225. data/lib/mongo/error/unsupported_option.rb +19 -21
  226. data/lib/mongo/error/write_retryable.rb +0 -2
  227. data/lib/mongo/error.rb +10 -24
  228. data/lib/mongo/event/base.rb +0 -2
  229. data/lib/mongo/event/listeners.rb +0 -3
  230. data/lib/mongo/event/publisher.rb +0 -3
  231. data/lib/mongo/event/subscriber.rb +0 -4
  232. data/lib/mongo/event.rb +4 -6
  233. data/lib/mongo/grid/file/chunk.rb +7 -10
  234. data/lib/mongo/grid/file/info.rb +20 -24
  235. data/lib/mongo/grid/file.rb +7 -8
  236. data/lib/mongo/grid/fs_bucket.rb +40 -48
  237. data/lib/mongo/grid/stream/read.rb +25 -35
  238. data/lib/mongo/grid/stream/write.rb +17 -22
  239. data/lib/mongo/grid/stream.rb +2 -4
  240. data/lib/mongo/grid.rb +0 -1
  241. data/lib/mongo/id.rb +0 -1
  242. data/lib/mongo/index/view.rb +49 -48
  243. data/lib/mongo/index.rb +7 -10
  244. data/lib/mongo/lint.rb +31 -37
  245. data/lib/mongo/loggable.rb +5 -8
  246. data/lib/mongo/logger.rb +1 -7
  247. data/lib/mongo/monitoring/cmap_log_subscriber.rb +0 -2
  248. data/lib/mongo/monitoring/command_log_subscriber.rb +25 -33
  249. data/lib/mongo/monitoring/event/cmap/base.rb +0 -2
  250. data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +1 -4
  251. data/lib/mongo/monitoring/event/cmap/connection_check_out_started.rb +0 -3
  252. data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +1 -4
  253. data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +2 -5
  254. data/lib/mongo/monitoring/event/cmap/connection_closed.rb +1 -4
  255. data/lib/mongo/monitoring/event/cmap/connection_created.rb +1 -4
  256. data/lib/mongo/monitoring/event/cmap/connection_ready.rb +1 -4
  257. data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +0 -3
  258. data/lib/mongo/monitoring/event/cmap/pool_closed.rb +1 -4
  259. data/lib/mongo/monitoring/event/cmap/pool_created.rb +1 -4
  260. data/lib/mongo/monitoring/event/cmap/pool_ready.rb +1 -4
  261. data/lib/mongo/monitoring/event/cmap.rb +0 -1
  262. data/lib/mongo/monitoring/event/command_failed.rb +5 -9
  263. data/lib/mongo/monitoring/event/command_started.rb +8 -12
  264. data/lib/mongo/monitoring/event/command_succeeded.rb +7 -15
  265. data/lib/mongo/monitoring/event/secure.rb +15 -20
  266. data/lib/mongo/monitoring/event/server_closed.rb +1 -4
  267. data/lib/mongo/monitoring/event/server_description_changed.rb +4 -8
  268. data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +5 -10
  269. data/lib/mongo/monitoring/event/server_heartbeat_started.rb +1 -4
  270. data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +3 -8
  271. data/lib/mongo/monitoring/event/server_opening.rb +1 -4
  272. data/lib/mongo/monitoring/event/topology_changed.rb +2 -5
  273. data/lib/mongo/monitoring/event/topology_closed.rb +1 -4
  274. data/lib/mongo/monitoring/event/topology_opening.rb +1 -4
  275. data/lib/mongo/monitoring/event.rb +0 -1
  276. data/lib/mongo/monitoring/publishable.rb +20 -30
  277. data/lib/mongo/monitoring/sdam_log_subscriber.rb +0 -2
  278. data/lib/mongo/monitoring/server_closed_log_subscriber.rb +0 -3
  279. data/lib/mongo/monitoring/server_description_changed_log_subscriber.rb +0 -3
  280. data/lib/mongo/monitoring/server_opening_log_subscriber.rb +0 -3
  281. data/lib/mongo/monitoring/topology_changed_log_subscriber.rb +5 -8
  282. data/lib/mongo/monitoring/topology_closed_log_subscriber.rb +0 -3
  283. data/lib/mongo/monitoring/topology_opening_log_subscriber.rb +0 -3
  284. data/lib/mongo/monitoring/unified_sdam_log_subscriber.rb +1 -3
  285. data/lib/mongo/monitoring.rb +38 -39
  286. data/lib/mongo/operation/aggregate/op_msg.rb +0 -2
  287. data/lib/mongo/operation/aggregate/result.rb +3 -6
  288. data/lib/mongo/operation/aggregate.rb +0 -2
  289. data/lib/mongo/operation/collections_info/result.rb +0 -3
  290. data/lib/mongo/operation/collections_info.rb +0 -2
  291. data/lib/mongo/operation/command/op_msg.rb +1 -4
  292. data/lib/mongo/operation/command.rb +0 -2
  293. data/lib/mongo/operation/context.rb +13 -16
  294. data/lib/mongo/operation/count/op_msg.rb +2 -4
  295. data/lib/mongo/operation/count.rb +0 -2
  296. data/lib/mongo/operation/create/op_msg.rb +2 -5
  297. data/lib/mongo/operation/create.rb +0 -2
  298. data/lib/mongo/operation/create_index/op_msg.rb +3 -7
  299. data/lib/mongo/operation/create_index.rb +0 -2
  300. data/lib/mongo/operation/create_user/op_msg.rb +2 -4
  301. data/lib/mongo/operation/create_user.rb +0 -2
  302. data/lib/mongo/operation/delete/bulk_result.rb +2 -3
  303. data/lib/mongo/operation/delete/op_msg.rb +3 -10
  304. data/lib/mongo/operation/delete/result.rb +0 -3
  305. data/lib/mongo/operation/delete.rb +1 -5
  306. data/lib/mongo/operation/distinct/op_msg.rb +2 -5
  307. data/lib/mongo/operation/distinct.rb +0 -2
  308. data/lib/mongo/operation/drop/op_msg.rb +0 -2
  309. data/lib/mongo/operation/drop.rb +0 -2
  310. data/lib/mongo/operation/drop_database/op_msg.rb +0 -2
  311. data/lib/mongo/operation/drop_database.rb +0 -2
  312. data/lib/mongo/operation/drop_index/op_msg.rb +4 -6
  313. data/lib/mongo/operation/drop_index.rb +0 -2
  314. data/lib/mongo/operation/explain/op_msg.rb +0 -2
  315. data/lib/mongo/operation/explain/result.rb +0 -3
  316. data/lib/mongo/operation/explain.rb +0 -2
  317. data/lib/mongo/operation/find/builder/command.rb +4 -12
  318. data/lib/mongo/operation/find/builder/flags.rb +9 -15
  319. data/lib/mongo/operation/find/builder/modifiers.rb +1 -4
  320. data/lib/mongo/operation/find/builder.rb +0 -1
  321. data/lib/mongo/operation/find/op_msg.rb +4 -12
  322. data/lib/mongo/operation/find/result.rb +0 -3
  323. data/lib/mongo/operation/find.rb +0 -2
  324. data/lib/mongo/operation/get_more/command_builder.rb +1 -6
  325. data/lib/mongo/operation/get_more/op_msg.rb +10 -4
  326. data/lib/mongo/operation/get_more/result.rb +0 -3
  327. data/lib/mongo/operation/get_more.rb +0 -2
  328. data/lib/mongo/operation/indexes/op_msg.rb +0 -2
  329. data/lib/mongo/operation/indexes/result.rb +1 -5
  330. data/lib/mongo/operation/indexes.rb +0 -2
  331. data/lib/mongo/operation/insert/bulk_result.rb +2 -6
  332. data/lib/mongo/operation/insert/op_msg.rb +2 -4
  333. data/lib/mongo/operation/insert/result.rb +0 -3
  334. data/lib/mongo/operation/insert.rb +2 -5
  335. data/lib/mongo/operation/kill_cursors/command_builder.rb +0 -3
  336. data/lib/mongo/operation/kill_cursors/op_msg.rb +1 -3
  337. data/lib/mongo/operation/kill_cursors.rb +0 -2
  338. data/lib/mongo/operation/list_collections/op_msg.rb +4 -6
  339. data/lib/mongo/operation/list_collections/result.rb +1 -4
  340. data/lib/mongo/operation/list_collections.rb +0 -2
  341. data/lib/mongo/operation/map_reduce/op_msg.rb +0 -2
  342. data/lib/mongo/operation/map_reduce/result.rb +3 -6
  343. data/lib/mongo/operation/map_reduce.rb +0 -2
  344. data/lib/mongo/operation/op_msg_base.rb +0 -1
  345. data/lib/mongo/operation/parallel_scan/op_msg.rb +4 -5
  346. data/lib/mongo/operation/parallel_scan/result.rb +2 -5
  347. data/lib/mongo/operation/parallel_scan.rb +0 -2
  348. data/lib/mongo/operation/remove_user/op_msg.rb +2 -4
  349. data/lib/mongo/operation/remove_user.rb +0 -2
  350. data/lib/mongo/operation/result.rb +38 -48
  351. data/lib/mongo/operation/shared/bypass_document_validation.rb +3 -7
  352. data/lib/mongo/operation/shared/causal_consistency_supported.rb +0 -3
  353. data/lib/mongo/operation/shared/executable.rb +19 -28
  354. data/lib/mongo/operation/shared/executable_no_validate.rb +0 -3
  355. data/lib/mongo/operation/shared/executable_transaction_label.rb +0 -2
  356. data/lib/mongo/operation/shared/idable.rb +3 -6
  357. data/lib/mongo/operation/shared/limited.rb +0 -3
  358. data/lib/mongo/operation/shared/object_id_generator.rb +0 -3
  359. data/lib/mongo/operation/shared/op_msg_executable.rb +0 -2
  360. data/lib/mongo/operation/shared/polymorphic_lookup.rb +0 -2
  361. data/lib/mongo/operation/shared/polymorphic_result.rb +2 -4
  362. data/lib/mongo/operation/shared/read_preference_supported.rb +10 -15
  363. data/lib/mongo/operation/shared/response_handling.rb +13 -26
  364. data/lib/mongo/operation/shared/result/aggregatable.rb +12 -13
  365. data/lib/mongo/operation/shared/sessions_supported.rb +87 -99
  366. data/lib/mongo/operation/shared/specifiable.rb +32 -58
  367. data/lib/mongo/operation/shared/write.rb +12 -17
  368. data/lib/mongo/operation/shared/write_concern_supported.rb +4 -7
  369. data/lib/mongo/operation/update/bulk_result.rb +13 -17
  370. data/lib/mongo/operation/update/op_msg.rb +2 -5
  371. data/lib/mongo/operation/update/result.rb +5 -5
  372. data/lib/mongo/operation/update.rb +1 -5
  373. data/lib/mongo/operation/update_user/op_msg.rb +2 -4
  374. data/lib/mongo/operation/update_user.rb +0 -2
  375. data/lib/mongo/operation/users_info/op_msg.rb +2 -4
  376. data/lib/mongo/operation/users_info/result.rb +1 -4
  377. data/lib/mongo/operation/users_info.rb +0 -2
  378. data/lib/mongo/operation/write_command/op_msg.rb +2 -10
  379. data/lib/mongo/operation/write_command.rb +0 -2
  380. data/lib/mongo/operation.rb +9 -14
  381. data/lib/mongo/options/mapper.rb +8 -15
  382. data/lib/mongo/options/redacted.rb +7 -9
  383. data/lib/mongo/options.rb +0 -1
  384. data/lib/mongo/protocol/bit_vector.rb +3 -5
  385. data/lib/mongo/protocol/caching_hash.rb +2 -7
  386. data/lib/mongo/protocol/compressed.rb +5 -10
  387. data/lib/mongo/protocol/get_more.rb +2 -8
  388. data/lib/mongo/protocol/kill_cursors.rb +2 -8
  389. data/lib/mongo/protocol/message.rb +103 -105
  390. data/lib/mongo/protocol/msg.rb +48 -63
  391. data/lib/mongo/protocol/query.rb +32 -41
  392. data/lib/mongo/protocol/registry.rb +2 -5
  393. data/lib/mongo/protocol/reply.rb +10 -16
  394. data/lib/mongo/protocol/serializers.rb +41 -59
  395. data/lib/mongo/protocol.rb +0 -1
  396. data/lib/mongo/query_cache.rb +7 -15
  397. data/lib/mongo/retryable/backpressure.rb +31 -0
  398. data/lib/mongo/retryable/base_worker.rb +39 -13
  399. data/lib/mongo/retryable/read_worker.rb +77 -21
  400. data/lib/mongo/retryable/retry_policy.rb +59 -0
  401. data/lib/mongo/retryable/write_worker.rb +155 -56
  402. data/lib/mongo/retryable.rb +70 -9
  403. data/lib/mongo/search_index/view.rb +1 -1
  404. data/lib/mongo/semaphore.rb +0 -1
  405. data/lib/mongo/server/app_metadata/environment.rb +3 -3
  406. data/lib/mongo/server/app_metadata.rb +4 -5
  407. data/lib/mongo/server/connection.rb +61 -61
  408. data/lib/mongo/server/connection_base.rb +43 -53
  409. data/lib/mongo/server/connection_common.rb +41 -64
  410. data/lib/mongo/server/connection_pool/generation_manager.rb +6 -11
  411. data/lib/mongo/server/connection_pool/populator.rb +1 -4
  412. data/lib/mongo/server/connection_pool.rb +195 -167
  413. data/lib/mongo/server/description/features.rb +23 -60
  414. data/lib/mongo/server/description/load_balancer.rb +0 -2
  415. data/lib/mongo/server/description.rb +117 -138
  416. data/lib/mongo/server/monitor/app_metadata.rb +3 -4
  417. data/lib/mongo/server/monitor/connection.rb +28 -35
  418. data/lib/mongo/server/monitor.rb +65 -60
  419. data/lib/mongo/server/pending_connection.rb +70 -71
  420. data/lib/mongo/server/push_monitor/connection.rb +0 -3
  421. data/lib/mongo/server/push_monitor.rb +21 -29
  422. data/lib/mongo/server/round_trip_time_calculator.rb +11 -17
  423. data/lib/mongo/server.rb +60 -93
  424. data/lib/mongo/server_selector/base.rb +133 -157
  425. data/lib/mongo/server_selector/nearest.rb +2 -5
  426. data/lib/mongo/server_selector/primary.rb +1 -5
  427. data/lib/mongo/server_selector/primary_preferred.rb +2 -6
  428. data/lib/mongo/server_selector/secondary.rb +2 -6
  429. data/lib/mongo/server_selector/secondary_preferred.rb +1 -5
  430. data/lib/mongo/server_selector.rb +3 -4
  431. data/lib/mongo/session/server_session.rb +6 -7
  432. data/lib/mongo/session/session_pool.rb +20 -34
  433. data/lib/mongo/session.rb +287 -188
  434. data/lib/mongo/socket/ocsp_cache.rb +8 -13
  435. data/lib/mongo/socket/ocsp_verifier.rb +69 -70
  436. data/lib/mongo/socket/ssl.rb +44 -43
  437. data/lib/mongo/socket/tcp.rb +5 -8
  438. data/lib/mongo/socket/unix.rb +0 -4
  439. data/lib/mongo/socket.rb +80 -102
  440. data/lib/mongo/srv/monitor.rb +6 -11
  441. data/lib/mongo/srv/resolver.rb +15 -24
  442. data/lib/mongo/srv/result.rb +18 -24
  443. data/lib/mongo/srv.rb +0 -1
  444. data/lib/mongo/timeout.rb +4 -11
  445. data/lib/mongo/topology_version.rb +8 -13
  446. data/lib/mongo/tracing/open_telemetry/command_tracer.rb +1 -1
  447. data/lib/mongo/tracing/open_telemetry/operation_tracer.rb +1 -1
  448. data/lib/mongo/tracing/open_telemetry/tracer.rb +1 -1
  449. data/lib/mongo/uri/options_mapper.rb +135 -126
  450. data/lib/mongo/uri/srv_protocol.rb +25 -38
  451. data/lib/mongo/uri.rb +95 -139
  452. data/lib/mongo/utils.rb +5 -12
  453. data/lib/mongo/version.rb +1 -1
  454. data/lib/mongo/write_concern/acknowledged.rb +0 -2
  455. data/lib/mongo/write_concern/base.rb +6 -6
  456. data/lib/mongo/write_concern/unacknowledged.rb +0 -2
  457. data/lib/mongo/write_concern.rb +14 -15
  458. data/lib/mongo.rb +1 -3
  459. data/mongo.gemspec +17 -17
  460. metadata +5 -5
  461. data/lib/mongo/error/server_api_not_supported.rb +0 -27
  462. data/lib/mongo/operation/shared/result/use_legacy_error_parser.rb +0 -32
  463. data/lib/mongo/operation/shared/validatable.rb +0 -87
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:todo all
3
2
 
4
3
  # Copyright (C) 2014-2020 MongoDB Inc.
5
4
  #
@@ -17,7 +16,6 @@
17
16
 
18
17
  module Mongo
19
18
  class Server
20
-
21
19
  # This class models the socket connections for servers and their behavior.
22
20
  #
23
21
  # @since 2.0.0
@@ -32,37 +30,23 @@ module Mongo
32
30
  # @since 2.1.0
33
31
  #
34
32
  # @deprecated No longer necessary with Server Selection specification.
35
- PING = { :ping => 1 }.freeze
33
+ PING = { ping: 1 }.freeze
36
34
 
37
- # The ping command for an OP_MSG (server versions >= 3.6).
35
+ # The ping command for an OP_MSG
38
36
  #
39
37
  # @since 2.5.0
40
38
  #
41
39
  # @deprecated No longer necessary with Server Selection specification.
42
40
  PING_OP_MSG = { :ping => 1, '$db' => Database::ADMIN }.freeze
43
41
 
44
- # Ping message.
45
- #
46
- # @since 2.1.0
47
- #
48
- # @deprecated No longer necessary with Server Selection specification.
49
- PING_MESSAGE = Protocol::Query.new(Database::ADMIN, Database::COMMAND, PING, :limit => -1)
50
-
51
- # Ping message as an OP_MSG (server versions >= 3.6).
42
+ # Ping message as an OP_MSG
52
43
  #
53
44
  # @since 2.5.0
54
45
  #
55
46
  # @deprecated No longer necessary with Server Selection specification.
56
47
  PING_OP_MSG_MESSAGE = Protocol::Msg.new([], {}, PING_OP_MSG)
57
48
 
58
- # The ping message as raw bytes.
59
- #
60
- # @since 2.1.0
61
- #
62
- # @deprecated No longer necessary with Server Selection specification.
63
- PING_BYTES = PING_MESSAGE.serialize.to_s.freeze
64
-
65
- # The ping OP_MSG message as raw bytes (server versions >= 3.6).
49
+ # The ping OP_MSG message as raw bytes
66
50
  #
67
51
  # @since 2.5.0
68
52
  #
@@ -105,7 +89,7 @@ module Mongo
105
89
  # @since 2.0.0
106
90
  def initialize(server, options = {})
107
91
  if server.load_balancer? && options[:generation]
108
- raise ArgumentError, "Generation cannot be set when server is a load balancer"
92
+ raise ArgumentError, 'Generation cannot be set when server is a load balancer'
109
93
  end
110
94
 
111
95
  @id = server.next_connection_id
@@ -117,7 +101,7 @@ module Mongo
117
101
  @last_checkin = nil
118
102
  @auth_mechanism = nil
119
103
  @pid = Process.pid
120
- @pinned = false
104
+ @pin_reasons = Set.new
121
105
 
122
106
  publish_cmap_event(
123
107
  Monitoring::Event::Cmap::ConnectionCreated.new(address, id)
@@ -198,21 +182,34 @@ module Mongo
198
182
  #
199
183
  # @api private
200
184
  def pinned?
201
- @pinned
185
+ !@pin_reasons.empty?
202
186
  end
203
187
 
204
- # Mark the connection as pinned.
188
+ # Mark the connection as pinned for the given reason.
189
+ #
190
+ # @param [ Symbol ] reason The reason for pinning (:cursor or
191
+ # :transaction). Defaults to :cursor for backward compatibility.
205
192
  #
206
193
  # @api private
207
- def pin
208
- @pinned = true
194
+ def pin(reason = :cursor)
195
+ @pin_reasons << reason
209
196
  end
210
197
 
211
- # Mark the connection as not pinned.
198
+ # Remove a pin from the connection for the given reason.
199
+ #
200
+ # @param [ Symbol ] reason The reason to unpin (:cursor or
201
+ # :transaction). Defaults to :cursor for backward compatibility.
212
202
  #
213
203
  # @api private
214
- def unpin
215
- @pinned = false
204
+ def unpin(reason = :cursor)
205
+ @pin_reasons.delete(reason)
206
+ end
207
+
208
+ # Remove all pins from the connection.
209
+ #
210
+ # @api private
211
+ def unpin_all
212
+ @pin_reasons.clear
216
213
  end
217
214
 
218
215
  # Establishes a network connection to the target address.
@@ -236,10 +233,9 @@ module Mongo
236
233
  @description, @compressor = do_connect
237
234
 
238
235
  if server.load_balancer?
239
- if Lint.enabled?
240
- unless service_id
241
- raise Error::InternalDriverError, "The connection is to a load balancer and it must have service_id set here, but does not"
242
- end
236
+ if Lint.enabled? && !service_id
237
+ raise Error::InternalDriverError,
238
+ 'The connection is to a load balancer and it must have service_id set here, but does not'
243
239
  end
244
240
  @generation = connection_pool.generation_manager.generation(service_id: service_id)
245
241
  end
@@ -280,7 +276,8 @@ module Mongo
280
276
  raise_if_closed!
281
277
  begin
282
278
  pending_connection = PendingConnection.new(
283
- socket, @server, monitoring, options.merge(id: id))
279
+ socket, @server, monitoring, options.merge(id: id)
280
+ )
284
281
  pending_connection.handshake_and_authenticate!
285
282
  rescue Exception
286
283
  socket&.close
@@ -288,7 +285,7 @@ module Mongo
288
285
  raise
289
286
  end
290
287
 
291
- [pending_connection.description, pending_connection.compressor]
288
+ [ pending_connection.description, pending_connection.compressor ]
292
289
  end
293
290
 
294
291
  # Disconnect the connection.
@@ -311,12 +308,16 @@ module Mongo
311
308
  #
312
309
  # @since 2.0.0
313
310
  def disconnect!(options = nil)
314
- # Note: @closed may be true here but we also may have a socket.
311
+ # NOTE: @closed may be true here but we also may have a socket.
315
312
  # Check the socket and not @closed flag.
316
313
  @auth_mechanism = nil
317
314
  @last_checkin = nil
318
315
  if socket
319
- socket.close rescue nil
316
+ begin
317
+ socket.close
318
+ rescue StandardError
319
+ nil
320
+ end
320
321
  @socket = nil
321
322
  end
322
323
  @closed = true
@@ -333,8 +334,8 @@ module Mongo
333
334
  Monitoring::Event::Cmap::ConnectionClosed.new(
334
335
  address,
335
336
  id,
336
- reason,
337
- ),
337
+ reason
338
+ )
338
339
  )
339
340
  @close_event_published = true
340
341
  end
@@ -356,10 +357,9 @@ module Mongo
356
357
  #
357
358
  # @deprecated No longer necessary with Server Selection specification.
358
359
  def ping
359
- bytes = features.op_msg_enabled? ? PING_OP_MSG_BYTES : PING_BYTES
360
360
  ensure_connected do |socket|
361
361
  reply = add_server_diagnostics do
362
- socket.write(bytes)
362
+ socket.write(PING_OP_MSG_BYTES)
363
363
  Protocol::Message.deserialize(socket, max_message_size)
364
364
  end
365
365
  reply.documents[0][Operation::Result::OK] == 1
@@ -375,7 +375,7 @@ module Mongo
375
375
  @timeout ||= options[:socket_timeout]
376
376
  end
377
377
  # @deprecated Please use :socket_timeout instead. Will be removed in 3.0.0
378
- alias :timeout :socket_timeout
378
+ alias timeout socket_timeout
379
379
 
380
380
  # Record the last checkin time.
381
381
  #
@@ -415,31 +415,31 @@ module Mongo
415
415
  end
416
416
 
417
417
  def handle_errors
418
- begin
419
- yield
420
- rescue Error::SocketError => e
421
- @error = e
422
- @server.unknown!(
423
- generation: e.generation,
424
- # or description.service_id?
425
- service_id: e.service_id,
426
- stop_push_monitor: true,
427
- )
428
- raise
429
- rescue Error::SocketTimeoutError => e
430
- @error = e
431
- raise
432
- end
418
+ yield
419
+ rescue Error::SocketError => e
420
+ @error = e
421
+ @server.unknown!(
422
+ generation: e.generation,
423
+ # or description.service_id?
424
+ service_id: e.service_id,
425
+ stop_push_monitor: true
426
+ )
427
+ raise
428
+ rescue Error::SocketTimeoutError => e
429
+ @error = e
430
+ raise
433
431
  end
434
432
 
435
433
  def raise_if_closed!
436
434
  if error?
437
- raise Error::ConnectionPerished, "Connection #{generation}:#{id} for #{address.seed} is perished. Reconnecting closed or errored connections is no longer supported"
435
+ raise Error::ConnectionPerished,
436
+ "Connection #{generation}:#{id} for #{address.seed} is perished. Reconnecting closed or errored connections is no longer supported"
438
437
  end
439
438
 
440
- if closed?
441
- raise Error::ConnectionPerished, "Connection #{generation}:#{id} for #{address.seed} is closed. Reconnecting closed or errored connections is no longer supported"
442
- end
439
+ return unless closed?
440
+
441
+ raise Error::ConnectionPerished,
442
+ "Connection #{generation}:#{id} for #{address.seed} is closed. Reconnecting closed or errored connections is no longer supported"
443
443
  end
444
444
  end
445
445
  end
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:todo all
3
2
 
4
3
  # Copyright (C) 2019-2020 MongoDB Inc.
5
4
  #
@@ -17,7 +16,6 @@
17
16
 
18
17
  module Mongo
19
18
  class Server
20
-
21
19
  # This class encapsulates common connection functionality.
22
20
  #
23
21
  # @note Although methods of this module are part of the public API,
@@ -37,17 +35,17 @@ module Mongo
37
35
  # MAX_BSON_COMMAND_OVERHEAD.
38
36
  #
39
37
  # @api private
40
- DEFAULT_MAX_BSON_OBJECT_SIZE = 16777216
38
+ DEFAULT_MAX_BSON_OBJECT_SIZE = 16_777_216
41
39
 
42
40
  # The additional overhead allowed for command data (i.e. fields added
43
41
  # to the command document by the driver, as opposed to documents
44
42
  # provided by the user) when serializing a complete command to BSON.
45
43
  #
46
44
  # @api private
47
- MAX_BSON_COMMAND_OVERHEAD = 16384
45
+ MAX_BSON_COMMAND_OVERHEAD = 16_384
48
46
 
49
47
  # @api private
50
- REDUCED_MAX_BSON_SIZE = 2097152
48
+ REDUCED_MAX_BSON_SIZE = 2_097_152
51
49
 
52
50
  # @return [ Hash ] options The passed in options.
53
51
  attr_reader :options
@@ -83,10 +81,10 @@ module Mongo
83
81
 
84
82
  # @deprecated
85
83
  def_delegators :description,
86
- :features,
87
- :max_bson_object_size,
88
- :max_message_size,
89
- :mongos?
84
+ :features,
85
+ :max_bson_object_size,
86
+ :max_message_size,
87
+ :mongos?
90
88
 
91
89
  # @return [ nil | Object ] The service id, if any.
92
90
  def service_id
@@ -151,12 +149,13 @@ module Mongo
151
149
  # The monitoring code does not correctly handle multiple messages,
152
150
  # and the driver internally does not send more than one message at
153
151
  # a time ever. Thus prohibit multiple message use for now.
154
- if messages.length != 1
155
- raise ArgumentError, 'Can only dispatch one message at a time'
156
- end
152
+ raise ArgumentError, 'Can only dispatch one message at a time' if messages.length != 1
153
+
157
154
  if description.unknown?
158
- raise Error::InternalDriverError, "Cannot dispatch a message on a connection with unknown description: #{description.inspect}"
155
+ raise Error::InternalDriverError,
156
+ "Cannot dispatch a message on a connection with unknown description: #{description.inspect}"
159
157
  end
158
+
160
159
  message = messages.first
161
160
  deliver(message, context, options)
162
161
  end
@@ -168,16 +167,16 @@ module Mongo
168
167
  if Lint.enabled? && !@socket
169
168
  raise Error::LintError, "Trying to deliver a message over a disconnected connection (to #{address})"
170
169
  end
170
+
171
171
  buffer = serialize(message, context)
172
172
  check_timeout!(context)
173
173
  ensure_connected do |socket|
174
174
  operation_id = Monitoring.next_operation_id
175
175
  started_event = command_started(address, operation_id, message.payload,
176
- socket_object_id: socket.object_id, connection_id: id,
177
- connection_generation: generation,
178
- server_connection_id: description.server_connection_id,
179
- service_id: description.service_id,
180
- )
176
+ socket_object_id: socket.object_id, connection_id: id,
177
+ connection_generation: generation,
178
+ server_connection_id: description.server_connection_id,
179
+ service_id: description.service_id)
181
180
  start = Utils.monotonic_time
182
181
  result = nil
183
182
  begin
@@ -185,32 +184,27 @@ module Mongo
185
184
  socket.write(buffer.to_s, timeout: context.remaining_timeout_sec)
186
185
  if message.replyable?
187
186
  check_timeout!(context)
188
- Protocol::Message.deserialize(socket, max_message_size, message.request_id, options.merge(timeout: context.remaining_timeout_sec))
189
- else
190
- nil
187
+ Protocol::Message.deserialize(socket, max_message_size, message.request_id,
188
+ options.merge(timeout: context.remaining_timeout_sec))
191
189
  end
192
190
  end
193
191
  rescue Exception => e
194
192
  total_duration = Utils.monotonic_time - start
195
193
  command_failed(nil, address, operation_id, message.payload,
196
- e.message, total_duration,
197
- started_event: started_event,
198
- server_connection_id: description.server_connection_id,
199
- service_id: description.service_id,
200
- )
194
+ e.message, total_duration,
195
+ started_event: started_event,
196
+ server_connection_id: description.server_connection_id,
197
+ service_id: description.service_id)
201
198
  raise
202
199
  else
203
200
  total_duration = Utils.monotonic_time - start
204
201
  command_completed(result, address, operation_id, message.payload,
205
- total_duration,
206
- started_event: started_event,
207
- server_connection_id: description.server_connection_id,
208
- service_id: description.service_id,
209
- )
210
- end
211
- if result && context.decrypt?
212
- result = result.maybe_decrypt(context)
202
+ total_duration,
203
+ started_event: started_event,
204
+ server_connection_id: description.server_connection_id,
205
+ service_id: description.service_id)
213
206
  end
207
+ result = result.maybe_decrypt(context) if result && context.decrypt?
214
208
  result
215
209
  end
216
210
  end
@@ -224,18 +218,16 @@ module Mongo
224
218
  # only as the default if the server's hello did not contain
225
219
  # maxBsonObjectSize.
226
220
  max_bson_size = max_bson_object_size || DEFAULT_MAX_BSON_OBJECT_SIZE
227
- if context.encrypt?
228
- # The client-side encryption specification requires bulk writes to
229
- # be split at a reduced maxBsonObjectSize. If this message is a bulk
230
- # write and its size exceeds the reduced size limit, the serializer
231
- # will raise an exception, which is caught by BulkWrite. BulkWrite
232
- # will split the operation into individual writes, which will
233
- # not be subject to the reduced maxBsonObjectSize.
234
- if message.bulk_write?
235
- # Make the new maximum size equal to the specified reduced size
236
- # limit plus the 16KiB overhead allowance.
237
- max_bson_size = REDUCED_MAX_BSON_SIZE
238
- end
221
+ # The client-side encryption specification requires bulk writes to
222
+ # be split at a reduced maxBsonObjectSize. If this message is a bulk
223
+ # write and its size exceeds the reduced size limit, the serializer
224
+ # will raise an exception, which is caught by BulkWrite. BulkWrite
225
+ # will split the operation into individual writes, which will
226
+ # not be subject to the reduced maxBsonObjectSize.
227
+ if context.encrypt? && message.bulk_write?
228
+ # Make the new maximum size equal to the specified reduced size
229
+ # limit plus the 16KiB overhead allowance.
230
+ max_bson_size = REDUCED_MAX_BSON_SIZE
239
231
  end
240
232
 
241
233
  # RUBY-2234: It is necessary to check that the message size does not
@@ -261,9 +253,7 @@ module Mongo
261
253
  temp_buffer.put_bytes(buffer.get_bytes(buffer.length))
262
254
 
263
255
  message.serialize(temp_buffer, max_bson_size, MAX_BSON_COMMAND_OVERHEAD)
264
- if temp_buffer.length > max_message_size
265
- raise Error::MaxMessageSize.new(max_message_size)
266
- end
256
+ raise Error::MaxMessageSize.new(max_message_size) if temp_buffer.length > max_message_size
267
257
  end
268
258
 
269
259
  # RUBY-2335: When the un-compressed message is smaller than the maximum
@@ -286,12 +276,12 @@ module Mongo
286
276
  # @raise [ Mongo::Error::TimeoutError ] if timeout expired or there is
287
277
  # not enough time to send the message to the server.
288
278
  def check_timeout!(context)
289
- return if [nil, 0].include?(context.deadline)
279
+ return if [ nil, 0 ].include?(context.deadline)
290
280
 
291
281
  time_to_execute = context.remaining_timeout_sec - server.minimum_round_trip_time
292
- if time_to_execute <= 0
293
- raise Mongo::Error::TimeoutError
294
- end
282
+ return unless time_to_execute <= 0
283
+
284
+ raise Mongo::Error::TimeoutError
295
285
  end
296
286
  end
297
287
  end
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:todo all
3
2
 
4
3
  # Copyright (C) 2020 MongoDB Inc.
5
4
  #
@@ -17,7 +16,6 @@
17
16
 
18
17
  module Mongo
19
18
  class Server
20
-
21
19
  # Common methods used by both monitoring and non-monitoring connections.
22
20
  #
23
21
  # @note Although methods of this module are part of the public API,
@@ -26,7 +24,6 @@ module Mongo
26
24
  #
27
25
  # @api semipublic
28
26
  class ConnectionCommon
29
-
30
27
  # The compressor negotiated during the handshake for this connection,
31
28
  # if any.
32
29
  #
@@ -73,12 +70,8 @@ module Mongo
73
70
  LEGACY_HELLO_DOC
74
71
  end
75
72
  document.merge(app_metadata.validated_document).tap do |doc|
76
- if speculative_auth_doc
77
- doc.update(speculativeAuthenticate: speculative_auth_doc)
78
- end
79
- if load_balancer
80
- doc.update(loadBalanced: true)
81
- end
73
+ doc.update(speculativeAuthenticate: speculative_auth_doc) if speculative_auth_doc
74
+ doc.update(loadBalanced: true) if load_balancer
82
75
  end
83
76
  end
84
77
 
@@ -94,19 +87,18 @@ module Mongo
94
87
  def handshake_command(handshake_document)
95
88
  if handshake_document['apiVersion'] || handshake_document['loadBalanced']
96
89
  Protocol::Msg.new(
97
- [], {}, handshake_document.merge({'$db' => Database::ADMIN})
90
+ [], {}, handshake_document.merge({ '$db' => Database::ADMIN })
98
91
  )
99
92
  else
100
93
  Protocol::Query.new(
101
94
  Database::ADMIN,
102
95
  Database::COMMAND,
103
96
  handshake_document,
104
- :limit => -1
97
+ limit: -1
105
98
  )
106
99
  end
107
100
  end
108
101
 
109
-
110
102
  private
111
103
 
112
104
  HELLO_DOC = BSON::Document.new({ hello: 1 }).freeze
@@ -118,22 +110,22 @@ module Mongo
118
110
  def set_compressor!(reply)
119
111
  server_compressors = reply['compression']
120
112
 
121
- if options[:compressors]
122
- if intersection = (server_compressors & options[:compressors])
123
- @compressor = intersection.first
124
- else
125
- msg = if server_compressors
126
- "The server at #{address} has no compression algorithms in common with those requested. " +
127
- "Server algorithms: #{server_compressors.join(', ')}; " +
128
- "Requested algorithms: #{options[:compressors].join(', ')}. " +
129
- "Compression will not be used"
130
- else
131
- "The server at #{address} did not advertise compression support. " +
132
- "Requested algorithms: #{options[:compressors].join(', ')}. " +
133
- "Compression will not be used"
134
- end
135
- log_warn(msg)
136
- end
113
+ return unless options[:compressors]
114
+
115
+ if intersection = (server_compressors & options[:compressors])
116
+ @compressor = intersection.first
117
+ else
118
+ msg = if server_compressors
119
+ "The server at #{address} has no compression algorithms in common with those requested. " +
120
+ "Server algorithms: #{server_compressors.join(', ')}; " +
121
+ "Requested algorithms: #{options[:compressors].join(', ')}. " +
122
+ 'Compression will not be used'
123
+ else
124
+ "The server at #{address} did not advertise compression support. " +
125
+ "Requested algorithms: #{options[:compressors].join(', ')}. " +
126
+ 'Compression will not be used'
127
+ end
128
+ log_warn(msg)
137
129
  end
138
130
  end
139
131
 
@@ -151,57 +143,42 @@ module Mongo
151
143
  # knows its address. Server::Connection delegates the address to its
152
144
  # server.
153
145
  note = +"on #{address.seed}"
154
- if respond_to?(:id)
155
- note << ", connection #{generation}:#{id}"
156
- end
146
+ note << ", connection #{generation}:#{id}" if respond_to?(:id)
157
147
  # Non-monitoring connections have service id.
158
148
  # Monitoring connections do not.
159
- if respond_to?(:service_id) && service_id
160
- note << ", service id #{service_id}"
161
- end
149
+ note << ", service id #{service_id}" if respond_to?(:service_id) && service_id
162
150
  e.add_note(note)
163
151
  if respond_to?(:generation)
164
152
  # Non-monitoring connections
165
153
  e.generation = generation
166
- if respond_to?(:global_id)
167
- e.connection_global_id = global_id
168
- end
169
- if respond_to?(:description)
170
- e.service_id = service_id
171
- end
154
+ e.connection_global_id = global_id if respond_to?(:global_id)
155
+ e.service_id = service_id if respond_to?(:description)
172
156
  end
173
157
  raise e
174
158
  end
175
159
 
176
160
  def ssl_options
177
161
  @ssl_options ||= if options[:ssl]
178
- options.select { |k, v| k.to_s.start_with?('ssl') }
179
- else
180
- # Due to the way options are propagated from the client, if we
181
- # decide that we don't want to use TLS we need to have the :ssl
182
- # option explicitly set to false or the value provided to the
183
- # connection might be overwritten by the default inherited from
184
- # the client.
185
- {ssl: false}
186
- end.freeze
162
+ options.select { |k, _v| k.to_s.start_with?('ssl') }
163
+ else
164
+ # Due to the way options are propagated from the client, if we
165
+ # decide that we don't want to use TLS we need to have the :ssl
166
+ # option explicitly set to false or the value provided to the
167
+ # connection might be overwritten by the default inherited from
168
+ # the client.
169
+ { ssl: false }
170
+ end.freeze
187
171
  end
188
172
 
189
173
  def ensure_connected
190
- begin
191
- unless socket
192
- raise ArgumentError, "Connection #{generation}:#{id} for #{address.seed} is not connected"
193
- end
194
- if @error
195
- raise Error::ConnectionPerished, "Connection #{generation}:#{id} for #{address.seed} is perished"
196
- end
197
- result = yield socket
198
- success = true
199
- result
200
- ensure
201
- unless success
202
- @error = true
203
- end
204
- end
174
+ raise ArgumentError, "Connection #{generation}:#{id} for #{address.seed} is not connected" unless socket
175
+ raise Error::ConnectionPerished, "Connection #{generation}:#{id} for #{address.seed} is perished" if @error
176
+
177
+ result = yield socket
178
+ success = true
179
+ result
180
+ ensure
181
+ @error = true unless success
205
182
  end
206
183
  end
207
184
  end
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:todo all
3
2
 
4
3
  # Copyright (C) 2021 MongoDB Inc.
5
4
  #
@@ -18,10 +17,8 @@
18
17
  module Mongo
19
18
  class Server
20
19
  class ConnectionPool
21
-
22
20
  # @api private
23
21
  class GenerationManager
24
-
25
22
  def initialize(server:)
26
23
  @map = Hash.new { |hash, key| hash[key] = 1 }
27
24
  @pipe_fds = Hash.new { |hash, key| hash[key] = { 1 => IO.pipe } }
@@ -82,7 +79,7 @@ module Mongo
82
79
  # increment the generation for each service.
83
80
  #
84
81
  # Incrementing everything in the map accomplishes both tasks.
85
- @map.each do |k, v|
82
+ @map.each do |k, _v|
86
83
  gen = @map[k] += 1
87
84
  @pipe_fds[service_id] ||= {}
88
85
  @pipe_fds[service_id][gen] = IO.pipe
@@ -112,19 +109,17 @@ module Mongo
112
109
  end
113
110
  end
114
111
 
115
-
116
112
  private
117
113
 
118
-
119
114
  def validate_service_id!(service_id)
120
115
  if service_id
121
116
  unless server.load_balancer?
122
- raise ArgumentError, "Generation scoping to services is only available in load-balanced mode, but the server at #{server.address} is not a load balancer"
123
- end
124
- else
125
- if server.load_balancer?
126
- raise ArgumentError, "The server at #{server.address} is a load balancer and therefore does not have a single global generation"
117
+ raise ArgumentError,
118
+ "Generation scoping to services is only available in load-balanced mode, but the server at #{server.address} is not a load balancer"
127
119
  end
120
+ elsif server.load_balancer?
121
+ raise ArgumentError,
122
+ "The server at #{server.address} is a load balancer and therefore does not have a single global generation"
128
123
  end
129
124
  end
130
125
 
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:todo all
3
2
 
4
3
  # Copyright (C) 2019-2020 MongoDB Inc.
5
4
  #
@@ -47,9 +46,7 @@ module Mongo
47
46
  throw(:done) if @pool.closed?
48
47
 
49
48
  begin
50
- unless @pool.populate
51
- @pool.populate_semaphore.wait
52
- end
49
+ @pool.populate_semaphore.wait unless @pool.populate
53
50
  rescue Error::AuthError, Error => e
54
51
  # Errors encountered when trying to add connections to
55
52
  # pool; try again later