Search in sources :

Example 21 with InodeFile

use of alluxio.master.file.meta.InodeFile in project alluxio by Alluxio.

the class DefaultFileSystemMaster method completeFileInternal.

/**
 * @param rpcContext the rpc context
 * @param inodePath the {@link LockedInodePath} to complete
 * @param length the length to use
 * @param opTimeMs the operation time (in milliseconds)
 * @param ufsFingerprint the ufs fingerprint
 */
private void completeFileInternal(RpcContext rpcContext, LockedInodePath inodePath, long length, long opTimeMs, String ufsFingerprint) throws FileDoesNotExistException, InvalidPathException, InvalidFileSizeException, FileAlreadyCompletedException, UnavailableException {
    Preconditions.checkState(inodePath.getLockPattern().isWrite());
    InodeFile inode = inodePath.getInodeFile();
    if (inode.isCompleted() && inode.getLength() != Constants.UNKNOWN_SIZE) {
        throw new FileAlreadyCompletedException(String.format("File %s has already been completed.", inode.getName()));
    }
    if (length < 0 && length != Constants.UNKNOWN_SIZE) {
        throw new InvalidFileSizeException("File " + inode.getName() + " cannot have negative length: " + length);
    }
    Builder entry = UpdateInodeFileEntry.newBuilder().setId(inode.getId()).setPath(inodePath.getUri().getPath()).setCompleted(true).setLength(length);
    if (length == Constants.UNKNOWN_SIZE) {
        // TODO(gpang): allow unknown files to be multiple blocks.
        // If the length of the file is unknown, only allow 1 block to the file.
        length = inode.getBlockSizeBytes();
    }
    int sequenceNumber = 0;
    long remainingBytes = length;
    while (remainingBytes > 0) {
        entry.addSetBlocks(BlockId.createBlockId(inode.getBlockContainerId(), sequenceNumber));
        remainingBytes -= Math.min(remainingBytes, inode.getBlockSizeBytes());
        sequenceNumber++;
    }
    if (inode.isPersisted()) {
        // Commit all the file blocks (without locations) so the metadata for the block exists.
        commitBlockInfosForFile(entry.getSetBlocksList(), length, inode.getBlockSizeBytes());
        // The path exists in UFS, so it is no longer absent
        mUfsAbsentPathCache.processExisting(inodePath.getUri());
    }
    // We could introduce a concept of composite entries, so that these two entries could
    // be applied in a single call to applyAndJournal.
    mInodeTree.updateInode(rpcContext, UpdateInodeEntry.newBuilder().setId(inode.getId()).setUfsFingerprint(ufsFingerprint).setLastModificationTimeMs(opTimeMs).setLastAccessTimeMs(opTimeMs).setOverwriteModificationTime(true).build());
    mInodeTree.updateInodeFile(rpcContext, entry.build());
    Metrics.FILES_COMPLETED.inc();
}
Also used : InvalidFileSizeException(alluxio.exception.InvalidFileSizeException) Builder(alluxio.proto.journal.File.UpdateInodeFileEntry.Builder) InodeFile(alluxio.master.file.meta.InodeFile) FileAlreadyCompletedException(alluxio.exception.FileAlreadyCompletedException) Fingerprint(alluxio.underfs.Fingerprint)

Example 22 with InodeFile

use of alluxio.master.file.meta.InodeFile in project alluxio by Alluxio.

the class DefaultFileSystemMaster method getInAlluxioPercentage.

/**
 * Gets the in-Alluxio percentage of an Inode. For a file that has all blocks in Alluxio, it
 * returns 100; for a file that has no block in Alluxio, it returns 0. Returns 0 for a directory.
 *
 * @param inode the inode
 * @return the in alluxio percentage
 */
private int getInAlluxioPercentage(Inode inode) throws UnavailableException {
    if (!inode.isFile()) {
        return 0;
    }
    InodeFile inodeFile = inode.asFile();
    long length = inodeFile.getLength();
    if (length == 0) {
        return 100;
    }
    long inAlluxioLength = 0;
    for (BlockInfo info : mBlockMaster.getBlockInfoList(inodeFile.getBlockIds())) {
        if (!info.getLocations().isEmpty()) {
            inAlluxioLength += info.getLength();
        }
    }
    return (int) (inAlluxioLength * 100 / length);
}
Also used : BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) InodeFile(alluxio.master.file.meta.InodeFile)

Example 23 with InodeFile

use of alluxio.master.file.meta.InodeFile in project alluxio by Alluxio.

the class DefaultFileSystemMaster method getFileBlockInfoListInternal.

/**
 * @param inodePath the {@link LockedInodePath} to get the info for
 * @return a list of {@link FileBlockInfo} for all the blocks of the given inode
 */
private List<FileBlockInfo> getFileBlockInfoListInternal(LockedInodePath inodePath) throws InvalidPathException, FileDoesNotExistException, UnavailableException {
    InodeFile file = inodePath.getInodeFile();
    List<BlockInfo> blockInfoList = mBlockMaster.getBlockInfoList(file.getBlockIds());
    List<FileBlockInfo> ret = new ArrayList<>();
    for (BlockInfo blockInfo : blockInfoList) {
        ret.add(generateFileBlockInfo(inodePath, blockInfo));
    }
    return ret;
}
Also used : BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) ArrayList(java.util.ArrayList) InodeFile(alluxio.master.file.meta.InodeFile) FileBlockInfo(alluxio.wire.FileBlockInfo)

Aggregations

InodeFile (alluxio.master.file.meta.InodeFile)23 BlockInfo (alluxio.wire.BlockInfo)9 FileBlockInfo (alluxio.wire.FileBlockInfo)9 MountTable (alluxio.master.file.meta.MountTable)7 AlluxioURI (alluxio.AlluxioURI)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)6 Inode (alluxio.master.file.meta.Inode)6 UnderFileSystem (alluxio.underfs.UnderFileSystem)6 IOException (java.io.IOException)6 Fingerprint (alluxio.underfs.Fingerprint)5 BlockInfoException (alluxio.exception.BlockInfoException)4 LockedInodePath (alluxio.master.file.meta.LockedInodePath)4 AccessControlException (alluxio.exception.AccessControlException)2 InvalidPathException (alluxio.exception.InvalidPathException)2 JobDoesNotExistException (alluxio.exception.JobDoesNotExistException)2 ResourceExhaustedException (alluxio.exception.status.ResourceExhaustedException)2 UnavailableException (alluxio.exception.status.UnavailableException)2 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)2 InodeTree (alluxio.master.file.meta.InodeTree)2 UfsStatus (alluxio.underfs.UfsStatus)2