Search in sources :

Example 1 with MountTable

use of alluxio.master.file.meta.MountTable 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 2 with MountTable

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

the class AccessTimeUpdaterTest method before.

@Before
public final void before() throws Exception {
    mFileSystemMaster = Mockito.mock(FileSystemMaster.class);
    when(mFileSystemMaster.getName()).thenReturn(Constants.FILE_SYSTEM_MASTER_NAME);
    ServerConfiguration.set(PropertyKey.MASTER_JOURNAL_TYPE, "UFS");
    MasterRegistry registry = new MasterRegistry();
    JournalSystem journalSystem = JournalTestUtils.createJournalSystem(mTestFolder);
    mContext = MasterTestUtils.testMasterContext(journalSystem);
    new MetricsMasterFactory().create(registry, mContext);
    mBlockMaster = new BlockMasterFactory().create(registry, mContext);
    InodeDirectoryIdGenerator directoryIdGenerator = new InodeDirectoryIdGenerator(mBlockMaster);
    UfsManager manager = mock(UfsManager.class);
    MountTable mountTable = new MountTable(manager, mock(MountInfo.class));
    InodeLockManager lockManager = new InodeLockManager();
    mInodeStore = mContext.getInodeStoreFactory().apply(lockManager);
    mInodeTree = new InodeTree(mInodeStore, mBlockMaster, directoryIdGenerator, mountTable, lockManager);
    journalSystem.start();
    journalSystem.gainPrimacy();
    mBlockMaster.start(true);
    ServerConfiguration.set(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED, true);
    ServerConfiguration.set(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_SUPERGROUP, "test-supergroup");
    mInodeTree.initializeRoot(TEST_OWNER, TEST_GROUP, TEST_MODE, NoopJournalContext.INSTANCE);
    mScheduler = new ControllableScheduler();
}
Also used : InodeDirectoryIdGenerator(alluxio.master.file.meta.InodeDirectoryIdGenerator) BlockMasterFactory(alluxio.master.block.BlockMasterFactory) UfsManager(alluxio.underfs.UfsManager) InodeLockManager(alluxio.master.file.meta.InodeLockManager) ControllableScheduler(alluxio.util.executor.ControllableScheduler) JournalSystem(alluxio.master.journal.JournalSystem) MasterRegistry(alluxio.master.MasterRegistry) MountTable(alluxio.master.file.meta.MountTable) MountInfo(alluxio.master.file.meta.options.MountInfo) InodeTree(alluxio.master.file.meta.InodeTree) MetricsMasterFactory(alluxio.master.metrics.MetricsMasterFactory) Before(org.junit.Before)

Example 3 with MountTable

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

the class PermissionCheckerTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    sFileContext = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setMode(TEST_NORMAL_MODE.toProto())).setOwner(TEST_USER_2.getUser()).setGroup(TEST_USER_2.getGroup());
    sWeirdFileContext = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setMode(TEST_WEIRD_MODE.toProto())).setOwner(TEST_USER_1.getUser()).setGroup(TEST_USER_1.getGroup());
    sNestedFileContext = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setMode(TEST_NORMAL_MODE.toProto()).setRecursive(true)).setOwner(TEST_USER_1.getUser()).setGroup(TEST_USER_1.getGroup());
    // setup an InodeTree
    sRegistry = new MasterRegistry();
    CoreMasterContext masterContext = MasterTestUtils.testMasterContext();
    sMetricsMaster = new MetricsMasterFactory().create(sRegistry, masterContext);
    sRegistry.add(MetricsMaster.class, sMetricsMaster);
    BlockMaster blockMaster = new BlockMasterFactory().create(sRegistry, masterContext);
    InodeDirectoryIdGenerator directoryIdGenerator = new InodeDirectoryIdGenerator(blockMaster);
    UfsManager ufsManager = mock(UfsManager.class);
    MountTable mountTable = new MountTable(ufsManager, mock(MountInfo.class));
    InodeLockManager lockManager = new InodeLockManager();
    sInodeStore = masterContext.getInodeStoreFactory().apply(lockManager);
    sTree = new InodeTree(sInodeStore, blockMaster, directoryIdGenerator, mountTable, lockManager);
    sRegistry.start(true);
    GroupMappingServiceTestUtils.resetCache();
    ServerConfiguration.set(PropertyKey.SECURITY_GROUP_MAPPING_CLASS, FakeUserGroupsMapping.class.getName());
    ServerConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName());
    ServerConfiguration.set(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED, true);
    ServerConfiguration.set(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_SUPERGROUP, TEST_SUPER_GROUP);
    sTree.initializeRoot(TEST_USER_ADMIN.getUser(), TEST_USER_ADMIN.getGroup(), TEST_NORMAL_MODE, NoopJournalContext.INSTANCE);
    // build file structure
    createAndSetPermission(TEST_DIR_FILE_URI, sNestedFileContext);
    createAndSetPermission(TEST_FILE_URI, sFileContext);
    createAndSetPermission(TEST_WEIRD_FILE_URI, sWeirdFileContext);
}
Also used : BlockMaster(alluxio.master.block.BlockMaster) InodeDirectoryIdGenerator(alluxio.master.file.meta.InodeDirectoryIdGenerator) BlockMasterFactory(alluxio.master.block.BlockMasterFactory) UfsManager(alluxio.underfs.UfsManager) CoreMasterContext(alluxio.master.CoreMasterContext) InodeLockManager(alluxio.master.file.meta.InodeLockManager) MasterRegistry(alluxio.master.MasterRegistry) MountTable(alluxio.master.file.meta.MountTable) MountInfo(alluxio.master.file.meta.options.MountInfo) InodeTree(alluxio.master.file.meta.InodeTree) MetricsMasterFactory(alluxio.master.metrics.MetricsMasterFactory) BeforeClass(org.junit.BeforeClass)

