mongo 2.22.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.
- checksums.yaml +4 -4
- data/bin/mongo_console +0 -1
- data/lib/mongo/active_support.rb +1 -2
- data/lib/mongo/address/ipv4.rb +3 -6
- data/lib/mongo/address/ipv6.rb +6 -10
- data/lib/mongo/address/unix.rb +1 -4
- data/lib/mongo/address/validator.rb +16 -28
- data/lib/mongo/address.rb +30 -40
- data/lib/mongo/auth/aws/conversation.rb +6 -10
- data/lib/mongo/auth/aws/credentials.rb +0 -1
- data/lib/mongo/auth/aws/credentials_cache.rb +0 -1
- data/lib/mongo/auth/aws/credentials_retriever.rb +45 -59
- data/lib/mongo/auth/aws/request.rb +20 -35
- data/lib/mongo/auth/aws.rb +1 -2
- data/lib/mongo/auth/base.rb +20 -29
- data/lib/mongo/auth/conversation_base.rb +14 -18
- data/lib/mongo/auth/cr/conversation.rb +0 -3
- data/lib/mongo/auth/cr.rb +1 -4
- data/lib/mongo/auth/credential_cache.rb +0 -2
- data/lib/mongo/auth/gssapi/conversation.rb +3 -8
- data/lib/mongo/auth/gssapi.rb +1 -4
- data/lib/mongo/auth/ldap/conversation.rb +0 -3
- data/lib/mongo/auth/ldap.rb +1 -4
- data/lib/mongo/auth/roles.rb +16 -19
- data/lib/mongo/auth/sasl_conversation_base.rb +7 -11
- data/lib/mongo/auth/scram/conversation.rb +2 -5
- data/lib/mongo/auth/scram.rb +5 -10
- data/lib/mongo/auth/scram256/conversation.rb +2 -5
- data/lib/mongo/auth/scram256.rb +1 -3
- data/lib/mongo/auth/scram_conversation_base.rb +18 -24
- data/lib/mongo/auth/stringprep/profiles/sasl.rb +17 -18
- data/lib/mongo/auth/stringprep/tables.rb +2209 -2210
- data/lib/mongo/auth/stringprep/unicode_normalize/normalize.rb +36 -38
- data/lib/mongo/auth/stringprep/unicode_normalize/tables.rb +1142 -1150
- data/lib/mongo/auth/stringprep.rb +9 -12
- data/lib/mongo/auth/user/view.rb +3 -5
- data/lib/mongo/auth/user.rb +14 -24
- data/lib/mongo/auth/x509/conversation.rb +0 -3
- data/lib/mongo/auth/x509.rb +7 -9
- data/lib/mongo/auth.rb +18 -30
- data/lib/mongo/background_thread.rb +9 -17
- data/lib/mongo/bson.rb +0 -2
- data/lib/mongo/bulk_write/combineable.rb +0 -3
- data/lib/mongo/bulk_write/ordered_combiner.rb +1 -3
- data/lib/mongo/bulk_write/result.rb +11 -16
- data/lib/mongo/bulk_write/result_combiner.rb +9 -12
- data/lib/mongo/bulk_write/transformable.rb +16 -19
- data/lib/mongo/bulk_write/unordered_combiner.rb +1 -3
- data/lib/mongo/bulk_write/validatable.rb +11 -18
- data/lib/mongo/bulk_write.rb +76 -91
- data/lib/mongo/caching_cursor.rb +2 -7
- data/lib/mongo/client.rb +267 -276
- data/lib/mongo/client_encryption.rb +4 -5
- data/lib/mongo/cluster/periodic_executor.rb +2 -5
- data/lib/mongo/cluster/reapers/cursor_reaper.rb +21 -29
- data/lib/mongo/cluster/reapers/socket_reaper.rb +1 -6
- data/lib/mongo/cluster/sdam_flow.rb +136 -159
- data/lib/mongo/cluster/topology/base.rb +15 -18
- data/lib/mongo/cluster/topology/load_balanced.rb +24 -14
- data/lib/mongo/cluster/topology/no_replica_set_options.rb +3 -6
- data/lib/mongo/cluster/topology/replica_set_no_primary.rb +20 -23
- data/lib/mongo/cluster/topology/replica_set_with_primary.rb +0 -2
- data/lib/mongo/cluster/topology/sharded.rb +19 -9
- data/lib/mongo/cluster/topology/single.rb +24 -14
- data/lib/mongo/cluster/topology/unknown.rb +20 -10
- data/lib/mongo/cluster/topology.rb +29 -25
- data/lib/mongo/cluster.rb +152 -184
- data/lib/mongo/cluster_time.rb +14 -31
- data/lib/mongo/collection/helpers.rb +5 -8
- data/lib/mongo/collection/view/aggregation/behavior.rb +1 -1
- data/lib/mongo/collection/view/aggregation.rb +10 -12
- data/lib/mongo/collection/view/builder/aggregation.rb +6 -9
- data/lib/mongo/collection/view/builder/map_reduce.rb +18 -17
- data/lib/mongo/collection/view/builder.rb +0 -1
- data/lib/mongo/collection/view/change_stream/retryable.rb +3 -8
- data/lib/mongo/collection/view/change_stream.rb +59 -58
- data/lib/mongo/collection/view/explainable.rb +11 -20
- data/lib/mongo/collection/view/immutable.rb +1 -3
- data/lib/mongo/collection/view/iterable.rb +44 -35
- data/lib/mongo/collection/view/map_reduce.rb +20 -25
- data/lib/mongo/collection/view/readable.rb +96 -94
- data/lib/mongo/collection/view/writable.rb +104 -114
- data/lib/mongo/collection/view.rb +11 -8
- data/lib/mongo/collection.rb +103 -106
- data/lib/mongo/condition_variable.rb +4 -4
- data/lib/mongo/config/options.rb +0 -3
- data/lib/mongo/config/validators/option.rb +3 -5
- data/lib/mongo/config.rb +6 -4
- data/lib/mongo/crypt/auto_decryption_context.rb +9 -3
- data/lib/mongo/crypt/auto_encrypter.rb +34 -43
- data/lib/mongo/crypt/auto_encryption_context.rb +0 -3
- data/lib/mongo/crypt/binary.rb +5 -9
- data/lib/mongo/crypt/binding.rb +150 -156
- data/lib/mongo/crypt/context.rb +20 -17
- data/lib/mongo/crypt/data_key_context.rb +2 -7
- data/lib/mongo/crypt/encryption_io.rb +29 -39
- data/lib/mongo/crypt/explicit_decryption_context.rb +9 -3
- data/lib/mongo/crypt/explicit_encrypter.rb +1 -1
- data/lib/mongo/crypt/explicit_encryption_context.rb +19 -30
- data/lib/mongo/crypt/explicit_encryption_expression_context.rb +0 -2
- data/lib/mongo/crypt/handle.rb +42 -48
- data/lib/mongo/crypt/hooks.rb +12 -15
- data/lib/mongo/crypt/kms/aws/credentials.rb +12 -16
- data/lib/mongo/crypt/kms/aws/master_document.rb +6 -9
- data/lib/mongo/crypt/kms/aws.rb +0 -2
- data/lib/mongo/crypt/kms/azure/credentials_retriever.rb +2 -7
- data/lib/mongo/crypt/kms/azure/master_document.rb +15 -19
- data/lib/mongo/crypt/kms/azure.rb +0 -1
- data/lib/mongo/crypt/kms/credentials.rb +13 -27
- data/lib/mongo/crypt/kms/gcp/credentials.rb +12 -14
- data/lib/mongo/crypt/kms/gcp/credentials_retriever.rb +7 -9
- data/lib/mongo/crypt/kms/gcp/master_document.rb +12 -16
- data/lib/mongo/crypt/kms/gcp.rb +0 -2
- data/lib/mongo/crypt/kms/kmip/credentials.rb +7 -8
- data/lib/mongo/crypt/kms/kmip/master_document.rb +3 -5
- data/lib/mongo/crypt/kms/kmip.rb +0 -1
- data/lib/mongo/crypt/kms/local/credentials.rb +7 -8
- data/lib/mongo/crypt/kms/local/master_document.rb +2 -6
- data/lib/mongo/crypt/kms/local.rb +0 -1
- data/lib/mongo/crypt/kms/master_key_document.rb +11 -15
- data/lib/mongo/crypt/kms.rb +14 -16
- data/lib/mongo/crypt/kms_context.rb +0 -2
- data/lib/mongo/crypt/rewrap_many_data_key_context.rb +2 -7
- data/lib/mongo/crypt/rewrap_many_data_key_result.rb +2 -4
- data/lib/mongo/crypt/status.rb +12 -14
- data/lib/mongo/crypt.rb +0 -1
- data/lib/mongo/csot_timeout_holder.rb +3 -2
- data/lib/mongo/cursor/kill_spec.rb +7 -10
- data/lib/mongo/cursor.rb +74 -64
- data/lib/mongo/cursor_host.rb +8 -10
- data/lib/mongo/database/view.rb +23 -39
- data/lib/mongo/database.rb +68 -65
- data/lib/mongo/dbref.rb +0 -1
- data/lib/mongo/deprecations.rb +98 -0
- data/lib/mongo/distinguishing_semaphore.rb +0 -1
- data/lib/mongo/error/auth_error.rb +0 -2
- data/lib/mongo/error/bad_load_balancer_target.rb +0 -2
- data/lib/mongo/error/bulk_write_error.rb +7 -10
- data/lib/mongo/error/change_stream_resumable.rb +0 -2
- data/lib/mongo/error/client_closed.rb +0 -2
- data/lib/mongo/error/closed_stream.rb +1 -4
- data/lib/mongo/error/connection_check_out_timeout.rb +3 -6
- data/lib/mongo/error/connection_perished.rb +0 -2
- data/lib/mongo/error/connection_unavailable.rb +0 -2
- data/lib/mongo/error/credential_check_error.rb +0 -2
- data/lib/mongo/error/crypt_error.rb +0 -2
- data/lib/mongo/error/extra_file_chunk.rb +1 -4
- data/lib/mongo/error/failed_string_prep_validation.rb +5 -6
- data/lib/mongo/error/file_not_found.rb +0 -3
- data/lib/mongo/error/handshake_error.rb +0 -2
- data/lib/mongo/error/insufficient_iteration_count.rb +1 -4
- data/lib/mongo/error/internal_driver_error.rb +0 -2
- data/lib/mongo/error/invalid_address.rb +0 -2
- data/lib/mongo/error/invalid_application_name.rb +0 -3
- data/lib/mongo/error/invalid_bulk_operation.rb +1 -4
- data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -4
- data/lib/mongo/error/invalid_collection_name.rb +1 -4
- data/lib/mongo/error/invalid_config_option.rb +0 -3
- data/lib/mongo/error/invalid_cursor_operation.rb +0 -2
- data/lib/mongo/error/invalid_database_name.rb +1 -4
- data/lib/mongo/error/invalid_document.rb +1 -4
- data/lib/mongo/error/invalid_file.rb +0 -3
- data/lib/mongo/error/invalid_file_revision.rb +0 -3
- data/lib/mongo/error/invalid_min_pool_size.rb +0 -3
- data/lib/mongo/error/invalid_nonce.rb +0 -3
- data/lib/mongo/error/invalid_read_concern.rb +2 -4
- data/lib/mongo/error/invalid_read_option.rb +0 -3
- data/lib/mongo/error/invalid_replacement_document.rb +2 -5
- data/lib/mongo/error/invalid_server_auth_host.rb +0 -2
- data/lib/mongo/error/invalid_server_auth_response.rb +0 -2
- data/lib/mongo/error/invalid_server_preference.rb +7 -16
- data/lib/mongo/error/invalid_session.rb +1 -4
- data/lib/mongo/error/invalid_signature.rb +0 -3
- data/lib/mongo/error/invalid_transaction_operation.rb +5 -8
- data/lib/mongo/error/invalid_txt_record.rb +0 -2
- data/lib/mongo/error/invalid_update_document.rb +2 -5
- data/lib/mongo/error/invalid_uri.rb +1 -4
- data/lib/mongo/error/invalid_write_concern.rb +2 -5
- data/lib/mongo/error/kms_error.rb +0 -2
- data/lib/mongo/error/labelable.rb +0 -3
- data/lib/mongo/error/lint_error.rb +0 -2
- data/lib/mongo/error/max_bson_size.rb +8 -11
- data/lib/mongo/error/max_message_size.rb +2 -5
- data/lib/mongo/error/mismatched_domain.rb +0 -2
- data/lib/mongo/error/missing_connection.rb +0 -2
- data/lib/mongo/error/missing_file_chunk.rb +0 -3
- data/lib/mongo/error/missing_password.rb +0 -2
- data/lib/mongo/error/missing_resume_token.rb +1 -4
- data/lib/mongo/error/missing_scram_server_signature.rb +2 -4
- data/lib/mongo/error/missing_service_id.rb +0 -2
- data/lib/mongo/error/mongocryptd_spawn_error.rb +0 -2
- data/lib/mongo/error/multi_index_drop.rb +0 -3
- data/lib/mongo/error/need_primary_server.rb +0 -2
- data/lib/mongo/error/no_server_available.rb +3 -8
- data/lib/mongo/error/no_service_connection_available.rb +1 -3
- data/lib/mongo/error/no_srv_records.rb +0 -2
- data/lib/mongo/error/notable.rb +8 -16
- data/lib/mongo/error/operation_failure.rb +22 -35
- data/lib/mongo/error/parser.rb +33 -75
- data/lib/mongo/error/pool_cleared_error.rb +1 -3
- data/lib/mongo/error/pool_closed_error.rb +0 -3
- data/lib/mongo/error/pool_error.rb +0 -3
- data/lib/mongo/error/pool_paused_error.rb +0 -2
- data/lib/mongo/error/raise_original_error.rb +1 -3
- data/lib/mongo/error/read_write_retryable.rb +14 -17
- data/lib/mongo/error/sdam_error_detection.rb +3 -5
- data/lib/mongo/error/server_api_conflict.rb +0 -2
- data/lib/mongo/error/server_certificate_revoked.rb +0 -2
- data/lib/mongo/error/server_not_usable.rb +0 -2
- data/lib/mongo/error/session_ended.rb +1 -3
- data/lib/mongo/error/session_not_materialized.rb +1 -3
- data/lib/mongo/error/sessions_not_supported.rb +1 -4
- data/lib/mongo/error/snapshot_session_invalid_server_version.rb +1 -4
- data/lib/mongo/error/snapshot_session_transaction_prohibited.rb +1 -4
- data/lib/mongo/error/socket_error.rb +0 -2
- data/lib/mongo/error/socket_timeout_error.rb +0 -2
- data/lib/mongo/error/transactions_not_supported.rb +3 -6
- data/lib/mongo/error/unchangeable_collection_option.rb +1 -4
- data/lib/mongo/error/unexpected_chunk_length.rb +0 -3
- data/lib/mongo/error/unexpected_response.rb +1 -4
- data/lib/mongo/error/unknown_payload_type.rb +0 -3
- data/lib/mongo/error/unmet_dependency.rb +0 -2
- data/lib/mongo/error/unsupported_array_filters.rb +3 -24
- data/lib/mongo/error/unsupported_collation.rb +3 -24
- data/lib/mongo/error/unsupported_features.rb +0 -2
- data/lib/mongo/error/unsupported_message_type.rb +0 -2
- data/lib/mongo/error/unsupported_option.rb +19 -21
- data/lib/mongo/error/write_retryable.rb +0 -2
- data/lib/mongo/error.rb +10 -24
- data/lib/mongo/event/base.rb +0 -2
- data/lib/mongo/event/listeners.rb +0 -3
- data/lib/mongo/event/publisher.rb +0 -3
- data/lib/mongo/event/subscriber.rb +0 -4
- data/lib/mongo/event.rb +4 -6
- data/lib/mongo/grid/file/chunk.rb +7 -10
- data/lib/mongo/grid/file/info.rb +20 -24
- data/lib/mongo/grid/file.rb +7 -8
- data/lib/mongo/grid/fs_bucket.rb +40 -48
- data/lib/mongo/grid/stream/read.rb +25 -35
- data/lib/mongo/grid/stream/write.rb +17 -22
- data/lib/mongo/grid/stream.rb +2 -4
- data/lib/mongo/grid.rb +0 -1
- data/lib/mongo/id.rb +0 -1
- data/lib/mongo/index/view.rb +68 -58
- data/lib/mongo/index.rb +7 -10
- data/lib/mongo/lint.rb +31 -37
- data/lib/mongo/loggable.rb +5 -8
- data/lib/mongo/logger.rb +1 -7
- data/lib/mongo/monitoring/cmap_log_subscriber.rb +0 -2
- data/lib/mongo/monitoring/command_log_subscriber.rb +25 -33
- data/lib/mongo/monitoring/event/cmap/base.rb +0 -2
- data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_check_out_started.rb +0 -3
- data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +2 -5
- data/lib/mongo/monitoring/event/cmap/connection_closed.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_created.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_ready.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +0 -3
- data/lib/mongo/monitoring/event/cmap/pool_closed.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/pool_created.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/pool_ready.rb +1 -4
- data/lib/mongo/monitoring/event/cmap.rb +0 -1
- data/lib/mongo/monitoring/event/command_failed.rb +5 -9
- data/lib/mongo/monitoring/event/command_started.rb +8 -12
- data/lib/mongo/monitoring/event/command_succeeded.rb +7 -15
- data/lib/mongo/monitoring/event/secure.rb +15 -20
- data/lib/mongo/monitoring/event/server_closed.rb +1 -4
- data/lib/mongo/monitoring/event/server_description_changed.rb +4 -8
- data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +5 -10
- data/lib/mongo/monitoring/event/server_heartbeat_started.rb +1 -4
- data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +3 -8
- data/lib/mongo/monitoring/event/server_opening.rb +1 -4
- data/lib/mongo/monitoring/event/topology_changed.rb +2 -5
- data/lib/mongo/monitoring/event/topology_closed.rb +1 -4
- data/lib/mongo/monitoring/event/topology_opening.rb +1 -4
- data/lib/mongo/monitoring/event.rb +0 -1
- data/lib/mongo/monitoring/publishable.rb +20 -30
- data/lib/mongo/monitoring/sdam_log_subscriber.rb +0 -2
- data/lib/mongo/monitoring/server_closed_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/server_description_changed_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/server_opening_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/topology_changed_log_subscriber.rb +5 -8
- data/lib/mongo/monitoring/topology_closed_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/topology_opening_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/unified_sdam_log_subscriber.rb +1 -3
- data/lib/mongo/monitoring.rb +38 -39
- data/lib/mongo/operation/aggregate/op_msg.rb +0 -2
- data/lib/mongo/operation/aggregate/result.rb +3 -6
- data/lib/mongo/operation/aggregate.rb +0 -2
- data/lib/mongo/operation/collections_info/result.rb +0 -3
- data/lib/mongo/operation/collections_info.rb +0 -2
- data/lib/mongo/operation/command/op_msg.rb +1 -4
- data/lib/mongo/operation/command.rb +0 -2
- data/lib/mongo/operation/context.rb +13 -16
- data/lib/mongo/operation/count/op_msg.rb +2 -4
- data/lib/mongo/operation/count.rb +0 -2
- data/lib/mongo/operation/create/op_msg.rb +2 -5
- data/lib/mongo/operation/create.rb +4 -2
- data/lib/mongo/operation/create_index/op_msg.rb +3 -7
- data/lib/mongo/operation/create_index.rb +0 -2
- data/lib/mongo/operation/create_user/op_msg.rb +2 -4
- data/lib/mongo/operation/create_user.rb +0 -2
- data/lib/mongo/operation/delete/bulk_result.rb +2 -3
- data/lib/mongo/operation/delete/op_msg.rb +3 -10
- data/lib/mongo/operation/delete/result.rb +0 -3
- data/lib/mongo/operation/delete.rb +1 -5
- data/lib/mongo/operation/distinct/op_msg.rb +2 -5
- data/lib/mongo/operation/distinct.rb +0 -2
- data/lib/mongo/operation/drop/op_msg.rb +0 -2
- data/lib/mongo/operation/drop.rb +0 -2
- data/lib/mongo/operation/drop_database/op_msg.rb +0 -2
- data/lib/mongo/operation/drop_database.rb +0 -2
- data/lib/mongo/operation/drop_index/op_msg.rb +4 -6
- data/lib/mongo/operation/drop_index.rb +0 -2
- data/lib/mongo/operation/explain/op_msg.rb +0 -2
- data/lib/mongo/operation/explain/result.rb +0 -3
- data/lib/mongo/operation/explain.rb +0 -2
- data/lib/mongo/operation/find/builder/command.rb +4 -12
- data/lib/mongo/operation/find/builder/flags.rb +9 -15
- data/lib/mongo/operation/find/builder/modifiers.rb +1 -4
- data/lib/mongo/operation/find/builder.rb +0 -1
- data/lib/mongo/operation/find/op_msg.rb +4 -12
- data/lib/mongo/operation/find/result.rb +0 -3
- data/lib/mongo/operation/find.rb +0 -2
- data/lib/mongo/operation/get_more/command_builder.rb +1 -6
- data/lib/mongo/operation/get_more/op_msg.rb +10 -4
- data/lib/mongo/operation/get_more/result.rb +0 -3
- data/lib/mongo/operation/get_more.rb +0 -2
- data/lib/mongo/operation/indexes/op_msg.rb +0 -2
- data/lib/mongo/operation/indexes/result.rb +1 -5
- data/lib/mongo/operation/indexes.rb +0 -2
- data/lib/mongo/operation/insert/bulk_result.rb +2 -6
- data/lib/mongo/operation/insert/op_msg.rb +7 -6
- data/lib/mongo/operation/insert/result.rb +0 -3
- data/lib/mongo/operation/insert.rb +2 -5
- data/lib/mongo/operation/kill_cursors/command_builder.rb +0 -3
- data/lib/mongo/operation/kill_cursors/op_msg.rb +1 -3
- data/lib/mongo/operation/kill_cursors.rb +0 -2
- data/lib/mongo/operation/list_collections/op_msg.rb +4 -6
- data/lib/mongo/operation/list_collections/result.rb +1 -4
- data/lib/mongo/operation/list_collections.rb +0 -2
- data/lib/mongo/operation/map_reduce/op_msg.rb +0 -2
- data/lib/mongo/operation/map_reduce/result.rb +3 -6
- data/lib/mongo/operation/map_reduce.rb +0 -2
- data/lib/mongo/operation/op_msg_base.rb +0 -1
- data/lib/mongo/operation/parallel_scan/op_msg.rb +4 -5
- data/lib/mongo/operation/parallel_scan/result.rb +2 -5
- data/lib/mongo/operation/parallel_scan.rb +0 -2
- data/lib/mongo/operation/remove_user/op_msg.rb +2 -4
- data/lib/mongo/operation/remove_user.rb +0 -2
- data/lib/mongo/operation/result.rb +38 -48
- data/lib/mongo/operation/shared/bypass_document_validation.rb +3 -7
- data/lib/mongo/operation/shared/causal_consistency_supported.rb +0 -3
- data/lib/mongo/operation/shared/executable.rb +29 -31
- data/lib/mongo/operation/shared/executable_no_validate.rb +0 -3
- data/lib/mongo/operation/shared/executable_transaction_label.rb +0 -2
- data/lib/mongo/operation/shared/idable.rb +3 -6
- data/lib/mongo/operation/shared/limited.rb +0 -3
- data/lib/mongo/operation/shared/object_id_generator.rb +0 -3
- data/lib/mongo/operation/shared/op_msg_executable.rb +0 -2
- data/lib/mongo/operation/shared/polymorphic_lookup.rb +0 -2
- data/lib/mongo/operation/shared/polymorphic_result.rb +2 -4
- data/lib/mongo/operation/shared/read_preference_supported.rb +10 -15
- data/lib/mongo/operation/shared/response_handling.rb +13 -26
- data/lib/mongo/operation/shared/result/aggregatable.rb +12 -13
- data/lib/mongo/operation/shared/sessions_supported.rb +87 -99
- data/lib/mongo/operation/shared/specifiable.rb +37 -59
- data/lib/mongo/operation/shared/write.rb +12 -17
- data/lib/mongo/operation/shared/write_concern_supported.rb +4 -7
- data/lib/mongo/operation/update/bulk_result.rb +13 -17
- data/lib/mongo/operation/update/op_msg.rb +2 -5
- data/lib/mongo/operation/update/result.rb +5 -5
- data/lib/mongo/operation/update.rb +1 -5
- data/lib/mongo/operation/update_user/op_msg.rb +2 -4
- data/lib/mongo/operation/update_user.rb +0 -2
- data/lib/mongo/operation/users_info/op_msg.rb +2 -4
- data/lib/mongo/operation/users_info/result.rb +1 -4
- data/lib/mongo/operation/users_info.rb +0 -2
- data/lib/mongo/operation/write_command/op_msg.rb +2 -10
- data/lib/mongo/operation/write_command.rb +0 -2
- data/lib/mongo/operation.rb +9 -14
- data/lib/mongo/options/mapper.rb +8 -15
- data/lib/mongo/options/redacted.rb +7 -9
- data/lib/mongo/options.rb +0 -1
- data/lib/mongo/protocol/bit_vector.rb +3 -5
- data/lib/mongo/protocol/caching_hash.rb +2 -7
- data/lib/mongo/protocol/compressed.rb +5 -10
- data/lib/mongo/protocol/get_more.rb +2 -8
- data/lib/mongo/protocol/kill_cursors.rb +2 -8
- data/lib/mongo/protocol/message.rb +103 -105
- data/lib/mongo/protocol/msg.rb +48 -63
- data/lib/mongo/protocol/query.rb +32 -41
- data/lib/mongo/protocol/registry.rb +2 -5
- data/lib/mongo/protocol/reply.rb +10 -16
- data/lib/mongo/protocol/serializers.rb +41 -59
- data/lib/mongo/protocol.rb +0 -1
- data/lib/mongo/query_cache.rb +7 -15
- data/lib/mongo/retryable/backpressure.rb +31 -0
- data/lib/mongo/retryable/base_worker.rb +39 -13
- data/lib/mongo/retryable/read_worker.rb +77 -21
- data/lib/mongo/retryable/retry_policy.rb +59 -0
- data/lib/mongo/retryable/write_worker.rb +155 -56
- data/lib/mongo/retryable.rb +70 -9
- data/lib/mongo/search_index/view.rb +30 -10
- data/lib/mongo/semaphore.rb +0 -1
- data/lib/mongo/server/app_metadata/environment.rb +3 -3
- data/lib/mongo/server/app_metadata/platform.rb +17 -4
- data/lib/mongo/server/app_metadata.rb +4 -5
- data/lib/mongo/server/connection.rb +79 -61
- data/lib/mongo/server/connection_base.rb +43 -53
- data/lib/mongo/server/connection_common.rb +41 -64
- data/lib/mongo/server/connection_pool/generation_manager.rb +6 -11
- data/lib/mongo/server/connection_pool/populator.rb +1 -4
- data/lib/mongo/server/connection_pool.rb +195 -167
- data/lib/mongo/server/description/features.rb +51 -59
- data/lib/mongo/server/description/load_balancer.rb +0 -2
- data/lib/mongo/server/description.rb +117 -138
- data/lib/mongo/server/monitor/app_metadata.rb +3 -4
- data/lib/mongo/server/monitor/connection.rb +28 -35
- data/lib/mongo/server/monitor.rb +65 -60
- data/lib/mongo/server/pending_connection.rb +70 -71
- data/lib/mongo/server/push_monitor/connection.rb +0 -3
- data/lib/mongo/server/push_monitor.rb +21 -29
- data/lib/mongo/server/round_trip_time_calculator.rb +11 -17
- data/lib/mongo/server.rb +62 -94
- data/lib/mongo/server_selector/base.rb +133 -157
- data/lib/mongo/server_selector/nearest.rb +2 -5
- data/lib/mongo/server_selector/primary.rb +1 -5
- data/lib/mongo/server_selector/primary_preferred.rb +2 -6
- data/lib/mongo/server_selector/secondary.rb +2 -6
- data/lib/mongo/server_selector/secondary_preferred.rb +1 -5
- data/lib/mongo/server_selector.rb +3 -4
- data/lib/mongo/session/server_session.rb +6 -7
- data/lib/mongo/session/session_pool.rb +20 -34
- data/lib/mongo/session.rb +334 -199
- data/lib/mongo/socket/ocsp_cache.rb +8 -13
- data/lib/mongo/socket/ocsp_verifier.rb +69 -70
- data/lib/mongo/socket/ssl.rb +44 -43
- data/lib/mongo/socket/tcp.rb +5 -8
- data/lib/mongo/socket/unix.rb +0 -4
- data/lib/mongo/socket.rb +80 -102
- data/lib/mongo/srv/monitor.rb +10 -11
- data/lib/mongo/srv/resolver.rb +15 -24
- data/lib/mongo/srv/result.rb +25 -21
- data/lib/mongo/srv.rb +0 -1
- data/lib/mongo/timeout.rb +4 -11
- data/lib/mongo/topology_version.rb +8 -13
- data/lib/mongo/tracing/open_telemetry/command_tracer.rb +320 -0
- data/lib/mongo/tracing/open_telemetry/operation_tracer.rb +227 -0
- data/lib/mongo/tracing/open_telemetry/tracer.rb +236 -0
- data/lib/mongo/{error/server_api_not_supported.rb → tracing/open_telemetry.rb} +10 -10
- data/lib/mongo/tracing.rb +42 -0
- data/lib/mongo/uri/options_mapper.rb +135 -126
- data/lib/mongo/uri/srv_protocol.rb +34 -42
- data/lib/mongo/uri.rb +95 -139
- data/lib/mongo/utils.rb +5 -12
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern/acknowledged.rb +0 -2
- data/lib/mongo/write_concern/base.rb +6 -6
- data/lib/mongo/write_concern/unacknowledged.rb +0 -2
- data/lib/mongo/write_concern.rb +14 -15
- data/lib/mongo.rb +4 -3
- data/mongo.gemspec +17 -17
- metadata +11 -5
- data/lib/mongo/operation/shared/result/use_legacy_error_parser.rb +0 -32
- data/lib/mongo/operation/shared/validatable.rb +0 -87
data/lib/mongo/collection.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/collection/helpers'
|
|
|
21
20
|
require 'mongo/collection/queryable_encryption'
|
|
22
21
|
|
|
23
22
|
module Mongo
|
|
24
|
-
|
|
25
23
|
# Represents a collection in the database and operations that can directly be
|
|
26
24
|
# applied to one.
|
|
27
25
|
#
|
|
@@ -35,12 +33,12 @@ module Mongo
|
|
|
35
33
|
# The capped option.
|
|
36
34
|
#
|
|
37
35
|
# @since 2.1.0
|
|
38
|
-
CAPPED = 'capped'
|
|
36
|
+
CAPPED = 'capped'
|
|
39
37
|
|
|
40
38
|
# The ns field constant.
|
|
41
39
|
#
|
|
42
40
|
# @since 2.1.0
|
|
43
|
-
NS = 'ns'
|
|
41
|
+
NS = 'ns'
|
|
44
42
|
|
|
45
43
|
# @return [ Mongo::Database ] The database the collection resides in.
|
|
46
44
|
attr_reader :database
|
|
@@ -57,22 +55,24 @@ module Mongo
|
|
|
57
55
|
# Delegate to the cluster for the next primary.
|
|
58
56
|
def_delegators :cluster, :next_primary
|
|
59
57
|
|
|
58
|
+
def_delegators :client, :tracer
|
|
59
|
+
|
|
60
60
|
# Options that can be updated on a new Collection instance via the #with method.
|
|
61
61
|
#
|
|
62
62
|
# @since 2.1.0
|
|
63
|
-
CHANGEABLE_OPTIONS = [
|
|
63
|
+
CHANGEABLE_OPTIONS = %i[read read_concern write write_concern].freeze
|
|
64
64
|
|
|
65
65
|
# Options map to transform create collection options.
|
|
66
66
|
#
|
|
67
67
|
# @api private
|
|
68
68
|
CREATE_COLLECTION_OPTIONS = {
|
|
69
|
-
:
|
|
70
|
-
:
|
|
71
|
-
:
|
|
72
|
-
:
|
|
73
|
-
:
|
|
74
|
-
:
|
|
75
|
-
:
|
|
69
|
+
time_series: :timeseries,
|
|
70
|
+
expire_after: :expireAfterSeconds,
|
|
71
|
+
clustered_index: :clusteredIndex,
|
|
72
|
+
change_stream_pre_and_post_images: :changeStreamPreAndPostImages,
|
|
73
|
+
encrypted_fields: :encryptedFields,
|
|
74
|
+
validator: :validator,
|
|
75
|
+
view_on: :viewOn
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
# Check if a collection is equal to another object. Will check the name and
|
|
@@ -88,6 +88,7 @@ module Mongo
|
|
|
88
88
|
# @since 2.0.0
|
|
89
89
|
def ==(other)
|
|
90
90
|
return false unless other.is_a?(Collection)
|
|
91
|
+
|
|
91
92
|
name == other.name && database == other.database && options == other.options
|
|
92
93
|
end
|
|
93
94
|
|
|
@@ -164,17 +165,17 @@ module Mongo
|
|
|
164
165
|
if options[:write] && options[:write_concern] && options[:write] != options[:write_concern]
|
|
165
166
|
raise ArgumentError, "If :write and :write_concern are both given, they must be identical: #{options.inspect}"
|
|
166
167
|
end
|
|
168
|
+
|
|
167
169
|
@database = database
|
|
168
170
|
@name = name.to_s.freeze
|
|
169
171
|
@options = options.dup
|
|
170
172
|
@timeout_ms = options.delete(:timeout_ms)
|
|
171
|
-
|
|
172
|
-
if @options[:write_concern].is_a?(WriteConcern::Base)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
end
|
|
177
|
-
=end
|
|
173
|
+
# WriteConcern object support
|
|
174
|
+
# if @options[:write_concern].is_a?(WriteConcern::Base)
|
|
175
|
+
# # Cache the instance so that we do not needlessly reconstruct it.
|
|
176
|
+
# @write_concern = @options[:write_concern]
|
|
177
|
+
# @options[:write_concern] = @write_concern.options
|
|
178
|
+
# end
|
|
178
179
|
@options.freeze
|
|
179
180
|
end
|
|
180
181
|
|
|
@@ -236,7 +237,8 @@ module Mongo
|
|
|
236
237
|
# @since 2.0.0
|
|
237
238
|
def write_concern
|
|
238
239
|
@write_concern ||= WriteConcern.get(
|
|
239
|
-
options[:write_concern] || options[:write] || database.write_concern
|
|
240
|
+
options[:write_concern] || options[:write] || database.write_concern
|
|
241
|
+
)
|
|
240
242
|
end
|
|
241
243
|
|
|
242
244
|
# Get the write concern to use for an operation on this collection,
|
|
@@ -252,12 +254,10 @@ module Mongo
|
|
|
252
254
|
# @api private
|
|
253
255
|
def write_concern_with_session(session)
|
|
254
256
|
wc = write_concern
|
|
255
|
-
if session && session.in_transaction?
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
return WriteConcern.get(opts)
|
|
260
|
-
end
|
|
257
|
+
if session && session.in_transaction? && wc && !wc.acknowledged?
|
|
258
|
+
opts = wc.options.dup
|
|
259
|
+
opts.delete(:w)
|
|
260
|
+
return WriteConcern.get(opts)
|
|
261
261
|
end
|
|
262
262
|
wc
|
|
263
263
|
end
|
|
@@ -301,12 +301,8 @@ module Mongo
|
|
|
301
301
|
raise Error::UnchangeableCollectionOption.new(k) unless CHANGEABLE_OPTIONS.include?(k)
|
|
302
302
|
end
|
|
303
303
|
options = @options.dup
|
|
304
|
-
if options[:write] && new_options[:write_concern]
|
|
305
|
-
|
|
306
|
-
end
|
|
307
|
-
if options[:write_concern] && new_options[:write]
|
|
308
|
-
options.delete(:write_concern)
|
|
309
|
-
end
|
|
304
|
+
options.delete(:write) if options[:write] && new_options[:write_concern]
|
|
305
|
+
options.delete(:write_concern) if options[:write_concern] && new_options[:write]
|
|
310
306
|
Collection.new(database, name, options.update(new_options))
|
|
311
307
|
end
|
|
312
308
|
|
|
@@ -320,8 +316,8 @@ module Mongo
|
|
|
320
316
|
# @since 2.0.0
|
|
321
317
|
def capped?
|
|
322
318
|
database.list_collections(filter: { name: name })
|
|
323
|
-
|
|
324
|
-
|
|
319
|
+
.first
|
|
320
|
+
&.dig('options', CAPPED) || false
|
|
325
321
|
end
|
|
326
322
|
|
|
327
323
|
# Force the collection to be created in the database.
|
|
@@ -387,44 +383,45 @@ module Mongo
|
|
|
387
383
|
# serialization.
|
|
388
384
|
# TODO put the list of read options in a class-level constant when
|
|
389
385
|
# we figure out what the full set of them is.
|
|
390
|
-
options = Hash[self.options.merge(opts).reject do |key,
|
|
391
|
-
%w
|
|
386
|
+
options = Hash[self.options.merge(opts).reject do |key, _value|
|
|
387
|
+
%w[read read_preference read_concern session].include?(key.to_s)
|
|
392
388
|
end]
|
|
393
389
|
# Converting Ruby options to server style.
|
|
394
390
|
CREATE_COLLECTION_OPTIONS.each do |ruby_key, server_key|
|
|
395
|
-
if options.key?(ruby_key)
|
|
396
|
-
options[server_key] = options.delete(ruby_key)
|
|
397
|
-
end
|
|
391
|
+
options[server_key] = options.delete(ruby_key) if options.key?(ruby_key)
|
|
398
392
|
end
|
|
399
|
-
operation = { :
|
|
393
|
+
operation = { create: name }.merge(options)
|
|
400
394
|
operation.delete(:write)
|
|
401
395
|
operation.delete(:write_concern)
|
|
402
396
|
client.send(:with_session, opts) do |session|
|
|
403
397
|
write_concern = if opts[:write_concern]
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
398
|
+
WriteConcern.get(opts[:write_concern])
|
|
399
|
+
else
|
|
400
|
+
self.write_concern
|
|
401
|
+
end
|
|
408
402
|
|
|
409
403
|
context = Operation::Context.new(
|
|
410
404
|
client: client,
|
|
411
405
|
session: session
|
|
412
406
|
)
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
)
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
407
|
+
operation = Operation::Create.new(
|
|
408
|
+
selector: operation,
|
|
409
|
+
db_name: database.name,
|
|
410
|
+
write_concern: write_concern,
|
|
411
|
+
session: session,
|
|
412
|
+
# Note that these are collection options, collation isn't
|
|
413
|
+
# taken from options passed to the create method.
|
|
414
|
+
collation: options[:collation] || options['collation'],
|
|
415
|
+
validator: options[:validator]
|
|
416
|
+
)
|
|
417
|
+
tracer.trace_operation(operation, context, op_name: 'createCollection') do
|
|
418
|
+
maybe_create_qe_collections(opts[:encrypted_fields], client, session) do |encrypted_fields|
|
|
419
|
+
operation.encrypted_fields = encrypted_fields
|
|
420
|
+
operation.execute(
|
|
421
|
+
next_primary(nil, session),
|
|
422
|
+
context: context
|
|
423
|
+
)
|
|
424
|
+
end
|
|
428
425
|
end
|
|
429
426
|
end
|
|
430
427
|
end
|
|
@@ -453,25 +450,27 @@ module Mongo
|
|
|
453
450
|
# @since 2.0.0
|
|
454
451
|
def drop(opts = {})
|
|
455
452
|
client.with_session(opts) do |session|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
453
|
+
context = Operation::Context.new(
|
|
454
|
+
client: client,
|
|
455
|
+
session: session,
|
|
456
|
+
operation_timeouts: operation_timeouts(opts)
|
|
457
|
+
)
|
|
458
|
+
temp_write_concern = write_concern
|
|
459
|
+
write_concern = if opts[:write_concern]
|
|
460
|
+
WriteConcern.get(opts[:write_concern])
|
|
461
|
+
else
|
|
462
|
+
temp_write_concern
|
|
463
|
+
end
|
|
464
|
+
operation = Operation::Drop.new({
|
|
465
|
+
selector: { drop: name },
|
|
466
|
+
db_name: database.name,
|
|
467
|
+
write_concern: write_concern,
|
|
468
|
+
session: session,
|
|
469
|
+
})
|
|
470
|
+
tracer.trace_operation(operation, context, op_name: 'dropCollection') do
|
|
471
|
+
maybe_drop_emm_collections(opts[:encrypted_fields], client, session) do
|
|
472
|
+
do_drop(operation, session, context)
|
|
462
473
|
end
|
|
463
|
-
context = Operation::Context.new(
|
|
464
|
-
client: client,
|
|
465
|
-
session: session,
|
|
466
|
-
operation_timeouts: operation_timeouts(opts)
|
|
467
|
-
)
|
|
468
|
-
operation = Operation::Drop.new({
|
|
469
|
-
selector: { :drop => name },
|
|
470
|
-
db_name: database.name,
|
|
471
|
-
write_concern: write_concern,
|
|
472
|
-
session: session,
|
|
473
|
-
})
|
|
474
|
-
do_drop(operation, session, context)
|
|
475
474
|
end
|
|
476
475
|
end
|
|
477
476
|
end
|
|
@@ -569,10 +568,8 @@ module Mongo
|
|
|
569
568
|
View.new(self, {}, options).aggregate(pipeline, options)
|
|
570
569
|
end
|
|
571
570
|
|
|
572
|
-
#
|
|
573
|
-
#
|
|
574
|
-
# to request that notifications are sent for all changes to a particular
|
|
575
|
-
# collection.
|
|
571
|
+
# Allows users to request that notifications are sent for all changes
|
|
572
|
+
# to a particular collection.
|
|
576
573
|
#
|
|
577
574
|
# @example Get change notifications for a given collection.
|
|
578
575
|
# collection.watch([{ '$match' => { operationType: { '$in' => ['insert', 'replace'] } } }])
|
|
@@ -620,7 +617,6 @@ module Mongo
|
|
|
620
617
|
# @option options [ BSON::Timestamp ] :start_at_operation_time Only return
|
|
621
618
|
# changes that occurred at or after the specified timestamp. Any command run
|
|
622
619
|
# against the server will return a cluster time that can be used here.
|
|
623
|
-
# Only recognized by server versions 4.0+.
|
|
624
620
|
# @option options [ Object ] :comment A user-provided
|
|
625
621
|
# comment to attach to this command.
|
|
626
622
|
# @option options [ Boolean ] :show_expanded_events Enables the server to
|
|
@@ -679,7 +675,7 @@ module Mongo
|
|
|
679
675
|
#
|
|
680
676
|
# @deprecated Use #count_documents or estimated_document_count instead. However, note that the
|
|
681
677
|
# following operators will need to be substituted when switching to #count_documents:
|
|
682
|
-
# * $where should be replaced with $expr
|
|
678
|
+
# * $where should be replaced with $expr
|
|
683
679
|
# * $near should be replaced with $geoWithin with $center
|
|
684
680
|
# * $nearSphere should be replaced with $geoWithin with $centerSphere
|
|
685
681
|
def count(filter = nil, options = {})
|
|
@@ -699,7 +695,7 @@ module Mongo
|
|
|
699
695
|
#
|
|
700
696
|
# @option options :skip [ Integer ] The number of documents to skip.
|
|
701
697
|
# @option options :hint [ Hash ] Override default index selection and force
|
|
702
|
-
# MongoDB to use a specific index for the query.
|
|
698
|
+
# MongoDB to use a specific index for the query.
|
|
703
699
|
# @option options :limit [ Integer ] Max number of docs to count.
|
|
704
700
|
# @option options :max_time_ms [ Integer ] The maximum amount of time to allow the
|
|
705
701
|
# command to run.
|
|
@@ -851,33 +847,34 @@ module Mongo
|
|
|
851
847
|
|
|
852
848
|
client.with_session(opts) do |session|
|
|
853
849
|
write_concern = if opts[:write_concern]
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
850
|
+
WriteConcern.get(opts[:write_concern])
|
|
851
|
+
else
|
|
852
|
+
write_concern_with_session(session)
|
|
853
|
+
end
|
|
858
854
|
|
|
859
|
-
if document.nil?
|
|
860
|
-
raise ArgumentError, "Document to be inserted cannot be nil"
|
|
861
|
-
end
|
|
855
|
+
raise ArgumentError, 'Document to be inserted cannot be nil' if document.nil?
|
|
862
856
|
|
|
863
857
|
context = Operation::Context.new(
|
|
864
858
|
client: client,
|
|
865
859
|
session: session,
|
|
866
860
|
operation_timeouts: operation_timeouts(opts)
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
861
|
+
)
|
|
862
|
+
operation = Operation::Insert.new(
|
|
863
|
+
documents: [ document ],
|
|
864
|
+
db_name: database.name,
|
|
865
|
+
coll_name: name,
|
|
866
|
+
write_concern: write_concern,
|
|
867
|
+
bypass_document_validation: !!opts[:bypass_document_validation],
|
|
868
|
+
options: opts,
|
|
869
|
+
id_generator: client.options[:id_generator],
|
|
870
|
+
session: session,
|
|
871
|
+
comment: opts[:comment]
|
|
872
|
+
)
|
|
873
|
+
tracer.trace_operation(operation, context) do
|
|
874
|
+
write_with_retry(write_concern, context: context) do |connection, txn_num, context|
|
|
875
|
+
operation.txn_num = txn_num
|
|
876
|
+
operation.execute_with_connection(connection, context: context)
|
|
877
|
+
end
|
|
881
878
|
end
|
|
882
879
|
end
|
|
883
880
|
end
|
|
@@ -910,7 +907,7 @@ module Mongo
|
|
|
910
907
|
def insert_many(documents, options = {})
|
|
911
908
|
QueryCache.clear_namespace(namespace)
|
|
912
909
|
|
|
913
|
-
inserts = documents.map{ |doc| { :
|
|
910
|
+
inserts = documents.map { |doc| { insert_one: doc } }
|
|
914
911
|
bulk_write(inserts, options)
|
|
915
912
|
end
|
|
916
913
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -32,6 +31,7 @@ module Mongo
|
|
|
32
31
|
def wait(timeout = nil)
|
|
33
32
|
raise_unless_locked!
|
|
34
33
|
return false if timeout && timeout < 0
|
|
34
|
+
|
|
35
35
|
@cv.wait(@lock, timeout)
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -50,9 +50,9 @@ module Mongo
|
|
|
50
50
|
private
|
|
51
51
|
|
|
52
52
|
def raise_unless_locked!
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
return if @lock.owned?
|
|
54
|
+
|
|
55
|
+
raise ArgumentError, 'the lock must be owned when calling this method'
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
end
|
data/lib/mongo/config/options.rb
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
module Mongo
|
|
5
4
|
module Config
|
|
6
5
|
module Validators
|
|
7
|
-
|
|
8
6
|
# Validator for configuration options.
|
|
9
7
|
#
|
|
10
8
|
# @api private
|
|
@@ -17,9 +15,9 @@ module Mongo
|
|
|
17
15
|
#
|
|
18
16
|
# @param [ String ] option The name of the option.
|
|
19
17
|
def validate(option)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
return if Config.settings.keys.include?(option.to_sym)
|
|
19
|
+
|
|
20
|
+
raise Mongo::Error::InvalidConfigOption.new(option)
|
|
23
21
|
end
|
|
24
22
|
end
|
|
25
23
|
end
|
data/lib/mongo/config.rb
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require 'mongo/config/options'
|
|
4
|
+
require 'mongo/config/validators/option'
|
|
6
5
|
|
|
7
6
|
module Mongo
|
|
8
|
-
|
|
9
7
|
# This module defines configuration options for Mongo.
|
|
10
8
|
#
|
|
11
9
|
# @api private
|
|
@@ -27,6 +25,10 @@ module Mongo
|
|
|
27
25
|
# validate the parameters and raise an error if they are invalid.
|
|
28
26
|
option :validate_update_replace, default: false
|
|
29
27
|
|
|
28
|
+
# When this flag is set to true, the CSFLE will use Ruby types for
|
|
29
|
+
# decryption instead of BSON types.
|
|
30
|
+
option :csfle_convert_to_ruby_types, default: false
|
|
31
|
+
|
|
30
32
|
# Set the configuration options.
|
|
31
33
|
#
|
|
32
34
|
# @example Set the options.
|
|
@@ -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,12 +16,10 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Crypt
|
|
20
|
-
|
|
21
19
|
# A Context object initialized for auto decryption
|
|
22
20
|
#
|
|
23
21
|
# @api private
|
|
24
22
|
class AutoDecryptionContext < Context
|
|
25
|
-
|
|
26
23
|
# Create a new AutoEncryptionContext object
|
|
27
24
|
#
|
|
28
25
|
# @param [ Mongo::Crypt::Handle ] mongocrypt a Handle that
|
|
@@ -38,6 +35,15 @@ module Mongo
|
|
|
38
35
|
|
|
39
36
|
Binding.ctx_decrypt_init(self, @command)
|
|
40
37
|
end
|
|
38
|
+
|
|
39
|
+
# Which BSON mode to use when creating documents from the outcome of
|
|
40
|
+
# the state machine. The returned value is based on the
|
|
41
|
+
# +Mongo::Config.csfle_convert_to_ruby_types+ option.
|
|
42
|
+
#
|
|
43
|
+
# @return [ Symbol, nil ] The BSON mode.
|
|
44
|
+
def bson_mode
|
|
45
|
+
Mongo::Config.csfle_convert_to_ruby_types ? nil : :bson
|
|
46
|
+
end
|
|
41
47
|
end
|
|
42
48
|
end
|
|
43
49
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2019-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,8 +16,7 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Crypt
|
|
20
|
-
|
|
21
|
-
# An AutoEcnrypter is an object that encapsulates the behavior of
|
|
19
|
+
# An AutoEncrypter is an object that encapsulates the behavior of
|
|
22
20
|
# automatic encryption. It controls all resources associated with
|
|
23
21
|
# auto-encryption, including the libmongocrypt handle, key vault client
|
|
24
22
|
# object, mongocryptd client object, and encryption I/O.
|
|
@@ -29,19 +27,15 @@ module Mongo
|
|
|
29
27
|
#
|
|
30
28
|
# @api private
|
|
31
29
|
class AutoEncrypter
|
|
32
|
-
|
|
33
|
-
attr_reader :mongocryptd_client
|
|
34
|
-
attr_reader :key_vault_client
|
|
35
|
-
attr_reader :metadata_client
|
|
36
|
-
attr_reader :options
|
|
30
|
+
attr_reader :mongocryptd_client, :key_vault_client, :metadata_client, :options
|
|
37
31
|
|
|
38
32
|
# A Hash of default values for the :extra_options option
|
|
39
33
|
DEFAULT_EXTRA_OPTIONS = Options::Redacted.new({
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
mongocryptd_uri: 'mongodb://localhost:27020',
|
|
35
|
+
mongocryptd_bypass_spawn: false,
|
|
36
|
+
mongocryptd_spawn_path: 'mongocryptd',
|
|
37
|
+
mongocryptd_spawn_args: [ '--idleShutdownTimeoutSecs=60' ],
|
|
38
|
+
})
|
|
45
39
|
|
|
46
40
|
# Set up encryption-related options and instance variables
|
|
47
41
|
# on the class that includes this module. Calls the same method
|
|
@@ -105,6 +99,7 @@ module Mongo
|
|
|
105
99
|
bypass_query_analysis: @options[:bypass_query_analysis],
|
|
106
100
|
crypt_shared_lib_path: @options[:extra_options][:crypt_shared_lib_path],
|
|
107
101
|
crypt_shared_lib_required: @options[:extra_options][:crypt_shared_lib_required],
|
|
102
|
+
disable_crypt_shared_lib_search: @options[:extra_options][:disable_crypt_shared_lib_search]
|
|
108
103
|
)
|
|
109
104
|
|
|
110
105
|
@mongocryptd_options = @options[:extra_options].slice(
|
|
@@ -114,9 +109,9 @@ module Mongo
|
|
|
114
109
|
:mongocryptd_spawn_args
|
|
115
110
|
)
|
|
116
111
|
@mongocryptd_options[:mongocryptd_bypass_spawn] = @options[:bypass_auto_encryption] ||
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
112
|
+
@options[:extra_options][:mongocryptd_bypass_spawn] ||
|
|
113
|
+
@crypt_handle.crypt_shared_lib_available? ||
|
|
114
|
+
@options[:extra_options][:crypt_shared_lib_required]
|
|
120
115
|
|
|
121
116
|
unless @options[:extra_options][:crypt_shared_lib_required] || @crypt_handle.crypt_shared_lib_available? || @options[:bypass_query_analysis]
|
|
122
117
|
@mongocryptd_client = Client.new(
|
|
@@ -137,33 +132,31 @@ module Mongo
|
|
|
137
132
|
metadata_client: @metadata_client,
|
|
138
133
|
mongocryptd_options: @mongocryptd_options
|
|
139
134
|
)
|
|
140
|
-
rescue
|
|
135
|
+
rescue StandardError
|
|
141
136
|
begin
|
|
142
137
|
@mongocryptd_client&.close
|
|
143
|
-
rescue => e
|
|
138
|
+
rescue StandardError => e
|
|
144
139
|
log_warn("Error closing mongocryptd client in auto encrypter's constructor: #{e.class}: #{e}")
|
|
145
140
|
# Drop this exception so that the original exception is raised
|
|
146
141
|
end
|
|
147
142
|
raise
|
|
148
143
|
end
|
|
149
|
-
rescue
|
|
144
|
+
rescue StandardError
|
|
150
145
|
if @key_vault_client && @key_vault_client != options[:client] &&
|
|
151
|
-
|
|
152
|
-
then
|
|
146
|
+
@key_vault_client.cluster != options[:client].cluster
|
|
153
147
|
begin
|
|
154
148
|
@key_vault_client.close
|
|
155
|
-
rescue => e
|
|
149
|
+
rescue StandardError => e
|
|
156
150
|
log_warn("Error closing key vault client in auto encrypter's constructor: #{e.class}: #{e}")
|
|
157
151
|
# Drop this exception so that the original exception is raised
|
|
158
152
|
end
|
|
159
153
|
end
|
|
160
154
|
|
|
161
155
|
if @metadata_client && @metadata_client != options[:client] &&
|
|
162
|
-
|
|
163
|
-
then
|
|
156
|
+
@metadata_client.cluster != options[:client].cluster
|
|
164
157
|
begin
|
|
165
158
|
@metadata_client.close
|
|
166
|
-
rescue => e
|
|
159
|
+
rescue StandardError => e
|
|
167
160
|
log_warn("Error closing metadata client in auto encrypter's constructor: #{e.class}: #{e}")
|
|
168
161
|
# Drop this exception so that the original exception is raised
|
|
169
162
|
end
|
|
@@ -216,14 +209,12 @@ module Mongo
|
|
|
216
209
|
@mongocryptd_client.close if @mongocryptd_client
|
|
217
210
|
|
|
218
211
|
if @key_vault_client && @key_vault_client != options[:client] &&
|
|
219
|
-
|
|
220
|
-
then
|
|
212
|
+
@key_vault_client.cluster != options[:client].cluster
|
|
221
213
|
@key_vault_client.close
|
|
222
214
|
end
|
|
223
215
|
|
|
224
216
|
if @metadata_client && @metadata_client != options[:client] &&
|
|
225
|
-
|
|
226
|
-
then
|
|
217
|
+
@metadata_client.cluster != options[:client].cluster
|
|
227
218
|
@metadata_client.close
|
|
228
219
|
end
|
|
229
220
|
|
|
@@ -234,7 +225,7 @@ module Mongo
|
|
|
234
225
|
|
|
235
226
|
# Returns a new set of options with the following changes:
|
|
236
227
|
# - sets default values for all extra_options
|
|
237
|
-
# - adds --
|
|
228
|
+
# - adds --idleShutdownTimeoutSecs=60 to extra_options[:mongocryptd_spawn_args]
|
|
238
229
|
# if not already present
|
|
239
230
|
# - sets bypass_auto_encryption to false
|
|
240
231
|
# - sets default key vault client
|
|
@@ -268,20 +259,20 @@ module Mongo
|
|
|
268
259
|
def set_or_create_clients(options)
|
|
269
260
|
client = options[:client]
|
|
270
261
|
@key_vault_client = if options[:key_vault_client]
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
262
|
+
options[:key_vault_client]
|
|
263
|
+
elsif client.options[:max_pool_size] == 0
|
|
264
|
+
client
|
|
265
|
+
else
|
|
266
|
+
internal_client(client)
|
|
267
|
+
end
|
|
277
268
|
|
|
278
269
|
@metadata_client = if options[:bypass_auto_encryption]
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
270
|
+
nil
|
|
271
|
+
elsif client.options[:max_pool_size] == 0
|
|
272
|
+
client
|
|
273
|
+
else
|
|
274
|
+
internal_client(client)
|
|
275
|
+
end
|
|
285
276
|
end
|
|
286
277
|
|
|
287
278
|
# Creates or return already created internal client to be used for
|
|
@@ -296,7 +287,7 @@ module Mongo
|
|
|
296
287
|
@internal_client ||= client.with(
|
|
297
288
|
auto_encryption_options: nil,
|
|
298
289
|
min_pool_size: 0,
|
|
299
|
-
monitoring: client.send(:monitoring)
|
|
290
|
+
monitoring: client.send(:monitoring)
|
|
300
291
|
)
|
|
301
292
|
end
|
|
302
293
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2019-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,12 +16,10 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Crypt
|
|
20
|
-
|
|
21
19
|
# A Context object initialized for auto encryption
|
|
22
20
|
#
|
|
23
21
|
# @api private
|
|
24
22
|
class AutoEncryptionContext < Context
|
|
25
|
-
|
|
26
23
|
# Create a new AutoEncryptionContext object
|
|
27
24
|
#
|
|
28
25
|
# @param [ Mongo::Crypt::Handle ] mongocrypt a Handle that
|