mongo 2.20.0 → 2.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -1
- data/Rakefile +59 -23
- data/lib/mongo/address.rb +22 -3
- data/lib/mongo/auth/aws/credentials_retriever.rb +70 -17
- data/lib/mongo/auth/base.rb +1 -1
- data/lib/mongo/bulk_write.rb +35 -2
- data/lib/mongo/client.rb +38 -6
- data/lib/mongo/client_encryption.rb +6 -3
- data/lib/mongo/cluster/reapers/cursor_reaper.rb +6 -1
- data/lib/mongo/cluster/sdam_flow.rb +20 -7
- data/lib/mongo/cluster.rb +14 -4
- data/lib/mongo/collection/helpers.rb +1 -1
- data/lib/mongo/collection/view/aggregation/behavior.rb +131 -0
- data/lib/mongo/collection/view/aggregation.rb +33 -99
- data/lib/mongo/collection/view/builder/aggregation.rb +1 -7
- data/lib/mongo/collection/view/change_stream.rb +80 -27
- data/lib/mongo/collection/view/iterable.rb +76 -60
- data/lib/mongo/collection/view/map_reduce.rb +25 -8
- data/lib/mongo/collection/view/readable.rb +79 -30
- data/lib/mongo/collection/view/writable.rb +109 -48
- data/lib/mongo/collection/view.rb +43 -3
- data/lib/mongo/collection.rb +158 -23
- data/lib/mongo/config.rb +2 -2
- data/lib/mongo/crypt/auto_encrypter.rb +4 -6
- data/lib/mongo/crypt/binding.rb +4 -4
- data/lib/mongo/crypt/context.rb +20 -14
- data/lib/mongo/crypt/encryption_io.rb +56 -26
- data/lib/mongo/crypt/explicit_encrypter.rb +49 -20
- data/lib/mongo/crypt/explicit_encryption_context.rb +17 -11
- data/lib/mongo/crypt/kms/azure/credentials_retriever.rb +22 -6
- data/lib/mongo/crypt/kms/gcp/credentials_retriever.rb +29 -4
- data/lib/mongo/csot_timeout_holder.rb +119 -0
- data/lib/mongo/cursor/kill_spec.rb +5 -2
- data/lib/mongo/cursor/nontailable.rb +27 -0
- data/lib/mongo/cursor.rb +86 -24
- data/lib/mongo/cursor_host.rb +82 -0
- data/lib/mongo/database/view.rb +81 -14
- data/lib/mongo/database.rb +88 -18
- data/lib/mongo/error/operation_failure.rb +209 -204
- data/lib/mongo/error/server_timeout_error.rb +12 -0
- data/lib/mongo/error/socket_timeout_error.rb +3 -1
- data/lib/mongo/error/timeout_error.rb +23 -0
- data/lib/mongo/error.rb +2 -0
- data/lib/mongo/grid/fs_bucket.rb +45 -12
- data/lib/mongo/grid/stream/read.rb +15 -1
- data/lib/mongo/grid/stream/write.rb +21 -4
- data/lib/mongo/index/view.rb +77 -16
- data/lib/mongo/operation/context.rb +40 -2
- data/lib/mongo/operation/create_search_indexes/op_msg.rb +2 -2
- data/lib/mongo/operation/delete/op_msg.rb +2 -1
- data/lib/mongo/operation/drop_search_index/op_msg.rb +2 -2
- data/lib/mongo/operation/find/op_msg.rb +45 -0
- data/lib/mongo/operation/get_more/op_msg.rb +33 -0
- data/lib/mongo/operation/insert/op_msg.rb +3 -2
- data/lib/mongo/operation/insert/result.rb +4 -2
- data/lib/mongo/operation/list_collections/result.rb +1 -1
- data/lib/mongo/operation/map_reduce/result.rb +1 -1
- data/lib/mongo/operation/op_msg_base.rb +3 -1
- data/lib/mongo/operation/result.rb +26 -5
- data/lib/mongo/operation/shared/executable.rb +12 -1
- data/lib/mongo/operation/shared/op_msg_executable.rb +4 -1
- data/lib/mongo/operation/shared/response_handling.rb +3 -3
- data/lib/mongo/operation/shared/sessions_supported.rb +1 -1
- data/lib/mongo/operation/shared/timed.rb +52 -0
- data/lib/mongo/operation/shared/write.rb +4 -1
- data/lib/mongo/operation/update/op_msg.rb +2 -1
- data/lib/mongo/operation/update_search_index/op_msg.rb +2 -2
- data/lib/mongo/operation.rb +1 -0
- data/lib/mongo/protocol/message.rb +1 -4
- data/lib/mongo/protocol/msg.rb +2 -2
- data/lib/mongo/retryable/base_worker.rb +28 -3
- data/lib/mongo/retryable/read_worker.rb +76 -35
- data/lib/mongo/retryable/write_worker.rb +53 -22
- data/lib/mongo/retryable.rb +8 -2
- data/lib/mongo/server/connection.rb +11 -5
- data/lib/mongo/server/connection_base.rb +22 -2
- data/lib/mongo/server/connection_pool.rb +32 -14
- data/lib/mongo/server/description/features.rb +1 -1
- data/lib/mongo/server/description.rb +18 -5
- data/lib/mongo/server/monitor.rb +7 -4
- data/lib/mongo/server/pending_connection.rb +25 -8
- data/lib/mongo/server/{round_trip_time_averager.rb → round_trip_time_calculator.rb} +25 -7
- data/lib/mongo/server.rb +11 -6
- data/lib/mongo/server_selector/base.rb +25 -9
- data/lib/mongo/session.rb +78 -9
- data/lib/mongo/socket/ssl.rb +131 -18
- data/lib/mongo/socket/tcp.rb +40 -6
- data/lib/mongo/socket.rb +154 -25
- data/lib/mongo/uri/options_mapper.rb +1 -0
- data/lib/mongo/version.rb +1 -5
- data/lib/mongo.rb +1 -0
- data/mongo.gemspec +8 -11
- data/spec/atlas/atlas_connectivity_spec.rb +4 -0
- data/spec/atlas/operations_spec.rb +4 -0
- data/spec/integration/client_side_encryption/auto_encryption_mongocryptd_spawn_spec.rb +2 -1
- data/spec/integration/client_side_encryption/auto_encryption_spec.rb +494 -487
- data/spec/integration/client_side_encryption/on_demand_aws_credentials_spec.rb +1 -1
- data/spec/integration/client_side_encryption/range_explicit_encryption_prose_spec.rb +67 -20
- data/spec/integration/client_side_operations_timeout/encryption_prose_spec.rb +131 -0
- data/spec/integration/connection_pool_populator_spec.rb +2 -0
- data/spec/integration/cursor_pinning_spec.rb +15 -60
- data/spec/integration/cursor_reaping_spec.rb +1 -1
- data/spec/integration/docs_examples_spec.rb +1 -1
- data/spec/integration/operation_failure_code_spec.rb +1 -1
- data/spec/integration/operation_failure_message_spec.rb +3 -3
- data/spec/integration/retryable_errors_spec.rb +2 -2
- data/spec/integration/retryable_reads_errors_spec.rb +35 -23
- data/spec/integration/sdam_error_handling_spec.rb +4 -1
- data/spec/integration/search_indexes_prose_spec.rb +4 -0
- data/spec/integration/server_spec.rb +4 -3
- data/spec/integration/transactions_api_examples_spec.rb +2 -0
- data/spec/kerberos/kerberos_spec.rb +4 -0
- data/spec/lite_spec_helper.rb +3 -11
- data/spec/mongo/auth/user/view_spec.rb +1 -1
- data/spec/mongo/caching_cursor_spec.rb +1 -1
- data/spec/mongo/client_encryption_spec.rb +1 -0
- data/spec/mongo/client_spec.rb +158 -4
- data/spec/mongo/collection/view/aggregation_spec.rb +14 -39
- data/spec/mongo/collection/view/change_stream_spec.rb +3 -3
- data/spec/mongo/collection_crud_spec.rb +1 -0
- data/spec/mongo/collection_spec.rb +5 -6
- data/spec/mongo/crypt/auto_encrypter_spec.rb +14 -12
- data/spec/mongo/crypt/data_key_context_spec.rb +3 -1
- data/spec/mongo/crypt/explicit_encryption_context_spec.rb +2 -2
- data/spec/mongo/crypt/handle_spec.rb +1 -1
- data/spec/mongo/cursor_spec.rb +26 -9
- data/spec/mongo/error/operation_failure_heavy_spec.rb +2 -2
- data/spec/mongo/operation/context_spec.rb +79 -0
- data/spec/mongo/operation/create/op_msg_spec.rb +106 -110
- data/spec/mongo/operation/delete/op_msg_spec.rb +6 -5
- data/spec/mongo/operation/find/op_msg_spec.rb +66 -0
- data/spec/mongo/operation/get_more/op_msg_spec.rb +65 -0
- data/spec/mongo/operation/insert/op_msg_spec.rb +128 -131
- data/spec/mongo/operation/shared/csot/examples.rb +113 -0
- data/spec/mongo/query_cache_spec.rb +243 -225
- data/spec/mongo/retryable_spec.rb +1 -0
- data/spec/mongo/server/connection_spec.rb +22 -0
- data/spec/mongo/server/round_trip_time_calculator_spec.rb +120 -0
- data/spec/mongo/socket/ssl_spec.rb +0 -10
- data/spec/runners/change_streams/test.rb +2 -2
- data/spec/runners/crud/operation.rb +1 -1
- data/spec/runners/crud/verifier.rb +3 -1
- data/spec/runners/transactions/operation.rb +4 -6
- data/spec/runners/unified/ambiguous_operations.rb +13 -0
- data/spec/runners/unified/assertions.rb +4 -0
- data/spec/runners/unified/change_stream_operations.rb +14 -24
- data/spec/runners/unified/crud_operations.rb +82 -59
- data/spec/runners/unified/ddl_operations.rb +38 -7
- data/spec/runners/unified/grid_fs_operations.rb +37 -2
- data/spec/runners/unified/support_operations.rb +43 -4
- data/spec/runners/unified/test.rb +22 -10
- data/spec/runners/unified.rb +1 -1
- data/spec/solo/clean_exit_spec.rb +2 -0
- data/spec/spec_tests/client_side_operations_timeout_spec.rb +15 -0
- data/spec/spec_tests/data/change_streams_unified/change-streams-clusterTime.yml +3 -1
- data/spec/spec_tests/data/change_streams_unified/change-streams-disambiguatedPaths.yml +3 -1
- data/spec/spec_tests/data/change_streams_unified/change-streams-errors.yml +3 -1
- data/spec/spec_tests/data/change_streams_unified/change-streams-pre_and_post_images.yml +1 -1
- data/spec/spec_tests/data/change_streams_unified/change-streams-resume-allowlist.yml +1 -1
- data/spec/spec_tests/data/change_streams_unified/change-streams-resume-errorLabels.yml +1 -1
- data/spec/spec_tests/data/change_streams_unified/change-streams-showExpandedEvents.yml +1 -1
- data/spec/spec_tests/data/client_side_encryption/badQueries.yml +2 -1
- data/spec/spec_tests/data/client_side_encryption/fle2v2-BypassQueryAnalysis.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Compact.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-CreateCollection.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-DecryptExistingData.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Delete.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-EncryptedFields-vs-EncryptedFieldsMap.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-EncryptedFields-vs-jsonSchema.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-EncryptedFieldsMap-defaults.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-FindOneAndUpdate.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-InsertFind-Indexed.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-InsertFind-Unindexed.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-MissingKey.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-NoEncryption.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Update.yml +1 -0
- data/spec/spec_tests/data/client_side_encryption/fle2v2-validatorAndPartialFieldExpression.yml +2 -1
- data/spec/spec_tests/data/client_side_encryption/timeoutMS.yml +67 -0
- data/spec/spec_tests/data/client_side_operations_timeout/bulkWrite.yml +87 -0
- data/spec/spec_tests/data/client_side_operations_timeout/change-streams.yml +358 -0
- data/spec/spec_tests/data/client_side_operations_timeout/close-cursors.yml +129 -0
- data/spec/spec_tests/data/client_side_operations_timeout/command-execution.yml +250 -0
- data/spec/spec_tests/data/client_side_operations_timeout/convenient-transactions.yml +113 -0
- data/spec/spec_tests/data/client_side_operations_timeout/cursors.yml +70 -0
- data/spec/spec_tests/data/client_side_operations_timeout/deprecated-options.yml +3982 -0
- data/spec/spec_tests/data/client_side_operations_timeout/error-transformations.yml +96 -0
- data/spec/spec_tests/data/client_side_operations_timeout/global-timeoutMS.yml +3236 -0
- data/spec/spec_tests/data/client_side_operations_timeout/gridfs-advanced.yml +207 -0
- data/spec/spec_tests/data/client_side_operations_timeout/gridfs-delete.yml +152 -0
- data/spec/spec_tests/data/client_side_operations_timeout/gridfs-download.yml +182 -0
- data/spec/spec_tests/data/client_side_operations_timeout/gridfs-find.yml +100 -0
- data/spec/spec_tests/data/client_side_operations_timeout/gridfs-upload.yml +249 -0
- data/spec/spec_tests/data/client_side_operations_timeout/legacy-timeouts.yml +204 -0
- data/spec/spec_tests/data/client_side_operations_timeout/non-tailable-cursors.yml +307 -0
- data/spec/spec_tests/data/client_side_operations_timeout/override-collection-timeoutMS.yml +1877 -0
- data/spec/spec_tests/data/client_side_operations_timeout/override-operation-timeoutMS.yml +1918 -0
- data/spec/spec_tests/data/client_side_operations_timeout/retryability-legacy-timeouts.yml +1676 -0
- data/spec/spec_tests/data/client_side_operations_timeout/retryability-timeoutMS.yml +2824 -0
- data/spec/spec_tests/data/client_side_operations_timeout/sessions-inherit-timeoutMS.yml +168 -0
- data/spec/spec_tests/data/client_side_operations_timeout/sessions-override-operation-timeoutMS.yml +171 -0
- data/spec/spec_tests/data/client_side_operations_timeout/sessions-override-timeoutMS.yml +168 -0
- data/spec/spec_tests/data/client_side_operations_timeout/tailable-awaitData.yml +247 -0
- data/spec/spec_tests/data/client_side_operations_timeout/tailable-non-awaitData.yml +181 -0
- data/spec/spec_tests/data/crud_unified/aggregate-write-readPreference.yml +6 -0
- data/spec/spec_tests/data/crud_unified/db-aggregate-write-readPreference.yml +6 -0
- data/spec/spec_tests/data/crud_unified/find-test-all-options.yml +29 -0
- data/spec/spec_tests/server_selection_rtt_spec.rb +6 -6
- data/spec/spec_tests/transactions_unified_spec.rb +2 -1
- data/spec/support/certificates/atlas-ocsp-ca.crt +89 -79
- data/spec/support/certificates/atlas-ocsp.crt +117 -122
- data/spec/support/certificates/retrieve-atlas-cert +1 -1
- data/spec/support/cluster_tools.rb +3 -3
- data/spec/support/common_shortcuts.rb +2 -2
- data/spec/support/crypt/encrypted_fields/range-encryptedFields-Date.json +1 -1
- data/spec/support/crypt/encrypted_fields/range-encryptedFields-DecimalNoPrecision.json +1 -1
- data/spec/support/crypt/encrypted_fields/range-encryptedFields-DecimalPrecision.json +1 -1
- data/spec/support/crypt/encrypted_fields/range-encryptedFields-DoubleNoPrecision.json +1 -1
- data/spec/support/crypt/encrypted_fields/range-encryptedFields-DoublePrecision.json +1 -1
- data/spec/support/crypt/encrypted_fields/range-encryptedFields-Int.json +1 -1
- data/spec/support/crypt/encrypted_fields/range-encryptedFields-Long.json +1 -1
- data/spec/support/shared/session.rb +2 -2
- data/spec/support/spec_setup.rb +2 -2
- data/spec/support/utils.rb +3 -1
- metadata +88 -173
- checksums.yaml.gz.sig +0 -0
- data/spec/mongo/server/round_trip_time_averager_spec.rb +0 -48
- data/spec/shared/LICENSE +0 -20
- data/spec/shared/bin/get-mongodb-download-url +0 -17
- data/spec/shared/bin/s3-copy +0 -45
- data/spec/shared/bin/s3-upload +0 -69
- data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
- data/spec/shared/lib/mrss/cluster_config.rb +0 -231
- data/spec/shared/lib/mrss/constraints.rb +0 -378
- data/spec/shared/lib/mrss/docker_runner.rb +0 -298
- data/spec/shared/lib/mrss/eg_config_utils.rb +0 -51
- data/spec/shared/lib/mrss/event_subscriber.rb +0 -210
- data/spec/shared/lib/mrss/lite_constraints.rb +0 -238
- data/spec/shared/lib/mrss/server_version_registry.rb +0 -113
- data/spec/shared/lib/mrss/session_registry.rb +0 -69
- data/spec/shared/lib/mrss/session_registry_legacy.rb +0 -60
- data/spec/shared/lib/mrss/spec_organizer.rb +0 -179
- data/spec/shared/lib/mrss/utils.rb +0 -37
- data/spec/shared/share/Dockerfile.erb +0 -281
- data/spec/shared/share/haproxy-1.conf +0 -16
- data/spec/shared/share/haproxy-2.conf +0 -17
- data/spec/shared/shlib/config.sh +0 -27
- data/spec/shared/shlib/distro.sh +0 -74
- data/spec/shared/shlib/server.sh +0 -417
- data/spec/shared/shlib/set_env.sh +0 -146
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-Aggregate.yml +0 -241
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-Correctness.yml +0 -422
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-Delete.yml +0 -182
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-FindOneAndUpdate.yml +0 -239
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-InsertFind.yml +0 -235
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-Update.yml +0 -252
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Decimal-Aggregate.yml +0 -1687
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Decimal-Correctness.yml +0 -293
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Decimal-Delete.yml +0 -905
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Decimal-FindOneAndUpdate.yml +0 -1684
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Decimal-InsertFind.yml +0 -1680
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Decimal-Update.yml +0 -1697
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DecimalPrecision-Aggregate.yml +0 -329
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DecimalPrecision-Correctness.yml +0 -424
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DecimalPrecision-Delete.yml +0 -226
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DecimalPrecision-FindOneAndUpdate.yml +0 -327
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DecimalPrecision-InsertFind.yml +0 -319
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DecimalPrecision-Update.yml +0 -336
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Double-Aggregate.yml +0 -913
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Double-Correctness.yml +0 -292
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Double-Delete.yml +0 -518
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Double-FindOneAndUpdate.yml +0 -911
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Double-InsertFind.yml +0 -907
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Double-Update.yml +0 -924
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DoublePrecision-Aggregate.yml +0 -325
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DoublePrecision-Correctness.yml +0 -424
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DoublePrecision-Delete.yml +0 -224
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DoublePrecision-FindOneAndUpdate.yml +0 -323
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DoublePrecision-InsertFind.yml +0 -319
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-DoublePrecision-Update.yml +0 -338
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Int-Aggregate.yml +0 -241
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Int-Correctness.yml +0 -423
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Int-Delete.yml +0 -182
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Int-FindOneAndUpdate.yml +0 -239
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Int-InsertFind.yml +0 -235
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Int-Update.yml +0 -254
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Long-Aggregate.yml +0 -241
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Long-Correctness.yml +0 -422
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Long-Delete.yml +0 -182
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Long-FindOneAndUpdate.yml +0 -239
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Long-InsertFind.yml +0 -235
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-Long-Update.yml +0 -254
- data/spec/spec_tests/data/client_side_encryption/fle2v2-Range-WrongType.yml +0 -43
- data/spec/support/faas/app/aws_lambda/mongodb/Gemfile.lock +0 -19
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -3
data/lib/mongo/collection.rb
CHANGED
@@ -134,8 +134,12 @@ module Mongo
|
|
134
134
|
# and *:nearest*.
|
135
135
|
# - *:tag_sets* -- an array of hashes.
|
136
136
|
# - *:local_threshold*.
|
137
|
-
# @option
|
138
|
-
# @option
|
137
|
+
# @option options [ Session ] :session The session to use for the operation.
|
138
|
+
# @option options [ Integer ] :size The size of the capped collection.
|
139
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
140
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
141
|
+
# The default value is unset which means the value is inherited from
|
142
|
+
# the database or the client.
|
139
143
|
# @option opts [ Hash ] :time_series Create a time-series collection.
|
140
144
|
# The hash may have the following items:
|
141
145
|
# - *:timeField* -- The name of the field which contains the date in each
|
@@ -163,6 +167,7 @@ module Mongo
|
|
163
167
|
@database = database
|
164
168
|
@name = name.to_s.freeze
|
165
169
|
@options = options.dup
|
170
|
+
@timeout_ms = options.delete(:timeout_ms)
|
166
171
|
=begin WriteConcern object support
|
167
172
|
if @options[:write_concern].is_a?(WriteConcern::Base)
|
168
173
|
# Cache the instance so that we do not needlessly reconstruct it.
|
@@ -401,7 +406,10 @@ module Mongo
|
|
401
406
|
self.write_concern
|
402
407
|
end
|
403
408
|
|
404
|
-
context = Operation::Context.new(
|
409
|
+
context = Operation::Context.new(
|
410
|
+
client: client,
|
411
|
+
session: session
|
412
|
+
)
|
405
413
|
maybe_create_qe_collections(opts[:encrypted_fields], client, session) do |encrypted_fields|
|
406
414
|
Operation::Create.new(
|
407
415
|
selector: operation,
|
@@ -413,7 +421,10 @@ module Mongo
|
|
413
421
|
collation: options[:collation] || options['collation'],
|
414
422
|
encrypted_fields: encrypted_fields,
|
415
423
|
validator: options[:validator],
|
416
|
-
).execute(
|
424
|
+
).execute(
|
425
|
+
next_primary(nil, session),
|
426
|
+
context: context
|
427
|
+
)
|
417
428
|
end
|
418
429
|
end
|
419
430
|
end
|
@@ -432,12 +443,16 @@ module Mongo
|
|
432
443
|
# @option opts [ Hash ] :write_concern The write concern options.
|
433
444
|
# @option opts [ Hash | nil ] :encrypted_fields Encrypted fields hash that
|
434
445
|
# was provided to `create` collection helper.
|
446
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
447
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
448
|
+
# The default value is unset which means the value is inherited from
|
449
|
+
# the collection or the database or the client.
|
435
450
|
#
|
436
451
|
# @return [ Result ] The result of the command.
|
437
452
|
#
|
438
453
|
# @since 2.0.0
|
439
454
|
def drop(opts = {})
|
440
|
-
client.
|
455
|
+
client.with_session(opts) do |session|
|
441
456
|
maybe_drop_emm_collections(opts[:encrypted_fields], client, session) do
|
442
457
|
temp_write_concern = write_concern
|
443
458
|
write_concern = if opts[:write_concern]
|
@@ -445,7 +460,11 @@ module Mongo
|
|
445
460
|
else
|
446
461
|
temp_write_concern
|
447
462
|
end
|
448
|
-
context = Operation::Context.new(
|
463
|
+
context = Operation::Context.new(
|
464
|
+
client: client,
|
465
|
+
session: session,
|
466
|
+
operation_timeouts: operation_timeouts(opts)
|
467
|
+
)
|
449
468
|
operation = Operation::Drop.new({
|
450
469
|
selector: { :drop => name },
|
451
470
|
db_name: database.name,
|
@@ -481,8 +500,9 @@ module Mongo
|
|
481
500
|
# this command.
|
482
501
|
# @option options [ :tailable, :tailable_await ] :cursor_type The type of cursor to use.
|
483
502
|
# @option options [ Integer ] :limit The max number of docs to return from the query.
|
484
|
-
# @option options [ Integer ] :max_time_ms
|
485
|
-
#
|
503
|
+
# @option options [ Integer ] :max_time_ms The maximum amount of time to
|
504
|
+
# allow the query to run, in milliseconds. This option is deprecated, use
|
505
|
+
# :timeout_ms instead.
|
486
506
|
# @option options [ Hash ] :modifiers A document containing meta-operators modifying the
|
487
507
|
# output or behavior of a query.
|
488
508
|
# @option options [ true | false ] :no_cursor_timeout The server normally times out idle
|
@@ -496,6 +516,13 @@ module Mongo
|
|
496
516
|
# @option options [ Integer ] :skip The number of docs to skip before returning results.
|
497
517
|
# @option options [ Hash ] :sort The key and direction pairs by which the result set
|
498
518
|
# will be sorted.
|
519
|
+
# @option options [ :cursor_lifetime | :iteration ] :timeout_mode How to interpret
|
520
|
+
# :timeout_ms (whether it applies to the lifetime of the cursor, or per
|
521
|
+
# iteration).
|
522
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
523
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
524
|
+
# The default value is unset which means the value is inherited from
|
525
|
+
# the collection or the database or the client.
|
499
526
|
# @option options [ Hash ] :let Mapping of variables to use in the command.
|
500
527
|
# See the server documentation for details.
|
501
528
|
#
|
@@ -526,13 +553,14 @@ module Mongo
|
|
526
553
|
# @option options [ String ] :hint The index to use for the aggregation.
|
527
554
|
# @option options [ Hash ] :let Mapping of variables to use in the pipeline.
|
528
555
|
# See the server documentation for details.
|
529
|
-
# @option options [ Integer ] :max_time_ms The maximum amount of time
|
530
|
-
#
|
531
|
-
#
|
532
|
-
# will request that the server provide results using a cursor. Note that
|
533
|
-
# as of server version 3.6, aggregations always provide results using a
|
534
|
-
# cursor and this option is therefore not valid.
|
556
|
+
# @option options [ Integer ] :max_time_ms The maximum amount of time to
|
557
|
+
# allow the query to run, in milliseconds. This option is deprecated, use
|
558
|
+
# :timeout_ms instead.
|
535
559
|
# @option options [ Session ] :session The session to use.
|
560
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
561
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
562
|
+
# The default value is unset which means the value is inherited from
|
563
|
+
# the collection or the database or the client.
|
536
564
|
#
|
537
565
|
# @return [ View::Aggregation ] The aggregation object.
|
538
566
|
#
|
@@ -600,6 +628,13 @@ module Mongo
|
|
600
628
|
# events included with this flag set are: createIndexes, dropIndexes,
|
601
629
|
# modify, create, shardCollection, reshardCollection,
|
602
630
|
# refineCollectionShardKey.
|
631
|
+
# @option options [ :cursor_lifetime | :iteration ] :timeout_mode How to interpret
|
632
|
+
# :timeout_ms (whether it applies to the lifetime of the cursor, or per
|
633
|
+
# iteration).
|
634
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
635
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
636
|
+
# The default value is unset which means the value is inherited from
|
637
|
+
# the collection or the database or the client.
|
603
638
|
#
|
604
639
|
# @note A change stream only allows 'majority' read concern.
|
605
640
|
# @note This helper method is preferable to running a raw aggregation with
|
@@ -610,7 +645,7 @@ module Mongo
|
|
610
645
|
# @since 2.5.0
|
611
646
|
def watch(pipeline = [], options = {})
|
612
647
|
view_options = options.dup
|
613
|
-
view_options[:
|
648
|
+
view_options[:cursor_type] = :tailable_await if options[:max_await_time_ms]
|
614
649
|
View::ChangeStream.new(View.new(self, {}, view_options), pipeline, nil, options)
|
615
650
|
end
|
616
651
|
|
@@ -624,13 +659,19 @@ module Mongo
|
|
624
659
|
#
|
625
660
|
# @option options [ Hash ] :hint The index to use.
|
626
661
|
# @option options [ Integer ] :limit The maximum number of documents to count.
|
627
|
-
# @option options [ Integer ] :max_time_ms The maximum amount of time to
|
662
|
+
# @option options [ Integer ] :max_time_ms The maximum amount of time to
|
663
|
+
# allow the query to run, in milliseconds. This option is deprecated, use
|
664
|
+
# :timeout_ms instead.
|
628
665
|
# @option options [ Integer ] :skip The number of documents to skip before counting.
|
629
666
|
# @option options [ Hash ] :read The read preference options.
|
630
667
|
# @option options [ Hash ] :collation The collation to use.
|
631
668
|
# @option options [ Session ] :session The session to use.
|
632
669
|
# @option options [ Object ] :comment A user-provided
|
633
670
|
# comment to attach to this command.
|
671
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
672
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
673
|
+
# The default value is unset which means the value is inherited from
|
674
|
+
# the collection or the database or the client.
|
634
675
|
#
|
635
676
|
# @return [ Integer ] The document count.
|
636
677
|
#
|
@@ -667,6 +708,10 @@ module Mongo
|
|
667
708
|
# @option options [ Session ] :session The session to use.
|
668
709
|
# @option options [ Object ] :comment A user-provided
|
669
710
|
# comment to attach to this command.
|
711
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
712
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
713
|
+
# The default value is unset which means the value is inherited from
|
714
|
+
# the collection or the database or the client.
|
670
715
|
#
|
671
716
|
# @return [ Integer ] The document count.
|
672
717
|
#
|
@@ -688,6 +733,10 @@ module Mongo
|
|
688
733
|
# @option options [ Hash ] :read The read preference options.
|
689
734
|
# @option options [ Object ] :comment A user-provided
|
690
735
|
# comment to attach to this command.
|
736
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
737
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
738
|
+
# The default value is unset which means the value is inherited from
|
739
|
+
# the collection or the database or the client.
|
691
740
|
#
|
692
741
|
# @return [ Integer ] The document count.
|
693
742
|
#
|
@@ -705,10 +754,16 @@ module Mongo
|
|
705
754
|
# @param [ Hash ] filter The documents from which to retrieve the distinct values.
|
706
755
|
# @param [ Hash ] options The distinct command options.
|
707
756
|
#
|
708
|
-
# @option options [ Integer ] :max_time_ms The maximum amount of time to
|
757
|
+
# @option options [ Integer ] :max_time_ms The maximum amount of time to
|
758
|
+
# allow the query to run, in milliseconds. This option is deprecated, use
|
759
|
+
# :timeout_ms instead.
|
709
760
|
# @option options [ Hash ] :read The read preference options.
|
710
761
|
# @option options [ Hash ] :collation The collation to use.
|
711
762
|
# @option options [ Session ] :session The session to use.
|
763
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
764
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
765
|
+
# The default value is unset which means the value is inherited from
|
766
|
+
# the collection or the database or the client.
|
712
767
|
#
|
713
768
|
# @return [ Array<Object> ] The list of distinct values.
|
714
769
|
#
|
@@ -781,6 +836,10 @@ module Mongo
|
|
781
836
|
# @option opts [ Object ] :comment A user-provided comment to attach to
|
782
837
|
# this command.
|
783
838
|
# @option opts [ Session ] :session The session to use for the operation.
|
839
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
840
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
841
|
+
# The default value is unset which means the value is inherited from
|
842
|
+
# the collection or the database or the client.
|
784
843
|
# @option opts [ Hash ] :write_concern The write concern options.
|
785
844
|
# Can be :w => Integer, :fsync => Boolean, :j => Boolean.
|
786
845
|
#
|
@@ -801,7 +860,11 @@ module Mongo
|
|
801
860
|
raise ArgumentError, "Document to be inserted cannot be nil"
|
802
861
|
end
|
803
862
|
|
804
|
-
context = Operation::Context.new(
|
863
|
+
context = Operation::Context.new(
|
864
|
+
client: client,
|
865
|
+
session: session,
|
866
|
+
operation_timeouts: operation_timeouts(opts)
|
867
|
+
)
|
805
868
|
write_with_retry(write_concern, context: context) do |connection, txn_num, context|
|
806
869
|
Operation::Insert.new(
|
807
870
|
:documents => [ document ],
|
@@ -834,6 +897,10 @@ module Mongo
|
|
834
897
|
# @option options [ true | false ] :ordered Whether the operations
|
835
898
|
# should be executed in order.
|
836
899
|
# @option options [ Session ] :session The session to use for the operation.
|
900
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
901
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
902
|
+
# The default value is unset which means the value is inherited from
|
903
|
+
# the collection or the database or the client.
|
837
904
|
# @option options [ Hash ] :write_concern The write concern options.
|
838
905
|
# Can be :w => Integer, :fsync => Boolean, :j => Boolean.
|
839
906
|
#
|
@@ -862,6 +929,10 @@ module Mongo
|
|
862
929
|
# @option options [ true | false ] :bypass_document_validation Whether or
|
863
930
|
# not to skip document level validation.
|
864
931
|
# @option options [ Session ] :session The session to use for the set of operations.
|
932
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
933
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
934
|
+
# The default value is unset which means the value is inherited from
|
935
|
+
# the collection or the database or the client.
|
865
936
|
# @option options [ Hash ] :let Mapping of variables to use in the command.
|
866
937
|
# See the server documentation for details.
|
867
938
|
#
|
@@ -884,6 +955,10 @@ module Mongo
|
|
884
955
|
# @option options [ Session ] :session The session to use.
|
885
956
|
# @option options [ Hash | String ] :hint The index to use for this operation.
|
886
957
|
# May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
|
958
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
959
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
960
|
+
# The default value is unset which means the value is inherited from
|
961
|
+
# the collection or the database or the client.
|
887
962
|
# @option options [ Hash ] :let Mapping of variables to use in the command.
|
888
963
|
# See the server documentation for details.
|
889
964
|
#
|
@@ -906,6 +981,10 @@ module Mongo
|
|
906
981
|
# @option options [ Session ] :session The session to use.
|
907
982
|
# @option options [ Hash | String ] :hint The index to use for this operation.
|
908
983
|
# May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
|
984
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
985
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
986
|
+
# The default value is unset which means the value is inherited from
|
987
|
+
# the collection or the database or the client.
|
909
988
|
# @option options [ Hash ] :let Mapping of variables to use in the command.
|
910
989
|
# See the server documentation for details.
|
911
990
|
#
|
@@ -928,15 +1007,23 @@ module Mongo
|
|
928
1007
|
# @param [ Integer ] cursor_count The max number of cursors to return.
|
929
1008
|
# @param [ Hash ] options The parallel scan command options.
|
930
1009
|
#
|
931
|
-
# @option options [ Integer ] :max_time_ms The maximum amount of time to
|
932
|
-
# to run in milliseconds.
|
1010
|
+
# @option options [ Integer ] :max_time_ms The maximum amount of time to
|
1011
|
+
# allow the query to run, in milliseconds. This option is deprecated, use
|
1012
|
+
# :timeout_ms instead.
|
933
1013
|
# @option options [ Session ] :session The session to use.
|
1014
|
+
# @option options [ :cursor_lifetime | :iteration ] :timeout_mode How to interpret
|
1015
|
+
# :timeout_ms (whether it applies to the lifetime of the cursor, or per
|
1016
|
+
# iteration).
|
1017
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
1018
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
1019
|
+
# The default value is unset which means the value is inherited from
|
1020
|
+
# the collection or the database or the client.
|
934
1021
|
#
|
935
1022
|
# @return [ Array<Cursor> ] An array of cursors.
|
936
1023
|
#
|
937
1024
|
# @since 2.1
|
938
1025
|
def parallel_scan(cursor_count, options = {})
|
939
|
-
find({}, options).
|
1026
|
+
find({}, options).parallel_scan(cursor_count, options)
|
940
1027
|
end
|
941
1028
|
|
942
1029
|
# Replaces a single document in the collection with the new document.
|
@@ -954,6 +1041,10 @@ module Mongo
|
|
954
1041
|
# not to skip document level validation.
|
955
1042
|
# @option options [ Hash ] :collation The collation to use.
|
956
1043
|
# @option options [ Session ] :session The session to use.
|
1044
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
1045
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
1046
|
+
# The default value is unset which means the value is inherited from
|
1047
|
+
# the collection or the database or the client.
|
957
1048
|
# @option options [ Hash | String ] :hint The index to use for this operation.
|
958
1049
|
# May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
|
959
1050
|
# @option options [ Hash ] :let Mapping of variables to use in the command.
|
@@ -983,6 +1074,10 @@ module Mongo
|
|
983
1074
|
# @option options [ Array ] :array_filters A set of filters specifying to which array elements
|
984
1075
|
# an update should apply.
|
985
1076
|
# @option options [ Session ] :session The session to use.
|
1077
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
1078
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
1079
|
+
# The default value is unset which means the value is inherited from
|
1080
|
+
# the collection or the database or the client.
|
986
1081
|
# @option options [ Hash | String ] :hint The index to use for this operation.
|
987
1082
|
# May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
|
988
1083
|
# @option options [ Hash ] :let Mapping of variables to use in the command.
|
@@ -1012,6 +1107,10 @@ module Mongo
|
|
1012
1107
|
# @option options [ Array ] :array_filters A set of filters specifying to which array elements
|
1013
1108
|
# an update should apply.
|
1014
1109
|
# @option options [ Session ] :session The session to use.
|
1110
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
1111
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
1112
|
+
# The default value is unset which means the value is inherited from
|
1113
|
+
# the collection or the database or the client.
|
1015
1114
|
# @option options [ Hash | String ] :hint The index to use for this operation.
|
1016
1115
|
# May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
|
1017
1116
|
# @option options [ Hash ] :let Mapping of variables to use in the command.
|
@@ -1033,8 +1132,9 @@ module Mongo
|
|
1033
1132
|
# @param [ Hash ] filter The filter to use.
|
1034
1133
|
# @param [ Hash ] options The options.
|
1035
1134
|
#
|
1036
|
-
# @option options [ Integer ] :max_time_ms The maximum amount of time to
|
1037
|
-
# to run in milliseconds.
|
1135
|
+
# @option options [ Integer ] :max_time_ms The maximum amount of time to
|
1136
|
+
# allow the query to run, in milliseconds. This option is deprecated, use
|
1137
|
+
# :timeout_ms instead.
|
1038
1138
|
# @option options [ Hash ] :projection The fields to include or exclude in the returned doc.
|
1039
1139
|
# @option options [ Hash ] :sort The key and direction pairs by which the result set
|
1040
1140
|
# will be sorted.
|
@@ -1042,6 +1142,10 @@ module Mongo
|
|
1042
1142
|
# Defaults to the collection's write concern.
|
1043
1143
|
# @option options [ Hash ] :collation The collation to use.
|
1044
1144
|
# @option options [ Session ] :session The session to use.
|
1145
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
1146
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
1147
|
+
# The default value is unset which means the value is inherited from
|
1148
|
+
# the collection or the database or the client.
|
1045
1149
|
# @option options [ Hash | String ] :hint The index to use for this operation.
|
1046
1150
|
# May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
|
1047
1151
|
# @option options [ Hash ] :let Mapping of variables to use in the command.
|
@@ -1086,6 +1190,10 @@ module Mongo
|
|
1086
1190
|
# May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
|
1087
1191
|
# @option options [ Hash ] :let Mapping of variables to use in the command.
|
1088
1192
|
# See the server documentation for details.
|
1193
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
1194
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
1195
|
+
# The default value is unset which means the value is inherited from
|
1196
|
+
# the collection or the database or the client.
|
1089
1197
|
#
|
1090
1198
|
# @return [ BSON::Document ] The document.
|
1091
1199
|
#
|
@@ -1122,6 +1230,10 @@ module Mongo
|
|
1122
1230
|
# @option options [ Session ] :session The session to use.
|
1123
1231
|
# @option options [ Hash | String ] :hint The index to use for this operation.
|
1124
1232
|
# May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
|
1233
|
+
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
1234
|
+
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
1235
|
+
# The default value is unset which means the value is inherited from
|
1236
|
+
# the collection or the database or the client.
|
1125
1237
|
# @option options [ Hash ] :let Mapping of variables to use in the command.
|
1126
1238
|
# See the server documentation for details.
|
1127
1239
|
#
|
@@ -1152,5 +1264,28 @@ module Mongo
|
|
1152
1264
|
def system_collection?
|
1153
1265
|
name.start_with?('system.')
|
1154
1266
|
end
|
1267
|
+
|
1268
|
+
# @return [ Integer | nil ] Operation timeout that is for this database or
|
1269
|
+
# for the corresponding client.
|
1270
|
+
#
|
1271
|
+
# @api private
|
1272
|
+
def timeout_ms
|
1273
|
+
@timeout_ms || database.timeout_ms
|
1274
|
+
end
|
1275
|
+
|
1276
|
+
# @return [ Hash ] timeout_ms value set on the operation level (if any),
|
1277
|
+
# and/or timeout_ms that is set on collection/database/client level (if any).
|
1278
|
+
#
|
1279
|
+
# @api private
|
1280
|
+
def operation_timeouts(opts = {})
|
1281
|
+
# TODO: We should re-evaluate if we need two timeouts separately.
|
1282
|
+
{}.tap do |result|
|
1283
|
+
if opts[:timeout_ms].nil?
|
1284
|
+
result[:inherited_timeout_ms] = timeout_ms
|
1285
|
+
else
|
1286
|
+
result[:operation_timeout_ms] = opts.delete(:timeout_ms)
|
1287
|
+
end
|
1288
|
+
end
|
1289
|
+
end
|
1155
1290
|
end
|
1156
1291
|
end
|
data/lib/mongo/config.rb
CHANGED
@@ -16,7 +16,7 @@ module Mongo
|
|
16
16
|
|
17
17
|
# When this flag is off, an aggregation done on a view will be executed over
|
18
18
|
# the documents included in that view, instead of all documents in the
|
19
|
-
# collection. When this flag is on, the view
|
19
|
+
# collection. When this flag is on, the view filter is ignored.
|
20
20
|
option :broken_view_aggregate, default: true
|
21
21
|
|
22
22
|
# When this flag is set to false, the view options will be correctly
|
@@ -24,7 +24,7 @@ module Mongo
|
|
24
24
|
option :broken_view_options, default: true
|
25
25
|
|
26
26
|
# When this flag is set to true, the update and replace methods will
|
27
|
-
# validate the
|
27
|
+
# validate the parameters and raise an error if they are invalid.
|
28
28
|
option :validate_update_replace, default: false
|
29
29
|
|
30
30
|
# Set the configuration options.
|
@@ -119,8 +119,6 @@ module Mongo
|
|
119
119
|
@options[:extra_options][:crypt_shared_lib_required]
|
120
120
|
|
121
121
|
unless @options[:extra_options][:crypt_shared_lib_required] || @crypt_handle.crypt_shared_lib_available? || @options[:bypass_query_analysis]
|
122
|
-
# Set server selection timeout to 1 to prevent the client waiting for a
|
123
|
-
# long timeout before spawning mongocryptd
|
124
122
|
@mongocryptd_client = Client.new(
|
125
123
|
@options[:extra_options][:mongocryptd_uri],
|
126
124
|
monitoring_io: @options[:client].options[:monitoring_io],
|
@@ -189,13 +187,13 @@ module Mongo
|
|
189
187
|
# @param [ Hash ] command The command to be encrypted.
|
190
188
|
#
|
191
189
|
# @return [ BSON::Document ] The encrypted command.
|
192
|
-
def encrypt(database_name, command)
|
190
|
+
def encrypt(database_name, command, timeout_holder)
|
193
191
|
AutoEncryptionContext.new(
|
194
192
|
@crypt_handle,
|
195
193
|
@encryption_io,
|
196
194
|
database_name,
|
197
195
|
command
|
198
|
-
).run_state_machine
|
196
|
+
).run_state_machine(timeout_holder)
|
199
197
|
end
|
200
198
|
|
201
199
|
# Decrypt a database command.
|
@@ -203,12 +201,12 @@ module Mongo
|
|
203
201
|
# @param [ Hash ] command The command with encrypted fields.
|
204
202
|
#
|
205
203
|
# @return [ BSON::Document ] The decrypted command.
|
206
|
-
def decrypt(command)
|
204
|
+
def decrypt(command, timeout_holder)
|
207
205
|
AutoDecryptionContext.new(
|
208
206
|
@crypt_handle,
|
209
207
|
@encryption_io,
|
210
208
|
command
|
211
|
-
).run_state_machine
|
209
|
+
).run_state_machine(timeout_holder)
|
212
210
|
end
|
213
211
|
|
214
212
|
# Close the resources created by the AutoEncrypter.
|
data/lib/mongo/crypt/binding.rb
CHANGED
@@ -1699,9 +1699,9 @@ module Mongo
|
|
1699
1699
|
# @!method self.mongocrypt_ctx_setopt_algorithm_range(ctx, opts)
|
1700
1700
|
# @api private
|
1701
1701
|
#
|
1702
|
-
# Set options for explicit encryption with the "
|
1702
|
+
# Set options for explicit encryption with the "range" algorithm.
|
1703
1703
|
#
|
1704
|
-
# @note The
|
1704
|
+
# @note The Range algorithm is experimental only. It is not intended for
|
1705
1705
|
# public use.
|
1706
1706
|
#
|
1707
1707
|
# @param [ FFI::Pointer ] ctx A pointer to a mongocrypt_ctx_t object.
|
@@ -1718,9 +1718,9 @@ module Mongo
|
|
1718
1718
|
:bool
|
1719
1719
|
)
|
1720
1720
|
|
1721
|
-
# Set options for explicit encryption with the "
|
1721
|
+
# Set options for explicit encryption with the "range" algorithm.
|
1722
1722
|
#
|
1723
|
-
# @note The
|
1723
|
+
# @note The Range algorithm is experimental only. It is not intended for
|
1724
1724
|
# public use.
|
1725
1725
|
#
|
1726
1726
|
# @param [ Mongo::Crypt::Context ] context
|
data/lib/mongo/crypt/context.rb
CHANGED
@@ -64,7 +64,10 @@ module Mongo
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# Runs the mongocrypt_ctx_t state machine and handles
|
67
|
-
# all I/O on behalf of
|
67
|
+
# all I/O on behalf of
|
68
|
+
#
|
69
|
+
# @param [ CsotTimeoutHolder ] timeout_holder CSOT timeouts for the
|
70
|
+
# operation the state.
|
68
71
|
#
|
69
72
|
# @return [ BSON::Document ] A BSON document representing the outcome
|
70
73
|
# of the state machine. Contents can differ depending on how the
|
@@ -75,8 +78,9 @@ module Mongo
|
|
75
78
|
#
|
76
79
|
# This method is not currently unit tested. It is integration tested
|
77
80
|
# in spec/integration/explicit_encryption_spec.rb
|
78
|
-
def run_state_machine
|
81
|
+
def run_state_machine(timeout_holder)
|
79
82
|
while true
|
83
|
+
timeout_ms = timeout_holder.remaining_timeout_ms!
|
80
84
|
case state
|
81
85
|
when :error
|
82
86
|
Binding.check_ctx_status(self)
|
@@ -88,7 +92,7 @@ module Mongo
|
|
88
92
|
when :need_mongo_keys
|
89
93
|
filter = Binding.ctx_mongo_op(self)
|
90
94
|
|
91
|
-
@encryption_io.find_keys(filter).each do |key|
|
95
|
+
@encryption_io.find_keys(filter, timeout_ms: timeout_ms).each do |key|
|
92
96
|
mongocrypt_feed(key) if key
|
93
97
|
end
|
94
98
|
|
@@ -96,14 +100,14 @@ module Mongo
|
|
96
100
|
when :need_mongo_collinfo
|
97
101
|
filter = Binding.ctx_mongo_op(self)
|
98
102
|
|
99
|
-
result = @encryption_io.collection_info(@db_name, filter)
|
103
|
+
result = @encryption_io.collection_info(@db_name, filter, timeout_ms: timeout_ms)
|
100
104
|
mongocrypt_feed(result) if result
|
101
105
|
|
102
106
|
mongocrypt_done
|
103
107
|
when :need_mongo_markings
|
104
108
|
cmd = Binding.ctx_mongo_op(self)
|
105
109
|
|
106
|
-
result = @encryption_io.mark_command(cmd)
|
110
|
+
result = @encryption_io.mark_command(cmd, timeout_ms: timeout_ms)
|
107
111
|
mongocrypt_feed(result)
|
108
112
|
|
109
113
|
mongocrypt_done
|
@@ -118,7 +122,7 @@ module Mongo
|
|
118
122
|
when :need_kms_credentials
|
119
123
|
Binding.ctx_provide_kms_providers(
|
120
124
|
self,
|
121
|
-
retrieve_kms_credentials.to_document
|
125
|
+
retrieve_kms_credentials(timeout_holder).to_document
|
122
126
|
)
|
123
127
|
else
|
124
128
|
raise Error::CryptError.new(
|
@@ -147,13 +151,15 @@ module Mongo
|
|
147
151
|
# Retrieves KMS credentials for providers that are configured
|
148
152
|
# for automatic credentials retrieval.
|
149
153
|
#
|
154
|
+
# @param [ CsotTimeoutHolder ] timeout_holder CSOT timeout.
|
155
|
+
#
|
150
156
|
# @return [ Crypt::KMS::Credentials ] Credentials for the configured
|
151
157
|
# KMS providers.
|
152
|
-
def retrieve_kms_credentials
|
158
|
+
def retrieve_kms_credentials(timeout_holder)
|
153
159
|
providers = {}
|
154
160
|
if kms_providers.aws&.empty?
|
155
161
|
begin
|
156
|
-
aws_credentials = Mongo::Auth::Aws::CredentialsRetriever.new.credentials
|
162
|
+
aws_credentials = Mongo::Auth::Aws::CredentialsRetriever.new.credentials(timeout_holder)
|
157
163
|
rescue Auth::Aws::CredentialsNotFound
|
158
164
|
raise Error::CryptError.new(
|
159
165
|
"Could not locate AWS credentials (checked environment variables, ECS and EC2 metadata)"
|
@@ -162,10 +168,10 @@ module Mongo
|
|
162
168
|
providers[:aws] = aws_credentials.to_h
|
163
169
|
end
|
164
170
|
if kms_providers.gcp&.empty?
|
165
|
-
providers[:gcp] = { access_token: gcp_access_token }
|
171
|
+
providers[:gcp] = { access_token: gcp_access_token(timeout_holder) }
|
166
172
|
end
|
167
173
|
if kms_providers.azure&.empty?
|
168
|
-
providers[:azure] = { access_token: azure_access_token }
|
174
|
+
providers[:azure] = { access_token: azure_access_token(timeout_holder) }
|
169
175
|
end
|
170
176
|
KMS::Credentials.new(providers)
|
171
177
|
end
|
@@ -175,8 +181,8 @@ module Mongo
|
|
175
181
|
# @return [ String ] A GCP access token.
|
176
182
|
#
|
177
183
|
# @raise [ Error::CryptError ] If the GCP access token could not be
|
178
|
-
def gcp_access_token
|
179
|
-
KMS::GCP::CredentialsRetriever.fetch_access_token
|
184
|
+
def gcp_access_token(timeout_holder)
|
185
|
+
KMS::GCP::CredentialsRetriever.fetch_access_token(timeout_holder)
|
180
186
|
rescue KMS::CredentialsNotFound => e
|
181
187
|
raise Error::CryptError.new(
|
182
188
|
"Could not locate GCP credentials: #{e.class}: #{e.message}"
|
@@ -189,9 +195,9 @@ module Mongo
|
|
189
195
|
#
|
190
196
|
# @raise [ Error::CryptError ] If the Azure access token could not be
|
191
197
|
# retrieved.
|
192
|
-
def azure_access_token
|
198
|
+
def azure_access_token(timeout_holder)
|
193
199
|
if @cached_azure_token.nil? || @cached_azure_token.expired?
|
194
|
-
@cached_azure_token = KMS::Azure::CredentialsRetriever.fetch_access_token
|
200
|
+
@cached_azure_token = KMS::Azure::CredentialsRetriever.fetch_access_token(timeout_holder: timeout_holder)
|
195
201
|
end
|
196
202
|
@cached_azure_token.access_token
|
197
203
|
rescue KMS::CredentialsNotFound => e
|