Example 4 with MountTable

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

the class UfsStatusCacheTest method before.

@Before
public void before() throws Exception {
    mUfsUri = mTempDir.newFolder().getAbsolutePath();
    mUfs = new LocalUnderFileSystem(new AlluxioURI(mUfsUri), UnderFileSystemConfiguration.defaults(ServerConfiguration.global()));
    mService = Executors.newSingleThreadExecutor();
    mCache = new UfsStatusCache(mService, new NoopUfsAbsentPathCache(), UfsAbsentPathCache.ALWAYS);
    MountInfo rootMountInfo = new MountInfo(new AlluxioURI(MountTable.ROOT), new AlluxioURI(mUfsUri), IdUtils.ROOT_MOUNT_ID, MountPOptions.newBuilder().setReadOnly(false).setShared(false).build());
    MasterUfsManager manager = new MasterUfsManager();
    // add root mount
    manager.getRoot();
    mMountTable = new MountTable(manager, rootMountInfo);
}
Also used : NoopUfsAbsentPathCache(alluxio.master.file.meta.NoopUfsAbsentPathCache) LocalUnderFileSystem(alluxio.underfs.local.LocalUnderFileSystem) MountInfo(alluxio.master.file.meta.options.MountInfo) MountTable(alluxio.master.file.meta.MountTable) AlluxioURI(alluxio.AlluxioURI) Before(org.junit.Before)

Example 5 with MountTable

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

the class ReplicationCheckerTest method before.

@Before
public void before() throws Exception {
    ServerConfiguration.set(PropertyKey.MASTER_JOURNAL_TYPE, "UFS");
    MasterRegistry registry = new MasterRegistry();
    JournalSystem journalSystem = JournalTestUtils.createJournalSystem(mTestFolder);
    mContext = MasterTestUtils.testMasterContext(journalSystem);
    new MetricsMasterFactory().create(registry, mContext);
    mBlockMaster = new BlockMasterFactory().create(registry, mContext);
    InodeDirectoryIdGenerator directoryIdGenerator = new InodeDirectoryIdGenerator(mBlockMaster);
    UfsManager manager = mock(UfsManager.class);
    MountTable mountTable = new MountTable(manager, mock(MountInfo.class));
    InodeLockManager lockManager = new InodeLockManager();
    mInodeStore = mContext.getInodeStoreFactory().apply(lockManager);
    mInodeTree = new InodeTree(mInodeStore, mBlockMaster, directoryIdGenerator, mountTable, lockManager);
    journalSystem.start();
    journalSystem.gainPrimacy();
    mBlockMaster.start(true);
    ServerConfiguration.set(PropertyKey.TEST_MODE, true);
    ServerConfiguration.set(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED, true);
    ServerConfiguration.set(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_SUPERGROUP, "test-supergroup");
    mInodeTree.initializeRoot(TEST_OWNER, TEST_GROUP, TEST_MODE, NoopJournalContext.INSTANCE);
    mMockReplicationHandler = new MockHandler();
    mReplicationChecker = new ReplicationChecker(mInodeTree, mBlockMaster, mContext.getSafeModeManager(), mMockReplicationHandler);
}
Also used : InodeDirectoryIdGenerator(alluxio.master.file.meta.InodeDirectoryIdGenerator) BlockMasterFactory(alluxio.master.block.BlockMasterFactory) UfsManager(alluxio.underfs.UfsManager) InodeLockManager(alluxio.master.file.meta.InodeLockManager) JournalSystem(alluxio.master.journal.JournalSystem) MasterRegistry(alluxio.master.MasterRegistry) MountTable(alluxio.master.file.meta.MountTable) MountInfo(alluxio.master.file.meta.options.MountInfo) InodeTree(alluxio.master.file.meta.InodeTree) MetricsMasterFactory(alluxio.master.metrics.MetricsMasterFactory) Before(org.junit.Before)

Aggregations

MountTable (alluxio.master.file.meta.MountTable)9 AlluxioURI (alluxio.AlluxioURI)6 MountInfo (alluxio.master.file.meta.options.MountInfo)5 UfsManager (alluxio.underfs.UfsManager)4 MasterRegistry (alluxio.master.MasterRegistry)3 BlockMasterFactory (alluxio.master.block.BlockMasterFactory)3 InodeDirectoryIdGenerator (alluxio.master.file.meta.InodeDirectoryIdGenerator)3 InodeLockManager (alluxio.master.file.meta.InodeLockManager)3 InodeTree (alluxio.master.file.meta.InodeTree)3 MetricsMasterFactory (alluxio.master.metrics.MetricsMasterFactory)3 Before (org.junit.Before)3 JournalSystem (alluxio.master.journal.JournalSystem)2 UnderFileSystem (alluxio.underfs.UnderFileSystem)2 IOException (java.io.IOException)2 Nullable (javax.annotation.Nullable)2 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)1 CoreMasterContext (alluxio.master.CoreMasterContext)1 BlockMaster (alluxio.master.block.BlockMaster)1 FileSystemMaster (alluxio.master.file.FileSystemMaster)1 CreateDirectoryContext (alluxio.master.file.contexts.CreateDirectoryContext)1