Repository navigation
FileLock: re-resolve the lock path only when the target file changed (#214) - #225
Merged
Merged
Conversation
…214) FileLock resolved its target with realpath (one lstat per path component) on every entry. It now remembers the identity of the file the path named when it resolved (one lstat, plus a stat through a symlink) and resolves again only when that identity changed or cannot be told (missing file, no inode numbers). A retargeted link, a replaced file and another working directory are still followed. Measured on a 13-component path: entry 50.7 -> 8.4 us, LockedAppender.append 68 -> 18 us. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…214 review) The first version checked the target file's identity, which a file moved to another folder keeps (as does a file recreated on a reused inode): the cached lock path went stale and two FileLocks on one file could both hold. The cache is now valid only while the target is not itself a symlink and its folder is the lock file's folder (same device and inode), which matches a fresh resolution exactly. Tests for the moved-file and mv+chdir cases; entry 50 -> 14 us, append 68 -> 25 us. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… round 2) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
Adversarial review, round 2 (independent Opus subagent, on aafa2b0): merge. No case found where the check passes and mutual exclusion breaks. It tried directory inode reuse, a folder recreated or mounted over, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #214.
FileLock.__enter__resolved its target withos.path.realpath(onelstatper path component) plus the lock-name normalisation on every entry. That was most of the cost ofLockedAppender.append, which access trackers call on every store read.Change.
FileLockkeeps its resolved lock path while a cheap check says a fresh resolution would give the same path: the target is not itself a symlink, and its folder is the folder the lock file sits in (statof both, same device and inode; a folder has one real path). Otherwise, including whenever this cannot be told (a symlink target, a folder gone, no inode numbers), it resolves again as before. There is no public API change, and the lock path is the one master computes in every case, so the #188 guarantees hold: a retargeted link, a moved folder and a changed working directory are all followed.Measured (Linux, path 13 components deep, min of 5×20000):
FileLockenter+exitLockedAppender.appendA target that is itself a symlink pays three extra
statcalls per entry, since it resolves every time, as before.Review (independent Opus subagent). Round 1 found a blocker in the first version, which checked the target file's identity. A file moved to another folder keeps its inode, and so does a file recreated on a reused inode (ext4 reused it 50 times in 50). The cached path then went stale, and two
FileLocks on one file could both hold at once. The reviewer reproduced this. Fixed in aafa2b0 with the reviewer's folder-identity check. The reviewer also flagged that one test passed on master and would pass with a cache that never expires; it was replaced by the deterministic moved-file and mv+chdir tests. Round 2 verdict: see the comment below.Tests (
dol/tests/test_atomic.py):The moved-file tests check both that the path equals a fresh resolution and that a second
FileLockfrom the same thread is refused. Both moved-file tests fail on the first version. Full suite: 1085 passed, 11 skipped.🤖 Generated with Claude Code