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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2014-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,7 +16,6 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Protocol
|
|
20
|
-
|
|
21
19
|
# A base class providing functionality required by all messages in
|
|
22
20
|
# the MongoDB wire protocol. It provides a minimal DSL for defining typed
|
|
23
21
|
# fields to enable serialization and deserialization over the wire.
|
|
@@ -49,34 +47,34 @@ module Mongo
|
|
|
49
47
|
# The batch size constant.
|
|
50
48
|
#
|
|
51
49
|
# @since 2.2.0
|
|
52
|
-
BATCH_SIZE = 'batchSize'
|
|
50
|
+
BATCH_SIZE = 'batchSize'
|
|
53
51
|
|
|
54
52
|
# The collection constant.
|
|
55
53
|
#
|
|
56
54
|
# @since 2.2.0
|
|
57
|
-
COLLECTION = 'collection'
|
|
55
|
+
COLLECTION = 'collection'
|
|
58
56
|
|
|
59
57
|
# The limit constant.
|
|
60
58
|
#
|
|
61
59
|
# @since 2.2.0
|
|
62
|
-
LIMIT = 'limit'
|
|
60
|
+
LIMIT = 'limit'
|
|
63
61
|
|
|
64
62
|
# The ordered constant.
|
|
65
63
|
#
|
|
66
64
|
# @since 2.2.0
|
|
67
|
-
ORDERED = 'ordered'
|
|
65
|
+
ORDERED = 'ordered'
|
|
68
66
|
|
|
69
67
|
# The q constant.
|
|
70
68
|
#
|
|
71
69
|
# @since 2.2.0
|
|
72
|
-
Q = 'q'
|
|
70
|
+
Q = 'q'
|
|
73
71
|
|
|
74
72
|
# Default max message size of 48MB.
|
|
75
73
|
#
|
|
76
74
|
# @since 2.2.1
|
|
77
|
-
MAX_MESSAGE_SIZE =
|
|
75
|
+
MAX_MESSAGE_SIZE = 50_331_648
|
|
78
76
|
|
|
79
|
-
def initialize(*
|
|
77
|
+
def initialize(*_args) # :nodoc:
|
|
80
78
|
set_request_id
|
|
81
79
|
end
|
|
82
80
|
|
|
@@ -109,7 +107,7 @@ module Mongo
|
|
|
109
107
|
#
|
|
110
108
|
# @since 2.5.0
|
|
111
109
|
# @api private
|
|
112
|
-
def maybe_compress(
|
|
110
|
+
def maybe_compress(_compressor, _zlib_compression_level = nil)
|
|
113
111
|
self
|
|
114
112
|
end
|
|
115
113
|
|
|
@@ -149,8 +147,8 @@ module Mongo
|
|
|
149
147
|
#
|
|
150
148
|
# @return [ Mongo::Protocol::Msg ] The decrypted message, or the original
|
|
151
149
|
# message if decryption was not possible or necessary.
|
|
152
|
-
def maybe_decrypt(
|
|
153
|
-
# TODO determine if we should be decrypting data coming from pre-4.2
|
|
150
|
+
def maybe_decrypt(_context)
|
|
151
|
+
# TODO: determine if we should be decrypting data coming from pre-4.2
|
|
154
152
|
# servers, potentially using legacy wire protocols. If so we need
|
|
155
153
|
# to implement decryption for those wire protocols as our current
|
|
156
154
|
# encryption/decryption code is OP_MSG-specific.
|
|
@@ -165,32 +163,33 @@ module Mongo
|
|
|
165
163
|
#
|
|
166
164
|
# @return [ Mongo::Protocol::Msg ] The encrypted message, or the original
|
|
167
165
|
# message if encryption was not possible or necessary.
|
|
168
|
-
def maybe_encrypt(
|
|
166
|
+
def maybe_encrypt(_connection, _context)
|
|
169
167
|
# Do nothing if the Message subclass has not implemented this method
|
|
170
168
|
self
|
|
171
169
|
end
|
|
172
170
|
|
|
171
|
+
# Protocol message subclasses that support the server api option should
|
|
172
|
+
# override this method to add the server api document to the message.
|
|
173
|
+
#
|
|
174
|
+
# @param [ Hash ] server_api The server api document to add to the message.
|
|
173
175
|
def maybe_add_server_api(server_api)
|
|
174
|
-
raise
|
|
176
|
+
raise NotImplementedError
|
|
175
177
|
end
|
|
176
178
|
|
|
177
179
|
private def merge_sections
|
|
178
180
|
cmd = if @sections.length > 1
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if cmd.nil?
|
|
192
|
-
raise "The command should never be nil here"
|
|
193
|
-
end
|
|
181
|
+
cmd = @sections.detect { |section| section[:type] == 0 }[:payload]
|
|
182
|
+
identifier = @sections.detect { |section| section[:type] == 1 }[:payload][:identifier]
|
|
183
|
+
cmd.merge(identifier.to_sym =>
|
|
184
|
+
@sections.select { |section| section[:type] == 1 }
|
|
185
|
+
.sum([]) { |section| section[:payload][:sequence] })
|
|
186
|
+
elsif @sections.first[:payload]
|
|
187
|
+
@sections.first[:payload]
|
|
188
|
+
else
|
|
189
|
+
@sections.first
|
|
190
|
+
end
|
|
191
|
+
raise 'The command should never be nil here' if cmd.nil?
|
|
192
|
+
|
|
194
193
|
cmd
|
|
195
194
|
end
|
|
196
195
|
|
|
@@ -204,8 +203,6 @@ module Mongo
|
|
|
204
203
|
max_bson_size + bson_overhead
|
|
205
204
|
elsif max_bson_size
|
|
206
205
|
max_bson_size
|
|
207
|
-
else
|
|
208
|
-
nil
|
|
209
206
|
end
|
|
210
207
|
|
|
211
208
|
start = buffer.length
|
|
@@ -214,7 +211,7 @@ module Mongo
|
|
|
214
211
|
buffer.replace_int32(start, buffer.length - start)
|
|
215
212
|
end
|
|
216
213
|
|
|
217
|
-
|
|
214
|
+
alias to_s serialize
|
|
218
215
|
|
|
219
216
|
# Deserializes messages from an IO stream.
|
|
220
217
|
#
|
|
@@ -236,29 +233,26 @@ module Mongo
|
|
|
236
233
|
#
|
|
237
234
|
# @api private
|
|
238
235
|
def self.deserialize(io,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
)
|
|
236
|
+
max_message_size = MAX_MESSAGE_SIZE,
|
|
237
|
+
expected_response_to = nil,
|
|
238
|
+
options = {})
|
|
243
239
|
# io is usually a Mongo::Socket instance, which supports the
|
|
244
240
|
# timeout option. For compatibility with whoever might call this
|
|
245
241
|
# method with some other IO-like object, pass options only when they
|
|
246
242
|
# are not empty.
|
|
247
243
|
read_options = options.slice(:timeout, :socket_timeout)
|
|
248
244
|
|
|
249
|
-
if read_options.empty?
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
245
|
+
chunk = if read_options.empty?
|
|
246
|
+
io.read(16)
|
|
247
|
+
else
|
|
248
|
+
io.read(16, **read_options)
|
|
249
|
+
end
|
|
254
250
|
buf = BSON::ByteBuffer.new(chunk)
|
|
255
251
|
length, _request_id, response_to, _op_code = deserialize_header(buf)
|
|
256
252
|
|
|
257
253
|
# Protection from potential DOS man-in-the-middle attacks. See
|
|
258
254
|
# DRIVERS-276.
|
|
259
|
-
if length > (max_message_size || MAX_MESSAGE_SIZE)
|
|
260
|
-
raise Error::MaxMessageSize.new(max_message_size)
|
|
261
|
-
end
|
|
255
|
+
raise Error::MaxMessageSize.new(max_message_size) if length > (max_message_size || MAX_MESSAGE_SIZE)
|
|
262
256
|
|
|
263
257
|
# Protection against returning the response to a previous request. See
|
|
264
258
|
# RUBY-1117
|
|
@@ -266,11 +260,11 @@ module Mongo
|
|
|
266
260
|
raise Error::UnexpectedResponse.new(expected_response_to, response_to)
|
|
267
261
|
end
|
|
268
262
|
|
|
269
|
-
if read_options.empty?
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
263
|
+
chunk = if read_options.empty?
|
|
264
|
+
io.read(length - 16)
|
|
265
|
+
else
|
|
266
|
+
io.read(length - 16, **read_options)
|
|
267
|
+
end
|
|
274
268
|
buf = BSON::ByteBuffer.new(chunk)
|
|
275
269
|
|
|
276
270
|
message = Registry.get(_op_code).allocate
|
|
@@ -281,9 +275,7 @@ module Mongo
|
|
|
281
275
|
deserialize_field(message, buf, field, options)
|
|
282
276
|
end
|
|
283
277
|
end
|
|
284
|
-
if message.is_a?(Msg)
|
|
285
|
-
message.fix_after_deserialization
|
|
286
|
-
end
|
|
278
|
+
message.fix_after_deserialization if message.is_a?(Msg)
|
|
287
279
|
message.maybe_inflate
|
|
288
280
|
end
|
|
289
281
|
|
|
@@ -294,13 +286,14 @@ module Mongo
|
|
|
294
286
|
# @return [true, false] The equality of the messages.
|
|
295
287
|
def ==(other)
|
|
296
288
|
return false if self.class != other.class
|
|
289
|
+
|
|
297
290
|
fields.all? do |field|
|
|
298
291
|
name = field[:name]
|
|
299
292
|
instance_variable_get(name) ==
|
|
300
293
|
other.instance_variable_get(name)
|
|
301
294
|
end
|
|
302
295
|
end
|
|
303
|
-
|
|
296
|
+
alias eql? ==
|
|
304
297
|
|
|
305
298
|
# Creates a hash from the values of the fields of a message.
|
|
306
299
|
#
|
|
@@ -323,68 +316,23 @@ module Mongo
|
|
|
323
316
|
# @return [ 0 ] This method must be overridden, otherwise, always returns 0.
|
|
324
317
|
#
|
|
325
318
|
# @since 2.5.0
|
|
326
|
-
def number_returned
|
|
327
|
-
|
|
328
|
-
private
|
|
329
|
-
|
|
330
|
-
# A method for getting the fields for a message class
|
|
331
|
-
#
|
|
332
|
-
# @return [Integer] the fields for the message class
|
|
333
|
-
def fields
|
|
334
|
-
self.class.fields
|
|
319
|
+
def number_returned
|
|
320
|
+
0
|
|
335
321
|
end
|
|
336
322
|
|
|
337
323
|
# A class method for getting the fields for a message class
|
|
338
324
|
#
|
|
339
325
|
# @return [Integer] the fields for the message class
|
|
326
|
+
# @api private
|
|
340
327
|
def self.fields
|
|
341
328
|
@fields ||= []
|
|
342
329
|
end
|
|
343
330
|
|
|
344
|
-
# Serializes message fields into a buffer
|
|
345
|
-
#
|
|
346
|
-
# @param buffer [String] buffer to receive the field
|
|
347
|
-
# @return [String] buffer with serialized field
|
|
348
|
-
def serialize_fields(buffer, max_bson_size = nil)
|
|
349
|
-
fields.each do |field|
|
|
350
|
-
value = instance_variable_get(field[:name])
|
|
351
|
-
if field[:multi]
|
|
352
|
-
value.each do |item|
|
|
353
|
-
if field[:type].respond_to?(:size_limited?)
|
|
354
|
-
field[:type].serialize(buffer, item, max_bson_size)
|
|
355
|
-
else
|
|
356
|
-
field[:type].serialize(buffer, item)
|
|
357
|
-
end
|
|
358
|
-
end
|
|
359
|
-
else
|
|
360
|
-
if field[:type].respond_to?(:size_limited?)
|
|
361
|
-
field[:type].serialize(buffer, value, max_bson_size)
|
|
362
|
-
else
|
|
363
|
-
field[:type].serialize(buffer, value)
|
|
364
|
-
end
|
|
365
|
-
end
|
|
366
|
-
end
|
|
367
|
-
end
|
|
368
|
-
|
|
369
|
-
# Serializes the header of the message consisting of 4 32bit integers
|
|
370
|
-
#
|
|
371
|
-
# The integers represent a message length placeholder (calculation of
|
|
372
|
-
# the actual length is deferred) the request id, the response to id,
|
|
373
|
-
# and the op code for the message
|
|
374
|
-
#
|
|
375
|
-
# Currently uses hardcoded 0 for request id and response to as their
|
|
376
|
-
# values are irrelevent to the server
|
|
377
|
-
#
|
|
378
|
-
# @param buffer [String] Buffer to receive the header
|
|
379
|
-
# @return [String] Serialized header
|
|
380
|
-
def serialize_header(buffer)
|
|
381
|
-
Header.serialize(buffer, [0, request_id, 0, op_code])
|
|
382
|
-
end
|
|
383
|
-
|
|
384
331
|
# Deserializes the header of the message
|
|
385
332
|
#
|
|
386
333
|
# @param io [IO] Stream containing the header.
|
|
387
334
|
# @return [Array<Fixnum>] Deserialized header.
|
|
335
|
+
# @api private
|
|
388
336
|
def self.deserialize_header(io)
|
|
389
337
|
Header.deserialize(io)
|
|
390
338
|
end
|
|
@@ -404,11 +352,12 @@ module Mongo
|
|
|
404
352
|
# fields that use the number.
|
|
405
353
|
#
|
|
406
354
|
# @return [NilClass]
|
|
355
|
+
# @api private
|
|
407
356
|
def self.field(name, type, multi = false)
|
|
408
357
|
fields << {
|
|
409
|
-
:
|
|
410
|
-
:
|
|
411
|
-
:
|
|
358
|
+
name: :"@#{name}",
|
|
359
|
+
type: type,
|
|
360
|
+
multi: multi
|
|
412
361
|
}
|
|
413
362
|
|
|
414
363
|
attr_reader name
|
|
@@ -429,6 +378,7 @@ module Mongo
|
|
|
429
378
|
# each of the elements in this array using BSON types wherever possible.
|
|
430
379
|
#
|
|
431
380
|
# @return [Message] Message with deserialized array.
|
|
381
|
+
# @api private
|
|
432
382
|
def self.deserialize_array(message, io, field, options = {})
|
|
433
383
|
elements = []
|
|
434
384
|
count = message.instance_variable_get(field[:multi])
|
|
@@ -447,12 +397,60 @@ module Mongo
|
|
|
447
397
|
# this field using BSON types wherever possible.
|
|
448
398
|
#
|
|
449
399
|
# @return [Message] Message with deserialized field.
|
|
400
|
+
# @api private
|
|
450
401
|
def self.deserialize_field(message, io, field, options = {})
|
|
451
402
|
message.instance_variable_set(
|
|
452
403
|
field[:name],
|
|
453
404
|
field[:type].deserialize(io, options)
|
|
454
405
|
)
|
|
455
406
|
end
|
|
407
|
+
|
|
408
|
+
private
|
|
409
|
+
|
|
410
|
+
# A method for getting the fields for a message class
|
|
411
|
+
#
|
|
412
|
+
# @return [Integer] the fields for the message class
|
|
413
|
+
def fields
|
|
414
|
+
self.class.fields
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
# Serializes message fields into a buffer
|
|
418
|
+
#
|
|
419
|
+
# @param buffer [String] buffer to receive the field
|
|
420
|
+
# @return [String] buffer with serialized field
|
|
421
|
+
def serialize_fields(buffer, max_bson_size = nil)
|
|
422
|
+
fields.each do |field|
|
|
423
|
+
value = instance_variable_get(field[:name])
|
|
424
|
+
if field[:multi]
|
|
425
|
+
value.each do |item|
|
|
426
|
+
if field[:type].respond_to?(:size_limited?)
|
|
427
|
+
field[:type].serialize(buffer, item, max_bson_size)
|
|
428
|
+
else
|
|
429
|
+
field[:type].serialize(buffer, item)
|
|
430
|
+
end
|
|
431
|
+
end
|
|
432
|
+
elsif field[:type].respond_to?(:size_limited?)
|
|
433
|
+
field[:type].serialize(buffer, value, max_bson_size)
|
|
434
|
+
else
|
|
435
|
+
field[:type].serialize(buffer, value)
|
|
436
|
+
end
|
|
437
|
+
end
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
# Serializes the header of the message consisting of 4 32bit integers
|
|
441
|
+
#
|
|
442
|
+
# The integers represent a message length placeholder (calculation of
|
|
443
|
+
# the actual length is deferred) the request id, the response to id,
|
|
444
|
+
# and the op code for the message
|
|
445
|
+
#
|
|
446
|
+
# Currently uses hardcoded 0 for request id and response to as their
|
|
447
|
+
# values are irrelevant to the server
|
|
448
|
+
#
|
|
449
|
+
# @param buffer [String] Buffer to receive the header
|
|
450
|
+
# @return [String] Serialized header
|
|
451
|
+
def serialize_header(buffer)
|
|
452
|
+
Header.serialize(buffer, [ 0, request_id, 0, op_code ])
|
|
453
|
+
end
|
|
456
454
|
end
|
|
457
455
|
end
|
|
458
456
|
end
|
data/lib/mongo/protocol/msg.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2017-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,12 +16,9 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Protocol
|
|
20
|
-
|
|
21
19
|
# MongoDB Wire protocol Msg message (OP_MSG), a bi-directional wire
|
|
22
20
|
# protocol opcode.
|
|
23
21
|
#
|
|
24
|
-
# OP_MSG is only available in MongoDB 3.6 (maxWireVersion >= 6) and later.
|
|
25
|
-
#
|
|
26
22
|
# @api private
|
|
27
23
|
#
|
|
28
24
|
# @since 2.5.0
|
|
@@ -32,13 +28,13 @@ module Mongo
|
|
|
32
28
|
# The identifier for the database name to execute the command on.
|
|
33
29
|
#
|
|
34
30
|
# @since 2.5.0
|
|
35
|
-
DATABASE_IDENTIFIER = '$db'
|
|
31
|
+
DATABASE_IDENTIFIER = '$db'
|
|
36
32
|
|
|
37
33
|
# Keys that the driver adds to commands. These are going to be
|
|
38
34
|
# moved to the end of the hash for better logging.
|
|
39
35
|
#
|
|
40
36
|
# @api private
|
|
41
|
-
INTERNAL_KEYS = Set.new(%w
|
|
37
|
+
INTERNAL_KEYS = Set.new(%w[$clusterTime $db lsid signature txnNumber]).freeze
|
|
42
38
|
|
|
43
39
|
# Creates a new OP_MSG protocol message
|
|
44
40
|
#
|
|
@@ -66,9 +62,7 @@ module Mongo
|
|
|
66
62
|
def initialize(flags, options, main_document, *sequences)
|
|
67
63
|
if flags
|
|
68
64
|
flags.each do |flag|
|
|
69
|
-
unless KNOWN_FLAGS.key?(flag)
|
|
70
|
-
raise ArgumentError, "Unknown flag: #{flag.inspect}"
|
|
71
|
-
end
|
|
65
|
+
raise ArgumentError, "Unknown flag: #{flag.inspect}" unless KNOWN_FLAGS.key?(flag)
|
|
72
66
|
end
|
|
73
67
|
end
|
|
74
68
|
@flags = flags || []
|
|
@@ -76,6 +70,7 @@ module Mongo
|
|
|
76
70
|
unless main_document.is_a?(Hash)
|
|
77
71
|
raise ArgumentError, "Main document must be a Hash, given: #{main_document.class}"
|
|
78
72
|
end
|
|
73
|
+
|
|
79
74
|
@main_document = main_document
|
|
80
75
|
sequences.each_with_index do |section, index|
|
|
81
76
|
unless section.is_a?(Section1)
|
|
@@ -84,14 +79,14 @@ module Mongo
|
|
|
84
79
|
end
|
|
85
80
|
@sequences = sequences
|
|
86
81
|
@sections = [
|
|
87
|
-
{type: 0, payload: @main_document}
|
|
82
|
+
{ type: 0, payload: @main_document }
|
|
88
83
|
] + @sequences.map do |section|
|
|
89
|
-
{type: 1, payload: {
|
|
84
|
+
{ type: 1, payload: {
|
|
90
85
|
identifier: section.identifier,
|
|
91
86
|
sequence: section.documents.map do |doc|
|
|
92
87
|
CachingHash.new(doc)
|
|
93
88
|
end,
|
|
94
|
-
}}
|
|
89
|
+
} }
|
|
95
90
|
end
|
|
96
91
|
@request_id = nil
|
|
97
92
|
super
|
|
@@ -140,7 +135,7 @@ module Mongo
|
|
|
140
135
|
database_name: @main_document[DATABASE_IDENTIFIER],
|
|
141
136
|
command: ordered_command,
|
|
142
137
|
request_id: request_id,
|
|
143
|
-
reply: @main_document
|
|
138
|
+
reply: @main_document
|
|
144
139
|
)
|
|
145
140
|
end
|
|
146
141
|
|
|
@@ -182,19 +177,20 @@ module Mongo
|
|
|
182
177
|
#
|
|
183
178
|
# @api private
|
|
184
179
|
def fix_after_deserialization
|
|
185
|
-
if @sections.nil?
|
|
186
|
-
|
|
187
|
-
end
|
|
180
|
+
raise NotImplementedError, 'After deserializations @sections should have been initialized' if @sections.nil?
|
|
181
|
+
|
|
188
182
|
if @sections.length != 1
|
|
189
|
-
raise NotImplementedError,
|
|
183
|
+
raise NotImplementedError,
|
|
184
|
+
"Deserialization must have produced exactly one section, but it produced #{sections.length} sections"
|
|
190
185
|
end
|
|
186
|
+
|
|
191
187
|
@main_document = @sections.first
|
|
192
188
|
@sequences = []
|
|
193
|
-
@sections = [{type: 0, payload: @main_document}]
|
|
189
|
+
@sections = [ { type: 0, payload: @main_document } ]
|
|
194
190
|
end
|
|
195
191
|
|
|
196
192
|
def documents
|
|
197
|
-
[@main_document]
|
|
193
|
+
[ @main_document ]
|
|
198
194
|
end
|
|
199
195
|
|
|
200
196
|
# Possibly encrypt this message with libmongocrypt. Message will only be
|
|
@@ -212,24 +208,20 @@ module Mongo
|
|
|
212
208
|
# @return [ Mongo::Protocol::Msg ] The encrypted message, or the original
|
|
213
209
|
# message if encryption was not possible or necessary.
|
|
214
210
|
def maybe_encrypt(connection, context)
|
|
215
|
-
# TODO verify compression happens later, i.e. when this method runs
|
|
216
|
-
# the message is not compressed.
|
|
217
211
|
if context.encrypt?
|
|
218
212
|
if connection.description.max_wire_version < 8
|
|
219
213
|
raise Error::CryptError.new(
|
|
220
|
-
|
|
221
|
-
|
|
214
|
+
'Cannot perform encryption against a MongoDB server older than ' +
|
|
215
|
+
'4.2 (wire version less than 8). Currently connected to server ' +
|
|
222
216
|
"with max wire version #{connection.description.max_wire_version}} " +
|
|
223
|
-
|
|
217
|
+
'(Auto-encryption requires a minimum MongoDB version of 4.2)'
|
|
224
218
|
)
|
|
225
219
|
end
|
|
226
220
|
|
|
227
221
|
db_name = @main_document[DATABASE_IDENTIFIER]
|
|
228
222
|
cmd = merge_sections
|
|
229
223
|
enc_cmd = context.encrypt(db_name, cmd)
|
|
230
|
-
if cmd.key?('$db') && !enc_cmd.key?('$db')
|
|
231
|
-
enc_cmd['$db'] = cmd['$db']
|
|
232
|
-
end
|
|
224
|
+
enc_cmd['$db'] = cmd['$db'] if cmd.key?('$db') && !enc_cmd.key?('$db')
|
|
233
225
|
|
|
234
226
|
Msg.new(@flags, @options, enc_cmd)
|
|
235
227
|
else
|
|
@@ -274,25 +266,22 @@ module Mongo
|
|
|
274
266
|
updates = @main_document['updates']
|
|
275
267
|
deletes = @main_document['deletes']
|
|
276
268
|
|
|
277
|
-
num_inserts = inserts && inserts.length || 0
|
|
278
|
-
num_updates = updates && updates.length || 0
|
|
279
|
-
num_deletes = deletes && deletes.length || 0
|
|
269
|
+
num_inserts = (inserts && inserts.length) || 0
|
|
270
|
+
num_updates = (updates && updates.length) || 0
|
|
271
|
+
num_deletes = (deletes && deletes.length) || 0
|
|
280
272
|
|
|
281
|
-
num_inserts > 1
|
|
273
|
+
num_inserts > 1 || num_updates > 1 || num_deletes > 1
|
|
282
274
|
end
|
|
283
275
|
|
|
284
276
|
def maybe_add_server_api(server_api)
|
|
285
277
|
conflicts = {}
|
|
286
|
-
%i
|
|
287
|
-
if @main_document.key?(key)
|
|
288
|
-
|
|
289
|
-
end
|
|
290
|
-
if @main_document.key?(key.to_s)
|
|
291
|
-
conflicts[key] = @main_document[key.to_s]
|
|
292
|
-
end
|
|
278
|
+
%i[apiVersion apiStrict apiDeprecationErrors].each do |key|
|
|
279
|
+
conflicts[key] = @main_document[key] if @main_document.key?(key)
|
|
280
|
+
conflicts[key] = @main_document[key.to_s] if @main_document.key?(key.to_s)
|
|
293
281
|
end
|
|
294
282
|
unless conflicts.empty?
|
|
295
|
-
raise Error::ServerApiConflict,
|
|
283
|
+
raise Error::ServerApiConflict,
|
|
284
|
+
"The Client is configured with :server_api option but the operation provided the following conflicting parameters: #{conflicts.inspect}"
|
|
296
285
|
end
|
|
297
286
|
|
|
298
287
|
main_document = @main_document.merge(
|
|
@@ -309,14 +298,11 @@ module Mongo
|
|
|
309
298
|
#
|
|
310
299
|
# @return [ Integer ] Number of returned documents.
|
|
311
300
|
def number_returned
|
|
312
|
-
if doc = documents.first
|
|
313
|
-
|
|
314
|
-
if batch = cursor['firstBatch'] || cursor['nextBatch']
|
|
315
|
-
return batch.length
|
|
316
|
-
end
|
|
317
|
-
end
|
|
301
|
+
if (doc = documents.first) && (cursor = doc['cursor']) && (batch = cursor['firstBatch'] || cursor['nextBatch'])
|
|
302
|
+
return batch.length
|
|
318
303
|
end
|
|
319
|
-
|
|
304
|
+
|
|
305
|
+
raise NotImplementedError, 'number_returned is only defined for cursor replies'
|
|
320
306
|
end
|
|
321
307
|
|
|
322
308
|
private
|
|
@@ -333,28 +319,27 @@ module Mongo
|
|
|
333
319
|
end
|
|
334
320
|
end
|
|
335
321
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
322
|
+
return unless contains_too_large_document
|
|
323
|
+
|
|
324
|
+
raise Error::MaxBSONSize.new('The document exceeds maximum allowed BSON object size after serialization')
|
|
339
325
|
end
|
|
340
326
|
|
|
341
327
|
def command
|
|
342
328
|
@command ||= if @main_document
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
329
|
+
@main_document.dup.tap do |cmd|
|
|
330
|
+
@sequences.each do |section|
|
|
331
|
+
cmd[section.identifier] ||= []
|
|
332
|
+
cmd[section.identifier] += section.documents
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
else
|
|
336
|
+
documents.first
|
|
337
|
+
end
|
|
352
338
|
end
|
|
353
339
|
|
|
354
|
-
def add_check_sum(
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
end
|
|
340
|
+
def add_check_sum(_buffer)
|
|
341
|
+
nil unless flags.include?(:checksum_present)
|
|
342
|
+
# buffer.put_int32(checksum)
|
|
358
343
|
end
|
|
359
344
|
|
|
360
345
|
# Encapsulates a type 1 OP_MSG section.
|
|
@@ -374,7 +359,7 @@ module Mongo
|
|
|
374
359
|
identifier == other.identifier && documents == other.documents
|
|
375
360
|
end
|
|
376
361
|
|
|
377
|
-
alias
|
|
362
|
+
alias eql? ==
|
|
378
363
|
end
|
|
379
364
|
|
|
380
365
|
# The operation code required to specify a OP_MSG message.
|