mongo 2.3.1 → 2.4.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -3
  4. data/lib/mongo/bulk_write.rb +8 -7
  5. data/lib/mongo/bulk_write/combineable.rb +4 -0
  6. data/lib/mongo/bulk_write/transformable.rb +17 -5
  7. data/lib/mongo/bulk_write/validatable.rb +1 -0
  8. data/lib/mongo/client.rb +3 -0
  9. data/lib/mongo/cluster.rb +8 -0
  10. data/lib/mongo/cluster/app_metadata.rb +135 -0
  11. data/lib/mongo/collection.rb +42 -10
  12. data/lib/mongo/collection/view.rb +15 -1
  13. data/lib/mongo/collection/view/aggregation.rb +5 -0
  14. data/lib/mongo/collection/view/builder/aggregation.rb +13 -3
  15. data/lib/mongo/collection/view/builder/find_command.rb +7 -21
  16. data/lib/mongo/collection/view/builder/map_reduce.rb +22 -5
  17. data/lib/mongo/collection/view/iterable.rb +1 -0
  18. data/lib/mongo/collection/view/map_reduce.rb +5 -0
  19. data/lib/mongo/collection/view/readable.rb +35 -14
  20. data/lib/mongo/collection/view/writable.rb +54 -23
  21. data/lib/mongo/cursor/builder/get_more_command.rb +2 -3
  22. data/lib/mongo/database.rb +10 -2
  23. data/lib/mongo/error.rb +2 -0
  24. data/lib/mongo/error/invalid_application_name.rb +38 -0
  25. data/lib/mongo/error/invalid_server_preference.rb +24 -3
  26. data/lib/mongo/error/unsupported_collation.rb +51 -0
  27. data/lib/mongo/index/view.rb +28 -15
  28. data/lib/mongo/operation.rb +6 -0
  29. data/lib/mongo/operation/commands.rb +3 -0
  30. data/lib/mongo/operation/commands/aggregate.rb +10 -10
  31. data/lib/mongo/operation/commands/create.rb +45 -0
  32. data/lib/mongo/operation/commands/drop.rb +45 -0
  33. data/lib/mongo/operation/commands/drop_database.rb +45 -0
  34. data/lib/mongo/operation/commands/map_reduce.rb +12 -1
  35. data/lib/mongo/operation/commands/parallel_scan.rb +1 -0
  36. data/lib/mongo/operation/read_preference.rb +9 -9
  37. data/lib/mongo/operation/specifiable.rb +34 -0
  38. data/lib/mongo/operation/takes_write_concern.rb +35 -0
  39. data/lib/mongo/operation/write/bulk/bulkable.rb +1 -1
  40. data/lib/mongo/operation/write/command/create_index.rb +6 -0
  41. data/lib/mongo/operation/write/command/drop_index.rb +6 -0
  42. data/lib/mongo/operation/write/command/insert.rb +1 -1
  43. data/lib/mongo/operation/write/command/update.rb +1 -0
  44. data/lib/mongo/operation/write/command/writable.rb +2 -2
  45. data/lib/mongo/operation/write/create_index.rb +2 -2
  46. data/lib/mongo/operation/write/create_user.rb +1 -1
  47. data/lib/mongo/operation/write/delete.rb +5 -1
  48. data/lib/mongo/operation/write/gle.rb +1 -1
  49. data/lib/mongo/operation/write/insert.rb +2 -2
  50. data/lib/mongo/operation/write/remove_user.rb +1 -1
  51. data/lib/mongo/operation/write/update.rb +5 -1
  52. data/lib/mongo/operation/write/update_user.rb +1 -1
  53. data/lib/mongo/operation/write/write_command_enabled.rb +10 -2
  54. data/lib/mongo/protocol/insert.rb +1 -2
  55. data/lib/mongo/protocol/query.rb +3 -7
  56. data/lib/mongo/server.rb +8 -3
  57. data/lib/mongo/server/connection.rb +17 -11
  58. data/lib/mongo/server/description.rb +22 -0
  59. data/lib/mongo/server/description/features.rb +2 -0
  60. data/lib/mongo/server/monitor.rb +5 -0
  61. data/lib/mongo/server/monitor/connection.rb +11 -0
  62. data/lib/mongo/server_selector/nearest.rb +9 -6
  63. data/lib/mongo/server_selector/primary.rb +4 -0
  64. data/lib/mongo/server_selector/primary_preferred.rb +7 -1
  65. data/lib/mongo/server_selector/secondary.rb +5 -0
  66. data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
  67. data/lib/mongo/server_selector/selectable.rb +57 -10
  68. data/lib/mongo/socket/ssl.rb +1 -0
  69. data/lib/mongo/uri.rb +4 -0
  70. data/lib/mongo/version.rb +1 -1
  71. data/lib/mongo/write_concern.rb +1 -0
  72. data/mongo.gemspec +1 -1
  73. data/spec/mongo/auth/cr_spec.rb +7 -1
  74. data/spec/mongo/auth/ldap_spec.rb +7 -1
  75. data/spec/mongo/auth/scram_spec.rb +7 -1
  76. data/spec/mongo/auth/x509_spec.rb +7 -1
  77. data/spec/mongo/bulk_write_spec.rb +598 -5
  78. data/spec/mongo/client_spec.rb +47 -1
  79. data/spec/mongo/cluster/app_metadata_spec.rb +104 -0
  80. data/spec/mongo/cluster/topology/replica_set_spec.rb +14 -8
  81. data/spec/mongo/cluster/topology/sharded_spec.rb +9 -3
  82. data/spec/mongo/cluster/topology/single_spec.rb +10 -4
  83. data/spec/mongo/cluster_spec.rb +29 -0
  84. data/spec/mongo/collection/view/aggregation_spec.rb +139 -0
  85. data/spec/mongo/collection/view/builder/find_command_spec.rb +6 -243
  86. data/spec/mongo/collection/view/map_reduce_spec.rb +104 -0
  87. data/spec/mongo/collection/view/readable_spec.rb +83 -0
  88. data/spec/mongo/collection/view/writable_spec.rb +447 -1
  89. data/spec/mongo/collection/view_spec.rb +57 -0
  90. data/spec/mongo/collection_spec.rb +926 -101
  91. data/spec/mongo/crud_spec.rb +4 -5
  92. data/spec/mongo/database_spec.rb +99 -1
  93. data/spec/mongo/index/view_spec.rb +360 -31
  94. data/spec/mongo/max_staleness_spec.rb +108 -0
  95. data/spec/mongo/operation/read_preference_spec.rb +8 -8
  96. data/spec/mongo/operation/write/command/delete_spec.rb +1 -1
  97. data/spec/mongo/operation/write/command/insert_spec.rb +1 -1
  98. data/spec/mongo/operation/write/command/update_spec.rb +1 -1
  99. data/spec/mongo/server/connection_pool_spec.rb +3 -1
  100. data/spec/mongo/server/connection_spec.rb +17 -7
  101. data/spec/mongo/server/description/features_spec.rb +50 -0
  102. data/spec/mongo/server/description_spec.rb +9 -3
  103. data/spec/mongo/server_selection_spec.rb +5 -3
  104. data/spec/mongo/server_selector/nearest_spec.rb +73 -0
  105. data/spec/mongo/server_selector/primary_preferred_spec.rb +73 -0
  106. data/spec/mongo/server_selector/primary_spec.rb +36 -0
  107. data/spec/mongo/server_selector/secondary_preferred_spec.rb +73 -0
  108. data/spec/mongo/server_selector/secondary_spec.rb +73 -0
  109. data/spec/mongo/server_selector_spec.rb +53 -0
  110. data/spec/mongo/server_spec.rb +3 -1
  111. data/spec/mongo/uri_spec.rb +54 -0
  112. data/spec/mongo/write_concern_spec.rb +18 -0
  113. data/spec/spec_helper.rb +10 -0
  114. data/spec/support/authorization.rb +8 -1
  115. data/spec/support/crud.rb +15 -0
  116. data/spec/support/crud/read.rb +27 -19
  117. data/spec/support/crud/write.rb +28 -3
  118. data/spec/support/crud_tests/read/aggregate.yml +15 -3
  119. data/spec/support/crud_tests/read/count.yml +14 -3
  120. data/spec/support/crud_tests/read/distinct.yml +13 -1
  121. data/spec/support/crud_tests/read/find.yml +12 -2
  122. data/spec/support/crud_tests/write/deleteMany.yml +22 -1
  123. data/spec/support/crud_tests/write/deleteOne.yml +20 -1
  124. data/spec/support/crud_tests/write/findOneAndDelete.yml +27 -2
  125. data/spec/support/crud_tests/write/findOneAndReplace.yml +43 -14
  126. data/spec/support/crud_tests/write/findOneAndUpdate.yml +50 -8
  127. data/spec/support/crud_tests/write/replaceOne.yml +34 -10
  128. data/spec/support/crud_tests/write/updateMany.yml +42 -11
  129. data/spec/support/crud_tests/write/updateOne.yml +32 -7
  130. data/spec/support/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.yml +26 -0
  131. data/spec/support/max_staleness/ReplicaSetNoPrimary/Incompatible.yml +25 -0
  132. data/spec/support/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.yml +33 -0
  133. data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest.yml +33 -0
  134. data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest2.yml +33 -0
  135. data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.yml +27 -0
  136. data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.yml +36 -0
  137. data/spec/support/max_staleness/ReplicaSetNoPrimary/Secondary.yml +51 -0
  138. data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.yml +26 -0
  139. data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.yml +51 -0
  140. data/spec/support/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.yml +26 -0
  141. data/spec/support/max_staleness/ReplicaSetWithPrimary/Incompatible.yml +25 -0
  142. data/spec/support/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.yml +35 -0
  143. data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.yml +25 -0
  144. data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.yml +23 -0
  145. data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest.yml +33 -0
  146. data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest2.yml +33 -0
  147. data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest_tags.yml +36 -0
  148. data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.yml +27 -0
  149. data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.yml +27 -0
  150. data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.yml +26 -0
  151. data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.yml +59 -0
  152. data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.yml +43 -0
  153. data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags.yml +59 -0
  154. data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.yml +43 -0
  155. data/spec/support/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness.yml +29 -0
  156. data/spec/support/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness2.yml +29 -0
  157. data/spec/support/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.yml +27 -0
  158. data/spec/support/max_staleness/Sharded/Incompatible.yml +25 -0
  159. data/spec/support/max_staleness/Sharded/SmallMaxStaleness.yml +20 -0
  160. data/spec/support/max_staleness/Single/Incompatible.yml +18 -0
  161. data/spec/support/max_staleness/Single/SmallMaxStaleness.yml +20 -0
  162. data/spec/support/server_selection.rb +25 -0
  163. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_multiple.yml +27 -0
  164. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_multi_tags.yml +31 -0
  165. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_multi_tags2.yml +31 -0
  166. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_multiple.yml +34 -0
  167. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_tags.yml +28 -0
  168. data/spec/support/shared/server_selector.rb +4 -3
  169. metadata +91 -6
  170. metadata.gz.sig +0 -0
