-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Emit module trace atomically by using LLVM's LockFileManager
#39888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please test |
Build failed |
Build failed |
71184f0
to
1f19efa
Compare
@swift-ci please test |
LockFileManager
Thanks @tschuett! I didn't know about this tool and with my original approach, this would have been much much better. However, I later realized that we must be able to atomically append to an existing trace file (even testing for that in |
1f19efa
to
5a6ef1f
Compare
@swift-ci please test |
"Failed to acquire filesystem lock - timeout"); | ||
// Clear the lock file so that future invocations can make progress. | ||
Locked.unsafeRemoveLockFile(); | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, we're clearing the lock here for the next invocation to work. Could we just clear the lock and try again right away instead? I'd expect that if other processes are currently waiting on this lock they'd trigger right away too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was to fail here because this timeout is 256 seconds and I wanted to avoid waiting forever if this times out. Is there not a risk that something goes wrong with this lock - we are not able to acquire it - and we hang forever, if we re-try here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense, I see 2 possible problematic situations here.
Too many processes are competing for access to the lock file and each one is taking too long. We've seen this before creating long hangs but it's less likely here as the work is simple.
The other one would be if an interruption prevents one run from clearing the lock then we'd have the interrupted run that failed (as expected), the next run would fail on the lock, and only the third run would work.
I don't know which is more of a concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go with clearing the lock and re-trying here, because it seems more-likely to be the case than too much contention in this particular scenario, to me. If we see compiler hangs when this feature is used, we'll know where to look...
5a6ef1f
to
cf47257
Compare
@swift-ci please test |
Build failed |
@swift-ci please test |
@swift-ci please test Windows platform |
Ensure that we only have one writer to the module trace file at a time by using LLVM's `LockFileManager` utilities, similarly to `ModuleInterfaceBuilder` Resolves rdar://76743462
cf47257
to
2905433
Compare
@swift-ci please test |
Ensuring that creation of and writing to the module trace file happens atomically overall.
LLVM provides utilities to perform an atomic write-to-file:
https://github.com/llvm/llvm-project/blob/5de69e16ea9ab916401f4a8390fff91f18bbba2a/llvm/include/llvm/Support/FileUtilities.h#L111
However, we must support emitting module trace that appends to an existing file, which isn't currently supported by those utilities since they write-to-temporary and perform an atomic rename to achieve this atomicity.
Instead, use the same approach as the
ModuleInterfaceBuilder
and place a filesystem lock on the module trace output file in order to do the write.Resolves rdar://76743462