Skip to content

Commit 3c899ae

Browse files
authored
PYTHON-1592 Remove Collection.parallel_scan (#547)
1 parent 387bfa0 commit 3c899ae

File tree

6 files changed

+14
-180
lines changed

6 files changed

+14
-180
lines changed

doc/api/pymongo/collection.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
.. automethod:: options
6969
.. automethod:: map_reduce
7070
.. automethod:: inline_map_reduce
71-
.. automethod:: parallel_scan
7271
.. automethod:: initialize_unordered_bulk_op
7372
.. automethod:: initialize_ordered_bulk_op
7473
.. automethod:: group

doc/changelog.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ Breaking Changes in 4.0
1515
.......................
1616

1717
- Removed support for Python 2.7, 3.4, and 3.5. Python 3.6+ is now required.
18-
- Removed :meth:`~pymongo.database.Database.eval`,
19-
:data:`~pymongo.database.Database.system_js` and
20-
:class:`~pymongo.database.SystemJS`.
18+
- Removed :meth:`pymongo.database.Database.eval`,
19+
:data:`pymongo.database.Database.system_js` and
20+
:class:`pymongo.database.SystemJS`.
2121
- Removed :meth:`pymongo.mongo_client.MongoClient.fsync`,
2222
:meth:`pymongo.mongo_client.MongoClient.unlock`, and
2323
:attr:`pymongo.mongo_client.MongoClient.is_locked`.
24-
- Removed :mod:`~pymongo.thread_util`.
24+
- Removed :meth:`pymongo.collection.Collection.parallel_scan`.
25+
- Removed :mod:`pymongo.thread_util`.
2526

2627
Notable improvements
2728
....................

doc/migrate-to-pymongo4.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,12 @@ can be changed to this::
116116

117117
>>> from bson.code import Code
118118
>>> result = database.command('eval', Code('function (x) {return x;}'), args=[3]).get('retval')
119+
120+
121+
Collection.parallel_scan is removed
122+
...................................
123+
124+
Removed :meth:`~pymongo.collection.Collection.parallel_scan`. MongoDB 4.2
125+
removed the `parallelCollectionScan command`_. There is no replacement.
126+
127+
.. _parallelCollectionScan command: https://docs.mongodb.com/manual/reference/command/parallelCollectionScan/

pymongo/collection.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,93 +1559,6 @@ def find_raw_batches(self, *args, **kwargs):
15591559

15601560
return RawBatchCursor(self, *args, **kwargs)
15611561

1562-
def parallel_scan(self, num_cursors, session=None, **kwargs):
1563-
"""**DEPRECATED**: Scan this entire collection in parallel.
1564-
1565-
Returns a list of up to ``num_cursors`` cursors that can be iterated
1566-
concurrently. As long as the collection is not modified during
1567-
scanning, each document appears once in one of the cursors result
1568-
sets.
1569-
1570-
For example, to process each document in a collection using some
1571-
thread-safe ``process_document()`` function:
1572-
1573-
>>> def process_cursor(cursor):
1574-
... for document in cursor:
1575-
... # Some thread-safe processing function:
1576-
... process_document(document)
1577-
>>>
1578-
>>> # Get up to 4 cursors.
1579-
...
1580-
>>> cursors = collection.parallel_scan(4)
1581-
>>> threads = [
1582-
... threading.Thread(target=process_cursor, args=(cursor,))
1583-
... for cursor in cursors]
1584-
>>>
1585-
>>> for thread in threads:
1586-
... thread.start()
1587-
>>>
1588-
>>> for thread in threads:
1589-
... thread.join()
1590-
>>>
1591-
>>> # All documents have now been processed.
1592-
1593-
The :meth:`parallel_scan` method obeys the :attr:`read_preference` of
1594-
this :class:`Collection`.
1595-
1596-
:Parameters:
1597-
- `num_cursors`: the number of cursors to return
1598-
- `session` (optional): a
1599-
:class:`~pymongo.client_session.ClientSession`.
1600-
- `**kwargs`: additional options for the parallelCollectionScan
1601-
command can be passed as keyword arguments.
1602-
1603-
.. note:: Requires server version **>= 2.5.5**.
1604-
1605-
.. versionchanged:: 3.7
1606-
Deprecated.
1607-
1608-
.. versionchanged:: 3.6
1609-
Added ``session`` parameter.
1610-
1611-
.. versionchanged:: 3.4
1612-
Added back support for arbitrary keyword arguments. MongoDB 3.4
1613-
adds support for maxTimeMS as an option to the
1614-
parallelCollectionScan command.
1615-
1616-
.. versionchanged:: 3.0
1617-
Removed support for arbitrary keyword arguments, since
1618-
the parallelCollectionScan command has no optional arguments.
1619-
"""
1620-
warnings.warn("parallel_scan is deprecated. MongoDB 4.2 will remove "
1621-
"the parallelCollectionScan command.",
1622-
DeprecationWarning, stacklevel=2)
1623-
cmd = SON([('parallelCollectionScan', self.__name),
1624-
('numCursors', num_cursors)])
1625-
cmd.update(kwargs)
1626-
1627-
with self._socket_for_reads(session) as (sock_info, slave_ok):
1628-
# We call sock_info.command here directly, instead of
1629-
# calling self._command to avoid using an implicit session.
1630-
result = sock_info.command(
1631-
self.__database.name,
1632-
cmd,
1633-
slave_ok,
1634-
self._read_preference_for(session),
1635-
self.codec_options,
1636-
read_concern=self.read_concern,
1637-
parse_write_concern_error=True,
1638-
session=session,
1639-
client=self.__database.client)
1640-
1641-
cursors = []
1642-
for cursor in result['cursors']:
1643-
cursors.append(CommandCursor(
1644-
self, cursor['cursor'], sock_info.address,
1645-
session=session, explicit_session=session is not None))
1646-
1647-
return cursors
1648-
16491562
def _count(self, cmd, collation=None, session=None):
16501563
"""Internal count helper."""
16511564
# XXX: "ns missing" checks can be removed when we drop support for

test/test_collection.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,52 +1737,6 @@ def test_aggregation_cursor_alive(self):
17371737

17381738
self.assertTrue(cursor.alive)
17391739

1740-
@client_context.require_no_mongos
1741-
@client_context.require_version_max(4, 1, 0)
1742-
@ignore_deprecations
1743-
def test_parallel_scan(self):
1744-
db = self.db
1745-
db.drop_collection("test")
1746-
if client_context.has_secondaries:
1747-
# Test that getMore messages are sent to the right server.
1748-
db = self.client.get_database(
1749-
db.name,
1750-
read_preference=ReadPreference.SECONDARY,
1751-
write_concern=WriteConcern(w=self.w))
1752-
1753-
coll = db.test
1754-
coll.insert_many([{'_id': i} for i in range(8000)])
1755-
docs = []
1756-
threads = [threading.Thread(target=docs.extend, args=(cursor,))
1757-
for cursor in coll.parallel_scan(3)]
1758-
for t in threads:
1759-
t.start()
1760-
for t in threads:
1761-
t.join()
1762-
1763-
self.assertEqual(
1764-
set(range(8000)),
1765-
set(doc['_id'] for doc in docs))
1766-
1767-
@client_context.require_no_mongos
1768-
@client_context.require_version_min(3, 3, 10)
1769-
@client_context.require_version_max(4, 1, 0)
1770-
@client_context.require_test_commands
1771-
@ignore_deprecations
1772-
def test_parallel_scan_max_time_ms(self):
1773-
self.client.admin.command("configureFailPoint",
1774-
"maxTimeAlwaysTimeOut",
1775-
mode="alwaysOn")
1776-
try:
1777-
self.assertRaises(ExecutionTimeout,
1778-
self.db.test.parallel_scan,
1779-
3,
1780-
maxTimeMS=1)
1781-
finally:
1782-
self.client.admin.command("configureFailPoint",
1783-
"maxTimeAlwaysTimeOut",
1784-
mode="off")
1785-
17861740
def test_large_limit(self):
17871741
db = self.db
17881742
db.drop_collection("test_large_limit")

test/test_session.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -323,40 +323,6 @@ def test_collection(self):
323323

324324
self._test_ops(client, *ops)
325325

326-
@client_context.require_no_mongos
327-
@client_context.require_version_max(4, 1, 0)
328-
@ignore_deprecations
329-
def test_parallel_collection_scan(self):
330-
listener = self.listener
331-
client = self.client
332-
coll = client.pymongo_test.collection
333-
coll.insert_many([{'_id': i} for i in range(1000)])
334-
335-
listener.results.clear()
336-
337-
def scan(session=None):
338-
cursors = coll.parallel_scan(4, session=session)
339-
for c in cursors:
340-
c.batch_size(2)
341-
list(c)
342-
343-
listener.results.clear()
344-
with client.start_session() as session:
345-
scan(session)
346-
cursor_lsids = {}
347-
for event in listener.results['started']:
348-
self.assertIn(
349-
'lsid', event.command,
350-
"parallel_scan sent no lsid with %s" % (event.command_name, ))
351-
352-
if event.command_name == 'getMore':
353-
cursor_id = event.command['getMore']
354-
if cursor_id in cursor_lsids:
355-
self.assertEqual(cursor_lsids[cursor_id],
356-
event.command['lsid'])
357-
else:
358-
cursor_lsids[cursor_id] = event.command['lsid']
359-
360326
def test_cursor_clone(self):
361327
coll = self.client.pymongo_test.collection
362328
# Ensure some batches.
@@ -874,14 +840,6 @@ def test_reads(self):
874840
lambda coll, session: coll.inline_map_reduce(
875841
'function() {}', 'function() {}', session=session),
876842
exception=map_reduce_exc)
877-
if (not client_context.is_mongos and
878-
not client_context.version.at_least(4, 1, 0)):
879-
def scan(coll, session):
880-
cursors = coll.parallel_scan(1, session=session)
881-
for cur in cursors:
882-
list(cur)
883-
self._test_reads(
884-
lambda coll, session: scan(coll, session=session))
885843

886844
self.assertRaises(
887845
ConfigurationError,

0 commit comments

Comments
 (0)