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/protocol/query.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
|
#
|
|
@@ -17,7 +16,6 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Protocol
|
|
20
|
-
|
|
21
19
|
# MongoDB Wire protocol Query message.
|
|
22
20
|
#
|
|
23
21
|
# This is a client request message that is sent to the server in order
|
|
@@ -64,20 +62,19 @@ module Mongo
|
|
|
64
62
|
def initialize(database, collection, selector, options = {})
|
|
65
63
|
@database = database
|
|
66
64
|
@namespace = "#{database}.#{collection}"
|
|
67
|
-
if selector.nil?
|
|
68
|
-
|
|
69
|
-
end
|
|
65
|
+
raise ArgumentError, 'Selector cannot be nil' if selector.nil?
|
|
66
|
+
|
|
70
67
|
@selector = selector
|
|
71
68
|
@options = options
|
|
72
69
|
@project = options[:project]
|
|
73
70
|
@limit = determine_limit
|
|
74
|
-
@skip = options[:skip]
|
|
71
|
+
@skip = options[:skip] || 0
|
|
75
72
|
@flags = options[:flags] || []
|
|
76
73
|
@upconverter = Upconverter.new(
|
|
77
74
|
collection,
|
|
78
75
|
BSON::Document.new(selector),
|
|
79
76
|
BSON::Document.new(options),
|
|
80
|
-
flags
|
|
77
|
+
flags
|
|
81
78
|
)
|
|
82
79
|
super
|
|
83
80
|
end
|
|
@@ -163,9 +160,9 @@ module Mongo
|
|
|
163
160
|
doc.to_bson.length > max_bson_size
|
|
164
161
|
end
|
|
165
162
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
163
|
+
return unless contains_too_large_document
|
|
164
|
+
|
|
165
|
+
raise Error::MaxBSONSize.new('The document exceeds maximum allowed BSON object size after serialization')
|
|
169
166
|
end
|
|
170
167
|
|
|
171
168
|
# The operation code required to specify a Query message.
|
|
@@ -180,15 +177,15 @@ module Mongo
|
|
|
180
177
|
|
|
181
178
|
# Available flags for a Query message.
|
|
182
179
|
# @api private
|
|
183
|
-
FLAGS = [
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
180
|
+
FLAGS = %i[
|
|
181
|
+
reserved
|
|
182
|
+
tailable_cursor
|
|
183
|
+
secondary_ok
|
|
184
|
+
oplog_replay
|
|
185
|
+
no_cursor_timeout
|
|
186
|
+
await_data
|
|
187
|
+
exhaust
|
|
188
|
+
partial
|
|
192
189
|
]
|
|
193
190
|
|
|
194
191
|
# @!attribute
|
|
@@ -215,20 +212,19 @@ module Mongo
|
|
|
215
212
|
# @return [Hash] The projection.
|
|
216
213
|
field :project, Document
|
|
217
214
|
|
|
218
|
-
# Converts legacy query messages to the
|
|
215
|
+
# Converts legacy query messages to the appropriate OP_COMMAND style
|
|
219
216
|
# message.
|
|
220
217
|
#
|
|
221
218
|
# @since 2.1.0
|
|
222
219
|
class Upconverter
|
|
223
|
-
|
|
224
220
|
# Mappings of the options to the find command options.
|
|
225
221
|
#
|
|
226
222
|
# @since 2.1.0
|
|
227
223
|
OPTION_MAPPINGS = {
|
|
228
|
-
:
|
|
229
|
-
:
|
|
230
|
-
:
|
|
231
|
-
:
|
|
224
|
+
project: 'projection',
|
|
225
|
+
skip: 'skip',
|
|
226
|
+
limit: 'limit',
|
|
227
|
+
batch_size: 'batchSize'
|
|
232
228
|
}.freeze
|
|
233
229
|
|
|
234
230
|
SPECIAL_FIELD_MAPPINGS = {
|
|
@@ -250,11 +246,11 @@ module Mongo
|
|
|
250
246
|
#
|
|
251
247
|
# @since 2.1.0
|
|
252
248
|
FLAG_MAPPINGS = {
|
|
253
|
-
:
|
|
254
|
-
:
|
|
255
|
-
:
|
|
256
|
-
:
|
|
257
|
-
:
|
|
249
|
+
tailable_cursor: 'tailable',
|
|
250
|
+
oplog_replay: 'oplogReplay',
|
|
251
|
+
no_cursor_timeout: 'noCursorTimeout',
|
|
252
|
+
await_data: 'awaitData',
|
|
253
|
+
partial: 'allowPartialResults'
|
|
258
254
|
}.freeze
|
|
259
255
|
|
|
260
256
|
# @return [ String ] collection The name of the collection.
|
|
@@ -284,12 +280,9 @@ module Mongo
|
|
|
284
280
|
# Although the docstring claims both hashes and BSON::Documents
|
|
285
281
|
# are acceptable, this class expects the filter and options to
|
|
286
282
|
# contain symbol keys which isn't what the operation layer produces.
|
|
287
|
-
unless BSON::Document
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
unless BSON::Document === options
|
|
291
|
-
raise ArgumentError, 'Options must provide indifferent access'
|
|
292
|
-
end
|
|
283
|
+
raise ArgumentError, 'Filter must provide indifferent access' unless filter.is_a?(BSON::Document)
|
|
284
|
+
raise ArgumentError, 'Options must provide indifferent access' unless options.is_a?(BSON::Document)
|
|
285
|
+
|
|
293
286
|
@collection = collection
|
|
294
287
|
@filter = filter
|
|
295
288
|
@options = options
|
|
@@ -342,16 +335,14 @@ module Mongo
|
|
|
342
335
|
def find_command
|
|
343
336
|
document = BSON::Document.new(
|
|
344
337
|
find: collection,
|
|
345
|
-
filter: query_filter
|
|
338
|
+
filter: query_filter
|
|
346
339
|
)
|
|
347
340
|
OPTION_MAPPINGS.each do |legacy, option|
|
|
348
341
|
document.store(option, options[legacy]) unless options[legacy].nil?
|
|
349
342
|
end
|
|
350
343
|
if Lint.enabled?
|
|
351
|
-
filter.each do |k,
|
|
352
|
-
|
|
353
|
-
raise Error::LintError, "All keys in filter must be strings: #{filter.inspect}"
|
|
354
|
-
end
|
|
344
|
+
filter.each do |k, _v|
|
|
345
|
+
raise Error::LintError, "All keys in filter must be strings: #{filter.inspect}" unless k.is_a?(String)
|
|
355
346
|
end
|
|
356
347
|
end
|
|
357
348
|
Lint.validate_camel_case_read_preference(filter['readPreference'])
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -16,9 +15,7 @@
|
|
|
16
15
|
# limitations under the License.
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
|
-
|
|
20
18
|
module Protocol
|
|
21
|
-
|
|
22
19
|
# Provides a registry for looking up a message class based on op code.
|
|
23
20
|
#
|
|
24
21
|
# @since 2.5.0
|
|
@@ -38,7 +35,7 @@ module Mongo
|
|
|
38
35
|
# @return [ Class ] The corresponding Ruby class for the message type.
|
|
39
36
|
#
|
|
40
37
|
# @since 2.5.0
|
|
41
|
-
def get(op_code,
|
|
38
|
+
def get(op_code, _message = nil)
|
|
42
39
|
if type = MAPPINGS[op_code]
|
|
43
40
|
type
|
|
44
41
|
else
|
|
@@ -65,7 +62,7 @@ module Mongo
|
|
|
65
62
|
private
|
|
66
63
|
|
|
67
64
|
def define_type_reader(type)
|
|
68
|
-
type.module_eval <<-MOD
|
|
65
|
+
type.module_eval <<-MOD, __FILE__, __LINE__ + 1
|
|
69
66
|
def op_code; OP_CODE; end
|
|
70
67
|
MOD
|
|
71
68
|
end
|
data/lib/mongo/protocol/reply.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
|
#
|
|
@@ -17,7 +16,6 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Protocol
|
|
20
|
-
|
|
21
19
|
# The MongoDB wire protocol message representing a reply
|
|
22
20
|
#
|
|
23
21
|
# @example
|
|
@@ -28,7 +26,6 @@ module Mongo
|
|
|
28
26
|
#
|
|
29
27
|
# @api semipublic
|
|
30
28
|
class Reply < Message
|
|
31
|
-
|
|
32
29
|
# Determine if the reply had a query failure flag.
|
|
33
30
|
#
|
|
34
31
|
# @example Did the reply have a query failure.
|
|
@@ -81,15 +78,13 @@ module Mongo
|
|
|
81
78
|
OP_CODE = 1
|
|
82
79
|
|
|
83
80
|
# Available flags for a Reply message.
|
|
84
|
-
FLAGS = [
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
FLAGS = %i[
|
|
82
|
+
cursor_not_found
|
|
83
|
+
query_failure
|
|
84
|
+
shard_config_stale
|
|
85
|
+
await_capable
|
|
89
86
|
]
|
|
90
87
|
|
|
91
|
-
public
|
|
92
|
-
|
|
93
88
|
# @!attribute
|
|
94
89
|
# @return [Array<Symbol>] The flags for this reply.
|
|
95
90
|
#
|
|
@@ -118,26 +113,25 @@ module Mongo
|
|
|
118
113
|
#
|
|
119
114
|
# @since 2.1.0
|
|
120
115
|
class Upconverter
|
|
121
|
-
|
|
122
116
|
# Next batch constant.
|
|
123
117
|
#
|
|
124
118
|
# @since 2.1.0
|
|
125
|
-
NEXT_BATCH = 'nextBatch'
|
|
119
|
+
NEXT_BATCH = 'nextBatch'
|
|
126
120
|
|
|
127
121
|
# First batch constant.
|
|
128
122
|
#
|
|
129
123
|
# @since 2.1.0
|
|
130
|
-
FIRST_BATCH = 'firstBatch'
|
|
124
|
+
FIRST_BATCH = 'firstBatch'
|
|
131
125
|
|
|
132
126
|
# Cursor field constant.
|
|
133
127
|
#
|
|
134
128
|
# @since 2.1.0
|
|
135
|
-
CURSOR = 'cursor'
|
|
129
|
+
CURSOR = 'cursor'
|
|
136
130
|
|
|
137
131
|
# Id field constant.
|
|
138
132
|
#
|
|
139
133
|
# @since 2.1.0
|
|
140
|
-
ID = 'id'
|
|
134
|
+
ID = 'id'
|
|
141
135
|
|
|
142
136
|
# Initialize the new upconverter.
|
|
143
137
|
#
|
|
@@ -179,7 +173,7 @@ module Mongo
|
|
|
179
173
|
private
|
|
180
174
|
|
|
181
175
|
def batch_field
|
|
182
|
-
starting_from > 0 ? NEXT_BATCH : FIRST_BATCH
|
|
176
|
+
(starting_from > 0) ? NEXT_BATCH : FIRST_BATCH
|
|
183
177
|
end
|
|
184
178
|
|
|
185
179
|
def command?
|
|
@@ -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,13 +16,12 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Protocol
|
|
20
|
-
|
|
21
19
|
# Container for various serialization strategies
|
|
22
20
|
#
|
|
23
|
-
# Each strategy must have a serialization method named +
|
|
21
|
+
# Each strategy must have a serialization method named +serialize+
|
|
24
22
|
# and a deserialization method named +deserialize+
|
|
25
23
|
#
|
|
26
|
-
# Serialize methods must take buffer and value
|
|
24
|
+
# Serialize methods must take buffer and value arguments and
|
|
27
25
|
# serialize the value into the buffer
|
|
28
26
|
#
|
|
29
27
|
# Deserialize methods must take an IO stream argument and
|
|
@@ -31,14 +29,11 @@ module Mongo
|
|
|
31
29
|
#
|
|
32
30
|
# @api private
|
|
33
31
|
module Serializers
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
ZERO = 0.freeze
|
|
32
|
+
ZERO = 0
|
|
38
33
|
NULL = 0.chr.freeze
|
|
39
|
-
INT32_PACK = 'l<'
|
|
40
|
-
INT64_PACK = 'q<'
|
|
41
|
-
HEADER_PACK = 'l<l<l<l<'
|
|
34
|
+
INT32_PACK = 'l<'
|
|
35
|
+
INT64_PACK = 'q<'
|
|
36
|
+
HEADER_PACK = 'l<l<l<l<'
|
|
42
37
|
|
|
43
38
|
# MongoDB wire protocol serialization strategy for message headers.
|
|
44
39
|
#
|
|
@@ -46,7 +41,6 @@ module Mongo
|
|
|
46
41
|
# of the length of the message, the request id, the response id,
|
|
47
42
|
# and the op code for the operation.
|
|
48
43
|
module Header
|
|
49
|
-
|
|
50
44
|
# Serializes the header value into the buffer
|
|
51
45
|
#
|
|
52
46
|
# @param buffer [ String ] Buffer to receive the serialized value.
|
|
@@ -55,7 +49,7 @@ module Mongo
|
|
|
55
49
|
# This option is deprecated and will not be used. It will removed in version 3.0.
|
|
56
50
|
#
|
|
57
51
|
# @return [ String ] Buffer with serialized value.
|
|
58
|
-
def self.serialize(buffer, value,
|
|
52
|
+
def self.serialize(buffer, value, _validating_keys = nil)
|
|
59
53
|
buffer.put_bytes(value.pack(HEADER_PACK))
|
|
60
54
|
end
|
|
61
55
|
|
|
@@ -66,7 +60,7 @@ module Mongo
|
|
|
66
60
|
#
|
|
67
61
|
# @return [ Array<Fixnum> ] Array consisting of the deserialized
|
|
68
62
|
# length, request id, response id, and op code.
|
|
69
|
-
def self.deserialize(buffer,
|
|
63
|
+
def self.deserialize(buffer, _options = {})
|
|
70
64
|
buffer.get_bytes(16).unpack(HEADER_PACK)
|
|
71
65
|
end
|
|
72
66
|
end
|
|
@@ -75,14 +69,13 @@ module Mongo
|
|
|
75
69
|
#
|
|
76
70
|
# Serializes and de-serializes C style strings (null terminated).
|
|
77
71
|
module CString
|
|
78
|
-
|
|
79
72
|
# Serializes a C style string into the buffer
|
|
80
73
|
#
|
|
81
74
|
# @param buffer [ String ] Buffer to receive the serialized CString.
|
|
82
75
|
# @param value [ String ] The string to be serialized.
|
|
83
76
|
#
|
|
84
77
|
# @return [ String ] Buffer with serialized value.
|
|
85
|
-
def self.serialize(buffer, value,
|
|
78
|
+
def self.serialize(buffer, value, _validating_keys = nil)
|
|
86
79
|
buffer.put_cstring(value)
|
|
87
80
|
end
|
|
88
81
|
end
|
|
@@ -91,14 +84,13 @@ module Mongo
|
|
|
91
84
|
#
|
|
92
85
|
# Serializes and de-serializes one 32-bit Zero.
|
|
93
86
|
module Zero
|
|
94
|
-
|
|
95
87
|
# Serializes a 32-bit Zero into the buffer
|
|
96
88
|
#
|
|
97
89
|
# @param buffer [ String ] Buffer to receive the serialized Zero.
|
|
98
90
|
# @param value [ Fixnum ] Ignored value.
|
|
99
91
|
#
|
|
100
92
|
# @return [ String ] Buffer with serialized value.
|
|
101
|
-
def self.serialize(buffer,
|
|
93
|
+
def self.serialize(buffer, _value, _validating_keys = nil)
|
|
102
94
|
buffer.put_int32(ZERO)
|
|
103
95
|
end
|
|
104
96
|
end
|
|
@@ -107,21 +99,20 @@ module Mongo
|
|
|
107
99
|
#
|
|
108
100
|
# Serializes and de-serializes one 32-bit integer.
|
|
109
101
|
module Int32
|
|
110
|
-
|
|
111
102
|
# Serializes a number to a 32-bit integer
|
|
112
103
|
#
|
|
113
104
|
# @param buffer [ String ] Buffer to receive the serialized Int32.
|
|
114
105
|
# @param value [ Integer | BSON::Int32 ] 32-bit integer to be serialized.
|
|
115
106
|
#
|
|
116
107
|
# @return [String] Buffer with serialized value.
|
|
117
|
-
def self.serialize(buffer, value,
|
|
108
|
+
def self.serialize(buffer, value, _validating_keys = nil)
|
|
118
109
|
if value.is_a?(BSON::Int32)
|
|
119
|
-
if value.respond_to?(:value)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
110
|
+
value = if value.respond_to?(:value)
|
|
111
|
+
# bson-ruby >= 4.6.0
|
|
112
|
+
value.value
|
|
113
|
+
else
|
|
114
|
+
value.instance_variable_get(:@integer)
|
|
115
|
+
end
|
|
125
116
|
end
|
|
126
117
|
buffer.put_int32(value)
|
|
127
118
|
end
|
|
@@ -132,7 +123,7 @@ module Mongo
|
|
|
132
123
|
# @param [ Hash ] options This method currently accepts no options.
|
|
133
124
|
#
|
|
134
125
|
# @return [ Fixnum ] Deserialized Int32
|
|
135
|
-
def self.deserialize(buffer,
|
|
126
|
+
def self.deserialize(buffer, _options = {})
|
|
136
127
|
buffer.get_int32
|
|
137
128
|
end
|
|
138
129
|
end
|
|
@@ -141,21 +132,20 @@ module Mongo
|
|
|
141
132
|
#
|
|
142
133
|
# Serializes and de-serializes one 64-bit integer.
|
|
143
134
|
module Int64
|
|
144
|
-
|
|
145
135
|
# Serializes a number to a 64-bit integer
|
|
146
136
|
#
|
|
147
137
|
# @param buffer [ String ] Buffer to receive the serialized Int64.
|
|
148
138
|
# @param value [ Integer | BSON::Int64 ] 64-bit integer to be serialized.
|
|
149
139
|
#
|
|
150
140
|
# @return [ String ] Buffer with serialized value.
|
|
151
|
-
def self.serialize(buffer, value,
|
|
141
|
+
def self.serialize(buffer, value, _validating_keys = nil)
|
|
152
142
|
if value.is_a?(BSON::Int64)
|
|
153
|
-
if value.respond_to?(:value)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
143
|
+
value = if value.respond_to?(:value)
|
|
144
|
+
# bson-ruby >= 4.6.0
|
|
145
|
+
value.value
|
|
146
|
+
else
|
|
147
|
+
value.instance_variable_get(:@integer)
|
|
148
|
+
end
|
|
159
149
|
end
|
|
160
150
|
buffer.put_int64(value)
|
|
161
151
|
end
|
|
@@ -166,7 +156,7 @@ module Mongo
|
|
|
166
156
|
# @param [ Hash ] options This method currently accepts no options.
|
|
167
157
|
#
|
|
168
158
|
# @return [Fixnum] Deserialized Int64.
|
|
169
|
-
def self.deserialize(buffer,
|
|
159
|
+
def self.deserialize(buffer, _options = {})
|
|
170
160
|
buffer.get_int64
|
|
171
161
|
end
|
|
172
162
|
end
|
|
@@ -177,7 +167,6 @@ module Mongo
|
|
|
177
167
|
#
|
|
178
168
|
# @since 2.5.0
|
|
179
169
|
module Sections
|
|
180
|
-
|
|
181
170
|
# Serializes the sections of an OP_MSG, payload type 0 or 1.
|
|
182
171
|
#
|
|
183
172
|
# @param [ BSON::ByteBuffer ] buffer Buffer to receive the serialized Sections.
|
|
@@ -189,7 +178,7 @@ module Mongo
|
|
|
189
178
|
# @return [ BSON::ByteBuffer ] Buffer with serialized value.
|
|
190
179
|
#
|
|
191
180
|
# @since 2.5.0
|
|
192
|
-
def self.serialize(buffer, value, max_bson_size = nil,
|
|
181
|
+
def self.serialize(buffer, value, max_bson_size = nil, _validating_keys = nil)
|
|
193
182
|
value.each do |section|
|
|
194
183
|
case section[:type]
|
|
195
184
|
when PayloadZero::TYPE
|
|
@@ -217,7 +206,7 @@ module Mongo
|
|
|
217
206
|
#
|
|
218
207
|
# @since 2.5.0
|
|
219
208
|
def self.deserialize(buffer, options = {})
|
|
220
|
-
end_length = (@flag_bits & Msg::FLAGS.index(:checksum_present)) == 1 ? 32 : 0
|
|
209
|
+
end_length = ((@flag_bits & Msg::FLAGS.index(:checksum_present)) == 1) ? 32 : 0
|
|
221
210
|
sections = []
|
|
222
211
|
until buffer.length == end_length
|
|
223
212
|
case byte = buffer.get_byte
|
|
@@ -245,7 +234,6 @@ module Mongo
|
|
|
245
234
|
#
|
|
246
235
|
# @since 2.5.0
|
|
247
236
|
module PayloadZero
|
|
248
|
-
|
|
249
237
|
# The byte identifier for this payload type.
|
|
250
238
|
#
|
|
251
239
|
# @since 2.5.0
|
|
@@ -267,7 +255,7 @@ module Mongo
|
|
|
267
255
|
# @return [ BSON::ByteBuffer ] Buffer with serialized value.
|
|
268
256
|
#
|
|
269
257
|
# @since 2.5.0
|
|
270
|
-
def self.serialize(buffer, value, max_bson_size = nil,
|
|
258
|
+
def self.serialize(buffer, value, max_bson_size = nil, _validating_keys = nil)
|
|
271
259
|
buffer.put_byte(TYPE_BYTE)
|
|
272
260
|
Serializers::Document.serialize(buffer, value, max_bson_size)
|
|
273
261
|
end
|
|
@@ -286,7 +274,7 @@ module Mongo
|
|
|
286
274
|
# @since 2.5.0
|
|
287
275
|
def self.deserialize(buffer, options = {})
|
|
288
276
|
mode = options[:deserialize_as_bson] ? :bson : nil
|
|
289
|
-
BSON::Document.from_bson(buffer,
|
|
277
|
+
BSON::Document.from_bson(buffer, mode: mode)
|
|
290
278
|
end
|
|
291
279
|
end
|
|
292
280
|
|
|
@@ -294,7 +282,6 @@ module Mongo
|
|
|
294
282
|
#
|
|
295
283
|
# @since 2.5.0
|
|
296
284
|
module PayloadOne
|
|
297
|
-
|
|
298
285
|
# The byte identifier for this payload type.
|
|
299
286
|
#
|
|
300
287
|
# @since 2.5.0
|
|
@@ -316,7 +303,7 @@ module Mongo
|
|
|
316
303
|
# @return [ BSON::ByteBuffer ] Buffer with serialized value.
|
|
317
304
|
#
|
|
318
305
|
# @since 2.5.0
|
|
319
|
-
def self.serialize(buffer, value, max_bson_size = nil,
|
|
306
|
+
def self.serialize(buffer, value, max_bson_size = nil, _validating_keys = nil)
|
|
320
307
|
buffer.put_byte(TYPE_BYTE)
|
|
321
308
|
start = buffer.length
|
|
322
309
|
buffer.put_int32(0) # hold for size
|
|
@@ -342,9 +329,7 @@ module Mongo
|
|
|
342
329
|
end_size = start_size - section_size
|
|
343
330
|
buffer.get_cstring # get the identifier
|
|
344
331
|
documents = []
|
|
345
|
-
until buffer.length == end_size
|
|
346
|
-
documents << BSON::Document.from_bson(buffer)
|
|
347
|
-
end
|
|
332
|
+
documents << BSON::Document.from_bson(buffer) until buffer.length == end_size
|
|
348
333
|
documents
|
|
349
334
|
end
|
|
350
335
|
end
|
|
@@ -354,21 +339,20 @@ module Mongo
|
|
|
354
339
|
#
|
|
355
340
|
# Serializes and de-serializes a single document.
|
|
356
341
|
module Document
|
|
357
|
-
|
|
358
342
|
# Serializes a document into the buffer
|
|
359
343
|
#
|
|
360
344
|
# @param buffer [ String ] Buffer to receive the BSON encoded document.
|
|
361
345
|
# @param value [ Hash ] Document to serialize as BSON.
|
|
362
346
|
#
|
|
363
347
|
# @return [ String ] Buffer with serialized value.
|
|
364
|
-
def self.serialize(buffer, value, max_bson_size = nil,
|
|
348
|
+
def self.serialize(buffer, value, max_bson_size = nil, _validating_keys = nil)
|
|
365
349
|
start_size = buffer.length
|
|
366
350
|
value.to_bson(buffer)
|
|
367
351
|
serialized_size = buffer.length - start_size
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
352
|
+
return unless max_bson_size && serialized_size > max_bson_size
|
|
353
|
+
|
|
354
|
+
raise Error::MaxBSONSize,
|
|
355
|
+
"The document exceeds maximum allowed BSON object size after serialization. Serialized size: #{serialized_size} bytes, maximum allowed size: #{max_bson_size} bytes"
|
|
372
356
|
end
|
|
373
357
|
|
|
374
358
|
# Deserializes a document from the IO stream
|
|
@@ -383,7 +367,7 @@ module Mongo
|
|
|
383
367
|
# @return [ Hash ] The decoded BSON document.
|
|
384
368
|
def self.deserialize(buffer, options = {})
|
|
385
369
|
mode = options[:deserialize_as_bson] ? :bson : nil
|
|
386
|
-
BSON::Document.from_bson(buffer,
|
|
370
|
+
BSON::Document.from_bson(buffer, mode: mode)
|
|
387
371
|
end
|
|
388
372
|
|
|
389
373
|
# Whether there can be a size limit on this type after serialization.
|
|
@@ -400,7 +384,6 @@ module Mongo
|
|
|
400
384
|
#
|
|
401
385
|
# Writes and fetches a single byte from the byte buffer.
|
|
402
386
|
module Byte
|
|
403
|
-
|
|
404
387
|
# Writes a byte into the buffer.
|
|
405
388
|
#
|
|
406
389
|
# @param [ BSON::ByteBuffer ] buffer Buffer to receive the single byte.
|
|
@@ -411,7 +394,7 @@ module Mongo
|
|
|
411
394
|
# @return [ BSON::ByteBuffer ] Buffer with serialized value.
|
|
412
395
|
#
|
|
413
396
|
# @since 2.5.0
|
|
414
|
-
def self.serialize(buffer, value,
|
|
397
|
+
def self.serialize(buffer, value, _validating_keys = nil)
|
|
415
398
|
buffer.put_byte(value)
|
|
416
399
|
end
|
|
417
400
|
|
|
@@ -423,7 +406,7 @@ module Mongo
|
|
|
423
406
|
# @return [ String ] The byte.
|
|
424
407
|
#
|
|
425
408
|
# @since 2.5.0
|
|
426
|
-
def self.deserialize(buffer,
|
|
409
|
+
def self.deserialize(buffer, _options = {})
|
|
427
410
|
buffer.get_byte
|
|
428
411
|
end
|
|
429
412
|
end
|
|
@@ -432,7 +415,6 @@ module Mongo
|
|
|
432
415
|
#
|
|
433
416
|
# Writes and fetches bytes from the byte buffer.
|
|
434
417
|
module Bytes
|
|
435
|
-
|
|
436
418
|
# Writes bytes into the buffer.
|
|
437
419
|
#
|
|
438
420
|
# @param [ BSON::ByteBuffer ] buffer Buffer to receive the bytes.
|
|
@@ -443,7 +425,7 @@ module Mongo
|
|
|
443
425
|
# @return [ BSON::ByteBuffer ] Buffer with serialized value.
|
|
444
426
|
#
|
|
445
427
|
# @since 2.5.0
|
|
446
|
-
def self.serialize(buffer, value,
|
|
428
|
+
def self.serialize(buffer, value, _validating_keys = nil)
|
|
447
429
|
buffer.put_bytes(value)
|
|
448
430
|
end
|
|
449
431
|
|
data/lib/mongo/protocol.rb
CHANGED
data/lib/mongo/query_cache.rb
CHANGED
|
@@ -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
|
#
|
|
@@ -18,7 +17,6 @@
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module QueryCache
|
|
20
19
|
class << self
|
|
21
|
-
|
|
22
20
|
# Set whether the cache is enabled.
|
|
23
21
|
#
|
|
24
22
|
# @example Set if the cache is enabled.
|
|
@@ -26,7 +24,7 @@ module Mongo
|
|
|
26
24
|
#
|
|
27
25
|
# @param [ true, false ] value The enabled value.
|
|
28
26
|
def enabled=(value)
|
|
29
|
-
Thread.current[
|
|
27
|
+
Thread.current['[mongo]:query_cache:enabled'] = value
|
|
30
28
|
end
|
|
31
29
|
|
|
32
30
|
# Is the query cache enabled on the current thread?
|
|
@@ -36,7 +34,7 @@ module Mongo
|
|
|
36
34
|
#
|
|
37
35
|
# @return [ true, false ] If the cache is enabled.
|
|
38
36
|
def enabled?
|
|
39
|
-
!!Thread.current[
|
|
37
|
+
!!Thread.current['[mongo]:query_cache:enabled']
|
|
40
38
|
end
|
|
41
39
|
|
|
42
40
|
# Execute the block while using the query cache.
|
|
@@ -78,7 +76,7 @@ module Mongo
|
|
|
78
76
|
#
|
|
79
77
|
# @return [ Hash ] The hash of cached queries.
|
|
80
78
|
private def cache_table
|
|
81
|
-
Thread.current[
|
|
79
|
+
Thread.current['[mongo]:query_cache'] ||= {}
|
|
82
80
|
end
|
|
83
81
|
|
|
84
82
|
# Clear the query cache.
|
|
@@ -88,7 +86,7 @@ module Mongo
|
|
|
88
86
|
#
|
|
89
87
|
# @return [ nil ] Always nil.
|
|
90
88
|
def clear
|
|
91
|
-
Thread.current[
|
|
89
|
+
Thread.current['[mongo]:query_cache'] = nil
|
|
92
90
|
end
|
|
93
91
|
|
|
94
92
|
# Clear the section of the query cache storing cursors with results
|
|
@@ -205,8 +203,6 @@ module Mongo
|
|
|
205
203
|
caching_cursor
|
|
206
204
|
elsif limit.nil? && caching_cursor_limit.nil?
|
|
207
205
|
caching_cursor
|
|
208
|
-
else
|
|
209
|
-
nil
|
|
210
206
|
end
|
|
211
207
|
end
|
|
212
208
|
|
|
@@ -214,6 +210,7 @@ module Mongo
|
|
|
214
210
|
return nil unless limit
|
|
215
211
|
# For the purposes of caching, a limit of 0 means no limit, as mongo treats it as such.
|
|
216
212
|
return nil if limit == 0
|
|
213
|
+
|
|
217
214
|
# For the purposes of caching, a negative limit is the same as as a positive limit.
|
|
218
215
|
limit.abs
|
|
219
216
|
end
|
|
@@ -221,12 +218,8 @@ module Mongo
|
|
|
221
218
|
private
|
|
222
219
|
|
|
223
220
|
def cache_key(**opts)
|
|
224
|
-
unless opts[:namespace]
|
|
225
|
-
|
|
226
|
-
end
|
|
227
|
-
unless opts[:selector]
|
|
228
|
-
raise ArgumentError.new("Cannot generate cache key without selector")
|
|
229
|
-
end
|
|
221
|
+
raise ArgumentError.new('Cannot generate cache key without namespace') unless opts[:namespace]
|
|
222
|
+
raise ArgumentError.new('Cannot generate cache key without selector') unless opts[:selector]
|
|
230
223
|
|
|
231
224
|
[
|
|
232
225
|
opts[:namespace],
|
|
@@ -254,7 +247,6 @@ module Mongo
|
|
|
254
247
|
|
|
255
248
|
# Rack middleware that activates the query cache for each request.
|
|
256
249
|
class Middleware
|
|
257
|
-
|
|
258
250
|
# Instantiate the middleware.
|
|
259
251
|
#
|
|
260
252
|
# @example Create the new middleware.
|