diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java index 11c0c45ef414a7..d32da13d6797a7 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java @@ -128,6 +128,7 @@ import io.reactivex.rxjava3.core.SingleObserver; import io.reactivex.rxjava3.disposables.Disposable; import io.reactivex.rxjava3.schedulers.Schedulers; + import java.io.IOException; import java.time.Instant; import java.util.ArrayList; @@ -340,7 +341,8 @@ public CachePolicy getWriteCachePolicy(Spawn spawn) { public boolean mayBeExecutedRemotely(Spawn spawn) { return remoteCache instanceof RemoteExecutionCache && remoteExecutor != null - && Spawns.mayBeExecutedRemotely(spawn); + && Spawns.mayBeExecutedRemotely(spawn) + && !(remoteOptions.remoteCacheKeyIgnoreStamping && hasVolatileArtifacts(spawn)); } private SortedMap buildOutputDirMap(Spawn spawn) { @@ -398,7 +400,7 @@ private MerkleTree buildInputMerkleTree( inputMap = newInputMap; } return MerkleTree.build( - inputMap, + filterInputs(inputMap), toolSignature == null ? ImmutableSet.of() : toolSignature.toolInputs, context.getMetadataProvider(), execRoot, @@ -430,7 +432,7 @@ public MerkleTree uncachedBuildMerkleTreeVisitor( ConcurrentLinkedQueue subMerkleTrees = new ConcurrentLinkedQueue<>(); subMerkleTrees.add( MerkleTree.build( - walker.getLeavesInputMapping(), + filterInputs(walker.getLeavesInputMapping()), metadataProvider, execRoot, artifactPathResolver, @@ -444,6 +446,20 @@ public MerkleTree uncachedBuildMerkleTreeVisitor( return MerkleTree.merge(subMerkleTrees, digestUtil); } + private SortedMap filterInputs(SortedMap inputs) { + if (!remoteOptions.remoteCacheKeyIgnoreStamping) { + return inputs; + } + SortedMap result = new TreeMap<>(); + for (Entry entry : inputs.entrySet()) { + ActionInput input = entry.getValue(); + if (!isConstantMetadata(input)) { + result.put(entry.getKey(), input); + } + } + return result; + } + @Nullable private static ByteString buildSalt(Spawn spawn) { CacheSalt.Builder saltBuilder = @@ -1585,6 +1601,23 @@ void report(Event evt) { } } + private static boolean hasVolatileArtifacts(Spawn spawn) { + var inputFiles = spawn.getInputFiles(); + for (ActionInput inputFile : inputFiles.getLeaves()) { + if (isConstantMetadata(inputFile)) { + return true; + } + } + return false; + } + + private static boolean isConstantMetadata(ActionInput input) { + if (input instanceof Artifact) { + return ((Artifact) input).isConstantMetadata(); + } + return false; + } + /** * A simple value class combining a hash of the tool inputs (and their digests) as well as a set * of the relative paths of all tool inputs. diff --git a/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java b/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java index 41d237fe5e6666..cfa65f5908a340 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java +++ b/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java @@ -80,6 +80,14 @@ public final class RemoteOptions extends CommonRemoteOptions { + "disable TLS.") public String remoteExecutor; + @Option( + name = "experimental_remote_cache_key_ignore_stamping", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.REMOTE, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "Don't use volatile stamping data in shared cache key. Also disable remote execution for stamping actions.") + public boolean remoteCacheKeyIgnoreStamping; + @Option( name = "experimental_remote_execution_keepalive", defaultValue = "false",