use of alluxio.wire.FileBlockInfo in project alluxio by Alluxio.
the class DefaultFileSystemMaster method getFileBlockInfoListInternal.
/**
* @param inodePath the {@link LockedInodePath} to get the info for
* @return a list of {@link FileBlockInfo} for all the blocks of the given inode
*/
private List<FileBlockInfo> getFileBlockInfoListInternal(LockedInodePath inodePath) throws InvalidPathException, FileDoesNotExistException, UnavailableException {
InodeFile file = inodePath.getInodeFile();
List<BlockInfo> blockInfoList = mBlockMaster.getBlockInfoList(file.getBlockIds());
List<FileBlockInfo> ret = new ArrayList<>();
for (BlockInfo blockInfo : blockInfoList) {
ret.add(generateFileBlockInfo(inodePath, blockInfo));
}
return ret;
}
use of alluxio.wire.FileBlockInfo in project alluxio by Alluxio.
the class DefaultAsyncPersistHandler method getWorkerStoringFile.
/**
* Gets a worker where the given file is stored.
*
* @param path the path to the file
* @return the id of the storing worker
* @throws FileDoesNotExistException when the file does not exist on any worker
* @throws AccessControlException if permission checking fails
*/
// TODO(calvin): Propagate the exceptions in certain cases
private long getWorkerStoringFile(AlluxioURI path) throws FileDoesNotExistException, AccessControlException, UnavailableException {
long fileId = mFileSystemMasterView.getFileId(path);
try {
if (mFileSystemMasterView.getFileInfo(fileId).getLength() == 0) {
// if file is empty, return any worker
List<WorkerInfo> workerInfoList = mFileSystemMasterView.getWorkerInfoList();
if (workerInfoList.isEmpty()) {
LOG.error("No worker is available");
return IdUtils.INVALID_WORKER_ID;
}
// randomly pick a worker
int index = new Random().nextInt(workerInfoList.size());
return workerInfoList.get(index).getId();
}
} catch (UnavailableException e) {
return IdUtils.INVALID_WORKER_ID;
}
Map<Long, Integer> workerBlockCounts = new HashMap<>();
List<FileBlockInfo> blockInfoList;
try {
blockInfoList = mFileSystemMasterView.getFileBlockInfoList(path);
for (FileBlockInfo fileBlockInfo : blockInfoList) {
for (BlockLocation blockLocation : fileBlockInfo.getBlockInfo().getLocations()) {
if (workerBlockCounts.containsKey(blockLocation.getWorkerId())) {
workerBlockCounts.put(blockLocation.getWorkerId(), workerBlockCounts.get(blockLocation.getWorkerId()) + 1);
} else {
workerBlockCounts.put(blockLocation.getWorkerId(), 1);
}
// all the blocks of a file must be stored on the same worker
if (workerBlockCounts.get(blockLocation.getWorkerId()) == blockInfoList.size()) {
return blockLocation.getWorkerId();
}
}
}
} catch (FileDoesNotExistException e) {
LOG.error("The file {} to persist does not exist", path);
return IdUtils.INVALID_WORKER_ID;
} catch (InvalidPathException e) {
LOG.error("The file {} to persist is invalid", path);
return IdUtils.INVALID_WORKER_ID;
} catch (UnavailableException e) {
return IdUtils.INVALID_WORKER_ID;
}
if (workerBlockCounts.size() == 0) {
LOG.error("The file " + path + " does not exist on any worker");
return IdUtils.INVALID_WORKER_ID;
}
LOG.error("Not all the blocks of file {} stored on the same worker", path);
return IdUtils.INVALID_WORKER_ID;
}
Aggregations