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
data/lib/mongo/cluster.rb CHANGED
@@ -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
  #
@@ -21,7 +20,6 @@ require 'mongo/cluster/reapers/cursor_reaper'
21
20
  require 'mongo/cluster/periodic_executor'
22
21
 
23
22
  module Mongo
24
-
25
23
  # Represents a group of servers on the server side, either as a
26
24
  # single server, a replica set, or a single or multiple mongos.
27
25
  #
@@ -58,7 +56,7 @@ module Mongo
58
56
  #
59
57
  # @since 2.5.0
60
58
  # @deprecated
61
- CLUSTER_TIME = 'clusterTime'.freeze
59
+ CLUSTER_TIME = 'clusterTime'
62
60
 
63
61
  # Instantiate the new cluster.
64
62
  #
@@ -118,14 +116,10 @@ module Mongo
118
116
  #
119
117
  # @since 2.0.0
120
118
  def initialize(seeds, monitoring, options = Options::Redacted.new)
121
- if seeds.nil?
122
- raise ArgumentError, 'Seeds cannot be nil'
123
- end
119
+ raise ArgumentError, 'Seeds cannot be nil' if seeds.nil?
124
120
 
125
121
  options = options.dup
126
- if options[:monitoring_io] == false && !options.key?(:cleanup)
127
- options[:cleanup] = false
128
- end
122
+ options[:cleanup] = false if options[:monitoring_io] == false && !options.key?(:cleanup)
129
123
  @tracer = options.delete(:tracer)
130
124
  @options = options.freeze
131
125
 
@@ -148,7 +142,7 @@ module Mongo
148
142
  @server_selection_semaphore = Semaphore.new
149
143
  @topology = Topology.initial(self, monitoring, options)
150
144
  # State change lock is similar to the sdam flow lock, but is designed
151
- # to serialize state changes initated by consumers of Cluster
145
+ # to serialize state changes initiated by consumers of Cluster
152
146
  # (e.g. application connecting or disconnecting the cluster), so that
153
147
  # e.g. an application calling disconnect-connect-disconnect rapidly
154
148
  # does not put the cluster into an inconsistent state.
@@ -160,9 +154,7 @@ module Mongo
160
154
  @sdam_flow_lock = Mutex.new
161
155
  @session_pool = Session::SessionPool.new(self)
162
156
 
163
- if seeds.empty? && load_balanced?
164
- raise ArgumentError, 'Load-balanced clusters with no seeds are prohibited'
165
- end
157
+ raise ArgumentError, 'Load-balanced clusters with no seeds are prohibited' if seeds.empty? && load_balanced?
166
158
 
167
159
  # The opening topology is always unknown with no servers.
168
160
  # https://github.com/mongodb/specifications/pull/388
@@ -222,62 +214,59 @@ module Mongo
222
214
  @cursor_reaper = CursorReaper.new(self)
223
215
  @socket_reaper = SocketReaper.new(self)
224
216
  @periodic_executor = PeriodicExecutor.new([
225
- @cursor_reaper, @socket_reaper,
226
- ], options)
217
+ @cursor_reaper, @socket_reaper,
218
+ ], options)
227
219
 
228
220
  @periodic_executor.run!
229
221
  end
230
222
 
231
- unless load_balanced?
232
- # Need to record start time prior to starting monitoring
233
- start_monotime = Utils.monotonic_time
223
+ return if load_balanced?
234
224
 
235
- servers.each do |server|
236
- server.start_monitoring
237
- end
225
+ # Need to record start time prior to starting monitoring
226
+ start_monotime = Utils.monotonic_time
227
+
228
+ servers.each do |server|
229
+ server.start_monitoring
230
+ end
238
231
 
