mongo 2.8.0 → 2.9.0.rc0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Rakefile +12 -0
- data/lib/mongo.rb +15 -1
- data/lib/mongo/address/ipv6.rb +0 -2
- data/lib/mongo/auth/scram/conversation.rb +0 -3
- data/lib/mongo/bulk_write/result_combiner.rb +12 -2
- data/lib/mongo/client.rb +59 -6
- data/lib/mongo/cluster.rb +19 -8
- data/lib/mongo/cluster/reapers/cursor_reaper.rb +0 -2
- data/lib/mongo/cluster/reapers/socket_reaper.rb +12 -9
- data/lib/mongo/collection.rb +1 -1
- data/lib/mongo/collection/view/aggregation.rb +5 -1
- data/lib/mongo/collection/view/builder/map_reduce.rb +1 -1
- data/lib/mongo/collection/view/change_stream.rb +30 -10
- data/lib/mongo/collection/view/iterable.rb +13 -6
- data/lib/mongo/collection/view/map_reduce.rb +12 -10
- data/lib/mongo/collection/view/readable.rb +19 -14
- data/lib/mongo/cursor.rb +12 -8
- data/lib/mongo/database.rb +10 -7
- data/lib/mongo/database/view.rb +18 -11
- data/lib/mongo/error.rb +2 -2
- data/lib/mongo/error/connection_check_out_timeout.rb +49 -0
- data/lib/mongo/error/operation_failure.rb +9 -9
- data/lib/mongo/error/parser.rb +25 -3
- data/lib/mongo/error/pool_closed_error.rb +43 -0
- data/lib/mongo/error/sdam_error_detection.rb +18 -0
- data/lib/mongo/grid/file/chunk.rb +0 -2
- data/lib/mongo/grid/fs_bucket.rb +26 -12
- data/lib/mongo/grid/stream/read.rb +36 -21
- data/lib/mongo/index/view.rb +11 -7
- data/lib/mongo/logger.rb +0 -2
- data/lib/mongo/monitoring.rb +31 -0
- data/lib/mongo/monitoring/cmap_log_subscriber.rb +53 -0
- data/lib/mongo/monitoring/event.rb +1 -0
- data/lib/mongo/monitoring/event/cmap.rb +25 -0
- data/lib/mongo/monitoring/event/cmap/base.rb +28 -0
- data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +78 -0
- data/lib/mongo/monitoring/event/cmap/connection_check_out_started.rb +56 -0
- data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +63 -0
- data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +64 -0
- data/lib/mongo/monitoring/event/cmap/connection_closed.rb +103 -0
- data/lib/mongo/monitoring/event/cmap/connection_created.rb +64 -0
- data/lib/mongo/monitoring/event/cmap/connection_ready.rb +64 -0
- data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +57 -0
- data/lib/mongo/monitoring/event/cmap/pool_closed.rb +57 -0
- data/lib/mongo/monitoring/event/cmap/pool_created.rb +63 -0
- data/lib/mongo/monitoring/event/command_started.rb +12 -3
- data/lib/mongo/monitoring/publishable.rb +10 -2
- data/lib/mongo/operation.rb +0 -1
- data/lib/mongo/operation/find/legacy/result.rb +1 -0
- data/lib/mongo/operation/list_collections/result.rb +7 -1
- data/lib/mongo/operation/result.rb +10 -1
- data/lib/mongo/operation/shared/executable.rb +15 -0
- data/lib/mongo/operation/shared/result/use_legacy_error_parser.rb +29 -0
- data/lib/mongo/operation/shared/specifiable.rb +0 -16
- data/lib/mongo/operation/update/legacy/result.rb +1 -0
- data/lib/mongo/protocol/compressed.rb +0 -2
- data/lib/mongo/protocol/msg.rb +25 -2
- data/lib/mongo/retryable.rb +171 -33
- data/lib/mongo/server.rb +26 -7
- data/lib/mongo/server/app_metadata.rb +0 -2
- data/lib/mongo/server/connectable.rb +8 -2
- data/lib/mongo/server/connection.rb +83 -13
- data/lib/mongo/server/connection_base.rb +1 -1
- data/lib/mongo/server/connection_pool.rb +439 -43
- data/lib/mongo/server/monitor/connection.rb +4 -1
- data/lib/mongo/session.rb +37 -5
- data/lib/mongo/session/session_pool.rb +2 -2
- data/lib/mongo/socket.rb +0 -2
- data/lib/mongo/socket/ssl.rb +0 -2
- data/lib/mongo/uri.rb +127 -66
- data/lib/mongo/uri/srv_protocol.rb +35 -13
- data/lib/mongo/version.rb +1 -1
- data/spec/README.md +190 -63
- data/spec/integration/change_stream_spec.rb +64 -0
- data/spec/integration/command_spec.rb +0 -7
- data/spec/integration/error_detection_spec.rb +39 -0
- data/spec/integration/read_concern.rb +83 -0
- data/spec/integration/retryable_writes_spec.rb +6 -50
- data/spec/integration/sdam_error_handling_spec.rb +60 -7
- data/spec/integration/ssl_uri_options_spec.rb +24 -0
- data/spec/integration/step_down_spec.rb +197 -0
- data/spec/lite_spec_helper.rb +4 -0
- data/spec/mongo/client_construction_spec.rb +42 -17
- data/spec/mongo/client_spec.rb +32 -1
- data/spec/mongo/cluster/socket_reaper_spec.rb +2 -2
- data/spec/mongo/cluster_spec.rb +36 -2
- data/spec/mongo/collection/view/aggregation_spec.rb +2 -0
- data/spec/mongo/collection/view/change_stream_spec.rb +28 -28
- data/spec/mongo/collection/view/readable_spec.rb +1 -1
- data/spec/mongo/collection/view_spec.rb +3 -1
- data/spec/mongo/cursor_spec.rb +5 -5
- data/spec/mongo/error/parser_spec.rb +61 -1
- data/spec/mongo/grid/stream/read_spec.rb +2 -2
- data/spec/mongo/monitoring/event/cmap/connection_check_out_failed_spec.rb +23 -0
- data/spec/mongo/monitoring/event/cmap/connection_check_out_started_spec.rb +19 -0
- data/spec/mongo/monitoring/event/cmap/connection_checked_in_spec.rb +23 -0
- data/spec/mongo/monitoring/event/cmap/connection_checked_out_spec.rb +23 -0
- data/spec/mongo/monitoring/event/cmap/connection_closed_spec.rb +27 -0
- data/spec/mongo/monitoring/event/cmap/connection_created_spec.rb +24 -0
- data/spec/mongo/monitoring/event/cmap/connection_ready_spec.rb +24 -0
- data/spec/mongo/monitoring/event/cmap/pool_cleared_spec.rb +19 -0
- data/spec/mongo/monitoring/event/cmap/pool_closed_spec.rb +19 -0
- data/spec/mongo/monitoring/event/cmap/pool_created_spec.rb +26 -0
- data/spec/mongo/operation/delete/bulk_spec.rb +1 -6
- data/spec/mongo/operation/delete/command_spec.rb +1 -1
- data/spec/mongo/operation/delete/op_msg_spec.rb +1 -1
- data/spec/mongo/operation/delete_spec.rb +4 -4
- data/spec/mongo/operation/insert/bulk_spec.rb +1 -1
- data/spec/mongo/operation/insert/command_spec.rb +1 -1
- data/spec/mongo/operation/insert/op_msg_spec.rb +1 -1
- data/spec/mongo/operation/update/bulk_spec.rb +1 -1
- data/spec/mongo/operation/update/command_spec.rb +2 -2
- data/spec/mongo/operation/update/op_msg_spec.rb +2 -2
- data/spec/mongo/protocol/msg_spec.rb +11 -0
- data/spec/mongo/retryable_spec.rb +78 -25
- data/spec/mongo/server/connection_pool_spec.rb +661 -126
- data/spec/mongo/server/connection_spec.rb +55 -7
- data/spec/mongo/server_spec.rb +5 -0
- data/spec/mongo/uri/srv_protocol_spec.rb +135 -2
- data/spec/mongo/uri_option_parsing_spec.rb +511 -0
- data/spec/mongo/uri_spec.rb +42 -6
- data/spec/spec_helper.rb +1 -84
- data/spec/spec_tests/cmap_spec.rb +50 -0
- data/spec/spec_tests/command_monitoring_spec.rb +7 -18
- data/spec/spec_tests/crud_spec.rb +3 -49
- data/spec/spec_tests/data/cmap/connection-must-have-id.yml +21 -0
- data/spec/spec_tests/data/cmap/connection-must-order-ids.yml +21 -0
- data/spec/spec_tests/data/cmap/pool-checkin-destroy-closed.yml +24 -0
- data/spec/spec_tests/data/cmap/pool-checkin-destroy-stale.yml +24 -0
- data/spec/spec_tests/data/cmap/pool-checkin-make-available.yml +21 -0
- data/spec/spec_tests/data/cmap/pool-checkin.yml +18 -0
- data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +13 -0
- data/spec/spec_tests/data/cmap/pool-checkout-error-closed.yml +28 -0
- data/spec/spec_tests/data/cmap/pool-checkout-multiple.yml +34 -0
- data/spec/spec_tests/data/cmap/pool-checkout-no-idle.yml +31 -0
- data/spec/spec_tests/data/cmap/pool-checkout-no-stale.yml +29 -0
- data/spec/spec_tests/data/cmap/pool-close-destroy-conns.yml +26 -0
- data/spec/spec_tests/data/cmap/pool-close.yml +11 -0
- data/spec/spec_tests/data/cmap/pool-create-max-size.yml +56 -0
- data/spec/spec_tests/data/cmap/pool-create-min-size.yml +27 -0
- data/spec/spec_tests/data/cmap/pool-create-with-options.yml +20 -0
- data/spec/spec_tests/data/cmap/pool-create.yml +12 -0
- data/spec/spec_tests/data/cmap/wait-queue-fairness.yml +94 -0
- data/spec/spec_tests/data/cmap/wait-queue-timeout.yml +41 -0
- data/spec/spec_tests/data/retryable_reads/aggregate-serverErrors.yml +157 -0
- data/spec/spec_tests/data/retryable_reads/aggregate.yml +87 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch-serverErrors.yml +149 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch.yml +61 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch-serverErrors.yml +149 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch.yml +65 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch-serverErrors.yml +153 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch.yml +61 -0
- data/spec/spec_tests/data/retryable_reads/count-serverErrors.yml +150 -0
- data/spec/spec_tests/data/retryable_reads/count.yml +64 -0
- data/spec/spec_tests/data/retryable_reads/countDocuments-serverErrors.yml +150 -0
- data/spec/spec_tests/data/retryable_reads/countDocuments.yml +64 -0
- data/spec/spec_tests/data/retryable_reads/distinct-serverErrors.yml +156 -0
- data/spec/spec_tests/data/retryable_reads/distinct.yml +71 -0
- data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-serverErrors.yml +148 -0
- data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount.yml +62 -0
- data/spec/spec_tests/data/retryable_reads/find-serverErrors.yml +160 -0
- data/spec/spec_tests/data/retryable_reads/find.yml +86 -0
- data/spec/spec_tests/data/retryable_reads/findOne-serverErrors.yml +154 -0
- data/spec/spec_tests/data/retryable_reads/findOne.yml +68 -0
- data/spec/spec_tests/data/retryable_reads/gridfs-download-serverErrors.yml +173 -0
- data/spec/spec_tests/data/retryable_reads/gridfs-download.yml +79 -0
- data/spec/spec_tests/data/retryable_reads/gridfs-downloadByName-serverErrors.yml +174 -0
- data/spec/spec_tests/data/retryable_reads/gridfs-downloadByName.yml +79 -0
- data/spec/spec_tests/data/retryable_reads/listCollectionNames-serverErrors.yml +143 -0
- data/spec/spec_tests/data/retryable_reads/listCollectionNames.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listCollectionObjects-serverErrors.yml +144 -0
- data/spec/spec_tests/data/retryable_reads/listCollectionObjects.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listCollections-serverErrors.yml +143 -0
- data/spec/spec_tests/data/retryable_reads/listCollections.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listDatabaseNames-serverErrors.yml +143 -0
- data/spec/spec_tests/data/retryable_reads/listDatabaseNames.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listDatabaseObjects-serverErrors.yml +144 -0
- data/spec/spec_tests/data/retryable_reads/listDatabaseObjects.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listDatabases-serverErrors.yml +144 -0
- data/spec/spec_tests/data/retryable_reads/listDatabases.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listIndexNames-serverErrors.yml +144 -0
- data/spec/spec_tests/data/retryable_reads/listIndexNames.yml +60 -0
- data/spec/spec_tests/data/retryable_reads/listIndexes-serverErrors.yml +145 -0
- data/spec/spec_tests/data/retryable_reads/listIndexes.yml +60 -0
- data/spec/spec_tests/data/retryable_reads/mapReduce.yml +60 -0
- data/spec/spec_tests/data/retryable_writes/bulkWrite-serverErrors.yml +10 -7
- data/spec/spec_tests/data/retryable_writes/bulkWrite.yml +15 -22
- data/spec/spec_tests/data/retryable_writes/deleteMany.yml +22 -0
- data/spec/spec_tests/data/retryable_writes/deleteOne-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/deleteOne.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/findOneAndDelete-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/findOneAndDelete.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/findOneAndReplace-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/findOneAndReplace.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/findOneAndUpdate-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/findOneAndUpdate.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/insertMany-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/insertMany.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/insertOne-serverErrors.yml +10 -45
- data/spec/spec_tests/data/retryable_writes/insertOne.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/replaceOne-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/replaceOne.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/updateMany.yml +27 -0
- data/spec/spec_tests/data/retryable_writes/updateOne-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/updateOne.yml +5 -14
- data/spec/spec_tests/data/transactions/abort.yml +7 -2
- data/spec/spec_tests/data/transactions/bulk.yml +7 -2
- data/spec/spec_tests/data/transactions/causal-consistency.yml +11 -4
- data/spec/spec_tests/data/transactions/commit.yml +11 -4
- data/spec/spec_tests/data/transactions/count.yml +64 -0
- data/spec/spec_tests/data/transactions/delete.yml +7 -2
- data/spec/spec_tests/data/transactions/error-labels.yml +8 -2
- data/spec/spec_tests/data/transactions/errors.yml +7 -2
- data/spec/spec_tests/data/transactions/findOneAndDelete.yml +7 -2
- data/spec/spec_tests/data/transactions/findOneAndReplace.yml +7 -2
- data/spec/spec_tests/data/transactions/findOneAndUpdate.yml +7 -2
- data/spec/spec_tests/data/transactions/insert.yml +9 -2
- data/spec/spec_tests/data/transactions/isolation.yml +7 -2
- data/spec/spec_tests/data/transactions/read-concern.yml +15 -6
- data/spec/spec_tests/data/transactions/read-pref.yml +7 -2
- data/spec/spec_tests/data/transactions/reads.yml +8 -48
- data/spec/spec_tests/data/transactions/retryable-abort.yml +7 -2
- data/spec/spec_tests/data/transactions/retryable-commit.yml +7 -2
- data/spec/spec_tests/data/transactions/retryable-writes.yml +7 -2
- data/spec/spec_tests/data/transactions/run-command.yml +7 -2
- data/spec/spec_tests/data/transactions/transaction-options.yml +7 -2
- data/spec/spec_tests/data/transactions/update.yml +7 -2
- data/spec/spec_tests/data/transactions/write-concern.yml +7 -2
- data/spec/spec_tests/data/transactions_api/callback-aborts.yml +6 -1
- data/spec/spec_tests/data/transactions_api/callback-commits.yml +6 -1
- data/spec/spec_tests/data/transactions_api/callback-retry.yml +6 -1
- data/spec/spec_tests/data/transactions_api/commit-retry.yml +6 -1
- data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +6 -3
- data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +6 -1
- data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +6 -1
- data/spec/spec_tests/data/transactions_api/commit.yml +6 -1
- data/spec/spec_tests/data/transactions_api/transaction-options.yml +6 -1
- data/spec/spec_tests/retryable_reads_spec.rb +11 -0
- data/spec/spec_tests/retryable_writes_spec.rb +4 -69
- data/spec/spec_tests/transactions_api_spec.rb +42 -37
- data/spec/spec_tests/transactions_spec.rb +42 -33
- data/spec/support/authorization.rb +12 -0
- data/spec/support/change_streams/operation.rb +1 -1
- data/spec/support/client_registry.rb +20 -0
- data/spec/support/cluster_config.rb +16 -15
- data/spec/support/cluster_tools.rb +346 -0
- data/spec/support/cmap.rb +367 -0
- data/spec/support/cmap/verifier.rb +46 -0
- data/spec/support/command_monitoring.rb +4 -6
- data/spec/support/common_shortcuts.rb +6 -0
- data/spec/support/connection_string.rb +2 -2
- data/spec/support/crud.rb +171 -184
- data/spec/support/crud/operation.rb +43 -0
- data/spec/support/crud/outcome.rb +53 -0
- data/spec/support/crud/read.rb +102 -12
- data/spec/support/crud/requirement.rb +69 -0
- data/spec/support/crud/spec.rb +68 -0
- data/spec/support/crud/test.rb +141 -0
- data/spec/support/crud/verifier.rb +96 -18
- data/spec/support/crud/write.rb +18 -3
- data/spec/support/event_subscriber.rb +15 -0
- data/spec/support/primary_socket.rb +2 -2
- data/spec/support/spec_config.rb +89 -20
- data/spec/support/transactions.rb +2 -306
- data/spec/support/transactions/operation.rb +7 -7
- data/spec/support/transactions/spec.rb +28 -0
- data/spec/support/transactions/test.rb +191 -0
- data/spec/support/utils.rb +123 -0
- metadata +202 -9
- metadata.gz.sig +0 -0
- data/lib/mongo/server/connection_pool/queue.rb +0 -359
- data/spec/mongo/server/connection_pool/queue_spec.rb +0 -353
- data/spec/support/transactions/verifier.rb +0 -97
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdc48b8fb67060880d69ada836cc9c468abe7fd2b2e959cffaeee5edb410f68a
|
4
|
+
data.tar.gz: c8a365dac958eea89f939f78a668474f9f2e5d1ddb94e8cf772d8eeccb52d6a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6984456cca54c0a352903f1336a6a5c3674eacdd6abf7f9558900cc11d33806d9c32aa7700bcc950a0a8ca973ea5c7f5ad223dbd49c267c04e68703cfb98eda3
|
7
|
+
data.tar.gz: 1ea50f9927a8bb622bf0188c1b158d00f80d35fe0fae72e81c6bac9a94775a3be3f7404b6674962db97833d3449f3bed448fff177527c853fd2e8610c78c783a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Rakefile
CHANGED
@@ -33,6 +33,18 @@ namespace :spec do
|
|
33
33
|
SpecSetup.new.run
|
34
34
|
end
|
35
35
|
|
36
|
+
desc 'Prints configuration used by the test suite'
|
37
|
+
task :config do
|
38
|
+
$: << File.join(File.dirname(__FILE__), 'spec')
|
39
|
+
|
40
|
+
# Since this task is usually used for troubleshooting of test suite
|
41
|
+
# configuration, leave driver log level at the default of debug to
|
42
|
+
# have connection diagnostics printed during handshakes and such.
|
43
|
+
require 'support/spec_config'
|
44
|
+
require 'support/client_registry'
|
45
|
+
SpecConfig.instance.print_summary
|
46
|
+
end
|
47
|
+
|
36
48
|
task :ci => ['spec:prepare', :spec]
|
37
49
|
end
|
38
50
|
|
data/lib/mongo.rb
CHANGED
@@ -12,9 +12,23 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require 'base64'
|
15
16
|
require 'forwardable'
|
16
|
-
require '
|
17
|
+
require 'ipaddr'
|
18
|
+
require 'logger'
|
17
19
|
require 'openssl'
|
20
|
+
require 'rbconfig'
|
21
|
+
require 'resolv'
|
22
|
+
require 'securerandom'
|
23
|
+
require 'set'
|
24
|
+
require 'socket'
|
25
|
+
require 'stringio'
|
26
|
+
require 'timeout'
|
27
|
+
require 'uri'
|
28
|
+
require 'zlib'
|
29
|
+
|
30
|
+
require 'bson'
|
31
|
+
|
18
32
|
require 'mongo/id'
|
19
33
|
require 'mongo/bson'
|
20
34
|
require 'mongo/semaphore'
|
data/lib/mongo/address/ipv6.rb
CHANGED
@@ -53,8 +53,18 @@ module Mongo
|
|
53
53
|
#
|
54
54
|
# @since 2.1.0
|
55
55
|
def combine!(result, count)
|
56
|
-
|
57
|
-
|
56
|
+
# Errors can be communicated by the server in a variety of fields:
|
57
|
+
# writeError, writeErrors, writeConcernError, writeConcernErrors.
|
58
|
+
# Currently only errors given in writeConcernErrors will cause
|
59
|
+
# counts not to be added, because this behavior is covered by the
|
60
|
+
# retryable writes tests. It is possible that some or all of the
|
61
|
+
# other errors should also be excluded when combining counts and
|
62
|
+
# ids, and it is also possible that only a subset of these error
|
63
|
+
# fields is actually possible in the context of bulk writes.
|
64
|
+
unless result.write_concern_error?
|
65
|
+
combine_counts!(result)
|
66
|
+
combine_ids!(result)
|
67
|
+
end
|
58
68
|
combine_errors!(result)
|
59
69
|
@count += count
|
60
70
|
end
|
data/lib/mongo/client.rb
CHANGED
@@ -26,7 +26,10 @@ module Mongo
|
|
26
26
|
# subcomponents.
|
27
27
|
#
|
28
28
|
# @since 2.1.0
|
29
|
-
CRUD_OPTIONS = [
|
29
|
+
CRUD_OPTIONS = [
|
30
|
+
:database, :read, :write, :retry_reads, :retry_writes,
|
31
|
+
:max_read_retries, :read_retry_interval, :max_write_retries,
|
32
|
+
].freeze
|
30
33
|
|
31
34
|
# Valid client options.
|
32
35
|
#
|
@@ -47,6 +50,7 @@ module Mongo
|
|
47
50
|
:max_idle_time,
|
48
51
|
:max_pool_size,
|
49
52
|
:max_read_retries,
|
53
|
+
:max_write_retries,
|
50
54
|
:min_pool_size,
|
51
55
|
:monitoring,
|
52
56
|
:monitoring_io,
|
@@ -56,6 +60,7 @@ module Mongo
|
|
56
60
|
:read_concern,
|
57
61
|
:read_retry_interval,
|
58
62
|
:replica_set,
|
63
|
+
:retry_reads,
|
59
64
|
:retry_writes,
|
60
65
|
:scan,
|
61
66
|
:sdam_proc,
|
@@ -170,7 +175,7 @@ module Mongo
|
|
170
175
|
# # connect to the replica set if given the address of a server in
|
171
176
|
# # a replica set
|
172
177
|
#
|
173
|
-
# @param [ Array<String
|
178
|
+
# @param [ Array<String> | String ] addresses_or_uri The array of server addresses in the
|
174
179
|
# form of host:port or a MongoDB URI connection string.
|
175
180
|
# @param [ Hash ] options The options to be used by the client.
|
176
181
|
#
|
@@ -204,7 +209,9 @@ module Mongo
|
|
204
209
|
# @option options [ Integer ] :max_pool_size The maximum size of the
|
205
210
|
# connection pool.
|
206
211
|
# @option options [ Integer ] :max_read_retries The maximum number of read
|
207
|
-
# retries
|
212
|
+
# retries when legacy read retries are in use.
|
213
|
+
# @option options [ Integer ] :max_write_retries The maximum number of write
|
214
|
+
# retries when legacy write retries are in use.
|
208
215
|
# @option options [ Integer ] :min_pool_size The minimum size of the
|
209
216
|
# connection pool.
|
210
217
|
# @option options [ true, false ] :monitoring If false is given, the
|
@@ -238,9 +245,13 @@ module Mongo
|
|
238
245
|
# in which reads on a mongos are retried.
|
239
246
|
# @option options [ Symbol ] :replica_set The name of the replica set to
|
240
247
|
# connect to. Servers not in this replica set will be ignored.
|
241
|
-
# @option options [ true
|
248
|
+
# @option options [ true | false ] :retry_reads If true, modern retryable
|
249
|
+
# reads are enabled (which is the default). If false, modern retryable
|
250
|
+
# reads are disabled and legacy retryable reads are enabled.
|
251
|
+
# @option options [ true | false ] :retry_writes Retry writes once when
|
242
252
|
# connected to a replica set or sharded cluster versions 3.6 and up.
|
243
|
-
#
|
253
|
+
# (Default is true.)
|
254
|
+
# @option options [ true | false ] :scan Whether to scan all seeds
|
244
255
|
# in constructor. The default in driver version 2.x is to do so;
|
245
256
|
# driver version 3.x will not scan seeds in constructor. Opt in to the
|
246
257
|
# new behavior by setting this option to false. *Note:* setting
|
@@ -318,6 +329,12 @@ module Mongo
|
|
318
329
|
else
|
319
330
|
options = {}
|
320
331
|
end
|
332
|
+
unless options[:retry_reads] == false
|
333
|
+
options[:retry_reads] = true
|
334
|
+
end
|
335
|
+
unless options[:retry_writes] == false
|
336
|
+
options[:retry_writes] = true
|
337
|
+
end
|
321
338
|
Lint.validate_underscore_read_preference(options[:read])
|
322
339
|
Lint.validate_read_concern_option(options[:read_concern])
|
323
340
|
if addresses_or_uri.is_a?(::String)
|
@@ -357,9 +374,45 @@ module Mongo
|
|
357
374
|
server_selection_semaphore: @server_selection_semaphore,
|
358
375
|
# but need to put the database back in for auth...
|
359
376
|
database: options[:database],
|
377
|
+
|
378
|
+
# Put these options in for legacy compatibility, but note that
|
379
|
+
# their values on the client and the cluster do not have to match -
|
380
|
+
# applications should read these values from client, not from cluster
|
381
|
+
max_read_retries: options[:max_read_retries],
|
382
|
+
read_retry_interval: options[:read_retry_interval],
|
360
383
|
)
|
361
384
|
end
|
362
385
|
|
386
|
+
# Get the maximum number of times the client can retry a read operation
|
387
|
+
# when using legacy read retries.
|
388
|
+
#
|
389
|
+
# @return [ Integer ] The maximum number of retries.
|
390
|
+
#
|
391
|
+
# @api private
|
392
|
+
def max_read_retries
|
393
|
+
options[:max_read_retries] || Cluster::MAX_READ_RETRIES
|
394
|
+
end
|
395
|
+
|
396
|
+
# Get the interval, in seconds, in which read retries when using legacy
|
397
|
+
# read retries.
|
398
|
+
#
|
399
|
+
# @return [ Float ] The interval.
|
400
|
+
#
|
401
|
+
# @api private
|
402
|
+
def read_retry_interval
|
403
|
+
options[:read_retry_interval] || Cluster::READ_RETRY_INTERVAL
|
404
|
+
end
|
405
|
+
|
406
|
+
# Get the maximum number of times the client can retry a write operation
|
407
|
+
# when using legacy write retries.
|
408
|
+
#
|
409
|
+
# @return [ Integer ] The maximum number of retries.
|
410
|
+
#
|
411
|
+
# @api private
|
412
|
+
def max_write_retries
|
413
|
+
options[:max_write_retries] || Cluster::MAX_WRITE_RETRIES
|
414
|
+
end
|
415
|
+
|
363
416
|
# Get an inspection of the client as a string.
|
364
417
|
#
|
365
418
|
# @example Inspect the client.
|
@@ -714,7 +767,7 @@ module Mongo
|
|
714
767
|
|
715
768
|
def validate_max_min_pool_size!(option, opts)
|
716
769
|
if option == :min_pool_size && opts[:min_pool_size]
|
717
|
-
max = opts[:max_pool_size] || Server::ConnectionPool::
|
770
|
+
max = opts[:max_pool_size] || Server::ConnectionPool::DEFAULT_MAX_SIZE
|
718
771
|
raise Error::InvalidMinPoolSize.new(opts[:min_pool_size], max) unless opts[:min_pool_size] <= max
|
719
772
|
end
|
720
773
|
true
|
data/lib/mongo/cluster.rb
CHANGED
@@ -29,17 +29,18 @@ module Mongo
|
|
29
29
|
include Event::Subscriber
|
30
30
|
include Loggable
|
31
31
|
|
32
|
-
# The default number of
|
32
|
+
# The default number of legacy read retries.
|
33
33
|
#
|
34
34
|
# @since 2.1.1
|
35
35
|
MAX_READ_RETRIES = 1
|
36
36
|
|
37
|
-
# The default number of
|
37
|
+
# The default number of legacy write retries.
|
38
38
|
#
|
39
39
|
# @since 2.4.2
|
40
40
|
MAX_WRITE_RETRIES = 1
|
41
41
|
|
42
|
-
# The default
|
42
|
+
# The default read retry interval, in seconds, when using legacy read
|
43
|
+
# retries.
|
43
44
|
#
|
44
45
|
# @since 2.1.1
|
45
46
|
READ_RETRY_INTERVAL = 5
|
@@ -246,21 +247,30 @@ module Mongo
|
|
246
247
|
:single?, :unknown?
|
247
248
|
def_delegators :@cursor_reaper, :register_cursor, :schedule_kill_cursor, :unregister_cursor
|
248
249
|
|
249
|
-
# Get the maximum number of times the
|
250
|
-
#
|
250
|
+
# Get the maximum number of times the client can retry a read operation
|
251
|
+
# when using legacy read retries.
|
252
|
+
#
|
253
|
+
# @note max_read_retries should be retrieved from the Client instance,
|
254
|
+
# not from a Cluster instance, because clusters may be shared between
|
255
|
+
# clients with different values for max read retries.
|
251
256
|
#
|
252
257
|
# @example Get the max read retries.
|
253
258
|
# cluster.max_read_retries
|
254
259
|
#
|
255
|
-
# @return [ Integer ] The maximum retries.
|
260
|
+
# @return [ Integer ] The maximum number of retries.
|
256
261
|
#
|
257
262
|
# @since 2.1.1
|
263
|
+
# @deprecated
|
258
264
|
def max_read_retries
|
259
265
|
options[:max_read_retries] || MAX_READ_RETRIES
|
260
266
|
end
|
261
267
|
|
262
|
-
# Get the interval, in seconds, in which
|
263
|
-
#
|
268
|
+
# Get the interval, in seconds, in which read retries when using legacy
|
269
|
+
# read retries.
|
270
|
+
#
|
271
|
+
# @note read_retry_interval should be retrieved from the Client instance,
|
272
|
+
# not from a Cluster instance, because clusters may be shared between
|
273
|
+
# clients with different values for the read retry interval.
|
264
274
|
#
|
265
275
|
# @example Get the read retry interval.
|
266
276
|
# cluster.read_retry_interval
|
@@ -268,6 +278,7 @@ module Mongo
|
|
268
278
|
# @return [ Float ] The interval.
|
269
279
|
#
|
270
280
|
# @since 2.1.1
|
281
|
+
# @deprecated
|
271
282
|
def read_retry_interval
|
272
283
|
options[:read_retry_interval] || READ_RETRY_INTERVAL
|
273
284
|
end
|
@@ -16,7 +16,7 @@ module Mongo
|
|
16
16
|
|
17
17
|
class Cluster
|
18
18
|
|
19
|
-
# A manager that calls a method on each of a cluster's pools to close
|
19
|
+
# A manager that calls a method on each of a cluster's pools to close idle
|
20
20
|
# sockets.
|
21
21
|
#
|
22
22
|
# @api private
|
@@ -29,7 +29,7 @@ module Mongo
|
|
29
29
|
# @example Initialize the socket reaper.
|
30
30
|
# SocketReaper.new(cluster)
|
31
31
|
#
|
32
|
-
# @param [ Mongo::Cluster ] cluster The cluster whose pools'
|
32
|
+
# @param [ Mongo::Cluster ] cluster The cluster whose pools' idle sockets
|
33
33
|
# need to be reaped at regular intervals.
|
34
34
|
#
|
35
35
|
# @since 2.5.0
|
@@ -37,23 +37,26 @@ module Mongo
|
|
37
37
|
@cluster = cluster
|
38
38
|
end
|
39
39
|
|
40
|
-
# Execute the operation to close the pool's
|
40
|
+
# Execute the operation to close the pool's idle sockets.
|
41
41
|
#
|
42
|
-
# @example Close the
|
42
|
+
# @example Close the idle sockets in each of the cluster's pools.
|
43
43
|
# socket_reaper.execute
|
44
44
|
#
|
45
45
|
# @since 2.5.0
|
46
46
|
def execute
|
47
47
|
@cluster.servers.each do |server|
|
48
|
-
server.pool.
|
49
|
-
end
|
48
|
+
server.pool.close_idle_sockets
|
49
|
+
end
|
50
|
+
true
|
50
51
|
end
|
51
52
|
|
52
|
-
# When the socket reaper is garbage-collected, there's no need to close
|
53
|
-
# sockets will be closed anyway when the pools are
|
53
|
+
# When the socket reaper is garbage-collected, there's no need to close
|
54
|
+
# idle sockets; sockets will be closed anyway when the pools are
|
55
|
+
# garbage collected.
|
54
56
|
#
|
55
57
|
# @since 2.5.0
|
56
|
-
def flush
|
58
|
+
def flush
|
59
|
+
end
|
57
60
|
end
|
58
61
|
end
|
59
62
|
end
|
data/lib/mongo/collection.rb
CHANGED
@@ -110,8 +110,12 @@ module Mongo
|
|
110
110
|
server.standalone? || server.mongos? || server.primary? || secondary_ok?
|
111
111
|
end
|
112
112
|
|
113
|
+
def out?
|
114
|
+
pipeline.any? { |op| op.key?('$out') || op.key?(:$out) }
|
115
|
+
end
|
116
|
+
|
113
117
|
def secondary_ok?
|
114
|
-
|
118
|
+
!out?
|
115
119
|
end
|
116
120
|
|
117
121
|
def send_initial_query(server, session)
|
@@ -81,6 +81,12 @@ module Mongo
|
|
81
81
|
# return changes that occurred at or after the specified timestamp. Any
|
82
82
|
# command run against the server will return a cluster time that can
|
83
83
|
# be used here. Only recognized by server versions 4.0+.
|
84
|
+
# @option options [ Bson::Document, Hash ] :start_after Similar to :resume_after, this
|
85
|
+
# option takes a resume token and starts a new change stream returning the first
|
86
|
+
# notification after the token. This will allow users to watch collections that have been
|
87
|
+
# dropped and recreated or newly renamed collections without missing any notifications.
|
88
|
+
#
|
89
|
+
# The server will report an error if `startAfter` and `resumeAfter` are both specified.
|
84
90
|
#
|
85
91
|
# @since 2.5.0
|
86
92
|
def initialize(view, pipeline, changes_for, options = {})
|
@@ -89,6 +95,7 @@ module Mongo
|
|
89
95
|
@change_stream_filters = pipeline && pipeline.dup
|
90
96
|
@options = options && options.dup.freeze
|
91
97
|
@resume_token = @options[:resume_after]
|
98
|
+
@start_after = @options[:start_after]
|
92
99
|
create_cursor!
|
93
100
|
|
94
101
|
# We send different parameters when we resume a change stream
|
@@ -263,17 +270,22 @@ module Mongo
|
|
263
270
|
@start_at_operation_time_supported = nil
|
264
271
|
|
265
272
|
session = client.send(:get_session, @options)
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
273
|
+
start_at_operation_time = nil
|
274
|
+
@cursor = read_with_retry_cursor(session, server_selector, view) do |server|
|
275
|
+
result = send_initial_query(server, session)
|
276
|
+
if doc = result.replies.first && result.replies.first.documents.first
|
277
|
+
start_at_operation_time = doc['operationTime']
|
278
|
+
else
|
279
|
+
# The above may set @start_at_operation_time to nil
|
280
|
+
# if it was not in the document for some reason,
|
281
|
+
# for consistency set it to nil here as well.
|
282
|
+
# NB: since this block may be executed more than once, each
|
283
|
+
# execution must write to start_at_operation_time either way.
|
284
|
+
start_at_operation_time = nil
|
285
|
+
end
|
286
|
+
result
|
275
287
|
end
|
276
|
-
@
|
288
|
+
@start_at_operation_time = start_at_operation_time
|
277
289
|
end
|
278
290
|
|
279
291
|
def pipeline
|
@@ -296,6 +308,10 @@ module Mongo
|
|
296
308
|
if @resume_token
|
297
309
|
# Spec says we need to remove startAtOperationTime if
|
298
310
|
# one was passed in by user, thus we won't forward it
|
311
|
+
elsif @start_after
|
312
|
+
# The spec says to set `resumeAfter` to the `startAfter` token and not to send
|
313
|
+
# either `startAfter` or `startAtOperationTime`.
|
314
|
+
@resume_token = @start_after
|
299
315
|
elsif start_at_operation_time_supported? && @start_at_operation_time
|
300
316
|
# It is crucial to check @start_at_operation_time_supported
|
301
317
|
# here - we may have switched to an older server that
|
@@ -309,6 +325,10 @@ module Mongo
|
|
309
325
|
raise Mongo::Error::MissingResumeToken
|
310
326
|
end
|
311
327
|
else
|
328
|
+
if @start_after
|
329
|
+
doc[:startAfter] = @start_after
|
330
|
+
end
|
331
|
+
|
312
332
|
if options[:start_at_operation_time]
|
313
333
|
doc[:startAtOperationTime] = time_to_bson_timestamp(
|
314
334
|
options[:start_at_operation_time])
|