Skip to content

Commit

Permalink
Add assertion for frontier candidate selection.
Browse files Browse the repository at this point in the history
Also discovered an edge case where we were unnecessarily serializing a BuildInfo node.

PiperOrigin-RevId: 676426951
Change-Id: I1d619557b4e870455b2e4245b528d0cdaadf9e36
  • Loading branch information
jin authored and copybara-github committed Sep 19, 2024
1 parent 6045087 commit dafa4b5
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static java.util.concurrent.ForkJoinPool.commonPool;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Stopwatch;
import com.google.common.eventbus.EventBus;
import com.google.common.util.concurrent.Futures;
Expand Down Expand Up @@ -115,6 +116,11 @@ public static Optional<FailureDetail> serializeAndUploadFrontier(
if (!marking.equals(FRONTIER_CANDIDATE)) {
return;
}
Preconditions.checkState(
!dependenciesProvider.withinActiveDirectories(key.getLabel().getPackageIdentifier()),
"frontier candidates cannot include any node in the active set, but got %s",
key);

try {
SerializationResult<ByteString> keyBytes =
codecs.serializeMemoizedAndBlocking(fingerprintValueService, key, profileCollector);
Expand Down Expand Up @@ -239,12 +245,28 @@ private static void markActiveAndTraverseEdges(
if (!(dep instanceof ActionLookupKey child)) {
continue;
}
selection.putIfAbsent(child, FRONTIER_CANDIDATE);

// Three cases where a child node is disqualified to be a frontier candidate:
//
// 1) It doesn't have a label (e.g. BuildInfoKey). These nodes are not deserialized by the
// analysis functions we care about.
// 2) It is _already_ marked as ACTIVE, which means it was visited as an rdep from an active
// root. putIfAbsent will be a no-op.
// 3) It _will_ be marked as ACTIVE when visited as a rdep from an active root later, and
// overrides its FRONTIER_CANDIDATE state.
//
// In all cases, frontier candidates will never include nodes in the active directories. This
// is enforced after selection completes.
if (child.getLabel() != null) {
selection.putIfAbsent(child, FRONTIER_CANDIDATE);
}
}
for (SkyKey rdep : node.getReverseDepsForDoneEntry()) {
if (!(rdep instanceof ActionLookupKey parent)) {
continue;
}
// The active set can include nodes outside of the active directories iff they are in the UTC
// of a root in the active directories.
markActiveAndTraverseEdges(graph, parent, selection);
}
}
Expand Down

0 comments on commit dafa4b5

Please sign in to comment.