239
- if options[:scan] != false
240
- server_selection_timeout = options[:server_selection_timeout] || ServerSelector::SERVER_SELECTION_TIMEOUT
241
- # The server selection timeout can be very short especially in
242
- # tests, when the client waits for a synchronous scan before
243
- # starting server selection. Limiting the scan to server selection time
244
- # then aborts the scan before it can process even local servers.
245
- # Therefore, allow at least 3 seconds for the scan here.
246
- if server_selection_timeout < 3
247
- server_selection_timeout = 3
232
+ if options[:scan] != false
233
+ server_selection_timeout = options[:server_selection_timeout] || ServerSelector::SERVER_SELECTION_TIMEOUT
234
+ # The server selection timeout can be very short especially in
235
+ # tests, when the client waits for a synchronous scan before
236
+ # starting server selection. Limiting the scan to server selection time
237
+ # then aborts the scan before it can process even local servers.
238
+ # Therefore, allow at least 3 seconds for the scan here.
239
+ server_selection_timeout = 3 if server_selection_timeout < 3
240
+ deadline = start_monotime + server_selection_timeout
241
+ # Wait for the first scan of each server to complete, for
242
+ # backwards compatibility.
243
+ # If any servers are discovered during this SDAM round we are going to
244
+ # wait for these servers to also be queried, and so on, up to the
245
+ # server selection timeout or the 3 second minimum.
246
+ loop do
247
+ # Ensure we do not try to read the servers list while SDAM is running
248
+ servers = @sdam_flow_lock.synchronize do
249
+ servers_list.dup
248
250
  end
249
- deadline = start_monotime + server_selection_timeout
250
- # Wait for the first scan of each server to complete, for
251
- # backwards compatibility.
252
- # If any servers are discovered during this SDAM round we are going to
253
- # wait for these servers to also be queried, and so on, up to the
254
- # server selection timeout or the 3 second minimum.
255
- loop do
256
- # Ensure we do not try to read the servers list while SDAM is running
257
- servers = @sdam_flow_lock.synchronize do
258
- servers_list.dup
259
- end
260
- if servers.all? { |server| server.last_scan_monotime && server.last_scan_monotime >= start_monotime }
261
- break
262
- end
263
- if (time_remaining = deadline - Utils.monotonic_time) <= 0
264
- break
265
- end
266
- log_debug("Waiting for up to #{'%.2f' % time_remaining} seconds for servers to be scanned: #{summary}")
267
- # Since the semaphore may have been signaled between us checking
268
- # the servers list above and the wait call below, we should not
269
- # wait for the full remaining time - wait for up to 0.5 second, then
270
- # recheck the state.
271
- begin
272
- server_selection_semaphore.wait([time_remaining, 0.5].min)
273
- rescue ::Timeout::Error
274
- # nothing
275
- end
251
+ break if servers.all? { |server| server.last_scan_monotime && server.last_scan_monotime >= start_monotime }
252
+ if (time_remaining = deadline - Utils.monotonic_time) <= 0
253
+ break
276
254
  end
277
- end
278
255
 
279
- start_stop_srv_monitor
256
+ log_debug("Waiting for up to #{'%.2f' % time_remaining} seconds for servers to be scanned: #{summary}")
257
+ # Since the semaphore may have been signaled between us checking
258
+ # the servers list above and the wait call below, we should not
259
+ # wait for the full remaining time - wait for up to 0.5 second, then
260
+ # recheck the state.
261
+ begin
262
+ server_selection_semaphore.wait([ time_remaining, 0.5 ].min)
263
+ rescue ::Timeout::Error
264
+ # nothing
265
+ end
266
+ end
280
267
  end
268
+
269
+ start_stop_srv_monitor
281
270
  end
282
271
 
283
272
  # Create a cluster for the provided client, for use when we don't want the
@@ -351,11 +340,11 @@ module Mongo
351
340
  topology.is_a?(Topology::LoadBalanced)
352
341
  end
353
342
 
354
- [:register_cursor, :schedule_kill_cursor, :unregister_cursor].each do |m|
343
+ %i[register_cursor schedule_kill_cursor unregister_cursor].each do |m|
355
344
  define_method(m) do |*args|
356
- if options[:cleanup] != false
357
- @cursor_reaper.send(m, *args)
358
- end
345
+ return unless options[:cleanup] != false
346
+
347
+ @cursor_reaper.send(m, *args)
359
348
  end
360
349
  end
361
350
 
@@ -484,9 +473,9 @@ module Mongo
484
473
  # @api experimental
485
474
  # @since 2.7.0
486
475
  def summary
