use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class RmCommand method runCommand.
@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
// TODO(calvin): Remove explicit state checking.
boolean recursive = cl.hasOption("R");
if (!mFileSystem.exists(path)) {
throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
}
if (!recursive && mFileSystem.getStatus(path).isFolder()) {
throw new IOException(path.getPath() + " is a directory, to remove it, please use \"rm -R <path>\"");
}
DeleteOptions options = DeleteOptions.defaults().setRecursive(recursive);
mFileSystem.delete(path, options);
System.out.println(path + " has been removed");
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMaster method getFileId.
/**
* Returns the file id for a given path. If the given path does not exist in Alluxio, the method
* attempts to load it from UFS.
* <p>
* This operation requires users to have {@link Mode.Bits#READ} permission of the path.
*
* @param path the path to get the file id for
* @return the file id for a given path, or -1 if there is no file at that path
* @throws AccessControlException if permission checking fails
*/
public long getFileId(AlluxioURI path) throws AccessControlException {
try (JournalContext journalContext = createJournalContext();
LockedInodePath inodePath = mInodeTree.lockInodePath(path, InodeTree.LockMode.WRITE)) {
// This is WRITE locked, since loading metadata is possible.
mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
loadMetadataIfNotExistAndJournal(inodePath, LoadMetadataOptions.defaults().setCreateAncestors(true), journalContext);
mInodeTree.ensureFullInodePath(inodePath, InodeTree.LockMode.READ);
return inodePath.getInode().getId();
} catch (InvalidPathException | FileDoesNotExistException e) {
return IdUtils.INVALID_FILE_ID;
}
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMaster method processJournalEntry.
@Override
public void processJournalEntry(JournalEntry entry) throws IOException {
if (entry.hasInodeFile()) {
mInodeTree.addInodeFileFromJournal(entry.getInodeFile());
// Add the file to TTL buckets, the insert automatically rejects files w/ Constants.NO_TTL
InodeFileEntry inodeFileEntry = entry.getInodeFile();
if (inodeFileEntry.hasTtl()) {
mTtlBuckets.insert(InodeFile.fromJournalEntry(inodeFileEntry));
}
} else if (entry.hasInodeDirectory()) {
try {
// Add the directory to TTL buckets, the insert automatically rejects directory
// w/ Constants.NO_TTL
InodeDirectoryEntry inodeDirectoryEntry = entry.getInodeDirectory();
if (inodeDirectoryEntry.hasTtl()) {
mTtlBuckets.insert(InodeDirectory.fromJournalEntry(inodeDirectoryEntry));
}
mInodeTree.addInodeDirectoryFromJournal(entry.getInodeDirectory());
} catch (AccessControlException e) {
throw new RuntimeException(e);
}
} else if (entry.hasInodeLastModificationTime()) {
InodeLastModificationTimeEntry modTimeEntry = entry.getInodeLastModificationTime();
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(modTimeEntry.getId(), InodeTree.LockMode.WRITE)) {
inodePath.getInode().setLastModificationTimeMs(modTimeEntry.getLastModificationTimeMs(), true);
} catch (FileDoesNotExistException e) {
throw new RuntimeException(e);
}
} else if (entry.hasPersistDirectory()) {
PersistDirectoryEntry typedEntry = entry.getPersistDirectory();
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(typedEntry.getId(), InodeTree.LockMode.WRITE)) {
inodePath.getInode().setPersistenceState(PersistenceState.PERSISTED);
} catch (FileDoesNotExistException e) {
throw new RuntimeException(e);
}
} else if (entry.hasCompleteFile()) {
try {
completeFileFromEntry(entry.getCompleteFile());
} catch (InvalidPathException | InvalidFileSizeException | FileAlreadyCompletedException e) {
throw new RuntimeException(e);
}
} else if (entry.hasSetAttribute()) {
try {
setAttributeFromEntry(entry.getSetAttribute());
} catch (AccessControlException | FileDoesNotExistException | InvalidPathException e) {
throw new RuntimeException(e);
}
} else if (entry.hasDeleteFile()) {
deleteFromEntry(entry.getDeleteFile());
} else if (entry.hasRename()) {
renameFromEntry(entry.getRename());
} else if (entry.hasInodeDirectoryIdGenerator()) {
mDirectoryIdGenerator.initFromJournalEntry(entry.getInodeDirectoryIdGenerator());
} else if (entry.hasReinitializeFile()) {
resetBlockFileFromEntry(entry.getReinitializeFile());
} else if (entry.hasAddMountPoint()) {
try {
mountFromEntry(entry.getAddMountPoint());
} catch (FileAlreadyExistsException | InvalidPathException e) {
throw new RuntimeException(e);
}
} else if (entry.hasDeleteMountPoint()) {
try {
unmountFromEntry(entry.getDeleteMountPoint());
} catch (InvalidPathException e) {
throw new RuntimeException(e);
}
} else if (entry.hasAsyncPersistRequest()) {
try {
long fileId = (entry.getAsyncPersistRequest()).getFileId();
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(fileId, InodeTree.LockMode.WRITE)) {
scheduleAsyncPersistenceInternal(inodePath);
}
// NOTE: persistence is asynchronous so there is no guarantee the path will still exist
mAsyncPersistHandler.scheduleAsyncPersistence(getPath(fileId));
} catch (AlluxioException e) {
// It's possible that rescheduling the async persist calls fails, because the blocks may no
// longer be in the memory
LOG.error(e.getMessage());
}
} else {
throw new IOException(ExceptionMessage.UNEXPECTED_JOURNAL_ENTRY.getMessage(entry));
}
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMaster method workerHeartbeat.
/**
* Instructs a worker to persist the files.
* <p>
* Needs {@link Mode.Bits#WRITE} permission on the list of files.
*
* @param workerId the id of the worker that heartbeats
* @param persistedFiles the files that persisted on the worker
* @return the command for persisting the blocks of a file
* @throws FileDoesNotExistException if the file does not exist
* @throws InvalidPathException if the file path corresponding to the file id is invalid
* @throws AccessControlException if permission checking fails
*/
public FileSystemCommand workerHeartbeat(long workerId, List<Long> persistedFiles) throws FileDoesNotExistException, InvalidPathException, AccessControlException {
for (long fileId : persistedFiles) {
try {
// Permission checking for each file is performed inside setAttribute
setAttribute(getPath(fileId), SetAttributeOptions.defaults().setPersisted(true));
} catch (FileDoesNotExistException | AccessControlException | InvalidPathException e) {
LOG.error("Failed to set file {} as persisted, because {}", fileId, e);
}
}
// get the files for the given worker to persist
List<PersistFile> filesToPersist = mAsyncPersistHandler.pollFilesToPersist(workerId);
if (!filesToPersist.isEmpty()) {
LOG.debug("Sent files {} to worker {} to persist", filesToPersist, workerId);
}
FileSystemCommandOptions options = new FileSystemCommandOptions();
options.setPersistOptions(new PersistCommandOptions(filesToPersist));
return new FileSystemCommand(CommandType.Persist, options);
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMaster method completeFileAndJournal.
/**
* Completes a file. After a file is completed, it cannot be written to.
* <p>
* Writes to the journal.
*
* @param inodePath the {@link LockedInodePath} to complete
* @param options the method options
* @param journalContext the journal context
* @throws InvalidPathException if an invalid path is encountered
* @throws FileDoesNotExistException if the file does not exist
* @throws BlockInfoException if a block information exception is encountered
* @throws FileAlreadyCompletedException if the file is already completed
* @throws InvalidFileSizeException if an invalid file size is encountered
*/
private void completeFileAndJournal(LockedInodePath inodePath, CompleteFileOptions options, JournalContext journalContext) throws InvalidPathException, FileDoesNotExistException, BlockInfoException, FileAlreadyCompletedException, InvalidFileSizeException {
Inode<?> inode = inodePath.getInode();
if (!inode.isFile()) {
throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(inodePath.getUri()));
}
InodeFile fileInode = (InodeFile) inode;
List<Long> blockIdList = fileInode.getBlockIds();
List<BlockInfo> blockInfoList = mBlockMaster.getBlockInfoList(blockIdList);
if (!fileInode.isPersisted() && blockInfoList.size() != blockIdList.size()) {
throw new BlockInfoException("Cannot complete a file without all the blocks committed");
}
// Iterate over all file blocks committed to Alluxio, computing the length and verify that all
// the blocks (except the last one) is the same size as the file block size.
long inMemoryLength = 0;
long fileBlockSize = fileInode.getBlockSizeBytes();
for (int i = 0; i < blockInfoList.size(); i++) {
BlockInfo blockInfo = blockInfoList.get(i);
inMemoryLength += blockInfo.getLength();
if (i < blockInfoList.size() - 1 && blockInfo.getLength() != fileBlockSize) {
throw new BlockInfoException("Block index " + i + " has a block size smaller than the file block size (" + fileInode.getBlockSizeBytes() + ")");
}
}
// If the file is persisted, its length is determined by UFS. Otherwise, its length is
// determined by its memory footprint.
long length = fileInode.isPersisted() ? options.getUfsLength() : inMemoryLength;
completeFileInternal(fileInode.getBlockIds(), inodePath, length, options.getOperationTimeMs());
CompleteFileEntry completeFileEntry = CompleteFileEntry.newBuilder().addAllBlockIds(fileInode.getBlockIds()).setId(inode.getId()).setLength(length).setOpTimeMs(options.getOperationTimeMs()).build();
appendJournalEntry(JournalEntry.newBuilder().setCompleteFile(completeFileEntry).build(), journalContext);
}
Aggregations