Skip to content

Commit 387bfa0

Browse files
authored
PYTHON-2310 Remove MongoClient.fsync, unlock, and is_locked (#546)
1 parent c70071d commit 387bfa0

File tree

7 files changed

+49
-199
lines changed

7 files changed

+49
-199
lines changed

doc/api/pymongo/mongo_client.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,3 @@
4646
.. automethod:: close_cursor
4747
.. automethod:: kill_cursors
4848
.. automethod:: set_cursor_manager
49-
.. autoattribute:: is_locked
50-
.. automethod:: fsync
51-
.. automethod:: unlock

doc/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Breaking Changes in 4.0
1818
- Removed :meth:`~pymongo.database.Database.eval`,
1919
:data:`~pymongo.database.Database.system_js` and
2020
:class:`~pymongo.database.SystemJS`.
21+
- Removed :meth:`pymongo.mongo_client.MongoClient.fsync`,
22+
:meth:`pymongo.mongo_client.MongoClient.unlock`, and
23+
:attr:`pymongo.mongo_client.MongoClient.is_locked`.
2124
- Removed :mod:`~pymongo.thread_util`.
2225

2326
Notable improvements

doc/migrate-to-pymongo4.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,52 @@ Warnings can also be changed to errors::
5050
.. note:: Not all deprecated features raise :exc:`DeprecationWarning` when
5151
used. See `Removed features with no migration path`_.
5252

53+
MongoClient
54+
-----------
55+
56+
MongoClient.fsync is removed
57+
............................
58+
59+
Removed :meth:`pymongo.mongo_client.MongoClient.fsync`. Run the
60+
`fsync command`_ directly with :meth:`~pymongo.database.Database.command`
61+
instead. For example::
62+
63+
client.admin.command('fsync', lock=True)
64+
65+
.. _fsync command: https://docs.mongodb.com/manual/reference/command/fsync/
66+
67+
MongoClient.unlock is removed
68+
.............................
69+
70+
Removed :meth:`pymongo.mongo_client.MongoClient.unlock`. Users of MongoDB
71+
version 3.2 or newer can run the `fsyncUnlock command`_ directly with
72+
:meth:`~pymongo.database.Database.command`::
73+
74+
client.admin.command('fsyncUnlock')
75+
76+
Users of MongoDB version 2.6 and 3.0 can query the "unlock" virtual
77+
collection::
78+
79+
client.admin["$cmd.sys.unlock"].find_one()
80+
81+
.. _fsyncUnlock command: https://docs.mongodb.com/manual/reference/command/fsyncUnlock/
82+
83+
MongoClient.is_locked is removed
84+
................................
85+
86+
Removed :attr:`pymongo.mongo_client.MongoClient.is_locked`. Users of MongoDB
87+
version 3.2 or newer can run the `currentOp command`_ directly with
88+
:meth:`~pymongo.database.Database.command`::
89+
90+
is_locked = client.admin.command('currentOp').get('fsyncLock')
91+
92+
Users of MongoDB version 2.6 and 3.0 can query the "inprog" virtual
93+
collection::
94+
95+
is_locked = client.admin["$cmd.sys.inprog"].find_one().get('fsyncLock')
96+
97+
.. _currentOp command: https://docs.mongodb.com/manual/reference/command/currentOp/
98+
5399
Removed features with no migration path
54100
---------------------------------------
55101

pymongo/mongo_client.py

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,122 +2104,6 @@ def _database_default_options(self, name):
21042104
read_preference=ReadPreference.PRIMARY,
21052105
write_concern=DEFAULT_WRITE_CONCERN)
21062106

2107-
@property
2108-
def is_locked(self):
2109-
"""**DEPRECATED**: Is this server locked? While locked, all write
2110-
operations are blocked, although read operations may still be allowed.
2111-
Use :meth:`unlock` to unlock.
2112-
2113-
Deprecated. Users of MongoDB version 3.2 or newer can run the
2114-
`currentOp command`_ directly with
2115-
:meth:`~pymongo.database.Database.command`::
2116-
2117-
is_locked = client.admin.command('currentOp').get('fsyncLock')
2118-
2119-
Users of MongoDB version 2.6 and 3.0 can query the "inprog" virtual
2120-
collection::
2121-
2122-
is_locked = client.admin["$cmd.sys.inprog"].find_one().get('fsyncLock')
2123-
2124-
.. versionchanged:: 3.11
2125-
Deprecated.
2126-
2127-
.. _currentOp command: https://docs.mongodb.com/manual/reference/command/currentOp/
2128-
"""
2129-
warnings.warn("is_locked is deprecated. See the documentation for "
2130-
"more information.", DeprecationWarning, stacklevel=2)
2131-
ops = self._database_default_options('admin')._current_op()
2132-
return bool(ops.get('fsyncLock', 0))
2133-
2134-
def fsync(self, **kwargs):
2135-
"""**DEPRECATED**: Flush all pending writes to datafiles.
2136-
2137-
Optional parameters can be passed as keyword arguments:
2138-
- `lock`: If True lock the server to disallow writes.
2139-
- `async`: If True don't block while synchronizing.
2140-
- `session` (optional): a
2141-
:class:`~pymongo.client_session.ClientSession`.
2142-
2143-
.. note:: Starting with Python 3.7 `async` is a reserved keyword.
2144-
The async option to the fsync command can be passed using a
2145-
dictionary instead::
2146-
2147-
options = {'async': True}
2148-
client.fsync(**options)
2149-
2150-
Deprecated. Run the `fsync command`_ directly with
2151-
:meth:`~pymongo.database.Database.command` instead. For example::
2152-
2153-
client.admin.command('fsync', lock=True)
2154-
2155-
.. versionchanged:: 3.11
2156-
Deprecated.
2157-
2158-
.. versionchanged:: 3.6
2159-
Added ``session`` parameter.
2160-
2161-
.. warning:: `async` and `lock` can not be used together.
2162-
2163-
.. warning:: MongoDB does not support the `async` option
2164-
on Windows and will raise an exception on that
2165-
platform.
2166-
2167-
.. _fsync command: https://docs.mongodb.com/manual/reference/command/fsync/
2168-
"""
2169-
warnings.warn("fsync is deprecated. Use "
2170-
"client.admin.command('fsync') instead.",
2171-
DeprecationWarning, stacklevel=2)
2172-
self.admin.command("fsync",
2173-
read_preference=ReadPreference.PRIMARY, **kwargs)
2174-
2175-
def unlock(self, session=None):
2176-
"""**DEPRECATED**: Unlock a previously locked server.
2177-
2178-
:Parameters:
2179-
- `session` (optional): a
2180-
:class:`~pymongo.client_session.ClientSession`.
2181-
2182-
Deprecated. Users of MongoDB version 3.2 or newer can run the
2183-
`fsyncUnlock command`_ directly with
2184-
:meth:`~pymongo.database.Database.command`::
2185-
2186-
client.admin.command('fsyncUnlock')
2187-
2188-
Users of MongoDB version 2.6 and 3.0 can query the "unlock" virtual
2189-
collection::
2190-
2191-
client.admin["$cmd.sys.unlock"].find_one()
2192-
2193-
.. versionchanged:: 3.11
2194-
Deprecated.
2195-
2196-
.. versionchanged:: 3.6
2197-
Added ``session`` parameter.
2198-
2199-
.. _fsyncUnlock command: https://docs.mongodb.com/manual/reference/command/fsyncUnlock/
2200-
"""
2201-
warnings.warn("unlock is deprecated. Use "
2202-
"client.admin.command('fsyncUnlock') instead. For "
2203-
"MongoDB 2.6 and 3.0, see the documentation for "
2204-
"more information.",
2205-
DeprecationWarning, stacklevel=2)
2206-
cmd = SON([("fsyncUnlock", 1)])
2207-
with self._socket_for_writes(session) as sock_info:
2208-
if sock_info.max_wire_version >= 4:
2209-
try:
2210-
with self._tmp_session(session) as s:
2211-
sock_info.command(
2212-
"admin", cmd, session=s, client=self)
2213-
except OperationFailure as exc:
2214-
# Ignore "DB not locked" to replicate old behavior
2215-
if exc.code != 125:
2216-
raise
2217-
else:
2218-
message._first_batch(sock_info, "admin", "$cmd.sys.unlock",
2219-
{}, -1, True, self.codec_options,
2220-
ReadPreference.PRIMARY, cmd,
2221-
self._event_listeners)
2222-
22232107
def __enter__(self):
22242108
return self
22252109

test/test_client.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,44 +1148,6 @@ def test_ipv6(self):
11481148
self.assertTrue("pymongo_test" in dbs)
11491149
self.assertTrue("pymongo_test_bernie" in dbs)
11501150

