Search in sources :

Example 1 with Builder

use of alluxio.proto.journal.File.UpdateInodeFileEntry.Builder 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)

Aggregations

FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)1 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)1 InodeFile (alluxio.master.file.meta.InodeFile)1 Builder (alluxio.proto.journal.File.UpdateInodeFileEntry.Builder)1 Fingerprint (alluxio.underfs.Fingerprint)1