Search in sources :

Example 6 with MountInfo

use of alluxio.master.file.meta.options.MountInfo in project alluxio by Alluxio.

the class MountTable method add.

/**
   * Mounts the given UFS path at the given Alluxio path. The Alluxio path should not be nested
   * under an existing mount point.
   *
   * @param alluxioUri an Alluxio path URI
   * @param ufsUri a UFS path URI
   * @param options the mount options
   * @throws FileAlreadyExistsException if the mount point already exists
   * @throws InvalidPathException if an invalid path is encountered
   */
public void add(AlluxioURI alluxioUri, AlluxioURI ufsUri, MountOptions options) throws FileAlreadyExistsException, InvalidPathException {
    String alluxioPath = alluxioUri.getPath();
    LOG.info("Mounting {} at {}", ufsUri, alluxioPath);
    try (LockResource r = new LockResource(mWriteLock)) {
        if (mMountTable.containsKey(alluxioPath)) {
            throw new FileAlreadyExistsException(ExceptionMessage.MOUNT_POINT_ALREADY_EXISTS.getMessage(alluxioPath));
        }
        // or suffix of any existing mount path.
        for (Map.Entry<String, MountInfo> entry : mMountTable.entrySet()) {
            String mountedAlluxioPath = entry.getKey();
            AlluxioURI mountedUfsUri = entry.getValue().getUfsUri();
            if (!mountedAlluxioPath.equals(ROOT) && PathUtils.hasPrefix(alluxioPath, mountedAlluxioPath)) {
                throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage(mountedAlluxioPath, alluxioPath));
            }
            if ((ufsUri.getScheme() == null || ufsUri.getScheme().equals(mountedUfsUri.getScheme())) && (ufsUri.getAuthority() == null || ufsUri.getAuthority().equals(mountedUfsUri.getAuthority()))) {
                String ufsPath = ufsUri.getPath();
                String mountedUfsPath = mountedUfsUri.getPath();
                if (PathUtils.hasPrefix(ufsPath, mountedUfsPath)) {
                    throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage(mountedUfsUri.toString(), ufsUri.toString()));
                }
                if (PathUtils.hasPrefix(mountedUfsPath, ufsPath)) {
                    throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage(ufsUri.toString(), mountedUfsUri.toString()));
                }
            }
        }
        mMountTable.put(alluxioPath, new MountInfo(ufsUri, options));
    }
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) LockResource(alluxio.resource.LockResource) MountInfo(alluxio.master.file.meta.options.MountInfo) HashMap(java.util.HashMap) Map(java.util.Map) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 7 with MountInfo

use of alluxio.master.file.meta.options.MountInfo in project alluxio by Alluxio.

the class MountTable method streamToJournalCheckpoint.

@Override
public void streamToJournalCheckpoint(JournalOutputStream outputStream) throws IOException {
    for (Map.Entry<String, MountInfo> entry : mMountTable.entrySet()) {
        String alluxioPath = entry.getKey();
        MountInfo info = entry.getValue();
        // do not journal the root mount point
        if (alluxioPath.equals(ROOT)) {
            continue;
        }
        Map<String, String> properties = info.getOptions().getProperties();
        List<File.StringPairEntry> protoProperties = new ArrayList<>(properties.size());
        for (Map.Entry<String, String> property : properties.entrySet()) {
            protoProperties.add(File.StringPairEntry.newBuilder().setKey(property.getKey()).setValue(property.getValue()).build());
        }
        AddMountPointEntry addMountPoint = AddMountPointEntry.newBuilder().setAlluxioPath(alluxioPath).setUfsPath(info.getUfsUri().toString()).setReadOnly(info.getOptions().isReadOnly()).addAllProperties(protoProperties).setShared(info.getOptions().isShared()).build();
        Journal.JournalEntry journalEntry = Journal.JournalEntry.newBuilder().setAddMountPoint(addMountPoint).build();
        outputStream.writeEntry(journalEntry);
    }
}
Also used : AddMountPointEntry(alluxio.proto.journal.File.AddMountPointEntry) ArrayList(java.util.ArrayList) Journal(alluxio.proto.journal.Journal) MountInfo(alluxio.master.file.meta.options.MountInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MountInfo (alluxio.master.file.meta.options.MountInfo)7 Map (java.util.Map)5 LockResource (alluxio.resource.LockResource)4 HashMap (java.util.HashMap)4 AlluxioURI (alluxio.AlluxioURI)3 AccessControlException (alluxio.exception.AccessControlException)1 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 AddMountPointEntry (alluxio.proto.journal.File.AddMountPointEntry)1 Journal (alluxio.proto.journal.Journal)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1 MountPointInfo (alluxio.wire.MountPointInfo)1 ArrayList (java.util.ArrayList)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Test (org.junit.Test)1