aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar felly <felly@google.com>2018-06-04 07:41:09 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-04 07:42:38 -0700
commitc3aa9fed6f91204817b9d2f5cb46d9484019f745 (patch)
treee5965db6f0d656c8272f54f8d29d599435281840 /src/main
parentbdba40fb49cf9bd472d749b3e0e5f5713caef277 (diff)
ActionFS is now aware of inserted files.
PiperOrigin-RevId: 199131390
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java34
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/InjectionListener.java26
2 files changed, 54 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java
index 383150a940..345c4c8968 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java
@@ -27,6 +27,7 @@ import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.FileStateType;
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.profiler.ProfilerTask;
+import com.google.devtools.build.lib.skyframe.FileArtifactValue.RemoteFileArtifactValue;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -56,7 +57,7 @@ import javax.annotation.Nullable;
* access {@link env}, they must also used synchronized access.
* </ul>
*/
-final class ActionFileSystem extends FileSystem implements ActionInputFileCache {
+final class ActionFileSystem extends FileSystem implements ActionInputFileCache, InjectionListener {
private static final Logger LOGGER = Logger.getLogger(ActionFileSystem.class.getName());
/** Actual underlying filesystem. */
@@ -156,6 +157,18 @@ final class ActionFileSystem extends FileSystem implements ActionInputFileCache
return getMetadataChecked(actionInput.getExecPath());
}
+ // -------------------- InjectionListener Implementation --------------------
+
+ @Override
+ public void onInsert(ActionInput dest, byte[] digest, long size, int backendIndex)
+ throws IOException {
+ OutputMetadata output = outputs.get(dest.getExecPath());
+ if (output != null) {
+ output.set(new RemoteFileArtifactValue(digest, size, backendIndex),
+ /*notifyConsumer=*/ false);
+ }
+ }
+
// -------------------- FileSystem implementation --------------------
@Override
@@ -274,7 +287,7 @@ final class ActionFileSystem extends FileSystem implements ActionInputFileCache
createSymbolicLinkErrorMessage(
linkPath, targetFragment, linkPath + " is not an output."));
}
- outputHolder.set(inputMetadata);
+ outputHolder.set(inputMetadata, /*notifyConsumer=*/ true);
}
@Override
@@ -447,7 +460,7 @@ final class ActionFileSystem extends FileSystem implements ActionInputFileCache
}
@FunctionalInterface
- public static interface MetadataConsumer {
+ public interface MetadataConsumer {
void accept(Artifact artifact, FileArtifactValue value) throws IOException;
}
@@ -503,8 +516,17 @@ final class ActionFileSystem extends FileSystem implements ActionInputFileCache
return metadata;
}
- public void set(FileArtifactValue metadata) throws IOException {
- metadataConsumer.accept(artifact, metadata);
+ /**
+ * Sets the output metadata, and maybe notify the metadataConsumer.
+ *
+ * @param metadata the metadata to write
+ * @param notifyConsumer whether to notify metadataConsumer. Callers should not notify the
+ * metadataConsumer if it will be notified separately at the Spawn level.
+ */
+ public void set(FileArtifactValue metadata, boolean notifyConsumer) throws IOException {
+ if (notifyConsumer) {
+ metadataConsumer.accept(artifact, metadata);
+ }
this.metadata = metadata;
}
@@ -518,7 +540,7 @@ final class ActionFileSystem extends FileSystem implements ActionInputFileCache
byte[] data = toByteArray();
set(
new FileArtifactValue.InlineFileArtifactValue(
- data, Hashing.md5().hashBytes(data).asBytes()));
+ data, Hashing.md5().hashBytes(data).asBytes()), /*notifyConsumer=*/ true);
}
};
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/InjectionListener.java b/src/main/java/com/google/devtools/build/lib/skyframe/InjectionListener.java
new file mode 100644
index 0000000000..bf7350ba39
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/InjectionListener.java
@@ -0,0 +1,26 @@
+// Copyright 2018 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.skyframe;
+
+import com.google.devtools.build.lib.actions.ActionInput;
+import java.io.IOException;
+
+/**
+ * An {@link InjectionListener} is notified when a remote file metadata is inserted into its
+ * associated storage.
+ */
+public interface InjectionListener {
+ void onInsert(ActionInput dest, byte[] digest, long size, int backendIndex) throws IOException;
+}