Skip to content

Commit f1af869

Browse files
coeuvrecopybara-github
authored andcommitted
Rename RemoteFileStatus to FileStatusWithMetadata and make it able to return any file metadata rather than remote.
Also make RemoteFileInfo store the metadata directly so we don't need to convert back and forth. PiperOrigin-RevId: 529665424 Change-Id: I038ef07b6b328f3fc641e73d2d7b1f5ab3c255b6
1 parent 2dca982 commit f1af869

File tree

4 files changed

+37
-39
lines changed

4 files changed

+37
-39
lines changed

src/main/java/com/google/devtools/build/lib/actions/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ java_library(
6565
"ResourceManager.java",
6666
"ResourceSet.java",
6767
"ResourceSetOrBuilder.java",
68-
"RemoteFileStatus.java",
68+
"FileStatusWithMetadata.java",
6969
"SharedActionEvent.java",
7070
"PackageRootResolver.java",
7171
"PackageRoots.java",
@@ -306,9 +306,9 @@ java_library(
306306
"FileContentsProxy.java",
307307
"FileStateType.java",
308308
"FileStateValue.java",
309+
"FileStatusWithMetadata.java",
309310
"FileValue.java",
310311
"RemoteArtifactChecker.java",
311-
"RemoteFileStatus.java",
312312
"cache/MetadataDigestUtils.java",
313313
],
314314
deps = [

src/main/java/com/google/devtools/build/lib/actions/RemoteFileStatus.java renamed to src/main/java/com/google/devtools/build/lib/actions/FileStatusWithMetadata.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
// limitations under the License.
1414
package com.google.devtools.build.lib.actions;
1515

16-
import com.google.devtools.build.lib.actions.FileArtifactValue.RemoteFileArtifactValue;
1716
import com.google.devtools.build.lib.vfs.FileStatusWithDigest;
1817

1918
/**
20-
* A FileStatus that exists remotely and provides remote metadata.
19+
* A FileStatus that provides metadata.
2120
*
22-
* <p>Filesystem may return implementation of this interface if the files are stored remotely. When
23-
* checking outputs of actions, Skyframe will inject the metadata returned by {@link
24-
* #getRemoteMetadata()} if the output file has {@link RemoteFileStatus}.
21+
* <p>Filesystem may return implementation of this interface if the files are stored in the memory.
22+
* When checking outputs of actions, Skyframe will inject the metadata returned by {@link
23+
* #getMetadata()} instead of construct a new metadata from the status.
2524
*/
26-
public interface RemoteFileStatus extends FileStatusWithDigest {
27-
RemoteFileArtifactValue getRemoteMetadata();
25+
public interface FileStatusWithMetadata extends FileStatusWithDigest {
26+
FileArtifactValue getMetadata();
2827
}

src/main/java/com/google/devtools/build/lib/remote/RemoteActionFileSystem.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
3535
import com.google.devtools.build.lib.actions.FileArtifactValue;
3636
import com.google.devtools.build.lib.actions.FileArtifactValue.RemoteFileArtifactValue;
37+
import com.google.devtools.build.lib.actions.FileStatusWithMetadata;
3738
import com.google.devtools.build.lib.actions.InputMetadataProvider;
38-
import com.google.devtools.build.lib.actions.RemoteFileStatus;
3939
import com.google.devtools.build.lib.actions.cache.MetadataInjector;
4040
import com.google.devtools.build.lib.clock.Clock;
4141
import com.google.devtools.build.lib.skyframe.TreeArtifactValue;
@@ -247,14 +247,6 @@ private void maybeInjectMetadataForSymlinkOrDownload(PathFragment linkPath, Arti
247247
}
248248
}
249249

250-
private RemoteFileArtifactValue createRemoteMetadata(RemoteFileInfo remoteFile) {
251-
return RemoteFileArtifactValue.create(
252-
remoteFile.getFastDigest(),
253-
remoteFile.getSize(),
254-
/* locationIndex= */ 1,
255-
remoteFile.getExpireAtEpochMilli());
256-
}
257-
258250
@Override
259251
public String getFileSystemType(PathFragment path) {
260252
return "remoteActionFS";
@@ -520,7 +512,7 @@ protected FileStatus stat(PathFragment path, boolean followSymlinks) throws IOEx
520512
}
521513

522514
private static FileStatus statFromRemoteMetadata(RemoteFileArtifactValue m) {
523-
return new RemoteFileStatus() {
515+
return new FileStatusWithMetadata() {
524516
@Override
525517
public byte[] getDigest() {
526518
return m.getDigest();
@@ -567,7 +559,7 @@ public long getNodeId() {
567559
}
568560

569561
@Override
570-
public RemoteFileArtifactValue getRemoteMetadata() {
562+
public RemoteFileArtifactValue getMetadata() {
571563
return m;
572564
}
573565
};
@@ -596,7 +588,7 @@ public FileArtifactValue getOutputMetadataForTopLevelArtifactDownloader(ActionIn
596588
remoteOutputTree.getRemoteFileInfo(
597589
execRoot.getRelative(input.getExecPath()), /* followSymlinks= */ true);
598590
if (remoteFile != null) {
599-
return createRemoteMetadata(remoteFile);
591+
return remoteFile.getMetadata();
600592
}
601593

602594
// TODO(tjgq): This should not work.
@@ -627,7 +619,7 @@ private FileArtifactValue getMetadataByExecPath(PathFragment execPath) {
627619
remoteOutputTree.getRemoteFileInfo(
628620
execRoot.getRelative(execPath), /* followSymlinks= */ true);
629621
if (remoteFile != null) {
630-
return createRemoteMetadata(remoteFile);
622+
return remoteFile.getMetadata();
631623
}
632624

633625
return null;
@@ -846,7 +838,10 @@ void injectRemoteFile(PathFragment path, byte[] digest, long size, long expireAt
846838
}
847839

848840
RemoteFileInfo remoteFileInfo = (RemoteFileInfo) node;
849-
remoteFileInfo.set(digest, size, expireAtEpochMilli);
841+
842+
var metadata =
843+
RemoteFileArtifactValue.create(digest, size, /* locationIndex= */ 1, expireAtEpochMilli);
844+
remoteFileInfo.set(metadata);
850845
}
851846

852847
@Nullable
@@ -859,21 +854,15 @@ RemoteFileInfo getRemoteFileInfo(PathFragment path, boolean followSymlinks) {
859854
}
860855
}
861856

862-
static class RemoteFileInfo extends FileInfo {
863-
864-
private byte[] digest;
865-
private long size;
866-
867-
private long expireAtEpochMilli;
857+
static class RemoteFileInfo extends FileInfo implements FileStatusWithMetadata {
858+
private RemoteFileArtifactValue metadata;
868859

869860
RemoteFileInfo(Clock clock) {
870861
super(clock);
871862
}
872863

873-
private void set(byte[] digest, long size, long expireAtEpochMilli) {
874-
this.digest = digest;
875-
this.size = size;
876-
this.expireAtEpochMilli = expireAtEpochMilli;
864+
private void set(RemoteFileArtifactValue metadata) {
865+
this.metadata = metadata;
877866
}
878867

879868
@Override
@@ -893,16 +882,26 @@ public byte[] getxattr(String name) throws IOException {
893882

894883
@Override
895884
public byte[] getFastDigest() {
896-
return digest;
885+
return metadata.getDigest();
886+
}
887+
888+
@Override
889+
public byte[] getDigest() throws IOException {
890+
return metadata.getDigest();
897891
}
898892

899893
@Override
900894
public long getSize() {
901-
return size;
895+
return metadata.getSize();
902896
}
903897

904898
public long getExpireAtEpochMilli() {
905-
return expireAtEpochMilli;
899+
return metadata.getExpireAtEpochMilli();
900+
}
901+
902+
@Override
903+
public RemoteFileArtifactValue getMetadata() {
904+
return metadata;
906905
}
907906
}
908907
}

src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
import com.google.devtools.build.lib.actions.FileArtifactValue;
3737
import com.google.devtools.build.lib.actions.FileStateType;
3838
import com.google.devtools.build.lib.actions.FileStateValue;
39+
import com.google.devtools.build.lib.actions.FileStatusWithMetadata;
3940
import com.google.devtools.build.lib.actions.FilesetManifest;
4041
import com.google.devtools.build.lib.actions.FilesetManifest.RelativeSymlinkBehaviorWithoutError;
4142
import com.google.devtools.build.lib.actions.FilesetOutputSymlink;
4243
import com.google.devtools.build.lib.actions.InputMetadataProvider;
43-
import com.google.devtools.build.lib.actions.RemoteFileStatus;
4444
import com.google.devtools.build.lib.actions.cache.OutputMetadataStore;
4545
import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor;
4646
import com.google.devtools.build.lib.vfs.DigestUtils;
@@ -682,8 +682,8 @@ private static FileArtifactValue fileArtifactValueFromStat(
682682
return FileArtifactValue.createForDirectoryWithMtime(stat.getLastModifiedTime());
683683
}
684684

685-
if (stat instanceof RemoteFileStatus) {
686-
return ((RemoteFileStatus) stat).getRemoteMetadata();
685+
if (stat instanceof FileStatusWithMetadata) {
686+
return ((FileStatusWithMetadata) stat).getMetadata();
687687
}
688688

689689
FileStateValue fileStateValue =

0 commit comments

Comments
 (0)