Skip to content

Commit 60749d5

Browse files
tjgqcoeuvre
andauthored
[6.2.0] Remove actionId from RemoteFileArtifactValue. (#17724)
actionId was added by #11236 to track download requests for input prefetches. However, according to the REAPI spec, action_id is > An identifier that ties multiple requests to the same action. For example, multiple requests to the CAS, Action Cache, and Execution API are used in order to compile foo.cc. The input prefetches are requested by local actions that depend on outputs of remote executed action (which is identified by the action_id). These requests are not part of generating action hence shouldn't be bound with the action_id. We could include ActionExecutionMetadata of the local action for the requests for the tracking purpose, but that desires another CL. PiperOrigin-RevId: 510430853 Change-Id: I8d64a4f7033320a394e02a2b11498f09a3d15310 Co-authored-by: Googler <[email protected]>
1 parent 94c519b commit 60749d5

13 files changed

+145
-185
lines changed

src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java

+10-41
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,6 @@ public int getLocationIndex() {
109109
return 0;
110110
}
111111

112-
/**
113-
* Remote action source identifier for the file.
114-
*
115-
* <p>"" indicates that a remote action output was not the source of this artifact.
116-
*/
117-
public String getActionId() {
118-
return "";
119-
}
120-
121112
/** Returns {@code true} if the file only exists remotely. */
122113
public boolean isRemote() {
123114
return false;
@@ -550,35 +541,27 @@ public static class RemoteFileArtifactValue extends FileArtifactValue {
550541
protected final byte[] digest;
551542
protected final long size;
552543
protected final int locationIndex;
553-
protected final String actionId;
554544

555-
private RemoteFileArtifactValue(byte[] digest, long size, int locationIndex, String actionId) {
556-
this.digest = Preconditions.checkNotNull(digest, actionId);
545+
private RemoteFileArtifactValue(byte[] digest, long size, int locationIndex) {
546+
this.digest = Preconditions.checkNotNull(digest);
557547
this.size = size;
558548
this.locationIndex = locationIndex;
559-
this.actionId = actionId;
560-
}
561-
562-
public static RemoteFileArtifactValue create(
563-
byte[] digest, long size, int locationIndex, String actionId) {
564-
return new RemoteFileArtifactValue(digest, size, locationIndex, actionId);
565549
}
566550

567551
public static RemoteFileArtifactValue create(byte[] digest, long size, int locationIndex) {
568-
return new RemoteFileArtifactValue(digest, size, locationIndex, /* actionId= */ "");
552+
return new RemoteFileArtifactValue(digest, size, locationIndex);
569553
}
570554

571555
public static RemoteFileArtifactValue create(
572556
byte[] digest,
573557
long size,
574558
int locationIndex,
575-
String actionId,
576559
@Nullable PathFragment materializationExecPath) {
577560
if (materializationExecPath != null) {
578561
return new RemoteFileArtifactValueWithMaterializationPath(
579-
digest, size, locationIndex, actionId, materializationExecPath);
562+
digest, size, locationIndex, materializationExecPath);
580563
}
581-
return new RemoteFileArtifactValue(digest, size, locationIndex, actionId);
564+
return new RemoteFileArtifactValue(digest, size, locationIndex);
582565
}
583566

584567
@Override
@@ -590,13 +573,12 @@ public boolean equals(Object o) {
590573
RemoteFileArtifactValue that = (RemoteFileArtifactValue) o;
591574
return Arrays.equals(digest, that.digest)
592575
&& size == that.size
593-
&& locationIndex == that.locationIndex
594-
&& Objects.equals(actionId, that.actionId);
576+
&& locationIndex == that.locationIndex;
595577
}
596578

597579
@Override
598580
public int hashCode() {
599-
return Objects.hash(Arrays.hashCode(digest), size, locationIndex, actionId);
581+
return Objects.hash(Arrays.hashCode(digest), size, locationIndex);
600582
}
601583

602584
@Override
@@ -619,11 +601,6 @@ public long getSize() {
619601
return size;
620602
}
621603

622-
@Override
623-
public String getActionId() {
624-
return actionId;
625-
}
626-
627604
@Override
628605
public long getModifiedTime() {
629606
throw new UnsupportedOperationException(
@@ -651,7 +628,6 @@ public String toString() {
651628
.add("digest", bytesToString(digest))
652629
.add("size", size)
653630
.add("locationIndex", locationIndex)
654-
.add("actionId", actionId)
655631
.toString();
656632
}
657633
}
@@ -667,12 +643,8 @@ public static final class RemoteFileArtifactValueWithMaterializationPath
667643
private final PathFragment materializationExecPath;
668644

669645
private RemoteFileArtifactValueWithMaterializationPath(
670-
byte[] digest,
671-
long size,
672-
int locationIndex,
673-
String actionId,
674-
PathFragment materializationExecPath) {
675-
super(digest, size, locationIndex, actionId);
646+
byte[] digest, long size, int locationIndex, PathFragment materializationExecPath) {
647+
super(digest, size, locationIndex);
676648
this.materializationExecPath = Preconditions.checkNotNull(materializationExecPath);
677649
}
678650

@@ -692,14 +664,12 @@ public boolean equals(Object o) {
692664
return Arrays.equals(digest, that.digest)
693665
&& size == that.size
694666
&& locationIndex == that.locationIndex
695-
&& Objects.equals(actionId, that.actionId)
696667
&& Objects.equals(materializationExecPath, that.materializationExecPath);
697668
}
698669

699670
@Override
700671
public int hashCode() {
701-
return Objects.hash(
702-
Arrays.hashCode(digest), size, locationIndex, actionId, materializationExecPath);
672+
return Objects.hash(Arrays.hashCode(digest), size, locationIndex, materializationExecPath);
703673
}
704674

705675
@Override
@@ -708,7 +678,6 @@ public String toString() {
708678
.add("digest", bytesToString(digest))
709679
.add("size", size)
710680
.add("locationIndex", locationIndex)
711-
.add("actionId", actionId)
712681
.add("materializationExecPath", materializationExecPath)
713682
.toString();
714683
}

src/main/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCache.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class CompactPersistentActionCache implements ActionCache {
7676

7777
private static final int NO_INPUT_DISCOVERY_COUNT = -1;
7878

79-
private static final int VERSION = 14;
79+
private static final int VERSION = 15;
8080

8181
private static final class ActionMap extends PersistentMap<Integer, byte[]> {
8282
private final Clock clock;
@@ -466,8 +466,6 @@ private static void encodeRemoteMetadata(
466466

467467
VarInt.putVarInt(value.getLocationIndex(), sink);
468468

469-
VarInt.putVarInt(indexer.getOrCreateIndex(value.getActionId()), sink);
470-
471469
Optional<PathFragment> materializationExecPath = value.getMaterializationExecPath();
472470
if (materializationExecPath.isPresent()) {
473471
VarInt.putVarInt(1, sink);
@@ -491,8 +489,6 @@ private static RemoteFileArtifactValue decodeRemoteMetadata(
491489

492490
int locationIndex = VarInt.getVarInt(source);
493491

494-
String actionId = getStringForIndex(indexer, VarInt.getVarInt(source));
495-
496492
PathFragment materializationExecPath = null;
497493
int numMaterializationExecPath = VarInt.getVarInt(source);
498494
if (numMaterializationExecPath > 0) {
@@ -503,8 +499,7 @@ private static RemoteFileArtifactValue decodeRemoteMetadata(
503499
PathFragment.create(getStringForIndex(indexer, VarInt.getVarInt(source)));
504500
}
505501

506-
return RemoteFileArtifactValue.create(
507-
digest, size, locationIndex, actionId, materializationExecPath);
502+
return RemoteFileArtifactValue.create(digest, size, locationIndex, materializationExecPath);
508503
}
509504

510505
/** @return action data encoded as a byte[] array. */

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

+6-18
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,11 @@ public void updateContext(MetadataInjector metadataInjector) {
115115
this.metadataInjector = metadataInjector;
116116
}
117117

118-
void injectRemoteFile(PathFragment path, byte[] digest, long size, String actionId)
119-
throws IOException {
118+
void injectRemoteFile(PathFragment path, byte[] digest, long size) throws IOException {
120119
if (!isOutput(path)) {
121120
return;
122121
}
123-
remoteOutputTree.injectRemoteFile(path, digest, size, actionId);
122+
remoteOutputTree.injectRemoteFile(path, digest, size);
124123
}
125124

126125
void flush() throws IOException {
@@ -207,7 +206,6 @@ private void maybeInjectMetadataForSymlink(PathFragment linkPath, Artifact outpu
207206
metadata.getDigest(),
208207
metadata.getSize(),
209208
metadata.getLocationIndex(),
210-
metadata.getActionId(),
211209
// Avoid a double indirection when the target is already materialized as a symlink.
212210
metadata.getMaterializationExecPath().orElse(targetPath.relativeTo(execRoot)));
213211

@@ -217,10 +215,7 @@ private void maybeInjectMetadataForSymlink(PathFragment linkPath, Artifact outpu
217215

218216
private RemoteFileArtifactValue createRemoteMetadata(RemoteFileInfo remoteFile) {
219217
return RemoteFileArtifactValue.create(
220-
remoteFile.getFastDigest(),
221-
remoteFile.getSize(),
222-
/* locationIndex= */ 1,
223-
remoteFile.getActionId());
218+
remoteFile.getFastDigest(), remoteFile.getSize(), /* locationIndex= */ 1);
224219
}
225220

226221
@Override
@@ -748,8 +743,7 @@ protected FileInfo newFile(Clock clock, PathFragment path) {
748743
return new RemoteFileInfo(clock);
749744
}
750745

751-
void injectRemoteFile(PathFragment path, byte[] digest, long size, String actionId)
752-
throws IOException {
746+
void injectRemoteFile(PathFragment path, byte[] digest, long size) throws IOException {
753747
createDirectoryAndParents(path.getParentDirectory());
754748
InMemoryContentInfo node = getOrCreateWritableInode(path);
755749
// If a node was already existed and is not a remote file node (i.e. directory or symlink node
@@ -759,7 +753,7 @@ void injectRemoteFile(PathFragment path, byte[] digest, long size, String action
759753
}
760754

761755
RemoteFileInfo remoteFileInfo = (RemoteFileInfo) node;
762-
remoteFileInfo.set(digest, size, actionId);
756+
remoteFileInfo.set(digest, size);
763757
}
764758

765759
@Nullable
@@ -776,16 +770,14 @@ static class RemoteFileInfo extends FileInfo {
776770

777771
private byte[] digest;
778772
private long size;
779-
private String actionId;
780773

781774
RemoteFileInfo(Clock clock) {
782775
super(clock);
783776
}
784777

785-
private void set(byte[] digest, long size, String actionId) {
778+
private void set(byte[] digest, long size) {
786779
this.digest = digest;
787780
this.size = size;
788-
this.actionId = actionId;
789781
}
790782

791783
@Override
@@ -812,9 +804,5 @@ public byte[] getFastDigest() {
812804
public long getSize() {
813805
return size;
814806
}
815-
816-
public String getActionId() {
817-
return actionId;
818-
}
819807
}
820808
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected ListenableFuture<Void> doDownloadFile(
104104
throws IOException {
105105
checkArgument(metadata.isRemote(), "Cannot download file that is not a remote file.");
106106
RequestMetadata requestMetadata =
107-
TracingMetadataUtils.buildMetadata(buildRequestId, commandId, metadata.getActionId(), null);
107+
TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "prefetcher", null);
108108
RemoteActionExecutionContext context = RemoteActionExecutionContext.create(requestMetadata);
109109

110110
Digest digest = DigestUtil.buildDigest(metadata.getDigest(), metadata.getSize());

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,6 @@ private void injectRemoteArtifacts(RemoteAction action, ActionResultMetadata met
812812
FileSystem actionFileSystem = action.getSpawnExecutionContext().getActionFileSystem();
813813
checkState(actionFileSystem instanceof RemoteActionFileSystem);
814814

815-
RemoteActionExecutionContext context = action.getRemoteActionExecutionContext();
816815
RemoteActionFileSystem remoteActionFileSystem = (RemoteActionFileSystem) actionFileSystem;
817816

818817
for (Map.Entry<Path, DirectoryMetadata> entry : metadata.directories()) {
@@ -827,17 +826,15 @@ private void injectRemoteArtifacts(RemoteAction action, ActionResultMetadata met
827826
remoteActionFileSystem.injectRemoteFile(
828827
file.path().asFragment(),
829828
DigestUtil.toBinaryDigest(file.digest()),
830-
file.digest().getSizeBytes(),
831-
context.getRequestMetadata().getActionId());
829+
file.digest().getSizeBytes());
832830
}
833831
}
834832

835833
for (FileMetadata file : metadata.files()) {
836834
remoteActionFileSystem.injectRemoteFile(
837835
file.path().asFragment(),
838836
DigestUtil.toBinaryDigest(file.digest()),
839-
file.digest().getSizeBytes(),
840-
context.getRequestMetadata().getActionId());
837+
file.digest().getSizeBytes());
841838
}
842839
}
843840

src/test/java/com/google/devtools/build/lib/actions/ActionCacheCheckerTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,7 @@ private RemoteFileArtifactValue createRemoteFileMetadata(String content) {
463463
private RemoteFileArtifactValue createRemoteFileMetadata(
464464
String content, @Nullable PathFragment materializationExecPath) {
465465
byte[] bytes = content.getBytes(UTF_8);
466-
return RemoteFileArtifactValue.create(
467-
digest(bytes), bytes.length, 1, "action-id", materializationExecPath);
466+
return RemoteFileArtifactValue.create(digest(bytes), bytes.length, 1, materializationExecPath);
468467
}
469468

470469
private static TreeArtifactValue createTreeMetadata(

src/test/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCacheTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ private RemoteFileArtifactValue createRemoteMetadata(
208208
.getHashFunction()
209209
.hashBytes(bytes)
210210
.asBytes();
211-
return RemoteFileArtifactValue.create(
212-
digest, bytes.length, 1, "action-id", materializationExecPath);
211+
return RemoteFileArtifactValue.create(digest, bytes.length, 1, materializationExecPath);
213212
}
214213

215214
private RemoteFileArtifactValue createRemoteMetadata(Artifact artifact, String content) {

src/test/java/com/google/devtools/build/lib/remote/ActionInputPrefetcherTestBase.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ protected Artifact createRemoteArtifact(
100100
hashCode.asBytes(),
101101
contentsBytes.length,
102102
/* locationIndex= */ 1,
103-
"action-id",
104103
materializationExecPath);
105104
metadata.put(a, f);
106105
if (cas != null) {
@@ -136,7 +135,7 @@ protected Pair<SpecialArtifact, ImmutableList<TreeFileArtifact>> createRemoteTre
136135
TreeFileArtifact.createTreeOutput(parent, PathFragment.create(entry.getKey()));
137136
RemoteFileArtifactValue childValue =
138137
RemoteFileArtifactValue.create(
139-
hashCode.asBytes(), contentsBytes.length, /* locationIndex= */ 1, "action-id");
138+
hashCode.asBytes(), contentsBytes.length, /* locationIndex= */ 1);
140139
treeBuilder.putChild(child, childValue);
141140
metadata.put(child, childValue);
142141
cas.put(hashCode, contentsBytes);

src/test/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ private Artifact createRemoteArtifact(
442442
byte[] b = contents.getBytes(StandardCharsets.UTF_8);
443443
HashCode h = HashCode.fromString(DIGEST_UTIL.compute(b).getHash());
444444
FileArtifactValue f =
445-
RemoteFileArtifactValue.create(h.asBytes(), b.length, /* locationIndex= */ 1, "action-id");
445+
RemoteFileArtifactValue.create(h.asBytes(), b.length, /* locationIndex= */ 1);
446446
inputs.putWithNoDepOwner(a, f);
447447
return a;
448448
}
@@ -513,8 +513,6 @@ public ListenableFuture<ImmutableSet<Digest>> findMissingDigests(
513513

514514
private static class AllMissingDigestsFinder implements MissingDigestsFinder {
515515

516-
public static final AllMissingDigestsFinder INSTANCE = new AllMissingDigestsFinder();
517-
518516
@Override
519517
public ListenableFuture<ImmutableSet<Digest>> findMissingDigests(
520518
RemoteActionExecutionContext context, Iterable<Digest> digests) {

src/test/java/com/google/devtools/build/lib/remote/RemoteActionFileSystemTest.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ protected void injectRemoteFile(FileSystem actionFs, PathFragment path, String c
326326
byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
327327
HashCode hashCode = HASH_FUNCTION.getHashFunction().hashBytes(contentBytes);
328328
((RemoteActionFileSystem) actionFs)
329-
.injectRemoteFile(path, hashCode.asBytes(), contentBytes.length, "action-id");
329+
.injectRemoteFile(path, hashCode.asBytes(), contentBytes.length);
330330
}
331331

332332
@Override
@@ -342,7 +342,7 @@ private Artifact createRemoteArtifact(
342342
byte[] b = contents.getBytes(StandardCharsets.UTF_8);
343343
HashCode h = HASH_FUNCTION.getHashFunction().hashBytes(b);
344344
RemoteFileArtifactValue f =
345-
RemoteFileArtifactValue.create(h.asBytes(), b.length, /* locationIndex= */ 1, "action-id");
345+
RemoteFileArtifactValue.create(h.asBytes(), b.length, /* locationIndex= */ 1);
346346
inputs.putWithNoDepOwner(a, f);
347347
return a;
348348
}
@@ -364,8 +364,7 @@ private TreeArtifactValue createRemoteTreeArtifactValue(
364364
byte[] b = entry.getValue().getBytes(StandardCharsets.UTF_8);
365365
HashCode h = HASH_FUNCTION.getHashFunction().hashBytes(b);
366366
RemoteFileArtifactValue childMeta =
367-
RemoteFileArtifactValue.create(
368-
h.asBytes(), b.length, /* locationIndex= */ 0, "action-id");
367+
RemoteFileArtifactValue.create(h.asBytes(), b.length, /* locationIndex= */ 0);
369368
builder.putChild(child, childMeta);
370369
}
371370
return builder.build();

0 commit comments

Comments
 (0)