Augment the QueryableGraph#get[BatchWithFieldHints] method to take in parameters conveying the requesting node (if any), the requested node(s), as well as a reason for the skyframe graph lookup. Alternate graph implementations may be interested in this information.
--
MOS_MIGRATED_REVID=128496089
diff --git a/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java b/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java
index 73e42ea..df6f99c 100644
--- a/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java
@@ -30,7 +30,7 @@
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.skyframe.GraphTester.StringValue;
import com.google.devtools.build.skyframe.NodeEntry.DependencyState;
-
+import com.google.devtools.build.skyframe.QueryableGraph.Reason;
import org.junit.Before;
import org.junit.Test;
@@ -77,7 +77,7 @@
@Test
public void createIfAbsentBatchSanity() {
- graph.createIfAbsentBatch(ImmutableList.of(key("cat"), key("dog")));
+ graph.createIfAbsentBatch(null, Reason.OTHER, ImmutableList.of(key("cat"), key("dog")));
}
@Test
@@ -91,11 +91,11 @@
new Runnable() {
@Override
public void run() {
- graph.get(key);
+ graph.get(null, Reason.OTHER, key);
}
}));
t.start();
- assertThat(graph.createIfAbsentBatch(ImmutableList.of(key))).isNotEmpty();
+ assertThat(graph.createIfAbsentBatch(null, Reason.OTHER, ImmutableList.of(key))).isNotEmpty();
graph.remove(key);
}
}
@@ -111,7 +111,7 @@
public void run() {
TrackingAwaiter.INSTANCE.awaitLatchAndTrackExceptions(
startThreads, "threads not started");
- graph.createIfAbsentBatch(ImmutableList.of(key));
+ graph.createIfAbsentBatch(null, Reason.OTHER, ImmutableList.of(key));
}
};
Runnable noCreateRunnable =
@@ -120,7 +120,7 @@
public void run() {
TrackingAwaiter.INSTANCE.awaitLatchAndTrackExceptions(
startThreads, "threads not started");
- graph.get(key);
+ graph.get(null, Reason.OTHER, key);
}
};
List<Thread> threads = new ArrayList<>(2 * numThreads);
@@ -144,7 +144,7 @@
public void testAddRemoveRdeps() throws Exception {
SkyKey key = key("foo");
final NodeEntry entry = Iterables.getOnlyElement(
- graph.createIfAbsentBatch(ImmutableList.of(key)).values());
+ graph.createIfAbsentBatch(null, Reason.OTHER, ImmutableList.of(key)).values());
// These numbers are arbitrary.
int numThreads = 50;
int numKeys = numThreads;
@@ -169,7 +169,7 @@
for (int i = 0; i < numKeys; i++) {
rdepKeys.add(key("rdep" + i));
}
- graph.createIfAbsentBatch(rdepKeys);
+ graph.createIfAbsentBatch(null, Reason.OTHER, rdepKeys);
for (int i = 0; i < numKeys; i++) {
final int j = i;
Runnable r =
@@ -200,18 +200,18 @@
waitForSetValue.countDown();
wrapper.waitForTasksAndMaybeThrow();
assertFalse(ExecutorUtil.interruptibleShutdown(pool));
- assertEquals(new StringValue("foo1"), graph.get(key).getValue());
- assertEquals(numKeys + 1, Iterables.size(graph.get(key).getReverseDeps()));
+ assertEquals(new StringValue("foo1"), graph.get(null, Reason.OTHER, key).getValue());
+ assertEquals(numKeys + 1, Iterables.size(graph.get(null, Reason.OTHER, key).getReverseDeps()));
graph = getGraph(getNextVersion(startingVersion));
- NodeEntry sameEntry = Preconditions.checkNotNull(graph.get(key));
+ NodeEntry sameEntry = Preconditions.checkNotNull(graph.get(null, Reason.OTHER, key));
// Mark the node as dirty again and check that the reverse deps have been preserved.
sameEntry.markDirty(true);
startEvaluation(sameEntry);
sameEntry.markRebuilding();
sameEntry.setValue(new StringValue("foo2"), getNextVersion(startingVersion));
- assertEquals(new StringValue("foo2"), graph.get(key).getValue());
- assertEquals(numKeys + 1, Iterables.size(graph.get(key).getReverseDeps()));
+ assertEquals(new StringValue("foo2"), graph.get(null, Reason.OTHER, key).getValue());
+ assertEquals(numKeys + 1, Iterables.size(graph.get(null, Reason.OTHER, key).getReverseDeps()));
}
// Tests adding inflight nodes with a given key while an existing node with the same key
@@ -236,12 +236,13 @@
new Runnable() {
public void run() {
for (SkyKey key : keys) {
- NodeEntry entry = graph.get(key);
+ NodeEntry entry = graph.get(null, Reason.OTHER, key);
if (entry == null) {
nodeCreated.add(key);
}
}
- Map<SkyKey, NodeEntry> entries = graph.createIfAbsentBatch(keys);
+ Map<SkyKey, NodeEntry> entries =
+ graph.createIfAbsentBatch(null, Reason.OTHER, keys);
for (Integer keyNum : ImmutableList.of(keyNum1, keyNum2)) {
SkyKey key = key("foo" + keyNum);
NodeEntry entry = entries.get(key);
@@ -255,7 +256,7 @@
}
}
// This shouldn't cause any problems from the other threads.
- graph.createIfAbsentBatch(keys);
+ graph.createIfAbsentBatch(null, Reason.OTHER, keys);
}
};
pool.execute(wrapper.wrap(r));
@@ -269,8 +270,9 @@
SkyKey key = key("foo" + i);
assertTrue(nodeCreated.contains(key));
assertTrue(valuesSet.contains(key));
- assertThat(graph.get(key).getValue()).isEqualTo(new StringValue("bar" + i));
- assertThat(graph.get(key).getVersion()).isEqualTo(startingVersion);
+ assertThat(graph.get(null, Reason.OTHER, key).getValue())
+ .isEqualTo(new StringValue("bar" + i));
+ assertThat(graph.get(null, Reason.OTHER, key).getVersion()).isEqualTo(startingVersion);
}
}
@@ -289,16 +291,16 @@
for (int i = 0; i < numKeys; i++) {
keys.add(key("foo" + i));
}
- Map<SkyKey, NodeEntry> entries = graph.createIfAbsentBatch(keys);
+ Map<SkyKey, NodeEntry> entries = graph.createIfAbsentBatch(null, Reason.OTHER, keys);
for (int i = 0; i < numKeys; i++) {
NodeEntry entry = entries.get(key("foo" + i));
startEvaluation(entry);
entry.setValue(new StringValue("bar"), startingVersion);
}
- assertNotNull(graph.get(key("foo" + 0)));
+ assertNotNull(graph.get(null, Reason.OTHER, key("foo" + 0)));
graph = getGraph(getNextVersion(startingVersion));
- assertNotNull(graph.get(key("foo" + 0)));
+ assertNotNull(graph.get(null, Reason.OTHER, key("foo" + 0)));
ExecutorService pool1 = Executors.newFixedThreadPool(numThreads);
ExecutorService pool2 = Executors.newFixedThreadPool(numThreads);
ExecutorService pool3 = Executors.newFixedThreadPool(numThreads);
@@ -323,7 +325,7 @@
} catch (InterruptedException e) {
throw new AssertionError(e);
}
- NodeEntry entry = graph.get(key("foo" + keyNum));
+ NodeEntry entry = graph.get(null, Reason.OTHER, key("foo" + keyNum));
entry.markDirty(true);
// Make some changes, like adding a dep and rdep.
entry.addReverseDepAndCheckIfDone(key("rdep"));
@@ -345,7 +347,7 @@
} catch (InterruptedException e) {
throw new AssertionError(e);
}
- NodeEntry entry = graph.get(key("foo" + keyNum));
+ NodeEntry entry = graph.get(null, Reason.OTHER, key("foo" + keyNum));
assertNotNull(entry);
// Requests for the value are made at the same time that the version increments from
// the base. Check that there is no problem in requesting the version and that the
@@ -379,7 +381,7 @@
throw new AssertionError(e);
}
Map<SkyKey, NodeEntry> batchMap =
- graph.getBatchWithFieldHints(batch, NodeEntryField.NO_FIELDS);
+ graph.getBatchWithFieldHints(null, Reason.OTHER, batch, NodeEntryField.NO_FIELDS);
getBatchCountDownLatch.countDown();
assertThat(batchMap).hasSize(batch.size());
for (NodeEntry entry : batchMap.values()) {
@@ -398,7 +400,7 @@
assertFalse(ExecutorUtil.interruptibleShutdown(pool2));
assertFalse(ExecutorUtil.interruptibleShutdown(pool3));
for (int i = 0; i < numKeys; i++) {
- NodeEntry entry = graph.get(key("foo" + i));
+ NodeEntry entry = graph.get(null, Reason.OTHER, key("foo" + i));
assertThat(entry.getValue()).isEqualTo(new StringValue("bar" + i));
assertThat(entry.getVersion()).isEqualTo(getNextVersion(startingVersion));
for (SkyKey key : entry.getReverseDeps()) {