Search in sources :

Example 1 with CompleteFileContext

use of alluxio.master.file.contexts.CompleteFileContext in project alluxio by Alluxio.

the class PermissionCheckTest method completeFileFail.

@Test
public void completeFileFail() throws Exception {
    // set unmask
    try (Closeable c = new ConfigurationRule(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK, "066", ServerConfiguration.global()).toResource()) {
        String file = PathUtils.concatPath(TEST_DIR_URI, "/testComplete1");
        verifyCreateFile(TEST_USER_1, file, false);
        CompleteFileContext expect = getNonDefaultCompleteFileContext();
        mThrown.expect(AccessControlException.class);
        mThrown.expectMessage(ExceptionMessage.PERMISSION_DENIED.getMessage(toExceptionMessage(TEST_USER_2.getUser(), Mode.Bits.WRITE, file, "testComplete1")));
        verifyCompleteFile(TEST_USER_2, file, expect);
    }
}
Also used : Closeable(java.io.Closeable) CompleteFileContext(alluxio.master.file.contexts.CompleteFileContext) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 2 with CompleteFileContext

use of alluxio.master.file.contexts.CompleteFileContext in project alluxio by Alluxio.

the class FileSystemMasterTest method createFileWithSingleBlock.

private long createFileWithSingleBlock(AlluxioURI uri) throws Exception {
    mFileSystemMaster.createFile(uri, mNestedFileContext);
    long blockId = mFileSystemMaster.getNewBlockIdForFile(uri);
    mBlockMaster.commitBlock(mWorkerId1, Constants.KB, Constants.MEDIUM_MEM, Constants.MEDIUM_MEM, blockId, Constants.KB);
    CompleteFileContext context = CompleteFileContext.mergeFrom(CompleteFilePOptions.newBuilder().setUfsLength(Constants.KB));
    mFileSystemMaster.completeFile(uri, context);
    return blockId;
}
Also used : CompleteFileContext(alluxio.master.file.contexts.CompleteFileContext)

Example 3 with CompleteFileContext

use of alluxio.master.file.contexts.CompleteFileContext in project alluxio by Alluxio.

the class InodeSyncStream method loadFileMetadataInternal.

/**
 * Loads metadata for the file identified by the given path from UFS into Alluxio.
 *
 * This method doesn't require any specific type of locking on inodePath. If the path needs to be
 * loaded, we will acquire a write-edge lock.
 *
 * @param rpcContext the rpc context
 * @param inodePath the path for which metadata should be loaded
 * @param resolution the UFS resolution of path
 * @param context the load metadata context
 */
