Skip to content

Refactor SimpleBlobStore#get(ActionResult)(...)#9200

Closed
buchgr wants to merge 1 commit intobazelbuild:masterfrom
buchgr:refactor-download
Closed

Refactor SimpleBlobStore#get(ActionResult)(...)#9200
buchgr wants to merge 1 commit intobazelbuild:masterfrom
buchgr:refactor-download

Conversation

@buchgr
Copy link
Copy Markdown
Contributor

@buchgr buchgr commented Aug 19, 2019

The change update methods signatures to be compatible with those in
AbstractRemoteActionCache:

  1. Future get(String, OutputStream) -> Future downloadBlob(Digest, OutputStream)
  2. Future getActionResult(String, OutputStream) -> Future downloadActionResult(ActionKey)

The refactoring uncovered a bug in CombinedDiskHttpBlobStore. We did not
close the output stream before moving a file to the disk cache, thus
potentially moving a corrupted file to the disk cache as any errors
would only be reported afterwards.

CacheNotFoundException(Digest missingDigest, DigestUtil digestUtil) {
super("Missing digest: " + digestUtil.toString(missingDigest));
public CacheNotFoundException(Digest missingDigest) {
super("Missing digest: " + missingDigest.getHash() + "/" + missingDigest.getSizeBytes());
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.

Suggested change
super("Missing digest: " + missingDigest.getHash() + "/" + missingDigest.getSizeBytes());
super("Missing digest: " + DigestUtil.toString(missingDigest));

Copy link
Copy Markdown
Contributor Author

@buchgr buchgr Sep 3, 2019

Choose a reason for hiding this comment

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

Same reason as above :. I added a TODO.

resourceName += options.remoteInstanceName + "/";
}
resourceName += "blobs/" + digestUtil.toString(digest);
resourceName += "blobs/" + digest.getHash() + "/" + digest.getSizeBytes();
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.

Suggested change
resourceName += "blobs/" + digest.getHash() + "/" + digest.getSizeBytes();
resourceName += "blobs/" + DigestUtil.toString(digest);

Copy link
Copy Markdown
Contributor Author

@buchgr buchgr Sep 3, 2019

Choose a reason for hiding this comment

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

This would introduce dependency cycles. However, it seems like a small price to pay.

assertThat(e).hasMessageThat().contains(digest.getHash());
}

private class ConcurrentMapBlobStore implements SimpleBlobStore {
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.

supernit: Maybe extract it into a separate file in test sources? Just to keep this file smaller :)

Could be package private if reusability is a concern

}

public boolean containsKey(Digest digest) {
return ((OnDiskBlobStore) blobStore).contains(digest);
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.

Maybe add a private final field that's already casted instead of casting every time?

I'm afraid casting every time will have runtime overhead before (if) JIT figures out that cast always succeeds, given how often containsKey will be called in large builds

Docs: checkcast

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point in general but this code is not performance critical as it's only used in tests.

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.

Still, it could be a good idea to 'not' make tests run longer ;)

@buchgr buchgr force-pushed the refactor-download branch 2 times, most recently from 494f06a to ba89d13 Compare August 21, 2019 13:06
@borkaehw
Copy link
Copy Markdown

@buchgr Is it also related to making GrpcRemoteCache a SimpleBlobStore implementation?

@jin jin added the WIP label Sep 3, 2019
@buchgr
Copy link
Copy Markdown
Contributor Author

buchgr commented Sep 3, 2019

@borkaehw yes

The change update methods signatures to be compatible with those in
AbstractRemoteActionCache:
  1) Future<Boolean> get(String, OutputStream) -> Future<Void> downloadBlob(Digest, OutputStream)
  2) Future<Boolean> getActionResult(String, OutputStream) -> Future<ActionResult> downloadActionResult(ActionKey)

The refactoring uncovered a bug in CombinedDiskHttpBlobStore. We did not
close the output stream *before* moving a file to the disk cache, thus
potentially moving a corrupted file to the disk cache as any errors
would only be reported afterwards.
@buchgr buchgr marked this pull request as ready for review September 3, 2019 17:21
@buchgr buchgr changed the title Refactor download Refactor SimpleBlobStore#get(ActionResult)(...) Sep 3, 2019
Copy link
Copy Markdown
Contributor

@ishikhman ishikhman left a comment

Choose a reason for hiding this comment

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

LGTM

}

public boolean containsKey(Digest digest) {
return ((OnDiskBlobStore) blobStore).contains(digest);
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.

Still, it could be a good idea to 'not' make tests run longer ;)

@buchgr
Copy link
Copy Markdown
Contributor Author

buchgr commented Sep 6, 2019

Still, it could be a good idea to 'not' make tests run longer ;)

They won't. This is a micro optimization that may shave off a few micro seconds.

@SrodriguezO
Copy link
Copy Markdown

@buchgr what's the status on this PR?

@ishikhman
Copy link
Copy Markdown
Contributor

@SrodriguezO it's on a way to be merged, but @buchgr is away for a few weeks, so it will be finalised in a week or so

@SrodriguezO
Copy link
Copy Markdown

@buchgr friendly ping : )

@bazel-io bazel-io closed this in 1846269 Nov 6, 2019
irengrig pushed a commit to irengrig/bazel that referenced this pull request Nov 7, 2019
The change update methods signatures to be compatible with those in
AbstractRemoteActionCache:
  1) Future<Boolean> get(String, OutputStream) -> Future<Void> downloadBlob(Digest, OutputStream)
  2) Future<Boolean> getActionResult(String, OutputStream) -> Future<ActionResult> downloadActionResult(ActionKey)

The refactoring uncovered a bug in CombinedDiskHttpBlobStore. We did not
close the output stream *before* moving a file to the disk cache, thus
potentially moving a corrupted file to the disk cache as any errors
would only be reported afterwards.

Closes bazelbuild#9200.

PiperOrigin-RevId: 278830531
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants