Skip to content

Commit 2f86207

Browse files
committed
PYTHON-526 secondaryAcceptableLatencyMS changes.
- Renamed to acceptableLatencyMS since it is also used in choosing a new mongos during mongos HA failover. - Moved to a global immutable setting. The expectation is that the value would be determined by a network/system admin. Changing it per operation doesn't make a lot of sense. Note - it's possible the name of this option may change again before 3.0 is released.
1 parent 9404ff1 commit 2f86207

19 files changed

+92
-185
lines changed

doc/api/pymongo/collection.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
.. autoattribute:: database
2626
.. autoattribute:: read_preference
2727
.. autoattribute:: tag_sets
28-
.. autoattribute:: secondary_acceptable_latency_ms
2928
.. autoattribute:: write_concern
3029
.. autoattribute:: uuid_subtype
3130
.. automethod:: insert(doc_or_docs[, manipulate=True[, check_keys=True[, continue_on_error=False[, **kwargs]]]])

doc/api/pymongo/cursor.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.. automodule:: pymongo.cursor
55
:synopsis: Tools for iterating over MongoDB query results
66

7-
.. autoclass:: pymongo.cursor.Cursor(collection, spec=None, fields=None, skip=0, limit=0, timeout=True, snapshot=False, tailable=False, sort=None, max_scan=None, as_class=None, await_data=False, partial=False, manipulate=True, read_preference=ReadPreference.PRIMARY, tag_sets=[{}], secondary_acceptable_latency_ms=None, exhaust=False)
7+
.. autoclass:: pymongo.cursor.Cursor(collection, spec=None, fields=None, skip=0, limit=0, timeout=True, snapshot=False, tailable=False, sort=None, max_scan=None, as_class=None, await_data=False, partial=False, manipulate=True, read_preference=ReadPreference.PRIMARY, tag_sets=[{}], exhaust=False)
88
:members:
99

1010
.. describe:: c[index]

doc/api/pymongo/database.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
.. autoattribute:: read_preference
2727
.. autoattribute:: tag_sets
28-
.. autoattribute:: secondary_acceptable_latency_ms
2928
.. autoattribute:: write_concern
3029
.. autoattribute:: uuid_subtype
3130

doc/api/pymongo/mongo_client.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
.. autoattribute:: max_wire_version
3232
.. autoattribute:: read_preference
3333
.. autoattribute:: tag_sets
34-
.. autoattribute:: secondary_acceptable_latency_ms
34+
.. autoattribute:: acceptable_latency_ms
3535
.. autoattribute:: write_concern
3636
.. autoattribute:: uuid_subtype
3737
.. autoattribute:: is_locked

doc/api/pymongo/mongo_replica_set_client.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
.. autoattribute:: auto_start_request
3333
.. autoattribute:: read_preference
3434
.. autoattribute:: tag_sets
35-
.. autoattribute:: secondary_acceptable_latency_ms
35+
.. autoattribute:: acceptable_latency_ms
3636
.. autoattribute:: write_concern
3737
.. autoattribute:: uuid_subtype
3838
.. automethod:: database_names

doc/examples/high_availability.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ per-query basis, e.g.::
200200
>>> db.collection.find_one(read_preference=ReadPreference.PRIMARY)
201201

202202
Reads are configured using three options: **read_preference**, **tag_sets**,
203-
and **secondary_acceptable_latency_ms**.
203+
and **acceptableLatencyMS**.
204204

205205
**read_preference**:
206206

@@ -210,18 +210,18 @@ and **secondary_acceptable_latency_ms**.
210210

211211
- ``PRIMARY_PREFERRED``: Read from the primary if available, or if there is
212212
none, read from a secondary matching your choice of ``tag_sets`` and
213-
``secondary_acceptable_latency_ms``.
213+
``acceptableLatencyMS``.
214214

215215
- ``SECONDARY``: Read from a secondary matching your choice of ``tag_sets`` and
216-
``secondary_acceptable_latency_ms``. If no matching secondary is available,
216+
``acceptableLatencyMS``. If no matching secondary is available,
217217
raise :class:`~pymongo.errors.AutoReconnect`.
218218

