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
  #
@@ -19,7 +18,6 @@ require 'mongo/cursor/nontailable'
19
18
 
20
19
  module Mongo
21
20
  module Index
22
-
23
21
  # A class representing a view of indexes.
24
22
  #
25
23
  # @since 2.0.0
@@ -50,39 +48,39 @@ module Mongo
50
48
  # The index key field.
51
49
  #
52
50
  # @since 2.0.0
53
- KEY = 'key'.freeze
51
+ KEY = 'key'
54
52
 
55
53
  # The index name field.
56
54
  #
57
55
  # @since 2.0.0
58
- NAME = 'name'.freeze
56
+ NAME = 'name'
59
57
 
60
58
  # The mappings of Ruby index options to server options.
61
59
  #
62
60
  # @since 2.0.0
63
61
  OPTIONS = {
64
- :background => :background,
65
- :bits => :bits,
66
- :bucket_size => :bucketSize,
67
- :default_language => :default_language,
68
- :expire_after => :expireAfterSeconds,
69
- :expire_after_seconds => :expireAfterSeconds,
70
- :key => :key,
71
- :language_override => :language_override,
72
- :max => :max,
73
- :min => :min,
74
- :name => :name,
75
- :partial_filter_expression => :partialFilterExpression,
76
- :sparse => :sparse,
77
- :sphere_version => :'2dsphereIndexVersion',
78
- :storage_engine => :storageEngine,
79
- :text_version => :textIndexVersion,
80
- :unique => :unique,
81
- :version => :v,
82
- :weights => :weights,
83
- :collation => :collation,
84
- :comment => :comment,
85
- :wildcard_projection => :wildcardProjection,
62
+ background: :background,
63
+ bits: :bits,
64
+ bucket_size: :bucketSize,
65
+ default_language: :default_language,
66
+ expire_after: :expireAfterSeconds,
67
+ expire_after_seconds: :expireAfterSeconds,
68
+ key: :key,
69
+ language_override: :language_override,
70
+ max: :max,
71
+ min: :min,
72
+ name: :name,
73
+ partial_filter_expression: :partialFilterExpression,
74
+ sparse: :sparse,
75
+ sphere_version: :'2dsphereIndexVersion',
76
+ storage_engine: :storageEngine,
77
+ text_version: :textIndexVersion,
78
+ unique: :unique,
79
+ version: :v,
80
+ weights: :weights,
81
+ collation: :collation,
82
+ comment: :comment,
83
+ wildcard_projection: :wildcardProjection,
86
84
  }.freeze
87
85
 
88
86
  # Drop an index by its name.
@@ -101,6 +99,7 @@ module Mongo
101
99
  # @since 2.0.0
102
100
  def drop_one(name, options = {})
103
101
  raise Error::MultiIndexDrop.new if name == Index::ALL
102
+
104
103
  drop_by_name(name, options)
105
104
  end
106
105
 
@@ -132,7 +131,7 @@ module Mongo
132
131
  # @option options [ true, false ] :unique (false) If true, this index will enforce
133
132
  # a uniqueness constraint on that field.
134
133
  # @option options [ true, false ] :background (false) If true, the index will be built
135
- # in the background (only available for server versions >= 1.3.2 )
134
+ # in the background
136
135
  # @option options [ true, false ] :drop_dups (false) If creating a unique index on
137
136
  # this collection, this option will keep the first document the database indexes
138
137
  # and drop all subsequent documents with duplicate values on this field.
@@ -172,7 +171,7 @@ module Mongo
172
171
  if session = @options[:session]
173
172
  create_options[:session] = session
174
173
  end
175
- %i(commit_quorum session comment timeout_ms max_time_ms).each do |key|
174
+ %i[commit_quorum session comment timeout_ms max_time_ms].each do |key|
176
175
  if value = options.delete(key)
177
176
  create_options[key] = value
178
177
  end
@@ -195,9 +194,6 @@ module Mongo
195
194
  # { commit_quorum: 'majority' }
196
195
  # )
197
196
  #
