Skip to content

Commit 3f19094

Browse files
committed
PYTHON-1588 Remove deprecated killCursors APIs
1 parent 4589d75 commit 3f19094

File tree

9 files changed

+25
-133
lines changed

9 files changed

+25
-133
lines changed

doc/api/pymongo/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Sub-modules:
3838
collection
3939
command_cursor
4040
cursor
41-
cursor_manager
4241
database
4342
driver_info
4443
encryption

doc/api/pymongo/mongo_client.rst

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

doc/api/pymongo/mongo_replica_set_client.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,4 @@
2727
.. automethod:: database_names
2828
.. automethod:: drop_database
2929
.. automethod:: get_database
30-
.. automethod:: close_cursor
31-
.. automethod:: kill_cursors
32-
.. automethod:: set_cursor_manager
3330
.. automethod:: get_default_database

doc/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Breaking Changes in 4.0
2222
:meth:`pymongo.mongo_client.MongoClient.unlock`, and
2323
:attr:`pymongo.mongo_client.MongoClient.is_locked`.
2424
- Removed :meth:`pymongo.collection.Collection.parallel_scan`.
25+
- Removed :meth:`pymongo.mongo_client.MongoClient.close_cursor`. Use
26+
:meth:`pymongo.cursor.Cursor.close` instead.
27+
- Removed :meth:`pymongo.mongo_client.MongoClient.kill_cursors`.
28+
- Removed :class:`pymongo.cursor_manager.CursorManager` and
29+
:mod:`pymongo.cursor_manager`.
30+
- Removed :meth:`pymongo.mongo_client.MongoClient.set_cursor_manager`.
2531
- Removed :mod:`pymongo.thread_util`.
2632

2733
Notable improvements

doc/migrate-to-pymongo4.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ collection::
9999
Removed features with no migration path
100100
---------------------------------------
101101

102+
cursor_manager support is removed
103+
.................................
104+
105+
Removed :class:`pymongo.cursor_manager.CursorManager`,
106+
:mod:`pymongo.cursor_manager`, and
107+
:meth:`pymongo.mongo_client.MongoClient.set_cursor_manager`.
108+
109+
MongoClient.close_cursor is removed
110+
...................................
111+
112+
Removed :meth:`pymongo.mongo_client.MongoClient.close_cursor` and
113+
:meth:`pymongo.mongo_client.MongoClient.kill_cursors`. Instead, close cursors
114+
with :meth:`pymongo.cursor.Cursor.close` or
115+
:meth:`pymongo.command_cursor.CommandCursor.close`.
116+
117+
.. _killCursors command: https://docs.mongodb.com/manual/reference/command/killCursors/
118+
102119
Database.eval, Database.system_js, and SystemJS are removed
103120
...........................................................
104121

@@ -117,7 +134,6 @@ can be changed to this::
117134
>>> from bson.code import Code
118135
>>> result = database.command('eval', Code('function (x) {return x;}'), args=[3]).get('retval')
119136

120-
121137
Collection.parallel_scan is removed
122138
...................................
123139

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
@@ -1551,38 +1551,6 @@ def __getitem__(self, name):
15511551
"""
15521552
return database.Database(self, name)
15531553

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

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