mongo 2.5.0.beta → 2.5.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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongo/address.rb +1 -1
- data/lib/mongo/address/unix.rb +1 -1
- data/lib/mongo/auth/user.rb +0 -5
- data/lib/mongo/auth/user/view.rb +4 -4
- data/lib/mongo/bulk_write.rb +60 -32
- data/lib/mongo/client.rb +44 -8
- data/lib/mongo/cluster.rb +14 -12
- data/lib/mongo/cluster/periodic_executor.rb +106 -0
- data/lib/mongo/cluster/{cursor_reaper.rb → reapers/cursor_reaper.rb} +5 -37
- data/lib/mongo/cluster/reapers/socket_reaper.rb +59 -0
- data/lib/mongo/collection.rb +9 -6
- data/lib/mongo/collection/view.rb +2 -2
- data/lib/mongo/collection/view/builder/aggregation.rb +2 -1
- data/lib/mongo/collection/view/builder/find_command.rb +1 -1
- data/lib/mongo/collection/view/change_stream.rb +14 -1
- data/lib/mongo/collection/view/map_reduce.rb +30 -13
- data/lib/mongo/collection/view/readable.rb +5 -5
- data/lib/mongo/collection/view/writable.rb +98 -51
- data/lib/mongo/error.rb +3 -0
- data/lib/mongo/error/invalid_txt_record.rb +27 -0
- data/lib/mongo/error/invalid_uri.rb +7 -6
- data/lib/mongo/error/mismatched_domain.rb +27 -0
- data/lib/mongo/error/no_srv_records.rb +26 -0
- data/lib/mongo/error/unsupported_features.rb +0 -18
- data/lib/mongo/index/view.rb +2 -2
- data/lib/mongo/operation.rb +1 -0
- data/lib/mongo/operation/causally_consistent.rb +33 -0
- data/lib/mongo/operation/commands.rb +2 -1
- data/lib/mongo/operation/commands/aggregate.rb +2 -7
- data/lib/mongo/operation/commands/count.rb +27 -0
- data/lib/mongo/operation/commands/distinct.rb +27 -0
- data/lib/mongo/operation/commands/find.rb +3 -1
- data/lib/mongo/operation/commands/map_reduce.rb +1 -0
- data/lib/mongo/operation/commands/parallel_scan.rb +1 -0
- data/lib/mongo/operation/specifiable.rb +12 -0
- data/lib/mongo/operation/uses_command_op_msg.rb +36 -5
- data/lib/mongo/operation/write.rb +0 -5
- data/lib/mongo/operation/write/bulk/bulkable.rb +4 -8
- data/lib/mongo/operation/write/bulk/mergable.rb +2 -0
- data/lib/mongo/operation/write/command/create_index.rb +19 -0
- data/lib/mongo/operation/write/command/create_user.rb +19 -0
- data/lib/mongo/operation/write/command/delete.rb +1 -2
- data/lib/mongo/operation/write/command/drop_index.rb +19 -0
- data/lib/mongo/operation/write/command/insert.rb +1 -2
- data/lib/mongo/operation/write/command/remove_user.rb +19 -0
- data/lib/mongo/operation/write/command/update.rb +1 -2
- data/lib/mongo/operation/write/command/update_user.rb +19 -0
- data/lib/mongo/operation/write/write_command_enabled.rb +1 -3
- data/lib/mongo/protocol/compressed.rb +2 -1
- data/lib/mongo/protocol/serializers.rb +6 -6
- data/lib/mongo/retryable.rb +48 -5
- data/lib/mongo/server.rb +15 -0
- data/lib/mongo/server/connection.rb +21 -1
- data/lib/mongo/server/connection_pool.rb +3 -0
- data/lib/mongo/server/connection_pool/queue.rb +50 -5
- data/lib/mongo/server/description.rb +11 -3
- data/lib/mongo/server/description/features.rb +26 -7
- data/lib/mongo/session.rb +133 -6
- data/lib/mongo/session/server_session.rb +30 -0
- data/lib/mongo/session/session_pool.rb +20 -20
- data/lib/mongo/uri.rb +88 -44
- data/lib/mongo/uri/srv_protocol.rb +158 -0
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern/normalizable.rb +12 -0
- data/mongo.gemspec +1 -2
- data/spec/mongo/address_spec.rb +12 -0
- data/spec/mongo/auth/user/view_spec.rb +1 -5
- data/spec/mongo/bulk_write_spec.rb +232 -401
- data/spec/mongo/change_stream_examples_spec.rb +150 -0
- data/spec/mongo/client_spec.rb +142 -2
- data/spec/mongo/cluster/cursor_reaper_spec.rb +0 -70
- data/spec/mongo/cluster/socket_reaper_spec.rb +32 -0
- data/spec/mongo/cluster_spec.rb +11 -7
- data/spec/mongo/collection/view/aggregation_spec.rb +46 -1
- data/spec/mongo/collection/view/builder/find_command_spec.rb +15 -0
- data/spec/mongo/collection/view/change_stream_spec.rb +79 -12
- data/spec/mongo/collection/view/map_reduce_spec.rb +120 -4
- data/spec/mongo/collection/view/readable_spec.rb +23 -5
- data/spec/mongo/collection_spec.rb +292 -102
- data/spec/mongo/command_monitoring_spec.rb +26 -32
- data/spec/mongo/crud_spec.rb +1 -1
- data/spec/mongo/cursor_spec.rb +2 -3
- data/spec/mongo/database_spec.rb +30 -14
- data/spec/mongo/dns_seedlist_discovery_spec.rb +94 -0
- data/spec/mongo/grid/fs_bucket_spec.rb +1 -1
- data/spec/mongo/grid/stream/write_spec.rb +1 -1
- data/spec/mongo/index/view_spec.rb +8 -46
- data/spec/mongo/operation/write/bulk/delete_spec.rb +2 -2
- data/spec/mongo/operation/write/bulk/insert_spec.rb +2 -10
- data/spec/mongo/operation/write/{create_index_spec.rb → command/create_index_spec.rb} +2 -6
- data/spec/mongo/operation/write/command/delete_spec.rb +35 -7
- data/spec/mongo/operation/write/{drop_index_spec.rb → command/drop_index_spec.rb} +1 -1
- data/spec/mongo/operation/write/command/insert_spec.rb +37 -6
- data/spec/mongo/operation/write/{remove_user_spec.rb → command/remove_user_spec.rb} +2 -6
- data/spec/mongo/operation/write/command/update_spec.rb +34 -7
- data/spec/mongo/operation/write/{update_user_spec.rb → command/update_user_spec.rb} +1 -1
- data/spec/mongo/operation/write/create_user_spec.rb +1 -1
- data/spec/mongo/operation/write/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/insert_spec.rb +2 -10
- data/spec/mongo/operation/write/update_spec.rb +3 -15
- data/spec/mongo/retryable_spec.rb +1 -1
- data/spec/mongo/retryable_writes_spec.rb +815 -0
- data/spec/mongo/server/connection_pool/queue_spec.rb +35 -2
- data/spec/mongo/server/connection_pool_spec.rb +234 -1
- data/spec/mongo/server/connection_spec.rb +10 -6
- data/spec/mongo/server/description/features_spec.rb +51 -37
- data/spec/mongo/server/description_spec.rb +6 -3
- data/spec/mongo/server_spec.rb +87 -0
- data/spec/mongo/session/server_session_spec.rb +43 -0
- data/spec/mongo/session/session_pool_spec.rb +63 -27
- data/spec/mongo/session_spec.rb +247 -0
- data/spec/mongo/shell_examples_spec.rb +2 -2
- data/spec/mongo/uri/srv_protocol_spec.rb +933 -0
- data/spec/mongo/uri_spec.rb +42 -3
- data/spec/mongo/write_concern/acknowledged_spec.rb +11 -0
- data/spec/mongo/write_concern/unacknowledged_spec.rb +11 -0
- data/spec/spec_helper.rb +11 -25
- data/spec/support/authorization.rb +2 -1
- data/spec/support/connection_string.rb +8 -4
- data/spec/support/crud.rb +38 -24
- data/spec/support/crud/write.rb +30 -3
- data/spec/support/crud_tests/read/aggregate-out.yml +21 -0
- data/spec/support/crud_tests/write/bulkWrite-arrayFilters.yml +44 -0
- data/spec/support/crud_tests/write/findOneAndUpdate-arrayFilters.yml +1 -1
- data/spec/support/crud_tests/write/insertMany.yml +1 -3
- data/spec/support/crud_tests/write/replaceOne.yml +1 -1
- data/spec/support/crud_tests/write/updateMany-arrayFilters.yml +1 -1
- data/spec/support/crud_tests/write/updateOne-arrayFilters.yml +1 -1
- data/spec/support/dns_seedlist_discovery_tests/longer-parent-in-return.yml +11 -0
- data/spec/support/dns_seedlist_discovery_tests/misformatted-option.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/no-results.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/not-enough-parts.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/one-result-default-port.yml +10 -0
- data/spec/support/dns_seedlist_discovery_tests/one-txt-record-multiple-strings.yml +10 -0
- data/spec/support/dns_seedlist_discovery_tests/one-txt-record.yml +11 -0
- data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch1.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch2.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch3.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch4.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch5.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/returned-parent-too-short.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/returned-parent-wrong.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/two-results-default-port.yml +11 -0
- data/spec/support/dns_seedlist_discovery_tests/two-results-nonstandard-port.yml +11 -0
- data/spec/support/dns_seedlist_discovery_tests/two-txt-records.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/txt-record-not-allowed-option.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/txt-record-with-overridden-ssl-option.yml +11 -0
- data/spec/support/dns_seedlist_discovery_tests/txt-record-with-overridden-uri-option.yml +11 -0
- data/spec/support/dns_seedlist_discovery_tests/txt-record-with-unallowed-option.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/uri-with-port.yml +5 -0
- data/spec/support/dns_seedlist_discovery_tests/uri-with-two-hosts.yml +5 -0
- data/spec/support/retryable_writes_tests/bulkWrite.yml +305 -0
- data/spec/support/retryable_writes_tests/deleteOne.yml +51 -0
- data/spec/support/retryable_writes_tests/findOneAndDelete.yml +52 -0
- data/spec/support/retryable_writes_tests/findOneAndReplace.yml +57 -0
- data/spec/support/retryable_writes_tests/findOneAndUpdate.yml +56 -0
- data/spec/support/retryable_writes_tests/insertMany.yml +72 -0
- data/spec/support/retryable_writes_tests/insertOne.yml +55 -0
- data/spec/support/retryable_writes_tests/replaceOne.yml +60 -0
- data/spec/support/retryable_writes_tests/updateOne.yml +120 -0
- data/spec/support/shared/session.rb +525 -24
- metadata +437 -350
- metadata.gz.sig +0 -0
- data/lib/mongo/operation/commands/user_query.rb +0 -72
- data/lib/mongo/operation/write/create_index.rb +0 -67
- data/lib/mongo/operation/write/create_user.rb +0 -50
- data/lib/mongo/operation/write/drop_index.rb +0 -63
- data/lib/mongo/operation/write/remove_user.rb +0 -48
- data/lib/mongo/operation/write/update_user.rb +0 -50
data/lib/mongo/error.rb
CHANGED
@@ -90,14 +90,17 @@ require 'mongo/error/invalid_replacement_document'
|
|
90
90
|
require 'mongo/error/invalid_server_preference'
|
91
91
|
require 'mongo/error/invalid_session'
|
92
92
|
require 'mongo/error/invalid_signature'
|
93
|
+
require 'mongo/error/invalid_txt_record'
|
93
94
|
require 'mongo/error/invalid_update_document'
|
94
95
|
require 'mongo/error/invalid_uri'
|
95
96
|
require 'mongo/error/invalid_write_concern'
|
96
97
|
require 'mongo/error/max_bson_size'
|
97
98
|
require 'mongo/error/max_message_size'
|
99
|
+
require 'mongo/error/mismatched_domain'
|
98
100
|
require 'mongo/error/multi_index_drop'
|
99
101
|
require 'mongo/error/need_primary_server'
|
100
102
|
require 'mongo/error/no_server_available'
|
103
|
+
require 'mongo/error/no_srv_records'
|
101
104
|
require 'mongo/error/socket_error'
|
102
105
|
require 'mongo/error/socket_timeout_error'
|
103
106
|
require 'mongo/error/unchangeable_collection_option'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (C) 2017 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
class Error
|
17
|
+
|
18
|
+
# This exception is raised when the URI Parser's query returns too many
|
19
|
+
# TXT records or the record specifies invalid options.
|
20
|
+
#
|
21
|
+
# @example Instantiate the exception.
|
22
|
+
# Mongo::Error::InvalidTXTRecord.new(message)
|
23
|
+
#
|
24
|
+
# @since 2.5.0
|
25
|
+
class InvalidTXTRecord < Error; end
|
26
|
+
end
|
27
|
+
end
|
@@ -24,14 +24,15 @@ module Mongo
|
|
24
24
|
# Instantiate the new exception.
|
25
25
|
#
|
26
26
|
# @example Instantiate the exception.
|
27
|
-
# Mongo::Error::InvalidURI.new(uri)
|
27
|
+
# Mongo::Error::InvalidURI.new(uri, details, format)
|
28
28
|
#
|
29
29
|
# @since 2.0.0
|
30
|
-
def initialize(uri, details)
|
31
|
-
|
32
|
-
|
33
|
-
"MongoDB URI must be in the following format: #{
|
34
|
-
"Please see the following URL for more information: #{Mongo::URI::HELP}\n"
|
30
|
+
def initialize(uri, details, format = nil)
|
31
|
+
message = "Bad URI: #{uri}\n" +
|
32
|
+
"#{details}\n"
|
33
|
+
message += "MongoDB URI must be in the following format: #{format}\n" if format
|
34
|
+
message += "Please see the following URL for more information: #{Mongo::URI::HELP}\n"
|
35
|
+
super(message)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (C) 2017 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
class Error
|
17
|
+
|
18
|
+
# This exception is raised when the URI Parser's DNS query returns SRV record(s)
|
19
|
+
# whose parent domain does not match the hostname used for the query.
|
20
|
+
#
|
21
|
+
# @example Instantiate the exception.
|
22
|
+
# Mongo::Error::MismatchedDomain.new(message)
|
23
|
+
#
|
24
|
+
# @since 2.5.0
|
25
|
+
class MismatchedDomain < Error; end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Copyright (C) 2017 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
class Error
|
17
|
+
|
18
|
+
# This exception is raised when the URI Parser's DNS query returns no SRV records.
|
19
|
+
#
|
20
|
+
# @example Instantiate the exception.
|
21
|
+
# Mongo::Error::NoSRVRecords.new(message)
|
22
|
+
#
|
23
|
+
# @since 2.5.0
|
24
|
+
class NoSRVRecords < Error; end
|
25
|
+
end
|
26
|
+
end
|
@@ -20,24 +20,6 @@ module Mongo
|
|
20
20
|
#
|
21
21
|
# @since 2.0.0
|
22
22
|
class UnsupportedFeatures < Error
|
23
|
-
|
24
|
-
# Initialize the exception.
|
25
|
-
#
|
26
|
-
# @example Initialize the exception.
|
27
|
-
# Unsupported.new(0..3)
|
28
|
-
#
|
29
|
-
# @param [ Range ] server_wire_versions The server's supported wire
|
30
|
-
# versions.
|
31
|
-
#
|
32
|
-
# @since 2.0.0
|
33
|
-
def initialize(server_wire_versions)
|
34
|
-
super(
|
35
|
-
"This version of the driver, #{Mongo::VERSION}, only supports wire " +
|
36
|
-
"protocol versions #{Server::Description::Features::DRIVER_WIRE_VERSIONS} " +
|
37
|
-
"and the server supports wire versions #{server_wire_versions}. " +
|
38
|
-
"Please upgrade the driver to be able to support this server version."
|
39
|
-
)
|
40
|
-
end
|
41
23
|
end
|
42
24
|
end
|
43
25
|
end
|
data/lib/mongo/index/view.rb
CHANGED
@@ -157,7 +157,7 @@ module Mongo
|
|
157
157
|
session: session
|
158
158
|
}
|
159
159
|
spec[:write_concern] = write_concern if server.features.collation_enabled?
|
160
|
-
Operation::Write::CreateIndex.new(spec).execute(server)
|
160
|
+
Operation::Write::Command::CreateIndex.new(spec).execute(server)
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
@@ -232,7 +232,7 @@ module Mongo
|
|
232
232
|
}
|
233
233
|
server = next_primary
|
234
234
|
spec[:write_concern] = write_concern if server.features.collation_enabled?
|
235
|
-
Operation::Write::DropIndex.new(spec).execute(server)
|
235
|
+
Operation::Write::Command::DropIndex.new(spec).execute(server)
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
data/lib/mongo/operation.rb
CHANGED
@@ -18,6 +18,7 @@ require 'mongo/operation/specifiable'
|
|
18
18
|
require 'mongo/operation/limited'
|
19
19
|
require 'mongo/operation/object_id_generator'
|
20
20
|
require 'mongo/operation/uses_command_op_msg'
|
21
|
+
require 'mongo/operation/causally_consistent'
|
21
22
|
require 'mongo/operation/read_preference'
|
22
23
|
require 'mongo/operation/takes_write_concern'
|
23
24
|
require 'mongo/operation/read'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright (C) 2017 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
module Operation
|
17
|
+
|
18
|
+
# Encapsulates behaviour for adding a causal consistency doc to the command.
|
19
|
+
#
|
20
|
+
# @since 2.5.0
|
21
|
+
module CausallyConsistent
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def apply_causal_consistency!(selector, server)
|
26
|
+
if !server.standalone?
|
27
|
+
full_read_concern_doc = session.send(:causal_consistency_doc, selector[:readConcern])
|
28
|
+
selector[:readConcern] = full_read_concern_doc if full_read_concern_doc
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -14,6 +14,8 @@
|
|
14
14
|
|
15
15
|
require 'mongo/operation/commands/command'
|
16
16
|
require 'mongo/operation/commands/find'
|
17
|
+
require 'mongo/operation/commands/count'
|
18
|
+
require 'mongo/operation/commands/distinct'
|
17
19
|
require 'mongo/operation/commands/explain'
|
18
20
|
require 'mongo/operation/commands/get_more'
|
19
21
|
require 'mongo/operation/commands/parallel_scan'
|
@@ -26,5 +28,4 @@ require 'mongo/operation/commands/drop_database'
|
|
26
28
|
require 'mongo/operation/commands/indexes'
|
27
29
|
require 'mongo/operation/commands/list_collections'
|
28
30
|
require 'mongo/operation/commands/list_indexes'
|
29
|
-
require 'mongo/operation/commands/user_query'
|
30
31
|
require 'mongo/operation/commands/users_info'
|
@@ -41,17 +41,12 @@ module Mongo
|
|
41
41
|
# @since 2.0.0
|
42
42
|
class Aggregate < Command
|
43
43
|
include TakesWriteConcern
|
44
|
+
include CausallyConsistent
|
44
45
|
|
45
46
|
private
|
46
47
|
|
47
|
-
def filter_cursor_from_selector(sel, server)
|
48
|
-
return sel if server.features.write_command_enabled?
|
49
|
-
sel.reject{ |option, value| option.to_s == 'cursor' }
|
50
|
-
end
|
51
|
-
|
52
48
|
def message(server)
|
53
|
-
sel =
|
54
|
-
sel = update_selector_for_write_concern(sel, server)
|
49
|
+
sel = update_selector_for_write_concern(selector, server)
|
55
50
|
if server.features.op_msg_enabled?
|
56
51
|
command_op_msg(server, sel, options)
|
57
52
|
else
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (C) 2017 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
module Operation
|
17
|
+
module Commands
|
18
|
+
|
19
|
+
# Encapsulates behaviour for executing a count command.
|
20
|
+
#
|
21
|
+
# @since 2.5.0
|
22
|
+
class Count < Command
|
23
|
+
include CausallyConsistent
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (C) 2017 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
module Operation
|
17
|
+
module Commands
|
18
|
+
|
19
|
+
# Encapsulates behaviour for executing a distinct command.
|
20
|
+
#
|
21
|
+
# @since 2.5.0
|
22
|
+
class Distinct < Command
|
23
|
+
include CausallyConsistent
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -514,6 +514,18 @@ module Mongo
|
|
514
514
|
def session
|
515
515
|
@spec[:session]
|
516
516
|
end
|
517
|
+
|
518
|
+
# The transaction number for the operation.
|
519
|
+
#
|
520
|
+
# @example Get the transaction number.
|
521
|
+
# specifiable.txn_num
|
522
|
+
#
|
523
|
+
# @return [ Integer ] The transaction number.
|
524
|
+
#
|
525
|
+
# @since 2.5.0
|
526
|
+
def txn_num
|
527
|
+
@spec[:txn_num]
|
528
|
+
end
|
517
529
|
end
|
518
530
|
end
|
519
531
|
end
|
@@ -22,23 +22,54 @@ module Mongo
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
ZERO_TIMESTAMP = BSON::Timestamp.new(0,0)
|
26
|
+
|
25
27
|
READ_PREFERENCE = '$readPreference'.freeze
|
26
28
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
29
|
+
def apply_causal_consistency!(selector, server); end
|
30
|
+
|
31
|
+
def apply_cluster_time!(selector, server)
|
32
|
+
if !server.standalone?
|
33
|
+
cluster_time = [ server.cluster_time, (session && session.cluster_time) ].max_by do |doc|
|
34
|
+
(doc && doc[Cluster::CLUSTER_TIME]) || ZERO_TIMESTAMP
|
35
|
+
end
|
36
|
+
|
37
|
+
if cluster_time && (cluster_time[Cluster::CLUSTER_TIME] > ZERO_TIMESTAMP)
|
38
|
+
selector[CLUSTER_TIME] = cluster_time
|
39
|
+
end
|
30
40
|
end
|
31
41
|
end
|
32
42
|
|
43
|
+
def apply_session_id!(selector)
|
44
|
+
session.add_id!(selector) if session && !unacknowledged_write?
|
45
|
+
end
|
46
|
+
|
33
47
|
def unacknowledged_write?
|
34
48
|
write_concern && write_concern.get_last_error.nil?
|
35
49
|
end
|
36
50
|
|
51
|
+
def update_selector_for_session!(selector, server)
|
52
|
+
# the driver MUST ignore any implicit session if at the point it is sending a command
|
53
|
+
# to a specific server it turns out that that particular server doesn't support sessions after all
|
54
|
+
if server.features.sessions_enabled?
|
55
|
+
apply_cluster_time!(selector, server)
|
56
|
+
selector[:txnNumber] = BSON::Int64.new(txn_num) if txn_num
|
57
|
+
if session
|
58
|
+
apply_session_id!(selector)
|
59
|
+
apply_causal_consistency!(selector, server)
|
60
|
+
end
|
61
|
+
elsif session && !session.send(:implicit_session?)
|
62
|
+
apply_cluster_time!(selector, server)
|
63
|
+
apply_session_id!(selector)
|
64
|
+
apply_causal_consistency!(selector, server)
|
65
|
+
selector[:txnNumber] = BSON::Int64.new(txn_num) if txn_num
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
37
69
|
def command_op_msg(server, selector, options)
|
38
|
-
|
70
|
+
update_selector_for_session!(selector, server)
|
39
71
|
selector[Protocol::Msg::DATABASE_IDENTIFIER] = db_name
|
40
72
|
selector[READ_PREFERENCE] = read.to_doc if read
|
41
|
-
session.add_id!(selector) if session
|
42
73
|
flags = unacknowledged_write? ? [:more_to_come] : [:none]
|
43
74
|
Protocol::Msg.new(flags, options, selector)
|
44
75
|
end
|
@@ -19,9 +19,4 @@ require 'mongo/operation/write/bulk'
|
|
19
19
|
require 'mongo/operation/write/delete'
|
20
20
|
require 'mongo/operation/write/insert'
|
21
21
|
require 'mongo/operation/write/update'
|
22
|
-
require 'mongo/operation/write/create_index'
|
23
|
-
require 'mongo/operation/write/drop_index'
|
24
|
-
require 'mongo/operation/write/create_user'
|
25
|
-
require 'mongo/operation/write/update_user'
|
26
|
-
require 'mongo/operation/write/remove_user'
|
27
22
|
require 'mongo/operation/write/command'
|
@@ -35,14 +35,10 @@ module Mongo
|
|
35
35
|
#
|
36
36
|
# @since 2.0.0
|
37
37
|
def execute(server)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
result
|
43
|
-
else
|
44
|
-
execute_message(server)
|
45
|
-
end
|
38
|
+
result = execute_write_command(server)
|
39
|
+
server.update_cluster_time(result)
|
40
|
+
session.process(result) if session
|
41
|
+
result
|
46
42
|
end
|
47
43
|
|
48
44
|
private
|