-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
src/main/java/com/google/devtools/build/lib/remote/blobstore/CombinedDiskHttpBlobStore.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/remote/blobstore/CombinedDiskHttpBlobStore.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/remote/blobstore/CombinedDiskHttpBlobStore.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/remote/blobstore/CombinedDiskHttpBlobStore.java
Outdated
Show resolved
Hide resolved
83eb90b
to
5927a12
Compare
5927a12
to
b84f14d
Compare
/** | ||
* 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not OnDiskBlobStore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. Changed.
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 ;)) .
@buchgr, PTAL. |
78cf7e7
to
08a5c42
Compare
} | ||
|
||
private ListenableFuture<Boolean> get(String key, OutputStream out, boolean actionResult) { | ||
boolean foundOnDisk = diskCache.toPath(key, actionResult).exists(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Can you please add a test for the regression? |
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
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/key/true/
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add license
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testValidUri
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testInvalidUri
There was a problem hiding this comment.
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")); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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")); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
LGTM |
The srcs test is failing. You need to add the srcs filegroup to the //:srcs target.
|
Thanks! |
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
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
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
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
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
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
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
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
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
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
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
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
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
Fixes #8052
The problem: CombinedCache is not working.
The cause: both
OnDiskBlobStore
andHttpBlobStore
store action results differently from other actions, but not in the same way. TheOnDiskBlobStore
appends "ac_" prefix to the key, while theHttpBlobStore
stores it in a different directory. Current implementation added "ac_" prefix for both blob stores, which is not correct for theHttpBlobStore
.The solution: treat actionResults'
gets
andputs
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.