Skip to content

Commit a6b5b05

Browse files
buchgrcopybara-github
authored andcommitted
Streamline uploading of stdout and stderr
This change removes extra upload logic for stdout/stderr. Besides the streamlined code this also saves two round trips uploading an action that produced both stdout and stderr. Closes #9025. PiperOrigin-RevId: 261288280
1 parent 09ec893 commit a6b5b05

2 files changed

Lines changed: 29 additions & 30 deletions

File tree

src/main/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCache.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,10 @@ static class UploadManifest {
640640
private final Path execRoot;
641641
private final boolean allowSymlinks;
642642
private final boolean uploadSymlinks;
643-
private final Map<Digest, Path> digestToFile;
644-
private final Map<Digest, Chunker> digestToChunkers;
643+
private final Map<Digest, Path> digestToFile = new HashMap<>();
644+
private final Map<Digest, Chunker> digestToChunkers = new HashMap<>();
645+
private Digest stderrDigest;
646+
private Digest stdoutDigest;
645647

646648
/**
647649
* Create an UploadManifest from an ActionResult builder and an exec root. The ActionResult
@@ -658,9 +660,17 @@ public UploadManifest(
658660
this.execRoot = execRoot;
659661
this.uploadSymlinks = uploadSymlinks;
660662
this.allowSymlinks = allowSymlinks;
663+
}
661664

662-
this.digestToFile = new HashMap<>();
663-
this.digestToChunkers = new HashMap<>();
665+
public void setStdoutStderr(FileOutErr outErr) throws IOException {
666+
if (outErr.getErrorPath().exists()) {
667+
stderrDigest = digestUtil.compute(outErr.getErrorPath());
668+
addFile(stderrDigest, outErr.getErrorPath());
669+
}
670+
if (outErr.getOutputPath().exists()) {
671+
stdoutDigest = digestUtil.compute(outErr.getOutputPath());
672+
addFile(stdoutDigest, outErr.getOutputPath());
673+
}
664674
}
665675

666676
/**
@@ -747,6 +757,16 @@ public Map<Digest, Chunker> getDigestToChunkers() {
747757
return digestToChunkers;
748758
}
749759

760+
@Nullable
761+
public Digest getStdoutDigest() {
762+
return stdoutDigest;
763+
}
764+
765+
@Nullable
766+
public Digest getStderrDigest() {
767+
return stderrDigest;
768+
}
769+
750770
private void addFileSymbolicLink(Path file, PathFragment target) throws IOException {
751771
result
752772
.addOutputFileSymlinksBuilder()

src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteCache.java

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.google.common.base.Ascii;
3939
import com.google.common.base.Preconditions;
4040
import com.google.common.base.Throwables;
41-
import com.google.common.collect.ImmutableList;
4241
import com.google.common.collect.ImmutableSet;
4342
import com.google.common.collect.Iterables;
4443
import com.google.common.collect.Maps;
@@ -419,6 +418,7 @@ void upload(
419418
options.incompatibleRemoteSymlinks,
420419
options.allowSymlinkUpload);
421420
manifest.addFiles(files);
421+
manifest.setStdoutStderr(outErr);
422422
manifest.addAction(actionKey, action, command);
423423

424424
Map<HashCode, Chunker> filesToUpload = Maps.newHashMap();
@@ -449,34 +449,13 @@ void upload(
449449
uploader.uploadBlobs(filesToUpload, /*forceUpload=*/true);
450450
}
451451

452-
// TODO(olaola): inline small stdout/stderr here.
453-
if (outErr.getErrorPath().exists()) {
454-
Digest stderr = uploadFileContents(outErr.getErrorPath());
455-
result.setStderrDigest(stderr);
452+
if (manifest.getStderrDigest() != null) {
453+
result.setStderrDigest(manifest.getStderrDigest());
456454
}
457-
if (outErr.getOutputPath().exists()) {
458-
Digest stdout = uploadFileContents(outErr.getOutputPath());
459-
result.setStdoutDigest(stdout);
455+
if (manifest.getStdoutDigest() != null) {
456+
result.setStdoutDigest(manifest.getStdoutDigest());
460457
}
461458
}
462-
463-
/**
464-
* Put the file contents cache if it is not already in it. No-op if the file is already stored in
465-
* cache. The given path must be a full absolute path.
466-
*
467-
* @return The key for fetching the file contents blob from cache.
468-
*/
469-
private Digest uploadFileContents(Path file) throws IOException, InterruptedException {
470-
Digest digest = digestUtil.compute(file);
471-
ImmutableSet<Digest> missing = getMissingDigests(ImmutableList.of(digest));
472-
if (!missing.isEmpty()) {
473-
uploader.uploadBlob(
474-
HashCode.fromString(digest.getHash()),
475-
Chunker.builder().setInput(digest.getSizeBytes(), file).build(),
476-
/* forceUpload=*/ true);
477-
}
478-
return digest;
479-
}
480459

481460
// Execution Cache API
482461

0 commit comments

Comments
 (0)