Implement distributed caching for Bazel
This patch implements distributed caching for Bazel using Hazelcast.
Hazelcast is used as a key value store that stores content of files
indexed by the digest of the file. The cache also stores the list of files
for an action. The key in this case is the digest from the key of the action
and the list of files.
In this change I also added the interface for remote execution. The
implementation will be added in a subsequent patch.
This change is only the first in a series of changes related to distributed
caching and remote execution. I plan to revise the APIs and implementation
in subsequent changes.
--
Change-Id: I569285d6149a4e9f8ba2362682c07a9f1e1943b7
Reviewed-on: https://bazel-review.googlesource.com/#/c/2760/
MOS_MIGRATED_REVID=114325038
diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteActionCache.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionCache.java
new file mode 100644
index 0000000..538a4c9
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionCache.java
@@ -0,0 +1,71 @@
+// Copyright 2016 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;
+
+import com.google.devtools.build.lib.actions.ActionInput;
+import com.google.devtools.build.lib.actions.ActionInputFileCache;
+import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible;
+import com.google.devtools.build.lib.vfs.Path;
+
+import java.io.IOException;
+import java.util.Collection;
+
+/**
+ * A cache for storing artifacts (input and output) as well as the output of running an action.
+ */
+@ThreadCompatible
+interface RemoteActionCache {
+ /**
+ * Put the file in cache if it is not already in it. No-op if the file is already stored in
+ * cache.
+ *
+ * @return The key for fetching the file from cache.
+ */
+ String putFileIfNotExist(Path file) throws IOException;
+
+ /**
+ * Same as {@link putFileIfNotExist(Path)} but this methods takes an ActionInput.
+ *
+ * @return The key for fetching the file from cache.
+ */
+ String putFileIfNotExist(ActionInputFileCache cache, ActionInput file) throws IOException;
+
+ /**
+ * Write the file in cache identified by key to the file system. The key must uniquely identify
+ * the content of the file. Throws CacheNotFoundException if the file is not found in cache.
+ */
+ void writeFile(String key, Path dest, boolean executable)
+ throws IOException, CacheNotFoundException;
+
+ /**
+ * Write the action output files identified by the key to the file system. The key must uniquely
+ * identify the action and the content of action inputs.
+ *
+ * @throws CacheNotFoundException if action output is not found in cache.
+ */
+ void writeActionOutput(String key, Path execRoot)
+ throws IOException, CacheNotFoundException;
+
+ /**
+ * Update the cache with the action outputs for the specified key.
+ */
+ void putActionOutput(String key, Collection<? extends ActionInput> outputs)
+ throws IOException;
+
+ /**
+ * Update the cache with the files for the specified key.
+ */
+ void putActionOutput(String key, Path execRoot, Collection<Path> files) throws IOException;
+}