Skip to content

Change RemoteActionInputFetcher to use temp files before staging#11340

Closed
sohaibiftikhar wants to merge 1 commit intobazelbuild:masterfrom
sohaibiftikhar:FACT-120
Closed

Change RemoteActionInputFetcher to use temp files before staging#11340
sohaibiftikhar wants to merge 1 commit intobazelbuild:masterfrom
sohaibiftikhar:FACT-120

Conversation

@sohaibiftikhar
Copy link
Copy Markdown

Attempts fixing #11339

@googlebot
Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels May 9, 2020

private static Path toTmpDownloadPath(Path actualPath) {
return actualPath.getParentDirectory().getRelative(
actualPath.getBaseName() + "." + actualPath.hashCode()
Copy link
Copy Markdown
Author

@sohaibiftikhar sohaibiftikhar May 9, 2020

Choose a reason for hiding this comment

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

This should give a unique + deterministic enough name so that we don't need to sort all downloads before moving to final location.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not use the same approach as RemoteCache?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Because RemoteCache collects all outputs before doing the moveToFinalLocation. This class was designed a bit differently in that it can call downloadFileAsync from two different methods (downloadFile and prefetchFiles) and the shared variables downloadsInProgress and downloadedPaths are controlled per download here.

So I would have to move the synchronized blocks to those two methods and that looked like a lot more refactoring to me. I can make that change if you think that is the way to go. But this seems cleaner to me.

"Failed to move to final location %s. -> %s", tmpPath, path
);
}
synchronized (lock) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Moved the synchronize block below. A file is considered to be downloaded only after its permissions are set and it has been moved to its final location.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is wrong. You are doing this even when the above code fails with an IOException

@aiuto aiuto requested a review from meisterT May 13, 2020 04:40
@meisterT
Copy link
Copy Markdown
Member

cc @ulfjack

Copy link
Copy Markdown
Contributor

@ulfjack ulfjack left a comment

Choose a reason for hiding this comment

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

I would generally prefer a temporary location in a place where it can't conflict with other files. In this case, it could potentially conflict (same for RemoteCache). That said, this seems like a reasonable change. I posted a question on the code above. Also, did you consider rm-ing the file after download instead of downloading to a temporary location.

I wonder how @jmmv does this in the dynamic strategy - I think he said he was planning to download to a temp location as well. Is there a way to make the different implementations more consistent with each other?


private static Path toTmpDownloadPath(Path actualPath) {
return actualPath.getParentDirectory().getRelative(
actualPath.getBaseName() + "." + actualPath.hashCode()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not use the same approach as RemoteCache?

@sohaibiftikhar
Copy link
Copy Markdown
Author

sohaibiftikhar commented May 14, 2020

Also, did you consider rm-ing the file after download instead of downloading to a temporary location.

There is a path.delete in the onFailure block that does this. The problem is that this never gets called in case the thread gets terminated from the outside. To be honest I don't quite know why. I couldn't find the place in the code where the termination happens.

Maybe someone with more knowledge of that part could point that out.

@jmmv
Copy link
Copy Markdown
Contributor

jmmv commented May 15, 2020

I went through various iterations to make the "download as temp" feature work (for the internal version of this feature).

  1. Put the temp file next to the output, with a .tmp suffix. This ended up causing trouble with tree artifacts (which would see "extra" files on disk before they were deleted, and failed validation).

  2. Put the temp files in the actions temp dir, using a file name derived from the original execroot-relative path but translating all path separators into underscores. This ended up running into path limits (on macOS).

  3. Put the temp files in the actions temp dir, using a counter for their file names. This has been working well so far.

So essentially, we do this:

Path tempDestFile =
    actionTempsDir.getChild("output-" + lastTempOutput.getAndAdd(1) + ".tmp");

More details here: https://jmmv.dev/2019/12/bazel-dynamic-execution-download-times.html

Would be great if the external logic of this code did the same.

@philwo
Copy link
Copy Markdown
Member

philwo commented Sep 23, 2020

@sohaibiftikhar Are you still working on this?

@sohaibiftikhar
Copy link
Copy Markdown
Author

I was involved with some other work that put this on a sidetrack. I can finish this by aligning with what @jmmv proposes here.

@meisterT
Copy link
Copy Markdown
Member

What's the current state?

@meisterT meisterT added the team-Remote-Exec Issues and PRs for the Execution (Remote) team label Oct 21, 2020
@meisterT
Copy link
Copy Markdown
Member

cc @coeuvre

@coeuvre
Copy link
Copy Markdown
Member

coeuvre commented Nov 11, 2020

#12453 fixes #11339 by deleting the partial downloaded files. However, changing how RemoteCache handles the temp download files to what @jmmv suggested would be great.

@jin
Copy link
Copy Markdown
Member

jin commented Jan 15, 2021

Closing this PR as as the referenced issue has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes team-Remote-Exec Issues and PRs for the Execution (Remote) team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants