diff options
author | ulfjack <ulfjack@google.com> | 2017-07-04 06:01:11 -0400 |
---|---|---|
committer | John Cater <jcater@google.com> | 2017-07-05 10:57:53 -0400 |
commit | 27762e2207d2ea817499756298f08c715790d187 (patch) | |
tree | 604382da8d38f7f2f8459aa7614e050124f80e8e /src/main/java/com/google/devtools/build | |
parent | 9409109c3016c51403ed4387ecda6c99459f1a8d (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/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/remote/blobstore/OnDiskBlobStore.java | 57 |
1 files changed, 57 insertions, 0 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 |