From f4922da97c414d7fa335562f315d673e7217be82 Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Mon, 24 Oct 2016 17:22:36 -0400 Subject: [PATCH] PYTHON-1104 - maxStalenessMS -> maxStalenessSeconds. --- doc/changelog.rst | 2 +- pymongo/client_options.py | 3 +- pymongo/common.py | 11 ++- pymongo/max_staleness_selectors.py | 6 +- pymongo/message.py | 4 +- pymongo/mongo_client.py | 8 +- pymongo/read_preferences.py | 8 +- .../ReplicaSetNoPrimary/Incompatible.json | 2 +- .../ReplicaSetNoPrimary/LastUpdateTime.json | 6 +- .../ReplicaSetNoPrimary/Nearest.json | 2 +- .../ReplicaSetNoPrimary/Nearest2.json | 2 +- .../ReplicaSetNoPrimary/PrimaryPreferred.json | 2 +- .../PrimaryPreferred_tags.json | 2 +- .../ReplicaSetNoPrimary/Secondary.json | 2 +- .../SecondaryPreferred.json | 2 +- .../SecondaryPreferred_tags.json | 2 +- .../ReplicaSetWithPrimary/Incompatible.json | 2 +- .../ReplicaSetWithPrimary/LastUpdateTime.json | 2 +- .../MaxStalenessTooSmall.json | 2 +- .../MaxStalenessWithModePrimary.json | 2 +- .../ReplicaSetWithPrimary/Nearest.json | 2 +- .../ReplicaSetWithPrimary/Nearest2.json | 2 +- .../ReplicaSetWithPrimary/Nearest_tags.json | 2 +- .../PrimaryPreferred.json | 2 +- .../PrimaryPreferred_incompatible.json | 2 +- .../SecondaryPreferred.json | 2 +- .../SecondaryPreferred_tags.json | 2 +- .../SecondaryPreferred_tags2.json | 2 +- .../ReplicaSetWithPrimary/Secondary_tags.json | 2 +- .../Secondary_tags2.json | 2 +- .../ShortHeartbeartShortMaxStaleness.json | 76 ------------------- .../ShortHeartbeartShortMaxStaleness2.json | 76 ------------------- .../ZeroMaxStaleness.json | 75 ------------------ test/max_staleness/Sharded/Incompatible.json | 2 +- .../Sharded/SmallMaxStaleness.json | 2 +- test/max_staleness/Single/Incompatible.json | 2 +- .../Single/SmallMaxStaleness.json | 2 +- .../Unknown/SmallMaxStaleness.json | 2 +- test/test_max_staleness.py | 16 ++-- test/test_read_preferences.py | 14 ++-- 40 files changed, 69 insertions(+), 290 deletions(-) delete mode 100644 test/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness.json delete mode 100644 test/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness2.json delete mode 100644 test/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.json diff --git a/doc/changelog.rst b/doc/changelog.rst index 3b0264371..da9265ee1 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -13,7 +13,7 @@ Highlights include: - Unicode aware string comparison using :doc:`examples/collations`. - Support for the new :class:`~bson.decimal128.Decimal128` BSON type. - - A new maxStalenessMS read preference option. + - A new maxStalenessSeconds read preference option. - :meth:`~pymongo.collection.Collection.parallel_scan` supports maxTimeMS. - :attr:`~pymongo.write_concern.WriteConcern` is automatically applied by all helpers for commands that write to the database when diff --git a/pymongo/client_options.py b/pymongo/client_options.py index 1e49d3343..39dc74a08 100644 --- a/pymongo/client_options.py +++ b/pymongo/client_options.py @@ -44,8 +44,7 @@ def _parse_read_preference(options): mode = options.get('readpreference', 0) tags = options.get('readpreferencetags') - # common.validate() has converted from ms to seconds. - max_staleness = options.get('maxstalenessms') + max_staleness = options.get('maxstalenessseconds') return make_read_preference(mode, tags, max_staleness) diff --git a/pymongo/common.py b/pymongo/common.py index 83d9e1d44..03d420348 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -286,6 +286,15 @@ def validate_timeout_or_zero(option, value): return validate_positive_float(option, value) / 1000.0 +def validate_max_staleness(option, value): + """Validates a timeout specified in seconds returning + a value in floating point seconds. + """ + if value is None: + return value + return validate_positive_float(option, value) + + def validate_read_preference(dummy, value): """Validate a read preference. """ @@ -495,7 +504,7 @@ TIMEOUT_VALIDATORS = { 'serverselectiontimeoutms': validate_timeout_or_zero, 'heartbeatfrequencyms': validate_timeout_or_none, 'maxidletimems': validate_timeout_or_none, - 'maxstalenessms': validate_timeout_or_none + 'maxstalenessseconds': validate_max_staleness, } KW_VALIDATORS = { diff --git a/pymongo/max_staleness_selectors.py b/pymongo/max_staleness_selectors.py index 511d0a1c6..6d88f55bb 100644 --- a/pymongo/max_staleness_selectors.py +++ b/pymongo/max_staleness_selectors.py @@ -12,7 +12,7 @@ # implied. See the License for the specific language governing # permissions and limitations under the License. -"""Criteria to select ServerDescriptions based on maxStalenessMS. +"""Criteria to select ServerDescriptions based on maxStalenessSeconds. The Max Staleness Spec says: When there is a known primary P, a secondary S's staleness is estimated with this formula: @@ -79,10 +79,10 @@ def select(max_staleness, selection): # Server Selection Spec: "A driver MUST raise an error if the # TopologyType is ReplicaSetWithPrimary or ReplicaSetNoPrimary and - # maxStalenessMS is less than twice heartbeatFrequencyMS." + # maxStalenessSeconds * 1000 is less than twice heartbeatFrequencyMS." if max_staleness < 2 * selection.heartbeat_frequency: raise ConfigurationError( - "maxStalenessMS must be twice heartbeatFrequencyMS") + "maxStalenessSeconds must be twice heartbeatFrequencyMS") if selection.primary: return _with_primary(max_staleness, selection) diff --git a/pymongo/message.py b/pymongo/message.py index 23da7deb6..76adcf88a 100644 --- a/pymongo/message.py +++ b/pymongo/message.py @@ -77,8 +77,8 @@ def _maybe_add_read_preference(spec, read_preference): # Only add $readPreference if it's something other than primary to avoid # problems with mongos versions that don't support read preferences. Also, # for maximum backwards compatibility, don't add $readPreference for - # secondaryPreferred unless tags or maxStalenessMS are in use (setting the - # slaveOkay bit has the same effect). + # secondaryPreferred unless tags or maxStalenessSeconds are in use (setting + # the slaveOkay bit has the same effect). if mode and ( mode != ReadPreference.SECONDARY_PREFERRED.mode or tag_sets != [{}] diff --git a/pymongo/mongo_client.py b/pymongo/mongo_client.py index 6d3f5b26c..9f5a9a24a 100644 --- a/pymongo/mongo_client.py +++ b/pymongo/mongo_client.py @@ -252,10 +252,10 @@ class MongoClient(common.BaseObject): - `readPreferenceTags`: Specifies a tag set as a comma-separated list of colon-separated key-value pairs. For example ``dc:ny,rack:1``. Defaults to ``None``. - - `maxStalenessMS`: (integer or float, in milliseconds) The maximum - estimated length of time a replica set secondary can fall behind - the primary in replication before it will no longer be selected for - operations. Defaults to ``None`` (no limit). + - `maxStalenessSeconds`: (integer or float) The maximum estimated + length of time a replica set secondary can fall behind the primary + in replication before it will no longer be selected for operations. + Defaults to ``None`` (no limit). | **SSL configuration:** diff --git a/pymongo/read_preferences.py b/pymongo/read_preferences.py index 19cfc2432..54afa20b8 100644 --- a/pymongo/read_preferences.py +++ b/pymongo/read_preferences.py @@ -108,7 +108,7 @@ class _ServerMode(object): if self.__tag_sets not in (None, [{}]): doc['tags'] = self.__tag_sets if self.__max_staleness: - doc['maxStalenessMS'] = int(self.__max_staleness * 1000) + doc['maxStalenessSeconds'] = int(self.__max_staleness) return doc @property @@ -145,8 +145,8 @@ class _ServerMode(object): def min_wire_version(self): """The wire protocol version the server must support. - Some read preferences impose version requirements on all servers in the - topology (e.g. maxStalenessMS requires MongoDB 3.4 / maxWireVersion 5). + Some read preferences impose version requirements on all servers (e.g. + maxStalenessSeconds requires MongoDB 3.4 / maxWireVersion 5). All servers' maxWireVersion must be at least this read preference's `min_wire_version`, or the driver raises @@ -347,7 +347,7 @@ def make_read_preference(mode, tag_sets, max_staleness=None): "cannot be combined with tags") if max_staleness: raise ConfigurationError("Read preference primary cannot be " - "combined with maxStalenessMS") + "combined with maxStalenessSeconds") return Primary() return _ALL_READ_PREFERENCES[mode](tag_sets, max_staleness) diff --git a/test/max_staleness/ReplicaSetNoPrimary/Incompatible.json b/test/max_staleness/ReplicaSetNoPrimary/Incompatible.json index e41ea79b3..f0eceefc2 100644 --- a/test/max_staleness/ReplicaSetNoPrimary/Incompatible.json +++ b/test/max_staleness/ReplicaSetNoPrimary/Incompatible.json @@ -1,7 +1,7 @@ { "error": true, "read_preference": { - "maxStalenessMS": 120000, + "maxStalenessSeconds": 120, "mode": "Nearest" }, "topology_description": { diff --git a/test/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.json b/test/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.json index 58e0ac4f8..7f5bdb283 100644 --- a/test/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.json +++ b/test/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.json @@ -15,7 +15,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "Nearest" }, "suitable_servers": [ @@ -37,7 +37,7 @@ "lastUpdateTime": 25002, "lastWrite": { "lastWriteDate": { - "$numberLong": "1" + "$numberLong": "2" } }, "maxWireVersion": 5, @@ -64,7 +64,7 @@ "lastUpdateTime": 25002, "lastWrite": { "lastWriteDate": { - "$numberLong": "1" + "$numberLong": "2" } }, "maxWireVersion": 5, diff --git a/test/max_staleness/ReplicaSetNoPrimary/Nearest.json b/test/max_staleness/ReplicaSetNoPrimary/Nearest.json index 97f471b11..7b87e5fe2 100644 --- a/test/max_staleness/ReplicaSetNoPrimary/Nearest.json +++ b/test/max_staleness/ReplicaSetNoPrimary/Nearest.json @@ -15,7 +15,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "Nearest" }, "suitable_servers": [ diff --git a/test/max_staleness/ReplicaSetNoPrimary/Nearest2.json b/test/max_staleness/ReplicaSetNoPrimary/Nearest2.json index 0438db264..db2440db4 100644 --- a/test/max_staleness/ReplicaSetNoPrimary/Nearest2.json +++ b/test/max_staleness/ReplicaSetNoPrimary/Nearest2.json @@ -15,7 +15,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "Nearest" }, "suitable_servers": [ diff --git a/test/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.json b/test/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.json index f287087b6..ba9caf8f3 100644 --- a/test/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.json +++ b/test/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.json @@ -15,7 +15,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "PrimaryPreferred" }, "suitable_servers": [ diff --git a/test/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.json b/test/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.json index ff847b563..6aabf7edc 100644 --- a/test/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.json +++ b/test/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.json @@ -18,7 +18,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "PrimaryPreferred", "tag_sets": [ { diff --git a/test/max_staleness/ReplicaSetNoPrimary/Secondary.json b/test/max_staleness/ReplicaSetNoPrimary/Secondary.json index db99b636c..d83edead5 100644 --- a/test/max_staleness/ReplicaSetNoPrimary/Secondary.json +++ b/test/max_staleness/ReplicaSetNoPrimary/Secondary.json @@ -18,7 +18,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "Secondary", "tag_sets": [ { diff --git a/test/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.json b/test/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.json index 66b9c1ffd..db4504233 100644 --- a/test/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.json +++ b/test/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.json @@ -14,7 +14,7 @@ } ], "read_preference": { - "maxStalenessMS": 120000, + "maxStalenessSeconds": 120, "mode": "SecondaryPreferred" }, "suitable_servers": [ diff --git a/test/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.json b/test/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.json index f41250d0d..9dfe1f48a 100644 --- a/test/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.json +++ b/test/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.json @@ -18,7 +18,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "SecondaryPreferred", "tag_sets": [ { diff --git a/test/max_staleness/ReplicaSetWithPrimary/Incompatible.json b/test/max_staleness/ReplicaSetWithPrimary/Incompatible.json index 0e99ba96a..ec65af9cf 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/Incompatible.json +++ b/test/max_staleness/ReplicaSetWithPrimary/Incompatible.json @@ -1,7 +1,7 @@ { "error": true, "read_preference": { - "maxStalenessMS": 120000, + "maxStalenessSeconds": 120, "mode": "Nearest" }, "topology_description": { diff --git a/test/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.json b/test/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.json index 7dc33872b..9de2224cd 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.json +++ b/test/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.json @@ -15,7 +15,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "Nearest" }, "suitable_servers": [ diff --git a/test/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.json b/test/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.json index add052fcb..3ed364f9b 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.json +++ b/test/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.json @@ -1,7 +1,7 @@ { "error": true, "read_preference": { - "maxStalenessMS": 1, + "maxStalenessSeconds": 1, "mode": "Nearest" }, "topology_description": { diff --git a/test/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.json b/test/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.json index b1cced7a3..54155d40f 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.json +++ b/test/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.json @@ -1,7 +1,7 @@ { "error": true, "read_preference": { - "maxStalenessMS": 120000 + "maxStalenessSeconds": 120 }, "topology_description": { "servers": [ diff --git a/test/max_staleness/ReplicaSetWithPrimary/Nearest.json b/test/max_staleness/ReplicaSetWithPrimary/Nearest.json index 1fa266e0c..0306579b3 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/Nearest.json +++ b/test/max_staleness/ReplicaSetWithPrimary/Nearest.json @@ -15,7 +15,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "Nearest" }, "suitable_servers": [ diff --git a/test/max_staleness/ReplicaSetWithPrimary/Nearest2.json b/test/max_staleness/ReplicaSetWithPrimary/Nearest2.json index 790bad947..9cc10e882 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/Nearest2.json +++ b/test/max_staleness/ReplicaSetWithPrimary/Nearest2.json @@ -15,7 +15,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "Nearest" }, "suitable_servers": [ diff --git a/test/max_staleness/ReplicaSetWithPrimary/Nearest_tags.json b/test/max_staleness/ReplicaSetWithPrimary/Nearest_tags.json index b9f04dc09..9ec1e718a 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/Nearest_tags.json +++ b/test/max_staleness/ReplicaSetWithPrimary/Nearest_tags.json @@ -18,7 +18,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "Nearest", "tag_sets": [ { diff --git a/test/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.json b/test/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.json index c45ecea1d..39b00a552 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.json +++ b/test/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.json @@ -15,7 +15,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "PrimaryPreferred" }, "suitable_servers": [ diff --git a/test/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.json b/test/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.json index 7805a2384..75dad2d53 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.json +++ b/test/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.json @@ -1,7 +1,7 @@ { "error": true, "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "PrimaryPreferred" }, "topology_description": { diff --git a/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.json b/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.json index d5a410f6b..01a9aea7e 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.json +++ b/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.json @@ -14,7 +14,7 @@ } ], "read_preference": { - "maxStalenessMS": 120000, + "maxStalenessSeconds": 120, "mode": "SecondaryPreferred" }, "suitable_servers": [ diff --git a/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.json b/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.json index b41855b7c..b92bd0c69 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.json +++ b/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.json @@ -18,7 +18,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "SecondaryPreferred", "tag_sets": [ { diff --git a/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.json b/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.json index c6aeb166e..d9c62a039 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.json +++ b/test/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.json @@ -18,7 +18,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "SecondaryPreferred", "tag_sets": [ { diff --git a/test/max_staleness/ReplicaSetWithPrimary/Secondary_tags.json b/test/max_staleness/ReplicaSetWithPrimary/Secondary_tags.json index f167bc3ef..9ae0c8e95 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/Secondary_tags.json +++ b/test/max_staleness/ReplicaSetWithPrimary/Secondary_tags.json @@ -18,7 +18,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "Secondary", "tag_sets": [ { diff --git a/test/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.json b/test/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.json index 26d1f27ed..235d6452e 100644 --- a/test/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.json +++ b/test/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.json @@ -18,7 +18,7 @@ } ], "read_preference": { - "maxStalenessMS": 50000, + "maxStalenessSeconds": 50, "mode": "Secondary", "tag_sets": [ { diff --git a/test/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness.json b/test/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness.json deleted file mode 100644 index 4a6c92708..000000000 --- a/test/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "heartbeatFrequencyMS": 1000, - "in_latency_window": [ - { - "address": "b:27017", - "avg_rtt_ms": 5, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSSecondary" - } - ], - "read_preference": { - "maxStalenessMS": 2000, - "mode": "Nearest" - }, - "suitable_servers": [ - { - "address": "a:27017", - "avg_rtt_ms": 50, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSPrimary" - }, - { - "address": "b:27017", - "avg_rtt_ms": 5, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSSecondary" - } - ], - "topology_description": { - "servers": [ - { - "address": "a:27017", - "avg_rtt_ms": 50, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSPrimary" - }, - { - "address": "b:27017", - "avg_rtt_ms": 5, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSSecondary" - } - ], - "type": "ReplicaSetWithPrimary" - } -} diff --git a/test/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness2.json b/test/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness2.json deleted file mode 100644 index e3c4242e5..000000000 --- a/test/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness2.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "heartbeatFrequencyMS": 1000, - "in_latency_window": [ - { - "address": "a:27017", - "avg_rtt_ms": 5, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSPrimary" - } - ], - "read_preference": { - "maxStalenessMS": 2000, - "mode": "Nearest" - }, - "suitable_servers": [ - { - "address": "a:27017", - "avg_rtt_ms": 5, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSPrimary" - }, - { - "address": "b:27017", - "avg_rtt_ms": 50, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSSecondary" - } - ], - "topology_description": { - "servers": [ - { - "address": "a:27017", - "avg_rtt_ms": 5, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSPrimary" - }, - { - "address": "b:27017", - "avg_rtt_ms": 50, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSSecondary" - } - ], - "type": "ReplicaSetWithPrimary" - } -} diff --git a/test/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.json b/test/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.json deleted file mode 100644 index 310912753..000000000 --- a/test/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "in_latency_window": [ - { - "address": "b:27017", - "avg_rtt_ms": 5, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSSecondary" - } - ], - "read_preference": { - "maxStalenessMS": 0, - "mode": "Nearest" - }, - "suitable_servers": [ - { - "address": "a:27017", - "avg_rtt_ms": 50, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1000001" - } - }, - "maxWireVersion": 5, - "type": "RSPrimary" - }, - { - "address": "b:27017", - "avg_rtt_ms": 5, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSSecondary" - } - ], - "topology_description": { - "servers": [ - { - "address": "a:27017", - "avg_rtt_ms": 50, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1000001" - } - }, - "maxWireVersion": 5, - "type": "RSPrimary" - }, - { - "address": "b:27017", - "avg_rtt_ms": 5, - "lastUpdateTime": 0, - "lastWrite": { - "lastWriteDate": { - "$numberLong": "1" - } - }, - "maxWireVersion": 5, - "type": "RSSecondary" - } - ], - "type": "ReplicaSetWithPrimary" - } -} diff --git a/test/max_staleness/Sharded/Incompatible.json b/test/max_staleness/Sharded/Incompatible.json index 58b6d577d..5e954166d 100644 --- a/test/max_staleness/Sharded/Incompatible.json +++ b/test/max_staleness/Sharded/Incompatible.json @@ -1,7 +1,7 @@ { "error": true, "read_preference": { - "maxStalenessMS": 120000, + "maxStalenessSeconds": 120, "mode": "Nearest" }, "topology_description": { diff --git a/test/max_staleness/Sharded/SmallMaxStaleness.json b/test/max_staleness/Sharded/SmallMaxStaleness.json index 89a7b357c..74e933e0b 100644 --- a/test/max_staleness/Sharded/SmallMaxStaleness.json +++ b/test/max_staleness/Sharded/SmallMaxStaleness.json @@ -15,7 +15,7 @@ } ], "read_preference": { - "maxStalenessMS": 1, + "maxStalenessSeconds": 1, "mode": "Nearest" }, "suitable_servers": [ diff --git a/test/max_staleness/Single/Incompatible.json b/test/max_staleness/Single/Incompatible.json index 1a0357564..852202638 100644 --- a/test/max_staleness/Single/Incompatible.json +++ b/test/max_staleness/Single/Incompatible.json @@ -1,7 +1,7 @@ { "error": true, "read_preference": { - "maxStalenessMS": 120000, + "maxStalenessSeconds": 120, "mode": "Nearest" }, "topology_description": { diff --git a/test/max_staleness/Single/SmallMaxStaleness.json b/test/max_staleness/Single/SmallMaxStaleness.json index 67f27cdff..7c1792861 100644 --- a/test/max_staleness/Single/SmallMaxStaleness.json +++ b/test/max_staleness/Single/SmallMaxStaleness.json @@ -15,7 +15,7 @@ } ], "read_preference": { - "maxStalenessMS": 1, + "maxStalenessSeconds": 1, "mode": "Nearest" }, "suitable_servers": [ diff --git a/test/max_staleness/Unknown/SmallMaxStaleness.json b/test/max_staleness/Unknown/SmallMaxStaleness.json index 6cad0873e..fc196abc9 100644 --- a/test/max_staleness/Unknown/SmallMaxStaleness.json +++ b/test/max_staleness/Unknown/SmallMaxStaleness.json @@ -2,7 +2,7 @@ "heartbeatFrequencyMS": 10000, "in_latency_window": [], "read_preference": { - "maxStalenessMS": 1, + "maxStalenessSeconds": 1, "mode": "Nearest" }, "suitable_servers": [], diff --git a/test/test_max_staleness.py b/test/test_max_staleness.py index c6c9f351e..148c25e8a 100644 --- a/test/test_max_staleness.py +++ b/test/test_max_staleness.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Test maxStalenessMS support.""" +"""Test maxStalenessSeconds support.""" import datetime import os @@ -158,9 +158,7 @@ def create_test(scenario_def): mode_string = pref_def.get('mode', 'primary') mode_string = mode_string[:1].lower() + mode_string[1:] mode = read_preferences.read_pref_mode_from_name(mode_string) - max_staleness = pref_def.get('maxStalenessMS', 0) / 1000.0 - if not max_staleness: - max_staleness = None + max_staleness = pref_def.get('maxStalenessSeconds') tag_sets = pref_def.get('tag_sets') if scenario_def.get('error'): @@ -224,19 +222,19 @@ class TestMaxStaleness(unittest.TestCase): def test_max_staleness(self): # These tests are specified in max-staleness-tests.rst. with self.assertRaises(ConfigurationError): - MongoClient("mongodb://a/?maxStalenessMS=120000") + MongoClient("mongodb://a/?maxStalenessSeconds=120") with self.assertRaises(ConfigurationError): MongoClient("mongodb://a/?readPreference=primary&" - "maxStalenessMS=120000") + "maxStalenessSeconds=120") client = MongoClient("mongodb://host/?readPreference=secondary&" - "maxStalenessMS=120000") + "maxStalenessSeconds=120") self.assertEqual(120, client.read_preference.max_staleness) client = MongoClient("mongodb://a/?readPreference=secondary&" - "maxStalenessMS=1") - self.assertEqual(0.001, client.read_preference.max_staleness) + "maxStalenessSeconds=1") + self.assertEqual(1, client.read_preference.max_staleness) if __name__ == "__main__": diff --git a/test/test_read_preferences.py b/test/test_read_preferences.py index 5b024c665..97b27dcb6 100644 --- a/test/test_read_preferences.py +++ b/test/test_read_preferences.py @@ -469,7 +469,7 @@ class TestMongosAndReadPreference(unittest.TestCase): pref.document, {'mode': 'primaryPreferred', 'tags': [{'dc': 'sf'}], - 'maxStalenessMS': 30000}) + 'maxStalenessSeconds': 30}) pref = Secondary() self.assertEqual( @@ -485,7 +485,7 @@ class TestMongosAndReadPreference(unittest.TestCase): pref.document, {'mode': 'secondary', 'tags': [{'dc': 'sf'}], - 'maxStalenessMS': 30000}) + 'maxStalenessSeconds': 30}) pref = SecondaryPreferred() self.assertEqual( @@ -501,7 +501,7 @@ class TestMongosAndReadPreference(unittest.TestCase): pref.document, {'mode': 'secondaryPreferred', 'tags': [{'dc': 'sf'}], - 'maxStalenessMS': 30000}) + 'maxStalenessSeconds': 30}) pref = Nearest() self.assertEqual( @@ -517,7 +517,7 @@ class TestMongosAndReadPreference(unittest.TestCase): pref.document, {'mode': 'nearest', 'tags': [{'dc': 'sf'}], - 'maxStalenessMS': 30000}) + 'maxStalenessSeconds': 30}) def test_maybe_add_read_preference(self): @@ -614,7 +614,7 @@ class TestMongosAndReadPreference(unittest.TestCase): @client_context.require_mongos @client_context.require_version_min(3, 3, 12) def test_mongos_max_staleness(self): - # Sanity check that we're sending maxStalenessMS + # Sanity check that we're sending maxStalenessSeconds coll = client_context.client.pymongo_test.get_collection( "test", read_preference=SecondaryPreferred(max_staleness=120)) # No error @@ -631,13 +631,13 @@ class TestMongosAndReadPreference(unittest.TestCase): coll = single_client( readPreference='secondaryPreferred', - maxStalenessMS=120000).pymongo_test.test + maxStalenessSeconds=120).pymongo_test.test # No error coll.find_one() coll = single_client( readPreference='secondaryPreferred', - maxStalenessMS=10000).pymongo_test.test + maxStalenessSeconds=10).pymongo_test.test try: coll.find_one() except OperationFailure as exc: