Skip to content

Commit cfa2348

Browse files
aherlihybehackett
authored andcommitted
PYTHON-979 - Use fsync command
1 parent ec47de7 commit cfa2348

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pymongo/mongo_client.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from bson.son import SON
4444
from pymongo import (common,
4545
database,
46+
helpers,
4647
message,
4748
periodic_executor,
4849
uri_parser)
@@ -1091,9 +1092,18 @@ def fsync(self, **kwargs):
10911092
def unlock(self):
10921093
"""Unlock a previously locked server.
10931094
"""
1094-
coll = self.admin.get_collection(
1095-
"$cmd.sys.unlock", read_preference=ReadPreference.PRIMARY)
1096-
coll.find_one()
1095+
with self._socket_for_writes() as sock_info:
1096+
if sock_info.max_wire_version >= 4:
1097+
try:
1098+
sock_info.command("admin", {"fsyncUnlock": 1})
1099+
except OperationFailure as exc:
1100+
# Ignore "DB not locked" to replicate old behavior
1101+
if exc.code != 125:
1102+
raise
1103+
else:
1104+
helpers._first_batch(sock_info, "admin.$cmd.sys.unlock",
1105+
{}, -1, True, self.codec_options, ReadPreference.PRIMARY)
1106+
10971107

10981108
def __enter__(self):
10991109
return self

0 commit comments

Comments
 (0)