198
- # @note On MongoDB 3.0.0 and higher, the indexes will be created in
199
- # parallel on the server.
200
- #
201
197
  # @param [ Array<Hash> ] models The index specifications. Each model MUST
202
198
  # include a :key option, except for the last item in the Array, which
203
199
  # may be a Hash specifying options relevant to the createIndexes operation.
@@ -217,15 +213,13 @@ module Mongo
217
213
  def create_many(*models)
218
214
  models = models.flatten
219
215
  options = {}
220
- if models && !models.last.key?(:key)
221
- options = models.pop
222
- end
216
+ options = models.pop if models && !models.last.key?(:key)
223
217
 
224
218
  client.with_session(@options.merge(options)) do |session|
225
219
  indexes = normalize_models(models)
226
220
  indexes.each do |index|
227
221
  if index[:bucketSize] || index['bucketSize']
228
- client.log_warn("Haystack indexes (bucketSize index option) are deprecated as of MongoDB 4.4")
222
+ client.log_warn('Haystack indexes (bucketSize index option) are deprecated as of MongoDB 4.4')
229
223
  end
230
224
  end
231
225
 
@@ -245,8 +239,11 @@ module Mongo
245
239
  )
246
240
  operation = Operation::CreateIndex.new(spec)
247
241
  tracer.trace_operation(operation, context, op_name: 'createIndexes') do
248
- server = next_primary(nil, session)
249
- operation.execute(server, context: context)
242
+ retry_enabled = collection.client.options[:retry_writes] != false
243
+ with_overload_retry(context: context, retry_enabled: retry_enabled) do
244
+ server = next_primary(nil, session)
245
+ operation.execute(server, context: context)
246
+ end
250
247
  end
251
248
  end
252
249
  end
@@ -292,9 +289,7 @@ module Mongo
292
289
  send_initial_query(op, server, session, context)
293
290
  end
294
291
  if block_given?
295
- cursor.each do |doc|
296
- yield doc
297
- end
292
+ cursor.each(&block)
298
293
  else
299
294
  cursor.to_enum
300
295
  end
@@ -370,10 +365,13 @@ module Mongo
370
365
  operation_timeouts: operation_timeouts(opts)
371
366
  )
372
367
  op = Operation::DropIndex.new(spec)
373
- op_name = name == Index::ALL ? 'dropIndexes' : 'dropIndex'
368
+ op_name = (name == Index::ALL) ? 'dropIndexes' : 'dropIndex'
374
369
  tracer.trace_operation(op, context, op_name: op_name) do
375
- server = next_primary(nil, session)
376
- op.execute(server, context: context)
370
+ retry_enabled = collection.client.options[:retry_writes] != false
371
+ with_overload_retry(context: context, retry_enabled: retry_enabled) do
372
+ server = next_primary(nil, session)
373
+ op.execute(server, context: context)
374
+ end
377
375
  end
378
376
  end
379
377
  end
@@ -385,21 +383,24 @@ module Mongo
385
383
  def indexes_spec(session)
386
384
  { selector: {
387
385
  listIndexes: collection.name,
388
- cursor: batch_size ? { batchSize: batch_size } : {} },
386
+ cursor: batch_size ? { batchSize: batch_size } : {}
387
+ },
389
388
  coll_name: collection.name,
390
389
  db_name: database.name,
391
- session: session
392
- }
390
+ session: session }
393
391
  end
394
392
 
395
393
  def initial_query_op(session)
396
394
  Operation::Indexes.new(indexes_spec(session))
397
395
  end
398
396
 
399
- def limit; -1; end
397
+ def limit
398
+ -1
399
+ end
400
400
 
401
401
  def normalize_keys(spec)
402
402
  return false if spec.is_a?(String)
403
+
403
404
  Options::Mapper.transform_keys_to_strings(spec)
404
405
  end
405
406
 
@@ -412,7 +413,7 @@ module Mongo
412
413
  end
413
414
  end
414
415
 
415
- def send_initial_query(op, server, session, context)
416
+ def send_initial_query(op, server, _session, context)
416
417
  if server.load_balancer?
417
418
  connection = server.pool.check_out(context: context)