487
- "#<Cluster " +
488
- "topology=#{topology.summary} "+
489
- "servers=[#{servers_list.map(&:summary).join(',')}]>"
476
+ '#<Cluster ' +
477
+ "topology=#{topology.summary} " +
478
+ "servers=[#{servers_list.map(&:summary).join(',')}]>"
490
479
  end
491
480
 
492
481
  # @api private
@@ -510,26 +499,23 @@ module Mongo
510
499
  # @api private
511
500
  def close
512
501
  @state_change_lock.synchronize do
513
- unless connecting? || connected?
514
- return nil
515
- end
502
+ return nil unless connecting? || connected?
503
+
516
504
  if options[:cleanup] != false
517
505
  session_pool.end_sessions
518
506
  @periodic_executor.stop!
519
507
  end
520
508
  @srv_monitor_lock.synchronize do
521
- if @srv_monitor
522
- @srv_monitor.stop!
523
- end
509
+ @srv_monitor.stop! if @srv_monitor
524
510
  end
525
511
  @servers.each do |server|
526
- if server.connected?
527
- server.close
528
- publish_sdam_event(
529
- Monitoring::SERVER_CLOSED,
530
- Monitoring::Event::ServerClosed.new(server.address, topology)
531
- )
532
- end
512
+ next unless server.connected?
513
+
514
+ server.close
515
+ publish_sdam_event(
516
+ Monitoring::SERVER_CLOSED,
517
+ Monitoring::Event::ServerClosed.new(server.address, topology)
518
+ )
533
519
  end
534
520
  publish_sdam_event(
535
521
  Monitoring::TOPOLOGY_CLOSED,
@@ -563,9 +549,7 @@ module Mongo
563
549
  end
564
550
  @periodic_executor.restart!
565
551
  @srv_monitor_lock.synchronize do
566
- if @srv_monitor
567
- @srv_monitor.run!
568
- end
552
+ @srv_monitor.run! if @srv_monitor
569
553
  end
570
554
  @update_lock.synchronize do
571
555
  @connecting = false
@@ -597,7 +581,7 @@ module Mongo
597
581
  # @return [ true ] Always true.
598
582
  #
599
583
  # @since 2.0.0
600
- def scan!(sync=true)
584
+ def scan!(sync = true)
601
585
  if sync
602
586
  servers_list.each do |server|
603
587
  if server.monitor
@@ -640,16 +624,14 @@ module Mongo
640
624
  # @api private
641
625
  def run_sdam_flow(previous_desc, updated_desc, options = {})
642
626
  if load_balanced?
643
- if updated_desc.config.empty?
644
- unless options[:keep_connection_pool]
645
- servers_list.each do |server|
646
- # TODO should service id be taken out of updated_desc?
647
- # We could also assert that
648
- # options[:service_id] == updated_desc.service_id
649
- err = options[:scan_error]
650
- interrupt = err && (err.is_a?(Error::SocketError) || err.is_a?(Error::SocketTimeoutError))
651
- server.clear_connection_pool(service_id: options[:service_id], interrupt_in_use_connections: interrupt)
652
- end
627
+ if updated_desc.config.empty? && !options[:keep_connection_pool]
628
+ servers_list.each do |server|
629
+ # TODO: should service id be taken out of updated_desc?
630
+ # We could also assert that
631
+ # options[:service_id] == updated_desc.service_id
632
+ err = options[:scan_error]
633
+ interrupt = err && (err.is_a?(Error::SocketError) || err.is_a?(Error::SocketTimeoutError))
634
+ server.clear_connection_pool(service_id: options[:service_id], interrupt_in_use_connections: interrupt)
653
635
  end
654
636
  end
655
637
  return
@@ -657,22 +639,20 @@ module Mongo
657
639
 
658
640
  @sdam_flow_lock.synchronize do
659
641
  flow = SdamFlow.new(self, previous_desc, updated_desc,
660
- awaited: options[:awaited])
642
+ awaited: options[:awaited])
661
643
  flow.server_description_changed
662
644
 
663
645
  # SDAM flow may alter the updated description - grab the final
664
646
  # version for the purposes of broadcasting if a server is available
665
647
  updated_desc = flow.updated_desc
666
648
 
