use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class MetadataCachingBaseFileSystemTest method createAndRename.
@Test
public void createAndRename() throws Exception {
mFs.createFile(NOT_EXIST_FILE);
mFs.getStatus(NOT_EXIST_FILE);
mFs.rename(NOT_EXIST_FILE, new AlluxioURI(NOT_EXIST_FILE.getPath() + ".rename"));
try {
mFs.getStatus(NOT_EXIST_FILE);
Assert.fail("Failed while getStatus for a non-exist path.");
} catch (FileDoesNotExistException e) {
// expected exception thrown. test passes
}
assertEquals(2, mFileSystemMasterClient.getStatusRpcCount(NOT_EXIST_FILE));
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class CpCommand method run.
@Override
public int run(CommandLine cl) throws AlluxioException, IOException {
String[] args = cl.getArgs();
AlluxioURI srcPath = new AlluxioURI(args[0]);
AlluxioURI dstPath = new AlluxioURI(args[1]);
if ((dstPath.getScheme() == null || isAlluxio(dstPath.getScheme())) && isFile(srcPath.getScheme())) {
List<AlluxioURI> srcPaths = new ArrayList<>();
if (srcPath.containsWildcard()) {
List<File> srcFiles = FileSystemShellUtils.getFiles(srcPath.getPath());
if (srcFiles.size() == 0) {
throw new IOException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(srcPath));
}
for (File srcFile : srcFiles) {
srcPaths.add(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), srcFile.getPath()));
}
} else {
File src = new File(srcPath.getPath());
if (src.isDirectory()) {
File[] files = src.listFiles();
if (files == null) {
throw new IOException(String.format("Failed to list files for directory %s", src));
}
for (File f : files) {
srcPaths.add(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), f.getPath()));
}
} else {
srcPaths.add(srcPath);
}
}
if (srcPaths.size() == 1 && !(new File(srcPaths.get(0).getPath())).isDirectory()) {
copyFromLocalFile(srcPaths.get(0), dstPath);
} else {
CopyThreadPoolExecutor pool = new CopyThreadPoolExecutor(mThread, System.out, System.err, mFileSystem, mFileSystem.exists(dstPath) ? null : dstPath);
try {
createDstDir(dstPath);
for (AlluxioURI src : srcPaths) {
AlluxioURI dst = new AlluxioURI(dstPath, new AlluxioURI(src.getName()));
asyncCopyLocalPath(pool, src, dst);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
} finally {
pool.shutdown();
}
}
System.out.println(String.format(COPY_SUCCEED_MESSAGE, srcPath, dstPath));
} else if ((srcPath.getScheme() == null || isAlluxio(srcPath.getScheme())) && isFile(dstPath.getScheme())) {
List<AlluxioURI> srcPaths = FileSystemShellUtils.getAlluxioURIs(mFileSystem, srcPath);
if (srcPaths.size() == 0) {
throw new IOException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(srcPath));
}
if (srcPath.containsWildcard()) {
copyWildcardToLocal(srcPaths, dstPath);
} else {
copyToLocal(srcPath, dstPath);
}
} else if ((srcPath.getScheme() == null || isAlluxio(srcPath.getScheme())) && (dstPath.getScheme() == null || isAlluxio(dstPath.getScheme()))) {
List<AlluxioURI> srcPaths = FileSystemShellUtils.getAlluxioURIs(mFileSystem, srcPath);
if (srcPaths.size() == 0) {
throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(srcPath.getPath()));
}
boolean recursive = cl.hasOption(RECURSIVE_OPTION.getOpt()) || cl.hasOption(RECURSIVE_ALIAS_OPTION.getOpt());
if (srcPath.containsWildcard()) {
copyWildcard(srcPaths, dstPath, recursive);
} else {
copy(srcPath, dstPath, recursive);
}
} else {
throw new InvalidPathException("Schemes must be either file or alluxio, and at most one file scheme is allowed.");
}
return 0;
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class AlluxioMasterRestServiceHandler method getWebUIData.
/**
* Gets Web UI data page data.
*
* @param requestOffset the request offset
* @param requestLimit the request limit
* @return the response object
*/
@GET
@Path(WEBUI_DATA)
public Response getWebUIData(@DefaultValue("0") @QueryParam("offset") String requestOffset, @DefaultValue("20") @QueryParam("limit") String requestLimit) {
return RestUtils.call(() -> {
MasterWebUIData response = new MasterWebUIData();
if (!ServerConfiguration.getBoolean(PropertyKey.WEB_FILE_INFO_ENABLED)) {
return response;
}
if (SecurityUtils.isSecurityEnabled(ServerConfiguration.global()) && AuthenticatedClientUser.get(ServerConfiguration.global()) == null) {
AuthenticatedClientUser.set(ServerUserState.global().getUser().getName());
}
response.setMasterNodeAddress(mMasterProcess.getRpcAddress().toString()).setFatalError("").setShowPermissions(ServerConfiguration.getBoolean(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED));
List<AlluxioURI> inAlluxioFiles = mFileSystemMaster.getInAlluxioFiles();
Collections.sort(inAlluxioFiles);
List<UIFileInfo> fileInfos = new ArrayList<>(inAlluxioFiles.size());
for (AlluxioURI file : inAlluxioFiles) {
try {
long fileId = mFileSystemMaster.getFileId(file);
FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
if (fileInfo != null && fileInfo.getInAlluxioPercentage() == 100) {
fileInfos.add(new UIFileInfo(fileInfo, ServerConfiguration.global(), new MasterStorageTierAssoc().getOrderedStorageAliases()));
}
} catch (FileDoesNotExistException e) {
response.setFatalError("Error: File does not exist " + e.getLocalizedMessage());
return response;
} catch (AccessControlException e) {
response.setPermissionError("Error: File " + file + " cannot be accessed " + e.getMessage());
return response;
}
}
response.setInAlluxioFileNum(fileInfos.size());
try {
int offset = Integer.parseInt(requestOffset);
int limit = Integer.parseInt(requestLimit);
limit = offset == 0 && limit > fileInfos.size() ? fileInfos.size() : limit;
limit = offset + limit > fileInfos.size() ? fileInfos.size() - offset : limit;
int sum = Math.addExact(offset, limit);
fileInfos = fileInfos.subList(offset, sum);
response.setFileInfos(fileInfos);
} catch (NumberFormatException e) {
response.setFatalError("Error: offset or limit parse error, " + e.getLocalizedMessage());
return response;
} catch (ArithmeticException e) {
response.setFatalError("Error: offset or offset + limit is out of bound, " + e.getLocalizedMessage());
return response;
} catch (IllegalArgumentException e) {
response.setFatalError(e.getLocalizedMessage());
return response;
}
return response;
}, ServerConfiguration.global());
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class ReplicationChecker method check.
private Set<Long> check(Set<Long> inodes, ReplicationHandler handler, Mode mode) throws InterruptedException {
Set<Long> processedFileIds = new HashSet<>();
for (long inodeId : inodes) {
if (mActiveJobToInodeID.size() >= mMaxActiveJobs) {
return processedFileIds;
}
if (mActiveJobToInodeID.containsValue(inodeId)) {
continue;
}
Set<Triple<AlluxioURI, Long, Integer>> requests = new HashSet<>();
// Throw if interrupted.
if (Thread.interrupted()) {
throw new InterruptedException("ReplicationChecker interrupted.");
}
// locking the entire path but just the inode file since this access is read-only.
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(inodeId, LockPattern.READ)) {
InodeFile file = inodePath.getInodeFile();
for (long blockId : file.getBlockIds()) {
BlockInfo blockInfo = null;
try {
blockInfo = mBlockMaster.getBlockInfo(blockId);
} catch (BlockInfoException e) {
// Cannot find this block in Alluxio from BlockMaster, possibly persisted in UFS
} catch (UnavailableException e) {
// The block master is not available, wait for the next heartbeat
LOG.warn("The block master is not available: {}", e.toString());
return processedFileIds;
}
int currentReplicas = (blockInfo == null) ? 0 : blockInfo.getLocations().size();
switch(mode) {
case EVICT:
int maxReplicas = file.getReplicationMax();
if (file.getPersistenceState() == PersistenceState.TO_BE_PERSISTED && file.getReplicationDurable() > maxReplicas) {
maxReplicas = file.getReplicationDurable();
}
if (currentReplicas > maxReplicas) {
requests.add(new ImmutableTriple<>(inodePath.getUri(), blockId, currentReplicas - maxReplicas));
}
break;
case REPLICATE:
int minReplicas = file.getReplicationMin();
if (file.getPersistenceState() == PersistenceState.TO_BE_PERSISTED && file.getReplicationDurable() > minReplicas) {
minReplicas = file.getReplicationDurable();
}
if (currentReplicas < minReplicas) {
// if this file is not persisted and block master thinks it is lost, no effort made
if (!file.isPersisted() && mBlockMaster.isBlockLost(blockId)) {
continue;
}
requests.add(new ImmutableTriple<>(inodePath.getUri(), blockId, minReplicas - currentReplicas));
}
break;
default:
LOG.warn("Unexpected replication mode {}.", mode);
}
}
} catch (FileDoesNotExistException e) {
LOG.warn("Failed to check replication level for inode id {} : {}", inodeId, e.toString());
}
for (Triple<AlluxioURI, Long, Integer> entry : requests) {
AlluxioURI uri = entry.getLeft();
long blockId = entry.getMiddle();
int numReplicas = entry.getRight();
try {
long jobId;
switch(mode) {
case EVICT:
jobId = handler.evict(uri, blockId, numReplicas);
break;
case REPLICATE:
jobId = handler.replicate(uri, blockId, numReplicas);
break;
default:
throw new RuntimeException(String.format("Unexpected replication mode {}.", mode));
}
processedFileIds.add(inodeId);
mActiveJobToInodeID.put(jobId, inodeId);
} catch (JobDoesNotExistException | ResourceExhaustedException e) {
LOG.warn("The job service is busy, will retry later. {}", e.toString());
return processedFileIds;
} catch (UnavailableException e) {
LOG.warn("Unable to complete the replication check: {}, will retry later.", e.toString());
return processedFileIds;
} catch (Exception e) {
SAMPLING_LOG.warn("Unexpected exception encountered when starting a {} job (uri={}," + " block ID={}, num replicas={}) : {}", mode, uri, blockId, numReplicas, e.toString());
LOG.debug("Job service unexpected exception: ", e);
}
}
}
return processedFileIds;
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class ReplicationChecker method checkMisreplicated.
private void checkMisreplicated(Set<Long> inodes, ReplicationHandler handler) throws InterruptedException {
for (long inodeId : inodes) {
if (mActiveJobToInodeID.size() >= mMaxActiveJobs) {
return;
}
if (mActiveJobToInodeID.containsValue(inodeId)) {
continue;
}
// Throw if interrupted.
if (Thread.interrupted()) {
throw new InterruptedException("ReplicationChecker interrupted.");
}
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(inodeId, LockPattern.READ)) {
InodeFile file = inodePath.getInodeFile();
for (long blockId : file.getBlockIds()) {
BlockInfo blockInfo = null;
try {
blockInfo = mBlockMaster.getBlockInfo(blockId);
} catch (BlockInfoException e) {
// Cannot find this block in Alluxio from BlockMaster, possibly persisted in UFS
} catch (UnavailableException e) {
// The block master is not available, wait for the next heartbeat
LOG.warn("The block master is not available: {}", e.toString());
return;
}
if (blockInfo == null) {
// no block info available, we simply log and return;
LOG.warn("Block info is null");
return;
}
for (Map.Entry<String, String> entry : findMisplacedBlock(file, blockInfo).entrySet()) {
try {
final long jobId = handler.migrate(inodePath.getUri(), blockId, entry.getKey(), entry.getValue());
mActiveJobToInodeID.put(jobId, inodeId);
} catch (Exception e) {
LOG.warn("Unexpected exception encountered when starting a migration job (uri={}," + " block ID={}, workerHost= {}) : {}", inodePath.getUri(), blockId, entry.getKey(), e.toString());
LOG.debug("Exception: ", e);
}
}
}
} catch (FileDoesNotExistException e) {
LOG.warn("Failed to check replication level for inode id {} : {}", inodeId, e.toString());
}
}
}
Aggregations