aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2017-07-04 06:01:11 -0400
committerGravatar John Cater <jcater@google.com>2017-07-05 10:57:53 -0400
commit27762e2207d2ea817499756298f08c715790d187 (patch)
tree604382da8d38f7f2f8459aa7614e050124f80e8e /src
parent9409109c3016c51403ed4387ecda6c99459f1a8d (diff)
Add an on-disk storage option for the remote worker
I'm planning to switch the remote worker over to the on-disk storage system, and delete the in-memory option. Currently, running a Bazel build with the in-memory storage system uses up over 50% of the total available memory on my machine (I only have 32 GB total), and grinds it to a complete halt (unless I close most of my apps) on a simple build of //src:bazel. PiperOrigin-RevId: 160877546
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/blobstore/OnDiskBlobStore.java57
-rw-r--r--src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java14
-rw-r--r--src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorkerOptions.java11
3 files changed, 80 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/remote/blobstore/OnDiskBlobStore.java b/src/main/java/com/google/devtools/build/lib/remote/blobstore/OnDiskBlobStore.java
new file mode 100644
index 0000000000..8f2ee0790e
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/remote/blobstore/OnDiskBlobStore.java
@@ -0,0 +1,57 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.remote.blobstore;
+
+import com.google.devtools.build.lib.vfs.FileSystemUtils;
+import com.google.devtools.build.lib.vfs.Path;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.UUID;
+
+/** A on-disk store for the remote action cache. */
+public final class OnDiskBlobStore implements SimpleBlobStore {
+ private final Path root;
+
+ public OnDiskBlobStore(Path root) {
+ this.root = root;
+ }
+
+ @Override
+ public boolean containsKey(String key) {
+ return toPath(key).exists();
+ }
+
+ @Override
+ public byte[] get(String key) throws IOException {
+ Path f = toPath(key);
+ return f.exists() ? FileSystemUtils.readContent(f) : null;
+ }
+
+ @Override
+ public void put(String key, byte[] value) throws IOException {
+ Path temp = toPath(UUID.randomUUID().toString());
+ try (OutputStream out = temp.getOutputStream()) {
+ out.write(value);
+ }
+ Path f = toPath(key);
+ temp.renameTo(f);
+ }
+
+ @Override
+ public void close() {}
+
+ private Path toPath(String key) {
+ return root.getChild(key);
+ }
+} \ No newline at end of file
diff --git a/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java b/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java
index d9056e9932..49e63d7915 100644
--- a/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java
+++ b/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java
@@ -27,6 +27,7 @@ import com.google.devtools.build.lib.remote.RemoteOptions;
import com.google.devtools.build.lib.remote.SimpleBlobStoreActionCache;
import com.google.devtools.build.lib.remote.SimpleBlobStoreFactory;
import com.google.devtools.build.lib.remote.blobstore.ConcurrentMapBlobStore;
+import com.google.devtools.build.lib.remote.blobstore.OnDiskBlobStore;
import com.google.devtools.build.lib.remote.blobstore.SimpleBlobStore;
import com.google.devtools.build.lib.shell.Command;
import com.google.devtools.build.lib.shell.CommandException;
@@ -39,6 +40,7 @@ import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.JavaIoFileSystem;
import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.common.options.OptionsParser;
import com.google.devtools.remoteexecution.v1test.ActionCacheGrpc.ActionCacheImplBase;
import com.google.devtools.remoteexecution.v1test.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase;
@@ -165,12 +167,20 @@ public final class RemoteWorker {
if (!usingRemoteCache) {
logger.warning("Not using remote cache. This should be used for testing only!");
}
+ if ((remoteWorkerOptions.casPath != null)
+ && (!PathFragment.create(remoteWorkerOptions.casPath).isAbsolute()
+ || !getFileSystem().getPath(remoteWorkerOptions.casPath).exists())) {
+ logger.severe("--cas_path must refer to an existing, absolute path!");
+ System.exit(1);
+ return;
+ }
SimpleBlobStore blobStore =
usingRemoteCache
? SimpleBlobStoreFactory.create(remoteOptions)
- : new ConcurrentMapBlobStore(
- new ConcurrentHashMap<String, byte[]>());
+ : remoteWorkerOptions.casPath != null
+ ? new OnDiskBlobStore(getFileSystem().getPath(remoteWorkerOptions.casPath))
+ : new ConcurrentMapBlobStore(new ConcurrentHashMap<String, byte[]>());
RemoteWorker worker =
new RemoteWorker(
diff --git a/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorkerOptions.java b/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorkerOptions.java
index 686761f9ed..e8bc12a781 100644
--- a/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorkerOptions.java
+++ b/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorkerOptions.java
@@ -43,6 +43,17 @@ public class RemoteWorkerOptions extends OptionsBase {
public String workPath;
@Option(
+ name = "cas_path",
+ defaultValue = "null",
+ category = "build_worker",
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ help = "A directory for the build worker to store it's files in. If left unset, and if no "
+ + "other store is set, the worker falls back to an in-memory store."
+ )
+ public String casPath;
+
+ @Option(
name = "debug",
defaultValue = "false",
category = "build_worker",