Skip to content

Commit

Permalink
Create a dedicated graph lookup reason for rewinding and add a wildca…
Browse files Browse the repository at this point in the history
…rd to `createIfAbsentBatch` to match `getBatch`.

PiperOrigin-RevId: 452172428
Change-Id: I2ed3fbd0a92568b231aa06471ee0be1cb574f987
  • Loading branch information
justinhorvitz authored and copybara-github committed May 31, 2022
1 parent 93f6e51 commit a0a0d09
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ private boolean maybeHandleRestart(SkyKey key, NodeEntry entry, SkyValue returne
}

Map<SkyKey, ? extends NodeEntry> additionalNodesToRestart =
evaluatorContext.getBatchValues(key, Reason.INVALIDATION, additionalKeysToRestart);
evaluatorContext.getBatchValues(key, Reason.REWINDING, additionalKeysToRestart);

ArrayList<SkyKey> missingNodes = null;
for (SkyKey keyToRestart : additionalKeysToRestart) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static InMemoryGraph createEdgeless() {

@Override
Map<SkyKey, ? extends NodeEntry> createIfAbsentBatch(
@Nullable SkyKey requestor, Reason reason, Iterable<SkyKey> keys);
@Nullable SkyKey requestor, Reason reason, Iterable<? extends SkyKey> keys);

@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected InMemoryNodeEntry newNodeEntry(SkyKey key) {

@Override
public Map<SkyKey, NodeEntry> createIfAbsentBatch(
@Nullable SkyKey requestor, Reason reason, Iterable<SkyKey> keys) {
@Nullable SkyKey requestor, Reason reason, Iterable<? extends SkyKey> keys) {
Map<SkyKey, NodeEntry> result = CompactHashMap.createWithExpectedSize(Iterables.size(keys));
for (SkyKey key : keys) {
result.put(key, nodeMap.computeIfAbsent(key, newNodeEntryFunction));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public interface ProcessableGraph extends QueryableGraph {
* @param reason the reason the nodes are being requested.
*/
Map<SkyKey, ? extends NodeEntry> createIfAbsentBatch(
@Nullable SkyKey requestor, Reason reason, Iterable<SkyKey> keys) throws InterruptedException;
@Nullable SkyKey requestor, Reason reason, Iterable<? extends SkyKey> keys)
throws InterruptedException;

/**
* Like {@link QueryableGraph#getBatchAsync}, except it creates a new node for each key not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public interface QueryableGraph {
*/
Map<SkyKey, ? extends NodeEntry> getBatch(
@Nullable SkyKey requestor, Reason reason, Iterable<? extends SkyKey> keys)
throws InterruptedException;
throws InterruptedException;

/**
* A version of {@link #getBatch} that returns an {@link InterruptibleSupplier} to possibly
Expand Down Expand Up @@ -153,6 +153,12 @@ enum Reason {
/** The node is being looked up merely to see if it is done or not. */
DONE_CHECKING,

/**
* The node is being looked up so that it can be {@linkplain
* ThinNodeEntry.DirtyType#FORCE_REBUILD force rebuilt} by rewinding.
*/
REWINDING,

/**
* The node is being looked up to service {@link WalkableGraph#getValue},
* {@link WalkableGraph#getException}, {@link WalkableGraph#getMissingAndExceptions}, or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void remove(SkyKey key) {

@Override
public Map<SkyKey, ? extends NodeEntry> createIfAbsentBatch(
@Nullable SkyKey requestor, Reason reason, Iterable<SkyKey> keys)
@Nullable SkyKey requestor, Reason reason, Iterable<? extends SkyKey> keys)
throws InterruptedException {
return makeDeterministic(super.createIfAbsentBatch(requestor, reason, keys));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DeterministicInMemoryGraph extends DeterministicHelper.DeterministicProces

@Override
public Map<SkyKey, ? extends NodeEntry> createIfAbsentBatch(
@Nullable SkyKey requestor, Reason reason, Iterable<SkyKey> keys) {
@Nullable SkyKey requestor, Reason reason, Iterable<? extends SkyKey> keys) {
try {
return super.createIfAbsentBatch(requestor, reason, keys);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.google.common.base.Joiner;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Maps;
import com.google.common.collect.Maps.EntryTransformer;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.util.GroupedList;
import com.google.devtools.build.lib.util.GroupedList.GroupedListHelper;
Expand Down Expand Up @@ -55,15 +54,6 @@ public ProcessableGraph transform(ProcessableGraph graph) {

protected final Listener graphListener;

protected final EntryTransformer<SkyKey, ThinNodeEntry, NodeEntry> wrapEntry =
new EntryTransformer<SkyKey, ThinNodeEntry, NodeEntry>() {
@Nullable
@Override
public NotifyingNodeEntry transformEntry(SkyKey key, @Nullable ThinNodeEntry nodeEntry) {
return wrapEntry(key, nodeEntry);
}
};

NotifyingHelper(Listener graphListener) {
this.graphListener = new ErrorRecordingDelegatingListener(graphListener);
}
Expand Down Expand Up @@ -96,8 +86,7 @@ static class NotifyingQueryableGraph implements QueryableGraph {
notifyingHelper.graphListener.accept(key, EventType.GET_BATCH, Order.BEFORE, reason);
}
return Maps.transformEntries(
delegate.getBatch(requestor, reason, keys),
notifyingHelper.wrapEntry);
delegate.getBatch(requestor, reason, keys), notifyingHelper::wrapEntry);
}

@Nullable
Expand Down Expand Up @@ -129,14 +118,13 @@ public void remove(SkyKey key) {

@Override
public Map<SkyKey, ? extends NodeEntry> createIfAbsentBatch(
@Nullable SkyKey requestor, Reason reason, Iterable<SkyKey> keys)
@Nullable SkyKey requestor, Reason reason, Iterable<? extends SkyKey> keys)
throws InterruptedException {
for (SkyKey key : keys) {
notifyingHelper.graphListener.accept(key, EventType.CREATE_IF_ABSENT, Order.BEFORE, null);
}
return Maps.transformEntries(
delegate.createIfAbsentBatch(requestor, reason, keys),
notifyingHelper.wrapEntry);
delegate.createIfAbsentBatch(requestor, reason, keys), notifyingHelper::wrapEntry);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NotifyingInMemoryGraph extends NotifyingHelper.NotifyingProcessableGraph

@Override
public Map<SkyKey, ? extends NodeEntry> createIfAbsentBatch(
@Nullable SkyKey requestor, Reason reason, Iterable<SkyKey> keys) {
@Nullable SkyKey requestor, Reason reason, Iterable<? extends SkyKey> keys) {
try {
return super.createIfAbsentBatch(requestor, reason, keys);
} catch (InterruptedException e) {
Expand Down

0 comments on commit a0a0d09

Please sign in to comment.