Skip to content
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

Ensure DirectoryContext.createOrSetWritable() always creates directories #19381

Conversation

EdSchouten
Copy link
Contributor

In case DirectoryContext.createOrSetWritable() is called on a directory inside of a Tree, it already does a nice forward sweep along the path to create missing intermediate directories. When creating a bare output file in a nested directory, it does not. It implicitly assumes that the output directory was already created at a previous point in time.

This doesn't cause issues whenever we do a fully clean build, as some earlier phase (the analysis phase?) creates the missing parent directories for us. However, if we remove the nested directory structure from bazel-bin/ manually and rerun the test, this causes failures along the lines:

java.io.FileNotFoundException: /REDACTED/execroot/main/bazel-out/darwin_x86_64-fastbuild/bin/some/very/very/very/deeply/nested (No such file or directory)

Solve this issue by properly catching FileNotFoundExceptions that are generated when we call Path.isWritable() on the parent directory of the output file. In that case we resort to calling
Path.createDirectoryAndParents().

I think this is likely the most efficient strategy, as it means we don't need to do a full forward scan of the path in the common case where the parent directory does exist.

This issue can be noticed in practice when switching from --remote_output_service (PR #12823) to --remote_download_minimal.

In case DirectoryContext.createOrSetWritable() is called on a directory
inside of a Tree, it already does a nice forward sweep along the path to
create missing intermediate directories. When creating a bare output
file in a nested directory, it does not. It implicitly assumes that the
output directory was already created at a previous point in time.

This doesn't cause issues whenever we do a fully clean build, as some
earlier phase (the analysis phase?) creates the missing parent
directories for us. However, if we remove the nested directory structure
from bazel-bin/ manually and rerun the test, this causes failures along
the lines:

    java.io.FileNotFoundException: /REDACTED/execroot/main/bazel-out/darwin_x86_64-fastbuild/bin/some/very/very/very/deeply/nested (No such file or directory)

Solve this issue by properly catching FileNotFoundExceptions that are
generated when we call Path.isWritable() on the parent directory of the
output file. In that case we resort to calling
Path.createDirectoryAndParents().

I think this is likely the most efficient strategy, as it means we don't
need to do a full forward scan of the path in the common case where the
parent directory does exist.

This issue can be noticed in practice when switching from
--remote_output_service (PR bazelbuild#12823) to --remote_download_minimal.
@EdSchouten EdSchouten requested a review from a team as a code owner August 31, 2023 15:46
@github-actions github-actions bot added awaiting-review PR is awaiting review from an assigned reviewer team-Remote-Exec Issues and PRs for the Execution (Remote) team labels Aug 31, 2023
@tjgq tjgq self-assigned this Aug 31, 2023
@tjgq
Copy link
Contributor

tjgq commented Sep 4, 2023

Thanks for finding and fixing this bug, @EdSchouten! I'd like to address this in a slightly different way, so instead of asking for changes back and forth, I'm going to submit a modified version of this PR internally.

@EdSchouten
Copy link
Contributor Author

Perfect! Thanks, @tjgq!

@copybara-service copybara-service bot closed this in 3040f50 Sep 7, 2023
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Remote-Exec Issues and PRs for the Execution (Remote) team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants