use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.
the class FileSystemContext method getWorkerAddresses.
/**
* @return if there are any local workers, the returned list will ONLY contain the local workers,
* otherwise a list of all remote workers will be returned
*/
private List<WorkerNetAddress> getWorkerAddresses() throws IOException {
List<WorkerInfo> infos;
BlockMasterClient blockMasterClient = mBlockMasterClientPool.acquire();
try {
infos = blockMasterClient.getWorkerInfoList();
} finally {
mBlockMasterClientPool.release(blockMasterClient);
}
if (infos.isEmpty()) {
throw new UnavailableException(ExceptionMessage.NO_WORKER_AVAILABLE.getMessage());
}
// Convert the worker infos into net addresses, if there are local addresses, only keep those
List<WorkerNetAddress> workerNetAddresses = new ArrayList<>();
List<WorkerNetAddress> localWorkerNetAddresses = new ArrayList<>();
String localHostname = NetworkAddressUtils.getClientHostName(getClusterConf());
for (WorkerInfo info : infos) {
WorkerNetAddress netAddress = info.getAddress();
if (netAddress.getHost().equals(localHostname)) {
localWorkerNetAddresses.add(netAddress);
}
workerNetAddresses.add(netAddress);
}
return localWorkerNetAddresses.isEmpty() ? workerNetAddresses : localWorkerNetAddresses;
}
use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.
the class DefaultFileSystemMaster method getDisplayMountPointInfo.
/**
* Gets the mount point information for display from a mount information.
*
* @param invokeUfs if true, invoke ufs to set ufs properties
* @param mountInfo the mount information to transform
* @return the mount point information
*/
private MountPointInfo getDisplayMountPointInfo(MountInfo mountInfo, boolean invokeUfs) {
MountPointInfo info = mountInfo.toDisplayMountPointInfo();
if (!invokeUfs) {
return info;
}
try (CloseableResource<UnderFileSystem> ufsResource = mUfsManager.get(mountInfo.getMountId()).acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
info.setUfsType(ufs.getUnderFSType());
try {
info.setUfsCapacityBytes(ufs.getSpace(info.getUfsUri(), UnderFileSystem.SpaceType.SPACE_TOTAL));
} catch (IOException e) {
LOG.warn("Cannot get total capacity of {}", info.getUfsUri(), e);
}
try {
info.setUfsUsedBytes(ufs.getSpace(info.getUfsUri(), UnderFileSystem.SpaceType.SPACE_USED));
} catch (IOException e) {
LOG.warn("Cannot get used capacity of {}", info.getUfsUri(), e);
}
} catch (UnavailableException | NotFoundException e) {
// We should never reach here
LOG.error("No UFS cached for {}", info, e);
}
return info;
}
use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.
the class DefaultFileSystemMaster method getFileInfoInternal.
/**
* @param inodePath the {@link LockedInodePath} to get the {@link FileInfo} for
* @return the {@link FileInfo} for the given inode
*/
private FileInfo getFileInfoInternal(LockedInodePath inodePath, Counter counter) throws FileDoesNotExistException, UnavailableException {
Inode inode = inodePath.getInode();
AlluxioURI uri = inodePath.getUri();
FileInfo fileInfo = inode.generateClientFileInfo(uri.toString());
if (fileInfo.isFolder()) {
fileInfo.setLength(inode.asDirectory().getChildCount());
}
fileInfo.setInMemoryPercentage(getInMemoryPercentage(inode));
fileInfo.setInAlluxioPercentage(getInAlluxioPercentage(inode));
if (inode.isFile()) {
try {
fileInfo.setFileBlockInfos(getFileBlockInfoListInternal(inodePath));
} catch (InvalidPathException e) {
throw new FileDoesNotExistException(e.getMessage(), e);
}
}
// Rehydrate missing block-infos for persisted files.
if (fileInfo.isCompleted() && fileInfo.getBlockIds().size() > fileInfo.getFileBlockInfos().size() && inode.isPersisted()) {
List<Long> missingBlockIds = fileInfo.getBlockIds().stream().filter((bId) -> fileInfo.getFileBlockInfo(bId) != null).collect(Collectors.toList());
LOG.warn("BlockInfo missing for file: {}. BlockIdsWithMissingInfos: {}", inodePath.getUri(), missingBlockIds.stream().map(Object::toString).collect(Collectors.joining(",")));
// Remove old block metadata from block-master before re-committing.
mBlockMaster.removeBlocks(fileInfo.getBlockIds(), true);
// Commit all the file blocks (without locations) so the metadata for the block exists.
commitBlockInfosForFile(fileInfo.getBlockIds(), fileInfo.getLength(), fileInfo.getBlockSizeBytes());
// Reset file-block-info list with the new list.
try {
fileInfo.setFileBlockInfos(getFileBlockInfoListInternal(inodePath));
} catch (InvalidPathException e) {
throw new FileDoesNotExistException(String.format("Hydration failed for file: %s", inodePath.getUri()), e);
}
}
fileInfo.setXAttr(inode.getXAttr());
MountTable.Resolution resolution;
try {
resolution = mMountTable.resolve(uri);
} catch (InvalidPathException e) {
throw new FileDoesNotExistException(e.getMessage(), e);
}
AlluxioURI resolvedUri = resolution.getUri();
fileInfo.setUfsPath(resolvedUri.toString());
fileInfo.setMountId(resolution.getMountId());
if (counter == null) {
Metrics.getUfsOpsSavedCounter(resolution.getUfsMountPointUri(), Metrics.UFSOps.GET_FILE_INFO).inc();
} else {
counter.inc();
}
Metrics.FILE_INFOS_GOT.inc();
return fileInfo;
}
use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.
the class DefaultFileSystemMaster method recordActiveSyncTxid.
@Override
public boolean recordActiveSyncTxid(long txId, long mountId) {
MountInfo mountInfo = mMountTable.getMountInfo(mountId);
if (mountInfo == null) {
return false;
}
AlluxioURI mountPath = mountInfo.getAlluxioUri();
try (RpcContext rpcContext = createRpcContext();
LockedInodePath inodePath = mInodeTree.lockFullInodePath(mountPath, LockPattern.READ)) {
File.ActiveSyncTxIdEntry txIdEntry = File.ActiveSyncTxIdEntry.newBuilder().setTxId(txId).setMountId(mountId).build();
rpcContext.journal(JournalEntry.newBuilder().setActiveSyncTxId(txIdEntry).build());
} catch (UnavailableException | InvalidPathException | FileDoesNotExistException e) {
LOG.warn("Exception when recording activesync txid, path {}, exception {}", mountPath, e);
return false;
}
return true;
}
use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.
the class DefaultBlockMaster method generateBlockInfo.
/**
* Generates block info, including worker locations, for a block id.
* This requires no locks on the {@link MasterWorkerInfo} because it is only reading
* final fields.
*
* @param blockId a block id
* @return optional block info, empty if the block does not exist
*/
private Optional<BlockInfo> generateBlockInfo(long blockId) throws UnavailableException {
if (mSafeModeManager.isInSafeMode()) {
throw new UnavailableException(ExceptionMessage.MASTER_IN_SAFEMODE.getMessage());
}
BlockMeta block;
List<BlockLocation> blockLocations;
try (LockResource r = lockBlock(blockId)) {
Optional<BlockMeta> blockOpt = mBlockStore.getBlock(blockId);
if (!blockOpt.isPresent()) {
return Optional.empty();
}
block = blockOpt.get();
blockLocations = new ArrayList<>(mBlockStore.getLocations(blockId));
}
// Sort the block locations by their alias ordinal in the master storage tier mapping
Collections.sort(blockLocations, Comparator.comparingInt(o -> mGlobalStorageTierAssoc.getOrdinal(o.getTier())));
List<alluxio.wire.BlockLocation> locations = new ArrayList<>();
for (BlockLocation location : blockLocations) {
MasterWorkerInfo workerInfo = mWorkers.getFirstByField(ID_INDEX, location.getWorkerId());
if (workerInfo != null) {
// worker metadata is intentionally not locked here because:
// - it would be an incorrect order (correct order is lock worker first, then block)
// - only uses getters of final variables
locations.add(new alluxio.wire.BlockLocation().setWorkerId(location.getWorkerId()).setWorkerAddress(workerInfo.getWorkerAddress()).setTierAlias(location.getTier()).setMediumType(location.getMediumType()));
}
}
return Optional.of(new BlockInfo().setBlockId(blockId).setLength(block.getLength()).setLocations(locations));
}
Aggregations