@@ -0,0 +1,43 @@
1
+ # maxStalenessMS is applied before tag sets. With tag sets
2
+ # [{data_center: nyc}, {data_center: tokyo}], if the only secondary in NYC is
3
+ # stale then use Tokyo.
4
+ ---
5
+ heartbeatFrequencyMS: 25000 # 25 seconds.
6
+ topology_description:
7
+ type: ReplicaSetWithPrimary
8
+ servers:
9
+ - &1
10
+ address: a:27017
11
+ type: RSPrimary
12
+ avg_rtt_ms: 5
13
+ lastUpdateTime: 0
14
+ lastWrite: {lastWriteDate: {$numberLong: "25002"}}
15
+ maxWireVersion: 5
16
+ - &2
17
+ address: b:27017
18
+ type: RSSecondary
19
+ avg_rtt_ms: 5
20
+ lastUpdateTime: 0
21
+ lastWrite: {lastWriteDate: {$numberLong: "2"}}
22
+ maxWireVersion: 5
23
+ tags:
24
+ data_center: tokyo
25
+ - &3
26
+ address: c:27017
27
+ type: RSSecondary
28
+ avg_rtt_ms: 5
29
+ lastUpdateTime: 0
30
+ lastWrite: {lastWriteDate: {$numberLong: "1"}} # Too stale.
31
+ maxWireVersion: 5
32
+ tags:
33
+ data_center: nyc
34
+ read_preference:
35
+ mode: SecondaryPreferred
36
+ maxStalenessMS: 50000
37
+ tag_sets:
38
+ - data_center: nyc
39
+ - data_center: tokyo
40
+ suitable_servers:
41
+ - *2
42
+ in_latency_window:
43
+ - *2
@@ -0,0 +1,59 @@
1
+ # Primary's lastWriteDate is used normally with SecondaryPreferred and tags.
2
+ ---
3
+ heartbeatFrequencyMS: 25000 # 25 seconds.
4
+ topology_description:
5
+ type: ReplicaSetWithPrimary
6
+ servers:
7
+ - &1
8
+ address: a:27017
9
+ type: RSPrimary
10
+ avg_rtt_ms: 5
11
+ lastUpdateTime: 0
12
+ maxWireVersion: 5
13
+ lastWrite: {lastWriteDate: {$numberLong: "25002"}}
14
+ - &2
15
+ address: b:27017
16
+ type: RSSecondary
17
+ avg_rtt_ms: 5
18
+ lastUpdateTime: 0
19
+ maxWireVersion: 5
20
+ lastWrite: {lastWriteDate: {$numberLong: "2"}} # 25 sec stale + 25 sec heartbeat <= 50 sec maxStaleness.
21
+ tags:
22
+ data_center: nyc
23
+ - &3
24
+ address: c:27017
25
+ type: RSSecondary
26
+ avg_rtt_ms: 50 # Too far.
27
+ lastUpdateTime: 1
28
+ maxWireVersion: 5
29
+ lastWrite: {lastWriteDate: {$numberLong: "1000001"}} # Not used in estimate since we have a primary.
30
+ tags:
31
+ data_center: nyc
32
+ - &4
33
+ address: d:27017
34
+ type: RSSecondary
35
+ avg_rtt_ms: 5
36
+ lastUpdateTime: 0
37
+ maxWireVersion: 5
38
+ lastWrite: {lastWriteDate: {$numberLong: "1"}} # Too stale.
39
+ tags:
40
+ data_center: nyc
41
+ - &5
42
+ address: e:27017
43
+ type: RSSecondary
44
+ avg_rtt_ms: 5
45
+ lastUpdateTime: 0
46
+ maxWireVersion: 5
47
+ lastWrite: {lastWriteDate: {$numberLong: "2"}}
48
+ tags:
49
+ data_center: tokyo # No match.
50
+ read_preference:
51
+ mode: Secondary
52
+ maxStalenessMS: 50000
53
+ tag_sets:
54
+ - data_center: nyc
55
+ suitable_servers:
56
+ - *2
57
+ - *3
58
+ in_latency_window:
59
+ - *2
@@ -0,0 +1,43 @@
1
+ # maxStalenessMS is applied before tag sets. With tag sets
2
+ # [{data_center: nyc}, {data_center: tokyo}], if the only secondary in NYC is
3
+ # stale then use Tokyo.
4
+ ---
5
+ heartbeatFrequencyMS: 25000 # 25 seconds.
6
+ topology_description:
7
+ type: ReplicaSetWithPrimary
8
+ servers:
9
+ - &1
10
+ address: a:27017
11
+ type: RSPrimary
12
+ avg_rtt_ms: 5
13
+ lastUpdateTime: 0
14
+ lastWrite: {lastWriteDate: {$numberLong: "25002"}}
15
+ maxWireVersion: 5
16
+ - &2
17
+ address: b:27017
18
+ type: RSSecondary
19
+ avg_rtt_ms: 5
20
+ lastUpdateTime: 0
21
+ lastWrite: {lastWriteDate: {$numberLong: "2"}}
22
+ maxWireVersion: 5
23
+ tags:
24
+ data_center: tokyo
25
+ - &3
26
+ address: c:27017
27
+ type: RSSecondary
28
+ avg_rtt_ms: 5
29
+ lastUpdateTime: 0
30
+ lastWrite: {lastWriteDate: {$numberLong: "1"}} # Too stale.
31
+ maxWireVersion: 5
32
+ tags:
33
+ data_center: nyc
34
+ read_preference:
35
+ mode: Secondary
36
+ maxStalenessMS: 50000
37
+ tag_sets:
38
+ - data_center: nyc
39
+ - data_center: tokyo
40
+ suitable_servers:
41
+ - *2
42
+ in_latency_window:
43
+ - *2
@@ -0,0 +1,29 @@
1
+ # Users can configure a shorter ``heartbeatFrequencyMS`` than the default to
2
+ # allow a smaller ``maxStalenessMS`` with replica sets.
3
+ ---
4
+ heartbeatFrequencyMS: 1000 # 1 second.
5
+ topology_description:
6
+ type: ReplicaSetWithPrimary
7
+ servers:
8
+ - &1
9
+ address: a:27017
10
+ type: RSPrimary
11
+ avg_rtt_ms: 50 # Too far.
12
+ lastUpdateTime: 0
13
+ maxWireVersion: 5
14
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
15
+ - &2
16
+ address: b:27017
17
+ type: RSSecondary
18
+ avg_rtt_ms: 5
19
+ lastUpdateTime: 0
20
+ maxWireVersion: 5
21
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
22
+ read_preference:
23
+ mode: Nearest
24
+ maxStalenessMS: 2000 # 2 seconds, permitted.
25
+ suitable_servers:
26
+ - *1
27
+ - *2
28
+ in_latency_window:
29
+ - *2
@@ -0,0 +1,29 @@
1
+ # Users can configure a shorter ``heartbeatFrequencyMS`` than the default to
2
+ # allow a smaller ``maxStalenessMS`` with replica sets.
3
+ ---
4
+ heartbeatFrequencyMS: 1000 # 1 second.
5
+ topology_description:
6
+ type: ReplicaSetWithPrimary
7
+ servers:
8
+ - &1
9
+ address: a:27017
10
+ type: RSPrimary
11
+ avg_rtt_ms: 5
12
+ lastUpdateTime: 0
13
+ maxWireVersion: 5
14
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
15
+ - &2
16
+ address: b:27017
17
+ type: RSSecondary
18
+ avg_rtt_ms: 50 # Too far.
19
+ lastUpdateTime: 0
20
+ maxWireVersion: 5
21
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
22
+ read_preference:
23
+ mode: Nearest
24
+ maxStalenessMS: 2000 # 2 seconds, permitted.
25
+ suitable_servers:
26
+ - *1
27
+ - *2
28
+ in_latency_window:
29
+ - *1
@@ -0,0 +1,27 @@
1
+ # A ``maxStalenessMS`` of zero or null MUST mean "no maximum".
2
+ ---
3
+ topology_description:
4
+ type: ReplicaSetWithPrimary
5
+ servers:
6
+ - &1
7
+ address: a:27017
8
+ type: RSPrimary
9
+ avg_rtt_ms: 50 # Too far.
10
+ lastUpdateTime: 0
11
+ maxWireVersion: 5
12
+ lastWrite: {lastWriteDate: {$numberLong: "1000001"}}
13
+ - &2
14
+ address: b:27017
15
+ type: RSSecondary
16
+ avg_rtt_ms: 5
17
+ lastUpdateTime: 0
18
+ maxWireVersion: 5
19
+ lastWrite: {lastWriteDate: {$numberLong: "1"}} # Very stale.
20
+ read_preference:
21
+ mode: Nearest
22
+ maxStalenessMS: 0 # Means "no max staleness".
23
+ suitable_servers: # Very stale server is fine.
24
+ - *1
25
+ - *2
26
+ in_latency_window:
27
+ - *2
@@ -0,0 +1,25 @@
1
+ # During server selection,
2
+ # clients (drivers or mongos) MUST raise an error if ``maxStalenessMS`` is not zero or null,
3
+ # and any server's ``maxWireVersion`` is less than 5 (`SERVER-23893`_).
4
+ ---
5
+ topology_description:
6
+ type: Sharded
7
+ servers:
8
+ - &1
9
+ address: a:27017
10
+ type: Mongos
11
+ avg_rtt_ms: 5
12
+ lastUpdateTime: 0
13
+ maxWireVersion: 5
14
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
15
+ - &2
16
+ address: b:27017
17
+ type: Mongos
18
+ avg_rtt_ms: 5
19
+ lastUpdateTime: 0
20
+ maxWireVersion: 4 # Incompatible.
21
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
22
+ read_preference:
23
+ mode: Nearest
24
+ maxStalenessMS: 120000
25
+ error: true
@@ -0,0 +1,20 @@
1
+ # Driver doesn't validate maxStalenessMS for mongos
2
+ ---
3
+ heartbeatFrequencyMS: 10000
4
+ topology_description:
5
+ type: Sharded
6
+ servers:
7
+ - &1
8
+ address: a:27017
9
+ type: Mongos
10
+ avg_rtt_ms: 5
11
+ lastUpdateTime: 0
12
+ maxWireVersion: 5
13
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
14
+ read_preference:
15
+ mode: Nearest
16
+ maxStalenessMS: 1 # OK for sharding.
17
+ suitable_servers:
18
+ - *1
19
+ in_latency_window:
20
+ - *1
@@ -0,0 +1,18 @@
1
+ # During server selection,
2
+ # clients (drivers or mongos) MUST raise an error if ``maxStalenessMS`` is not zero or null,
3
+ # and any server's ``maxWireVersion`` is less than 5 (`SERVER-23893`_).
4
+ ---
5
+ topology_description:
6
+ type: Single
7
+ servers:
8
+ - &1
9
+ address: a:27017
10
+ type: Standalone
11
+ avg_rtt_ms: 5
12
+ lastUpdateTime: 0
13
+ maxWireVersion: 4 # Incompatible.
14
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
15
+ read_preference:
16
+ mode: Nearest
17
+ maxStalenessMS: 120000
18
+ error: true
@@ -0,0 +1,20 @@
1
+ # Driver doesn't validate maxStalenessMS for direct connection.
2
+ ---
3
+ heartbeatFrequencyMS: 10000
4
+ topology_description:
5
+ type: Single
6
+ servers:
7
+ - &1
8
+ address: a:27017
9
+ type: Standalone
10
+ avg_rtt_ms: 5
11
+ lastUpdateTime: 0
12
+ maxWireVersion: 5
13
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
14
+ read_preference:
15
+ mode: Nearest
16
+ maxStalenessMS: 1
17
+ suitable_servers:
18
+ - *1
19
+ in_latency_window:
20
+ - *1
@@ -39,6 +39,16 @@ module Mongo
39
39
  # @since 2.0.0
