Search in sources :

Example 6 with CreateDirectoryContext

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

the class InodeSyncStream method loadDirectoryMetadata.

/**
 * Loads metadata for the directory identified by the given path from UFS into Alluxio. This does
 * not actually require looking at the UFS path.
 * It is a no-op if the directory exists.
 *
 * 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 if necessary.
 *
 * @param rpcContext the rpc context
 * @param inodePath the path for which metadata should be loaded
 * @param context the load metadata context
 */
static void loadDirectoryMetadata(RpcContext rpcContext, LockedInodePath inodePath, LoadMetadataContext context, MountTable mountTable, DefaultFileSystemMaster fsMaster) throws FileDoesNotExistException, InvalidPathException, AccessControlException, IOException {
    if (inodePath.fullPathExists()) {
        return;
    }
    CreateDirectoryContext createDirectoryContext = CreateDirectoryContext.defaults();
    createDirectoryContext.getOptions().setRecursive(context.getOptions().getCreateAncestors()).setAllowExists(false).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(context.getOptions().getCommonOptions().getTtl()).setTtlAction(context.getOptions().getCommonOptions().getTtlAction()));
    createDirectoryContext.setMountPoint(mountTable.isMountPoint(inodePath.getUri()));
    createDirectoryContext.setMetadataLoad(true);
    createDirectoryContext.setWriteType(WriteType.THROUGH);
    MountTable.Resolution resolution = mountTable.resolve(inodePath.getUri());
    AlluxioURI ufsUri = resolution.getUri();
    AccessControlList acl = null;
    DefaultAccessControlList defaultAcl = null;
    try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
        UnderFileSystem ufs = ufsResource.get();
        if (context.getUfsStatus() == null) {
            context.setUfsStatus(ufs.getExistingDirectoryStatus(ufsUri.toString()));
        }
        Pair<AccessControlList, DefaultAccessControlList> aclPair = ufs.getAclPair(ufsUri.toString());
        if (aclPair != null) {
            acl = aclPair.getFirst();
            defaultAcl = aclPair.getSecond();
        }
    }
    String ufsOwner = context.getUfsStatus().getOwner();
    String ufsGroup = context.getUfsStatus().getGroup();
    short ufsMode = context.getUfsStatus().getMode();
    Long lastModifiedTime = context.getUfsStatus().getLastModifiedTime();
    Mode mode = new Mode(ufsMode);
    if (resolution.getShared()) {
        mode.setOtherBits(mode.getOtherBits().or(mode.getOwnerBits()));
    }
    createDirectoryContext.getOptions().setMode(mode.toProto());
    createDirectoryContext.setOwner(ufsOwner).setGroup(ufsGroup).setUfsStatus(context.getUfsStatus());
    createDirectoryContext.setXAttr(context.getUfsStatus().getXAttr());
    if (acl != null) {
        createDirectoryContext.setAcl(acl.getEntries());
    }
    if (defaultAcl != null) {
        createDirectoryContext.setDefaultAcl(defaultAcl.getEntries());
    }
    if (lastModifiedTime != null) {
        createDirectoryContext.setOperationTimeMs(lastModifiedTime);
    }
    try (LockedInodePath writeLockedPath = inodePath.lockFinalEdgeWrite()) {
        fsMaster.createDirectoryInternal(rpcContext, writeLockedPath, createDirectoryContext);
    } catch (FileAlreadyExistsException e) {
    // This may occur if a thread created or loaded the directory before we got the write lock.
    // The directory already exists, so nothing needs to be loaded.
    }
    // 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) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext) Mode(alluxio.security.authorization.Mode) MountTable(alluxio.master.file.meta.MountTable) LockedInodePath(alluxio.master.file.meta.LockedInodePath) DefaultAccessControlList(alluxio.security.authorization.DefaultAccessControlList) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Example 7 with CreateDirectoryContext

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

the class FileSystemMasterIntegrationTest method renameToDeeper.

@Test
public void renameToDeeper() throws Exception {
    CreateFileContext createFileOptions = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setRecursive(true));
    CreateDirectoryContext createDirectoryContext = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true));
    mThrown.expect(InvalidPathException.class);
    mFsMaster.createDirectory(new AlluxioURI("/testDir1/testDir2"), createDirectoryContext);
    mFsMaster.createFile(new AlluxioURI("/testDir1/testDir2/testDir3/testFile3"), createFileOptions);
    mFsMaster.rename(new AlluxioURI("/testDir1/testDir2"), new AlluxioURI("/testDir1/testDir2/testDir3/testDir4"), RenameContext.defaults());
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 8 with CreateDirectoryContext

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

