Skip to content

Commit ee275b9

Browse files
committed
⚡ perf(api): skip path guards on unshared locks
1 parent b2a0ddb commit ee275b9

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

‎docs/concepts.rst‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,13 @@ claim by age, a strict lock needs no liveness guess; a claim it cannot read with
670670
:class:`SoftFileLockProtocolError <filelock.SoftFileLockProtocolError>` rather than reclaiming it.
671671

672672
A :class:`SoftFileLease <filelock.SoftFileLease>` can expire while its holder is still working. If the heartbeat
673-
detects a lost claim, it calls ``on_compromise``. Further acquires on that instance raise ``RuntimeError`` until the holder
674-
releases it.
673+
detects a lost claim, it calls ``on_compromise``. Further acquires on that instance raise ``RuntimeError`` until the
674+
holder releases it.
675675

676-
The :attr:`token <filelock.SoftFileLease.token>` identifies the claim. A paused holder can resume and write after a peer
677-
takes the lease. To fence those writes, the protected resource must atomically track the highest generation it has
678-
accepted and reject operations from earlier generations.
676+
The :attr:`token <filelock.SoftFileLease.token>` identifies the claim. It does **not** fence the protected resource.
677+
A paused holder can resume and write after another process takes the lease. Fencing requires a linearizable resource
678+
that rejects any operation carrying a generation lower than the highest it has accepted. Chubby's lock sequence
679+
number and ZooKeeper's ``zxid`` can supply generations for the resource to check.
679680

680681
A lease expires on the contender's own clock. The holder's heartbeat rewrites the marker's modification time, and a
681682
contender times how long that time stays the same on its ``time.monotonic()``, the rule :class:`SoftReadWriteLock

‎src/filelock/_api.py‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -992,11 +992,8 @@ def acquire(
992992
"""
993993
self._raise_if_inherited()
994994
state = self._hold_state()
995-
if timeout is None:
996-
timeout = state.timeout
997-
998-
if blocking is None:
999-
blocking = state.blocking
995+
timeout = state.timeout if timeout is None else timeout
996+
blocking = state.blocking if blocking is None else blocking
1000997

1001998
# A truthy non-bool such as the string "false" would otherwise turn a single attempt into a blocking wait.
1002999
check_blocking(blocking)
@@ -1133,7 +1130,7 @@ def _raise_if_hold_unusable(self) -> None:
11331130

11341131
def _resolve_lock_path(self) -> str:
11351132
resolved = canonical(self.lock_file)
1136-
if not self.is_locked and self._singleton_shared and path_key(resolved) != self._singleton_key:
1133+
if self._singleton_shared and not self.is_locked and path_key(resolved) != self._singleton_key:
11371134
msg = f"singleton lock path changed after sharing: {self.lock_file}"
11381135
raise RuntimeError(msg)
11391136
return resolved

0 commit comments

Comments
 (0)