LocatedFileStatus getLocatedFileStatus(
FileSystem fs, Path p) throws IOException {
HashMap<String, LocatedFileStatus> cache =
locatedFileStatusCache.get();
LocatedFileStatus result = cache.get(p.toUri().getPath());
if (result != null) {
return result;
}
Path parent = p.getParent();
String parentPath = parent.toUri().getPath();
//If we already did listlocatedStatus on parent path,
//it means path p doesn't exist, we don't need to list again
if (cache.containsKey(parentPath) &&
cache.get(parentPath) == null) {
return null;
}
RemoteIterator<LocatedFileStatus> iter = fs.listLocatedStatus(parent);
while (iter.hasNext()) {
LocatedFileStatus stat = iter.next();
cache.put(stat.getPath().toUri().getPath(), stat);
}
// trick: add parent path to the cache with value = null
cache.put(parentPath, null);
result = cache.get(p.toUri().getPath());
// This may still return null