418
419
  op.execute_with_connection(connection, context: context)
data/lib/mongo/index.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
  #
@@ -18,16 +17,14 @@
18
17
  require 'mongo/index/view'
19
18
 
20
19
  module Mongo
21
-
22
20
  # Contains constants for indexing purposes.
23
21
  #
24
22
  # @since 2.0.0
25
23
  module Index
26
-
27
24
  # Wildcard constant for all.
28
25
  #
29
26
  # @since 2.1.0
30
- ALL = '*'.freeze
27
+ ALL = '*'
31
28
 
32
29
  # Specify ascending order for an index.
33
30
  #
@@ -42,32 +39,32 @@ module Mongo
42
39
  # Specify a 2d Geo index.
43
40
  #
44
41
  # @since 2.0.0
45
- GEO2D = '2d'.freeze
42
+ GEO2D = '2d'
46
43
 
47
44
  # Specify a 2d sphere Geo index.
48
45
  #
49
46
  # @since 2.0.0
50
- GEO2DSPHERE = '2dsphere'.freeze
47
+ GEO2DSPHERE = '2dsphere'
51
48
 
52
49
  # Specify a geoHaystack index.
53
50
  #
54
51
  # @since 2.0.0
55
52
  # @deprecated
56
- GEOHAYSTACK = 'geoHaystack'.freeze
53
+ GEOHAYSTACK = 'geoHaystack'
57
54
 
58
55
  # Encodes a text index.
59
56
  #
60
57
  # @since 2.0.0
61
- TEXT = 'text'.freeze
58
+ TEXT = 'text'
62
59
 
63
60
  # Specify a hashed index.
64
61
  #
65
62
  # @since 2.0.0
66
- HASHED = 'hashed'.freeze
63
+ HASHED = 'hashed'
67
64
 
68
65
  # Constant for the indexes collection.
69
66
  #
70
67
  # @since 2.0.0
71
- COLLECTION = 'system.indexes'.freeze
68
+ COLLECTION = 'system.indexes'
72
69
  end
73
70
  end
data/lib/mongo/lint.rb CHANGED
@@ -1,57 +1,52 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:todo all
3
2
 
4
3
  module Mongo
5
-
6
4
  # @api private
7
5
  module Lint
8
-
9
6
  # Raises LintError if +obj+ is not of type +cls+.
10
7
  def assert_type(obj, cls)
11
8
  return unless enabled?
12
- unless obj.is_a?(cls)
13
- raise Error::LintError, "Expected #{obj} to be a #{cls}"
14
- end
9
+ return if obj.is_a?(cls)
10
+
11
+ raise Error::LintError, "Expected #{obj} to be a #{cls}"
15
12
  end
16
13
  module_function :assert_type
17
14
 
18
15
  def validate_underscore_read_preference(read_pref)
19
16
  return unless enabled?
20
17
  return if read_pref.nil?
21
- unless read_pref.is_a?(Hash)
22
- raise Error::LintError, "Read preference is not a hash: #{read_pref}"
23
- end
18
+ raise Error::LintError, "Read preference is not a hash: #{read_pref}" unless read_pref.is_a?(Hash)
19
+
24
20
  validate_underscore_read_preference_mode(read_pref[:mode] || read_pref['mode'])
25
21
  end
26
22
  module_function :validate_underscore_read_preference
27
23
 
28
24
  def validate_underscore_read_preference_mode(mode)
29
25
  return unless enabled?
30
- if mode
31
- unless %w(primary primary_preferred secondary secondary_preferred nearest).include?(mode.to_s)
32
- raise Error::LintError, "Invalid read preference mode: #{mode}"
33
- end
34
- end
26
+
27
+ return unless mode
28
+ return if %w[primary primary_preferred secondary secondary_preferred nearest].include?(mode.to_s)
29
+
30
+ raise Error::LintError, "Invalid read preference mode: #{mode}"
35
31
  end
36
32
  module_function :validate_underscore_read_preference_mode
37
33
 
38
34
  def validate_camel_case_read_preference(read_pref)
39
35
  return unless enabled?
40
36
  return if read_pref.nil?