40
40
  attr_reader :read_preference
41
41
 
42
+ # @return [ Integer ] heartbeat_frequency The heartbeat frequency to be set on the client.
43
+ #
44
+ # @since 2.4.0
45
+ attr_reader :heartbeat_frequency
46
+
47
+ # @return [ Integer ] max_staleness The max_staleness.
48
+ #
49
+ # @since 2.4.0
50
+ attr_reader :max_staleness
51
+
42
52
  # @return [ Array<Hash> ] candidate_servers The candidate servers.
43
53
  #
44
54
  # @since 2.0.0
@@ -74,8 +84,10 @@ module Mongo
74
84
  @test = YAML.load(ERB.new(file.read).result)
75
85
  file.close
76
86
  @description = "#{@test['topology_description']['type']}: #{File.basename(file)}"
87
+ @heartbeat_frequency = @test['heartbeatFrequencyMS']
77
88
  @read_preference = @test['read_preference']
78
89
  @read_preference['mode'] = READ_PREFERENCES[@read_preference['mode']]
90
+ @max_staleness = @read_preference['maxStalenessMS']
79
91
  @candidate_servers = @test['topology_description']['servers']
80
92
  @suitable_servers = @test['suitable_servers']
81
93
  @in_latency_window = @test['in_latency_window']
