Search in sources :

Example 41 with FileDoesNotExistException

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;
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) InvalidPathException(alluxio.exception.InvalidPathException)

Example 42 with FileDoesNotExistException

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));
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) InodeFileEntry(alluxio.proto.journal.File.InodeFileEntry) AccessControlException(alluxio.exception.AccessControlException) IOException(java.io.IOException) InodeLastModificationTimeEntry(alluxio.proto.journal.File.InodeLastModificationTimeEntry) PersistDirectoryEntry(alluxio.proto.journal.File.PersistDirectoryEntry) InvalidPathException(alluxio.exception.InvalidPathException) LockedInodePath(alluxio.master.file.meta.LockedInodePath) InodeDirectoryEntry(alluxio.proto.journal.File.InodeDirectoryEntry) InvalidFileSizeException(alluxio.exception.InvalidFileSizeException) FileAlreadyCompletedException(alluxio.exception.FileAlreadyCompletedException) AlluxioException(alluxio.exception.AlluxioException) UnexpectedAlluxioException(alluxio.exception.UnexpectedAlluxioException)

Example 43 with FileDoesNotExistException

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);
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) PersistFile(alluxio.thrift.PersistFile) AccessControlException(alluxio.exception.AccessControlException) PersistCommandOptions(alluxio.thrift.PersistCommandOptions) FileSystemCommandOptions(alluxio.thrift.FileSystemCommandOptions) FileSystemCommand(alluxio.thrift.FileSystemCommand) InvalidPathException(alluxio.exception.InvalidPathException)

Example 44 with FileDoesNotExistException

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);
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) CompleteFileEntry(alluxio.proto.journal.File.CompleteFileEntry) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockInfoException(alluxio.exception.BlockInfoException) InodeFile(alluxio.master.file.meta.InodeFile)

Example 45 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class FileSystemMaster method getFileInfoInternal.

/**
   * @param inodePath the {@link LockedInodePath} to get the {@link FileInfo} for
   * @return the {@link FileInfo} for the given inode
   * @throws FileDoesNotExistException if the file does not exist
   * @throws AccessControlException if permission denied
   */
private FileInfo getFileInfoInternal(LockedInodePath inodePath) throws FileDoesNotExistException, AccessControlException {
    Inode<?> inode = inodePath.getInode();
    AlluxioURI uri = inodePath.getUri();
    FileInfo fileInfo = inode.generateClientFileInfo(uri.toString());
    fileInfo.setInMemoryPercentage(getInMemoryPercentage(inode));
    if (inode instanceof InodeFile) {
        try {
            fileInfo.setFileBlockInfos(getFileBlockInfoListInternal(inodePath));
        } catch (InvalidPathException e) {
            throw new FileDoesNotExistException(e.getMessage(), e);
        }
    }
    MountTable.Resolution resolution;
    try {
        resolution = mMountTable.resolve(uri);
    } catch (InvalidPathException e) {
        throw new FileDoesNotExistException(e.getMessage(), e);
    }
    AlluxioURI resolvedUri = resolution.getUri();
    // Only set the UFS path if the path is nested under a mount point.
    if (!uri.equals(resolvedUri)) {
        fileInfo.setUfsPath(resolvedUri.toString());
    }
    Metrics.FILE_INFOS_GOT.inc();
    return fileInfo;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) InodeFile(alluxio.master.file.meta.InodeFile) MountTable(alluxio.master.file.meta.MountTable) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Aggregations

FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)51 AlluxioURI (alluxio.AlluxioURI)36 InvalidPathException (alluxio.exception.InvalidPathException)20 IOException (java.io.IOException)19 AlluxioException (alluxio.exception.AlluxioException)16 Test (org.junit.Test)14 URIStatus (alluxio.client.file.URIStatus)13 ArrayList (java.util.ArrayList)10 AccessControlException (alluxio.exception.AccessControlException)7 FileInfo (alluxio.wire.FileInfo)7 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)5 BlockInfoException (alluxio.exception.BlockInfoException)4 RestApiTest (alluxio.rest.RestApiTest)4 TestCase (alluxio.rest.TestCase)4 HashMap (java.util.HashMap)4 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)3 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)3 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)3 Inode (alluxio.master.file.meta.Inode)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3