667
- unless options[:keep_connection_pool]
668
- if flow.became_unknown?
669
- servers_list.each do |server|
670
- if server.address == updated_desc.address
671
- err = options[:scan_error]
672
- interrupt = err && (err.is_a?(Error::SocketError) || err.is_a?(Error::SocketTimeoutError))
673
- server.clear_connection_pool(interrupt_in_use_connections: interrupt)
674
- end
675
- end
649
+ if !options[:keep_connection_pool] && flow.became_unknown?
650
+ servers_list.each do |server|
651
+ next unless server.address == updated_desc.address
652
+
653
+ err = options[:scan_error]
654
+ interrupt = err && (err.is_a?(Error::SocketError) || err.is_a?(Error::SocketTimeoutError))
655
+ server.clear_connection_pool(interrupt_in_use_connections: interrupt)
676
656
  end
677
657
  end
678
658
 
@@ -690,9 +670,9 @@ module Mongo
690
670
  # thread got killed the server should have been closed and no client
691
671
  # should be currently waiting for it, thus not signaling the semaphore
692
672
  # shouldn't cause any problems.
693
- unless updated_desc.unknown?
694
- server_selection_semaphore.broadcast
695
- end
673
+ return if updated_desc.unknown?
674
+
675
+ server_selection_semaphore.broadcast
696
676
  end
697
677
 
698
678
  # Sets the list of servers to the addresses in the provided list of address
@@ -714,9 +694,7 @@ module Mongo
714
694
  # If one of the new addresses is not in the current servers list,
715
695
  # add it to the servers list.
716
696
  server_address_strs.each do |address_str|
717
- unless servers_list.any? { |server| server.address.seed == address_str }
718
- add(address_str)
719
- end
697
+ add(address_str) unless servers_list.any? { |server| server.address.seed == address_str }
720
698
  end
721
699
 
722
700
  # If one of the servers' addresses are not in the new address list,
@@ -742,6 +720,7 @@ module Mongo
742
720
  # @since 2.0.0
743
721
  def ==(other)
744
722
  return false unless other.is_a?(Cluster)
723
+
745
724
  addresses == other.addresses && options == other.options
746
725
  end
747
726
 
@@ -788,7 +767,7 @@ module Mongo
788
767
  # @return [ Mongo::Server ] A primary server.
789
768
  #
790
769
  # @since 2.0.0
