FS: don't cache fallback if running in background

If the background job is a little late, the true result might
arrive and be cached later. So make sure we don't cache the large
fallback resolution in the per-directory cache. Otherwise we'd work
with the large fallback until the next restart.

Bug: 566170
Change-Id: I7354a6cfddfc0c05144bb0aa41c23029bd4f6af0
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
This commit is contained in:
Thomas Wolf 2020-08-20 22:15:11 +02:00
parent efd1cc05af
commit eec9b55dcf
1 changed files with 10 additions and 2 deletions

View File

@ -294,6 +294,10 @@ public static FileStoreAttributes get(Path path) {
return cached;
}
FileStoreAttributes attrs = getFileStoreAttributes(dir);
if (attrs == null) {
// Don't cache, result might be late
return FALLBACK_FILESTORE_ATTRIBUTES;
}
attrCacheByPath.put(dir, attrs);
return attrs;
} catch (SecurityException e) {
@ -382,12 +386,16 @@ private static FileStoreAttributes getFileStoreAttributes(Path dir) {
});
// even if measuring in background wait a little - if the result
// arrives, it's better than returning the large fallback
Optional<FileStoreAttributes> d = background.get() ? f.get(
boolean runInBackground = background.get();
Optional<FileStoreAttributes> d = runInBackground ? f.get(
100, TimeUnit.MILLISECONDS) : f.get();
if (d.isPresent()) {
return d.get();
} else if (runInBackground) {
// return null until measurement is finished
return null;
}
// return fallback until measurement is finished
// fall through and return fallback
} catch (IOException | InterruptedException
| ExecutionException | CancellationException e) {
LOG.error(e.getMessage(), e);