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

Remote: Do not upload empty output to remote cache. #13594

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,32 @@ public ActionResult downloadActionResult(
return getFromFuture(cacheProtocol.downloadActionResult(context, actionKey, inlineOutErr));
}

/** Upload a local file to the remote cache. */
public ListenableFuture<Void> uploadFile(
RemoteActionExecutionContext context,
Digest digest,
Path file
) {
if (digest.getSizeBytes() == 0) {
return COMPLETED_SUCCESS;
}

return cacheProtocol.uploadFile(context, digest, file);
}

/** Upload sequence of bytes to the remote cache. */
public ListenableFuture<Void> uploadBlob(
RemoteActionExecutionContext context,
Digest digest,
ByteString data
) {
if (digest.getSizeBytes() == 0) {
return COMPLETED_SUCCESS;
}

return cacheProtocol.uploadBlob(context, digest, data);
}

/**
* Upload the result of a locally executed action to the remote cache.
*
Expand Down Expand Up @@ -212,14 +238,14 @@ private void uploadOutputs(
for (Digest digest : digestsToUpload) {
Path file = digestToFile.get(digest);
if (file != null) {
uploads.add(cacheProtocol.uploadFile(context, digest, file));
uploads.add(uploadFile(context, digest, file));
} else {
ByteString blob = digestToBlobs.get(digest);
if (blob == null) {
String message = "FindMissingBlobs call returned an unknown digest: " + digest;
throw new IOException(message);
}
uploads.add(cacheProtocol.uploadBlob(context, digest, blob));
uploads.add(uploadBlob(context, digest, blob));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,50 @@ public void testUploadDirectory() throws Exception {
assertThat(remoteCache.findMissingDigests(context, toQuery)).isEmpty();
}

@Test
public void testUploadEmptyBlobAndFile() throws Exception {
// Test that uploading an empty BLOB/file does not try to perform an upload.
InMemoryRemoteCache remoteCache = newRemoteCache();
Digest emptyDigest = fakeFileCache.createScratchInput(ActionInputHelper.fromPath("file"), "");
Path file = execRoot.getRelative("file");

Utils.getFromFuture(remoteCache.uploadBlob(context, emptyDigest, ByteString.EMPTY));
assertThat(remoteCache.findMissingDigests(context, ImmutableSet.of(emptyDigest)))
.containsExactly(emptyDigest);

Utils.getFromFuture(remoteCache.uploadFile(context, emptyDigest, file));
assertThat(remoteCache.findMissingDigests(context, ImmutableSet.of(emptyDigest)))
.containsExactly(emptyDigest);
}

@Test
public void testUploadEmptyOutputs() throws Exception {
// Test that uploading an empty output does not try to perform an upload.

// arrange
Digest emptyDigest =
fakeFileCache.createScratchInput(ActionInputHelper.fromPath("bar/test/wobble"), "");
Path file = execRoot.getRelative("bar/test/wobble");
InMemoryRemoteCache remoteCache = newRemoteCache();
Action action = Action.getDefaultInstance();
ActionKey actionDigest = digestUtil.computeActionKey(action);
Command cmd = Command.getDefaultInstance();

// act
remoteCache.upload(
context,
remotePathResolver,
actionDigest,
action,
cmd,
ImmutableList.of(file),
new FileOutErr(execRoot.getRelative("stdout"), execRoot.getRelative("stderr")));

// assert
assertThat(remoteCache.findMissingDigests(context, ImmutableSet.of(emptyDigest)))
.containsExactly(emptyDigest);
}

@Test
public void testUploadEmptyDirectory() throws Exception {
// Test that uploading an empty directory works.
Expand Down