41
- unless read_pref.is_a?(Hash)
42
- raise Error::LintError, "Read preference is not a hash: #{read_pref}"
43
- end
37
+ raise Error::LintError, "Read preference is not a hash: #{read_pref}" unless read_pref.is_a?(Hash)
38
+
44
39
  validate_camel_case_read_preference_mode(read_pref[:mode] || read_pref['mode'])
45
40
  end
46
41
  module_function :validate_camel_case_read_preference
47
42
 
48
43
  def validate_camel_case_read_preference_mode(mode)
49
44
  return unless enabled?
50
- if mode
51
- unless %w(primary primaryPreferred secondary secondaryPreferred nearest).include?(mode.to_s)
52
- raise Error::LintError, "Invalid read preference mode: #{mode}"
53
- end
54
- end
45
+
46
+ return unless mode
47
+ return if %w[primary primaryPreferred secondary secondaryPreferred nearest].include?(mode.to_s)
48
+
49
+ raise Error::LintError, "Invalid read preference mode: #{mode}"
55
50
  end
56
51
  module_function :validate_camel_case_read_preference_mode
57
52
 
@@ -76,29 +71,28 @@ module Mongo
76
71
  def validate_read_concern_option(read_concern)
77
72
  return unless enabled?
78
73
  return if read_concern.nil?
79
- unless read_concern.is_a?(Hash)
80
- raise Error::LintError, "Read concern is not a hash: #{read_concern}"
81
- end
74
+ raise Error::LintError, "Read concern is not a hash: #{read_concern}" unless read_concern.is_a?(Hash)
82
75
  return if read_concern.empty?
76
+
83
77
  keys = read_concern.keys
84
- if read_concern.is_a?(BSON::Document)
85
- # Permits indifferent access
86
- allowed_keys = ['level']
87
- else
88
- # Does not permit indifferent access
89
- allowed_keys = [:level]
90
- end
91
- if keys != allowed_keys
92
- raise Error::LintError, "Read concern has invalid keys: #{keys.inspect}"
93
- end
78
+ allowed_keys = if read_concern.is_a?(BSON::Document)
79
+ # Permits indifferent access
80
+ [ 'level' ]
81
+ else
82
+ # Does not permit indifferent access
83
+ [ :level ]
84
+ end
85
+ raise Error::LintError, "Read concern has invalid keys: #{keys.inspect}" if keys != allowed_keys
86
+
94
87
  level = read_concern[:level]
95
- return if [:local, :available, :majority, :linearizable, :snapshot].include?(level)
88
+ return if %i[local available majority linearizable snapshot].include?(level)
89
+
96
90
  raise Error::LintError, "Read concern level is invalid: value must be a symbol: #{level.inspect}"
97
91
  end
98
92
  module_function :validate_read_concern_option
99
93
 
100
94
  def enabled?
101
- ENV['MONGO_RUBY_DRIVER_LINT'] && %w(1 yes true on).include?(ENV['MONGO_RUBY_DRIVER_LINT'].downcase)
95
+ ENV['MONGO_RUBY_DRIVER_LINT'] && %w[1 yes true on].include?(ENV['MONGO_RUBY_DRIVER_LINT'].downcase)
102
96
  end
103
97
  module_function :enabled?
104
98
  end
@@ -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
  #
@@ -16,16 +15,14 @@
16
15
  # limitations under the License.
17
16
 
18
17
  module Mongo
19
-
20
18
  # Allows objects to easily log operations.
21
19
  #
22
20
  # @since 2.0.0
23
21
  module Loggable
24
-
25
22
  # The standard MongoDB log prefix.
26
23
  #
27
24
  # @since 2.0.0
28
- PREFIX = 'MONGODB'.freeze
25
+ PREFIX = 'MONGODB'
29
26
 
30
27
  # Convenience method to log debug messages with the standard prefix.
31
28
  #
@@ -41,7 +38,7 @@ module Mongo
41
38
 
42
39
  # Convenience method to log error messages with the standard prefix.
43
40
  #
44
- # @example Log a error message.
41
+ # @example Log an error message.
45
42
  # log_error('Message')
