这是indexloc提供的服务,不要输入任何密码
Skip to content

Log to temp files then rename #1351

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

Merged
merged 3 commits into from
Jun 9, 2022
Merged

Log to temp files then rename #1351

merged 3 commits into from
Jun 9, 2022

Conversation

gsoltis
Copy link
Contributor

@gsoltis gsoltis commented Jun 8, 2022

Log files are hard-linked into the cache, so when re-running a task we need to ensure we don't pollute a previous run.

This changes our logging to stream to a temp file, which we then rename to the actual log file. This serves to break the hard link.

Note that:

  • renames will succeed even if the target already exists, as long as the target isn't a directory. All of our targets are log files
  • renames can fail if the rename is across filesystem boundaries. Our renames are within the same directory.

Fixes #1323

@vercel
Copy link

vercel bot commented Jun 8, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
turbo-site ✅ Ready (Inspect) Visit Preview Jun 9, 2022 at 5:48PM (UTC)

@gsoltis gsoltis marked this pull request as ready for review June 8, 2022 18:58
@gsoltis gsoltis requested a review from tknickman June 8, 2022 18:58
Copy link
Member

@tknickman tknickman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 logic looks sound. Verified this fixes #1323 locally as well.

@nathanhammond nathanhammond mentioned this pull request Jun 9, 2022
Copy link
Contributor

@nathanhammond nathanhammond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fix for a single symptom of a larger issue. It solves for the fact that our method of moving logs into the cache is:

  1. Write the log file into the package directory at a consistent location (e.g. examples/basic/apps/docs/.turbo/turbo-build.log)
  2. Add the path to the package outputs.
  3. Move all the contents into the cache via hardlinks.

On a second run of the same task, since the file is in a consistent location, it writes the log to the same path which is hardlinked to an existing cache. This issue will show up every time.

This issue is just an instance of a larger problem we encounter with using hardlinks. Any time time a task is re-run and the task itself does not, say, remove the paths that it outputs to first (breaking the hardlinks on our behalf) it can pollute any number of previous local caches when writing to the same output paths.

I don't believe that trying to play whack-a-mole with breaking hardlinks is a sustainable solution. Even if we properly break hardlinks in our own code that doesn't preclude a user accidentally polluting their cache by modifying something manually.

Given that, I don't believe that we should take this approach to solving the problem. I have opened #1354 with an alternate proposal which I believe addresses the root of the problem with the smallest possible change.

kodiakhq bot pushed a commit that referenced this pull request Jun 9, 2022
This is the simplest possible change to fix #1323 which addresses the root issue: turning off the hard linking behavior via function arguments.

This is an alternative to #1351.
@kodiakhq kodiakhq bot merged commit 8649514 into main Jun 9, 2022
@kodiakhq kodiakhq bot deleted the gsoltis/log_to_tmp branch June 9, 2022 17:54
gsoltis added a commit that referenced this pull request Jun 9, 2022
kodiakhq bot pushed a commit that referenced this pull request Jun 9, 2022
Reverts #1351

We don't need this PR, as #1354 supersedes it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Caching doesn't seem to correctly bust when discarding git changes
3 participants