791
- def next_primary(ping = nil, session = nil, timeout: nil)
770
+ def next_primary(_ping = nil, session = nil, timeout: nil)
792
771
  ServerSelector.primary.select_server(
793
772
  self,
794
773
  nil,
@@ -823,10 +802,10 @@ module Mongo
823
802
  #
824
803
  # @since 2.5.0
825
804
  def update_cluster_time(result)
826
- if cluster_time_doc = result.cluster_time
827
- @cluster_time_lock.synchronize do
828
- advance_cluster_time(cluster_time_doc)
829
- end
805
+ return unless cluster_time_doc = result.cluster_time
806
+
807
+ @cluster_time_lock.synchronize do
808
+ advance_cluster_time(cluster_time_doc)
830
809
  end
831
810
  end
832
811
 
@@ -845,34 +824,32 @@ module Mongo
845
824
  # @return [ Server ] The newly added server, if not present already.
846
825
  #
847
826
  # @since 2.0.0
848
- def add(host, add_options=nil)
827
+ def add(host, add_options = nil)
849
828
  address = Address.new(host, options)
850
- if !addresses.include?(address)
851
- opts = options.merge(monitor: false)
852
- # If we aren't starting the montoring threads, we also don't want to
853
- # start the pool's populator thread.
854
- opts.merge!(populator_io: false) unless options.fetch(:monitoring_io, true)
855
- # Note that in a load-balanced topology, every server must be a
856
- # load balancer (load_balancer: true is specified in the options)
857
- # but this option isn't set here because we are required by the
858
- # specifications to pretent the server started out as an unknown one
859
- # and publish server description change event into the load balancer
860
- # one. The actual correct description for this server will be set
861
- # by the fabricate_lb_sdam_events_and_set_server_type method.
862
- server = Server.new(address, self, @monitoring, event_listeners, opts)
863
- @update_lock.synchronize do
864
- # Need to recheck whether server is present in @servers, because
865
- # the previous check was not under a lock.
866
- # Since we are under the update lock here, we cannot call servers_list.
867
- return if @servers.map(&:address).include?(address)
829
+ return if addresses.include?(address)
830
+
831
+ opts = options.merge(monitor: false)
832
+ # If we aren't starting the monitoring threads, we also don't want to
833
+ # start the pool's populator thread.
834
+ opts.merge!(populator_io: false) unless options.fetch(:monitoring_io, true)
835
+ # Note that in a load-balanced topology, every server must be a
836
+ # load balancer (load_balancer: true is specified in the options)
837
+ # but this option isn't set here because we are required by the
838
+ # specifications to pretend the server started out as an unknown one
839
+ # and publish server description change event into the load balancer
840
+ # one. The actual correct description for this server will be set
841
+ # by the fabricate_lb_sdam_events_and_set_server_type method.
842
+ server = Server.new(address, self, @monitoring, event_listeners, opts)
843
+ @update_lock.synchronize do
844
+ # Need to recheck whether server is present in @servers, because
845
+ # the previous check was not under a lock.
846
+ # Since we are under the update lock here, we cannot call servers_list.
847
+ return if @servers.map(&:address).include?(address)
868
848
 
869
- @servers.push(server)
870
- end
871
- if add_options.nil? || add_options[:monitor] != false
872
- server.start_monitoring
873
- end
874
- server
849
+ @servers.push(server)
875
850
  end
851
+ server.start_monitoring if add_options.nil? || add_options[:monitor] != false
852
+ server
876
853
  end
877
854
 
878
855
  # Remove the server from the cluster for the provided address, if it
@@ -900,9 +877,7 @@ module Mongo
900
877
  @update_lock.synchronize do
901
878
  @servers.delete_if do |server|
902
879
  (server.address == address).tap do |delete|
903
- if delete
904
- removed_servers << server
905
- end
880
+ removed_servers << server if delete
906
881
  end
907
882
  end
908
883
  end
@@ -911,10 +886,10 @@ module Mongo
911
886
  disconnect_server_if_connected(server)
912
887
  end
913
888
  end
914
- if disconnect != false
915
- removed_servers.any?
916
- else
889
+ if disconnect == false
917
890
  removed_servers
891
+ else
892
+ removed_servers.any?
918
893
  end
919
894
  end
920
895
 
@@ -954,14 +929,14 @@ module Mongo
954
929
 
955
930
  # @api private
956
931
  def disconnect_server_if_connected(server)
957
- if server.connected?
958
- server.clear_description
959
- server.disconnect!
960
- publish_sdam_event(
961
- Monitoring::SERVER_CLOSED,
962
- Monitoring::Event::ServerClosed.new(server.address, topology)
963
- )
964
- end
932
+ return unless server.connected?
933
+
934
+ server.clear_description
935
+ server.disconnect!
936
+ publish_sdam_event(
937
+ Monitoring::SERVER_CLOSED,
938
+ Monitoring::Event::ServerClosed.new(server.address, topology)
939
+ )
965
940
  end
966
941
 
967
942
  # Raises Error::SessionsNotAvailable if the deployment that the driver
@@ -989,17 +964,11 @@ module Mongo
989
964
  #
990
965
  # @api private
991
966
  def validate_session_support!(timeout: nil)
992
- if topology.is_a?(Topology::LoadBalanced)
993
- return
994
- end
967
+ return if topology.is_a?(Topology::LoadBalanced)
995
968
 
996
969
  @state_change_lock.synchronize do
997
970
  @sdam_flow_lock.synchronize do
998
- if topology.data_bearing_servers?
999
- unless topology.logical_session_timeout
1000
- raise_sessions_not_supported
1001
- end
1002
- end
971
+ raise_sessions_not_supported if topology.data_bearing_servers? && !topology.logical_session_timeout
1003
972
  end
1004
973
  end
1005
974
 
@@ -1009,9 +978,7 @@ module Mongo
1009
978
  ServerSelector.get(mode: :primary_preferred).select_server(self, timeout: timeout)
1010
979
  @state_change_lock.synchronize do
1011
980
  @sdam_flow_lock.synchronize do
1012
- unless topology.logical_session_timeout
1013
- raise_sessions_not_supported
1014
- end
981
+ raise_sessions_not_supported unless topology.logical_session_timeout
1015
982
  end
1016
983
  end
1017
984
  end
@@ -1029,7 +996,8 @@ module Mongo
1029
996
  @srv_monitor_lock.synchronize do
1030
997
  unless @srv_monitor
1031
998
  monitor_options = Utils.shallow_symbolize_keys(options.merge(
1032
- timeout: options[:connect_timeout] || Server::CONNECT_TIMEOUT))
999
+ timeout: options[:connect_timeout] || Server::CONNECT_TIMEOUT
1000
+ ))
1033
1001
  @srv_monitor = _srv_monitor = Srv::Monitor.new(self, **monitor_options)
