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: made CombinedCache a composition of Disk and Http Cache #8141

Closed
wants to merge 10 commits into from

Conversation

ishikhman
Copy link
Contributor

@ishikhman ishikhman commented Apr 25, 2019

Fixes #8052

The problem: CombinedCache is not working.
The cause: both OnDiskBlobStore and HttpBlobStore store action results differently from other actions, but not in the same way. The OnDiskBlobStore appends "ac_" prefix to the key, while the HttpBlobStore stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the HttpBlobStore.
The solution: treat actionResults' gets and puts in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in this and this comments.

@ishikhman ishikhman changed the title draft - made CombinedCache a composition of Disk and Http remote: made CombinedCache a composition of Disk and Http Cache Apr 29, 2019
@ishikhman ishikhman marked this pull request as ready for review April 29, 2019 10:48
/**
* A {@link SimpleBlobStore} implementation combining two blob stores. A local disk blob store and a
* remote http blob store. If a blob isn't found in the first store, the second store is used, and
* the blob added to the first. Put puts the blob on both stores.
*/
public final class CombinedDiskHttpBlobStore extends OnDiskBlobStore {
public final class CombinedDiskHttpBlobStore implements SimpleBlobStore {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what this buys us. The code is still closely tight to the local disk cache by having copied the move logic in get. I couldn't possibly plug in anything except the disk cache there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, it is quite tight to the local disk cache, but it has a modified not just copied logic. I'd say there is not much difference in this particular case, so I'd stay with composition (it is done already and did not take more than 2 minutes of implementation time ;)) .

private final OnDiskBlobStore diskCache;
private final Path root;

public CombinedDiskHttpBlobStore(SimpleBlobStore diskCache, SimpleBlobStore httpCache, Path root) {
Copy link
Contributor

@buchgr buchgr Apr 29, 2019

Choose a reason for hiding this comment

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

why not OnDiskBlobStore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point. Changed.

Copy link
Contributor Author

@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.

Pushed the updated version. Will think about merging Combined Cache with Disk Cache.

private final OnDiskBlobStore diskCache;
private final Path root;

public CombinedDiskHttpBlobStore(SimpleBlobStore diskCache, SimpleBlobStore httpCache, Path root) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point. Changed.

/**
* A {@link SimpleBlobStore} implementation combining two blob stores. A local disk blob store and a
* remote http blob store. If a blob isn't found in the first store, the second store is used, and
* the blob added to the first. Put puts the blob on both stores.
*/
public final class CombinedDiskHttpBlobStore extends OnDiskBlobStore {
public final class CombinedDiskHttpBlobStore implements SimpleBlobStore {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, it is quite tight to the local disk cache, but it has a modified not just copied logic. I'd say there is not much difference in this particular case, so I'd stay with composition (it is done already and did not take more than 2 minutes of implementation time ;)) .

@ishikhman
Copy link
Contributor Author

@buchgr, PTAL.
I tried to merge DiskStore and CombinedDiskStore - it looked much more complex than it is now, because every method had to be there 3 times: 1 public, 1 private for actual interactions with disk store, 1 private for interactions with Remote Store. The class became big and not readable. So, i'd stay with the current solution.

}

private ListenableFuture<Boolean> get(String key, OutputStream out, boolean actionResult) {
boolean foundOnDisk = diskCache.toPath(key, actionResult).exists();
Copy link
Contributor

Choose a reason for hiding this comment

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

why not call contains here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because it's not aware of the 'actionResult' flag, and I don't want to change an interface at this very moment

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be cleaner to update the interface.

@buchgr
Copy link
Contributor

buchgr commented May 2, 2019

Can you please add a test for the regression?

@buchgr
Copy link
Contributor

buchgr commented May 2, 2019

Also, please update the commit message as discussed.

well, actually fixed RemoteWorker to make regression tests failing for erroneous solution and pass for the fix
Copy link
Contributor

@buchgr buchgr left a comment

Choose a reason for hiding this comment

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

mostly lgtm. just some smaller things. thanks!


public CombinedDiskHttpBlobStore(OnDiskBlobStore diskCache, SimpleBlobStore remoteCache) {
this.diskCache = Preconditions.checkNotNull(diskCache);
this.remoteCache = Preconditions.checkNotNull(remoteCache);
}

@Override
public boolean containsKey(String key) {
Copy link
Contributor

Choose a reason for hiding this comment

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

call this only contains to be in line with get now that you introduced containsActionResult?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -30,6 +30,11 @@
*/
boolean containsKey(String key) throws IOException, InterruptedException;

/**
* Returns {@code key} if the provided {@code key} is stored in the Action Cache.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/key/true/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,38 @@
package com.google.devtools.build.remote.worker;
Copy link
Contributor

Choose a reason for hiding this comment

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

add license

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

)

java_test(
name = "test-remote-worker",
Copy link
Contributor

Choose a reason for hiding this comment

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

s/test-remote-worker/worker/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

private HttpCacheServerHandler handler = new HttpCacheServerHandler();

@Test
public void isUriValidWhenValidUri() {
Copy link
Contributor

Choose a reason for hiding this comment

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

testValidUri

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

@Test
public void isUriValidWhenInvalidUri() {
Copy link
Contributor

Choose a reason for hiding this comment

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

testInvalidUri

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


@Test
public void isUriValidWhenValidUri() {
assertTrue(handler.isUriValid("http://some-path.co.uk:8080/ac/1111111111111111111111111111111111111111111111111111111111111111"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Use an actual hash here. Maybe the one for the empty file e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -54,7 +57,19 @@ protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request)
}
}

@VisibleForTesting
boolean isUriValid(String uri) {
Copy link
Contributor

Choose a reason for hiding this comment

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

static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@VisibleForTesting
boolean isUriValid(String uri) {
String URL_PATTERN = "^/?(.*/)?(ac/|cas/)([a-f0-9]{64})$";
Matcher matcher = Pattern.compile(URL_PATTERN).matcher(uri);
Copy link
Contributor

Choose a reason for hiding this comment

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

put Pattern.compile(URL_PATTERN) in a field and compute only once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

assertTrue(handler.isUriValid("http://localhost:8080/cas/1111111111111111111111111111111111111111111111111111111111111111"));
assertTrue(handler.isUriValid("https://localhost:8080/cas/1111111111111111111111111111111111111111111111111111111111111111"));
assertTrue(handler.isUriValid("localhost:8080/cas/1111111111111111111111111111111111111111111111111111111111111111"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC HttpRequest.getUri() for servers will return the path. So maybe test cas/hash too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@buchgr
Copy link
Contributor

buchgr commented May 7, 2019

LGTM

@buchgr
Copy link
Contributor

buchgr commented May 7, 2019

The srcs test is failing. You need to add the srcs filegroup to the //:srcs target.

//:srcs filegroup do not contains all the sources, missing:
src/tools/remote/src/test/java/com/google/devtools/build/remote/worker/BUILD
src/tools/remote/src/test/java/com/google/devtools/build/remote/worker/HttpCacheServerHandlerTest.java

@irengrig irengrig added the WIP label May 7, 2019
@ishikhman
Copy link
Contributor Author

The srcs test is failing. You need to add the srcs filegroup to the //:srcs target.

//:srcs filegroup do not contains all the sources, missing:
src/tools/remote/src/test/java/com/google/devtools/build/remote/worker/BUILD
src/tools/remote/src/test/java/com/google/devtools/build/remote/worker/HttpCacheServerHandlerTest.java

Thanks!

@bazel-io bazel-io closed this in 597e289 May 9, 2019
aehlig pushed a commit that referenced this pull request May 9, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
aehlig pushed a commit that referenced this pull request May 10, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
aehlig pushed a commit that referenced this pull request May 10, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
aehlig pushed a commit that referenced this pull request May 13, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
aehlig pushed a commit that referenced this pull request May 17, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
aehlig pushed a commit that referenced this pull request May 17, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
aehlig pushed a commit that referenced this pull request May 20, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
aehlig pushed a commit that referenced this pull request May 21, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
aehlig pushed a commit that referenced this pull request May 22, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
aehlig pushed a commit that referenced this pull request May 23, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
aehlig pushed a commit that referenced this pull request May 23, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
aehlig pushed a commit that referenced this pull request May 24, 2019
Fixes #8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in #8052 and the root cause is described in [this](#8052 (comment)) and [this](#8052 (comment)) comments.

Closes #8141.

PiperOrigin-RevId: 247387377
irengrig pushed a commit to irengrig/bazel that referenced this pull request Jun 18, 2019
Fixes bazelbuild#8052

The problem: CombinedCache is not working.
The cause: both `OnDiskBlobStore` and `HttpBlobStore` store action results differently from other actions, but not in the same way. The `OnDiskBlobStore` appends "ac_" prefix to the key, while the `HttpBlobStore` stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for the `HttpBlobStore`.
The solution: treat actionResults' `gets` and `puts` in accordance with a particular Blob Store used.

The problem is described in bazelbuild#8052 and the root cause is described in [this](bazelbuild#8052 (comment)) and [this](bazelbuild#8052 (comment)) comments.

Closes bazelbuild#8141.

PiperOrigin-RevId: 247387377
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.

Remote cache + disk cache requests incorrect action keys
5 participants