Skip to content

Commit 0e250be

Browse files
ShaneHarveykaldown
andauthored
PYTHON-1301/PYTHON-1302/PYTHON-1588 Remove deprecated cursor manager APIs (#550)
Remove MongoClient.set_cursor_manager and pymongo.cursor_manager. Remove MongoClient.kill_cursors and MongoClient.close_cursor. Co-authored-by: kAldown <[email protected]>
1 parent 56925fd commit 0e250be

12 files changed

+36
-344
lines changed

doc/api/pymongo/cursor_manager.rst

Lines changed: 0 additions & 6 deletions
This file was deleted.

doc/api/pymongo/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Sub-modules:
3434
collection
3535
command_cursor
3636
cursor
37-
cursor_manager
3837
database
3938
driver_info
4039
encryption

doc/api/pymongo/mongo_client.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,3 @@
4242
.. automethod:: get_database
4343
.. automethod:: server_info
4444
.. automethod:: watch
45-
.. automethod:: close_cursor
46-
.. automethod:: kill_cursors
47-
.. automethod:: set_cursor_manager

doc/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Breaking Changes in 4.0
2424
- Removed :meth:`pymongo.mongo_client.MongoClient.database_names`.
2525
- Removed :meth:`pymongo.database.Database.collection_names`.
2626
- Removed :meth:`pymongo.collection.Collection.parallel_scan`.
27+
- Removed :meth:`pymongo.mongo_client.MongoClient.close_cursor`. Use
28+
:meth:`pymongo.cursor.Cursor.close` instead.
29+
- Removed :meth:`pymongo.mongo_client.MongoClient.kill_cursors`.
30+
- Removed :class:`pymongo.cursor_manager.CursorManager` and
31+
:mod:`pymongo.cursor_manager`.
32+
- Removed :meth:`pymongo.mongo_client.MongoClient.set_cursor_manager`.
2733
- Removed :mod:`pymongo.thread_util`.
2834
- Removed :class:`~pymongo.mongo_replica_set_client.MongoReplicaSetClient`.
2935

doc/migrate-to-pymongo4.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ can be changed to this::
139139
Removed features with no migration path
140140
---------------------------------------
141141

142+
cursor_manager support is removed
143+
.................................
144+
145+
Removed :class:`pymongo.cursor_manager.CursorManager`,
146+
:mod:`pymongo.cursor_manager`, and
147+
:meth:`pymongo.mongo_client.MongoClient.set_cursor_manager`.
148+
149+
MongoClient.close_cursor is removed
150+
...................................
151+
152+
Removed :meth:`pymongo.mongo_client.MongoClient.close_cursor` and
153+
:meth:`pymongo.mongo_client.MongoClient.kill_cursors`. Instead, close cursors
154+
with :meth:`pymongo.cursor.Cursor.close` or
155+
:meth:`pymongo.command_cursor.CommandCursor.close`.
156+
157+
.. _killCursors command: https://docs.mongodb.com/manual/reference/command/killCursors/
158+
142159
Database.eval, Database.system_js, and SystemJS are removed
143160
...........................................................
144161

@@ -157,7 +174,6 @@ can be changed to this::
157174
>>> from bson.code import Code
158175
>>> result = database.command('eval', Code('function (x) {return x;}'), args=[3]).get('retval')
159176

160-
161177
Collection.parallel_scan is removed
162178
...................................
163179

pymongo/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
# Frequency to call ismaster on servers, in seconds.
6464
HEARTBEAT_FREQUENCY = 10
6565

66-
# Frequency to process kill-cursors, in seconds. See MongoClient.close_cursor.
66+
# Frequency to clean up unclosed cursors, in seconds.
67+
# See MongoClient._process_kill_cursors.
6768
KILL_CURSOR_FREQUENCY = 1
6869

6970
# Frequency to process events queue, in seconds.

pymongo/cursor.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,10 +1171,6 @@ def alive(self):
11711171
def cursor_id(self):
11721172
"""Returns the id of the cursor
11731173
1174-
Useful if you need to manage cursor ids and want to handle killing
1175-
cursors manually using
1176-
:meth:`~pymongo.mongo_client.MongoClient.kill_cursors`
1177-
11781174
.. versionadded:: 2.2
11791175
"""
11801176
return self.__id

pymongo/cursor_manager.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

pymongo/mongo_client.py

Lines changed: 8 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
from pymongo.change_stream import ClusterChangeStream
5454
from pymongo.client_options import ClientOptions
5555
from pymongo.command_cursor import CommandCursor
56-
from pymongo.cursor_manager import CursorManager
5756
from pymongo.errors import (AutoReconnect,
5857
BulkWriteError,
5958
ConfigurationError,
@@ -704,7 +703,6 @@ def __init__(
704703

705704
self.__default_database_name = dbase
706705
self.__lock = threading.Lock()
707-
self.__cursor_manager = None
708706
self.__kill_cursors_queue = []
709707

710708
self._event_listeners = options.pool_options.event_listeners
@@ -1209,35 +1207,6 @@ def close(self):
12091207
# TODO: PYTHON-1921 Encrypted MongoClients cannot be re-opened.
12101208
self._encrypter.close()
12111209

1212-
def set_cursor_manager(self, manager_class):
1213-
"""DEPRECATED - Set this client's cursor manager.
1214-
1215-
Raises :class:`TypeError` if `manager_class` is not a subclass of
1216-
:class:`~pymongo.cursor_manager.CursorManager`. A cursor manager
1217-
handles closing cursors. Different managers can implement different
1218-
policies in terms of when to actually kill a cursor that has
1219-
been closed.
1220-
1221-
:Parameters:
1222-
- `manager_class`: cursor manager to use
1223-
1224-
.. versionchanged:: 3.3
1225-
Deprecated, for real this time.
1226-
1227-
.. versionchanged:: 3.0
1228-
Undeprecated.
1229-
"""
1230-
warnings.warn(
1231-
"set_cursor_manager is Deprecated",
1232-
DeprecationWarning,
1233-
stacklevel=2)
1234-
manager = manager_class(self)
1235-
if not isinstance(manager, CursorManager):
1236-
raise TypeError("manager_class must be a subclass of "
1237-
"CursorManager")
1238-
1239-
self.__cursor_manager = manager
1240-
12411210
def _get_topology(self):
12421211
"""Get the internal :class:`~pymongo.topology.Topology` object.
12431212
@@ -1580,101 +1549,29 @@ def __getitem__(self, name):
15801549
"""
15811550
return database.Database(self, name)
15821551

1583-
def close_cursor(self, cursor_id, address=None):
1584-
"""DEPRECATED - Send a kill cursors message soon with the given id.
1585-
1586-
Raises :class:`TypeError` if `cursor_id` is not an instance of
1587-
``(int, long)``. What closing the cursor actually means
1588-
depends on this client's cursor manager.
1589-
1590-
This method may be called from a :class:`~pymongo.cursor.Cursor`
1591-
destructor during garbage collection, so it isn't safe to take a
1592-
lock or do network I/O. Instead, we schedule the cursor to be closed
1593-
soon on a background thread.
1594-
1595-
:Parameters:
1596-
- `cursor_id`: id of cursor to close
1597-
- `address` (optional): (host, port) pair of the cursor's server.
1598-
If it is not provided, the client attempts to close the cursor on
1599-
the primary or standalone, or a mongos server.
1600-
1601-
.. versionchanged:: 3.7
1602-
Deprecated.
1603-
1604-
.. versionchanged:: 3.0
1605-
Added ``address`` parameter.
1606-
"""
1607-
warnings.warn(
1608-
"close_cursor is deprecated.",
1609-
DeprecationWarning,
1610-
stacklevel=2)
1611-
if not isinstance(cursor_id, integer_types):
1612-
raise TypeError("cursor_id must be an instance of (int, long)")
1613-
1614-
self._close_cursor(cursor_id, address)
1615-
16161552
def _close_cursor(self, cursor_id, address):
16171553
"""Send a kill cursors message with the given id.
16181554
16191555
What closing the cursor actually means depends on this client's
16201556
cursor manager. If there is none, the cursor is closed asynchronously
16211557
on a background thread.
16221558
"""
1623-
if self.__cursor_manager is not None:
1624-
self.__cursor_manager.close(cursor_id, address)
1625-
else:
1626-
self.__kill_cursors_queue.append((address, [cursor_id]))
1559+
self.__kill_cursors_queue.append((address, [cursor_id]))
16271560

16281561
def _close_cursor_now(self, cursor_id, address=None, session=None):
16291562
"""Send a kill cursors message with the given id.
16301563
1631-
What closing the cursor actually means depends on this client's
1632-
cursor manager. If there is none, the cursor is closed synchronously
1633-
on the current thread.
1564+
The cursor is closed synchronously on the current thread.
16341565
"""
16351566
if not isinstance(cursor_id, integer_types):
16361567
raise TypeError("cursor_id must be an instance of (int, long)")
16371568

1638-
if self.__cursor_manager is not None:
1639-
self.__cursor_manager.close(cursor_id, address)
1640-
else:
1641-
try:
1642-
self._kill_cursors(
1643-
[cursor_id], address, self._get_topology(), session)
1644-
except PyMongoError:
1645-
# Make another attempt to kill the cursor later.
1646-
self.__kill_cursors_queue.append((address, [cursor_id]))
1647-
1648-
def kill_cursors(self, cursor_ids, address=None):
1649-
"""DEPRECATED - Send a kill cursors message soon with the given ids.
1650-
1651-
Raises :class:`TypeError` if `cursor_ids` is not an instance of
1652-
``list``.
1653-
1654-
:Parameters:
1655-
- `cursor_ids`: list of cursor ids to kill
1656-
- `address` (optional): (host, port) pair of the cursor's server.
1657-
If it is not provided, the client attempts to close the cursor on
1658-
the primary or standalone, or a mongos server.
1659-
1660-
.. versionchanged:: 3.3
1661-
Deprecated.
1662-
1663-
.. versionchanged:: 3.0
1664-
Now accepts an `address` argument. Schedules the cursors to be
1665-
closed on a background thread instead of sending the message
1666-
immediately.
1667-
"""
1668-
warnings.warn(
1669-
"kill_cursors is deprecated.",
1670-
DeprecationWarning,
1671-
stacklevel=2)
1672-
1673-
if not isinstance(cursor_ids, list):
1674-
raise TypeError("cursor_ids must be a list")
1675-
1676-
# "Atomic", needs no lock.
1677-
self.__kill_cursors_queue.append((address, cursor_ids))
1569+
try:
1570+
self._kill_cursors(
1571+
[cursor_id], address, self._get_topology(), session)
1572+
except PyMongoError:
1573+
# Make another attempt to kill the cursor later.
1574+
self.__kill_cursors_queue.append((address, [cursor_id]))
16781575

16791576
def _kill_cursors(self, cursor_ids, address, topology, session):
16801577
"""Send a kill cursors message with the given ids."""

0 commit comments

Comments
 (0)