aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar robinnabel <rnabel@ucdavis.edu>2018-03-22 07:18:14 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-22 07:19:28 -0700
commit7fc3410f21be3326325fc297ec86f0c79a091d01 (patch)
tree45af4913ac377288aef1d9b71135aed31cfe92d1 /src/main/java/com
parentd01e8ad9acb2f30e91a653d3af00bd0302c44ad5 (diff)
Local Disk Cache: Only write to disk if target hash doesn't already exist.
Under Windows, the default permissions used when writing to the local disk cache prevent the files from being overwritten. This CR adds a check: if the target file already exists, return early. This is a performance improvement and will fix the error described above as existing files will no longer need to be overwritten. Similar features have been implemented on the remote gRPC cache implementations, see bazel issue #4789. Closes #4886. PiperOrigin-RevId: 190060233
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/blobstore/OnDiskBlobStore.java8
1 files changed, 6 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
index 2dbd3208a7..011431013b 100644
--- 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
@@ -54,6 +54,11 @@ public final class OnDiskBlobStore implements SimpleBlobStore {
@Override
public void put(String key, long length, InputStream in) throws IOException {
+ Path target = toPath(key);
+ if (target.exists()) {
+ return;
+ }
+
// Write a temporary file first, and then rename, to avoid data corruption in case of a crash.
Path temp = toPath(UUID.randomUUID().toString());
try (OutputStream out = temp.getOutputStream()) {
@@ -61,8 +66,7 @@ public final class OnDiskBlobStore implements SimpleBlobStore {
}
// TODO(ulfjack): Fsync temp here before we rename it to avoid data loss in the case of machine
// crashes (the OS may reorder the writes and the rename).
- Path f = toPath(key);
- temp.renameTo(f);
+ temp.renameTo(target);
}
@Override