46
43
  #
47
44
  # @param [ String ] message The message to log.
@@ -65,7 +62,7 @@ module Mongo
65
62
 
66
63
  # Convenience method to log info messages with the standard prefix.
67
64
  #
68
- # @example Log a info message.
65
+ # @example Log an info message.
69
66
  # log_info('Message')
70
67
  #
71
68
  # @param [ String ] message The message to log.
@@ -96,13 +93,13 @@ module Mongo
96
93
  #
97
94
  # @since 2.1.0
98
95
  def logger
99
- ((respond_to?(:options) && options && options[:logger]) || Logger.logger)
96
+ (respond_to?(:options) && options && options[:logger]) || Logger.logger
100
97
  end
101
98
 
102
99
  private
103
100
 
104
101
  def format_message(message)
105
- format("%s | %s".freeze, _mongo_log_prefix, message)
102
+ format('%s | %s', _mongo_log_prefix, message)
106
103
  end
107
104
 
108
105
  def _mongo_log_prefix
data/lib/mongo/logger.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
  #
@@ -16,14 +15,11 @@
16
15
  # limitations under the License.
17
16
 
18
17
  module Mongo
19
-
20
18
  # Provides ability to log messages.
21
19
  #
22
20
  # @since 2.0.0
23
21
  class Logger
24
-
25
22
  class << self
26
-
27
23
  # Get the wrapped logger. If none was set will return a default info
28
24
  # level logger.
29
25
  #
@@ -47,9 +43,7 @@ module Mongo
47
43
  # @return [ ::Logger ] The wrapped logger.
48
44
  #
49
45
  # @since 2.0.0
50
- def logger=(other)
51
- @logger = other
52
- end
46
+ attr_writer :logger
53
47
 
54
48
  # Get the global logger level.
55
49
  #
@@ -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 Monitoring
20
-
21
19
  # Subscribes to CMAP events and logs them.
22
20
  #
23
21
  # @since 2.9.0
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:todo all
3
2
 
4
3
  # Copyright (C) 2015-2020 MongoDB Inc.
5
4
  #
@@ -17,7 +16,6 @@
17
16
 
18
17
  module Mongo
19
18
  class Monitoring
20
-
21
19
  # Subscribes to command events and logs them.
22
20
  #
23
21
  # @since 2.1.0
@@ -56,14 +54,13 @@ module Mongo
56
54
  #
57
55
  # @since 2.1.0
58
56
  def started(event)
59
- if logger.debug?
60
- _prefix = prefix(event,
61
- connection_generation: event.connection_generation,
62
- connection_id: event.connection_id,
63
- server_connection_id: event.server_connection_id,
64
- )
65
- log_debug("#{_prefix} | STARTED | #{format_command(event.command)}")
66
- end
57
+ return unless logger.debug?
58
+
59
+ _prefix = prefix(event,
60
+ connection_generation: event.connection_generation,
61
+ connection_id: event.connection_id,
62
+ server_connection_id: event.server_connection_id)
63
+ log_debug("#{_prefix} | STARTED | #{format_command(event.command)}")
67
64
  end
68
65
 
69
66
  # Handle the command succeeded event.
@@ -75,9 +72,9 @@ module Mongo
75
72
  #
76
73
  # @since 2.1.0
77
74
  def succeeded(event)
78
- if logger.debug?
79
- log_debug("#{prefix(event)} | SUCCEEDED | #{'%.3f' % event.duration}s")
80
- end
75
+ return unless logger.debug?
76
+
77
+ log_debug("#{prefix(event)} | SUCCEEDED | #{'%.3f' % event.duration}s")
81
78
  end
82
79
 
83
80
  # Handle the command failed event.
@@ -89,34 +86,29 @@ module Mongo
89
86
  #
90
87
  # @since 2.1.0
91
88
  def failed(event)
92
- if logger.debug?
93
- log_debug("#{prefix(event)} | FAILED | #{event.message} | #{event.duration}s")
94
- end
89
+ return unless logger.debug?
90
+
91
+ log_debug("#{prefix(event)} | FAILED | #{event.message} | #{event.duration}s")
95
92
  end
