use of alluxio.exception.UnexpectedAlluxioException in project alluxio by Alluxio.
the class FileSystemMaster method freeAndJournal.
/**
* Implements free operation.
* <p>
* This may write to the journal as free operation may change the pinned state of inodes.
*
* @param inodePath inode of the path to free
* @param options options to free
* @param journalContext the journal context
* @throws FileDoesNotExistException if the file does not exist
* @throws AccessControlException if permission checking fails
* @throws InvalidPathException if the given path is invalid
* @throws UnexpectedAlluxioException if the file or directory can not be freed
*/
private void freeAndJournal(LockedInodePath inodePath, FreeOptions options, JournalContext journalContext) throws FileDoesNotExistException, UnexpectedAlluxioException, AccessControlException, InvalidPathException {
Inode<?> inode = inodePath.getInode();
if (inode.isDirectory() && !options.isRecursive() && ((InodeDirectory) inode).getNumberOfChildren() > 0) {
// inode is nonempty, and we don't free a nonempty directory unless recursive is true
throw new UnexpectedAlluxioException(ExceptionMessage.CANNOT_FREE_NON_EMPTY_DIR.getMessage(mInodeTree.getPath(inode)));
}
long opTimeMs = System.currentTimeMillis();
List<Inode<?>> freeInodes = new ArrayList<>();
freeInodes.add(inode);
try (InodeLockList lockList = mInodeTree.lockDescendants(inodePath, InodeTree.LockMode.WRITE)) {
freeInodes.addAll(lockList.getInodes());
TempInodePathForDescendant tempInodePath = new TempInodePathForDescendant(inodePath);
// We go through each inode.
for (int i = freeInodes.size() - 1; i >= 0; i--) {
Inode<?> freeInode = freeInodes.get(i);
if (freeInode.isFile()) {
if (freeInode.getPersistenceState() != PersistenceState.PERSISTED) {
throw new UnexpectedAlluxioException(ExceptionMessage.CANNOT_FREE_NON_PERSISTED_FILE.getMessage(mInodeTree.getPath(freeInode)));
}
if (freeInode.isPinned()) {
if (!options.isForced()) {
throw new UnexpectedAlluxioException(ExceptionMessage.CANNOT_FREE_PINNED_FILE.getMessage(mInodeTree.getPath(freeInode)));
}
// the path to inode for getPath should already be locked.
tempInodePath.setDescendant(freeInode, mInodeTree.getPath(freeInode));
SetAttributeOptions setAttributeOptions = SetAttributeOptions.defaults().setRecursive(false).setPinned(false);
setAttributeInternal(tempInodePath, false, opTimeMs, setAttributeOptions);
journalSetAttribute(tempInodePath, opTimeMs, setAttributeOptions, journalContext);
}
// Remove corresponding blocks from workers.
mBlockMaster.removeBlocks(((InodeFile) freeInode).getBlockIds(), false);
}
}
}
Metrics.FILES_FREED.inc(freeInodes.size());
}
Aggregations