219219
- ``SECONDARY_PREFERRED``: Read from a secondary matching your choice of
220-
``tag_sets`` and ``secondary_acceptable_latency_ms`` if available, otherwise
220+
``tag_sets`` and ``acceptableLatencyMS`` if available, otherwise
221221
from primary (regardless of the primary's tags and latency).
222222

223223
- ``NEAREST``: Read from any member matching your choice of ``tag_sets`` and
224-
``secondary_acceptable_latency_ms``.
224+
``acceptableLatencyMS``.
225225

226226
**tag_sets**:
227227

@@ -248,22 +248,22 @@ and raises :class:`~pymongo.errors.AutoReconnect` if none are available. As an
248248
additional fallback, specify a final, empty tag set, ``{}``, which means "read
249249
from any member that matches the mode, ignoring tags."
250250

251-
**secondary_acceptable_latency_ms**:
251+
**acceptableLatencyMS**:
252252

253253
If multiple members match the mode and tag sets, MongoReplicaSetClient reads
254254
from among the nearest members, chosen according to ping time. By default,
255255
only members whose ping times are within 15 milliseconds of the nearest
256256
are used for queries. You can choose to distribute reads among members with
257-
higher latencies by setting ``secondary_acceptable_latency_ms`` to a larger
257+
higher latencies by setting ``acceptableLatencyMS`` to a larger
258258
number. In that case, MongoReplicaSetClient distributes reads among matching
259-
members within ``secondary_acceptable_latency_ms`` of the closest member's
259+
members within ``acceptableLatencyMS`` of the closest member's
260260
ping time.
261261

262-
.. note:: ``secondary_acceptable_latency_ms`` is ignored when talking to a
262+
.. note:: ``acceptableLatencyMS`` is ignored when talking to a
263263
replica set *through* a mongos. The equivalent is the localThreshold_ command
264264
line option.
265265

266-
.. _localThreshold: http://docs.mongodb.org/manual/reference/mongos/#cmdoption-mongos--localThreshold
266+
.. _localThreshold: http://docs.mongodb.org/manual/reference/mongos/#cmdoption--localThreshold
267267

268268
Health Monitoring
269269
'''''''''''''''''

gridfs/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,6 @@ def find(self, *args, **kwargs):
325325
- `read_preference` (optional): The read preference for
326326
this query.
327327
- `tag_sets` (optional): The tag sets for this query.
328-
- `secondary_acceptable_latency_ms` (optional): Any replica-set
329-
member whose ping time is within secondary_acceptable_latency_ms of
330-
the nearest member may accept reads. Default 15 milliseconds.
331-
**Ignored by mongos** and must be configured on the command line.
332-
See the localThreshold_ option for more information.
333328
- `compile_re` (optional): if ``False``, don't attempt to compile
334329
BSON regex objects into Python regexes. Return instances of
335330
:class:`~bson.regex.Regex` instead.
@@ -341,7 +336,6 @@ def find(self, *args, **kwargs):
341336
342337
.. versionadded:: 2.7
343338
.. mongodoc:: find
344-
.. _localThreshold: http://docs.mongodb.org/manual/reference/mongos/#cmdoption-mongos--localThreshold
345339
"""
346340
return GridOutCursor(self.__collection, *args, **kwargs)
347341

gridfs/grid_file.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,7 @@ class GridOutCursor(Cursor):
625625
"""
626626
def __init__(self, collection, spec=None, skip=0, limit=0,
627627
timeout=True, sort=None, max_scan=None,
628-
read_preference=None, tag_sets=None,
629-
secondary_acceptable_latency_ms=None, compile_re=True):
628+
read_preference=None, tag_sets=None, compile_re=True):
630629
"""Create a new cursor, similar to the normal
631630
:class:`~pymongo.cursor.Cursor`.
632631
@@ -643,14 +642,11 @@ def __init__(self, collection, spec=None, skip=0, limit=0,
643642
# Copy these settings from collection if they are not set by caller.
644643
read_preference = read_preference or collection.files.read_preference
645644
tag_sets = tag_sets or collection.files.tag_sets
646-
latency = (secondary_acceptable_latency_ms
647-
or collection.files.secondary_acceptable_latency_ms)
648645

649646
super(GridOutCursor, self).__init__(
650647
collection.files, spec, skip=skip, limit=limit, timeout=timeout,
651648
sort=sort, max_scan=max_scan, read_preference=read_preference,
652-
secondary_acceptable_latency_ms=latency, compile_re=compile_re,
653-
tag_sets=tag_sets)
649+
compile_re=compile_re, tag_sets=tag_sets)
654650

655651
def next(self):
656652
"""Get next GridOut object from cursor.

pymongo/collection.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ def __init__(self, database, name, create=False, **kwargs):
8888
super(Collection, self).__init__(
8989
read_preference=database.read_preference,
9090
tag_sets=database.tag_sets,
91-
secondary_acceptable_latency_ms=(
92-
database.secondary_acceptable_latency_ms),
9391
uuidrepresentation=database.uuid_subtype,
9492
**database.write_concern)
9593

@@ -784,11 +782,6 @@ def find(self, *args, **kwargs):
784782
- `read_preference` (optional): The read preference for
785783
this query.
786784
- `tag_sets` (optional): The tag sets for this query.
787-
- `secondary_acceptable_latency_ms` (optional): Any replica-set
788-
member whose ping time is within secondary_acceptable_latency_ms of
789-
the nearest member may accept reads. Default 15 milliseconds.
790-
**Ignored by mongos** and must be configured on the command line.
791-
See the localThreshold_ option for more information.
792785
- `compile_re` (optional): if ``False``, don't attempt to compile
793786
BSON regex objects into Python regexes. Return instances of
794787
:class:`~bson.regex.Regex` instead.
@@ -823,7 +816,8 @@ def find(self, *args, **kwargs):
823816
version **>= 1.5.1**
824817
825818
.. versionchanged:: 3.0
826-
Removed the ``network_timeout`` parameter.
819+
Removed the `network_timeout` and
820+
`secondary_acceptable_latency_ms` parameters.
827821
828822
.. versionadded:: 2.7
829823
The ``compile_re`` parameter.
@@ -848,15 +842,11 @@ def find(self, *args, **kwargs):
848842
The `tailable` parameter.
849843
850844
.. mongodoc:: find
851-
.. _localThreshold: http://docs.mongodb.org/manual/reference/mongos/#cmdoption-mongos--localThreshold
852845
"""
853846
if not 'read_preference' in kwargs:
854847
kwargs['read_preference'] = self.read_preference
855848
if not 'tag_sets' in kwargs:
856849
kwargs['tag_sets'] = self.tag_sets
857-
if not 'secondary_acceptable_latency_ms' in kwargs:
858-
kwargs['secondary_acceptable_latency_ms'] = (
859-
self.secondary_acceptable_latency_ms)
860850
return Cursor(self, *args, **kwargs)
861851

862852
def parallel_scan(self, num_cursors, **kwargs):
@@ -907,8 +897,6 @@ def process_cursor(cursor):
907897
'numCursors': num_cursors,
908898
'read_preference': self.read_preference,
909899
'tag_sets': self.tag_sets,
910-
'secondary_acceptable_latency_ms': (
911-
self.secondary_acceptable_latency_ms),
912900
}
913901
command_kwargs.update(kwargs)
914902

@@ -1288,8 +1276,6 @@ def aggregate(self, pipeline, **kwargs):
12881276
'pipeline': pipeline,
12891277
'read_preference': self.read_preference,
12901278
'tag_sets': self.tag_sets,
1291-
'secondary_acceptable_latency_ms': (
1292-
self.secondary_acceptable_latency_ms),
12931279
}
12941280

12951281
command_kwargs.update(kwargs)
@@ -1363,8 +1349,6 @@ def group(self, key, condition, initial, reduce, finalize=None, **kwargs):
13631349
uuid_subtype=self.uuid_subtype,
13641350
read_preference=self.read_preference,
13651351
tag_sets=self.tag_sets,
1366-
secondary_acceptable_latency_ms=(
1367-
self.secondary_acceptable_latency_ms),
13681352
**kwargs)["retval"]
13691353

13701354
def rename(self, new_name, **kwargs):
@@ -1469,8 +1453,6 @@ def map_reduce(self, map, reduce, out, full_response=False, **kwargs):
14691453
map=map, reduce=reduce,
14701454
read_preference=self.read_preference,
14711455
tag_sets=self.tag_sets,
1472-
secondary_acceptable_latency_ms=(
1473-
self.secondary_acceptable_latency_ms),
14741456
out=out, **kwargs)
14751457

14761458
if full_response or not response.get('result'):
@@ -1519,8 +1501,6 @@ def inline_map_reduce(self, map, reduce, full_response=False, **kwargs):
15191501
uuid_subtype=self.uuid_subtype,
15201502
read_preference=self.read_preference,
15211503
tag_sets=self.tag_sets,
1522-
secondary_acceptable_latency_ms=(
1523-
self.secondary_acceptable_latency_ms),
15241504
map=map, reduce=reduce,
15251505
out={"inline": 1}, **kwargs)
15261506

pymongo/common.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ def validate_uuid_subtype(dummy, value):
271271
'read_preference': validate_read_preference,
272272
'readpreferencetags': validate_tag_sets,
273273
'tag_sets': validate_tag_sets,
274-
'secondaryacceptablelatencyms': validate_positive_float,
275-
'secondary_acceptable_latency_ms': validate_positive_float,
274+
'acceptablelatencyms': validate_positive_float,
276275
'auto_start_request': validate_boolean,
277276
'use_greenlets': validate_boolean,
278277
'authmechanism': validate_auth_mechanism,
@@ -341,7 +340,6 @@ def __init__(self, **options):
341340

342341
self.__read_pref = ReadPreference.PRIMARY
343342
self.__tag_sets = [{}]
344-
self.__secondary_acceptable_latency_ms = 15
345343
self.__uuid_subtype = OLD_UUID_SUBTYPE
346344
self.__write_concern = WriteConcern()
347345
self.__set_options(options)
@@ -368,12 +366,6 @@ def __set_options(self, options):
368366
self.__tag_sets = validate_tag_sets(option, value)
369367
elif option == 'uuidrepresentation':
370368
self.__uuid_subtype = validate_uuid_subtype(option, value)
371-
elif option in (
372-
'secondaryacceptablelatencyms',
373-
'secondary_acceptable_latency_ms'
374-
):
375-
self.__secondary_acceptable_latency_ms = \
376-
validate_positive_float(option, value)
377369
elif option in WRITE_CONCERN_OPTIONS:
378370
if option == 'journal':
379371
self.__set_write_concern_option('j', value)
@@ -465,31 +457,6 @@ def __set_read_pref(self, value):
465457

466458
read_preference = property(__get_read_pref, __set_read_pref)
467459

468-
def __get_acceptable_latency(self):
469-
"""Any replica-set member whose ping time is within
470-
secondary_acceptable_latency_ms of the nearest member may accept
471-
reads. Defaults to 15 milliseconds.
472-
473-
See :class:`~pymongo.read_preferences.ReadPreference`.
474-
475-
.. versionadded:: 2.3
476-
477-
.. note:: ``secondary_acceptable_latency_ms`` is ignored when talking
478-
to a replica set *through* a mongos. The equivalent is the
479-
localThreshold_ command line option.
480-
481-
.. _localThreshold: http://docs.mongodb.org/manual/reference/mongos/#cmdoption-mongos--localThreshold
482-
"""
483-
return self.__secondary_acceptable_latency_ms
484-
485-
def __set_acceptable_latency(self, value):
486-
"""Property setter for secondary_acceptable_latency_ms"""
487-
self.__secondary_acceptable_latency_ms = (validate_positive_float(
488-
'secondary_acceptable_latency_ms', value))
489-
490-
secondary_acceptable_latency_ms = property(
491-
__get_acceptable_latency, __set_acceptable_latency)
492-
493460
def __get_tag_sets(self):
494461
"""Set ``tag_sets`` to a list of dictionaries like [{'dc': 'ny'}] to
495462
read only from members whose ``dc`` tag has the value ``"ny"``.

0 commit comments

Comments
 (0)