mongo 2.3.1 → 2.4.0.rc0

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.
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,26 @@
1
+ # Filter out the stale secondary.
2
+ ---
3
+ topology_description:
4
+ type: ReplicaSetNoPrimary
5
+ servers:
6
+ - &1
7
+ address: a:27017
8
+ type: RSSecondary
9
+ avg_rtt_ms: 5
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: SecondaryPreferred
22
+ maxStalenessMS: 120000
23
+ suitable_servers:
24
+ - *1
25
+ in_latency_window:
26
+ - *1
@@ -0,0 +1,51 @@
1
+ # Latest secondary's lastWriteDate is used normally with read preference tags.
2
+ ---
3
+ heartbeatFrequencyMS: 25000 # 25 seconds.
4
+ topology_description:
5
+ type: ReplicaSetNoPrimary
6
+ servers:
7
+ - &1
8
+ address: a:27017
9
+ type: RSSecondary
10
+ avg_rtt_ms: 5
11
+ lastUpdateTime: 0
12
+ maxWireVersion: 5
13
+ lastWrite: {lastWriteDate: {$numberLong: "25002"}}
14
+ tags:
15
+ data_center: tokyo # No match, but its lastWriteDate is used in estimate.
16
+ - &2
17
+ address: b:27017
18
+ type: RSSecondary
19
+ avg_rtt_ms: 5
20
+ lastUpdateTime: 0
21
+ maxWireVersion: 5
22
+ lastWrite: {lastWriteDate: {$numberLong: "2"}} # 25 sec stale + 25 sec heartbeat <= 50 sec maxStaleness.
23
+ tags:
24
+ data_center: nyc
25
+ - &3
26
+ address: c:27017
27
+ type: RSSecondary
28
+ avg_rtt_ms: 5
29
+ lastUpdateTime: 0
30
+ maxWireVersion: 5
31
+ lastWrite: {lastWriteDate: {$numberLong: "1"}} # Too stale.
32
+ tags:
33
+ data_center: nyc
34
+ - &4
35
+ address: d:27017
36
+ type: RSSecondary
37
+ avg_rtt_ms: 5
38
+ lastUpdateTime: 0
39
+ maxWireVersion: 5
40
+ lastWrite: {lastWriteDate: {$numberLong: "2"}}
41
+ tags:
42
+ data_center: tokyo # No match.
43
+ read_preference:
44
+ mode: SecondaryPreferred
45
+ maxStalenessMS: 50000
46
+ tag_sets:
47
+ - data_center: nyc
48
+ suitable_servers:
49
+ - *2
50
+ in_latency_window:
51
+ - *2
@@ -0,0 +1,26 @@
1
+ # By default, a read preference sets no maximum on staleness.
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
+ suitable_servers: # Very stale server is fine.
23
+ - *1
24
+ - *2
25
+ in_latency_window:
26
+ - *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: 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: 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,35 @@
1
+ heartbeatFrequencyMS: 25000 # 25 seconds.
2
+ topology_description:
3
+ type: ReplicaSetWithPrimary
4
+ servers:
5
+ - &1
6
+ address: a:27017
7
+ type: RSPrimary
8
+ avg_rtt_ms: 50 # Too far.
9
+ lastUpdateTime: 1
10
+ lastWrite: {lastWriteDate: {$numberLong: "2"}}
11
+ maxWireVersion: 5
12
+ - &2
13
+ address: b:27017
14
+ type: RSSecondary
15
+ avg_rtt_ms: 5
16
+ lastUpdateTime: 25001
17
+ # Updated 25 sec after primary, so 25 sec stale.
18
+ # 25 sec stale + 25 sec heartbeat <= 50 sec maxStaleness.
19
+ lastWrite: {lastWriteDate: {$numberLong: "2"}}
20
+ maxWireVersion: 5
21
+ - &3
22
+ address: c:27017
23
+ type: RSSecondary
24
+ avg_rtt_ms: 5
25
+ lastUpdateTime: 25001
26
+ lastWrite: {lastWriteDate: {$numberLong: "1"}} # Too stale.
27
+ maxWireVersion: 5
28
+ read_preference:
29
+ mode: Nearest
30
+ maxStalenessMS: 50000
31
+ suitable_servers:
32
+ - *1
33
+ - *2
34
+ in_latency_window:
35
+ - *2
@@ -0,0 +1,25 @@
1
+ # A driver MUST raise an error
2
+ # if the TopologyType is ReplicaSetWithPrimary or ReplicaSetNoPrimary
3
+ # and ``maxStalenessMS`` is less than twice the client's `heartbeatFrequencyMS`.
4
+ ---
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: 5
19
+ lastUpdateTime: 0
20
+ maxWireVersion: 5
21
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
22
+ read_preference:
23
+ mode: Nearest
24
+ maxStalenessMS: 1 # Too small.
25
+ error: true
@@ -0,0 +1,23 @@
1
+ # Drivers MUST raise an error if ``maxStalenessMS`` is not zero or null
2
+ # and the ``mode`` field is 'primary'.
3
+ ---
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: "1"}}
14
+ - &2
15
+ address: b:27017
16
+ type: RSSecondary
17
+ avg_rtt_ms: 5
18
+ lastUpdateTime: 0
19
+ maxWireVersion: 5
20
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
21
+ read_preference:
22
+ maxStalenessMS: 120000
23
+ error: true
@@ -0,0 +1,33 @@
1
+ heartbeatFrequencyMS: 25000 # 25 seconds.
2
+ topology_description:
3
+ type: ReplicaSetWithPrimary
4
+ servers:
5
+ - &1
6
+ address: a:27017
7
+ type: RSPrimary
8
+ avg_rtt_ms: 5
9
+ lastUpdateTime: 0
10
+ lastWrite: {lastWriteDate: {$numberLong: "25002"}}
11
+ maxWireVersion: 5
12
+ - &2
13
+ address: b:27017
14
+ type: RSSecondary
15
+ avg_rtt_ms: 50 # Too far.
16
+ lastUpdateTime: 0
17
+ lastWrite: {lastWriteDate: {$numberLong: "2"}} # 25 sec stale + 25 sec heartbeat <= 50 sec maxStaleness.
18
+ maxWireVersion: 5
19
+ - &3
20
+ address: c:27017
21
+ avg_rtt_ms: 5
22
+ lastUpdateTime: 0
23
+ type: RSSecondary
24
+ lastWrite: {lastWriteDate: {$numberLong: "1"}} # Too stale.
25
+ maxWireVersion: 5
26
+ read_preference:
27
+ mode: Nearest
28
+ maxStalenessMS: 50000
29
+ suitable_servers:
30
+ - *1
31
+ - *2
32
+ in_latency_window:
33
+ - *1
@@ -0,0 +1,33 @@
1
+ heartbeatFrequencyMS: 25000 # 25 seconds.
2
+ topology_description:
3
+ type: ReplicaSetWithPrimary
4
+ servers:
5
+ - &1
6
+ address: a:27017
7
+ type: RSPrimary
8
+ avg_rtt_ms: 50 # Too far.
9
+ lastUpdateTime: 0
10
+ lastWrite: {lastWriteDate: {$numberLong: "25002"}}
11
+ maxWireVersion: 5
12
+ - &2
13
+ address: b:27017
14
+ type: RSSecondary
15
+ avg_rtt_ms: 5
16
+ lastUpdateTime: 0
17
+ lastWrite: {lastWriteDate: {$numberLong: "2"}} # 25 sec stale + 25 sec heartbeat <= 50 sec maxStaleness.
18
+ maxWireVersion: 5
19
+ - &3
20
+ address: c:27017
21
+ avg_rtt_ms: 5
22
+ lastUpdateTime: 0
23
+ type: RSSecondary
24
+ lastWrite: {lastWriteDate: {$numberLong: "1"}} # Too stale.
25
+ maxWireVersion: 5
26
+ read_preference:
27
+ mode: Nearest
28
+ maxStalenessMS: 50000
29
+ suitable_servers:
30
+ - *1
31
+ - *2
32
+ in_latency_window:
33
+ - *2
@@ -0,0 +1,36 @@
1
+ # maxStalenessMS is applied before tag sets. With tag sets
2
+ # [{data_center: nyc}, {data_center: tokyo}], if the only node in NYC is stale
3
+ # 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
+ tags:
17
+ data_center: tokyo
18
+ - &2
19
+ address: b:27017
20
+ type: RSSecondary
21
+ avg_rtt_ms: 5
22
+ lastUpdateTime: 0
23
+ lastWrite: {lastWriteDate: {$numberLong: "1"}} # Too stale.
24
+ maxWireVersion: 5
25
+ tags:
26
+ data_center: nyc
27
+ read_preference:
28
+ mode: Nearest
29
+ maxStalenessMS: 50000
30
+ tag_sets:
31
+ - data_center: nyc
32
+ - data_center: tokyo
33
+ suitable_servers:
34
+ - *1
35
+ in_latency_window:
36
+ - *1
@@ -0,0 +1,27 @@
1
+ # Ignore maxStalenessMS is primary is available.
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: "1"}}
14
+ - &2
15
+ address: b:27017
16
+ type: RSSecondary
17
+ avg_rtt_ms: 5
18
+ lastUpdateTime: 0
19
+ maxWireVersion: 5
20
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
21
+ read_preference:
22
+ mode: PrimaryPreferred
23
+ maxStalenessMS: 50000
24
+ suitable_servers:
25
+ - *1
26
+ in_latency_window:
27
+ - *1
@@ -0,0 +1,27 @@
1
+ # Primary has wire version 5, secondary has 4, read preference primaryPreferred
2
+ # with maxStalenessMS. The client must error, even though it uses primary and
3
+ # never applies maxStalenessMS. Proves that the compatibility check precedes
4
+ # filtration.
5
+ ---
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
+ maxWireVersion: 5
15
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
16
+ - &2
17
+ address: b:27017
18
+ type: RSSecondary
19
+ avg_rtt_ms: 5
20
+ lastUpdateTime: 0
21
+ maxWireVersion: 4 # Too old.
22
+ lastWrite: {lastWriteDate: {$numberLong: "1"}}
23
+ read_preference:
24
+ mode: PrimaryPreferred
25
+ maxStalenessMS: 50000
26
+ error: true
27
+
@@ -0,0 +1,26 @@
1
+ # Fallback to primary if no secondary is fresh enough.
2
+ ---
3
+ topology_description:
4
+ type: ReplicaSetWithPrimary
5
+ servers:
6
+ - &1
7
+ address: a:27017
8
+ type: RSPrimary
9
+ avg_rtt_ms: 5
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: SecondaryPreferred
22
+ maxStalenessMS: 120000
23
+ suitable_servers:
24
+ - *1
25
+ in_latency_window:
26
+ - *1
@@ -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: SecondaryPreferred
52
+ maxStalenessMS: 50000
53
+ tag_sets:
54
+ - data_center: nyc
55
+ suitable_servers:
56
+ - *2
57
+ - *3
58
+ in_latency_window:
59
+ - *2