static void loadFileMetadataInternal(RpcContext rpcContext, LockedInodePath inodePath, MountTable.Resolution resolution, LoadMetadataContext context, DefaultFileSystemMaster fsMaster) throws BlockInfoException, FileDoesNotExistException, InvalidPathException, FileAlreadyCompletedException, InvalidFileSizeException, IOException {
    if (inodePath.fullPathExists()) {
        return;
    }
    AlluxioURI ufsUri = resolution.getUri();
    long ufsBlockSizeByte;
    long ufsLength;
    AccessControlList acl = null;
    try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
        UnderFileSystem ufs = ufsResource.get();
        if (context.getUfsStatus() == null) {
            context.setUfsStatus(ufs.getExistingFileStatus(ufsUri.toString()));
        }
        ufsLength = ((UfsFileStatus) context.getUfsStatus()).getContentLength();
        long blockSize = ((UfsFileStatus) context.getUfsStatus()).getBlockSize();
        ufsBlockSizeByte = blockSize != UfsFileStatus.UNKNOWN_BLOCK_SIZE ? blockSize : ufs.getBlockSizeByte(ufsUri.toString());
        if (fsMaster.isAclEnabled()) {
            Pair<AccessControlList, DefaultAccessControlList> aclPair = ufs.getAclPair(ufsUri.toString());
            if (aclPair != null) {
                acl = aclPair.getFirst();
                // DefaultACL should be null, because it is a file
                if (aclPair.getSecond() != null) {
                    LOG.warn("File {} has default ACL in the UFS", inodePath.getUri());
                }
            }
        }
    }
    // Metadata loaded from UFS has no TTL set.
    CreateFileContext createFileContext = CreateFileContext.defaults();
    createFileContext.getOptions().setBlockSizeBytes(ufsBlockSizeByte);
    createFileContext.getOptions().setRecursive(context.getOptions().getCreateAncestors());
    createFileContext.getOptions().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(context.getOptions().getCommonOptions().getTtl()).setTtlAction(context.getOptions().getCommonOptions().getTtlAction()));
    // set as through since already in UFS
    createFileContext.setWriteType(WriteType.THROUGH);
    createFileContext.setMetadataLoad(true);
    createFileContext.setOwner(context.getUfsStatus().getOwner());
    createFileContext.setGroup(context.getUfsStatus().getGroup());
    createFileContext.setXAttr(context.getUfsStatus().getXAttr());
    short ufsMode = context.getUfsStatus().getMode();
    Mode mode = new Mode(ufsMode);
    Long ufsLastModified = context.getUfsStatus().getLastModifiedTime();
    if (resolution.getShared()) {
        mode.setOtherBits(mode.getOtherBits().or(mode.getOwnerBits()));
    }
    createFileContext.getOptions().setMode(mode.toProto());
    if (acl != null) {
        createFileContext.setAcl(acl.getEntries());
    }
    if (ufsLastModified != null) {
        createFileContext.setOperationTimeMs(ufsLastModified);
    }
    try (LockedInodePath writeLockedPath = inodePath.lockFinalEdgeWrite();
        MergeJournalContext merger = new MergeJournalContext(rpcContext.getJournalContext(), writeLockedPath.getUri(), InodeSyncStream::mergeCreateComplete)) {
        // We do not want to close this wrapRpcContext because it uses elements from another context
        RpcContext wrapRpcContext = new RpcContext(rpcContext.getBlockDeletionContext(), merger, rpcContext.getOperationContext());
        fsMaster.createFileInternal(wrapRpcContext, writeLockedPath, createFileContext);
        CompleteFileContext completeContext = CompleteFileContext.mergeFrom(CompleteFilePOptions.newBuilder().setUfsLength(ufsLength)).setUfsStatus(context.getUfsStatus());
        if (ufsLastModified != null) {
            completeContext.setOperationTimeMs(ufsLastModified);
        }
        fsMaster.completeFileInternal(wrapRpcContext, writeLockedPath, completeContext);
    } catch (FileAlreadyExistsException e) {
        // This may occur if a thread created or loaded the file before we got the write lock.
        // The file already exists, so nothing needs to be loaded.
        LOG.debug("Failed to load file metadata: {}", e.toString());
    }
    // Re-traverse the path to pick up any newly created inodes.
    inodePath.traverse();
}
Also used : AccessControlList(alluxio.security.authorization.AccessControlList) DefaultAccessControlList(alluxio.security.authorization.DefaultAccessControlList) UfsFileStatus(alluxio.underfs.UfsFileStatus) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) MergeJournalContext(alluxio.master.journal.MergeJournalContext) Mode(alluxio.security.authorization.Mode) CompleteFileContext(alluxio.master.file.contexts.CompleteFileContext) CreateFileContext(alluxio.master.file.contexts.CreateFileContext) LockedInodePath(alluxio.master.file.meta.LockedInodePath) DefaultAccessControlList(alluxio.security.authorization.DefaultAccessControlList) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Example 4 with CompleteFileContext

use of alluxio.master.file.contexts.CompleteFileContext in project alluxio by Alluxio.

the class PermissionCheckTest method completeFileSuccess.

