Repository navigation
Read the current second for stat signatures off the filesystem clock - #7189
Merged
Merged
Conversation
The kernel stamps files with a clock that advances only on a timer tick, so for a few milliseconds after time() moves to the next second, a file or directory written still gets the previous second. FileStatSignatures compared timestamps to time(), so it vouched for such a change and a DirectoryWalker listing or a result cache file hash could be reused over different contents. This made DirectoryWalkerTest fail now and then when the whole test suite was run. The current second is now read off the mtime of a temporary file created in begin(), the way git compares to the mtime of its index. Amp-Thread-ID: https://ampcode.com/threads/T-01a21723-3824-7286-98c0-56d7b4e30d96
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.
The kernel stamps files with a clock that advances only on a timer tick (
ktime_get_coarse_real_ts64), so for a few milliseconds aftertime()moves to the next second, a file or directory written still gets the previous second.FileStatSignatures::begin()compared timestamps totime(), soFileStatSignatureReadervouched for such a change: aDirectoryWalkerlisting, or a file hash in the result cache, could be reused over different contents.This is what made
DirectoryWalkerTest(testListingsSeeAddedAndRemovedFiles,testReplacedDirectoryIsReadAgain) fail now and then in the full test suite: the test's changes sometimes landed in that window right afterwaitUntilTheTreeIsInThePast()returned.begin()now reads the current second off the mtime of atmpfile()it creates, the way git compares to the mtime of its index. If the probe cannot be created, it falls back totime() - 1, which treats the last second as racy too.Evidence on an ext4 orb:
begin()and asking for its signature: before, 1784 of 347782 changes still got a signature; after, 0 of 172356.DirectoryWalkerTestwith all 16 cores busy: failed 2 of 6 runs before, passed 8 of 8 after.ResultCacheManager::hashAnalysedFiles()has the same lag in its$hashedAt = time()racy check; it is left for a follow-up.Amp thread: https://ampcode.com/threads/T-01a21723-3824-7286-98c0-56d7b4e30d96