1034
1002
  end
1035
1003
  @srv_monitor.run!
@@ -1040,9 +1008,7 @@ module Mongo
1040
1008
  # is discovered, since it's not a sharded cluster, the SRV monitor
1041
1009
  # needs to be stopped.
1042
1010
  @srv_monitor_lock.synchronize do
1043
- if @srv_monitor
1044
- @srv_monitor.stop!
1045
- end
1011
+ @srv_monitor.stop! if @srv_monitor
1046
1012
  end
1047
1013
  end
1048
1014
  end
@@ -1055,10 +1021,10 @@ module Mongo
1055
1021
  server.description.data_bearing? && server.logical_session_timeout.nil?
1056
1022
  end
1057
1023
  reason = if offending_servers.empty?
1058
- "There are no known data bearing servers (current seeds: #{@servers.map(&:address).map(&:seed).join(', ')})"
1059
- else
1060
- "The following servers have null logical session timeout: #{offending_servers.map(&:address).map(&:seed).join(', ')}"
1061
- end
1024
+ "There are no known data bearing servers (current seeds: #{@servers.map(&:address).map(&:seed).join(', ')})"
1025
+ else
1026
+ "The following servers have null logical session timeout: #{offending_servers.map(&:address).map(&:seed).join(', ')}"
1027
+ end
1062
1028
  msg = "The deployment that the driver is connected to does not support sessions: #{reason}"
1063
1029
  raise Error::SessionsNotSupported, msg
1064
1030
  end
@@ -1074,9 +1040,8 @@ module Mongo
1074
1040
  # description.
1075
1041
  server.update_description(
1076
1042
  Server::Description.new(server.address, {},
1077
- load_balancer: true,
1078
- force_load_balancer: options[:connect] == :load_balanced,
1079
- )
1043
+ load_balancer: true,
1044
+ force_load_balancer: options[:connect] == :load_balanced)
1080
1045
  )
