close
Skip to content

Commit 5fb1073

Browse files
haxorzfweikert
authored andcommitted
Reintroduce an inconsistency check (albeit, in a weaker form) removed by a previous change that was trying to optimize away a filesystem call.
-- MOS_MIGRATED_REVID=104246368
1 parent 3251ebb commit 5fb1073

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

‎src/main/java/com/google/devtools/build/lib/skyframe/FileContentsProxy.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public int hashCode() {
6161

6262
@Override
6363
public String toString() {
64-
return "mtime: " + mtime + " valueId: " + valueId;
64+
return prettyPrint();
65+
}
66+
67+
public String prettyPrint() {
68+
return String.format("mtime of %d and nodeId of %d", mtime, valueId);
6569
}
6670
}

‎src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public FileFunction(AtomicReference<PathPackageLocator> pkgLocator,
5959
@Override
6060
public SkyValue compute(SkyKey skyKey, Environment env) throws FileFunctionException {
6161
RootedPath rootedPath = (RootedPath) skyKey.argument();
62-
RootedPath realRootedPath = rootedPath;
62+
RootedPath realRootedPath = null;
6363
FileStateValue realFileStateValue = null;
6464
PathFragment relativePath = rootedPath.getRelativePath();
6565

@@ -83,7 +83,16 @@ public SkyValue compute(SkyKey skyKey, Environment env) throws FileFunctionExcep
8383
return null;
8484
}
8585
if (realFileStateValue == null) {
86+
realRootedPath = rootedPath;
8687
realFileStateValue = fileStateValue;
88+
} else if (rootedPath.equals(realRootedPath) && !fileStateValue.equals(realFileStateValue)) {
89+
String message = String.format(
90+
"Some filesystem operations implied %s was a %s but others made us think it was a %s",
91+
rootedPath.asPath().getPathString(),
92+
fileStateValue.prettyPrint(),
93+
realFileStateValue.prettyPrint());
94+
throw new FileFunctionException(new InconsistentFilesystemException(message),
95+
Transience.TRANSIENT);
8796
}
8897

8998
ArrayList<RootedPath> symlinkChain = new ArrayList<>();

‎src/main/java/com/google/devtools/build/lib/skyframe/FileStateValue.java‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ byte[] getDigest() {
115115
throw new IllegalStateException();
116116
}
117117

118+
@Override
119+
public String toString() {
120+
return prettyPrint();
121+
}
122+
123+
abstract String prettyPrint();
124+
118125
/**
119126
* Implementation of {@link FileStateValue} for files that exist.
120127
*
@@ -212,9 +219,12 @@ public int hashCode() {
212219
}
213220

214221
@Override
215-
public String toString() {
216-
return "[size: " + size + " " + (mtime != -1 ? "mtime: " + mtime : "")
217-
+ (digest != null ? "digest: " + Arrays.toString(digest) : contentsProxy) + "]";
222+
public String prettyPrint() {
223+
String contents = digest != null
224+
? String.format("digest of ", Arrays.toString(digest))
225+
: contentsProxy.prettyPrint();
226+
String extra = mtime != -1 ? String.format(" and mtime of %d", mtime) : "";
227+
return String.format("regular file with size of %d and %s%s", size, contents, extra);
218228
}
219229
}
220230

@@ -232,7 +242,7 @@ Type getType() {
232242
}
233243

234244
@Override
235-
public String toString() {
245+
public String prettyPrint() {
236246
return "directory";
237247
}
238248

@@ -282,7 +292,7 @@ public int hashCode() {
282292
}
283293

284294
@Override
285-
public String toString() {
295+
public String prettyPrint() {
286296
return "symlink to " + symlinkTarget;
287297
}
288298
}
@@ -301,8 +311,8 @@ Type getType() {
301311
}
302312

303313
@Override
304-
public String toString() {
305-
return "nonexistent";
314+
public String prettyPrint() {
315+
return "nonexistent path";
306316
}
307317

308318
// This object is normally a singleton, but deserialization produces copies.

0 commit comments

Comments
 (0)