Search in sources :

Example 6 with MountTable

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

the class UfsStatusCacheTest method spyUfs.

/**
 * Recreates the mount table with the local UFS as a spy'd mockito object.
 */
private void spyUfs() {
    mUfs = Mockito.spy(mUfs);
    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();
    manager.mUnderFileSystemMap.put(new AbstractUfsManager.Key(new AlluxioURI("/"), null), mUfs);
    mMountTable = new MountTable(manager, rootMountInfo);
}
Also used : MountInfo(alluxio.master.file.meta.options.MountInfo) MountTable(alluxio.master.file.meta.MountTable) AlluxioURI(alluxio.AlluxioURI)

Example 7 with MountTable

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

the class UfsStatusCache method fetchStatusIfAbsent.

/**
 * Attempts to return a status from the cache. If it doesn't exist, reaches to the UFS for it.
 *
 * @param path the path the retrieve
 * @param mountTable the Alluxio mount table
 * @return The corresponding {@link UfsStatus} or {@code null} if there is none stored
 */
@Nullable
public UfsStatus fetchStatusIfAbsent(AlluxioURI path, MountTable mountTable) throws InvalidPathException, IOException {
    UfsStatus status;
    try {
        status = getStatus(path);
    } catch (FileNotFoundException e) {
        return null;
    }
    if (status != null) {
        return status;
    }
    MountTable.Resolution resolution = mountTable.resolve(path);
    AlluxioURI ufsUri = resolution.getUri();
    try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
        UnderFileSystem ufs = ufsResource.get();
        UfsStatus ufsStatus = ufs.getStatus(ufsUri.toString());
        if (ufsStatus == null) {
            mAbsentCache.addSinglePath(path);
            return null;
        }
        ufsStatus.setName(path.getName());
        addStatus(path, ufsStatus);
        return ufsStatus;
    } catch (FileNotFoundException e) {
        // If the ufs can not find the file, we explicitly mark it absent so we do not recheck it
        mAbsentCache.addSinglePath(path);
    } catch (IllegalArgumentException | IOException e) {
        LogUtils.warnWithException(LOG, "Failed to fetch status for {}", path, e);
    }
    return null;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) MountTable(alluxio.master.file.meta.MountTable) AlluxioURI(alluxio.AlluxioURI) Nullable(javax.annotation.Nullable)

Example 8 with MountTable

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

the class UfsStatusCache method getChildrenIfAbsent.

/**
 * Retrieves the child UFS statuses for a given path and stores them in the cache.
 *
 * This method first checks if the children have already been retrieved, and if not, then
 * retrieves them.
 *
 * @param path the path to get the children for
 * @param mountTable the Alluxio mount table
 * @return the child statuses that were stored in the cache, or null if the UFS couldn't list the
 *         statuses
 * @throws InvalidPathException when the table can't resolve the mount for the given URI
 */
@Nullable
Collection<UfsStatus> getChildrenIfAbsent(AlluxioURI path, MountTable mountTable) throws InvalidPathException {
    Collection<UfsStatus> children = getChildren(path);
    if (children != null) {
        return children;
    }
    if (mAbsentCache.isAbsentSince(path, mCacheValidTime)) {
        return null;
    }
    MountTable.Resolution resolution = mountTable.resolve(path);
    AlluxioURI ufsUri = resolution.getUri();
    try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
        UnderFileSystem ufs = ufsResource.get();
        UfsStatus[] statuses = ufs.listStatus(ufsUri.toString());
        if (statuses == null) {
            mAbsentCache.addSinglePath(path);
            return null;
        }
        children = Arrays.asList(statuses);
        addChildren(path, children);
    } catch (IllegalArgumentException | IOException e) {
        LOG.debug("Failed to add status to cache {}", path, e);
    }
    return children;
}
Also used : IOException(java.io.IOException) MountTable(alluxio.master.file.meta.MountTable) AlluxioURI(alluxio.AlluxioURI) Nullable(javax.annotation.Nullable)

Example 9 with MountTable

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

the class UfsConfigurationJournalTest method testOptionsPersisted.

@Test
public void testOptionsPersisted() throws Exception {
    // Set ufs specific options and other mount flags
    AlluxioURI mountPoint = new AlluxioURI("/mnt");
    ImmutableMap<String, String> options = ImmutableMap.of("k1", "v1", "k2", "v2");
    mFs.mount(mountPoint, new AlluxioURI(LOCAL_UFS_PATH), MountPOptions.newBuilder().putAllProperties(options).setReadOnly(true).setShared(true).build());
    // Get mount id
    MountTable mountTable = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class), "mMountTable");
    long mountId = mountTable.resolve(mountPoint).getMountId();
    // Restart masters
    mLocalAlluxioClusterResource.get().restartMasters();
    // Checks all options and flags are persisted after restart
    UfsManager ufsManager = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class), "mUfsManager");
    try (CloseableResource<UnderFileSystem> resource = ufsManager.get(mountId).acquireUfsResource()) {
        UnderFileSystemConfiguration ufsConf = Whitebox.getInternalState(resource.get(), "mConf");
        assertEquals(ufsConf.getMountSpecificConf().size(), options.size());
        for (Map.Entry<String, String> entry : options.entrySet()) {
            assertEquals(entry.getValue(), ufsConf.getMountSpecificConf().get(entry.getKey()));
        }
        assertTrue(ufsConf.isReadOnly());
        assertTrue(ufsConf.isShared());
    }
}
Also used : UfsManager(alluxio.underfs.UfsManager) UnderFileSystemConfiguration(alluxio.underfs.UnderFileSystemConfiguration) FileSystemMaster(alluxio.master.file.FileSystemMaster) MountTable(alluxio.master.file.meta.MountTable) UnderFileSystem(alluxio.underfs.UnderFileSystem) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

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