1151-
@ignore_deprecations
1152-
@client_context.require_no_mongos
1153-
def test_fsync_lock_unlock(self):
1154-
if server_is_master_with_slave(client_context.client):
1155-
raise SkipTest('SERVER-7714')
1156-
1157-
self.assertFalse(self.client.is_locked)
1158-
# async flushing not supported on windows...
1159-
if sys.platform not in ('cygwin', 'win32'):
1160-
# Work around async becoming a reserved keyword in Python 3.7
1161-
opts = {'async': True}
1162-
self.client.fsync(**opts)
1163-
self.assertFalse(self.client.is_locked)
1164-
self.client.fsync(lock=True)
1165-
self.assertTrue(self.client.is_locked)
1166-
locked = True
1167-
self.client.unlock()
1168-
for _ in range(5):
1169-
locked = self.client.is_locked
1170-
if not locked:
1171-
break
1172-
time.sleep(1)
1173-
self.assertFalse(locked)
1174-
1175-
def test_deprecated_methods(self):
1176-
with warnings.catch_warnings():
1177-
warnings.simplefilter("error", DeprecationWarning)
1178-
with self.assertRaisesRegex(DeprecationWarning,
1179-
'is_locked is deprecated'):
1180-
_ = self.client.is_locked
1181-
if not client_context.is_mongos:
1182-
with self.assertRaisesRegex(DeprecationWarning,
1183-
'fsync is deprecated'):
1184-
self.client.fsync(lock=True)
1185-
with self.assertRaisesRegex(DeprecationWarning,
1186-
'unlock is deprecated'):
1187-
self.client.unlock()
1188-
11891151
def test_contextlib(self):
11901152
client = rs_or_single_client()
11911153
client.pymongo_test.drop_collection("test")

test/test_monitoring.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,32 +1336,6 @@ def test_first_batch_helper(self):
13361336
self.assertTrue('inprog' in succeeded.reply)
13371337
self.assertTrue('ok' in succeeded.reply)
13381338

1339-
if not client_context.is_mongos:
1340-
with ignore_deprecations():
1341-
self.client.fsync(lock=True)
1342-
self.listener.results.clear()
1343-
self.client.unlock()
1344-
# Wait for async unlock...
1345-
wait_until(
1346-
lambda: not self.client.is_locked, "unlock the database")
1347-
started = results['started'][0]
1348-
succeeded = results['succeeded'][0]
1349-
self.assertEqual(0, len(results['failed']))
1350-
self.assertIsInstance(started, monitoring.CommandStartedEvent)
1351-
expected = {'fsyncUnlock': 1}
1352-
self.assertEqualCommand(expected, started.command)
1353-
self.assertEqual('admin', started.database_name)
1354-
self.assertEqual('fsyncUnlock', started.command_name)
1355-
self.assertIsInstance(started.request_id, int)
1356-
self.assertEqual(self.client.address, started.connection_id)
1357-
self.assertIsInstance(succeeded, monitoring.CommandSucceededEvent)
1358-
self.assertIsInstance(succeeded.duration_micros, int)
1359-
self.assertEqual(started.command_name, succeeded.command_name)
1360-
self.assertEqual(started.request_id, succeeded.request_id)
1361-
self.assertEqual(started.connection_id, succeeded.connection_id)
1362-
self.assertTrue('info' in succeeded.reply)
1363-
self.assertTrue('ok' in succeeded.reply)
1364-
13651339
def test_sensitive_commands(self):
13661340
listeners = self.client._event_listeners
13671341

test/test_session.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,28 +230,12 @@ def test_end_sessions(self):
230230
@ignore_deprecations # fsync and unlock
231231
def test_client(self):
232232
client = self.client
233-
234-
# Make sure if the test fails we unlock the server.
235-
def unlock():
236-
try:
237-
client.unlock()
238-
except OperationFailure:
239-
pass
240-
241-
self.addCleanup(unlock)
242-
243233
ops = [
244234
(client.server_info, [], {}),
245235
(client.database_names, [], {}),
246236
(client.drop_database, ['pymongo_test'], {}),
247237
]
248238

249-
if not client_context.is_mongos:
250-
ops.extend([
251-
(client.fsync, [], {'lock': True}),
252-
(client.unlock, [], {}),
253-
])
254-
255239
self._test_ops(client, *ops)
256240

257241
def test_database(self):

0 commit comments

Comments
 (0)