the class InodeStoreBench method writeInode.

private static void writeInode() {
    int id = NEXT_INODE_ID.getAndIncrement();
    CreateDirectoryContext createContext = CreateDirectoryContext.defaults();
    MutableInodeDirectory dir = MutableInodeDirectory.create(id, 0, CommonUtils.randomAlphaNumString(30), createContext);
    sStore.writeInode(dir);
}
Also used : MutableInodeDirectory(alluxio.master.file.meta.MutableInodeDirectory) CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext)

Example 9 with CreateDirectoryContext

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

the class FileSystemMasterTest method setTtlForDirectoryWithNoTtl.

/**
 * Tests that an exception is thrown when trying to get information about a Directory after
 * it has been deleted because of a TTL of 0.
 */
@Test
public void setTtlForDirectoryWithNoTtl() throws Exception {
    CreateDirectoryContext directoryContext = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true));
    mFileSystemMaster.createDirectory(NESTED_URI, directoryContext);
    mFileSystemMaster.createDirectory(NESTED_DIR_URI, directoryContext);
    CreateFileContext createFileContext = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true));
    long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, createFileContext).getFileId();
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
    // Since no TTL is set, the file should not be deleted.
    assertEquals(fileId, mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT).getFileId());
    // Set ttl.
    mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(0))));
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
    // TTL is set to 0, the file and directory should have been deleted during last TTL check.
    mThrown.expect(FileDoesNotExistException.class);
    mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT);
    mFileSystemMaster.getFileInfo(NESTED_DIR_URI, GET_STATUS_CONTEXT);
    mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT);
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext) Test(org.junit.Test)

Example 10 with CreateDirectoryContext

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

the class FileSystemMasterTest method ttlDirectoryFreeReplay.

/**
 * Tests that TTL free of a directory is not forgotten across restarts.
 */
@Test
public void ttlDirectoryFreeReplay() throws Exception {
    CreateDirectoryContext directoryContext = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true));
    mFileSystemMaster.createDirectory(NESTED_URI, directoryContext);
    long blockId = createFileWithSingleBlock(NESTED_FILE_URI);
    assertEquals(1, mBlockMaster.getBlockInfo(blockId).getLocations().size());
    // Set ttl & operation.
    mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setCommonOptions(FileSystemOptions.commonDefaults(ServerConfiguration.global()).toBuilder().setTtl(0).setTtlAction(alluxio.grpc.TtlAction.FREE))));
    // Simulate restart.
    stopServices();
    startServices();
    Command heartbeat = mBlockMaster.workerHeartbeat(mWorkerId1, null, ImmutableMap.of(Constants.MEDIUM_MEM, (long) Constants.KB), ImmutableList.of(blockId), ImmutableMap.of(), ImmutableMap.of(), mMetrics);
    // Verify the muted Free command on worker1.
    assertEquals(Command.newBuilder().setCommandType(CommandType.Nothing).build(), heartbeat);
    assertEquals(0, mBlockMaster.getBlockInfo(blockId).getLocations().size());
}
Also used : CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext) Command(alluxio.grpc.Command) FileSystemCommand(alluxio.wire.FileSystemCommand) Test(org.junit.Test)

Aggregations

CreateDirectoryContext (alluxio.master.file.contexts.CreateDirectoryContext)15 Test (org.junit.Test)10 AlluxioURI (alluxio.AlluxioURI)6 CreateFileContext (alluxio.master.file.contexts.CreateFileContext)5 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)3 FileInfo (alluxio.wire.FileInfo)3 Command (alluxio.grpc.Command)2 AccessControlList (alluxio.security.authorization.AccessControlList)2 DefaultAccessControlList (alluxio.security.authorization.DefaultAccessControlList)2 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)2 FileSystemCommand (alluxio.wire.FileSystemCommand)2 AuthenticatedUserRule (alluxio.AuthenticatedUserRule)1 BlockInfoException (alluxio.exception.BlockInfoException)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 LockedInodePath (alluxio.master.file.meta.LockedInodePath)1 MountTable (alluxio.master.file.meta.MountTable)1 MutableInodeDirectory (alluxio.master.file.meta.MutableInodeDirectory)1 UpdateInodeEntry (alluxio.proto.journal.File.UpdateInodeEntry)1 LockResource (alluxio.resource.LockResource)1