96
93
 
97
94
  private
98
95
 
99
96
  def format_command(args)
100
- begin
101
- truncating? ? truncate(args) : args.inspect
102
- rescue Exception
103
- '<Unable to inspect arguments>'
104
- end
97
+ truncating? ? truncate(args) : args.inspect
98
+ rescue Exception
99
+ '<Unable to inspect arguments>'
105
100
  end
106
101
 
107
102
  def prefix(event, connection_generation: nil, connection_id: nil,
108
- server_connection_id: nil
109
- )
110
- extra = [connection_generation, connection_id].compact.join(':')
111
- if extra == ''
112
- extra = nil
113
- else
114
- extra = "conn:#{extra}"
115
- end
116
- if server_connection_id
117
- extra += " sconn:#{server_connection_id}"
118
- end
119
- "#{event.address.to_s} req:#{event.request_id}#{extra && " #{extra}"} | " +
103
+ server_connection_id: nil)
104
+ extra = [ connection_generation, connection_id ].compact.join(':')
105
+ extra = if extra == ''
106
+ nil
107
+ else
108
+ "conn:#{extra}"
109
+ end
110
+ extra += " sconn:#{server_connection_id}" if server_connection_id
111
+ "#{event.address} req:#{event.request_id}#{extra && " #{extra}"} | " +
120
112
  "#{event.database_name}.#{event.command_name}"
121
113
  end
122
114
 
@@ -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
  #
@@ -19,7 +18,6 @@ module Mongo
19
18
  class Monitoring
20
19
  module Event
21
20
  module Cmap
22
-
23
21
  # Base class for CMAP events.
24
22
  #
25
23
  # @since 2.9.0
@@ -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
  #
@@ -19,12 +18,10 @@ module Mongo
19
18
  class Monitoring
20
19
  module Event
21
20
  module Cmap
22
-
23
21
  # Event published when a connection is unable to be checked out of a pool.
24
22
  #
25
23
  # @since 2.9.0
26
24
  class ConnectionCheckOutFailed < Base
27
-
28
25
  # @return [ Symbol ] POOL_CLOSED Indicates that the connection check
29
26
  # out failed due to the pool already being closed.
30
27
  #
@@ -79,7 +76,7 @@ module Mongo
79
76
  # @api experimental
80
77
  def summary
81
78
  "#<#{self.class.name.sub(/^Mongo::Monitoring::Event::Cmap::/, '')} address=#{address} " +
82
- "reason=#{reason}>"
79
+ "reason=#{reason}>"
83
80
  end
84
81
  end
85
82
  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
  #
@@ -19,12 +18,10 @@ module Mongo
19
18
  class Monitoring
20
19
  module Event
21
20
  module Cmap
22
-
23
21
  # Event published when a thread begins attempting to check a connection out of a pool.
24
22
  #
25
23
  # @since 2.9.0
26
24
  class ConnectionCheckOutStarted < Base
27
-
28
25
  # @return [ Mongo::Address ] address The address of the server that the connection will
29
26
  # connect to.
30
27
  #
@@ -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
  #
@@ -19,12 +18,10 @@ module Mongo
19
18
  class Monitoring
20
19
  module Event
21
20
  module Cmap
22
-
23
21
  # Event published when a connection is returned to a connection pool.
24
22
  #
25
23
  # @since 2.9.0
26
24
  class ConnectionCheckedIn < Base
27
-
28
25
  # @return [ Address ] address The address of the server the connection was connected to.
29
26
  #
30
27
  # @since 2.9.0
@@ -65,7 +62,7 @@ module Mongo
65
62
  # @api experimental
66
63
  def summary
67
64
  "#<#{self.class.name.sub(/^Mongo::Monitoring::Event::Cmap::/, '')} " +
68
- "address=#{address} connection_id=#{connection_id} pool=0x#{pool.object_id}>"
65
+ "address=#{address} connection_id=#{connection_id} pool=0x#{pool.object_id}>"
69
66
  end
70
67
  end
71
68
  end