mongo 2.10.5 → 2.11.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/lib/mongo.rb +2 -0
  6. data/lib/mongo/address.rb +4 -0
  7. data/lib/mongo/address/validator.rb +99 -0
  8. data/lib/mongo/auth.rb +7 -2
  9. data/lib/mongo/auth/user.rb +1 -7
  10. data/lib/mongo/background_thread.rb +135 -0
  11. data/lib/mongo/bulk_write/transformable.rb +3 -3
  12. data/lib/mongo/client.rb +74 -16
  13. data/lib/mongo/cluster.rb +193 -41
  14. data/lib/mongo/cluster/periodic_executor.rb +31 -43
  15. data/lib/mongo/cluster/sdam_flow.rb +26 -3
  16. data/lib/mongo/cluster/srv_monitor.rb +127 -0
  17. data/lib/mongo/collection/view/readable.rb +3 -5
  18. data/lib/mongo/collection/view/writable.rb +3 -3
  19. data/lib/mongo/cursor/builder/get_more_command.rb +1 -4
  20. data/lib/mongo/cursor/builder/kill_cursors_command.rb +5 -23
  21. data/lib/mongo/cursor/builder/op_get_more.rb +2 -2
  22. data/lib/mongo/cursor/builder/op_kill_cursors.rb +5 -24
  23. data/lib/mongo/error.rb +1 -0
  24. data/lib/mongo/error/auth_error.rb +1 -1
  25. data/lib/mongo/error/connection_check_out_timeout.rb +7 -8
  26. data/lib/mongo/error/invalid_address.rb +24 -0
  27. data/lib/mongo/error/notable.rb +2 -2
  28. data/lib/mongo/error/operation_failure.rb +3 -3
  29. data/lib/mongo/error/pool_closed_error.rb +11 -4
  30. data/lib/mongo/event.rb +1 -1
  31. data/lib/mongo/grid/file.rb +0 -5
  32. data/lib/mongo/grid/file/chunk.rb +0 -2
  33. data/lib/mongo/grid/fs_bucket.rb +13 -15
  34. data/lib/mongo/grid/stream/write.rb +3 -9
  35. data/lib/mongo/loggable.rb +5 -1
  36. data/lib/mongo/monitoring.rb +1 -0
  37. data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +7 -0
  38. data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +11 -3
  39. data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +11 -3
  40. data/lib/mongo/monitoring/event/cmap/pool_closed.rb +11 -3
  41. data/lib/mongo/monitoring/event/cmap/pool_created.rb +12 -3
  42. data/lib/mongo/monitoring/unified_sdam_log_subscriber.rb +62 -0
  43. data/lib/mongo/operation/shared/executable.rb +5 -10
  44. data/lib/mongo/operation/shared/sessions_supported.rb +1 -5
  45. data/lib/mongo/protocol/get_more.rb +1 -2
  46. data/lib/mongo/protocol/kill_cursors.rb +13 -6
  47. data/lib/mongo/protocol/serializers.rb +4 -20
  48. data/lib/mongo/retryable.rb +9 -34
  49. data/lib/mongo/semaphore.rb +1 -1
  50. data/lib/mongo/server.rb +113 -42
  51. data/lib/mongo/server/connection.rb +12 -5
  52. data/lib/mongo/server/connection_pool.rb +250 -40
  53. data/lib/mongo/server/connection_pool/populator.rb +58 -0
  54. data/lib/mongo/server/description.rb +9 -2
  55. data/lib/mongo/server/monitor.rb +68 -93
  56. data/lib/mongo/server/monitor/connection.rb +2 -0
  57. data/lib/mongo/server_selector/selectable.rb +13 -5
  58. data/lib/mongo/session.rb +0 -13
  59. data/lib/mongo/srv.rb +17 -0
  60. data/lib/mongo/srv/monitor.rb +96 -0
  61. data/lib/mongo/srv/resolver.rb +130 -0
  62. data/lib/mongo/srv/result.rb +126 -0
  63. data/lib/mongo/srv/warning_result.rb +35 -0
  64. data/lib/mongo/uri.rb +45 -55
  65. data/lib/mongo/uri/srv_protocol.rb +89 -42
  66. data/lib/mongo/version.rb +1 -1
  67. data/mongo.gemspec +3 -4
  68. data/spec/README.md +6 -1
  69. data/spec/enterprise_auth/kerberos_spec.rb +7 -6
  70. data/spec/integration/change_stream_examples_spec.rb +0 -4
  71. data/spec/integration/client_construction_spec.rb +14 -2
  72. data/spec/integration/connect_single_rs_name_spec.rb +2 -2
  73. data/spec/integration/connection_pool_populator_spec.rb +296 -0
  74. data/spec/integration/connection_spec.rb +31 -22
  75. data/spec/integration/cursor_reaping_spec.rb +1 -2
  76. data/spec/integration/docs_examples_spec.rb +0 -4
  77. data/spec/integration/heartbeat_events_spec.rb +17 -15
  78. data/spec/integration/reconnect_spec.rb +144 -1
  79. data/spec/integration/retryable_writes_errors_spec.rb +0 -4
  80. data/spec/integration/retryable_writes_spec.rb +36 -36
  81. data/spec/integration/sdam_error_handling_spec.rb +31 -25
  82. data/spec/integration/sdam_events_spec.rb +2 -6
  83. data/spec/integration/server_monitor_spec.rb +28 -0
  84. data/spec/integration/server_selector_spec.rb +7 -5
  85. data/spec/integration/srv_monitoring_spec.rb +360 -0
  86. data/spec/integration/step_down_spec.rb +4 -6
  87. data/spec/lite_spec_helper.rb +22 -0
  88. data/spec/mongo/address/validator_spec.rb +51 -0
  89. data/spec/mongo/auth/cr_spec.rb +1 -29
  90. data/spec/mongo/auth/ldap_spec.rb +1 -29
  91. data/spec/mongo/auth/scram/conversation_spec.rb +0 -2
  92. data/spec/mongo/auth/scram/negotiation_spec.rb +1 -1
  93. data/spec/mongo/auth/scram_spec.rb +1 -29
  94. data/spec/mongo/auth/user/view_spec.rb +1 -36
  95. data/spec/mongo/auth/user_spec.rb +0 -12
  96. data/spec/mongo/auth/x509_spec.rb +1 -29
  97. data/spec/mongo/bulk_write_spec.rb +2 -2
  98. data/spec/mongo/client_construction_spec.rb +56 -15
  99. data/spec/mongo/client_spec.rb +31 -27
  100. data/spec/mongo/cluster/periodic_executor_spec.rb +16 -0
  101. data/spec/mongo/cluster/srv_monitor_spec.rb +214 -0
  102. data/spec/mongo/cluster/topology/replica_set_spec.rb +16 -11
  103. data/spec/mongo/cluster/topology/sharded_spec.rb +12 -9
  104. data/spec/mongo/cluster/topology/single_spec.rb +20 -11
  105. data/spec/mongo/cluster_spec.rb +45 -29
  106. data/spec/mongo/collection/view/map_reduce_spec.rb +14 -9
  107. data/spec/mongo/collection/view/readable_spec.rb +0 -16
  108. data/spec/mongo/collection_spec.rb +0 -44
  109. data/spec/mongo/cursor/builder/get_more_command_spec.rb +2 -4
  110. data/spec/mongo/cursor/builder/op_get_more_spec.rb +2 -4
  111. data/spec/mongo/cursor_spec.rb +27 -7
  112. data/spec/mongo/monitoring/event/cmap/connection_checked_in_spec.rb +10 -3
  113. data/spec/mongo/monitoring/event/cmap/connection_checked_out_spec.rb +10 -3
  114. data/spec/mongo/monitoring/event/cmap/pool_closed_spec.rb +10 -3
  115. data/spec/mongo/monitoring/event/cmap/pool_created_spec.rb +10 -3
  116. data/spec/mongo/operation/delete/op_msg_spec.rb +17 -8
  117. data/spec/mongo/operation/insert/op_msg_spec.rb +50 -35
  118. data/spec/mongo/operation/update/op_msg_spec.rb +14 -7
  119. data/spec/mongo/retryable_spec.rb +52 -31
  120. data/spec/mongo/server/app_metadata_spec.rb +0 -8
  121. data/spec/mongo/server/connection_auth_spec.rb +5 -2
  122. data/spec/mongo/server/connection_pool/populator_spec.rb +101 -0
  123. data/spec/mongo/server/connection_pool_spec.rb +256 -107
  124. data/spec/mongo/server/connection_spec.rb +22 -33
  125. data/spec/mongo/server/description_spec.rb +42 -4
  126. data/spec/mongo/server/monitor/connection_spec.rb +22 -11
  127. data/spec/mongo/server/monitor_spec.rb +66 -107
  128. data/spec/mongo/server_spec.rb +82 -60
  129. data/spec/mongo/session/session_pool_spec.rb +1 -5
  130. data/spec/mongo/session_spec.rb +0 -4
  131. data/spec/mongo/socket/ssl_spec.rb +2 -2
  132. data/spec/mongo/srv/monitor_spec.rb +211 -0
  133. data/spec/mongo/srv/result_spec.rb +54 -0
  134. data/spec/mongo/uri/srv_protocol_spec.rb +30 -15
  135. data/spec/mongo/uri_spec.rb +125 -4
  136. data/spec/spec_helper.rb +6 -0
  137. data/spec/spec_tests/auth_spec.rb +39 -0
  138. data/spec/spec_tests/cmap_spec.rb +55 -8
  139. data/spec/spec_tests/connection_string_spec.rb +6 -31
  140. data/spec/spec_tests/data/auth/connection-string.yml +297 -0
  141. data/spec/spec_tests/data/cmap/pool-checkout-error-closed.yml +4 -1
  142. data/spec/spec_tests/data/cmap/pool-create-with-options.yml +1 -0
  143. data/spec/spec_tests/data/command_monitoring/insertMany.yml +1 -1
  144. data/spec/spec_tests/data/connection_string/invalid-uris.yml +20 -0
  145. data/spec/spec_tests/data/connection_string/valid-auth.yml +16 -0
  146. data/spec/spec_tests/data/connection_string/valid-warnings.yml +26 -30
  147. data/spec/spec_tests/data/transactions/abort.yml +3 -3
  148. data/spec/spec_tests/data/transactions/error-labels.yml +3 -3
  149. data/spec/spec_tests/data/transactions_api/callback-retry.yml +3 -3
  150. data/spec/spec_tests/data/uri_options/auth-options.yml +1 -1
  151. data/spec/spec_tests/max_staleness_spec.rb +7 -2
  152. data/spec/spec_tests/retryable_reads_spec.rb +0 -31
  153. data/spec/spec_tests/sdam_monitoring_spec.rb +12 -12
  154. data/spec/spec_tests/sdam_spec.rb +4 -7
  155. data/spec/spec_tests/server_selection_spec.rb +6 -2
  156. data/spec/spec_tests/transactions_spec.rb +0 -2
  157. data/spec/spec_tests/uri_options_spec.rb +4 -2
  158. data/spec/stress/connection_pool_stress_spec.rb +203 -0
  159. data/spec/stress/connection_pool_timing_spec.rb +181 -0
  160. data/spec/support/auth.rb +113 -0
  161. data/spec/support/background_thread_registry.rb +63 -0
  162. data/spec/support/client_registry.rb +11 -2
  163. data/spec/support/cluster_config.rb +65 -46
  164. data/spec/support/cluster_tools.rb +2 -2
  165. data/spec/support/cmap.rb +13 -14
  166. data/spec/support/cmap/verifier.rb +4 -5
  167. data/spec/support/command_monitoring.rb +0 -5
  168. data/spec/support/common_shortcuts.rb +101 -1
  169. data/spec/support/constraints.rb +25 -0
  170. data/spec/support/dns.rb +13 -0
  171. data/spec/support/event_subscriber.rb +0 -7
  172. data/spec/support/json_ext_formatter.rb +5 -1
  173. data/spec/support/lite_constraints.rb +22 -6
  174. data/spec/support/local_resource_registry.rb +34 -0
  175. data/spec/support/sdam_monitoring.rb +115 -0
  176. data/spec/support/spec_config.rb +20 -6
  177. data/spec/support/spec_setup.rb +2 -2
  178. data/spec/support/transactions.rb +1 -1
  179. data/spec/support/transactions/test.rb +1 -1
  180. data/spec/support/utils.rb +1 -16
  181. metadata +685 -659
  182. metadata.gz.sig +0 -0
  183. data/lib/mongo/event/description_changed.rb +0 -52
  184. data/spec/integration/bson_symbol_spec.rb +0 -34
  185. data/spec/integration/crud_spec.rb +0 -45
  186. data/spec/integration/get_more_spec.rb +0 -32
  187. data/spec/integration/grid_fs_bucket_spec.rb +0 -48
  188. data/spec/integration/retryable_errors_spec.rb +0 -265
  189. data/spec/integration/size_limit_spec.rb~12e1e9c4f... RUBY-2242 Fix zlib compression (#2021) +0 -98
  190. data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +0 -56
  191. data/spec/runners/sdam/verifier.rb +0 -88
@@ -1,98 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'BSON & command size limits' do
4
- let(:max_document_size) { 16*1024*1024 }
5
-
6
- before do
7
- authorized_collection.delete_many
8
- end
9
-
10
- # This test uses a large document that is significantly smaller than the
11
- # size limit. It is a basic sanity check.
12
- it 'allows user-provided documents to be 15MiB' do
13
- document = { key: 'a' * 15*1024*1024, _id: 'foo' }
14
-
15
- authorized_collection.insert_one(document)
16
- end
17
-
18
- # This test uses a large document that is significantly larger than the
19
- # size limit. It is a basic sanity check.
20
- it 'fails single write of oversized documents' do
21
- document = { key: 'a' * 17*1024*1024, _id: 'foo' }
22
-
23
- lambda do
24
- authorized_collection.insert_one(document)
25
- end.should raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
26
- end
27
-
28
- # This test checks our bulk write splitting when documents are not close
29
- # to the limit, but where splitting is definitely required.
30
- it 'allows split bulk write of medium sized documents' do
31
- # 8 documents of 4 MiB each = 32 MiB total data, should be split over
32
- # either 2 or 3 bulk writes depending on how well the driver splits
33
- documents = []
34
- 1.upto(8) do |index|
35
- documents << { key: 'a' * 4*1024*1024, _id: "in#{index}" }
36
- end
37
-
38
- authorized_collection.insert_many(documents)
39
- authorized_collection.count_documents({}).should == 8
40
- end
41
-
42
- # This test ensures that document which are too big definitely fail insertion.
43
- it 'fails bulk write of oversized documents' do
44
- documents = []
45
- 1.upto(3) do |index|
46
- documents << { key: 'a' * 17*1024*1024, _id: "in#{index}" }
47
- end
48
-
49
- lambda do
50
- authorized_collection.insert_many(documents)
51
- end.should raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
52
- authorized_collection.count_documents({}).should == 0
53
- end
54
-
55
- it 'allows user-provided documents to be exactly 16MiB' do
56
- # The document must contain the _id field, otherwise the server will
57
- # add it which will increase the size of the document as persisted by
58
- # the server.
59
- document = { key: 'a' * (max_document_size - 28), _id: 'foo' }
60
- expect(document.to_bson.length).to eq(max_document_size)
61
-
62
- authorized_collection.insert_one(document)
63
- end
64
-
65
- it 'fails on the server when a document larger than 16MiB is inserted' do
66
- document = { key: 'a' * (max_document_size - 27), _id: 'foo' }
67
- expect(document.to_bson.length).to eq(max_document_size+1)
68
-
69
- lambda do
70
- authorized_collection.insert_one(document)
71
- end.should raise_error(Mongo::Error::OperationFailure, /object to insert too large/)
72
- end
73
-
74
- it 'fails in the driver when a document larger than 16MiB+16KiB is inserted' do
75
- document = { key: 'a' * (max_document_size - 27 + 16*1024), _id: 'foo' }
76
- expect(document.to_bson.length).to eq(max_document_size+16*1024+1)
77
-
78
- lambda do
79
- authorized_collection.insert_one(document)
80
- end.should raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
81
- end
82
-
83
- it 'allows bulk writes of multiple documents of exactly 16 MiB each' do
84
- if SpecConfig.instance.compressors
85
- pending "RUBY-2234"
86
- end
87
-
88
- documents = []
89
- 1.upto(3) do |index|
90
- document = { key: 'a' * (max_document_size - 28), _id: "in#{index}" }
91
- expect(document.to_bson.length).to eq(max_document_size)
92
- documents << document
93
- end
94
-
95
- authorized_collection.insert_many(documents)
96
- authorized_collection.count_documents({}).should == 3
97
- end
98
- end
@@ -1,56 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mongo::Cursor::Builder::OpKillCursors do
4
-
5
- let(:reply) do
6
- Mongo::Protocol::Reply.allocate.tap do |reply|
7
- allow(reply).to receive(:cursor_id).and_return(8000)
8
- end
9
- end
10
-
11
- let(:result) do
12
- Mongo::Operation::Result.new(reply)
13
- end
14
-
15
- let(:view) do
16
- Mongo::Collection::View.new(
17
- authorized_collection,
18
- {},
19
- tailable: true,
20
- max_time_ms: 100
21
- )
22
- end
23
-
24
- let(:cursor) do
25
- Mongo::Cursor.new(view, result, authorized_primary)
26
- end
27
-
28
- let(:builder) do
29
- described_class.new(cursor)
30
- end
31
-
32
- describe '#specification' do
33
-
34
- let(:specification) do
35
- builder.specification
36
- end
37
-
38
- it 'includes the cursor ids' do
39
- expect(specification[:cursor_ids]).to eq([BSON::Int64.new(8000)])
40
- end
41
-
42
- it 'includes the database name' do
43
- expect(specification[:db_name]).to eq(SpecConfig.instance.test_db)
44
- end
45
-
46
- it 'includes the collection name' do
47
- expect(specification[:coll_name]).to eq(TEST_COLL)
48
- end
49
- end
50
-
51
- describe '.get_cursors_list' do
52
- it 'returns integer cursor ids' do
53
- expect(described_class.get_cursors_list(builder.specification)).to eq([8000])
54
- end
55
- end
56
- end
@@ -1,88 +0,0 @@
1
- module Sdam
2
- class Verifier
3
- include RSpec::Matchers
4
-
5
- def verify_sdam_event(expected_events, actual_events, i)
6
- expect(expected_events.length).to be > i
7
- expect(actual_events.length).to be > i
8
-
9
- expected_event = expected_events[i]
10
- actual_event = actual_events[i]
11
-
12
- actual_event_name = Utils.underscore(actual_event.class.name.sub(/.*::/, ''))
13
- actual_event_name = actual_event_name.to_s.sub('topology_changed', 'topology_description_changed') + '_event'
14
- expect(actual_event_name).to eq(expected_event.name)
15
-
16
- send("verify_#{expected_event.name}", expected_event, actual_event)
17
- end
18
-
19
- def verify_topology_opening_event(expected, actual)
20
- expect(actual.topology).not_to be nil
21
- end
22
-
23
- def verify_topology_description_changed_event(expected, actual)
24
- verify_topology_matches(expected.data['previousDescription'], actual.previous_topology)
25
- verify_topology_matches(expected.data['newDescription'], actual.new_topology)
26
- end
27
-
28
- def verify_topology_matches(expected, actual)
29
- expected_type = ::Mongo::Cluster::Topology.const_get(expected['topologyType'])
30
- expect(actual).to be_a(expected_type)
31
-
32
- expect(actual.replica_set_name).to eq(expected['setName'])
33
-
34
- expected['servers'].each do |server|
35
- desc = actual.server_descriptions[server['address'].to_s]
36
- expect(desc).not_to be nil
37
- verify_description_matches(server, desc)
38
- end
39
-
40
- actual.server_descriptions.keys.each do |address_str|
41
- expect(
42
- expected['servers'].any? { |server| server['address'] == address_str }
43
- ).to be true
44
- end
45
- end
46
-
47
- def verify_server_opening_event(expected, actual)
48
- expect(actual.address.to_s).to eq(expected.data['address'])
49
- end
50
-
51
- def verify_server_description_changed_event(expected, actual)
52
- verify_description_matches(expected.data['previousDescription'], actual.previous_description)
53
- verify_description_matches(expected.data['newDescription'], actual.new_description)
54
- end
55
-
56
- def verify_description_matches(expected, actual)
57
- case expected['type']
58
- when 'Standalone'
59
- expect(actual).to be_standalone
60
- when 'RSPrimary'
61
- expect(actual).to be_primary
62
- when 'RSSecondary'
63
- expect(actual).to be_secondary
64
- when 'RSArbiter'
65
- expect(actual).to be_arbiter
66
- when 'Mongos'
67
- expect(actual).to be_mongos
68
- when 'Unknown', 'PossiblePrimary'
69
- expect(actual).to be_unknown
70
- when 'RSGhost'
71
- expect(actual).to be_ghost
72
- when 'RSOther'
73
- expect(actual).to be_other
74
- end
75
-
76
- expect(actual.address.to_s).to eq(expected['address'])
77
- expect(actual.arbiters).to eq(expected['arbiters'])
78
- expect(actual.hosts).to eq(expected['hosts'])
79
- expect(actual.passives).to eq(expected['passives'])
80
- expect(actual.primary_host).to eq(expected['primary'])
81
- expect(actual.replica_set_name).to eq(expected['setName'])
82
- end
83
-
84
- def verify_server_closed_event(expected, actual)
85
- expect(actual.address.to_s).to eq(expected.data['address'])
86
- end
87
- end
88
- end