【BlockLocation的源码】
Client-->fs.getFileBlockLocations(stat, 0, stat.getLen());
-->【DistributedFileSystem.class】getFileBlockLocations(FileStatus file, long start,long len)
-->【DistributedFileSystem.class】getFileBlockLocations(Path p,final long start, final long len)
-->调用new FileSystemLinkResolver<BlockLocation[]>(),
创建匿名内部类,重写doCall方法
-->调用doCall方法
-->【DFSClient.class】getBlockLocations(String src, long start,long length)
说明:DFSClient可以连接到Hadoop文件系统并执行基本的文件任务。
它使用clientprotocol与NameNode守护进程通信,
并直接连接到datanode来读取/写入数据块
-->【DFSClient.class】getLocatedBlocks(String src, long start, long length)
-->【DFSClient.class】callGetBlockLocations(ClientProtocol namenode,String src, long start, long length)
{
return namenode.getBlockLocations(src, start, length);
}
-->[ClientNamenodeProtocolTranslatorPB]getBlockLocations(String src, long offset, long length)
{
try {
//客户端通过rpc协议与namenode通信,获取内存中的块映射信息等
GetBlockLocationsResponseProto resp = rpcProxy.getBlockLocations(null,req);
return resp.hasLocations() ? PBHelper.convert(resp.getLocations()) : null;
} catch (ServiceException e) {
throw ProtobufHelper.getRemoteException(e);
}
}
-->【FileSystemLinkResolver】resolve()
说明:尝试使用指定文件系统和调用重写doCall(Path)方法。
如果调用失败,它将尝试解析路径并重试调用