1081
1046
  publish_sdam_event(
1082
1047
  Monitoring::SERVER_DESCRIPTION_CHANGED,
@@ -1100,13 +1065,13 @@ module Mongo
1100
1065
 
1101
1066
  COSMOSDB_HOST_PATTERNS = %w[ .cosmos.azure.com ]
1102
1067
  COSMOSDB_LOG_MESSAGE = 'You appear to be connected to a CosmosDB cluster. ' \
1103
- 'For more information regarding feature compatibility and support please visit ' \
1104
- 'https://www.mongodb.com/supportability/cosmosdb'
1068
+ 'For more information regarding feature compatibility and support please visit ' \
1069
+ 'https://www.mongodb.com/supportability/cosmosdb'
1105
1070
 
1106
1071
  DOCUMENTDB_HOST_PATTERNS = %w[ .docdb.amazonaws.com .docdb-elastic.amazonaws.com ]
1107
1072
  DOCUMENTDB_LOG_MESSAGE = 'You appear to be connected to a DocumentDB cluster. ' \
1108
- 'For more information regarding feature compatibility and support please visit ' \
1109
- 'https://www.mongodb.com/supportability/documentdb'
1073
+ 'For more information regarding feature compatibility and support please visit ' \
1074
+ 'https://www.mongodb.com/supportability/documentdb'
1110
1075
 
1111
1076
  # Compares the server hosts with address suffixes of known services
1112
1077
  # that provide limited MongoDB API compatibility, and warns about them.
@@ -1116,10 +1081,10 @@ module Mongo
1116
1081
  return
1117
1082
  end
1118
1083
 
1119
- if topology.server_hosts_match_any?(DOCUMENTDB_HOST_PATTERNS)
1120
- log_info DOCUMENTDB_LOG_MESSAGE
1121
- return
1122
- end
1084
+ return unless topology.server_hosts_match_any?(DOCUMENTDB_HOST_PATTERNS)
1085
+
1086
+ log_info DOCUMENTDB_LOG_MESSAGE
1087
+ nil
1123
1088
  end
1124
1089
  end
1125
1090
  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
  #
@@ -27,12 +26,14 @@ module Mongo
27
26
  #
28
27
  # @api private
29
28
  class ClusterTime < BSON::Document
29
+ include Comparable
30
+
30
31
  def initialize(elements = nil)
31
32
  super
32
33
 
33
- if Lint.enabled? && !self['clusterTime']
34
- raise ArgumentError, 'Creating a cluster time without clusterTime field'
35
- end
34
+ return unless Lint.enabled? && !self['clusterTime']
35
+
36
+ raise ArgumentError, 'Creating a cluster time without clusterTime field'
36
37
  end
37
38
 
38
39
  # Advances the cluster time in the receiver to the cluster time in +other+.
@@ -44,8 +45,7 @@ module Mongo
44
45
  # Return value is nil or a ClusterTime instance.
45
46
  def advance(other)
46
47
  if self['clusterTime'] && other['clusterTime'] &&
47
- other['clusterTime'] > self['clusterTime']
48
- then
48
+ other['clusterTime'] > self['clusterTime']
49
49
  ClusterTime[other]
50
50
  else
51
51
  self
@@ -58,32 +58,16 @@ module Mongo
58
58
  self['clusterTime'] <=> other['clusterTime']
59
59
  elsif !self['clusterTime']
60
60
  raise ArgumentError, "Cannot compare cluster times when receiver is missing clusterTime key: #{inspect}"
61
- else other['clusterTime']
61
+ else
62
+ other['clusterTime']
62
63
  raise ArgumentError, "Cannot compare cluster times when other is missing clusterTime key: #{other.inspect}"
63
64
  end
64
65
  end
65
66
 
66
- # Older Rubies do not implement other logical operators through <=>.
67
- # TODO revise whether these methods are needed when
68
- # https://jira.mongodb.org/browse/RUBY-1622 is implemented.
69
- def >=(other)
70
- (self <=> other) != -1
71
- end
72
- def >(other)
73
- (self <=> other) == 1
74
- end
75
- def <=(other)
76
- (self <=> other) != 1
77
- end
78
- def <(other)
79
- (self <=> other) == -1
80
- end
81
-
82
67
  # Compares two ClusterTime instances by comparing their timestamps.
83
68
  def ==(other)
84
69
  if self['clusterTime'] && other['clusterTime'] &&
85
- self['clusterTime'] == other['clusterTime']
86
- then
70
+ self['clusterTime'] == other['clusterTime']
87
71
  true
88
72
  else
89
73
  false
@@ -110,7 +94,6 @@ module Mongo
110
94
  # the methods are defined on this module and not directly on the
111
95
  # including classes is not part of the public API.
112
96
  module Consumer
113
-
114
97
  # The cluster time tracked by the object including this module.
115
98
  #
116
99
  # @return [ nil | ClusterTime ] The cluster time.
@@ -131,11 +114,11 @@ module Mongo
131
114
  #
132
115
  # @since 2.5.0
133
116
  def advance_cluster_time(new_cluster_time)
134
- if @cluster_time
135
- @cluster_time = @cluster_time.advance(new_cluster_time)
136
- else
137
- @cluster_time = ClusterTime[new_cluster_time]
138
- end
117
+ @cluster_time = if @cluster_time
118
+ @cluster_time.advance(new_cluster_time)
119
+ else
120
+ ClusterTime[new_cluster_time]
121
+ end
139
122
  end
140
123
  end
141
124
  end