@Test
public void completeFileSuccess() throws Exception {
    // set unmask
    try (Closeable c = new ConfigurationRule(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK, "044", ServerConfiguration.global()).toResource()) {
        String file = PathUtils.concatPath(TEST_DIR_URI, "/testState1");
        verifyCreateFile(TEST_USER_1, file, false);
        CompleteFileContext expect = getNonDefaultCompleteFileContext();
        verifyCompleteFile(TEST_USER_2, file, expect);
    }
}
Also used : Closeable(java.io.Closeable) CompleteFileContext(alluxio.master.file.contexts.CompleteFileContext) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 5 with CompleteFileContext

use of alluxio.master.file.contexts.CompleteFileContext in project alluxio by Alluxio.

the class FileSystemMasterFaultToleranceIntegrationTest method partitionTolerantCompleteFile.

@Test
public void partitionTolerantCompleteFile() throws Exception {
    // Create paths for the test.
    AlluxioURI testPath1 = new AlluxioURI("/testPath1");
    // Create context1 with unique operation id.
    CompleteFileContext context = CompleteFileContext.mergeFrom(CompleteFilePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setOperationId(new OperationId(UUID.randomUUID()).toFsProto())));
    // Create context2 with unique operation id.
    CompleteFileContext context2 = CompleteFileContext.mergeFrom(CompleteFilePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setOperationId(new OperationId(UUID.randomUUID()).toFsProto())));
    // Run partition tolerance test on leading master.
    {
        // Acquire file-system-master of leading master.
        FileSystemMaster leadingFsMaster = mMultiMasterLocalAlluxioCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class);
        // Create the path to complete.
        leadingFsMaster.createFile(testPath1, CreateFileContext.defaults());
        // Complete the path the first time.
        leadingFsMaster.completeFile(testPath1, context);
        // Complete the path the second time with the same context.
        // It should just return successfully.
        leadingFsMaster.completeFile(testPath1, context);
        // Complete the file again with a different context.
        // It should fail with `FileAlreadyCompletedException`.
        assertThrows(FileAlreadyCompletedException.class, () -> leadingFsMaster.completeFile(testPath1, context2));
    }
    // Promote standby to be a leader and reset test state.
    mMultiMasterLocalAlluxioCluster.stopLeader();
    mMultiMasterLocalAlluxioCluster.waitForNewMaster(CLUSTER_WAIT_TIMEOUT_MS);
    mAuthenticatedUser.resetUser();
    // Run partition tolerance test on the *new* leading master.
    {
        // Acquire file-system-master of leading master.
        FileSystemMaster leadingFsMaster = mMultiMasterLocalAlluxioCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class);
        // Completing the file on the new leader with the original operation-id should succeed.
        leadingFsMaster.completeFile(testPath1, context);
        // Creating on the new leader with a different operation-id.
        // It should fail with `FileAlreadyCompletedException`.
        assertThrows(FileAlreadyCompletedException.class, () -> leadingFsMaster.completeFile(testPath1, context2));
    }
}
Also used : OperationId(alluxio.wire.OperationId) FileSystemMaster(alluxio.master.file.FileSystemMaster) CompleteFileContext(alluxio.master.file.contexts.CompleteFileContext) FileAlreadyCompletedException(alluxio.exception.FileAlreadyCompletedException) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

CompleteFileContext (alluxio.master.file.contexts.CompleteFileContext)5 Test (org.junit.Test)3 AlluxioURI (alluxio.AlluxioURI)2 ConfigurationRule (alluxio.ConfigurationRule)2 Closeable (java.io.Closeable)2 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)1 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)1 FileSystemMaster (alluxio.master.file.FileSystemMaster)1 CreateFileContext (alluxio.master.file.contexts.CreateFileContext)1 LockedInodePath (alluxio.master.file.meta.LockedInodePath)1 MergeJournalContext (alluxio.master.journal.MergeJournalContext)1 AccessControlList (alluxio.security.authorization.AccessControlList)1 DefaultAccessControlList (alluxio.security.authorization.DefaultAccessControlList)1 Mode (alluxio.security.authorization.Mode)1 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)1 UfsFileStatus (alluxio.underfs.UfsFileStatus)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1 OperationId (alluxio.wire.OperationId)1