@@ -106,6 +118,19 @@ module Mongo
106
118
  !in_latency_window.empty?
107
119
  end
108
120
 
121
+ # Is the max staleness setting invalid.
122
+ #
123
+ # @example Will the max staleness setting be valid with other options.
124
+ # spec.invalid_max_staleness?
125
+ #
126
+ # @return [ true, false ] If an error will be raised by the max staleness setting.
127
+ #
128
+ # @since 2.4.0
129
+ def invalid_max_staleness?
130
+ @test['error'] ||
131
+ candidate_servers.any? { |server| server['maxWireVersion'] < 5 }
132
+ end
133
+
109
134
  # The subset of suitable servers that falls within the allowable latency
110
135
  # window.
111
136
  # We have to correct for our server selection algorithm that adds the primary
@@ -0,0 +1,27 @@
1
+ ---
2
+ topology_description:
3
+ type: ReplicaSetNoPrimary
4
+ servers:
5
+ - &1
6
+ address: b:27017
7
+ avg_rtt_ms: 10
8
+ type: RSSecondary
9
+ tags:
10
+ data_center: nyc
11
+ - &2
12
+ address: c:27017
13
+ avg_rtt_ms: 20
14
+ type: RSSecondary
15
+ tags:
16
+ data_center: nyc
17
+ operation: read
18
+ read_preference:
19
+ mode: Nearest
20
+ tag_sets:
21
+ - data_center: nyc
22
+ suitable_servers:
23
+ - *1
24
+ - *2
25
+ in_latency_window:
26
+ - *1
27
+ - *2
@@ -0,0 +1,31 @@
1
+ # Catch bugs like CDRIVER-1447, ensure clients select a server that matches all
2
+ # tags, even when the other server mismatches multiple tags.
3
+ ---
4
+ topology_description:
5
+ type: ReplicaSetNoPrimary
6
+ servers:
7
+ - &1
8
+ address: b:27017
9
+ avg_rtt_ms: 5
10
+ type: RSSecondary
11
+ tags:
12
+ rack: one
13
+ data_center: nyc
14
+ - &2
15
+ address: c:27017
16
+ avg_rtt_ms: 5
17
+ type: RSSecondary
18
+ tags:
19
+ rack: two
20
+ data_center: sf
21
+ operation: read
22
+ read_preference:
23
+ mode: Secondary
24
+ tag_sets:
25
+ - data_center: nyc
26
+ rack: one
27
+ - other_tag: doesntexist
28
+ suitable_servers:
29
+ - *1
30
+ in_latency_window:
31
+ - *1
@@ -0,0 +1,31 @@
1
+ # Ensure clients select a server that matches all tags, even when the other
2
+ # server matches one tag and doesn't match the other.
3
+ ---
4
+ topology_description:
5
+ type: ReplicaSetNoPrimary
6
+ servers:
7
+ - &1
8
+ address: b:27017
9
+ avg_rtt_ms: 5
10
+ type: RSSecondary
11
+ tags:
12
+ rack: one
13
+ data_center: nyc
14
+ - &2
15
+ address: c:27017
16
+ avg_rtt_ms: 5
17
+ type: RSSecondary
18
+ tags:
19
+ rack: two # mismatch
20
+ data_center: nyc # match
21
+ operation: read
22
+ read_preference:
23
+ mode: Secondary
24
+ tag_sets:
25
+ - data_center: nyc
26
+ rack: one
27
+ - other_tag: doesntexist
28
+ suitable_servers:
29
+ - *1
30
+ in_latency_window:
31
+ - *1