Skip to content

Commit 8f2d868

Browse files
committed
PYTHON-1588 Remove deprecated killCursors APIs
1 parent 9dec2c9 commit 8f2d868

File tree

8 files changed

+25
-130
lines changed

8 files changed

+25
-130
lines changed

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/mongo_client.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,38 +1549,6 @@ def __getitem__(self, name):
15491549
"""
15501550
return database.Database(self, name)
15511551

1552-
def close_cursor(self, cursor_id, address=None):
1553-
"""DEPRECATED - Send a kill cursors message soon with the given id.
1554-
1555-
Raises :class:`TypeError` if `cursor_id` is not an instance of
1556-
``(int, long)``.
1557-
1558-
This method may be called from a :class:`~pymongo.cursor.Cursor`
1559-
destructor during garbage collection, so it isn't safe to take a
1560-
lock or do network I/O. Instead, we schedule the cursor to be closed
1561-
soon on a background thread.
1562-
1563-
:Parameters:
1564-
- `cursor_id`: id of cursor to close
1565-
- `address` (optional): (host, port) pair of the cursor's server.
1566-
If it is not provided, the client attempts to close the cursor on
1567-
the primary or standalone, or a mongos server.
1568-
1569-
.. versionchanged:: 3.7
1570-
Deprecated.
1571-
1572-
.. versionchanged:: 3.0
1573-
Added ``address`` parameter.
1574-
"""
1575-
warnings.warn(
1576-
"close_cursor is deprecated.",
1577-
DeprecationWarning,
1578-
stacklevel=2)
1579-
if not isinstance(cursor_id, integer_types):
1580-
raise TypeError("cursor_id must be an instance of (int, long)")
1581-
1582-
self._close_cursor(cursor_id, address)
1583-
15841552
def _close_cursor(self, cursor_id, address):
15851553
"""Send a kill cursors message with the given id.
15861554
@@ -1605,37 +1573,6 @@ def _close_cursor_now(self, cursor_id, address=None, session=None):
16051573
# Make another attempt to kill the cursor later.
16061574
self.__kill_cursors_queue.append((address, [cursor_id]))
16071575

1608-
def kill_cursors(self, cursor_ids, address=None):
1609-
"""DEPRECATED - Send a kill cursors message soon with the given ids.
1610-
1611-
Raises :class:`TypeError` if `cursor_ids` is not an instance of
1612-
``list``.
1613-
1614-
:Parameters:
1615-
- `cursor_ids`: list of cursor ids to kill
1616-
- `address` (optional): (host, port) pair of the cursor's server.
1617-
If it is not provided, the client attempts to close the cursor on
1618-
the primary or standalone, or a mongos server.
1619-
1620-
.. versionchanged:: 3.3
1621-
Deprecated.
1622-
1623-
.. versionchanged:: 3.0
1624-
Now accepts an `address` argument. Schedules the cursors to be
1625-
closed on a background thread instead of sending the message
1626-
immediately.
1627-
"""
1628-
warnings.warn(
1629-
"kill_cursors is deprecated.",
1630-
DeprecationWarning,
1631-
stacklevel=2)
1632-
1633-
if not isinstance(cursor_ids, list):
1634-
raise TypeError("cursor_ids must be a list")
1635-
1636-
# "Atomic", needs no lock.
1637-
self.__kill_cursors_queue.append((address, cursor_ids))
1638-
16391576
def _kill_cursors(self, cursor_ids, address, topology, session):
16401577
"""Send a kill cursors message with the given ids."""
16411578
listeners = self._event_listeners

test/test_legacy_api.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,63 +1366,6 @@ def run(self):
13661366
self.assertEqual(10001, coll.count())
13671367
coll.drop()
13681368

1369-
def test_kill_cursors_with_cursoraddress(self):
1370-
coll = self.client.pymongo_test.test
1371-
coll.drop()
1372-
1373-
coll.insert_many([{'_id': i} for i in range(200)])
1374-
cursor = coll.find().batch_size(1)
1375-
next(cursor)
1376-
self.client.kill_cursors(
1377-
[cursor.cursor_id],
1378-
_CursorAddress(self.client.address, coll.full_name))
1379-
1380-
# Prevent killcursors from reaching the server while a getmore is in
1381-
# progress -- the server logs "Assertion: 16089:Cannot kill active
1382-
# cursor."
1383-
time.sleep(2)
1384-
1385-
def raises_cursor_not_found():
1386-
try:
1387-
next(cursor)
1388-
return False
1389-
except CursorNotFound:
1390-
return True
1391-
1392-
wait_until(raises_cursor_not_found, 'close cursor')
1393-
1394-
def test_kill_cursors_with_tuple(self):
1395-
# Some evergreen distros (Debian 7.1) still test against 3.6.5 where
1396-
# OP_KILL_CURSORS does not work.
1397-
if (client_context.is_mongos and client_context.auth_enabled and
1398-
(3, 6, 0) <= client_context.version < (3, 6, 6)):
1399-
raise SkipTest("SERVER-33553 This server version does not support "
1400-
"OP_KILL_CURSORS")
1401-
1402-
coll = self.client.pymongo_test.test
1403-
coll.drop()
1404-
1405-
coll.insert_many([{'_id': i} for i in range(200)])
1406-
cursor = coll.find().batch_size(1)
1407-
next(cursor)
1408-
self.client.kill_cursors(
1409-
[cursor.cursor_id],
1410-
self.client.address)
1411-
1412-
# Prevent killcursors from reaching the server while a getmore is in
1413-
# progress -- the server logs "Assertion: 16089:Cannot kill active
1414-
# cursor."
1415-
time.sleep(2)
1416-
1417-
def raises_cursor_not_found():
1418-
try:
1419-
next(cursor)
1420-
return False
1421-
except CursorNotFound:
1422-
return True
1423-
1424-
wait_until(raises_cursor_not_found, 'close cursor')
1425-
14261369

14271370
class TestLegacyBulk(BulkTestBase):
14281371

0 commit comments

Comments
 (0)