Skip to content

Commit

Permalink
Embed the blaze installation md5 into FrontierNodeVersion.
Browse files Browse the repository at this point in the history
This will allow only identical binaries to share remote SkyValues with each other,
even for development versions.

PiperOrigin-RevId: 681451196
Change-Id: I6f770bf28cddc4d45ef45afcc5d7873e5c3aa9bf
  • Loading branch information
jin authored and copybara-github committed Oct 2, 2024
1 parent b9999f4 commit cda2598
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
import com.google.common.flogger.GoogleLogger;
import com.google.common.hash.HashCode;
import com.google.devtools.build.lib.actions.Artifact.ArtifactSerializationContext;
import com.google.devtools.build.lib.actions.BuildFailedException;
import com.google.devtools.build.lib.actions.CommandLineExpansionException;
Expand Down Expand Up @@ -1117,6 +1118,7 @@ private static final class RemoteAnalysisCachingDependenciesProviderImpl
private final FingerprintValueService fingerprintValueService;
private final PathFragmentPrefixTrie activeDirectoriesMatcher;
private final RemoteAnalysisCachingEventListener listener;
private final HashCode blazeInstallMD5;

// Non-final because the top level BuildConfigurationValue is determined just before analysis
// begins in BuildView for the download/deserialization pass, which is later than when this
Expand Down Expand Up @@ -1148,6 +1150,7 @@ private RemoteAnalysisCachingDependenciesProviderImpl(
this.activeDirectoriesMatcher = activeDirectoriesMatcher;
this.listener = env.getRemoteAnalysisCachingEventListener();
this.topLevelConfig = env.getSkyframeBuildView().getBuildConfiguration();
this.blazeInstallMD5 = requireNonNull(env.getDirectories().getInstallMD5());
}

private static ObjectCodecs initAnalysisObjectCodecs(
Expand Down Expand Up @@ -1182,7 +1185,8 @@ public FrontierNodeVersion getSkyValueVersion() throws SerializationException {
frontierNodeVersionSingleton =
new FrontierNodeVersion(
topLevelConfig.checksum(),
getObjectCodecs().serializeMemoized(activeDirectoriesMatcher.toString()));
getObjectCodecs().serializeMemoized(activeDirectoriesMatcher.toString()),
blazeInstallMD5);
}
}
return frontierNodeVersionSingleton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.hash.HashCode;
import com.google.common.primitives.Bytes;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
Expand Down Expand Up @@ -326,18 +327,26 @@ private SkyValueRetriever() {}
/** A tuple representing the version of a cached SkyValue in the frontier. */
public static final class FrontierNodeVersion {
public static final FrontierNodeVersion CONSTANT_FOR_TESTING =
new FrontierNodeVersion("123", ByteString.copyFrom(new byte[] {1, 2, 3}));
new FrontierNodeVersion(
"123", ByteString.copyFrom(new byte[] {1, 2, 3}), HashCode.fromInt(42));
private final byte[] topLevelConfigFingerprint;
private final byte[] directoryMatcherFingerprint;
private final byte[] blazeInstallMD5Fingerprint;
private final byte[] precomputedFingerprint;

public FrontierNodeVersion(
String topLevelConfigChecksum, ByteString directoryMatcherFingerprint) {
String topLevelConfigChecksum,
ByteString directoryMatcherFingerprint,
HashCode blazeInstallMD5) {
// TODO: b/364831651 - add more fields like source and blaze versions.
this.topLevelConfigFingerprint = topLevelConfigChecksum.getBytes(UTF_8);
this.directoryMatcherFingerprint = directoryMatcherFingerprint.toByteArray();
this.blazeInstallMD5Fingerprint = blazeInstallMD5.asBytes();
this.precomputedFingerprint =
Bytes.concat(topLevelConfigFingerprint, this.directoryMatcherFingerprint);
Bytes.concat(
this.topLevelConfigFingerprint,
this.directoryMatcherFingerprint,
this.blazeInstallMD5Fingerprint);
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.junit.Assert.assertThrows;

import com.google.common.collect.ImmutableList;
import com.google.common.hash.HashCode;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.devtools.build.lib.skyframe.serialization.SkyValueRetriever.FrontierNodeVersion;
import com.google.devtools.build.lib.skyframe.serialization.SkyValueRetriever.ObservedFutureStatus;
Expand Down Expand Up @@ -166,7 +167,8 @@ public void waitingForFutureValueBytes_withMatchingDistinguisher_returnsImmediat
var version =
new FrontierNodeVersion(
/* topLevelConfigChecksum= */ "42",
/* directoryMatcherFingerprint= */ ByteString.copyFrom(new byte[] {1, 2, 3}));
/* directoryMatcherFingerprint= */ ByteString.copyFrom(new byte[] {1, 2, 3}),
/* blazeInstallMD5= */ HashCode.fromInt(42));
uploadKeyValuePair(key, version, value, fingerprintValueService);

RetrievalResult result =
Expand All @@ -192,7 +194,8 @@ public void waitingForFutureValueBytes_withNonMatchingDistinguisher_returnsNoCac
var version =
new FrontierNodeVersion(
/* topLevelConfigChecksum= */ "42",
/* directoryMatcherFingerprint= */ ByteString.copyFrom(new byte[] {1, 2, 3}));
/* directoryMatcherFingerprint= */ ByteString.copyFrom(new byte[] {1, 2, 3}),
/* blazeInstallMD5= */ HashCode.fromInt(42));
uploadKeyValuePair(key, version, value, fingerprintValueService);

RetrievalResult result =
Expand All @@ -205,7 +208,8 @@ public void waitingForFutureValueBytes_withNonMatchingDistinguisher_returnsNoCac
/* stateProvider= */ this,
/* frontierNodeVersion= */ new FrontierNodeVersion(
/* topLevelConfigChecksum= */ "9000",
/* directoryMatcherFingerprint= */ ByteString.copyFrom(new byte[] {7, 8, 9})));
/* directoryMatcherFingerprint= */ ByteString.copyFrom(new byte[] {7, 8, 9}),
/* blazeInstallMD5= */ HashCode.fromInt(9000)));

assertThat(result).isSameInstanceAs(NO_CACHED_DATA);
}
Expand Down

0 comments on commit cda2598

Please sign in to comment.